Ticket #3834: smallerOOSlog.diff

File smallerOOSlog.diff, 5.8 KB (added by sanderd17, 7 years ago)
  • binaries/data/mods/public/simulation/components/AIInterface.js

     
    4848            continue;
    4949        if (typeof this[key] == "function")
    5050            continue;
     51        if (key == "templates")
     52            continue;
    5153        state[key] = this[key];
    5254    }
    5355    return state;
  • source/simulation2/components/CCmpRangeManager.cpp

     
    415415
    416416        serialize.Bool("global visibility update", m_GlobalVisibilityUpdate);
    417417        SerializeVector<SerializeU8_Unbounded>()(serialize, "global player visibility update", m_GlobalPlayerVisibilityUpdate);
    418         SerializeVector<SerializeU16_Unbounded>()(serialize, "dirty visibility", m_DirtyVisibility);
     418        SerializeRepetitiveVector<SerializeU16_Unbounded>()(serialize, "dirty visibility", m_DirtyVisibility);
    419419        SerializeVector<SerializeU32_Unbounded>()(serialize, "modified entities", m_ModifiedEntities);
    420420
    421421        // We don't serialize m_Subdivision, m_LosPlayerCounts or m_LosTiles
     
    422422        // since they can be recomputed from the entity data when deserializing;
    423423        // m_LosState must be serialized since it depends on the history of exploration
    424424
    425         SerializeVector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState);
     425        SerializeRepetitiveVector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState);
    426426        SerializeVector<SerializeU32_Unbounded>()(serialize, "shared los masks", m_SharedLosMasks);
    427427        SerializeVector<SerializeU16_Unbounded>()(serialize, "shared dirty visibility masks", m_SharedDirtyVisibilityMasks);
    428428    }
  • source/simulation2/components/CCmpTemplateManager.cpp

     
    6868        }
    6969        serialize.NumberU32_Unbounded("num entities", (u32)count);
    7070
    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)
    7275        {
    7376            if (ENTITY_IS_LOCAL(it->first))
    7477                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;
    7790        }
    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);
    8294    }
    8395
    8496    virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize)
     
    8799
    88100        u32 numEntities;
    89101        deserialize.NumberU32_Unbounded("num entities", numEntities);
    90         for (u32 i = 0; i < numEntities; ++i)
     102        for (u32 i = 0; i < numEntities;)
    91103        {
    92104            entity_id_t ent;
     105            u32 count;
    93106            std::string templateName;
    94107            deserialize.NumberU32_Unbounded("id", ent);
     108            deserialize.NumberU32_Unbounded("#", count);
    95109            deserialize.StringASCII("template", templateName, 0, 256);
    96             m_LatestTemplates[ent] = templateName;
     110            i += count;
     111            for (; count > 0; --count)
     112                m_LatestTemplates[ent++] = templateName;   
    97113        }
    98114    }
    99115
  • source/simulation2/serialization/SerializeTemplates.h

     
    2424 */
    2525
    2626#include "simulation2/components/ICmpPathfinder.h"
     27#include <type_traits>
    2728
    2829template<typename ELEM>
    2930struct SerializeVector
     
    5354    }
    5455};
    5556
     57template<typename ELEM>
     58struct 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
    56105template<typename KS, typename VS>
    57106struct SerializeMap
    58107{