perf: InterestManagement update time is now set in RebuildAll instead of Update. Avoids unnecessary updates if someone just called RebuildAll anyway

This commit is contained in:
vis2k 2020-10-08 10:23:34 +02:00
parent 2c41dc0ae5
commit 294c267472

View File

@ -111,19 +111,22 @@ public void RebuildAll()
RebuildObservers(); RebuildObservers();
RemoveOldObservers(); RemoveOldObservers();
AddNewObservers(); AddNewObservers();
// RebuildAll can be called from the outside, so we should set the
// lastUpdateTime in here instead of in Update.
// this way we avoid updating if someone from the outside recently
// did a rebuild anyway (e.g. in OnServerDisconnect).
lastUpdateTime = Time.time;
} }
// update rebuilds every couple of seconds // update rebuilds every couple of seconds
void Update() void Update()
{ {
// only while server is running // only while server is running
if (NetworkServer.active) if (NetworkServer.active &&
{ Time.time >= lastUpdateTime + updateInterval)
if (Time.time >= lastUpdateTime + updateInterval)
{ {
RebuildAll(); RebuildAll();
lastUpdateTime = Time.time;
}
} }
} }
} }