improve js load time

This commit is contained in:
RandomityGuy 2024-07-09 01:46:16 +05:30
parent 4c956235e2
commit 96b5136c92
2 changed files with 23 additions and 20 deletions

View file

@ -1782,6 +1782,26 @@ class MarbleWorld extends Scheduler {
if (lock)
return;
#if js
lock = true;
var func = this.resourceLoadFuncs.shift();
var consumeFn;
consumeFn = () -> {
this._resourcesLoaded++;
if (this.resourceLoadFuncs.length != 0) {
var fn = this.resourceLoadFuncs.shift();
fn(consumeFn);
} else {
lock = false;
}
}
func(consumeFn);
#end
#if hl
if (Settings.optionsSettings.fastLoad) {
#if hl
while (this.resourceLoadFuncs.length != 0) {
@ -1793,24 +1813,6 @@ class MarbleWorld extends Scheduler {
});
}
#end
#if js
lock = true;
var func = this.resourceLoadFuncs.shift();
var consumeFn;
consumeFn = () -> {
this._resourcesLoaded++;
if (this.resourceLoadFuncs.length != 0) {
var fn = this.resourceLoadFuncs.shift();
fn(consumeFn);
} else {
lock = false;
}
}
func(consumeFn);
#end
} else {
var func = this.resourceLoadFuncs.shift();
lock = true;
@ -1827,6 +1829,7 @@ class MarbleWorld extends Scheduler {
});
#end
}
#end
} else {
if (!this._loadBegin || lock)
return;

View file

@ -106,7 +106,7 @@ class ManifestEntry extends FileEntry {
public function fancyLoad(onReady:() -> Void, onProgress:(cur:Int, max:Int) -> Void) {
#if js
if (loaded) {
haxe.Timer.delay(onReady, 1);
onReady();
} else {
var br:BinaryLoader = new BinaryLoader(file);
br.onLoaded = (b) -> {
@ -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();