2012-11-26 04:18:34 -05:00
|
|
|
/*
|
2013-02-24 12:40:43 -05:00
|
|
|
Minetest
|
2013-02-24 13:38:45 -05:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-11-26 04:18:34 -05:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "staticobject.h"
|
|
|
|
#include "util/serialize.h"
|
|
|
|
|
|
|
|
void StaticObject::serialize(std::ostream &os)
|
|
|
|
{
|
|
|
|
// type
|
2014-11-16 21:52:24 -05:00
|
|
|
writeU8(os, type);
|
2012-11-26 04:18:34 -05:00
|
|
|
// pos
|
2014-11-16 21:52:24 -05:00
|
|
|
writeV3F1000(os, pos);
|
2012-11-26 04:18:34 -05:00
|
|
|
// data
|
|
|
|
os<<serializeString(data);
|
|
|
|
}
|
|
|
|
void StaticObject::deSerialize(std::istream &is, u8 version)
|
|
|
|
{
|
|
|
|
// type
|
2014-11-16 21:52:24 -05:00
|
|
|
type = readU8(is);
|
2012-11-26 04:18:34 -05:00
|
|
|
// pos
|
2014-11-16 21:52:24 -05:00
|
|
|
pos = readV3F1000(is);
|
2012-11-26 04:18:34 -05:00
|
|
|
// data
|
|
|
|
data = deSerializeString(is);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StaticObjectList::serialize(std::ostream &os)
|
|
|
|
{
|
|
|
|
// version
|
2014-11-16 21:52:24 -05:00
|
|
|
u8 version = 0;
|
|
|
|
writeU8(os, version);
|
2012-11-26 04:18:34 -05:00
|
|
|
// count
|
|
|
|
u16 count = m_stored.size() + m_active.size();
|
2014-11-16 21:52:24 -05:00
|
|
|
writeU16(os, count);
|
2015-03-04 11:18:57 -05:00
|
|
|
for(std::vector<StaticObject>::iterator
|
2012-11-26 04:18:34 -05:00
|
|
|
i = m_stored.begin();
|
2015-03-04 11:18:57 -05:00
|
|
|
i != m_stored.end(); ++i) {
|
2012-11-26 04:18:34 -05:00
|
|
|
StaticObject &s_obj = *i;
|
|
|
|
s_obj.serialize(os);
|
|
|
|
}
|
2012-12-20 12:19:49 -05:00
|
|
|
for(std::map<u16, StaticObject>::iterator
|
|
|
|
i = m_active.begin();
|
|
|
|
i != m_active.end(); ++i)
|
2012-11-26 04:18:34 -05:00
|
|
|
{
|
2012-12-20 12:19:49 -05:00
|
|
|
StaticObject s_obj = i->second;
|
2012-11-26 04:18:34 -05:00
|
|
|
s_obj.serialize(os);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void StaticObjectList::deSerialize(std::istream &is)
|
|
|
|
{
|
|
|
|
// version
|
2014-11-16 21:52:24 -05:00
|
|
|
u8 version = readU8(is);
|
2012-11-26 04:18:34 -05:00
|
|
|
// count
|
2014-11-16 21:52:24 -05:00
|
|
|
u16 count = readU16(is);
|
2015-03-04 11:18:57 -05:00
|
|
|
for(u16 i = 0; i < count; i++) {
|
2012-11-26 04:18:34 -05:00
|
|
|
StaticObject s_obj;
|
|
|
|
s_obj.deSerialize(is, version);
|
|
|
|
m_stored.push_back(s_obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|