debug commands

This commit is contained in:
RandomityGuy 2022-12-26 23:47:04 +05:30
parent de20dbf0b8
commit b62da3af89
11 changed files with 178 additions and 55 deletions

View file

@ -1,6 +1,8 @@
package src; package src;
import mis.MisParser;
import src.Settings; import src.Settings;
import src.Debug;
@:publicFields @:publicFields
class ConsoleEntry { class ConsoleEntry {
@ -97,4 +99,49 @@ class Console {
public static function removeConsumer(c:ConsoleEntry->Void) { public static function removeConsumer(c:ConsoleEntry->Void) {
instance.consumers.remove(c); instance.consumers.remove(c);
} }
public static function eval(cmd:String) {
var cmdSplit = cmd.split(" ");
if (cmdSplit.length != 0) {
var cmdType = cmdSplit[0];
if (cmdType == "help") {
log("Available commands:");
log("help");
log("timeScale <scale>");
log("drawBounds <true/false>");
log("wireframe <true/false>");
} else if (cmdType == "timeScale") {
if (cmdSplit.length == 2) {
var scale = Std.parseFloat(cmdSplit[1]);
if (Math.isNaN(scale))
scale = 1;
Debug.timeScale = scale;
log("Time scale set to " + scale);
} else {
error("Expected one argument, got " + (cmdSplit.length - 1));
}
} else if (cmdType == "drawBounds") {
if (cmdSplit.length == 2) {
var scale = MisParser.parseBoolean(cmdSplit[1]);
Debug.drawBounds = scale;
log("Debug.drawBounds set to " + scale);
} else {
error("Expected one argument, got " + (cmdSplit.length - 1));
}
} else if (cmdType == "wireframe") {
if (cmdSplit.length == 2) {
var scale = MisParser.parseBoolean(cmdSplit[1]);
Debug.wireFrame = scale;
log("Debug.wireframe set to " + scale);
} else {
error("Expected one argument, got " + (cmdSplit.length - 1));
}
} else {
error("Unknown command");
}
return;
}
error("Unknown command");
}
} }

8
src/Debug.hx Normal file
View file

@ -0,0 +1,8 @@
package src;
@:publicFields
class Debug {
static var timeScale:Float = 1.0;
static var wireFrame:Bool = false;
static var drawBounds:Bool = false;
}

View file

@ -32,6 +32,7 @@ import src.InteriorObject;
import src.MarbleGame; import src.MarbleGame;
import src.ResourceLoaderWorker; import src.ResourceLoaderWorker;
import src.Console; import src.Console;
import src.Debug;
class DifBuilderTriangle { class DifBuilderTriangle {
public var texture:String; public var texture:String;
@ -753,7 +754,8 @@ class DifBuilder {
material.receiveShadows = true; material.receiveShadows = true;
} }
// material.mainPass.addShader(new h3d.shader.pbr.PropsValues(1, 0, 0, 1)); // material.mainPass.addShader(new h3d.shader.pbr.PropsValues(1, 0, 0, 1));
// material.mainPass.wireframe = true; if (Debug.wireFrame)
material.mainPass.wireframe = true;
var mesh = new Mesh(prim, material, itr); var mesh = new Mesh(prim, material, itr);
} }

View file

