From f291eeb853494f3b78f66c4cd01a952ff8b8a4d2 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:17:55 +0530 Subject: [PATCH] more console support --- src/Console.hx | 12 ++++++++++ src/DifBuilder.hx | 2 ++ src/DtsObject.hx | 39 ++++---------------------------- src/InstanceManager.hx | 4 ++-- src/Main.hx | 32 ++++++++++++++++++-------- src/MarbleGame.hx | 2 +- src/MarbleWorld.hx | 8 +++++++ src/MissionList.hx | 14 ++++++++++++ src/ParticleSystem.hx | 2 ++ src/PathedInterior.hx | 3 --- src/Replay.hx | 3 +++ src/Resource.hx | 1 - src/ResourceLoader.hx | 5 ---- src/Settings.hx | 1 + src/Sky.hx | 2 ++ src/collision/CollisionEntity.hx | 12 ---------- src/gui/ConsoleDlg.hx | 1 - src/gui/GuiConsoleScrollCtrl.hx | 7 ++++-- src/gui/GuiControl.hx | 4 ++++ src/triggers/TeleportTrigger.hx | 6 +++++ 20 files changed, 88 insertions(+), 72 deletions(-) diff --git a/src/Console.hx b/src/Console.hx index 186f5186..64cdc075 100644 --- a/src/Console.hx +++ b/src/Console.hx @@ -1,5 +1,7 @@ package src; +import src.Settings; + @:publicFields class ConsoleEntry { var time:Float; @@ -21,6 +23,10 @@ class Console { var consumers:ArrayVoid>; var timeSinceStart:Float; + #if hl + var consoleFileHandle:sys.io.FileOutput; + #end + public function new() { if (instance == null) { instance = this; @@ -28,6 +34,9 @@ class Console { entries = []; consumers = []; timeSinceStart = haxe.Timer.stamp(); + #if hl + consoleFileHandle = sys.io.File.write(haxe.io.Path.join([Settings.settingsDir, "console.log"]), false); + #end } public function clear() { @@ -41,6 +50,9 @@ class Console { function addEntry(type:String, msg:String) { var e = new ConsoleEntry(getTime(), type, msg); entries.push(e); + #if hl + consoleFileHandle.writeString('[${e.time}] ${e.text}\n'); + #end for (c in consumers) { c(e); } diff --git a/src/DifBuilder.hx b/src/DifBuilder.hx index 0921e5bb..a40fe452 100644 --- a/src/DifBuilder.hx +++ b/src/DifBuilder.hx @@ -31,6 +31,7 @@ import dif.Dif; import src.InteriorObject; import src.MarbleGame; import src.ResourceLoaderWorker; +import src.Console; class DifBuilderTriangle { public var texture:String; @@ -746,6 +747,7 @@ class DifBuilder { material.receiveShadows = true; } } else { + Console.warn('Unable to load ${grp} texture for dif ${path}'); material = Material.create(); material.shadows = false; material.receiveShadows = true; diff --git a/src/DtsObject.hx b/src/DtsObject.hx index fca3e181..d65e94e2 100644 --- a/src/DtsObject.hx +++ b/src/DtsObject.hx @@ -33,6 +33,7 @@ import dts.DtsFile; import h3d.Matrix; import src.Util; import src.Resource; +import src.Console; var DROP_TEXTURE_FOR_ENV_MAP = ['shapes/items/superjump.dts', 'shapes/items/antigravity.dts']; @@ -373,6 +374,7 @@ class DtsObject extends GameObject { if (fullName == null || (this.isTSStatic && ((flags & (1 << 31) > 0)))) { if (this.isTSStatic) { + Console.warn('Unsupported material type for ${fullName}, dts: ${this.dtsPath}'); // TODO USE PBR??? } } else if (Path.extension(fullName) == "ifl") { @@ -417,6 +419,7 @@ class DtsObject extends GameObject { var texture:Texture = ResourceLoader.getResource("data/shapes/pads/white.jpg", ResourceLoader.getTexture, this.textureResources); texture.wrap = Wrap.Repeat; #end + Console.warn('Unable to load ${matName}'); material.texture = texture; dtsshader.texture = texture; material.mainPass.addShader(dtsshader); @@ -461,6 +464,7 @@ class DtsObject extends GameObject { if (this.materials.length == 0) { var mat = Material.create(); this.materials.push(mat); + Console.warn('No materials found for ${this.dtsPath}}'); // TODO THIS } } @@ -655,41 +659,6 @@ class DtsObject extends GameObject { return materialGeometry; } - function mergeMaterialGeometries(materialGeometries:Array>) { - var merged = materialGeometries[0].map(x -> { - vertices: [], - normals: [], - uvs: [], - indices: [] - }); - - for (matGeom in materialGeometries) { - for (i in 0...matGeom.length) { - merged[i].vertices = merged[i].vertices.concat(matGeom[i].vertices); - merged[i].normals = merged[i].normals.concat(matGeom[i].normals); - merged[i].uvs = merged[i].uvs.concat(matGeom[i].uvs); - merged[i].indices = merged[i].indices.concat(matGeom[i].indices); - } - } - - return merged; - } - - function createGeometryFromMaterialGeometry(materialGeometry:Array) { - var geo = new Object(); - for (i in 0...materialGeometry.length) { - if (materialGeometry[i].vertices.length == 0) - continue; - - var poly = new Polygon(materialGeometry[i].vertices.map(x -> x.toPoint())); - poly.normals = materialGeometry[i].normals.map(x -> x.toPoint()); - poly.uvs = materialGeometry[i].uvs; - - var obj = new Mesh(poly, materials[i], geo); - } - return geo; - } - public override function setTransform(mat:Matrix) { super.setTransform(mat); if (this.isBoundingBoxCollideable) { diff --git a/src/InstanceManager.hx b/src/InstanceManager.hx index dda49732..d67506cc 100644 --- a/src/InstanceManager.hx +++ b/src/InstanceManager.hx @@ -75,7 +75,7 @@ class InstanceManager { minfo.meshbatch.shadersChanged = true; minfo.meshbatch.material.mainPass.setPassName(minfo.mesh.material.mainPass.name); minfo.meshbatch.material.mainPass.enableLights = minfo.mesh.material.mainPass.enableLights; - minfo.meshbatch.setTransform(transform); + minfo.meshbatch.worldPosition = transform; minfo.meshbatch.emitInstance(); } } @@ -98,7 +98,7 @@ class InstanceManager { // minfo.transparencymeshbatch.shadersChanged = true; // } var transform = instance.emptyObj.getAbsPos(); - minfo.transparencymeshbatch.setTransform(transform); + minfo.transparencymeshbatch.worldPosition = transform; minfo.transparencymeshbatch.emitInstance(); } } diff --git a/src/Main.hx b/src/Main.hx index 06882c5e..768e789c 100644 --- a/src/Main.hx +++ b/src/Main.hx @@ -65,17 +65,23 @@ class Main extends hxd.App { Console.log("System: " + Sys.systemName()); #end - Settings.init(); - ResourceLoader.init(s2d, () -> { - AudioManager.init(); - AudioManager.playShell(); - marbleGame = new MarbleGame(s2d, s3d); - MarbleGame.canvas.setContent(new MainMenuGui()); + try { + Settings.init(); + ResourceLoader.init(s2d, () -> { + AudioManager.init(); + AudioManager.playShell(); + marbleGame = new MarbleGame(s2d, s3d); + MarbleGame.canvas.setContent(new MainMenuGui()); - new ProfilerUI(s2d); + new ProfilerUI(s2d); - loaded = true; - }); + loaded = true; + }); + } catch (e) { + Console.error(e.message); + Console.error(e.stack.toString()); + throw e; + } // ResourceLoader.init(s2d, () -> { // Settings.init(); @@ -103,7 +109,13 @@ class Main extends hxd.App { if (loaded) { ProfilerUI.begin(); ProfilerUI.measure("updateBegin"); - marbleGame.update(dt); + 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/MarbleGame.hx b/src/MarbleGame.hx index 536853d8..e8b89814 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -193,7 +193,7 @@ class MarbleGame { if (Key.isPressed(Key.QWERTY_TILDE)) { consoleShown = !consoleShown; if (consoleShown) { - if (console == null) + if (console == null || @:privateAccess console._disposed) console = new ConsoleDlg(); @:privateAccess console.isShowing = true; canvas.pushDialog(console); diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index ed4a07bd..2c95aeb6 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -259,6 +259,7 @@ class MarbleWorld extends Scheduler { if (this.endPad != null) this.endPad.generateCollider(); this.playGui.formatGemCounter(this.gemCount, this.totalGems); + Console.log("MISSION LOADED"); start(); } @@ -404,6 +405,7 @@ class MarbleWorld extends Scheduler { } public function restart(full:Bool = false) { + Console.log("LEVEL RESTART"); if (!full && this.currentCheckpoint != null) { this.loadCheckpointState(); return 0; // Load checkpoint @@ -918,6 +920,7 @@ class MarbleWorld extends Scheduler { } else if (datablockLowercase == "checkpointtrigger") { trigger = new CheckpointTrigger(element, cast this); } else { + Console.error("Unknown trigger: " + element.datablock); onFinish(); return; } @@ -1700,6 +1703,7 @@ class MarbleWorld extends Scheduler { if (this.marble.heldPowerup != null) if (this.marble.heldPowerup.identifier == powerUp.identifier) return false; + Console.log("PowerUp pickup: " + powerUp.identifier); this.marble.heldPowerup = powerUp; this.playGui.setPowerupImage(powerUp.identifier); MarbleGame.instance.touchInput.powerupButton.setEnabled(true); @@ -1881,6 +1885,10 @@ class MarbleWorld extends Scheduler { this.marble.setPosition(mpos.x, mpos.y, mpos.z); marble.velocity.load(new Vector(0, 0, 0)); marble.omega.load(new Vector(0, 0, 0)); + Console.log('Respawn:'); + Console.log('Marble Position: ${mpos.x} ${mpos.y} ${mpos.z}'); + Console.log('Marble Velocity: ${marble.velocity.x} ${marble.velocity.y} ${marble.velocity.z}'); + Console.log('Marble Angular: ${marble.omega.x} ${marble.omega.y} ${marble.omega.z}'); // Set camera orientation var euler = this.currentCheckpoint.obj.getRotationQuat().toEuler(); this.marble.camera.CameraYaw = euler.z + Math.PI / 2; diff --git a/src/MissionList.hx b/src/MissionList.hx index 8b342eec..7ab46634 100644 --- a/src/MissionList.hx +++ b/src/MissionList.hx @@ -2,6 +2,7 @@ import haxe.Json; import mis.MisParser; import src.ResourceLoader; import src.Mission; +import src.Console; @:publicFields class MissionList { @@ -92,6 +93,19 @@ class MissionList { missionList.set("platinum", platinumMissions); missionList.set("ultra", ultraMissions); + Console.log("Loaded MissionList"); + Console.log("Gold Beginner: " + goldMissions["beginner"].length); + Console.log("Gold Intermediate: " + goldMissions["intermediate"].length); + Console.log("Gold Advanced: " + goldMissions["advanced"].length); + Console.log("Platinum Beginner: " + platinumMissions["beginner"].length); + Console.log("Platinum Intermediate: " + platinumMissions["intermediate"].length); + Console.log("Platinum Advanced: " + platinumMissions["advanced"].length); + Console.log("Platinum Expert: " + platinumMissions["expert"].length); + Console.log("Ultra Beginner: " + ultraMissions["beginner"].length); + Console.log("Ultra Intermediate: " + ultraMissions["intermediate"].length); + Console.log("Ultra Advanced: " + ultraMissions["advanced"].length); + Console.log("Custom: " + customMissions.length); + // parseCLAList(); _build = true; diff --git a/src/ParticleSystem.hx b/src/ParticleSystem.hx index f0f01d70..3f5dcf94 100644 --- a/src/ParticleSystem.hx +++ b/src/ParticleSystem.hx @@ -21,6 +21,7 @@ import h3d.Vector; import h3d.scene.MeshBatch; import h3d.scene.Mesh; import src.ResourceLoader; +import src.Console; @:publicFields class ParticleData { @@ -303,6 +304,7 @@ class ParticleManager { var emitters:Array = []; public function new(level:MarbleWorld) { + Console.log("Initializing Particle Manager"); this.level = level; this.scene = level.scene; } diff --git a/src/PathedInterior.hx b/src/PathedInterior.hx index 909b263f..4c8ade16 100644 --- a/src/PathedInterior.hx +++ b/src/PathedInterior.hx @@ -74,9 +74,6 @@ class PathedInterior extends InteriorObject { pathedInterior.simGroup = simGroup; pathedInterior.element = interiorElement; level.interiors.push(pathedInterior); - // await - // Util.wait(10); // See shapes for the meaning of this hack - // await pathedInterior.init(level, () -> { onFinish(pathedInterior); }); diff --git a/src/Replay.hx b/src/Replay.hx index b4b99990..a38c5c43 100644 --- a/src/Replay.hx +++ b/src/Replay.hx @@ -11,6 +11,7 @@ import haxe.EnumFlags; import h3d.Quat; import h3d.Vector; import src.Util; +import src.Console; enum ReplayMarbleState { UsedPowerup; @@ -429,8 +430,10 @@ class Replay { } public function read(data:Bytes) { + Console.log("Loading replay"); var replayVersion = data.get(0); if (replayVersion > version) { + Console.log("Replay loading failed: unknown version"); return false; } var uncompressedLength = data.getInt32(1); diff --git a/src/Resource.hx b/src/Resource.hx index 14292ee6..7054b42d 100644 --- a/src/Resource.hx +++ b/src/Resource.hx @@ -25,7 +25,6 @@ class Resource { public function release() { this.referenceCount--; if (this.referenceCount == 0) { - Console.log("Freeing: " + identifier); disposeFunc(this.resource); this.resourceMap.remove(this.identifier); // trace('Releasing Resource ${this.identifier}'); diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index 626e2c1b..56049af0 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -283,7 +283,6 @@ class ResourceLoader { if (interiorResources.exists(path)) return interiorResources.get(path); else { - Console.log("Load Interior: " + path); var itr:Dif; // var lock = new Lock(); // threadPool.run(() -> { @@ -302,7 +301,6 @@ class ResourceLoader { if (dtsResources.exists(path)) return dtsResources.get(path); else { - Console.log("Load DTS: " + path); var dts = new DtsFile(); // var lock = new Lock(); // threadPool.run(() -> { @@ -321,7 +319,6 @@ class ResourceLoader { if (textureCache.exists(path)) return textureCache.get(path); if (fileSystem.exists(path)) { - Console.log("Load Texture: " + path); var img = loader.load(path).toImage(); Image.setupTextureFlags = (texObj) -> { texObj.flags.set(MipMapped); @@ -345,7 +342,6 @@ class ResourceLoader { if (imageCache.exists(path)) return imageCache.get(path); if (fileSystem.exists(path)) { - Console.log("Load Image: " + path); var tex = loader.load(path).toImage(); var imageresource = new Resource(tex, path, imageCache, img -> {}); imageCache.set(path, imageresource); @@ -361,7 +357,6 @@ class ResourceLoader { if (audioCache.exists(path)) return audioCache.get(path); if (fileSystem.exists(path)) { - Console.log("Load Audio: " + path); var snd = loader.load(path).toSound(); // @:privateAccess snd.watchCallb(); var audioresource = new Resource(snd, path, audioCache, snd -> snd.dispose()); diff --git a/src/Settings.hx b/src/Settings.hx index c9d43e4c..75a3e4a4 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -272,6 +272,7 @@ class Settings { FileSystem.createDirectory(settingsDir); } File.saveContent(Path.join([settingsDir, "settings.json"]), json); + Console.log("Saved settings to " + Path.join([settingsDir, "settings.json"])); #end #if android saveAndroid('settings', json); diff --git a/src/Sky.hx b/src/Sky.hx index b072a73f..df1ec1e0 100644 --- a/src/Sky.hx +++ b/src/Sky.hx @@ -16,6 +16,7 @@ import h3d.scene.Object; import src.Resource; import hxd.res.Image; import src.ResourceLoaderWorker; +import src.Console; class Sky extends Object { public var dmlPath:String; @@ -101,6 +102,7 @@ class Sky extends Object { skyboxImages.push(pixels); // var tex = new h3d.mat.Texture(); // skyboxImages.push(new BitmapData(128, 128)); + Console.error("Skybox image " + filenames[0] + " does not exist"); } else { var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toBitmap(); var pixels = image.getPixels(); diff --git a/src/collision/CollisionEntity.hx b/src/collision/CollisionEntity.hx index b12c9167..46120a31 100644 --- a/src/collision/CollisionEntity.hx +++ b/src/collision/CollisionEntity.hx @@ -152,18 +152,6 @@ class CollisionEntity implements IOctreeObject implements IBVHObject { var tform = transform.clone(); // tform.setPosition(tform.getPosition().add(this.velocity.multiply(timeState.dt))); - function toDifPoint(pt:Vector) { - return new Point3F(pt.x, pt.y, pt.z); - } - - function fromDifPoint(pt:Point3F) { - return new Vector(pt.x, pt.y, pt.z); - } - - function hashEdge(i1:Int, i2:Int) { - return i1 >= i2 ? i1 * i1 + i1 + i2 : i1 + i2 * i2; - } - var contacts = []; for (obj in surfaces) { diff --git a/src/gui/ConsoleDlg.hx b/src/gui/ConsoleDlg.hx index 94ec1e68..6cceb5f6 100644 --- a/src/gui/ConsoleDlg.hx +++ b/src/gui/ConsoleDlg.hx @@ -94,7 +94,6 @@ class ConsoleDlg extends GuiControl { consoleContent.text.text += txt; if (isShowing) { scroll.setScrollMax(consoleContent.text.textHeight); - haxe.Timer.delay(() -> scroll.setScrollPercentage(1), 1); } }; diff --git a/src/gui/GuiConsoleScrollCtrl.hx b/src/gui/GuiConsoleScrollCtrl.hx index 14653fae..91a75441 100644 --- a/src/gui/GuiConsoleScrollCtrl.hx +++ b/src/gui/GuiConsoleScrollCtrl.hx @@ -76,7 +76,7 @@ class GuiConsoleScrollCtrl extends GuiControl { this.scrollBarY = new Graphics(); this.scrollBarY.scale(Settings.uiScale); - this.clickInteractive = new Interactive(10 * Settings.uiScale, 1); + this.clickInteractive = new Interactive(18 * Settings.uiScale, 1); this.clickInteractive.onPush = (e) -> { if (!this.pressed) { this.pressed = true; @@ -111,7 +111,10 @@ class GuiConsoleScrollCtrl extends GuiControl { } public function setScrollMax(max:Float) { - this.scrollY = 0; + var renderRect = this.getRenderRectangle(); + var scrollExtentY = renderRect.extent.y - 34 * Settings.uiScale; + var scrollBarYSize = (scrollExtentY * scrollExtentY / (maxScrollY * Settings.uiScale - 34 * Settings.uiScale)); + this.scrollY = scrollExtentY - scrollBarYSize * Settings.uiScale; this.maxScrollY = max; this.dirty = true; this.updateScrollVisual(); diff --git a/src/gui/GuiControl.hx b/src/gui/GuiControl.hx index 383a9810..529d3768 100644 --- a/src/gui/GuiControl.hx +++ b/src/gui/GuiControl.hx @@ -53,6 +53,8 @@ class GuiControl { var textureResources:Array> = []; var soundResources:Array> = []; + var _disposed = false; + public function new() {} public function render(scene2d:Scene) { @@ -240,6 +242,8 @@ class GuiControl { for (audioResource in soundResources) { audioResource.release(); } + + _disposed = true; } public function onMouseDown(mouseState:MouseState) {} diff --git a/src/triggers/TeleportTrigger.hx b/src/triggers/TeleportTrigger.hx index 2ca14a0a..018fc588 100644 --- a/src/triggers/TeleportTrigger.hx +++ b/src/triggers/TeleportTrigger.hx @@ -6,6 +6,7 @@ import src.AudioManager; import mis.MisParser; import src.MarbleWorld; import mis.MissionElement.MissionElementTrigger; +import src.Console; class TeleportTrigger extends Trigger { var delay:Float = 2; @@ -103,6 +104,11 @@ class TeleportTrigger extends Trigger { if (!MisParser.parseBoolean(chooseNonNull(this.element.keepangular, destination.element.keepangular))) this.level.marble.omega.set(0, 0, 0); + Console.log('Teleport:'); + Console.log('Marble Position: ${position.x} ${position.y} ${position.z}'); + Console.log('Marble Velocity: ${this.level.marble.velocity.x} ${this.level.marble.velocity.y} ${this.level.marble.velocity.z}'); + Console.log('Marble Angular: ${this.level.marble.omega.x} ${this.level.marble.omega.y} ${this.level.marble.omega.z}'); + // Determine camera orientation if (!MisParser.parseBoolean(chooseNonNull(this.element.keepcamera, destination.element.keepcamera))) { var yaw:Float;