diff options
Diffstat (limited to 'src/itemdef.cpp')
-rw-r--r-- | src/itemdef.cpp | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 5fd27fca3..72ce0e654 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -75,6 +75,7 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def) } groups = def.groups; node_placement_prediction = def.node_placement_prediction; + sound_place = def.sound_place; return *this; } @@ -107,13 +108,17 @@ void ItemDefinition::reset() tool_capabilities = NULL; } groups.clear(); + sound_place = SimpleSoundSpec(); node_placement_prediction = ""; } -void ItemDefinition::serialize(std::ostream &os) const +void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const { - writeU8(os, 1); // version + if(protocol_version <= 17) + writeU8(os, 1); // version + else + writeU8(os, 2); // version writeU8(os, type); os<<serializeString(name); os<<serializeString(description); @@ -126,7 +131,7 @@ void ItemDefinition::serialize(std::ostream &os) const std::string tool_capabilities_s = ""; if(tool_capabilities){ std::ostringstream tmp_os(std::ios::binary); - tool_capabilities->serialize(tmp_os); + tool_capabilities->serialize(tmp_os, protocol_version); tool_capabilities_s = tmp_os.str(); } os<<serializeString(tool_capabilities_s); @@ -137,6 +142,11 @@ void ItemDefinition::serialize(std::ostream &os) const writeS16(os, i->second); } os<<serializeString(node_placement_prediction); + if(protocol_version > 17){ + //serializeSimpleSoundSpec(sound_place, os); + os<<serializeString(sound_place.name); + writeF1000(os, sound_place.gain); + } } void ItemDefinition::deSerialize(std::istream &is) @@ -146,7 +156,7 @@ void ItemDefinition::deSerialize(std::istream &is) // Deserialize int version = readU8(is); - if(version != 1) + if(version != 1 && version != 2) throw SerializationError("unsupported ItemDefinition version"); type = (enum ItemType)readU8(is); name = deSerializeString(is); @@ -171,10 +181,24 @@ void ItemDefinition::deSerialize(std::istream &is) int value = readS16(is); groups[name] = value; } + if(version == 1){ + // We cant be sure that node_placement_prediction is send in version 1 + try{ + node_placement_prediction = deSerializeString(is); + }catch(SerializationError &e) {}; + // Set the old default sound + sound_place.name = "default_place_node"; + sound_place.gain = 0.5; + } else if(version == 2) { + node_placement_prediction = deSerializeString(is); + //deserializeSimpleSoundSpec(sound_place, is); + sound_place.name = deSerializeString(is); + sound_place.gain = readF1000(is); + } // If you add anything here, insert it primarily inside the try-catch // block to not need to increase the version. try{ - node_placement_prediction = deSerializeString(is); + }catch(SerializationError &e) {}; } @@ -211,8 +235,8 @@ public: virtual ~CItemDefManager() { #ifndef SERVER - const core::list<ClientCached*> &values = m_clientcached.getValues(); - for(core::list<ClientCached*>::ConstIterator + const std::list<ClientCached*> &values = m_clientcached.getValues(); + for(std::list<ClientCached*>::const_iterator i = values.begin(); i != values.end(); ++i) { ClientCached *cc = *i; @@ -547,7 +571,7 @@ public: m_aliases[name] = convert_to; } } - void serialize(std::ostream &os) + void serialize(std::ostream &os, u16 protocol_version) { writeU8(os, 0); // version u16 count = m_item_definitions.size(); @@ -559,7 +583,7 @@ public: ItemDefinition *def = i->second; // Serialize ItemDefinition and write wrapped in a string std::ostringstream tmp_os(std::ios::binary); - def->serialize(tmp_os); + def->serialize(tmp_os, protocol_version); os<<serializeString(tmp_os.str()); } writeU16(os, m_aliases.size()); @@ -599,7 +623,7 @@ public: void processQueue(IGameDef *gamedef) { #ifndef SERVER - while(m_get_clientcached_queue.size() > 0) + while(!m_get_clientcached_queue.empty()) { GetRequest<std::string, ClientCached*, u8, u8> request = m_get_clientcached_queue.pop(); |