Fix Map Entity Updates

This commit is contained in:
Evil Factory
2022-02-24 16:06:08 -03:00
parent 147307c891
commit f31142b754
2 changed files with 48 additions and 17 deletions
@@ -134,7 +134,18 @@ namespace Barotrauma
public bool disableDisconnectCharacter = false; public bool disableDisconnectCharacter = false;
public bool enableControlHusk = false; public bool enableControlHusk = false;
public int mapEntityUpdateRate = 1; public int mapEntityUpdateInterval
{
get { return MapEntity.MapEntityUpdateInterval; }
set { MapEntity.MapEntityUpdateInterval = value; }
}
public int gapUpdateInterval
{
get { return MapEntity.GapUpdateInterval; }
set { MapEntity.GapUpdateInterval = value; }
}
public HashSet<Item> updatePriorityItems = new HashSet<Item>(); public HashSet<Item> updatePriorityItems = new HashSet<Item>();
public void AddPriorityItem(Item item) public void AddPriorityItem(Item item)
@@ -19,8 +19,9 @@ namespace Barotrauma
protected List<ushort> linkedToID; protected List<ushort> linkedToID;
public List<ushort> unresolvedLinkedToID; public List<ushort> unresolvedLinkedToID;
private const int GapUpdateInterval = 4; public static int MapEntityUpdateInterval = 1;
private static int gapUpdateTimer; public static int GapUpdateInterval = 4;
private static int mapEntityUpdateTick;
/// <summary> /// <summary>
/// List of upgrades this item has /// List of upgrades this item has
@@ -560,42 +561,61 @@ namespace Barotrauma
/// </summary> /// </summary>
public static void UpdateAll(float deltaTime, Camera cam) public static void UpdateAll(float deltaTime, Camera cam)
{ {
foreach (Hull hull in Hull.hullList) mapEntityUpdateTick++;
if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
{ {
hull.Update(deltaTime, cam);
} foreach (Hull hull in Hull.hullList)
{
hull.Update(deltaTime * MapEntityUpdateInterval, cam);
}
#if CLIENT #if CLIENT
Hull.UpdateCheats(deltaTime, cam); Hull.UpdateCheats(deltaTime * MapEntityUpdateInterval, cam);
#endif #endif
foreach (Structure structure in Structure.WallList) foreach (Structure structure in Structure.WallList)
{ {
structure.Update(deltaTime, cam); structure.Update(deltaTime * MapEntityUpdateInterval, cam);
}
} }
//update gaps in random order, because otherwise in rooms with multiple gaps //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, //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 //which may lead to weird behavior like water draining down only through
//one gap in a room even if there are several //one gap in a room even if there are several
gapUpdateTimer++; if (mapEntityUpdateTick % GapUpdateInterval == 0)
if (gapUpdateTimer >= GapUpdateInterval)
{ {
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 * GapUpdateInterval, cam); gap.Update(deltaTime * GapUpdateInterval, cam);
} }
gapUpdateTimer = 0;
} }
Powered.UpdatePower(deltaTime); if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
foreach (Item item in Item.ItemList)
{ {
Powered.UpdatePower(deltaTime * MapEntityUpdateInterval);
foreach (Item item in Item.ItemList)
{
if (GameMain.Lua.game.updatePriorityItems.Contains(item)) continue;
item.Update(deltaTime * MapEntityUpdateInterval, cam);
}
}
foreach (var item in GameMain.Lua.game.updatePriorityItems)
{
if (item.Removed) continue;
item.Update(deltaTime, cam); item.Update(deltaTime, cam);
} }
UpdateAllProjSpecific(deltaTime); if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
{
Spawner?.Update(); UpdateAllProjSpecific(deltaTime * MapEntityUpdateInterval);
Spawner?.Update();
}
} }
static partial void UpdateAllProjSpecific(float deltaTime); static partial void UpdateAllProjSpecific(float deltaTime);