@ -109,13 +109,14 @@ class Main extends hxd.App {
if (loaded) { if (loaded) {
ProfilerUI.begin(); ProfilerUI.begin();
ProfilerUI.measure("updateBegin"); ProfilerUI.measure("updateBegin");
try {
marbleGame.update(dt); // try {
} catch (e) { marbleGame.update(dt);
Console.error(e.message); // } catch (e) {
Console.error(e.stack.toString()); // Console.error(e.message);
throw e; // Console.error(e.stack.toString());
} // throw e;
// }
// world.update(dt); // world.update(dt);
ProfilerUI.update(this.engine.fps); ProfilerUI.update(this.engine.fps);
} }

View file

@ -60,6 +60,7 @@ import h3d.mat.Texture;
import collision.CCDCollision.TraceInfo; import collision.CCDCollision.TraceInfo;
import src.ResourceLoaderWorker; import src.ResourceLoaderWorker;
import src.InteriorObject; import src.InteriorObject;
import src.Console;
class Move { class Move {
public var d:Vector; public var d:Vector;
@ -310,6 +311,7 @@ class Marble extends GameObject {
var isUltra = level.mission.game.toLowerCase() == "ultra"; var isUltra = level.mission.game.toLowerCase() == "ultra";
var marbleDts = new DtsObject(); var marbleDts = new DtsObject();
Console.log("Marble: " + Settings.optionsSettings.marbleModel + " (" + Settings.optionsSettings.marbleSkin + ")");
marbleDts.dtsPath = Settings.optionsSettings.marbleModel; marbleDts.dtsPath = Settings.optionsSettings.marbleModel;
marbleDts.matNameOverride.set("base.marble", Settings.optionsSettings.marbleSkin + ".marble"); marbleDts.matNameOverride.set("base.marble", Settings.optionsSettings.marbleSkin + ".marble");
marbleDts.showSequences = false; marbleDts.showSequences = false;

View file

@ -19,6 +19,7 @@ import src.Util;
import src.ProfilerUI; import src.ProfilerUI;
import src.Settings; import src.Settings;
import src.Console; import src.Console;
import src.Debug;
@:publicFields @:publicFields
class MarbleGame { class MarbleGame {
@ -173,7 +174,7 @@ class MarbleGame {
touchInput.update(); touchInput.update();
} }
if (!paused) { if (!paused) {
world.update(dt); world.update(dt * Debug.timeScale);
} }
if (Key.isPressed(Key.ESCAPE) && world.finishTime == null && world._ready) { if (Key.isPressed(Key.ESCAPE) && world.finishTime == null && world._ready) {
#if hl #if hl

View file

@ -10,6 +10,7 @@ import h3d.col.Ray;
import h3d.Vector; import h3d.Vector;
import h3d.col.Sphere; import h3d.col.Sphere;
import h3d.col.Bounds; import h3d.col.Bounds;
import src.Debug;
class BoxCollisionEntity extends CollisionEntity implements IBVHObject { class BoxCollisionEntity extends CollisionEntity implements IBVHObject {
var bounds:Bounds; var bounds:Bounds;
@ -25,24 +26,28 @@ class BoxCollisionEntity extends CollisionEntity implements IBVHObject {
public override function generateBoundingBox() { public override function generateBoundingBox() {
this.boundingBox = bounds.clone(); this.boundingBox = bounds.clone();
this.boundingBox.transform(this.transform); this.boundingBox.transform(this.transform);
// if (_dbgEntity == null) { if (Debug.drawBounds) {
// _dbgEntity = this.boundingBox.makeDebugObj(); if (_dbgEntity == null) {
// _dbgEntity.getMaterials()[0].mainPass.wireframe = true; _dbgEntity = this.boundingBox.makeDebugObj();
// MarbleGame.instance.scene.addChild(_dbgEntity); _dbgEntity.getMaterials()[0].mainPass.wireframe = true;
// } else { MarbleGame.instance.scene.addChild(_dbgEntity);
// _dbgEntity = this.boundingBox.makeDebugObj(); } else {
// _dbgEntity.getMaterials()[0].mainPass.wireframe = true; _dbgEntity = this.boundingBox.makeDebugObj();
// MarbleGame.instance.scene.addChild(_dbgEntity); _dbgEntity.getMaterials()[0].mainPass.wireframe = true;
// } MarbleGame.instance.scene.addChild(_dbgEntity);
}
}
} }
public override function setTransform(transform:Matrix) { public override function setTransform(transform:Matrix) {
super.setTransform(transform); super.setTransform(transform);
// if (_dbgEntity != null) { if (Debug.drawBounds) {
// _dbgEntity = this.boundingBox.makeDebugObj(); if (_dbgEntity != null) {
// _dbgEntity.getMaterials()[0].mainPass.wireframe = true; _dbgEntity = this.boundingBox.makeDebugObj();
// MarbleGame.instance.scene.addChild(_dbgEntity); _dbgEntity.getMaterials()[0].mainPass.wireframe = true;
// } MarbleGame.instance.scene.addChild(_dbgEntity);
}
}
} }
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) { public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {

View file

@ -8,6 +8,7 @@ import h3d.Vector;
import h3d.col.Sphere; import h3d.col.Sphere;
import h3d.col.Bounds; import h3d.col.Bounds;
import src.MarbleGame; import src.MarbleGame;
import src.Debug;
class SphereCollisionEntity extends CollisionEntity { class SphereCollisionEntity extends CollisionEntity {
public var radius:Float; public var radius:Float;
@ -31,37 +32,41 @@ class SphereCollisionEntity extends CollisionEntity {
boundingBox.transform3x3(transform); boundingBox.transform3x3(transform);
this.boundingBox = boundingBox; this.boundingBox = boundingBox;
// if (_dbgEntity == null) { if (Debug.drawBounds) {
// var cube = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true); if (_dbgEntity == null) {
// cube.addNormals(); var cube = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true);
// cube.addUVs(); cube.addNormals();
// _dbgEntity = new h3d.scene.Mesh(cube); cube.addUVs();
// _dbgEntity.material.mainPass.wireframe = true; _dbgEntity = new h3d.scene.Mesh(cube);
// _dbgEntity.setTransform(transform); _dbgEntity.material.mainPass.wireframe = true;
// MarbleGame.instance.scene.addChild(_dbgEntity); _dbgEntity.setTransform(transform);
MarbleGame.instance.scene.addChild(_dbgEntity);
// var cube2 = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true); var cube2 = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true);
// cube2.addNormals(); cube2.addNormals();
// cube2.addUVs(); cube2.addUVs();
// _dbgEntity2 = new h3d.scene.Mesh(cube2); _dbgEntity2 = new h3d.scene.Mesh(cube2);
// _dbgEntity2.material.mainPass.wireframe = true; _dbgEntity2.material.mainPass.wireframe = true;
// _dbgEntity2.setTransform(transform); _dbgEntity2.setTransform(transform);
// MarbleGame.instance.scene.addChild(_dbgEntity2); MarbleGame.instance.scene.addChild(_dbgEntity2);
// } else { } else {
// _dbgEntity.setTransform(transform); _dbgEntity.setTransform(transform);
// var cube2 = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true); var cube2 = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true);
// cube2.addNormals(); cube2.addNormals();
// cube2.addUVs(); cube2.addUVs();
// _dbgEntity2.primitive = cube2; _dbgEntity2.primitive = cube2;
// _dbgEntity2.setPosition(pos.x, pos.y, pos.z); _dbgEntity2.setPosition(pos.x, pos.y, pos.z);
// } }
}
} }
public override function setTransform(transform:Matrix) { public override function setTransform(transform:Matrix) {
super.setTransform(transform); super.setTransform(transform);
// if (_dbgEntity != null) { if (Debug.drawBounds) {
// _dbgEntity.setTransform(transform); if (_dbgEntity != null) {
// } _dbgEntity.setTransform(transform);
}
}
} }
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) { public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {

View file

@ -1,5 +1,8 @@
package gui; package gui;
import hxd.Key;
import gui.GuiControl.MouseState;
import h2d.Scene;
import src.Console.ConsoleEntry; import src.Console.ConsoleEntry;
import h2d.Graphics; import h2d.Graphics;
import h2d.Tile; import h2d.Tile;
@ -14,6 +17,13 @@ class ConsoleDlg extends GuiControl {
var onConsoleEntry:(e:ConsoleEntry) -> Void; var onConsoleEntry:(e:ConsoleEntry) -> Void;
var isShowing = false; var isShowing = false;
var consoleContent:GuiMLText;
var scroll:GuiConsoleScrollCtrl;
var consoleInput:GuiTextInput;
var cmdHistory:Array<String> = [];
var cmdHistoryIndex = 0;
public function new() { public function new() {
super(); super();
this.position = new Vector(0, 0); this.position = new Vector(0, 0);
@ -28,8 +38,7 @@ class ConsoleDlg extends GuiControl {
consoleWhite.vertSizing = Top; consoleWhite.vertSizing = Top;
this.addChild(consoleWhite); this.addChild(consoleWhite);
var scroll = new GuiConsoleScrollCtrl(ResourceLoader.getResource("data/ui/common/darkscroll.png", ResourceLoader.getImage, this.imageResources) scroll = new GuiConsoleScrollCtrl(ResourceLoader.getResource("data/ui/common/darkscroll.png", ResourceLoader.getImage, this.imageResources).toTile());
.toTile());
scroll.position = new Vector(0, 0); scroll.position = new Vector(0, 0);
scroll.extent = new Vector(640, 350); scroll.extent = new Vector(640, 350);
scroll.horizSizing = Width; scroll.horizSizing = Width;
@ -46,7 +55,7 @@ class ConsoleDlg extends GuiControl {
return null; return null;
} }
var consoleContent = new GuiMLText(consoleb, mlFontLoader); consoleContent = new GuiMLText(consoleb, mlFontLoader);
consoleContent.position = new Vector(0, 0); consoleContent.position = new Vector(0, 0);
consoleContent.extent = new Vector(640, 350); consoleContent.extent = new Vector(640, 350);
consoleContent.horizSizing = Width; consoleContent.horizSizing = Width;
@ -77,7 +86,7 @@ class ConsoleDlg extends GuiControl {
bord.horizSizing = Width; bord.horizSizing = Width;
consoleContent.addChild(bord); consoleContent.addChild(bord);
var consoleInput = new GuiTextInput(arial14); consoleInput = new GuiTextInput(arial14);
consoleInput.position = new Vector(1, 351); consoleInput.position = new Vector(1, 351);
consoleInput.extent = new Vector(638, 20); consoleInput.extent = new Vector(638, 20);
consoleInput.horizSizing = Width; consoleInput.horizSizing = Width;
@ -104,4 +113,37 @@ class ConsoleDlg extends GuiControl {
super.dispose(); super.dispose();
Console.removeConsumer(onConsoleEntry); Console.removeConsumer(onConsoleEntry);
} }
public override function render(scene2d:Scene) {
super.render(scene2d);
scroll.setScrollMax(consoleContent.text.textHeight);
}
public override function update(dt:Float, mouseState:MouseState) {
super.update(dt, mouseState);
if (Key.isPressed(Key.ENTER) && consoleInput.text.text != "") {
var cmdText = consoleInput.text.text;
cmdHistory.push(cmdText);
consoleContent.text.text += '==> ${cmdText}<br/>';
Console.eval(cmdText);
consoleInput.text.text = "";
consoleInput.text.focus();
}
if (Key.isPressed(Key.UP)) {
if (cmdHistoryIndex < cmdHistory.length) {
cmdHistoryIndex++;
consoleInput.text.text = cmdHistory[cmdHistory.length - cmdHistoryIndex];
}
}
if (Key.isPressed(Key.DOWN)) {
if (cmdHistoryIndex > 1) {
cmdHistoryIndex--;
consoleInput.text.text = cmdHistory[cmdHistory.length - cmdHistoryIndex];
}
}
}
} }

View file

@ -22,6 +22,8 @@ class GuiMLText extends GuiControl {
public var scrollable:Bool = false; public var scrollable:Bool = false;
var _scroll:Float = 0;
public function new(font:h2d.Font, loadFontFunc:String->h2d.Font) { public function new(font:h2d.Font, loadFontFunc:String->h2d.Font) {
super(); super();
this.text = new HtmlText(font); this.text = new HtmlText(font);
@ -57,11 +59,12 @@ class GuiMLText extends GuiControl {
text.textAlign = Center; text.textAlign = Center;
} }
if (scrollable)
text.setPosition(0, -_scroll);
if (scene2d.contains(obj)) if (scene2d.contains(obj))
scene2d.removeChild(obj); scene2d.removeChild(obj);
scene2d.addChild(obj);
scene2d.addChild(obj); scene2d.addChild(obj);
super.render(scene2d); super.render(scene2d);
} }
@ -86,6 +89,9 @@ class GuiMLText extends GuiControl {
} }
public override function onScroll(scrollX:Float, scrollY:Float) { public override function onScroll(scrollX:Float, scrollY:Float) {
_scroll = scrollY;
text.setPosition(0, -scrollY); text.setPosition(0, -scrollY);
if (flow != null)
flow.getProperties(text).offsetY = cast - scrollY;
} }
} }

View file

@ -386,6 +386,10 @@ class MisParser {
/** Parses a boolean value. */ /** Parses a boolean value. */
public static function parseBoolean(string:String) { public static function parseBoolean(string:String) {
if (string == "true")
return true;
if (string == "false")
return false;
if (string == null) if (string == null)
return false; return false;
if (string == "") if (string == "")