diff --git a/src/engine/ai/MobileFSMManager.java b/src/engine/ai/MobileFSMManager.java index 1c52b11c..25727a80 100644 --- a/src/engine/ai/MobileFSMManager.java +++ b/src/engine/ai/MobileFSMManager.java @@ -15,6 +15,9 @@ import engine.server.MBServerStatics; import engine.util.ThreadUtils; import org.pmw.tinylog.Logger; +import java.time.Duration; +import java.time.Instant; + public class MobileFSMManager { @@ -23,6 +26,8 @@ public class MobileFSMManager { private volatile boolean alive; private long timeOfKill = -1; + public static Duration executionTime; + private MobileFSMManager() { Runnable worker = new Runnable() { @@ -67,6 +72,7 @@ public class MobileFSMManager { //Load zone threshold once. long mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD; + Instant startTime; while (alive) { @@ -74,6 +80,8 @@ public class MobileFSMManager { if (System.currentTimeMillis() > mobPulse) { + startTime = Instant.now(); + for (Zone zone : ZoneManager.getAllZones()) { for (Mob mob : zone.zoneMobSet) { @@ -88,6 +96,7 @@ public class MobileFSMManager { } } + this.executionTime = Duration.between(startTime, Instant.now()); mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD; } } diff --git a/src/engine/devcmd/cmds/HeartbeatCmd.java b/src/engine/devcmd/cmds/HeartbeatCmd.java index c43c81a0..eccec5e8 100644 --- a/src/engine/devcmd/cmds/HeartbeatCmd.java +++ b/src/engine/devcmd/cmds/HeartbeatCmd.java @@ -10,11 +10,15 @@ package engine.devcmd.cmds; +import engine.ai.MobileFSMManager; import engine.devcmd.AbstractDevCmd; import engine.gameManager.SimulationManager; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; +import java.time.temporal.TemporalUnit; +import java.util.concurrent.TimeUnit; + public class HeartbeatCmd extends AbstractDevCmd { public HeartbeatCmd() { @@ -25,19 +29,19 @@ public class HeartbeatCmd extends AbstractDevCmd { protected void _doCmd(PlayerCharacter pc, String[] words, AbstractGameObject target) { - this.throwbackInfo(pc, "Current Heartbeat : " + SimulationManager.currentHeartBeatDelta + " ms."); - this.throwbackInfo(pc, "Max Heartbeat : " + SimulationManager.HeartbeatDelta + " ms."); + this.throwbackInfo(pc, "Heartbeat : " + TimeUnit.NANOSECONDS.toMillis(SimulationManager.HeartbeatDelta.getNano())); + this.throwbackInfo(pc, "FSM: " + TimeUnit.NANOSECONDS.toMillis(MobileFSMManager.executionTime.getNano())); } @Override protected String _getHelpString() { - return "Temporarily Changes SubRace"; + return "Displays simulation metrics"; } @Override protected String _getUsageString() { - return "' /subrace mobBaseID"; + return "' ./heartbeat"; } } diff --git a/src/engine/gameManager/SimulationManager.java b/src/engine/gameManager/SimulationManager.java index 088e4cba..aa38194b 100644 --- a/src/engine/gameManager/SimulationManager.java +++ b/src/engine/gameManager/SimulationManager.java @@ -16,6 +16,8 @@ import engine.objects.PlayerCharacter; import engine.objects.Runegate; import org.pmw.tinylog.Logger; +import java.time.Duration; +import java.time.Instant; import java.util.Collection; /* @@ -39,8 +41,7 @@ public enum SimulationManager { private long _updatePulseTime = System.currentTimeMillis() + UPDATE_PULSE; private long _flightPulseTime = System.currentTimeMillis() + FlIGHT_PULSE; - public static long HeartbeatDelta = 0; - public static long currentHeartBeatDelta = 0; + public static Duration HeartbeatDelta; private SimulationManager() { @@ -69,7 +70,7 @@ public enum SimulationManager { * runegates stop working than the game itself! */ - long start = System.currentTimeMillis(); + Instant startTime = Instant.now(); try { if ((_flightPulseTime != 0) @@ -112,17 +113,8 @@ public enum SimulationManager { e.printStackTrace(); } - - long end = System.currentTimeMillis(); - - long delta = end - start; - - if (delta > SimulationManager.HeartbeatDelta) - SimulationManager.HeartbeatDelta = delta; - - SimulationManager.currentHeartBeatDelta = delta; - + SimulationManager.HeartbeatDelta = Duration.between(startTime, Instant.now()); }