From abd0f4709a02100e9a5bfaf88441aef710e9140b Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Tue, 20 Dec 2022 17:53:01 +0530 Subject: [PATCH] android attempt fixes --- src/MarbleGame.hx | 1 + src/MarbleWorld.hx | 30 ++++++++++++----- src/ResourceLoader.hx | 7 ++-- src/ResourceLoaderWorker.hx | 64 +++++++++++++++++++++++++++++++----- src/fs/ManifestBuilder.hx | 4 +-- src/fs/ManifestFileSystem.hx | 8 ++--- 6 files changed, 88 insertions(+), 26 deletions(-) diff --git a/src/MarbleGame.hx b/src/MarbleGame.hx index 01d22d7a..657909d1 100644 --- a/src/MarbleGame.hx +++ b/src/MarbleGame.hx @@ -6,6 +6,7 @@ import gui.ReplayCenterGui; #end import gui.ReplayNameDlg; import gui.ConsoleDlg; +import gui.MessageBoxOkDlg; import src.Replay; import touch.TouchInput; import src.ResourceLoader; diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 2785f4a5..e825eac1 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -8,6 +8,7 @@ import gui.MainMenuGui; import gui.ReplayCenterGui; #end import gui.ReplayNameDlg; +import gui.MessageBoxOkDlg; import collision.Collision; import shapes.MegaMarble; import shapes.Blast; @@ -254,11 +255,11 @@ class MarbleWorld extends Scheduler { scanMission(this.mission.root); this.resourceLoadFuncs.push(fwd -> this.initScene(fwd)); this.resourceLoadFuncs.push(fwd -> this.initMarble(fwd)); - this.resourceLoadFuncs.push(fwd -> { - this.addSimGroup(this.mission.root); - this._loadingLength = resourceLoadFuncs.length; - fwd(); - }); + // this.resourceLoadFuncs.push(fwd -> { + // this.addSimGroup(this.mission.root); + // this._loadingLength = resourceLoadFuncs.length; + // fwd(); + // }); this.resourceLoadFuncs.push(fwd -> this.loadMusic(fwd)); this._loadingLength = resourceLoadFuncs.length; } @@ -280,7 +281,8 @@ class MarbleWorld extends Scheduler { var musicFileName = 'data/sound/music/' + this.mission.missionInfo.music; AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources), this.mission.missionInfo.music); MarbleGame.canvas.clearContent(); - this.endPad.generateCollider(); + if (this.endPad != null) + this.endPad.generateCollider(); this.playGui.formatGemCounter(this.gemCount, this.totalGems); Console.log("MISSION LOADED"); start(); @@ -1103,11 +1105,21 @@ class MarbleWorld extends Scheduler { var func = this.resourceLoadFuncs.shift(); lock = true; #if hl - func(() -> { + try { + func(() -> { + lock = false; + this._resourcesLoaded++; + this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); + }); + } catch (e) { lock = false; this._resourcesLoaded++; - this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength)); - }); + var errorTxt = new h2d.Text(hxd.res.DefaultFont.get()); + errorTxt.setPosition(20, 20); + errorTxt.text = e.toString(); + errorTxt.textColor = 0xFFFFFF; + MarbleGame.canvas.scene2d.addChild(errorTxt); + } #end #if js func(() -> { diff --git a/src/ResourceLoader.hx b/src/ResourceLoader.hx index 4b644ba2..0a695c7b 100644 --- a/src/ResourceLoader.hx +++ b/src/ResourceLoader.hx @@ -62,12 +62,12 @@ class ResourceLoader { #if (js || android) var mfileSystem = ManifestBuilder.create("data"); var mloader:ManifestLoader = new ManifestLoader(mfileSystem); - var preloader = new ManifestProgress(mloader, () -> { loader = mloader; fileSystem = mfileSystem; onLoadedFunc(); }, scene2d); + #if js loader = mloader; fileSystem = mfileSystem; var loadg = new h2d.Text(hxd.res.DefaultFont.get()); @@ -109,7 +109,10 @@ class ResourceLoader { fwd(); }); worker.run(); - // preloader.start(); + #end + #if android + preloader.start(); + #end #end #if (hl && !android) onLoadedFunc(); diff --git a/src/ResourceLoaderWorker.hx b/src/ResourceLoaderWorker.hx index 3f192b6e..d7357398 100644 --- a/src/ResourceLoaderWorker.hx +++ b/src/ResourceLoaderWorker.hx @@ -1,6 +1,8 @@ package src; +import gui.MessageBoxOkDlg; import src.ResourceLoader; +import src.MarbleGame; class ResourceLoaderWorker { var tasks:Array<(() -> Void)->Void> = []; @@ -20,7 +22,11 @@ class ResourceLoaderWorker { } public function addTaskParallel(task:(() -> Void)->Void) { + #if (!android) paralleltasks.push(task); + #else + tasks.push(task); + #end } public function run() { @@ -41,19 +47,59 @@ class ResourceLoaderWorker { if (tasks.length > 0) { var task = tasks.shift(); - task(() -> { - if (tasks.length > 0) { - run(); - } else { - onFinish(); - } - }); + try { + task(() -> { + if (tasks.length > 0) { + run(); + } else { + onFinish(); + } + }); + } catch (e) { + var errorTxt = new h2d.Text(hxd.res.DefaultFont.get()); + errorTxt.setPosition(20, 20); + errorTxt.text = e.toString(); + errorTxt.textColor = 0xFFFFFF; + MarbleGame.canvas.scene2d.addChild(errorTxt); + } } else { - onFinish(); + try { + onFinish(); + } catch (e) { + var errorTxt = new h2d.Text(hxd.res.DefaultFont.get()); + errorTxt.setPosition(20, 20); + errorTxt.text = e.toString(); + errorTxt.textColor = 0xFFFFFF; + MarbleGame.canvas.scene2d.addChild(errorTxt); + } } } public function loadFile(path:String) { - paralleltasks.push(fwd -> ResourceLoader.load(path).entry.load(fwd)); + #if (!android) + paralleltasks.push(fwd -> { + try { + ResourceLoader.load(path).entry.load(fwd); + } catch (e) { + var errorTxt = new h2d.Text(hxd.res.DefaultFont.get()); + errorTxt.setPosition(20, 20); + errorTxt.text = e.toString(); + errorTxt.textColor = 0xFFFFFF; + MarbleGame.canvas.scene2d.addChild(errorTxt); + } + }); + #else + tasks.push(fwd -> { + try { + ResourceLoader.load(path).entry.load(fwd); + } catch (e) { + var errorTxt = new h2d.Text(hxd.res.DefaultFont.get()); + errorTxt.setPosition(20, 20); + errorTxt.text = e.toString(); + errorTxt.textColor = 0xFFFFFF; + MarbleGame.canvas.scene2d.addChild(errorTxt); + } + }); + #end } } diff --git a/src/fs/ManifestBuilder.hx b/src/fs/ManifestBuilder.hx index 577aaacb..b730e785 100644 --- a/src/fs/ManifestBuilder.hx +++ b/src/fs/ManifestBuilder.hx @@ -130,13 +130,13 @@ class ManifestBuilder { // try later with another fs if (!StringTools.startsWith(file.fullPath, basePath)) continue; - var info = {path: file.relPath.toLowerCase(), original: file.relPath}; + var info = {path: file.relPath, original: file.relPath}; out.push(info); var f = fs.get(file.relPath); // convert if (f.originalFile != null && f.originalFile != f.file) { info.original = f.relPath; info.path = StringTools.startsWith(f.file, fs.baseDir) ? f.file.substr(fs.baseDir.length) : f.file; - info.path = info.path.toLowerCase(); + info.path = info.path; } } diff --git a/src/fs/ManifestFileSystem.hx b/src/fs/ManifestFileSystem.hx index ad099099..acbb47de 100644 --- a/src/fs/ManifestFileSystem.hx +++ b/src/fs/ManifestFileSystem.hx @@ -267,7 +267,7 @@ class ManifestFileSystem implements FileSystem { } var entry:ManifestEntry = new ManifestEntry(this, Path.withoutDirectory(original), original, file, original); r.contents.push(entry); - manifest.set(path.toLowerCase(), entry); + manifest.set(path, entry); } switch (_manifest.get(0)) { @@ -298,7 +298,7 @@ class ManifestFileSystem implements FileSystem { // JSON var json:Array<{path:String, original:String}> = haxe.Json.parse(_manifest.toString()); for (entry in json) { - insert(entry.path.toLowerCase(), baseDir + entry.path, entry.original); + insert(entry.path, baseDir + entry.path, entry.original); } } } @@ -322,11 +322,11 @@ class ManifestFileSystem implements FileSystem { } public function exists(path:String) { - return find(path.toLowerCase()) != null; + return find(path) != null; } public function get(path:String) { - var entry:ManifestEntry = find(path.toLowerCase()); + var entry:ManifestEntry = find(path); if (entry == null) throw new NotFound(path); return entry;