Skip to content

Commit

Permalink
Move StatisticsManager.SendBroadcastIfNeeded from real time to logic …
Browse files Browse the repository at this point in the history
…tick (60)
  • Loading branch information
starfi5h committed Dec 5, 2024
1 parent a5b0be1 commit ae3a9b1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
10 changes: 0 additions & 10 deletions NebulaNetwork/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class Server : IServer
public INetPacketProcessor PacketProcessor { get; set; } = new NebulaNetPacketProcessor();

private const float GAME_RESEARCH_UPDATE_INTERVAL = 2;
private const float STATISTICS_UPDATE_INTERVAL = 1;
private const float LAUNCH_UPDATE_INTERVAL = 4;
private const float DYSONSPHERE_UPDATE_INTERVAL = 2;
private const float WARNING_UPDATE_INTERVAL = 1;
Expand All @@ -54,8 +53,6 @@ public class Server : IServer

private float gameResearchHashUpdateTimer;
private NgrokManager ngrokManager;
private float productionStatisticsUpdateTimer;


private WebSocketServer socket;
private float warningUpdateTimer;
Expand Down Expand Up @@ -414,7 +411,6 @@ public void Update()
}

gameResearchHashUpdateTimer += Time.deltaTime;
productionStatisticsUpdateTimer += Time.deltaTime;
dysonLaunchUpateTimer += Time.deltaTime;
dysonSphereUpdateTimer += Time.deltaTime;
warningUpdateTimer += Time.deltaTime;
Expand All @@ -430,12 +426,6 @@ public void Update()
}
}

if (productionStatisticsUpdateTimer > STATISTICS_UPDATE_INTERVAL)
{
productionStatisticsUpdateTimer = 0;
Multiplayer.Session.Statistics.SendBroadcastIfNeeded();
}

if (dysonLaunchUpateTimer > LAUNCH_UPDATE_INTERVAL)
{
dysonLaunchUpateTimer = 0;
Expand Down
1 change: 1 addition & 0 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ public static void GameTick_Postfix(long time)
if (Multiplayer.Session.LocalPlayer.IsHost)
{
Multiplayer.Session.Launch.CollectProjectile();
Multiplayer.Session.Statistics.SendBroadcastIfNeeded(time);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/UIStatisticsWindow_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace NebulaPatcher.Patches.Dynamic;
[HarmonyPatch(typeof(UIStatisticsWindow))]
internal class UIStatisticsWindow_Patch
{
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(nameof(UIStatisticsWindow._OnOpen))]
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Original Function Name")]
public static void _OnOpen_Postfix()
Expand Down
6 changes: 4 additions & 2 deletions NebulaWorld/Statistics/StatisticsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class StatisticsManager : IDisposable
private PlanetData[] planetDataMap = new PlanetData[GameMain.data.factories.Length];

private List<StatisticalSnapShot> statisticalSnapShots = [];
private long lastUpdateTime;

public bool IsStatisticsNeeded { get; set; }
public long[] PowerEnergyStoredData { get; set; }
Expand Down Expand Up @@ -92,12 +93,13 @@ public void CaptureStatisticalSnapshot()
statisticalSnapShots.Add(snapshot);
}

public void SendBroadcastIfNeeded()
public void SendBroadcastIfNeeded(long time)
{
if (!IsStatisticsNeeded)
if (!IsStatisticsNeeded || time % 60 != 0 || lastUpdateTime == time)
{
return;
}
lastUpdateTime = time;
using (GetRequestors(out var requestors))
{
if (requestors.Count <= 0)
Expand Down

0 comments on commit ae3a9b1

Please sign in to comment.