implement priority item updates, seems to work correctly after heavy testing in random servers
This commit is contained in:
@@ -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,41 +535,59 @@ 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)
|
||||||
{
|
{
|
||||||
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);
|
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user