]> git.lizzy.rs Git - minetest.git/blob - src/staticobject.cpp
Small fixes of minetest.has_feature
[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::vector<StaticObject>::iterator
51                         i = m_stored.begin();
52                         i != m_stored.end(); ++i) {
53                 StaticObject &s_obj = *i;
54                 s_obj.serialize(os);
55         }
56         for(std::map<u16, StaticObject>::iterator
57                         i = m_active.begin();
58                         i != m_active.end(); ++i)
59         {
60                 StaticObject s_obj = i->second;
61                 s_obj.serialize(os);
62         }
63 }
64 void StaticObjectList::deSerialize(std::istream &is)
65 {
66         // version
67         u8 version = readU8(is);
68         // count
69         u16 count = readU16(is);
70         for(u16 i = 0; i < count; i++) {
71                 StaticObject s_obj;
72                 s_obj.deSerialize(is, version);
73                 m_stored.push_back(s_obj);
74         }
75 }
76