diff --git a/src/Console.hx b/src/Console.hx index 64cdc075..0be1b7ea 100644 --- a/src/Console.hx +++ b/src/Console.hx @@ -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 "); + log("drawBounds "); + log("wireframe "); + } 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"); + } } diff --git a/src/Debug.hx b/src/Debug.hx new file mode 100644 index 00000000..34f1d427 --- /dev/null +++ b/src/Debug.hx @@ -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; +} diff --git a/src/DifBuilder.hx b/src/DifBuilder.hx index a40fe452..e353358d 100644 --- a/src/DifBuilder.hx +++ b/src/DifBuilder.hx @@ -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); } diff --git a/src/Main.hx b/src/Main.hx index 768e789c..b7ef5cf1 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -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); } diff --git a/src/Marble.hx b/src/Marble.hx index 08dace61..226784a2 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -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; diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index e8b89814..24c145f4 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -20,6 +20,7 @@ import src.Util; import src.ProfilerUI; import src.Settings; import src.Console; +import src.Debug; @:publicFields class MarbleGame { @@ -174,7 +175,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 diff --git a/src/collision/BoxCollisionEntity.hx b/src/collision/BoxCollisionEntity.hx index c8b37950..9866fc29 100644 --- a/src/collision/BoxCollisionEntity.hx +++ b/src/collision/BoxCollisionEntity.hx @@ -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) { diff --git a/src/collision/SphereCollisionEntity.hx b/src/collision/SphereCollisionEntity.hx index a813ad63..0e10d59b 100644 --- a/src/collision/SphereCollisionEntity.hx +++ b/src/collision/SphereCollisionEntity.hx @@ -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) { diff --git a/src/gui/ConsoleDlg.hx b/src/gui/ConsoleDlg.hx index 6cceb5f6..b3bb3d77 100644 --- a/src/gui/ConsoleDlg.hx +++ b/src/gui/ConsoleDlg.hx @@ -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 = []; + 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}
'; + 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]; + } + } + } } diff --git a/src/gui/GuiMLText.hx b/src/gui/GuiMLText.hx index b74612d9..9ff8ddea 100644 --- a/src/gui/GuiMLText.hx +++ b/src/gui/GuiMLText.hx @@ -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; } } diff --git a/src/mis/MisParser.hx b/src/mis/MisParser.hx index 9bc6977b..331c52fa 100644 --- a/src/mis/MisParser.hx +++ b/src/mis/MisParser.hx @@ -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 == "")