implement priority item updates, seems to work correctly after heavy testing in random servers

This commit is contained in:
Evil Factory
2022-01-02 18:57:35 -03:00
parent afd58681d7
commit fcd0b2cc6d
3 changed files with 57 additions and 28 deletions
@@ -117,6 +117,22 @@ namespace Barotrauma
public bool enableControlHusk = false; public bool enableControlHusk = false;
public int mapEntityUpdateRate = 1; public int mapEntityUpdateRate = 1;
public HashSet<Item> updatePriorityItems = new HashSet<Item>();
public void AddPriorityItem(Item item)
{
updatePriorityItems.Add(item);
}
public void RemovePriorityItem(Item item)
{
updatePriorityItems.Remove(item);
}
public void ClearPriorityItem()
{
updatePriorityItems.Clear();
}
public bool RoundStarted public bool RoundStarted
{ {
@@ -535,20 +535,25 @@ namespace Barotrauma
linkedTo.Clear(); linkedTo.Clear();
} }
} }
static int tick = 0;
/// <summary> /// <summary>
/// Call Update() on every object in Entity.list /// Call Update() on every object in Entity.list
/// </summary> /// </summary>
public static void UpdateAll(float deltaTime, Camera cam) public static void UpdateAll(float deltaTime, Camera cam)
{ {
tick++;
if (tick % GameMain.Lua.game.mapEntityUpdateRate == 0)
{
foreach (Hull hull in Hull.hullList) foreach (Hull hull in Hull.hullList)
{ {
hull.Update(deltaTime, cam); hull.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
} }
foreach (Structure structure in Structure.WallList) foreach (Structure structure in Structure.WallList)
{ {
structure.Update(deltaTime, cam); structure.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
} }
@@ -558,19 +563,32 @@ namespace Barotrauma
//one gap in a room even if there are several //one gap in a room even if there are several
foreach (Gap gap in Gap.GapList.OrderBy(g => Rand.Int(int.MaxValue))) foreach (Gap gap in Gap.GapList.OrderBy(g => Rand.Int(int.MaxValue)))
{ {
gap.Update(deltaTime, cam); gap.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
} }
Powered.UpdatePower(deltaTime); Powered.UpdatePower(deltaTime * GameMain.Lua.game.mapEntityUpdateRate);
foreach (Item item in Item.ItemList) foreach (Item item in Item.ItemList)
{ {
if (GameMain.Lua.game.updatePriorityItems.Contains(item)) continue;
item.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
}
}
foreach (var item in GameMain.Lua.game.updatePriorityItems)
{
if (item.Removed) continue;
item.Update(deltaTime, cam); item.Update(deltaTime, cam);
} }
UpdateAllProjSpecific(deltaTime); if (tick % GameMain.Lua.game.mapEntityUpdateRate == 0)
{
UpdateAllProjSpecific(deltaTime * GameMain.Lua.game.mapEntityUpdateRate);
Spawner?.Update(); Spawner?.Update();
} }
}
static partial void UpdateAllProjSpecific(float deltaTime); static partial void UpdateAllProjSpecific(float deltaTime);
@@ -83,7 +83,6 @@ namespace Barotrauma
GUI.ClearMessages(); GUI.ClearMessages();
#endif #endif
} }
int step = 0;
/// <summary> /// <summary>
/// Allows the game to run logic such as updating the world, /// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio. /// checking for collisions, gathering input, and playing audio.
@@ -260,15 +259,11 @@ namespace Barotrauma
} }
} }
step++;
if (step % GameMain.Lua.game.mapEntityUpdateRate == 0)
{
#if CLIENT #if CLIENT
MapEntity.UpdateAll((float)deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam); MapEntity.UpdateAll((float)deltaTime, cam);
#elif SERVER #elif SERVER
MapEntity.UpdateAll((float)deltaTime * GameMain.Lua.game.mapEntityUpdateRate, Camera.Instance); MapEntity.UpdateAll((float)deltaTime, Camera.Instance);
#endif #endif
}
#if CLIENT #if CLIENT
sw.Stop(); sw.Stop();