3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU 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.
20 #ifndef STATICOBJECT_HEADER
21 #define STATICOBJECT_HEADER
23 #include "common_irrlicht.h"
39 StaticObject(u8 type_, v3f pos_, const std::string &data_):
46 void serialize(std::ostream &os)
53 writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000));
56 os<<serializeString(data);
58 void deSerialize(std::istream &is, u8 version)
66 v3s32 intp = readV3S32((u8*)buf);
67 pos.X = (f32)intp.X/1000;
68 pos.Y = (f32)intp.Y/1000;
69 pos.Z = (f32)intp.Z/1000;
71 data = deSerializeString(is);
75 class StaticObjectList
79 Inserts an object to the container.
80 Id must be unique or 0.
82 void insert(u16 id, StaticObject obj)
86 m_stored.push_back(obj);
90 if(m_active.find(id) != NULL)
92 dstream<<"ERROR: StaticObjectList::insert(): "
93 <<"id already exists"<<std::endl;
97 m_active.insert(id, obj);
104 if(m_active.find(id) == NULL)
106 dstream<<"WARNING: StaticObjectList::remove(): id="<<id
107 <<" not found"<<std::endl;
113 void serialize(std::ostream &os)
120 u16 count = m_stored.size() + m_active.size();
121 writeU16((u8*)buf, count);
123 for(core::list<StaticObject>::Iterator
124 i = m_stored.begin();
125 i != m_stored.end(); i++)
127 StaticObject &s_obj = *i;
130 for(core::map<u16, StaticObject>::Iterator
131 i = m_active.getIterator();
132 i.atEnd()==false; i++)
134 StaticObject s_obj = i.getNode()->getValue();
138 void deSerialize(std::istream &is)
146 u16 count = readU16((u8*)buf);
147 for(u16 i=0; i<count; i++)
150 s_obj.deSerialize(is, version);
151 m_stored.push_back(s_obj);
156 NOTE: When an object is transformed to active, it is removed
157 from m_stored and inserted to m_active.
158 The caller directly manipulates these containers.
160 core::list<StaticObject> m_stored;
161 core::map<u16, StaticObject> m_active;