From e5d1083ca13071197629620d364519ecea613dfb Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 22 Jun 2021 16:40:26 +0530 Subject: [PATCH] Fix bugs --- src/CameraController.hx | 10 ++++++++-- src/DtsObject.hx | 19 ++++++++++--------- src/MarbleGame.hx | 20 +++++++++++++++++++- src/MarbleWorld.hx | 18 ++++++++++++++++++ src/Mission.hx | 4 +++- src/collision/Collision.hx | 9 ++++++--- src/gui/ExitGameDlg.hx | 20 +++++++++++++++++++- src/shaders/Skybox.hx | 5 +++-- src/shapes/Tornado.hx | 3 +-- src/triggers/MustChangeTrigger.hx | 4 ++-- 10 files changed, 89 insertions(+), 23 deletions(-) diff --git a/src/CameraController.hx b/src/CameraController.hx index 90332107..9042adec 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -76,12 +76,18 @@ class CameraController extends Object { function onEvent(e:Event) { switch (e.kind) { case EMove: - orbit(e.relX, e.relY); - Sdl.warpMouseGlobal(cast this.screenWidth / 2, cast this.screenHeight / 2); + if (this.level.cursorLock) { + orbit(e.relX, e.relY); + lockCursor(); + } default: } } + public function lockCursor() { + Sdl.warpMouseGlobal(cast this.screenWidth / 2, cast this.screenHeight / 2); + } + function orbit(mouseX:Float, mouseY:Float) { var window = Window.getInstance(); var deltaposX = (window.width / 2) - mouseX; diff --git a/src/DtsObject.hx b/src/DtsObject.hx index ad002e02..d63a4b74 100644 --- a/src/DtsObject.hx +++ b/src/DtsObject.hx @@ -115,7 +115,7 @@ class DtsObject extends GameObject { if (level != null) this.level = level; - var isInstanced = false; + isInstanced = false; if (this.level != null) isInstanced = this.level.instanceManager.isInstanced(this) && useInstancing; if (!isInstanced) @@ -360,10 +360,10 @@ class DtsObject extends GameObject { } if (flags & 4 > 0) { material.blendMode = BlendMode.Alpha; - material.mainPass.depthWrite = false; - // material.mainPass.culling = h3d.mat.Data.Face.Front; + // mmaterial.mainPass.depthWrite = false; + material.mainPass.culling = h3d.mat.Data.Face.Front; } - // TODO TRANSPARENCY SHIT + // // TODO TRANSPARENCY SHIT if (flags & 8 > 0) { material.blendMode = BlendMode.Add; material.mainPass.setPassName("overlay"); @@ -373,11 +373,12 @@ class DtsObject extends GameObject { material.blendMode = BlendMode.Sub; if (flags & 32 > 0) { - var pbrprops = material.mainPass.getShader(h3d.shader.pbr.PropsValues); - pbrprops.emissiveValue = 1; - pbrprops.roughnessValue = 0; - pbrprops.occlusionValue = 0; - pbrprops.metalnessValue = 1; + material.mainPass.setPassName("overlay"); + // var pbrprops = material.mainPass.getShader(h3d.shader.pbr.PropsValues); + // pbrprops.emissiveValue = 1; + // pbrprops.roughnessValue = 1; + // pbrprops.occlusionValue = 0; + // pbrprops.metalnessValue = 0; } // if (this.isTSStatic && !(flags & 64 > 0)) { diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 996e681b..f6e527f9 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -1,5 +1,6 @@ package src; +import gui.PlayMissionGui; import gui.ExitGameDlg; import hxd.Key; import src.Mission; @@ -35,10 +36,27 @@ class MarbleGame { if (Key.isPressed(Key.ESCAPE)) { paused = !paused; if (paused) { - exitGameDlg = new ExitGameDlg(); + world.setCursorLock(false); + exitGameDlg = new ExitGameDlg((sender) -> { + canvas.popDialog(exitGameDlg); + paused = !paused; + world.dispose(); + world = null; + canvas.setContent(new PlayMissionGui()); + }, (sender) -> { + canvas.popDialog(exitGameDlg); + paused = !paused; + world.setCursorLock(true); + }, (sender) -> { + canvas.popDialog(exitGameDlg); + world.restart(); + world.setCursorLock(true); + paused = !paused; + }); canvas.pushDialog(exitGameDlg); } else { canvas.popDialog(exitGameDlg); + world.setCursorLock(true); } } } diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index eff1ee94..0d7c9a68 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1,5 +1,6 @@ package src; +import sdl.Cursor; import src.ForceObject; import h3d.scene.pbr.DirLight; import h3d.col.Bounds; @@ -94,6 +95,8 @@ class MarbleWorld extends Scheduler { public var totalGems:Int = 0; public var gemCount:Int = 0; + public var cursorLock:Bool = true; + var helpTextTimeState:Float = -1e8; var alertTextTimeState:Float = -1e8; @@ -862,6 +865,21 @@ class MarbleWorld extends Scheduler { // if (this.replay.mode != = 'playback') this.schedule(this.timeState.currentAttemptTime + 2, () -> this.restart()); } + + public function setCursorLock(enabled:Bool) { + this.cursorLock = enabled; + if (enabled) { + this.marble.camera.lockCursor(); + Cursor.show(false); + } else { + Cursor.show(true); + } + } + + public function dispose() { + this.playGui.dispose(); + scene.removeChildren(); + } } typedef ScheduleInfo = { diff --git a/src/Mission.hx b/src/Mission.hx index dd59d71c..9a18b1bd 100644 --- a/src/Mission.hx +++ b/src/Mission.hx @@ -62,6 +62,8 @@ class Mission { var path = StringTools.replace(rawElementPath.substring(rawElementPath.indexOf('data/')), "\"", ""); if (StringTools.contains(path, 'interiors_mbg/')) path = StringTools.replace(path, 'interiors_mbg/', 'interiors/'); - return path; + if (ResourceLoader.fileSystem.exists(path)) + return path; + return ""; } } diff --git a/src/collision/Collision.hx b/src/collision/Collision.hx index 49289b2f..dcc243eb 100644 --- a/src/collision/Collision.hx +++ b/src/collision/Collision.hx @@ -55,7 +55,7 @@ class Collision { var p = PlaneF.PointNormal(new Point3F(v0.x, v0.y, v0.z), new Point3F(normal.x, normal.y, normal.z)); var pdist = p.distance(new Point3F(center.x, center.y, center.z)); - if (pdist < 0) { + if (Math.abs(pdist) < 0.001) { return res; // Dont collide internal edges } @@ -68,8 +68,11 @@ class Collision { } if (pdist < radius) { - var t = -toDifPoint(center).dot(p.getNormal()) / p.getNormal().lengthSq(); - var pt = fromDifPoint(p.project(toDifPoint(center))); // center.add(fromDifPoint(p.getNormal().scalar(t))); + var n = normal.normalized(); + var t = center.dot(n) - v0.dot(n); + + var pt = center.sub(n.multiply(t)); + if (PointInTriangle(pt, v0, v1, v2)) { res.result = true; res.point = pt; diff --git a/src/gui/ExitGameDlg.hx b/src/gui/ExitGameDlg.hx index 38ef5f6c..d7589fbf 100644 --- a/src/gui/ExitGameDlg.hx +++ b/src/gui/ExitGameDlg.hx @@ -1,10 +1,11 @@ package gui; +import hxd.res.BitmapFont; import h3d.Vector; import src.ResourceLoader; class ExitGameDlg extends GuiControl { - public function new() { + public function new(yesFunc:GuiControl->Void, noFunc:GuiControl->Void, restartFunc:GuiControl->Void) { super(); this.horizSizing = Width; @@ -25,24 +26,41 @@ class ExitGameDlg extends GuiControl { dialogImg.position = new Vector(134, 148); dialogImg.extent = new Vector(388, 186); + var domcasual32fontdata = ResourceLoader.loader.load("data/font/DomCasual32px.fnt"); + var domcasual32 = new BitmapFont(domcasual32fontdata.entry); + @:privateAccess domcasual32.loader = ResourceLoader.loader; + + var exitGameText = new GuiText(domcasual32); + exitGameText.text.textColor = 0x000000; + exitGameText.text.text = "Exit from this Level?"; + exitGameText.justify = Center; + exitGameText.position = new Vector(95, 46); + exitGameText.extent = new Vector(198, 23); + exitGameText.horizSizing = Center; + exitGameText.vertSizing = Bottom; + var yesButton = new GuiButton(loadButtonImages("data/ui/common/yes")); yesButton.position = new Vector(47, 107); yesButton.extent = new Vector(88, 52); yesButton.vertSizing = Top; yesButton.horizSizing = Right; + yesButton.pressedAction = yesFunc; var noButton = new GuiButton(loadButtonImages("data/ui/common/no")); noButton.position = new Vector(151, 107); noButton.extent = new Vector(83, 55); noButton.vertSizing = Top; noButton.horizSizing = Right; + noButton.pressedAction = noFunc; var restartButton = new GuiButton(loadButtonImages("data/ui/common/restart")); restartButton.position = new Vector(249, 107); restartButton.extent = new Vector(103, 56); restartButton.vertSizing = Top; restartButton.horizSizing = Right; + restartButton.pressedAction = restartFunc; + dialogImg.addChild(exitGameText); dialogImg.addChild(yesButton); dialogImg.addChild(noButton); dialogImg.addChild(restartButton); diff --git a/src/shaders/Skybox.hx b/src/shaders/Skybox.hx index 5498821d..09c2f8ec 100644 --- a/src/shaders/Skybox.hx +++ b/src/shaders/Skybox.hx @@ -12,11 +12,12 @@ class Skybox extends hxsl.Shader { var view:Mat4; var proj:Mat4; }; + var projNorm:Vec3; function vertex() { - transformedNormal = transformedPosition - camera.position; + projNorm = transformedPosition - camera.position; } function fragment() { - pixelColor.rgb = texture.get(normalize(transformedNormal)).rgb; + pixelColor.rgba = texture.get(normalize(projNorm)).rgba; } } diff --git a/src/shapes/Tornado.hx b/src/shapes/Tornado.hx index 38469896..6315c704 100644 --- a/src/shapes/Tornado.hx +++ b/src/shapes/Tornado.hx @@ -7,10 +7,9 @@ class Tornado extends ForceObject { public function new() { super(); this.dtsPath = "data/shapes/hazards/tornado.dts"; - this.isCollideable = true; + this.isCollideable = false; this.isTSStatic = false; this.identifier = "Tornado"; - // this.useInstancing = false; this.forceDatas = [ { forceType: ForceSpherical, diff --git a/src/triggers/MustChangeTrigger.hx b/src/triggers/MustChangeTrigger.hx index aed9cd9d..b32ed300 100644 --- a/src/triggers/MustChangeTrigger.hx +++ b/src/triggers/MustChangeTrigger.hx @@ -14,12 +14,12 @@ class MustChangeTrigger extends Trigger { } public override function onMarbleEnter(time:TimeState) { - this.interior.setTargetTime(time, MisParser.parseNumber(this.element.targettime)); + this.interior.setTargetTime(time, MisParser.parseNumber(this.element.targettime) / 1000); if (this.element.instant == "1") { if (this.element.icontinuetottime != null && this.element.icontinuetottime != "0") { // Absolutely strange, and not sure if it's even a thing in MBG, but is implement nonetheless. this.interior.currentTime = this.interior.targetTime; - this.interior.targetTime = MisParser.parseNumber(this.element.icontinuetottime); + this.interior.targetTime = MisParser.parseNumber(this.element.icontinuetottime) / 1000; } else { this.interior.changeTime = Math.NEGATIVE_INFINITY; // "If instant is 1, the MP will warp to targetTime instantly." }