android attempt fixes

This commit is contained in:
RandomityGuy 2022-12-20 17:53:01 +05:30
parent e8b8a422f7
commit abd0f4709a
6 changed files with 88 additions and 26 deletions

View file

@ -6,6 +6,7 @@ import gui.ReplayCenterGui;
#end #end
import gui.ReplayNameDlg; import gui.ReplayNameDlg;
import gui.ConsoleDlg; import gui.ConsoleDlg;
import gui.MessageBoxOkDlg;
import src.Replay; import src.Replay;
import touch.TouchInput; import touch.TouchInput;
import src.ResourceLoader; import src.ResourceLoader;

View file

@ -8,6 +8,7 @@ import gui.MainMenuGui;
import gui.ReplayCenterGui; import gui.ReplayCenterGui;
#end #end
import gui.ReplayNameDlg; import gui.ReplayNameDlg;
import gui.MessageBoxOkDlg;
import collision.Collision; import collision.Collision;
import shapes.MegaMarble; import shapes.MegaMarble;
import shapes.Blast; import shapes.Blast;
@ -254,11 +255,11 @@ class MarbleWorld extends Scheduler {
scanMission(this.mission.root); scanMission(this.mission.root);
this.resourceLoadFuncs.push(fwd -> this.initScene(fwd)); this.resourceLoadFuncs.push(fwd -> this.initScene(fwd));
this.resourceLoadFuncs.push(fwd -> this.initMarble(fwd)); this.resourceLoadFuncs.push(fwd -> this.initMarble(fwd));
this.resourceLoadFuncs.push(fwd -> { // this.resourceLoadFuncs.push(fwd -> {
this.addSimGroup(this.mission.root); // this.addSimGroup(this.mission.root);
this._loadingLength = resourceLoadFuncs.length; // this._loadingLength = resourceLoadFuncs.length;
fwd(); // fwd();
}); // });
this.resourceLoadFuncs.push(fwd -> this.loadMusic(fwd)); this.resourceLoadFuncs.push(fwd -> this.loadMusic(fwd));
this._loadingLength = resourceLoadFuncs.length; this._loadingLength = resourceLoadFuncs.length;
} }
@ -280,7 +281,8 @@ class MarbleWorld extends Scheduler {
var musicFileName = 'data/sound/music/' + this.mission.missionInfo.music; var musicFileName = 'data/sound/music/' + this.mission.missionInfo.music;
AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources), this.mission.missionInfo.music); AudioManager.playMusic(ResourceLoader.getResource(musicFileName, ResourceLoader.getAudio, this.soundResources), this.mission.missionInfo.music);
MarbleGame.canvas.clearContent(); MarbleGame.canvas.clearContent();
this.endPad.generateCollider(); if (this.endPad != null)
this.endPad.generateCollider();
this.playGui.formatGemCounter(this.gemCount, this.totalGems); this.playGui.formatGemCounter(this.gemCount, this.totalGems);
Console.log("MISSION LOADED"); Console.log("MISSION LOADED");
start(); start();
@ -1103,11 +1105,21 @@ class MarbleWorld extends Scheduler {
var func = this.resourceLoadFuncs.shift(); var func = this.resourceLoadFuncs.shift();
lock = true; lock = true;
#if hl #if hl
func(() -> { try {
func(() -> {
lock = false;
this._resourcesLoaded++;
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
});
} catch (e) {
lock = false; lock = false;
this._resourcesLoaded++; 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 #end
#if js #if js
func(() -> { func(() -> {

View file

@ -62,12 +62,12 @@ class ResourceLoader {
#if (js || android) #if (js || android)
var mfileSystem = ManifestBuilder.create("data"); var mfileSystem = ManifestBuilder.create("data");
var mloader:ManifestLoader = new ManifestLoader(mfileSystem); var mloader:ManifestLoader = new ManifestLoader(mfileSystem);
var preloader = new ManifestProgress(mloader, () -> { var preloader = new ManifestProgress(mloader, () -> {
loader = mloader; loader = mloader;
fileSystem = mfileSystem; fileSystem = mfileSystem;
onLoadedFunc(); onLoadedFunc();
}, scene2d); }, scene2d);
#if js
loader = mloader; loader = mloader;
fileSystem = mfileSystem; fileSystem = mfileSystem;
var loadg = new h2d.Text(hxd.res.DefaultFont.get()); var loadg = new h2d.Text(hxd.res.DefaultFont.get());
@ -109,7 +109,10 @@ class ResourceLoader {
fwd(); fwd();
}); });
worker.run(); worker.run();
// preloader.start(); #end
#if android
preloader.start();
#end
#end #end
#if (hl && !android) #if (hl && !android)
onLoadedFunc(); onLoadedFunc();

View file

@ -1,6 +1,8 @@
package src; package src;
import gui.MessageBoxOkDlg;
import src.ResourceLoader; import src.ResourceLoader;
import src.MarbleGame;
class ResourceLoaderWorker { class ResourceLoaderWorker {
var tasks:Array<(() -> Void)->Void> = []; var tasks:Array<(() -> Void)->Void> = [];
@ -20,7 +22,11 @@ class ResourceLoaderWorker {
} }
public function addTaskParallel(task:(() -> Void)->Void) { public function addTaskParallel(task:(() -> Void)->Void) {
#if (!android)
paralleltasks.push(task); paralleltasks.push(task);
#else
tasks.push(task);
#end
} }
public function run() { public function run() {
@ -41,19 +47,59 @@ class ResourceLoaderWorker {
if (tasks.length > 0) { if (tasks.length > 0) {
var task = tasks.shift(); var task = tasks.shift();
task(() -> { try {
if (tasks.length > 0) { task(() -> {
run(); if (tasks.length > 0) {
} else { run();
onFinish(); } 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 { } 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) { 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
} }
} }

View file

@ -130,13 +130,13 @@ class ManifestBuilder {
// try later with another fs // try later with another fs
if (!StringTools.startsWith(file.fullPath, basePath)) if (!StringTools.startsWith(file.fullPath, basePath))
continue; continue;
var info = {path: file.relPath.toLowerCase(), original: file.relPath}; var info = {path: file.relPath, original: file.relPath};
out.push(info); out.push(info);
var f = fs.get(file.relPath); // convert var f = fs.get(file.relPath); // convert
if (f.originalFile != null && f.originalFile != f.file) { if (f.originalFile != null && f.originalFile != f.file) {
info.original = f.relPath; info.original = f.relPath;
info.path = StringTools.startsWith(f.file, fs.baseDir) ? f.file.substr(fs.baseDir.length) : f.file; 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;
} }
} }

View file

@ -267,7 +267,7 @@ class ManifestFileSystem implements FileSystem {
} }
var entry:ManifestEntry = new ManifestEntry(this, Path.withoutDirectory(original), original, file, original); var entry:ManifestEntry = new ManifestEntry(this, Path.withoutDirectory(original), original, file, original);
r.contents.push(entry); r.contents.push(entry);
manifest.set(path.toLowerCase(), entry); manifest.set(path, entry);
} }
switch (_manifest.get(0)) { switch (_manifest.get(0)) {
@ -298,7 +298,7 @@ class ManifestFileSystem implements FileSystem {
// JSON // JSON
var json:Array<{path:String, original:String}> = haxe.Json.parse(_manifest.toString()); var json:Array<{path:String, original:String}> = haxe.Json.parse(_manifest.toString());
for (entry in json) { 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) { public function exists(path:String) {
return find(path.toLowerCase()) != null; return find(path) != null;
} }
public function get(path:String) { public function get(path:String) {
var entry:ManifestEntry = find(path.toLowerCase()); var entry:ManifestEntry = find(path);
if (entry == null) if (entry == null)
throw new NotFound(path); throw new NotFound(path);
return entry; return entry;