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"
22 #include "server/serveractiveobject.h"
24 StaticObject::StaticObject(const ServerActiveObject
*s_obj
, const v3f
&pos_
):
25 type(s_obj
->getType()),
28 s_obj
->getStaticData(&data
);
31 void StaticObject::serialize(std::ostream
&os
)
36 writeV3F1000(os
, pos
);
38 os
<<serializeString16(data
);
40 void StaticObject::deSerialize(std::istream
&is
, u8 version
)
45 pos
= readV3F1000(is
);
47 data
= deSerializeString16(is
);
50 void StaticObjectList::serialize(std::ostream
&os
)
57 size_t count
= m_stored
.size() + m_active
.size();
58 // Make sure it fits into u16, else it would get truncated and cause e.g.
59 // issue #2610 (Invalid block data in database: unsupported NameIdMapping version).
60 if (count
> U16_MAX
) {
61 errorstream
<< "StaticObjectList::serialize(): "
62 << "too many objects (" << count
<< ") in list, "
63 << "not writing them to disk." << std::endl
;
64 writeU16(os
, 0); // count = 0
69 for (StaticObject
&s_obj
: m_stored
) {
73 for (auto &i
: m_active
) {
74 StaticObject s_obj
= i
.second
;
78 void StaticObjectList::deSerialize(std::istream
&is
)
80 if (m_active
.size()) {
81 errorstream
<< "StaticObjectList::deSerialize(): "
82 << "deserializing objects while " << m_active
.size()
83 << " active objects already exist (not cleared). "
84 << m_stored
.size() << " stored objects _were_ cleared"
90 u8 version
= readU8(is
);
92 u16 count
= readU16(is
);
93 for(u16 i
= 0; i
< count
; i
++) {
95 s_obj
.deSerialize(is
, version
);
96 m_stored
.push_back(s_obj
);