Ticket #3834: smallerOOSlog.2.diff
File smallerOOSlog.2.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 for (std::pair<entity_id_t, std::string> templateEnt : m_LatestTemplates) 64 65 { 65 if (ENTITY_IS_LOCAL( it->first))66 if (ENTITY_IS_LOCAL(templateEnt.first)) 66 67 continue; 67 ++count;68 templateMap[templateEnt.second].push_back(templateEnt.first); 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 serialize.NumberU32_Unbounded("num templates", (u32)templateMap.size()); 72 for (std::pair<CStr, std::vector<entity_id_t>> list : templateMap) 72 73 { 73 if (ENTITY_IS_LOCAL(it->first)) 74 continue; 75 serialize.NumberU32_Unbounded("id", it->first); 76 serialize.StringASCII("template", it->second, 0, 256); 74 serialize.StringASCII("template", list.first, 0, 256); 75 SerializeVector<SerializeU32_Unbounded>()(serialize, "ids", list.second); 77 76 } 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 out81 // template data before other components (like the tech components) have been deserialized82 77 } 83 78 84 79 virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize) … … 85 80 { 86 81 Init(paramNode); 87 82 88 u32 num Entities;89 deserialize.NumberU32_Unbounded("num entities", num Entities);90 for (u32 i = 0; i < num Entities; ++i)83 u32 numTemplates; 84 deserialize.NumberU32_Unbounded("num entities", numTemplates); 85 for (u32 i = 0; i < numTemplates; ++i) 91 86 { 92 entity_id_t ent;93 87 std::string templateName; 94 deserialize.NumberU32_Unbounded("id", ent);88 std::vector<entity_id_t> ids; 95 89 deserialize.StringASCII("template", templateName, 0, 256); 96 m_LatestTemplates[ent] = templateName; 90 SerializeVector<SerializeU32_Unbounded>()(deserialize, "ids", ids); 91 for (entity_id_t id : ids) 92 m_LatestTemplates[id] = templateName; 97 93 } 98 94 } 99 95 -
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 value.insert(value.end(), count, el); 100 } 101 } 102 }; 103 56 104 template<typename KS, typename VS> 57 105 struct SerializeMap 58 106 {