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

View File

@@ -117,6 +117,22 @@ namespace Barotrauma
public bool enableControlHusk = false;
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
{

View File

@@ -535,41 +535,59 @@ namespace Barotrauma
linkedTo.Clear();
}
}
static int tick = 0;
/// <summary>
/// Call Update() on every object in Entity.list
/// </summary>
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);

View File

@@ -83,7 +83,6 @@ namespace Barotrauma
GUI.ClearMessages();
#endif
}
int step = 0;
/// <summary>
/// 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();