Improve performance of full state hash computation, by skipping script components that are known to have no data.

Switch to much quicker (and less comprehensive) per-turn hashing in
multiplayer games.

This was SVN commit r9036.
This commit is contained in:
Ykkrosh
2011-03-05 22:30:32 +00:00
parent 20ebaa5b79
commit 6f9da85d9f
21 changed files with 114 additions and 30 deletions
@@ -100,11 +100,15 @@ bool CComponentManager::DumpDebugState(std::ostream& stream)
return true;
}
bool CComponentManager::ComputeStateHash(std::string& outHash)
bool CComponentManager::ComputeStateHash(std::string& outHash, bool quick)
{
// Hash serialization: this includes the minimal data necessary to detect
// differences in the state, and ignores things like counts and names
// If 'quick' is set, this checks even fewer things, so that it will
// be fast enough to run every turn but will typically detect any
// out-of-syncs fairly soon
CHashSerializer serializer(m_ScriptInterface);
serializer.StringASCII("rng", SerializeRNG(m_RNG), 0, 32);
@@ -116,6 +120,10 @@ bool CComponentManager::ComputeStateHash(std::string& outHash)
if (cit->second.empty())
continue;
// In quick mode, only check unit positions
if (quick && !(cit->first == CID_Position))
continue;
serializer.NumberI32_Unbounded("component type id", cit->first);
std::map<entity_id_t, IComponent*>::const_iterator eit = cit->second.begin();