Merge support for anaglyph stereo
[oweals/minetest.git] / src / staticobject.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef STATICOBJECT_HEADER
21 #define STATICOBJECT_HEADER
22
23 #include "irrlichttypes_bloated.h"
24 #include <string>
25 #include <sstream>
26 #include "debug.h"
27
28 struct StaticObject
29 {
30         u8 type;
31         v3f pos;
32         std::string data;
33
34         StaticObject():
35                 type(0),
36                 pos(0,0,0)
37         {
38         }
39         StaticObject(u8 type_, v3f pos_, const std::string &data_):
40                 type(type_),
41                 pos(pos_),
42                 data(data_)
43         {
44         }
45
46         void serialize(std::ostream &os);
47         void deSerialize(std::istream &is, u8 version);
48 };
49
50 class StaticObjectList
51 {
52 public:
53         /*
54                 Inserts an object to the container.
55                 Id must be unique or 0.
56         */
57         void insert(u16 id, StaticObject obj)
58         {
59                 if(id == 0)
60                 {
61                         m_stored.push_back(obj);
62                 }
63                 else
64                 {
65                         if(m_active.find(id) != NULL)
66                         {
67                                 dstream<<"ERROR: StaticObjectList::insert(): "
68                                                 <<"id already exists"<<std::endl;
69                                 assert(0);
70                                 return;
71                         }
72                         m_active.insert(id, obj);
73                 }
74         }
75
76         void remove(u16 id)
77         {
78                 assert(id != 0);
79                 if(m_active.find(id) == NULL)
80                 {
81                         dstream<<"WARNING: StaticObjectList::remove(): id="<<id
82                                         <<" not found"<<std::endl;
83                         return;
84                 }
85                 m_active.remove(id);
86         }
87
88         void serialize(std::ostream &os);
89         void deSerialize(std::istream &is);
90         
91         /*
92                 NOTE: When an object is transformed to active, it is removed
93                 from m_stored and inserted to m_active.
94                 The caller directly manipulates these containers.
95         */
96         core::list<StaticObject> m_stored;
97         core::map<u16, StaticObject> m_active;
98
99 private:
100 };
101
102 #endif
103