diff --git a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs index 73606eecb..f62e3ab48 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Lua/LuaClasses.cs @@ -117,6 +117,22 @@ namespace Barotrauma public bool enableControlHusk = false; public int mapEntityUpdateRate = 1; + public HashSet updatePriorityItems = new HashSet(); + + public void AddPriorityItem(Item item) + { + updatePriorityItems.Add(item); + } + + public void RemovePriorityItem(Item item) + { + updatePriorityItems.Remove(item); + } + + public void ClearPriorityItem() + { + updatePriorityItems.Clear(); + } public bool RoundStarted { diff --git a/Barotrauma/BarotraumaShared/SharedSource/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/SharedSource/Map/MapEntity.cs index c53c98b81..8134430b4 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Map/MapEntity.cs @@ -535,41 +535,59 @@ namespace Barotrauma linkedTo.Clear(); } } - + static int tick = 0; /// /// Call Update() on every object in Entity.list /// public static void UpdateAll(float deltaTime, Camera cam) { - foreach (Hull hull in Hull.hullList) + tick++; + + if (tick % GameMain.Lua.game.mapEntityUpdateRate == 0) { - hull.Update(deltaTime, cam); + + foreach (Hull hull in Hull.hullList) + { + hull.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam); + } + + foreach (Structure structure in Structure.WallList) + { + structure.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam); + } + + + //update gaps in random order, because otherwise in rooms with multiple gaps + //the water/air will always tend to flow through the first gap in the list, + //which may lead to weird behavior like water draining down only through + //one gap in a room even if there are several + foreach (Gap gap in Gap.GapList.OrderBy(g => Rand.Int(int.MaxValue))) + { + gap.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam); + } + + Powered.UpdatePower(deltaTime * GameMain.Lua.game.mapEntityUpdateRate); + foreach (Item item in Item.ItemList) + { + if (GameMain.Lua.game.updatePriorityItems.Contains(item)) continue; + + item.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam); + } } - foreach (Structure structure in Structure.WallList) + foreach (var item in GameMain.Lua.game.updatePriorityItems) { - structure.Update(deltaTime, cam); - } + if (item.Removed) continue; - - //update gaps in random order, because otherwise in rooms with multiple gaps - //the water/air will always tend to flow through the first gap in the list, - //which may lead to weird behavior like water draining down only through - //one gap in a room even if there are several - foreach (Gap gap in Gap.GapList.OrderBy(g => Rand.Int(int.MaxValue))) - { - gap.Update(deltaTime, cam); - } - - Powered.UpdatePower(deltaTime); - foreach (Item item in Item.ItemList) - { 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); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs b/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs index 231fd8081..77bdc67bc 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Screens/GameScreen.cs @@ -83,7 +83,6 @@ namespace Barotrauma GUI.ClearMessages(); #endif } - int step = 0; /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. @@ -260,15 +259,11 @@ namespace Barotrauma } } - step++; - if (step % GameMain.Lua.game.mapEntityUpdateRate == 0) - { #if CLIENT - MapEntity.UpdateAll((float)deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam); + MapEntity.UpdateAll((float)deltaTime, cam); #elif SERVER - MapEntity.UpdateAll((float)deltaTime * GameMain.Lua.game.mapEntityUpdateRate, Camera.Instance); + MapEntity.UpdateAll((float)deltaTime, Camera.Instance); #endif - } #if CLIENT sw.Stop();