mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-24 00:42:46 +00:00
fix some js bug and significantly speed up loading
This commit is contained in:
parent
00e4420100
commit
cd3fe87fed
7 changed files with 145 additions and 45 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ class HuntMode extends NullMode {
|
|||
closestSpawnIndex = i;
|
||||
}
|
||||
}
|
||||
idealSpawnIndex = closestSpawnIndex;
|
||||
}
|
||||
for (i in 0...spawnPointTaken.length) {
|
||||
spawnPointTaken[i] = false;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue