From cd3fe87fedad1d63c1dc5c36ccba4f6992dfdb30 Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 9 Jul 2024 01:36:33 +0530 Subject: [PATCH] fix some js bug and significantly speed up loading --- src/MarbleGame.hx | 7 ++++ src/MarbleWorld.hx | 65 +++++++++++++++++++++++++++++------- src/fs/ManifestFileSystem.hx | 2 +- src/fs/TorqueFileSystem.hx | 53 +++++++++++++++++++++++++++-- src/gui/MPServerDlg.hx | 1 + src/gui/PlayGui.hx | 61 ++++++++++++++++----------------- src/modes/HuntMode.hx | 1 + 7 files changed, 145 insertions(+), 45 deletions(-) diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 568f0783..76b4f7ef 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -79,6 +79,13 @@ class MarbleGame { if (!paused && world != null) { if (world.finishTime == null && world._ready && @:privateAccess !world.playGui.isChatFocused()) { if (js.Browser.document.pointerLockElement != @:privateAccess Window.getInstance().canvas) { + if (MarbleGame.canvas.children[MarbleGame.canvas.children.length - 1] is MPPreGameDlg + || (Net.isMP + && paused + && !(MarbleGame.canvas.children[MarbleGame.canvas.children.length - 1] is MPExitGameDlg))) { + return; // don't pause + } + paused = true; handlePauseGame(); // Focus the shit again diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 074a4121..13bf90b1 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -676,7 +676,9 @@ class MarbleWorld extends Scheduler { this.rewindManager.clear(); - setCursorLock(true); + if (!this.isMultiplayer || _skipPreGame) { + setCursorLock(true); + } this.timeState.currentAttemptTime = 0; this.timeState.gameplayClock = this.gameMode.getStartTime(); @@ -1354,6 +1356,8 @@ class MarbleWorld extends Scheduler { restart(marble, true); } + setCursorLock(true); + startTime = this.timeState.timeSinceLoad + 4; for (exp in explodables) { @@ -2046,22 +2050,59 @@ class MarbleWorld extends Scheduler { if (lock) return; - var func = this.resourceLoadFuncs.shift(); - lock = true; #if hl - func(() -> { - lock = false; - this._resourcesLoaded++; - this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); - }); + var loadPerTick = Math.max(1, this.resourceLoadFuncs.length / 20); + var loadedFuncs = 0; + while (this.resourceLoadFuncs.length != 0) { + var func = this.resourceLoadFuncs.shift(); + lock = true; + func(() -> { + lock = false; + this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); + this._resourcesLoaded++; + }); + loadedFuncs += 1; + if (loadedFuncs >= loadPerTick) + break; + } #end + #if js - func(() -> { - lock = false; - this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); + lock = true; + + var func = this.resourceLoadFuncs.shift(); + + var consumeFn; + consumeFn = () -> { this._resourcesLoaded++; - }); + this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); + if (this.resourceLoadFuncs.length != 0) { + var fn = this.resourceLoadFuncs.shift(); + fn(consumeFn); + } else { + lock = false; + } + } + + func(consumeFn); #end + + // var func = this.resourceLoadFuncs.shift(); + // lock = true; + // #if hl + // func(() -> { + // lock = false; + // this._resourcesLoaded++; + // this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); + // }); + // #end + // #if js + // func(() -> { + // lock = false; + // this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); + // this._resourcesLoaded++; + // }); + // #end } else { if (!this._loadBegin || lock) return; diff --git a/src/fs/ManifestFileSystem.hx b/src/fs/ManifestFileSystem.hx index ad099099..48d781bc 100644 --- a/src/fs/ManifestFileSystem.hx +++ b/src/fs/ManifestFileSystem.hx @@ -128,7 +128,7 @@ class ManifestEntry extends FileEntry { #elseif js if (loaded) { if (onReady != null) - haxe.Timer.delay(onReady, 1); + onReady(); } else { js.Browser.window.fetch(file).then((res:js.html.Response) -> { return res.arrayBuffer(); diff --git a/src/fs/TorqueFileSystem.hx b/src/fs/TorqueFileSystem.hx index 4158cba9..ed774242 100644 --- a/src/fs/TorqueFileSystem.hx +++ b/src/fs/TorqueFileSystem.hx @@ -2,8 +2,54 @@ package fs; import hxd.fs.LocalFileSystem; +#if hl +class TorqueFileEntry extends LocalEntry { + override function load(?onReady:Void->Void):Void { + #if macro + onReady(); + #else + // if (Settings.optionsSettings.fastLoad) + onReady(); + // else { + // if (onReady != null) + // haxe.Timer.delay(onReady, 1); + // } + #end + } +} +#end + class TorqueFileSystem extends LocalFileSystem { #if hl + public function new(dir:String, configuration:String) { + super(dir, configuration); + baseDir = dir; + if (configuration == null) + configuration = "default"; + + #if (macro && haxe_ver >= 4.0) + var exePath = null; + #elseif (haxe_ver >= 3.3) + var pr = Sys.programPath(); + var exePath = pr == null ? null : pr.split("\\").join("/").split("/"); + #else + var exePath = Sys.executablePath().split("\\").join("/").split("/"); + #end + + if (exePath != null) + exePath.pop(); + var froot = exePath == null ? baseDir : sys.FileSystem.fullPath(exePath.join("/") + "/" + baseDir); + if (froot == null || !sys.FileSystem.exists(froot) || !sys.FileSystem.isDirectory(froot)) { + froot = sys.FileSystem.fullPath(baseDir); + if (froot == null || !sys.FileSystem.exists(froot) || !sys.FileSystem.isDirectory(froot)) + throw "Could not find dir " + dir; + } + baseDir = froot.split("\\").join("/"); + if (!StringTools.endsWith(baseDir, "/")) + baseDir += "/"; + root = new TorqueFileEntry(this, "root", null, baseDir); + } + override function checkPath(path:String) { // make sure the file is loaded with correct case ! var baseDir = new haxe.io.Path(path).dir; @@ -12,7 +58,10 @@ class TorqueFileSystem extends LocalFileSystem { if (c == null) { isNew = true; c = new Map(); - for (f in try sys.FileSystem.readDirectory(baseDir) catch (e:Dynamic) []) + for (f in try + sys.FileSystem.readDirectory(baseDir) + catch (e:Dynamic) + []) c.set(f.toLowerCase(), true); directoryCache.set(baseDir.toLowerCase(), c); } @@ -37,7 +86,7 @@ class TorqueFileSystem extends LocalFileSystem { return null; f = f.split("\\").join("/"); if (!check || (sys.FileSystem.exists(f) && checkPath(f))) { - e = new LocalEntry(this, path.split("/").pop(), path, f); + e = new TorqueFileEntry(this, path.split("/").pop(), path, f); convert.run(e); if (e.file == null) e = null; diff --git a/src/gui/MPServerDlg.hx b/src/gui/MPServerDlg.hx index 9ee2b593..88363e2b 100644 --- a/src/gui/MPServerDlg.hx +++ b/src/gui/MPServerDlg.hx @@ -114,6 +114,7 @@ class MPServerDlg extends GuiImage { NetCommands.sendServerSettings(Settings.serverSettings.name, Settings.serverSettings.description, Settings.serverSettings.quickRespawn, Settings.serverSettings.forceSpectators, Settings.serverSettings.competitiveMode); } + Settings.save(); MarbleGame.canvas.popDialog(this); } diff --git a/src/gui/PlayGui.hx b/src/gui/PlayGui.hx index 2dcdee0c..ba2aabf1 100644 --- a/src/gui/PlayGui.hx +++ b/src/gui/PlayGui.hx @@ -206,38 +206,39 @@ class PlayGui { powerupBox = new GuiImage(ResourceLoader.getResource('data/ui/game/powerup.png', ResourceLoader.getImage, this.imageResources).toTile()); initTimer(); initGemCounter(() -> { + initCenterText(); + initPowerupBox(); + if (game == 'ultra' || Net.isMP) + initBlastBar(); + initTexts(); + if (Settings.optionsSettings.frameRateVis) + initFPSMeter(); + + if (MarbleGame.instance.world.isMultiplayer) { + initPlayerList(); + initChatHud(); + if (Net.hostSpectate || Net.clientSpectate) + initSpectatorMenu(); + + initGemCountdownTimer(); + } + + if (Util.isTouchDevice()) { + MarbleGame.instance.touchInput.showControls(this.playGuiCtrl, game == 'ultra'); + } + + playGuiCtrl.render(scene2d); + + resizeEv = () -> { + var wnd = Window.getInstance(); + playGuiCtrl.render(MarbleGame.canvas.scene2d); + powerupImageSceneTargetBitmap.x = wnd.width - 88; + }; + + Window.getInstance().addResizeEvent(resizeEv); + onFinish(); }); - initCenterText(); - initPowerupBox(); - if (game == 'ultra' || Net.isMP) - initBlastBar(); - initTexts(); - if (Settings.optionsSettings.frameRateVis) - initFPSMeter(); - - if (MarbleGame.instance.world.isMultiplayer) { - initPlayerList(); - initChatHud(); - if (Net.hostSpectate || Net.clientSpectate) - initSpectatorMenu(); - - initGemCountdownTimer(); - } - - if (Util.isTouchDevice()) { - MarbleGame.instance.touchInput.showControls(this.playGuiCtrl, game == 'ultra'); - } - - playGuiCtrl.render(scene2d); - - resizeEv = () -> { - var wnd = Window.getInstance(); - playGuiCtrl.render(MarbleGame.canvas.scene2d); - powerupImageSceneTargetBitmap.x = wnd.width - 88; - }; - - Window.getInstance().addResizeEvent(resizeEv); } public function initTimer() { diff --git a/src/modes/HuntMode.hx b/src/modes/HuntMode.hx index 22f2a087..a913257c 100644 --- a/src/modes/HuntMode.hx +++ b/src/modes/HuntMode.hx @@ -220,6 +220,7 @@ class HuntMode extends NullMode { closestSpawnIndex = i; } } + idealSpawnIndex = closestSpawnIndex; } for (i in 0...spawnPointTaken.length) { spawnPointTaken[i] = false;