periodic rebuilds

This commit is contained in:
Robin Rolf 2024-01-30 03:22:01 +01:00
parent a14d094bc5
commit d09f5ef008
2 changed files with 13 additions and 1 deletions

View File

@ -13,6 +13,10 @@ public class FastSpatialInterestManagement : InterestManagementBase
[Tooltip("The maximum range that objects will be visible at.")]
public int visRange = 30;
[Tooltip("Rebuild all every 'rebuildInterval' seconds.")]
public float rebuildInterval = 1;
double lastRebuildTime;
// we use a 9 neighbour grid.
// so we always see in a distance of 2 grids.
// for example, our own grid and then one on top / below / left / right.
@ -62,7 +66,14 @@ internal void LateUpdate()
// only on server
if (!NetworkServer.active) return;
// rebuild all spawned entities' observers every 'interval'
// this will call OnRebuildObservers which then returns the
// observers at grid[position] for each entity.
if (NetworkTime.localTime >= lastRebuildTime + rebuildInterval)
{
RebuildAll();
lastRebuildTime = NetworkTime.localTime;
}
}
// When a new identity is spawned

View File

@ -41,6 +41,7 @@ public override void SetUp()
aoi = holder.AddComponent<FastSpatialInterestManagement>();
aoi.visRange = 10;
aoi.rebuildInterval = -1; // rebuild every call :)
// setup server aoi since InterestManagement Awake isn't called
NetworkServer.aoi = aoi;
}