]> git.lizzy.rs Git - dragonfireclient.git/blob - src/staticobject.cpp
Fix ambient occlusion and dark lines at mapblock borders
[dragonfireclient.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 #include "log.h"
23
24 void StaticObject::serialize(std::ostream &os)
25 {
26         // type
27         writeU8(os, type);
28         // pos
29         writeV3F1000(os, pos);
30         // data
31         os<<serializeString(data);
32 }
33 void StaticObject::deSerialize(std::istream &is, u8 version)
34 {
35         // type
36         type = readU8(is);
37         // pos
38         pos = readV3F1000(is);
39         // data
40         data = deSerializeString(is);
41 }
42
43 void StaticObjectList::serialize(std::ostream &os)
44 {
45         // version
46         u8 version = 0;
47         writeU8(os, version);
48
49         // count
50         size_t count = m_stored.size() + m_active.size();
51         // Make sure it fits into u16, else it would get truncated and cause e.g.
52         // issue #2610 (Invalid block data in database: unsupported NameIdMapping version).
53         if (count > U16_MAX) {
54                 errorstream << "StaticObjectList::serialize(): "
55                         << "too many objects (" << count << ") in list, "
56                         << "not writing them to disk." << std::endl;
57                 writeU16(os, 0);  // count = 0
58                 return;
59         }
60         writeU16(os, count);
61
62         for (StaticObject &s_obj : m_stored) {
63                 s_obj.serialize(os);
64         }
65
66         for (auto &i : m_active) {
67                 StaticObject s_obj = i.second;
68                 s_obj.serialize(os);
69         }
70 }
71 void StaticObjectList::deSerialize(std::istream &is)
72 {
73         // version
74         u8 version = readU8(is);
75         // count
76         u16 count = readU16(is);
77         for(u16 i = 0; i < count; i++) {
78                 StaticObject s_obj;
79                 s_obj.deSerialize(is, version);
80                 m_stored.push_back(s_obj);
81         }
82 }
83