X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fstaticobject.cpp;h=d656b62214950c47cb95ab59d7f233a842b77933;hb=d1df09841d0eac7a88f638676b80ec848522cca5;hp=2183f2ffec3845d85871d035f2d70df4517ac958;hpb=bb454b184656735b51fea17a0cb6276514b1c8c1;p=dragonfireclient.git diff --git a/src/staticobject.cpp b/src/staticobject.cpp index 2183f2ffe..d656b6221 100644 --- a/src/staticobject.cpp +++ b/src/staticobject.cpp @@ -1,6 +1,6 @@ /* -Minetest-c55 -Copyright (C) 2010-2012 celeron55, Perttu Ahola +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola 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 @@ -19,71 +19,67 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "staticobject.h" #include "util/serialize.h" +#include "log.h" void StaticObject::serialize(std::ostream &os) { - char buf[12]; // type - buf[0] = type; - os.write(buf, 1); + writeU8(os, type); // pos - writeV3S32((u8*)buf, v3s32(pos.X*1000,pos.Y*1000,pos.Z*1000)); - os.write(buf, 12); + writeV3F1000(os, pos); // data os<::Iterator + size_t count = m_stored.size() + m_active.size(); + // Make sure it fits into u16, else it would get truncated and cause e.g. + // issue #2610 (Invalid block data in database: unsupported NameIdMapping version). + if (count > U16_MAX) { + errorstream << "StaticObjectList::serialize(): " + << "too many objects (" << count << ") in list, " + << "not writing them to disk." << std::endl; + writeU16(os, 0); // count = 0 + return; + } + writeU16(os, count); + + for(std::vector::iterator i = m_stored.begin(); - i != m_stored.end(); i++) - { + i != m_stored.end(); ++i) { StaticObject &s_obj = *i; s_obj.serialize(os); } - for(core::map::Iterator - i = m_active.getIterator(); - i.atEnd()==false; i++) + for(std::map::iterator + i = m_active.begin(); + i != m_active.end(); ++i) { - StaticObject s_obj = i.getNode()->getValue(); + StaticObject s_obj = i->second; s_obj.serialize(os); } } void StaticObjectList::deSerialize(std::istream &is) { - char buf[12]; // version - is.read(buf, 1); - u8 version = buf[0]; + u8 version = readU8(is); // count - is.read(buf, 2); - u16 count = readU16((u8*)buf); - for(u16 i=0; i