mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:04:06 +00:00
Iterate the component map only once on serialization
This commit is contained in:
committed by
wraitii
parent
ea34960249
commit
9eccf1f27d
@@ -97,6 +97,7 @@ bool CComponentManager::DumpDebugState(std::ostream& stream, bool includeDebugIn
|
||||
|
||||
bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) const
|
||||
{
|
||||
PROFILE2("ComputeStateHash");
|
||||
// Hash serialization: this includes the minimal data necessary to detect
|
||||
// differences in the state, and ignores things like counts and names
|
||||
|
||||
@@ -117,27 +118,17 @@ bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick) const
|
||||
continue;
|
||||
|
||||
// Only emit component types if they have a component that will be serialized
|
||||
bool needsSerialization = false;
|
||||
for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
|
||||
{
|
||||
// Don't serialize local entities
|
||||
if (ENTITY_IS_LOCAL(eit->first))
|
||||
continue;
|
||||
|
||||
needsSerialization = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!needsSerialization)
|
||||
continue;
|
||||
|
||||
serializer.NumberI32_Unbounded("component type id", cit->first);
|
||||
|
||||
bool hasEmittedComponent = false;
|
||||
for (std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin(); eit != cit->second.end(); ++eit)
|
||||
{
|
||||
// Don't serialize local entities
|
||||
if (ENTITY_IS_LOCAL(eit->first))
|
||||
continue;
|
||||
if (!hasEmittedComponent)
|
||||
{
|
||||
serializer.NumberI32_Unbounded("component type id", cit->first);
|
||||
hasEmittedComponent = true;
|
||||
}
|
||||
|
||||
serializer.NumberU32_Unbounded("entity id", eit->first);
|
||||
eit->second->Serialize(serializer);
|
||||
|
||||
Reference in New Issue
Block a user