3 Copyright (C) 2010-2013 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 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.
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.
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.
20 #include "staticobject.h"
21 #include "util/serialize.h"
23 void StaticObject::serialize(std::ostream &os)
30 writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000));
33 os<<serializeString(data);
35 void StaticObject::deSerialize(std::istream &is, u8 version)
43 v3s32 intp = readV3S32((u8*)buf);
44 pos.X = (f32)intp.X/1000;
45 pos.Y = (f32)intp.Y/1000;
46 pos.Z = (f32)intp.Z/1000;
48 data = deSerializeString(is);
51 void StaticObjectList::serialize(std::ostream &os)
58 u16 count = m_stored.size() + m_active.size();
59 writeU16((u8*)buf, count);
61 for(std::list<StaticObject>::iterator
63 i != m_stored.end(); ++i)
65 StaticObject &s_obj = *i;
68 for(std::map<u16, StaticObject>::iterator
70 i != m_active.end(); ++i)
72 StaticObject s_obj = i->second;
76 void StaticObjectList::deSerialize(std::istream &is)
84 u16 count = readU16((u8*)buf);
85 for(u16 i=0; i<count; i++)
88 s_obj.deSerialize(is, version);
89 m_stored.push_back(s_obj);