]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/staticobject.cpp
Increase limit for simultaneous blocks sent per client and the meshgen cache.
[dragonfireclient.git] / src / staticobject.cpp
index e226f0b2e681f4dd219649a586b4ec458fafa90a..86e455b9f65093247d5aaf09609733657e6d1db0 100644 (file)
@@ -19,7 +19,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "staticobject.h"
 #include "util/serialize.h"
-#include "log.h"
+#include "server/serveractiveobject.h"
+
+StaticObject::StaticObject(const ServerActiveObject *s_obj, const v3f &pos_):
+       type(s_obj->getType()),
+       pos(pos_)
+{
+       s_obj->getStaticData(&data);
+}
 
 void StaticObject::serialize(std::ostream &os)
 {
@@ -28,7 +35,7 @@ void StaticObject::serialize(std::ostream &os)
        // pos
        writeV3F1000(os, pos);
        // data
-       os<<serializeString(data);
+       os<<serializeString16(data);
 }
 void StaticObject::deSerialize(std::istream &is, u8 version)
 {
@@ -37,7 +44,7 @@ void StaticObject::deSerialize(std::istream &is, u8 version)
        // pos
        pos = readV3F1000(is);
        // data
-       data = deSerializeString(is);
+       data = deSerializeString16(is);
 }
 
 void StaticObjectList::serialize(std::ostream &os)
@@ -50,7 +57,7 @@ void StaticObjectList::serialize(std::ostream &os)
        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)-1) {
+       if (count > U16_MAX) {
                errorstream << "StaticObjectList::serialize(): "
                        << "too many objects (" << count << ") in list, "
                        << "not writing them to disk." << std::endl;
@@ -59,22 +66,26 @@ void StaticObjectList::serialize(std::ostream &os)
        }
        writeU16(os, count);
 
-       for(std::vector<StaticObject>::iterator
-                       i = m_stored.begin();
-                       i != m_stored.end(); ++i) {
-               StaticObject &s_obj = *i;
+       for (StaticObject &s_obj : m_stored) {
                s_obj.serialize(os);
        }
-       for(std::map<u16, StaticObject>::iterator
-                       i = m_active.begin();
-                       i != m_active.end(); ++i)
-       {
-               StaticObject s_obj = i->second;
+
+       for (auto &i : m_active) {
+               StaticObject s_obj = i.second;
                s_obj.serialize(os);
        }
 }
 void StaticObjectList::deSerialize(std::istream &is)
 {
+       if (m_active.size()) {
+               errorstream << "StaticObjectList::deSerialize(): "
+                       << "deserializing objects while " << m_active.size()
+                       << " active objects already exist (not cleared). "
+                       << m_stored.size() << " stored objects _were_ cleared"
+                       << std::endl;
+       }
+       m_stored.clear();
+
        // version
        u8 version = readU8(is);
        // count