From 4e90a93d6891dbb24724838950c3a2cc5168d8ef Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 11 Mar 2025 14:02:41 +0100 Subject: [PATCH] debug key combos reimplemented --- java/src/game/Game.java | 318 ++++++++++++++++++++++++++-------------- 1 file changed, 212 insertions(+), 106 deletions(-) diff --git a/java/src/game/Game.java b/java/src/game/Game.java index f8cc700..355fc48 100755 --- a/java/src/game/Game.java +++ b/java/src/game/Game.java @@ -2,7 +2,6 @@ package game; import java.awt.Desktop; import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; import java.awt.image.BufferedImage; import java.io.BufferedInputStream; import java.io.BufferedReader; @@ -37,6 +36,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.FutureTask; +import java.util.function.Function; import javax.imageio.ImageIO; import javax.swing.JOptionPane; @@ -120,6 +120,7 @@ import game.util.FileCallback; import game.util.FileUtils; import game.util.PerfSection; import game.util.Timing; +import game.util.Util; import game.vars.BoolVar; import game.vars.CVar; import game.vars.CVarCategory; @@ -197,18 +198,33 @@ public class Game implements IThreadListener { public static class DistanceFunction implements IntFunction { public void apply(IntVar cv, int value) { - if(Game.getGame().renderGlobal != null) - Game.getGame().renderGlobal.setDisplayListEntitiesDirty(); Game.getGame().distance(value); } } + private interface DebugRunner { + void execute(Keysym key); + } + + private class DebugFunction { + public final DebugRunner runner; + public final Keysym key; + public final String help; + + public DebugFunction(Keysym key, DebugRunner runner, String help) { + this.key = key; + this.runner = runner; + this.help = help; + } + } + public static final int LOG_BUFFER = 32768; private final Queue> tasks = new ArrayDeque>(); private final Map bars = Maps.newTreeMap(); private final Thread clThread = Thread.currentThread(); private final Map cvars = Maps.newTreeMap(); + private final Map debug = Maps.newTreeMap(); private final List log = Lists.newArrayList(); private final File config = new File(System.getProperty("config.file", "game.cfg")); @@ -1862,6 +1878,8 @@ public class Game implements IThreadListener { } private void key(Keysym key, KeyEvent act) { + if((act == KeyEvent.PRESS) && Bind.isInputEnabled() && Bind.CHEAT.isDown() && this.handleDebugKey(key)) + return; if(open != null && (act != KeyEvent.RELEASE) && Bind.isInputEnabled()) { open.key(key, ctrl(), shift()); } @@ -1992,6 +2010,7 @@ public class Game implements IThreadListener { Log.SYSTEM.info("Starte ..."); this.init(); + this.registerDebug(); System.gc(); System.gc(); Font.load(); @@ -2083,13 +2102,6 @@ public class Game implements IThreadListener { private void input() { - if(Bind.QUIT.isPressed()) { - this.interrupted = true; - } - if(Bind.SYNC.isPressed()) { - this.getVar("win_sync").parse("" + (this.vsync ? this.syncLimit : (this.syncLimited ? -1 : 0))); - this.setDirty(); - } if(!this.saving && Bind.SCREENSHOT.isPressed()) { this.screenshot = true; } @@ -2133,26 +2145,6 @@ public class Game implements IThreadListener { } } } - if(Bind.isWindowActive() && this.open == null) { - if(Bind.NOCLIP.isPressed()) { - this.performAction(Action.NOCLIP); - } - if(Bind.GOD.isPressed()) { - this.performAction(Action.GOD); - } - if(Bind.SPEED.isPressed()) { - this.performAction(Action.SPEED); - } - if(Bind.CHEAT.isPressed()) { - Log.CONSOLE.user("Cheat-Menü: %s", (this.itemCheat ^= true) ? "an" : "aus"); - } - if(Bind.REPAIR.isPressed()) { - this.performAction(Action.REPAIR); - } - if(Bind.LIGHT.isPressed()) { - Log.CONSOLE.user("Maximale Helligkeit: %s", (this.setGamma ^= true) ? "an" : "aus"); - } - } } private void screenshot() { @@ -2326,75 +2318,6 @@ public class Game implements IThreadListener { public double ftime() { return ((double)rtime()) / 1000000.0; } - - - - public void jvmgc() { - Log.CONSOLE.user("Führe JVM GC aus"); - long mem = Runtime.getRuntime().freeMemory(); - System.gc(); - System.gc(); - mem = Runtime.getRuntime().freeMemory() - mem; - mem = mem < 0L ? 0L : mem; - Log.CONSOLE.user("JVM GC ausgeführt: %d MB freigegeben", (int)(mem / 1024L / 1024L)); - } - - public void hitboxes() { - this.getRenderManager().setDebugBoundingBox(!this.getRenderManager().isDebugBoundingBox()); - Log.CONSOLE.user("Objekt-Grenzen: %s", this.getRenderManager().isDebugBoundingBox() ? "an" : "aus"); - } - - public void debugcam() { - Log.CONSOLE.user("Debug-Kamera 3. Person: %s", (this.debugCamEnable ^= true) ? "an" : "aus"); - } - - public void xray() { - this.xrayActive ^= true; - this.renderGlobal.loadRenderers(); - Log.CONSOLE.user("Röntgenblick: %s", this.xrayActive ? "an" : "aus"); - } - - public void outlines() { - Log.CONSOLE.user("Objekt-Umrahmung: %s", (this.renderOutlines ^= true) ? "an" : "aus"); - } - - public void tileview() { - Log.CONSOLE.user("Block-Objekte anzeigen: %s", (this.tileOverlay ^= true) ? "an" : "aus"); - } - - public void rebuild() { - Log.CONSOLE.user("Kompiliere alle Chunks neu"); - this.renderGlobal.loadRenderers(); - Log.CONSOLE.user("Alle Chunks wurden neu kompiliert"); - } - - public void refreshtex() { - Log.CONSOLE.user("Lade Texturen neu"); - this.refreshResources(); - Log.CONSOLE.user("Texturen wurden neu geladen"); - } - - public void warp() { - if(server != null) { - server.schedule(new Runnable() { - public void run() { - server.setTpsTarget(server.getTpsTarget() < 10000.0f ? 10000.0f : 20.0f); - } - }); - } - } - - public void magnet() { - this.performAction(Action.MAGNET); - } - - public void heal() { - this.performAction(Action.HEAL); - } - - public void perfs() { - this.performAction(Action.PERF); - } public void convert(File folder, String user) { Converter.convertMapFormat(folder, user); @@ -2408,15 +2331,198 @@ public class Game implements IThreadListener { public String getldebug() { return this.getLeft(server); } - - - public void crash() { - throw new RuntimeException("Manuell herbeigerufener Debugging-Absturz"); - } public void distance(int distance) { - if(server != null) - server.setVar("viewDistance", "" + distance); + if(this.renderGlobal != null) + this.renderGlobal.setDisplayListEntitiesDirty(); + if(this.server != null) + this.server.setVar("viewDistance", "" + distance); + } + + private void registerDebug(Keysym key, String help, DebugRunner runner) { + if(this.debug.containsKey(key)) + throw new IllegalStateException("Debug-Taste " + key.getDisplay() + " ist bereits registriert"); + this.debug.put(key, new DebugFunction(key, runner, help)); + } + + private void registerDebug() { + this.registerDebug(Keysym.H, "Hilfe zu Tastenkombinationen anzeigen", new DebugRunner() { + public void execute(Keysym key) { + String bind = Bind.CHEAT.getInput() == null ? "n/a" : Bind.CHEAT.getInput().getDisplay(); + Game.this.displayGuiScreen(new GuiInfo("Hilfe zu Tastenkombinationen", TextColor.DGREEN + "" + Game.this.debug.size() + " Tastenkombinationen stehen zur Verfügung:\n" + + Util.buildLines(new Function() { + public String apply(DebugFunction func) { + return TextColor.CYAN + bind + TextColor.RED + "+" + TextColor.GREEN + func.key.getDisplay() + TextColor.GRAY + " - " + TextColor.YELLOW + func.help; + } + }, Game.this.debug.values()))); + } + }); + this.registerDebug(Keysym.N, "NoClip umschalten", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.NOCLIP); + } + }); + this.registerDebug(Keysym.G, "Unsterblichkeit umschalten", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.GOD); + } + }); + this.registerDebug(Keysym.F, "Geschwindigkeit umschalten", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.SPEED); + } + }); + this.registerDebug(Keysym.R, "Gegenstand reparieren und Stapel auffüllen", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.REPAIR); + } + }); + this.registerDebug(Keysym.E, "Gegenstands-Cheat-Menü umschalten", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Cheat-Menü: %s", (Game.this.itemCheat ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.L, "Maximale Helligkeit umschalten", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Maximale Helligkeit: %s", (Game.this.setGamma ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.J, "JVM GC ausführen", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Führe JVM GC aus"); + long mem = Runtime.getRuntime().freeMemory(); + System.gc(); + System.gc(); + mem = Runtime.getRuntime().freeMemory() - mem; + mem = mem < 0L ? 0L : mem; + Log.CONSOLE.user("JVM GC ausgeführt: %d MB freigegeben", (int)(mem / 1024L / 1024L)); + } + }); + this.registerDebug(Keysym.B, "Hitbox-Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Game.this.getRenderManager().setDebugBoundingBox(!Game.this.getRenderManager().isDebugBoundingBox()); + Log.CONSOLE.user("Objekt-Grenzen: %s", Game.this.getRenderManager().isDebugBoundingBox() ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.K, "Debug-Kamera in 3. Person umschalten", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Debug-Kamera 3. Person: %s", (Game.this.debugCamEnable ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.X, "Röntgenblick umschalten", new DebugRunner() { + public void execute(Keysym key) { + Game.this.xrayActive ^= true; + Game.this.renderGlobal.loadRenderers(); + Log.CONSOLE.user("Röntgenblick: %s", Game.this.xrayActive ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.O, "Objekt-Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Objekt-Umrahmung: %s", (Game.this.renderOutlines ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.I, "Block-Objekt-Overlay umschalten", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Block-Objekte anzeigen: %s", (Game.this.tileOverlay ^= true) ? "an" : "aus"); + } + }); + this.registerDebug(Keysym.Y, "Alle Chunks neu kompilieren", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Kompiliere alle Chunks neu"); + Game.this.renderGlobal.loadRenderers(); + Log.CONSOLE.user("Alle Chunks wurden neu kompiliert"); + } + }); + this.registerDebug(Keysym.T, "Alle Texturen neu laden", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Lade Texturen neu"); + Game.this.refreshResources(); + Log.CONSOLE.user("Texturen wurden neu geladen"); + } + }); + this.registerDebug(Keysym.S, "Alle Sounds neu laden", new DebugRunner() { + public void execute(Keysym key) { + Log.CONSOLE.user("Lade Sounds neu"); + Game.this.restartSound(true); + Log.CONSOLE.user("Sounds wurden neu geladen"); + } + }); + this.registerDebug(Keysym.W, "Server-Tick-Limit umschalten (Welt beschleunigen / Warpmodus)", new DebugRunner() { + public void execute(Keysym key) { + if(server != null) { + server.schedule(new Runnable() { + public void run() { + server.setTpsTarget(server.getTpsTarget() < 10000.0f ? 10000.0f : 20.0f); + } + }); + } + } + }); + this.registerDebug(Keysym.M, "Alle Gegenstände herbei ziehen (Magnetmodus)", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.MAGNET); + } + }); + this.registerDebug(Keysym.Z, "Den Spieler heilen", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.HEAL); + } + }); + this.registerDebug(Keysym.P, "Server Performance-Anfrage senden", new DebugRunner() { + public void execute(Keysym key) { + Game.this.performAction(Action.PERF); + } + }); + this.registerDebug(Keysym.C, "Debug-Crash auslösen (2x schnell hintereinander)", new DebugRunner() { + long lastUsed; + + public void execute(Keysym key) { + if(System.currentTimeMillis() - this.lastUsed <= 1000L) { + throw new RuntimeException("Manuell herbeigerufener Debugging-Absturz"); + } + else { + this.lastUsed = System.currentTimeMillis(); + Log.CONSOLE.warn("VORSICHT: Debug-Absturz nach mehrmaligem Drücken innerhalb einer Sekunde"); + } + } + }); + this.registerDebug(Keysym.V, "Alle Sounds stoppen", new DebugRunner() { + public void execute(Keysym key) { + Game.this.soundManager.stopSounds(); + } + }); + this.registerDebug(Keysym.Q, "Programm sofort beenden und speichern", new DebugRunner() { + public void execute(Keysym key) { + Game.this.interrupted = true; + } + }); + this.registerDebug(Keysym.A, "Bild-Synchonisation umschalten (VSync - begrenzt - unbegrenzt)", new DebugRunner() { + public void execute(Keysym key) { + Game.this.getVar("win_sync").parse("" + (Game.this.vsync ? Game.this.syncLimit : (Game.this.syncLimited ? -1 : 0))); + Game.this.setDirty(); + } + }); + this.registerDebug(Keysym.D, "Konsole und Chat leeren", new DebugRunner() { + public void execute(Keysym key) { + GuiConsole.INSTANCE.reset(); + if(Game.this.open instanceof GuiConsole) + ((GuiConsole)Game.this.open).setLog(Game.this.buffer); + } + }); + this.registerDebug(Keysym.U, "HUD umschalten", new DebugRunner() { + public void execute(Keysym key) { + + } + }); + } + + private boolean handleDebugKey(Keysym key) { + DebugFunction func = this.debug.get(key); + if(func != null) { + Bind.disableInput(key); + func.runner.execute(key); + } + return func != null; }