split server #3

This commit is contained in:
Sen 2025-05-03 23:14:58 +02:00
parent 8f8abfa0d3
commit 19f3813338
6 changed files with 83 additions and 5 deletions

View file

@ -405,6 +405,7 @@ public class Game implements IThreadListener {
private ServerProcess server; private ServerProcess server;
private String serverInfo; private String serverInfo;
private int lastTickTime = -1;
private AudioInterface audio; private AudioInterface audio;
private long start; private long start;
private boolean cfgDirty; private boolean cfgDirty;
@ -476,6 +477,7 @@ public class Game implements IThreadListener {
this.theWorld = null; this.theWorld = null;
this.thePlayer = null; this.thePlayer = null;
this.serverInfo = null; this.serverInfo = null;
this.lastTickTime = -1;
this.soundManager.stopSounds(); this.soundManager.stopSounds();
} }
@ -1609,6 +1611,13 @@ public class Game implements IThreadListener {
this.serverInfo = info; this.serverInfo = info;
} }
public void setLastTick(int time) {
if(this.lastTickTime >= 0) {
this.lastTicked = System.currentTimeMillis();
this.lastTickTime = time;
}
}
public void updatePlayerMoveState() public void updatePlayerMoveState()
{ {
this.moveStrafe = 0.0F; this.moveStrafe = 0.0F;
@ -2076,7 +2085,7 @@ public class Game implements IThreadListener {
return; return;
this.frameWait = 50000000L - ((n - (this.frameLast + this.frameWait)) < 50000000L ? (n - (this.frameLast + this.frameWait)) : 0L); this.frameWait = 50000000L - ((n - (this.frameLast + this.frameWait)) < 50000000L ? (n - (this.frameLast + this.frameWait)) : 0L);
this.frameLast = n; this.frameLast = n;
this.tickTimes[this.tickIndex++] = this.server == null ? 0 : this.server.getLastTick(); this.tickTimes[this.tickIndex++] = this.lastTickTime;
if(this.tickIndex == 240) { if(this.tickIndex == 240) {
this.tickIndex = 0; 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"); 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) { private boolean handleDebugKey(Keysym key) {
@ -3169,7 +3190,7 @@ public class Game implements IThreadListener {
Drawing.drawText("60ms", 2, h - 60 - 14, 0xffE0E0E0); Drawing.drawText("60ms", 2, h - 60 - 14, 0xffE0E0E0);
Drawing.drawTextRight("ms/Frame", 238, h - 60 - 14, 0xffE0E0E0); Drawing.drawTextRight("ms/Frame", 238, h - 60 - 14, 0xffE0E0E0);
if(this.server != null) { if(this.lastTickTime >= 0) {
this.updateTick(); this.updateTick();
Drawing.drawRect(w - 240, h - 74, 240, 60, 0x90505050); Drawing.drawRect(w - 240, h - 74, 240, 60, 0x90505050);
x = w - 240; x = w - 240;

View file

@ -96,6 +96,7 @@ import game.packet.SPacketMessage;
import game.packet.SPacketMultiBlockChange; import game.packet.SPacketMultiBlockChange;
import game.packet.SPacketPlayerPosLook; import game.packet.SPacketPlayerPosLook;
import game.packet.SPacketRespawn; import game.packet.SPacketRespawn;
import game.packet.SPacketServerTick;
import game.packet.SPacketSetExperience; import game.packet.SPacketSetExperience;
import game.packet.SPacketSkin; import game.packet.SPacketSkin;
import game.packet.SPacketSpawnMob; import game.packet.SPacketSpawnMob;
@ -927,6 +928,12 @@ public class ClientPlayer extends NetHandler
this.gameController.setTicked(packetIn.getServerinfo()); 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) // public void handleCompass(SPacketCompass packetIn)
// { // {
// NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); // NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController);

View file

@ -75,6 +75,7 @@ import game.packet.SPacketMessage;
import game.packet.SPacketMultiBlockChange; import game.packet.SPacketMultiBlockChange;
import game.packet.SPacketPlayerPosLook; import game.packet.SPacketPlayerPosLook;
import game.packet.SPacketRespawn; import game.packet.SPacketRespawn;
import game.packet.SPacketServerTick;
import game.packet.SPacketSetExperience; import game.packet.SPacketSetExperience;
import game.packet.SPacketSkin; import game.packet.SPacketSkin;
import game.packet.SPacketSpawnMob; import game.packet.SPacketSpawnMob;
@ -179,6 +180,7 @@ public enum PacketRegistry
// this.server(SPacketNotify.class); // this.server(SPacketNotify.class);
this.server(SPacketDimensionName.class); this.server(SPacketDimensionName.class);
this.server(SPacketCharacterList.class); this.server(SPacketCharacterList.class);
this.server(SPacketServerTick.class);
this.server(SPacketLoading.class); this.server(SPacketLoading.class);
this.client(CPacketKeepAlive.class); this.client(CPacketKeepAlive.class);

View file

@ -101,6 +101,7 @@ import game.packet.SPacketMapChunkBulk;
import game.packet.SPacketMessage; import game.packet.SPacketMessage;
import game.packet.SPacketMessage.Type; import game.packet.SPacketMessage.Type;
import game.packet.SPacketPlayerPosLook; import game.packet.SPacketPlayerPosLook;
import game.packet.SPacketServerTick;
import game.packet.SPacketSetExperience; import game.packet.SPacketSetExperience;
import game.packet.SPacketSkin; import game.packet.SPacketSkin;
import game.packet.SPacketTrades; import game.packet.SPacketTrades;
@ -188,6 +189,7 @@ public class Player extends NetHandler implements ICrafting, Executor
private int ping; private int ping;
private boolean deleted; private boolean deleted;
private String password; private String password;
private boolean profiling;
private int selectionDim = Integer.MIN_VALUE; private int selectionDim = Integer.MIN_VALUE;
private ClipboardBlock[][][] clipboard; private ClipboardBlock[][][] clipboard;
@ -274,8 +276,8 @@ public class Player extends NetHandler implements ICrafting, Executor
this.pingKey = (int)this.lastPingTime; this.pingKey = (int)this.lastPingTime;
this.sendPacket(new SPacketKeepAlive(this.pingKey)); 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) {
if(--this.respawnTimer == 0) { if(--this.respawnTimer == 0) {
this.respawnPlayer(); this.respawnPlayer();
@ -2895,6 +2897,16 @@ public class Player extends NetHandler implements ICrafting, Executor
}); });
} }
break; break;
case START_PROFILING:
if(this.admin)
this.profiling = true;
break;
case STOP_PROFILING:
if(this.admin)
this.profiling = false;
break;
default: default:
throw new IllegalArgumentException("Ungültige Aktion!"); throw new IllegalArgumentException("Ungültige Aktion!");

View file

@ -95,7 +95,9 @@ public class CPacketAction implements Packet<Player>
PERF, PERF,
MAGNET, MAGNET,
// SET_VIEWDIST, // SET_VIEWDIST,
WARP_MODE; WARP_MODE,
START_PROFILING,
STOP_PROFILING;
// SHUTDOWN; // SHUTDOWN;
} }
} }

View file

@ -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<ClientPlayer> {
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;
}
}