]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/itemdef.cpp
SQLite rollback
[dragonfireclient.git] / src / itemdef.cpp
index 4ac23d0fc86e056caa0d3b7daf19891fb1e69e6f..d34d68582a77004b21f07725f6786f44e115e59e 100644 (file)
@@ -119,8 +119,10 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
 {
        if(protocol_version <= 17)
                writeU8(os, 1); // version
-       else
+       else if(protocol_version <= 20)
                writeU8(os, 2); // version
+       else
+               writeU8(os, 3); // version
        writeU8(os, type);
        os<<serializeString(name);
        os<<serializeString(description);
@@ -148,6 +150,8 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
                //serializeSimpleSoundSpec(sound_place, os);
                os<<serializeString(sound_place.name);
                writeF1000(os, sound_place.gain);
+       }
+       if(protocol_version > 20){
                writeF1000(os, range);
        }
 }
@@ -159,7 +163,7 @@ void ItemDefinition::deSerialize(std::istream &is)
 
        // Deserialize
        int version = readU8(is);
-       if(version != 1 && version != 2)
+       if(version < 1 || version > 3)
                throw SerializationError("unsupported ItemDefinition version");
        type = (enum ItemType)readU8(is);
        name = deSerializeString(is);
@@ -192,16 +196,18 @@ void ItemDefinition::deSerialize(std::istream &is)
                // Set the old default sound
                sound_place.name = "default_place_node";
                sound_place.gain = 0.5;
-       } else if(version == 2) {
+       } else if(version >= 2) {
                node_placement_prediction = deSerializeString(is);
                //deserializeSimpleSoundSpec(sound_place, is);
                sound_place.name = deSerializeString(is);
                sound_place.gain = readF1000(is);
        }
+       if(version == 3) {
+               range = readF1000(is);
+       }
        // If you add anything here, insert it primarily inside the try-catch
        // block to not need to increase the version.
        try{
-               range = readF1000(is);
        }catch(SerializationError &e) {};
 }
 
@@ -471,21 +477,24 @@ class CItemDefManager: public IWritableItemDefManager
                else
                {
                        // We're gonna ask the result to be put into here
-                       ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
+                       static ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
+
                        // Throw a request in
                        m_get_clientcached_queue.add(name, 0, 0, &result_queue);
                        try{
-                               // Wait result for a second
-                               GetResult<std::string, ClientCached*, u8, u8>
+                               while(true) {
+                                       // Wait result for a second
+                                       GetResult<std::string, ClientCached*, u8, u8>
                                                result = result_queue.pop_front(1000);
-                               // Check that at least something worked OK
-                               assert(result.key == name);
-                               // Return it
-                               return result.item;
+
+                                       if (result.key == name) {
+                                               return result.item;
+                                       }
+                               }
                        }
                        catch(ItemNotFoundException &e)
                        {
-                               errorstream<<"Waiting for clientcached timed out."<<std::endl;
+                               errorstream<<"Waiting for clientcached " << name << " timed out."<<std::endl;
                                return &m_dummy_clientcached;
                        }
                }
@@ -554,7 +563,7 @@ class CItemDefManager: public IWritableItemDefManager
                // Ensure that the "" item (the hand) always has ToolCapabilities
                if(def.name == "")
                        assert(def.tool_capabilities != NULL);
-               
+
                if(m_item_definitions.count(def.name) == 0)
                        m_item_definitions[def.name] = new ItemDefinition(def);
                else
@@ -632,12 +641,9 @@ class CItemDefManager: public IWritableItemDefManager
                {
                        GetRequest<std::string, ClientCached*, u8, u8>
                                        request = m_get_clientcached_queue.pop();
-                       GetResult<std::string, ClientCached*, u8, u8>
-                                       result;
-                       result.key = request.key;
-                       result.callers = request.callers;
-                       result.item = createClientCachedDirect(request.key, gamedef);
-                       request.dest->push_back(result);
+
+                       m_get_clientcached_queue.pushResult(request,
+                                       createClientCachedDirect(request.key, gamedef));
                }
 #endif
        }