Browse Source

Updated simulation metrics access.

master
MagicBot 2 years ago
parent
commit
a4029fb6e2
  1. 9
      src/engine/ai/MobileFSMManager.java
  2. 12
      src/engine/devcmd/cmds/HeartbeatCmd.java
  3. 18
      src/engine/gameManager/SimulationManager.java

9
src/engine/ai/MobileFSMManager.java

@ -15,6 +15,9 @@ import engine.server.MBServerStatics; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -88,6 +96,7 @@ public class MobileFSMManager {
}
}
this.executionTime = Duration.between(startTime, Instant.now());
mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD;
}
}

12
src/engine/devcmd/cmds/HeartbeatCmd.java

@ -10,11 +10,15 @@ @@ -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 { @@ -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";
}
}

18
src/engine/gameManager/SimulationManager.java

@ -16,6 +16,8 @@ import engine.objects.PlayerCharacter; @@ -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 { @@ -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 { @@ -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)
@ -113,16 +114,7 @@ public enum SimulationManager { @@ -113,16 +114,7 @@ public enum SimulationManager {
}
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());
}

Loading…
Cancel
Save