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

View file

@ -106,7 +106,7 @@ class ManifestEntry extends FileEntry {
public function fancyLoad(onReady:() -> Void, onProgress:(cur:Int, max:Int) -> Void) { public function fancyLoad(onReady:() -> Void, onProgress:(cur:Int, max:Int) -> Void) {
#if js #if js
if (loaded) { if (loaded) {
haxe.Timer.delay(onReady, 1); onReady();
} else { } else {
var br:BinaryLoader = new BinaryLoader(file); var br:BinaryLoader = new BinaryLoader(file);
br.onLoaded = (b) -> { br.onLoaded = (b) -> {
@ -128,7 +128,7 @@ class ManifestEntry extends FileEntry {
#elseif js #elseif js
if (loaded) { if (loaded) {
if (onReady != null) if (onReady != null)
haxe.Timer.delay(onReady, 1); onReady();
} else { } else {
js.Browser.window.fetch(file).then((res:js.html.Response) -> { js.Browser.window.fetch(file).then((res:js.html.Response) -> {
return res.arrayBuffer(); return res.arrayBuffer();