Ticket #3834: smallerOOSlog.3.diff
File smallerOOSlog.3.diff, 6.3 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
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 21 21 #include "ICmpTemplateManager.h" 22 22 23 23 #include "simulation2/MessageTypes.h" 24 #include "simulation2/serialization/SerializeTemplates.h" 24 25 25 26 #include "ps/TemplateLoader.h" 26 27 … … 58 59 59 60 virtual void Serialize(ISerializer& serialize) 60 61 { 61 s ize_t count = 0;62 std::map<CStr, std::vector<entity_id_t>> templateMap; 62 63 63 for (std::map<entity_id_t, std::string>::const_iterator it = m_LatestTemplates.begin(); it != m_LatestTemplates.end(); ++it) 64 65 for (std::pair<entity_id_t, std::string> templateEnt : m_LatestTemplates) 64 66 { 65 if (ENTITY_IS_LOCAL( it->first))67 if (ENTITY_IS_LOCAL(templateEnt.first)) 66 68 continue; 67 ++count; 69 // subtract the vecor length to get a more repetitive vector 70 size_t s = templateMap[templateEnt.second].size(); 71 templateMap[templateEnt.second].push_back(templateEnt.first - s); 68 72 } 69 serialize.NumberU32_Unbounded("num entities", (u32)count); 70 71 for (std::map<entity_id_t, std::string>::const_iterator it = m_LatestTemplates.begin(); it != m_LatestTemplates.end(); ++it) 72 { 73 if (ENTITY_IS_LOCAL(it->first)) 74 continue; 75 serialize.NumberU32_Unbounded("id", it->first); 76 serialize.StringASCII("template", it->second, 0, 256); 77 } 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 73 SerializeMap<SerializeString, SerializeRepetitiveVector<SerializeU32_Unbounded>>()(serialize, "templates", templateMap); 82 74 } 83 75 84 76 virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) … … 85 77 { 86 78 Init(paramNode); 87 79 88 u32 numEntities; 89 deserialize.NumberU32_Unbounded("num entities", numEntities); 90 for (u32 i = 0; i < numEntities; ++i) 91 { 92 entity_id_t ent; 93 std::string templateName; 94 deserialize.NumberU32_Unbounded("id", ent); 95 deserialize.StringASCII("template", templateName, 0, 256); 96 m_LatestTemplates[ent] = templateName; 97 } 80 std::map<CStr, std::vector<entity_id_t>> templateMap; 81 SerializeMap<SerializeString, SerializeRepetitiveVector<SerializeU32_Unbounded>>()(deserialize, "templates", templateMap); 82 for (std::pair<CStr, std::vector<entity_id_t>> list : templateMap) 83 for (u32 i = 0; i < list.second.size(); i++) 84 m_LatestTemplates[list.second[i] + i] = list.first; 98 85 } 99 86 100 87 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global)) -
source/simulation2/serialization/SerializeTemplates.h
53 53 } 54 54 }; 55 55 56 template<typename ELEM> 57 struct SerializeRepetitiveVector 58 { 59 template<typename T> 60 void operator()(ISerializer& serialize, const char* name, std::vector<T>& value) 61 { 62 size_t len = value.size(); 63 serialize.NumberU32_Unbounded("length", (u32)len); 64 if (len == 0) 65 return; 66 u32 count = 1; 67 T prevVal = value[0]; 68 for (size_t i = 1; i < len; ++i) 69 { 70 if (prevVal == value[i]) 71 { 72 count++; 73 continue; 74 } 75 serialize.NumberU32_Unbounded("#", count); 76 ELEM()(serialize, name, prevVal); 77 count = 1; 78 prevVal = value[i]; 79 } 80 serialize.NumberU32_Unbounded("#", count); 81 ELEM()(serialize, name, prevVal); 82 } 83 84 template<typename T> 85 void operator()(IDeserializer& deserialize, const char* name, std::vector<T>& value) 86 { 87 value.clear(); 88 u32 len; 89 deserialize.NumberU32_Unbounded("length", len); 90 value.reserve(len); // TODO: watch out for out-of-memory 91 for (size_t i = 0; i < len;) 92 { 93 u32 count; 94 deserialize.NumberU32_Unbounded("#", count); 95 T el; 96 ELEM()(deserialize, name, el); 97 i += count; 98 value.insert(value.end(), count, el); 99 } 100 } 101 }; 102 56 103 template<typename KS, typename VS> 57 104 struct SerializeMap 58 105 {