Ticket #3834: smallerOOSlog.diff
File smallerOOSlog.diff, 5.8 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/AIInterface.js
48 48 continue; 49 49 if (typeof this[key] == "function") 50 50 continue; 51 if (key == "templates") 52 continue; 51 53 state[key] = this[key]; 52 54 } 53 55 return state; -
source/simulation2/components/CCmpRangeManager.cpp
415 415 416 416 serialize.Bool("global visibility update", m_GlobalVisibilityUpdate); 417 417 SerializeVector<SerializeU8_Unbounded>()(serialize, "global player visibility update", m_GlobalPlayerVisibilityUpdate); 418 Serialize Vector<SerializeU16_Unbounded>()(serialize, "dirty visibility", m_DirtyVisibility);418 SerializeRepetitiveVector<SerializeU16_Unbounded>()(serialize, "dirty visibility", m_DirtyVisibility); 419 419 SerializeVector<SerializeU32_Unbounded>()(serialize, "modified entities", m_ModifiedEntities); 420 420 421 421 // We don't serialize m_Subdivision, m_LosPlayerCounts or m_LosTiles … … 422 422 // since they can be recomputed from the entity data when deserializing; 423 423 // m_LosState must be serialized since it depends on the history of exploration 424 424 425 Serialize Vector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState);425 SerializeRepetitiveVector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState); 426 426 SerializeVector<SerializeU32_Unbounded>()(serialize, "shared los masks", m_SharedLosMasks); 427 427 SerializeVector<SerializeU16_Unbounded>()(serialize, "shared dirty visibility masks", m_SharedDirtyVisibilityMasks); 428 428 } -
source/simulation2/components/CCmpTemplateManager.cpp
68 68 } 69 69 serialize.NumberU32_Unbounded("num entities", (u32)count); 70 70 71 for (std::map<entity_id_t, std::string>::const_iterator it = m_LatestTemplates.begin(); it != m_LatestTemplates.end(); ++it) 71 count = 1; 72 u32 prevId = m_LatestTemplates.begin()->first; 73 CStr prevTemplate = m_LatestTemplates.begin()->second; 74 for (std::map<entity_id_t, std::string>::const_iterator it = ++m_LatestTemplates.begin(); it != m_LatestTemplates.end(); ++it) 72 75 { 73 76 if (ENTITY_IS_LOCAL(it->first)) 74 77 continue; 75 serialize.NumberU32_Unbounded("id", it->first); 76 serialize.StringASCII("template", it->second, 0, 256); 78 if (prevId + 1 == it->first && prevTemplate == it->second) 79 { 80 count++; 81 prevId = it->first; 82 continue; 83 } 84 serialize.NumberU32_Unbounded("id", prevId - count + 1); 85 serialize.NumberU32_Unbounded("#", count); 86 serialize.StringASCII("template", prevTemplate, 0, 256); 87 prevId = it->first; 88 prevTemplate = it->second; 89 count = 1; 77 90 } 78 // TODO: maybe we should do some kind of interning thing instead of printing so many strings? 79 80 // TODO: will need to serialize techs too, because we need to be giving out 81 // template data before other components (like the tech components) have been deserialized 91 serialize.NumberU32_Unbounded("id", prevId + 1 - count); 92 serialize.NumberU32_Unbounded("#", count); 93 serialize.StringASCII("template", prevTemplate, 0, 256); 82 94 } 83 95 84 96 virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) … … 87 99 88 100 u32 numEntities; 89 101 deserialize.NumberU32_Unbounded("num entities", numEntities); 90 for (u32 i = 0; i < numEntities; ++i)102 for (u32 i = 0; i < numEntities;) 91 103 { 92 104 entity_id_t ent; 105 u32 count; 93 106 std::string templateName; 94 107 deserialize.NumberU32_Unbounded("id", ent); 108 deserialize.NumberU32_Unbounded("#", count); 95 109 deserialize.StringASCII("template", templateName, 0, 256); 96 m_LatestTemplates[ent] = templateName; 110 i += count; 111 for (; count > 0; --count) 112 m_LatestTemplates[ent++] = templateName; 97 113 } 98 114 } 99 115 -
source/simulation2/serialization/SerializeTemplates.h
24 24 */ 25 25 26 26 #include "simulation2/components/ICmpPathfinder.h" 27 #include <type_traits> 27 28 28 29 template<typename ELEM> 29 30 struct SerializeVector … … 53 54 } 54 55 }; 55 56 57 template<typename ELEM> 58 struct SerializeRepetitiveVector 59 { 60 template<typename T> 61 void operator()(ISerializer& serialize, const char* name, std::vector<T>& value) 62 { 63 size_t len = value.size(); 64 serialize.NumberU32_Unbounded("length", (u32)len); 65 if (len == 0) 66 return; 67 u32 count = 1; 68 T prevVal = value[0]; 69 for (size_t i = 1; i < len; ++i) 70 { 71 if (prevVal == value[i]) 72 { 73 count++; 74 continue; 75 } 76 serialize.NumberU32_Unbounded("#", count); 77 ELEM()(serialize, name, prevVal); 78 count = 1; 79 prevVal = value[i]; 80 } 81 serialize.NumberU32_Unbounded("#", count); 82 ELEM()(serialize, name, prevVal); 83 } 84 85 template<typename T> 86 void operator()(IDeserializer& deserialize, const char* name, std::vector<T>& value) 87 { 88 value.clear(); 89 u32 len; 90 deserialize.NumberU32_Unbounded("length", len); 91 value.reserve(len); // TODO: watch out for out-of-memory 92 for (size_t i = 0; i < len;) 93 { 94 u32 count; 95 deserialize.NumberU32_Unbounded("#", count); 96 T el; 97 ELEM()(deserialize, name, el); 98 i += count; 99 for (; count > 0; --count) 100 value.push_back(el); 101 } 102 } 103 }; 104 56 105 template<typename KS, typename VS> 57 106 struct SerializeMap 58 107 {