mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 05:01:38 +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 (!paused && world != null) {
|
||||||
if (world.finishTime == null && world._ready && @:privateAccess !world.playGui.isChatFocused()) {
|
if (world.finishTime == null && world._ready && @:privateAccess !world.playGui.isChatFocused()) {
|
||||||
if (js.Browser.document.pointerLockElement != @:privateAccess Window.getInstance().canvas) {
|
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;
|
paused = true;
|
||||||
handlePauseGame();
|
handlePauseGame();
|
||||||
// Focus the shit again
|
// Focus the shit again
|
||||||
|
|
|
||||||
|
|
@ -676,7 +676,9 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
this.rewindManager.clear();
|
this.rewindManager.clear();
|
||||||
|
|
||||||
setCursorLock(true);
|
if (!this.isMultiplayer || _skipPreGame) {
|
||||||
|
setCursorLock(true);
|
||||||
|
}
|
||||||
|
|
||||||
this.timeState.currentAttemptTime = 0;
|
this.timeState.currentAttemptTime = 0;
|
||||||
this.timeState.gameplayClock = this.gameMode.getStartTime();
|
this.timeState.gameplayClock = this.gameMode.getStartTime();
|
||||||
|
|
@ -1354,6 +1356,8 @@ class MarbleWorld extends Scheduler {
|
||||||
restart(marble, true);
|
restart(marble, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setCursorLock(true);
|
||||||
|
|
||||||
startTime = this.timeState.timeSinceLoad + 4;
|
startTime = this.timeState.timeSinceLoad + 4;
|
||||||
|
|
||||||
for (exp in explodables) {
|
for (exp in explodables) {
|
||||||
|
|
@ -2046,22 +2050,59 @@ class MarbleWorld extends Scheduler {
|
||||||
if (lock)
|
if (lock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var func = this.resourceLoadFuncs.shift();
|
|
||||||
lock = true;
|
|
||||||
#if hl
|
#if hl
|
||||||
func(() -> {
|
var loadPerTick = Math.max(1, this.resourceLoadFuncs.length / 20);
|
||||||
lock = false;
|
var loadedFuncs = 0;
|
||||||
this._resourcesLoaded++;
|
while (this.resourceLoadFuncs.length != 0) {
|
||||||
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
|
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
|
#end
|
||||||
|
|
||||||
#if js
|
#if js
|
||||||
func(() -> {
|
lock = true;
|
||||||
lock = false;
|
|
||||||
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
|
var func = this.resourceLoadFuncs.shift();
|
||||||
|
|
||||||
|
var consumeFn;
|
||||||
|
consumeFn = () -> {
|
||||||
this._resourcesLoaded++;
|
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
|
#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 {
|
} else {
|
||||||
if (!this._loadBegin || lock)
|
if (!this._loadBegin || lock)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,54 @@ package fs;
|
||||||
|
|
||||||
import hxd.fs.LocalFileSystem;
|
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 {
|
class TorqueFileSystem extends LocalFileSystem {
|
||||||
#if hl
|
#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) {
|
override function checkPath(path:String) {
|
||||||
// make sure the file is loaded with correct case !
|
// make sure the file is loaded with correct case !
|
||||||
var baseDir = new haxe.io.Path(path).dir;
|
var baseDir = new haxe.io.Path(path).dir;
|
||||||
|
|
@ -12,7 +58,10 @@ class TorqueFileSystem extends LocalFileSystem {
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
isNew = true;
|
isNew = true;
|
||||||
c = new Map();
|
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);
|
c.set(f.toLowerCase(), true);
|
||||||
directoryCache.set(baseDir.toLowerCase(), c);
|
directoryCache.set(baseDir.toLowerCase(), c);
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +86,7 @@ class TorqueFileSystem extends LocalFileSystem {
|
||||||
return null;
|
return null;
|
||||||
f = f.split("\\").join("/");
|
f = f.split("\\").join("/");
|
||||||
if (!check || (sys.FileSystem.exists(f) && checkPath(f))) {
|
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);
|
convert.run(e);
|
||||||
if (e.file == null)
|
if (e.file == null)
|
||||||
e = null;
|
e = null;
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ class MPServerDlg extends GuiImage {
|
||||||
NetCommands.sendServerSettings(Settings.serverSettings.name, Settings.serverSettings.description, Settings.serverSettings.quickRespawn,
|
NetCommands.sendServerSettings(Settings.serverSettings.name, Settings.serverSettings.description, Settings.serverSettings.quickRespawn,
|
||||||
Settings.serverSettings.forceSpectators, Settings.serverSettings.competitiveMode);
|
Settings.serverSettings.forceSpectators, Settings.serverSettings.competitiveMode);
|
||||||
}
|
}
|
||||||
|
Settings.save();
|
||||||
MarbleGame.canvas.popDialog(this);
|
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());
|
powerupBox = new GuiImage(ResourceLoader.getResource('data/ui/game/powerup.png', ResourceLoader.getImage, this.imageResources).toTile());
|
||||||
initTimer();
|
initTimer();
|
||||||
initGemCounter(() -> {
|
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();
|
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() {
|
public function initTimer() {
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,7 @@ class HuntMode extends NullMode {
|
||||||
closestSpawnIndex = i;
|
closestSpawnIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
idealSpawnIndex = closestSpawnIndex;
|
||||||
}
|
}
|
||||||
for (i in 0...spawnPointTaken.length) {
|
for (i in 0...spawnPointTaken.length) {
|
||||||
spawnPointTaken[i] = false;
|
spawnPointTaken[i] = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue