mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 12:41:40 +00:00
begin attempting to async js resource loading
This commit is contained in:
parent
22b9ecd172
commit
bac815ebc2
5 changed files with 150 additions and 5 deletions
|
|
@ -9,6 +9,7 @@ import hxd.res.Sound;
|
||||||
import src.Settings;
|
import src.Settings;
|
||||||
import hxd.snd.ChannelGroup;
|
import hxd.snd.ChannelGroup;
|
||||||
import src.Resource;
|
import src.Resource;
|
||||||
|
import src.ResourceLoaderWorker;
|
||||||
|
|
||||||
class AudioManager {
|
class AudioManager {
|
||||||
static var manager:hxd.snd.Manager;
|
static var manager:hxd.snd.Manager;
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ class DtsObject extends GameObject {
|
||||||
#end
|
#end
|
||||||
// Apparently creating these bitmap datas dont work so we'll just get the snag a white texture in the filesystem
|
// Apparently creating these bitmap datas dont work so we'll just get the snag a white texture in the filesystem
|
||||||
#if js
|
#if js
|
||||||
var texture:Texture = ResourceLoader.getResource("data/interiors/parts/white.jpg", ResourceLoader.getTexture, this.textureResources);
|
var texture:Texture = ResourceLoader.getResource("data/shapes/pads/white.jpg", ResourceLoader.getTexture, this.textureResources);
|
||||||
texture.wrap = Wrap.Repeat;
|
texture.wrap = Wrap.Repeat;
|
||||||
#end
|
#end
|
||||||
material.texture = texture;
|
material.texture = texture;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import hxd.fs.LocalFileSystem;
|
||||||
import hxd.fs.FileSystem;
|
import hxd.fs.FileSystem;
|
||||||
import hxd.res.Loader;
|
import hxd.res.Loader;
|
||||||
import src.Resource;
|
import src.Resource;
|
||||||
|
import src.ResourceLoaderWorker;
|
||||||
|
|
||||||
class ResourceLoader {
|
class ResourceLoader {
|
||||||
#if (hl && !android)
|
#if (hl && !android)
|
||||||
|
|
@ -45,20 +46,131 @@ class ResourceLoader {
|
||||||
haxe.MainLoop.add(() -> {});
|
haxe.MainLoop.add(() -> {});
|
||||||
#if (js || android)
|
#if (js || android)
|
||||||
var mfileSystem = ManifestBuilder.create("data");
|
var mfileSystem = ManifestBuilder.create("data");
|
||||||
var mloader = 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);
|
||||||
preloader.start();
|
loader = mloader;
|
||||||
|
fileSystem = mfileSystem;
|
||||||
|
var worker = new ResourceLoaderWorker(onLoadedFunc);
|
||||||
|
worker.addTask(fwd -> preloadUI(fwd));
|
||||||
|
worker.addTask(fwd -> preloadMisFiles(fwd));
|
||||||
|
worker.addTask(fwd -> preloadMusic(fwd));
|
||||||
|
worker.addTask(fwd -> preloadUISounds(fwd));
|
||||||
|
worker.addTask(fwd -> preloadShapes(fwd));
|
||||||
|
worker.run();
|
||||||
|
// preloader.start();
|
||||||
#end
|
#end
|
||||||
#if (hl && !android)
|
#if (hl && !android)
|
||||||
onLoadedFunc();
|
onLoadedFunc();
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function preloadUI(onFinish:Void->Void) {
|
||||||
|
var toloadfiles = [];
|
||||||
|
var toloaddirs = [];
|
||||||
|
var filestats = fileSystem.dir("font").concat(fileSystem.dir("ui"));
|
||||||
|
for (file in filestats) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
toloaddirs.push(file);
|
||||||
|
} else {
|
||||||
|
toloadfiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (toloaddirs.length > 0) {
|
||||||
|
var nextdir = toloaddirs.pop();
|
||||||
|
for (file in fileSystem.dir(nextdir.path.substring(2))) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
toloaddirs.push(file);
|
||||||
|
} else {
|
||||||
|
toloadfiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var worker = new ResourceLoaderWorker(onFinish);
|
||||||
|
for (file in toloadfiles) {
|
||||||
|
worker.addTask((fwd) -> file.load(fwd));
|
||||||
|
}
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function preloadMisFiles(onFinish:Void->Void) {
|
||||||
|
var toloadfiles = [];
|
||||||
|
var toloaddirs = [];
|
||||||
|
var filestats = fileSystem.dir("missions");
|
||||||
|
for (file in filestats) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
toloaddirs.push(file);
|
||||||
|
} else {
|
||||||
|
toloadfiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (toloaddirs.length > 0) {
|
||||||
|
var nextdir = toloaddirs.pop();
|
||||||
|
for (file in fileSystem.dir(nextdir.path.substring(2))) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
toloaddirs.push(file);
|
||||||
|
} else {
|
||||||
|
if (file.extension == "mis")
|
||||||
|
toloadfiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var worker = new ResourceLoaderWorker(onFinish);
|
||||||
|
for (file in toloadfiles) {
|
||||||
|
worker.addTask((fwd) -> file.load(fwd));
|
||||||
|
}
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function preloadMusic(onFinish:Void->Void) {
|
||||||
|
var worker = new ResourceLoaderWorker(onFinish);
|
||||||
|
worker.loadFile("sound/shell.ogg");
|
||||||
|
worker.loadFile("sound/groovepolice.ogg");
|
||||||
|
worker.loadFile("sound/classic vibe.ogg");
|
||||||
|
worker.loadFile("sound/beach party.ogg");
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function preloadUISounds(onFinish:Void->Void) {
|
||||||
|
var worker = new ResourceLoaderWorker(onFinish);
|
||||||
|
worker.loadFile("sound/testing.wav");
|
||||||
|
worker.loadFile("sound/buttonover.wav");
|
||||||
|
worker.loadFile("sound/buttonpress.wav");
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
static function preloadShapes(onFinish:Void->Void) {
|
||||||
|
var toloadfiles = [];
|
||||||
|
var toloaddirs = [];
|
||||||
|
var filestats = fileSystem.dir("shapes");
|
||||||
|
for (file in filestats) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
toloaddirs.push(file);
|
||||||
|
} else {
|
||||||
|
toloadfiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (toloaddirs.length > 0) {
|
||||||
|
var nextdir = toloaddirs.pop();
|
||||||
|
for (file in fileSystem.dir(nextdir.path.substring(2))) {
|
||||||
|
if (file.isDirectory) {
|
||||||
|
toloaddirs.push(file);
|
||||||
|
} else {
|
||||||
|
toloadfiles.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var worker = new ResourceLoaderWorker(onFinish);
|
||||||
|
for (file in toloadfiles) {
|
||||||
|
worker.addTask((fwd) -> file.load(fwd));
|
||||||
|
}
|
||||||
|
worker.run();
|
||||||
|
}
|
||||||
|
|
||||||
public static function loadInterior(path:String) {
|
public static function loadInterior(path:String) {
|
||||||
#if (js || android)
|
#if (js || android)
|
||||||
path = StringTools.replace(path, "data/", "");
|
path = StringTools.replace(path, "data/", "");
|
||||||
|
|
|
||||||
32
src/ResourceLoaderWorker.hx
Normal file
32
src/ResourceLoaderWorker.hx
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package src;
|
||||||
|
|
||||||
|
import src.ResourceLoader;
|
||||||
|
|
||||||
|
class ResourceLoaderWorker {
|
||||||
|
var tasks:Array<(() -> Void)->Void> = [];
|
||||||
|
|
||||||
|
var onFinish:() -> Void;
|
||||||
|
|
||||||
|
public function new(onFinish:() -> Void) {
|
||||||
|
this.onFinish = onFinish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addTask(task:(() -> Void)->Void) {
|
||||||
|
tasks.push(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run() {
|
||||||
|
var task = tasks.shift();
|
||||||
|
task(() -> {
|
||||||
|
if (tasks.length > 0) {
|
||||||
|
run();
|
||||||
|
} else {
|
||||||
|
onFinish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function loadFile(path:String) {
|
||||||
|
addTask(fwd -> ResourceLoader.loader.load(path).entry.load(fwd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -61,8 +61,8 @@ class GuiTextInput extends GuiControl {
|
||||||
if (Util.isTouchDevice()) {
|
if (Util.isTouchDevice()) {
|
||||||
text.text = js.Browser.window.prompt("Enter your name", text.text);
|
text.text = js.Browser.window.prompt("Enter your name", text.text);
|
||||||
var canvas = js.Browser.document.querySelector("#webgl");
|
var canvas = js.Browser.document.querySelector("#webgl");
|
||||||
canvas.focus();
|
// canvas.focus();
|
||||||
js.Browser.document.documentElement.requestFullscreen();
|
// js.Browser.document.documentElement.requestFullscreen();
|
||||||
}
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue