]> git.lizzy.rs Git - minetest.git/blob - src/staticobject.cpp
Typo fix in networkprotocol.h
[minetest.git] / src / staticobject.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 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 #include "staticobject.h"
21 #include "util/serialize.h"
22
23 void StaticObject::serialize(std::ostream &os)
24 {
25         // type
26         writeU8(os, type);
27         // pos
28         writeV3F1000(os, pos);
29         // data
30         os<<serializeString(data);
31 }
32 void StaticObject::deSerialize(std::istream &is, u8 version)
33 {
34         // type
35         type = readU8(is);
36         // pos
37         pos = readV3F1000(is);
38         // data
39         data = deSerializeString(is);
40 }
41
42 void StaticObjectList::serialize(std::ostream &os)
43 {
44         // version
45         u8 version = 0;
46         writeU8(os, version);
47         // count
48         u16 count = m_stored.size() + m_active.size();
49         writeU16(os, count);
50         for(std::list<StaticObject>::iterator
51                         i = m_stored.begin();
52                         i != m_stored.end(); ++i)
53         {
54                 StaticObject &s_obj = *i;
55                 s_obj.serialize(os);
56         }
57         for(std::map<u16, StaticObject>::iterator
58                         i = m_active.begin();
59                         i != m_active.end(); ++i)
60         {
61                 StaticObject s_obj = i->second;
62                 s_obj.serialize(os);
63         }
64 }
65 void StaticObjectList::deSerialize(std::istream &is)
66 {
67         // version
68         u8 version = readU8(is);
69         // count
70         u16 count = readU16(is);
71         for(u16 i=0; i<count; i++)
72         {
73                 StaticObject s_obj;
74                 s_obj.deSerialize(is, version);
75                 m_stored.push_back(s_obj);
76         }
77 }
78