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;
import mis.MisParser;
import src.Settings;
import src.Debug;
@:publicFields
class ConsoleEntry {
@ -97,4 +99,49 @@ class Console {
public static function removeConsumer(c:ConsoleEntry->Void) {
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.ResourceLoaderWorker;
import src.Console;
import src.Debug;
class DifBuilderTriangle {
public var texture:String;
@ -753,7 +754,8 @@ class DifBuilder {
material.receiveShadows = true;
}
// 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);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,8 @@
package gui;
import hxd.Key;
import gui.GuiControl.MouseState;
import h2d.Scene;
import src.Console.ConsoleEntry;
import h2d.Graphics;
import h2d.Tile;
@ -14,6 +17,13 @@ class ConsoleDlg extends GuiControl {
var onConsoleEntry:(e:ConsoleEntry) -> Void;
var isShowing = false;
var consoleContent:GuiMLText;
var scroll:GuiConsoleScrollCtrl;
var consoleInput:GuiTextInput;
var cmdHistory:Array<String> = [];
var cmdHistoryIndex = 0;
public function new() {
super();
this.position = new Vector(0, 0);
@ -28,8 +38,7 @@ class ConsoleDlg extends GuiControl {
consoleWhite.vertSizing = Top;
this.addChild(consoleWhite);
var scroll = new GuiConsoleScrollCtrl(ResourceLoader.getResource("data/ui/common/darkscroll.png", ResourceLoader.getImage, this.imageResources)
.toTile());
scroll = new GuiConsoleScrollCtrl(ResourceLoader.getResource("data/ui/common/darkscroll.png", ResourceLoader.getImage, this.imageResources).toTile());
scroll.position = new Vector(0, 0);
scroll.extent = new Vector(640, 350);
scroll.horizSizing = Width;
@ -46,7 +55,7 @@ class ConsoleDlg extends GuiControl {
return null;
}
var consoleContent = new GuiMLText(consoleb, mlFontLoader);
consoleContent = new GuiMLText(consoleb, mlFontLoader);
consoleContent.position = new Vector(0, 0);
consoleContent.extent = new Vector(640, 350);
consoleContent.horizSizing = Width;
@ -77,7 +86,7 @@ class ConsoleDlg extends GuiControl {
bord.horizSizing = Width;
consoleContent.addChild(bord);
var consoleInput = new GuiTextInput(arial14);
consoleInput = new GuiTextInput(arial14);
consoleInput.position = new Vector(1, 351);
consoleInput.extent = new Vector(638, 20);
consoleInput.horizSizing = Width;
@ -104,4 +113,37 @@ class ConsoleDlg extends GuiControl {
super.dispose();
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;
var _scroll:Float = 0;
public function new(font:h2d.Font, loadFontFunc:String->h2d.Font) {
super();
this.text = new HtmlText(font);
@ -57,11 +59,12 @@ class GuiMLText extends GuiControl {
text.textAlign = Center;
}
if (scrollable)
text.setPosition(0, -_scroll);
if (scene2d.contains(obj))
scene2d.removeChild(obj);
scene2d.addChild(obj);
scene2d.addChild(obj);
super.render(scene2d);
}
@ -86,6 +89,9 @@ class GuiMLText extends GuiControl {
}
public override function onScroll(scrollX:Float, scrollY:Float) {
_scroll = 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. */
public static function parseBoolean(string:String) {
if (string == "true")
return true;
if (string == "false")
return false;
if (string == null)
return false;
if (string == "")