diff --git a/java/src/game/Game.java b/java/src/game/Game.java index a8b0d6f..2e1ebee 100755 --- a/java/src/game/Game.java +++ b/java/src/game/Game.java @@ -405,6 +405,7 @@ public class Game implements IThreadListener { private ServerProcess server; private String serverInfo; + private int lastTickTime = -1; private AudioInterface audio; private long start; private boolean cfgDirty; @@ -476,6 +477,7 @@ public class Game implements IThreadListener { this.theWorld = null; this.thePlayer = null; this.serverInfo = null; + this.lastTickTime = -1; this.soundManager.stopSounds(); } @@ -1609,6 +1611,13 @@ public class Game implements IThreadListener { this.serverInfo = info; } + public void setLastTick(int time) { + if(this.lastTickTime >= 0) { + this.lastTicked = System.currentTimeMillis(); + this.lastTickTime = time; + } + } + public void updatePlayerMoveState() { this.moveStrafe = 0.0F; @@ -2076,7 +2085,7 @@ public class Game implements IThreadListener { return; this.frameWait = 50000000L - ((n - (this.frameLast + this.frameWait)) < 50000000L ? (n - (this.frameLast + this.frameWait)) : 0L); this.frameLast = n; - this.tickTimes[this.tickIndex++] = this.server == null ? 0 : this.server.getLastTick(); + this.tickTimes[this.tickIndex++] = this.lastTickTime; if(this.tickIndex == 240) { this.tickIndex = 0; } @@ -2613,6 +2622,18 @@ public class Game implements IThreadListener { Game.this.logFeed("Spieler-Info in Overlay: %s", (Game.this.debugPlayer ^= true) ? "an" : "aus"); } }); + this.registerDebug(Keysym.OE, "Tick-Profiler umschalten", new DebugRunner() { + public void execute(Keysym key) { + if(Game.this.lastTickTime >= 0) { + Game.this.performAction(Action.STOP_PROFILING); + Game.this.lastTickTime = -1; + } + else { + Game.this.performAction(Action.START_PROFILING); + Game.this.lastTickTime = 0; + } + } + }); } private boolean handleDebugKey(Keysym key) { @@ -3169,7 +3190,7 @@ public class Game implements IThreadListener { Drawing.drawText("60ms", 2, h - 60 - 14, 0xffE0E0E0); Drawing.drawTextRight("ms/Frame", 238, h - 60 - 14, 0xffE0E0E0); - if(this.server != null) { + if(this.lastTickTime >= 0) { this.updateTick(); Drawing.drawRect(w - 240, h - 74, 240, 60, 0x90505050); x = w - 240; diff --git a/java/src/game/network/ClientPlayer.java b/java/src/game/network/ClientPlayer.java index 38d311d..8bc4e24 100755 --- a/java/src/game/network/ClientPlayer.java +++ b/java/src/game/network/ClientPlayer.java @@ -96,6 +96,7 @@ import game.packet.SPacketMessage; import game.packet.SPacketMultiBlockChange; import game.packet.SPacketPlayerPosLook; import game.packet.SPacketRespawn; +import game.packet.SPacketServerTick; import game.packet.SPacketSetExperience; import game.packet.SPacketSkin; import game.packet.SPacketSpawnMob; @@ -927,6 +928,12 @@ public class ClientPlayer extends NetHandler this.gameController.setTicked(packetIn.getServerinfo()); } + public void handleServerTick(SPacketServerTick packet) + { + NetHandler.checkThread(packet, this, this.gameController); + this.gameController.setLastTick(packet.getTime()); + } + // public void handleCompass(SPacketCompass packetIn) // { // NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); diff --git a/java/src/game/network/PacketRegistry.java b/java/src/game/network/PacketRegistry.java index b11b19e..cbfaffc 100755 --- a/java/src/game/network/PacketRegistry.java +++ b/java/src/game/network/PacketRegistry.java @@ -75,6 +75,7 @@ import game.packet.SPacketMessage; import game.packet.SPacketMultiBlockChange; import game.packet.SPacketPlayerPosLook; import game.packet.SPacketRespawn; +import game.packet.SPacketServerTick; import game.packet.SPacketSetExperience; import game.packet.SPacketSkin; import game.packet.SPacketSpawnMob; @@ -179,6 +180,7 @@ public enum PacketRegistry // this.server(SPacketNotify.class); this.server(SPacketDimensionName.class); this.server(SPacketCharacterList.class); + this.server(SPacketServerTick.class); this.server(SPacketLoading.class); this.client(CPacketKeepAlive.class); diff --git a/java/src/game/network/Player.java b/java/src/game/network/Player.java index 7d50801..8a19a68 100755 --- a/java/src/game/network/Player.java +++ b/java/src/game/network/Player.java @@ -101,6 +101,7 @@ import game.packet.SPacketMapChunkBulk; import game.packet.SPacketMessage; import game.packet.SPacketMessage.Type; import game.packet.SPacketPlayerPosLook; +import game.packet.SPacketServerTick; import game.packet.SPacketSetExperience; import game.packet.SPacketSkin; import game.packet.SPacketTrades; @@ -188,6 +189,7 @@ public class Player extends NetHandler implements ICrafting, Executor private int ping; private boolean deleted; private String password; + private boolean profiling; private int selectionDim = Integer.MIN_VALUE; private ClipboardBlock[][][] clipboard; @@ -274,8 +276,8 @@ public class Player extends NetHandler implements ICrafting, Executor this.pingKey = (int)this.lastPingTime; this.sendPacket(new SPacketKeepAlive(this.pingKey)); } -// if(this.local) - + if(this.admin && this.profiling) + this.sendPacket(new SPacketServerTick((int)this.server.getLastTick())); if(this.respawnTimer > 0) { if(--this.respawnTimer == 0) { this.respawnPlayer(); @@ -2895,6 +2897,16 @@ public class Player extends NetHandler implements ICrafting, Executor }); } break; + + case START_PROFILING: + if(this.admin) + this.profiling = true; + break; + + case STOP_PROFILING: + if(this.admin) + this.profiling = false; + break; default: throw new IllegalArgumentException("Ungültige Aktion!"); diff --git a/java/src/game/packet/CPacketAction.java b/java/src/game/packet/CPacketAction.java index d0f655d..5a93ea9 100755 --- a/java/src/game/packet/CPacketAction.java +++ b/java/src/game/packet/CPacketAction.java @@ -95,7 +95,9 @@ public class CPacketAction implements Packet PERF, MAGNET, // SET_VIEWDIST, - WARP_MODE; + WARP_MODE, + START_PROFILING, + STOP_PROFILING; // SHUTDOWN; } } diff --git a/java/src/game/packet/SPacketServerTick.java b/java/src/game/packet/SPacketServerTick.java new file mode 100644 index 0000000..14dcaea --- /dev/null +++ b/java/src/game/packet/SPacketServerTick.java @@ -0,0 +1,34 @@ +package game.packet; + +import java.io.IOException; + +import game.network.ClientPlayer; +import game.network.Packet; +import game.network.PacketBuffer; + +public class SPacketServerTick implements Packet { + private int time; + + public SPacketServerTick() { + } + + public SPacketServerTick(int time) { + this.time = time; + } + + public void readPacketData(PacketBuffer buf) throws IOException { + this.time = buf.readInt(); + } + + public void writePacketData(PacketBuffer buf) throws IOException { + buf.writeInt(this.time); + } + + public void processPacket(ClientPlayer handler) { + handler.handleServerTick(this); + } + + public int getTime() { + return this.time; + } +}