Moved Item related stuff to the end of MapEntity.UpdateAll to avoid issues
Added a threadlock to avoid some issue(someday i will take care of) Add a function that automatically log server performence every 60s
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Security.Cryptography;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
namespace Barotrauma
|
namespace Barotrauma
|
||||||
{
|
{
|
||||||
public class PerformenceMonitor
|
public class PerformenceMonitor
|
||||||
@@ -129,6 +130,9 @@ namespace Barotrauma
|
|||||||
TickRateLow = 60;
|
TickRateLow = 60;
|
||||||
TickRateHigh = 60;
|
TickRateHigh = 60;
|
||||||
tickrate60stimer = TotalTimeElapsed;
|
tickrate60stimer = TotalTimeElapsed;
|
||||||
|
#if !DEBUG
|
||||||
|
GameServer.Log(PM.ToString(), ServerLog.MessageType.ServerMessage);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
if (RealTickRate > TickRateHigh)
|
if (RealTickRate > TickRateHigh)
|
||||||
{
|
{
|
||||||
@@ -147,7 +151,12 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
override public string ToString()
|
override public string ToString()
|
||||||
{
|
{
|
||||||
return $"Item Count: {ItemCount}\n" +
|
return
|
||||||
|
#if !DEBUG
|
||||||
|
$"[{DateTime.Now}]\n" +
|
||||||
|
$"Server Performence Info \n" +
|
||||||
|
#endif
|
||||||
|
$"Item Count: {ItemCount}\n" +
|
||||||
$"Character Count: {CharacterCount}\n" +
|
$"Character Count: {CharacterCount}\n" +
|
||||||
$"PhysicsBody Count: {PhysicsBodyCount}\n" +
|
$"PhysicsBody Count: {PhysicsBodyCount}\n" +
|
||||||
$"Tick Rate: {RealTickRate}\n" +
|
$"Tick Rate: {RealTickRate}\n" +
|
||||||
@@ -156,8 +165,8 @@ namespace Barotrauma
|
|||||||
$"Total Ticks: {TotalTicks}\n" +
|
$"Total Ticks: {TotalTicks}\n" +
|
||||||
$"All time Average Tick Rate: {AverageTickRate}\n" +
|
$"All time Average Tick Rate: {AverageTickRate}\n" +
|
||||||
$"10s Average Tick Rate: {AverageTickRate10s}\n" +
|
$"10s Average Tick Rate: {AverageTickRate10s}\n" +
|
||||||
$"TotalTimeElapsed: {TotalTimeElapsed}\n" +
|
$"Total Time Elapsed: {TotalTimeElapsed}\n" +
|
||||||
$"Memory Usage: {MemoryUsage}";
|
$"Memory Usage: {MemoryUsage}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -503,17 +503,19 @@ namespace Barotrauma
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float GetResistance(AfflictionPrefab afflictionPrefab, LimbType limbType)
|
public float GetResistance(AfflictionPrefab afflictionPrefab, LimbType limbType)
|
||||||
{
|
{
|
||||||
// This is a % resistance (0 to 1.0)
|
lock (afflictions) {
|
||||||
float resistance = 0.0f;
|
// This is a % resistance (0 to 1.0)
|
||||||
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
|
float resistance = 0.0f;
|
||||||
{
|
foreach (KeyValuePair<Affliction, LimbHealth> kvp in afflictions)
|
||||||
var affliction = kvp.Key;
|
{
|
||||||
resistance += affliction.GetResistance(afflictionPrefab.Identifier, limbType);
|
var affliction = kvp.Key;
|
||||||
|
resistance += affliction.GetResistance(afflictionPrefab.Identifier, limbType);
|
||||||
|
}
|
||||||
|
// This is a multiplier, ie. 0.0 = 100% resistance and 1.0 = 0% resistance
|
||||||
|
float abilityResistanceMultiplier = Character.GetAbilityResistance(afflictionPrefab);
|
||||||
|
// The returned value is calculated to be a % resistance again
|
||||||
|
return 1 - ((1 - resistance) * abilityResistanceMultiplier);
|
||||||
}
|
}
|
||||||
// This is a multiplier, ie. 0.0 = 100% resistance and 1.0 = 0% resistance
|
|
||||||
float abilityResistanceMultiplier = Character.GetAbilityResistance(afflictionPrefab);
|
|
||||||
// The returned value is calculated to be a % resistance again
|
|
||||||
return 1 - ((1 - resistance) * abilityResistanceMultiplier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetStatValue(StatTypes statType)
|
public float GetStatValue(StatTypes statType)
|
||||||
|
|||||||
@@ -693,30 +693,6 @@ namespace Barotrauma
|
|||||||
GameMain.PerformanceCounter.AddElapsedTicks("Update:MapEntity:Misc", sw.ElapsedTicks);
|
GameMain.PerformanceCounter.AddElapsedTicks("Update:MapEntity:Misc", sw.ElapsedTicks);
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
#endif
|
#endif
|
||||||
Item.UpdatePendingConditionUpdates(deltaTime);
|
|
||||||
if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
|
|
||||||
{
|
|
||||||
Item lastUpdatedItem = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach (Item item in Item.ItemList)
|
|
||||||
{
|
|
||||||
if (GameMain.LuaCs.Game.UpdatePriorityItems.Contains(item)) { continue; }
|
|
||||||
lastUpdatedItem = item;
|
|
||||||
item.Update(deltaTime * MapEntityUpdateInterval, cam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (InvalidOperationException e)
|
|
||||||
{
|
|
||||||
GameAnalyticsManager.AddErrorEventOnce(
|
|
||||||
"MapEntity.UpdateAll:ItemUpdateInvalidOperation",
|
|
||||||
GameAnalyticsManager.ErrorSeverity.Critical,
|
|
||||||
$"Error while updating item {lastUpdatedItem?.Name ?? "null"}: {e.Message}");
|
|
||||||
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Task PItemTask = Task.Factory.StartNew(() =>
|
Task PItemTask = Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
foreach (var item in GameMain.LuaCs.Game.UpdatePriorityItems)
|
foreach (var item in GameMain.LuaCs.Game.UpdatePriorityItems)
|
||||||
@@ -727,11 +703,6 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
#if CLIENT
|
|
||||||
sw.Stop();
|
|
||||||
GameMain.PerformanceCounter.AddElapsedTicks("Update:MapEntity:Items", sw.ElapsedTicks);
|
|
||||||
sw.Restart();
|
|
||||||
#endif
|
|
||||||
Task SpawnerTask = Task.Factory.StartNew(() =>
|
Task SpawnerTask = Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
|
if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
|
||||||
@@ -741,7 +712,40 @@ namespace Barotrauma
|
|||||||
Spawner?.Update();
|
Spawner?.Update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Task.WaitAll(SpawnerTask, PItemTask, GapTask, StructuralTask);
|
Task.WaitAll(SpawnerTask, PItemTask, GapTask, StructuralTask);
|
||||||
|
|
||||||
|
Item.UpdatePendingConditionUpdates(deltaTime);
|
||||||
|
if (mapEntityUpdateTick % MapEntityUpdateInterval == 0)
|
||||||
|
{
|
||||||
|
lock(Item.ItemList)
|
||||||
|
{
|
||||||
|
Item lastUpdatedItem = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (Item item in Item.ItemList)
|
||||||
|
{
|
||||||
|
if (GameMain.LuaCs.Game.UpdatePriorityItems.Contains(item)) { continue; }
|
||||||
|
lastUpdatedItem = item;
|
||||||
|
item.Update(deltaTime * MapEntityUpdateInterval, cam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (InvalidOperationException e)
|
||||||
|
{
|
||||||
|
GameAnalyticsManager.AddErrorEventOnce(
|
||||||
|
"MapEntity.UpdateAll:ItemUpdateInvalidOperation",
|
||||||
|
GameAnalyticsManager.ErrorSeverity.Critical,
|
||||||
|
$"Error while updating item {lastUpdatedItem?.Name ?? "null"}: {e.Message}");
|
||||||
|
throw new InvalidOperationException($"Error while updating item {lastUpdatedItem?.Name ?? "null"}", innerException: e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if CLIENT
|
||||||
|
sw.Stop();
|
||||||
|
GameMain.PerformanceCounter.AddElapsedTicks("Update:MapEntity:Items", sw.ElapsedTicks);
|
||||||
|
sw.Restart();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static partial void UpdateAllProjSpecific(float deltaTime);
|
static partial void UpdateAllProjSpecific(float deltaTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user