mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-06-12 11:31:34 +00:00
- fix some loading issues on web
- now properly load bitmaps via browser api instead for js - fix negative material values not handled - fix multiplayer not loading with multiple people on web
This commit is contained in:
parent
786dcb169e
commit
9b4d8a9b5e
5 changed files with 61 additions and 14 deletions
|
|
@ -425,7 +425,6 @@ class DtsObject extends GameObject {
|
|||
var textures = [];
|
||||
for (keyframe in keyframes) {
|
||||
var texture = ResourceLoader.getResource(this.directoryPath + '/' + keyframe, ResourceLoader.getTexture, this.textureResources);
|
||||
texture.realloc(); // alloc this in gpu!
|
||||
textures.push(texture);
|
||||
}
|
||||
this.materialInfos.set(material, textures);
|
||||
|
|
|
|||
|
|
@ -142,7 +142,17 @@ class ResourceLoader {
|
|||
}
|
||||
var worker = new ResourceLoaderWorker(onFinish);
|
||||
for (file in toloadfiles) {
|
||||
worker.addTaskParallel((fwd) -> file.load(fwd));
|
||||
worker.addTaskParallel((fwd) -> {
|
||||
// if its a jpg, png or gif, load it as bitmap else load as file
|
||||
var fileExtension = file.extension.toLowerCase();
|
||||
if (fileExtension == "jpg" || fileExtension == "png" || fileExtension == "bmp") {
|
||||
file.loadBitmap(v -> {
|
||||
fwd();
|
||||
});
|
||||
} else {
|
||||
file.load(fwd);
|
||||
}
|
||||
});
|
||||
}
|
||||
worker.run();
|
||||
}
|
||||
|
|
@ -567,15 +577,20 @@ class ResourceLoader {
|
|||
if (zipFilesystem.exists(path.toLowerCase() + ".dds")) {
|
||||
return [path + ".dds"];
|
||||
}
|
||||
var files = fileSystem.dir(Path.directory(path)); // FileSystem.readDirectory(Path.directory(path));
|
||||
var names = [];
|
||||
var fname = Path.withoutDirectory(path).toLowerCase();
|
||||
for (file in files) {
|
||||
var fname2 = file.name;
|
||||
if (Path.withoutExtension(fname2).toLowerCase() == fname || fname2.toLowerCase() == fname)
|
||||
names.push(file.path);
|
||||
var dirPath = Path.directory(path);
|
||||
if (fileSystem.exists(dirPath)) {
|
||||
var files = fileSystem.dir(Path.directory(path)); // FileSystem.readDirectory(Path.directory(path));
|
||||
var names = [];
|
||||
var fname = Path.withoutDirectory(path).toLowerCase();
|
||||
for (file in files) {
|
||||
var fname2 = file.name;
|
||||
if (Path.withoutExtension(fname2).toLowerCase() == fname || fname2.toLowerCase() == fname)
|
||||
names.push(file.path);
|
||||
}
|
||||
return names;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
public static function loadZip(entries:Array<haxe.zip.Entry>, game:String) {
|
||||
|
|
|
|||
|
|
@ -28,13 +28,22 @@ class ResourceLoaderWorker {
|
|||
parallelstarted = true;
|
||||
var taskcount = paralleltasks.length;
|
||||
var tasksdone = 0;
|
||||
var doneTasks = new Map();
|
||||
var i = 0;
|
||||
for (task in paralleltasks) {
|
||||
var taskIndex = i;
|
||||
task(() -> {
|
||||
tasksdone++;
|
||||
if (doneTasks.exists(taskIndex)) {
|
||||
trace('Warning: Task already marked as done!');
|
||||
} else {
|
||||
doneTasks.set(taskIndex, true);
|
||||
tasksdone++;
|
||||
}
|
||||
if (tasksdone == taskcount) {
|
||||
this.run();
|
||||
}
|
||||
});
|
||||
i++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -54,6 +63,22 @@ class ResourceLoaderWorker {
|
|||
}
|
||||
|
||||
public function loadFile(path:String) {
|
||||
paralleltasks.push(fwd -> ResourceLoader.load(path).entry.load(fwd));
|
||||
// if its a jpg, png or gif, load it as bitmap else load as file
|
||||
var fileExtension = path.split('.').pop();
|
||||
if (fileExtension != null) {
|
||||
fileExtension = fileExtension.toLowerCase();
|
||||
if (fileExtension == "jpg" || fileExtension == "png" || fileExtension == "bmp") {
|
||||
paralleltasks.push(fwd -> {
|
||||
var file = ResourceLoader.load(path);
|
||||
file.entry.loadBitmap(v -> {
|
||||
fwd();
|
||||
});
|
||||
});
|
||||
} else if (fileExtension != "") {
|
||||
paralleltasks.push(fwd -> ResourceLoader.load(path).entry.load(fwd));
|
||||
}
|
||||
} else {
|
||||
paralleltasks.push(fwd -> ResourceLoader.load(path).entry.load(fwd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class ManifestEntry extends FileEntry {
|
|||
private var bytes:Bytes;
|
||||
private var readPos:Int;
|
||||
private var loaded:Bool;
|
||||
var loadedBmp:LoadedBitmap;
|
||||
#end
|
||||
|
||||
public function new(fs:ManifestFileSystem, name:String, relPath:String, file:String, ?originalFile:String) {
|
||||
|
|
@ -164,9 +165,16 @@ class ManifestEntry extends FileEntry {
|
|||
var bmp = new hxd.res.Image(this).toBitmap();
|
||||
onLoaded(new hxd.fs.LoadedBitmap(bmp));
|
||||
#elseif js
|
||||
if (loadedBmp != null) {
|
||||
onLoaded(loadedBmp);
|
||||
return;
|
||||
}
|
||||
load(() -> {
|
||||
var img:js.html.Image = new js.html.Image();
|
||||
img.onload = (_) -> onLoaded(new LoadedBitmap(img));
|
||||
img.onload = (_) -> {
|
||||
loadedBmp = new LoadedBitmap(img);
|
||||
onLoaded(loadedBmp);
|
||||
};
|
||||
img.src = file;
|
||||
});
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ final lineCommentRegEx = ~/\/\/.*/g;
|
|||
final assignmentRegEx = ~/(\$(?:\w|\d)+)\s*=\s*(.+?);/g;
|
||||
final marbleAttributesRegEx = ~/setMarbleAttributes\("(\w+)",\s*(.+?)\);/g;
|
||||
final activatePackageRegEx = ~/activatePackage\((.+?)\);/g;
|
||||
final materialPropertyRegEx = ~/new MaterialProperty *\( *(.+?) *\)\s*{\s*((?:\w+ *= *(\d|\.)+;\s*)*)}/gi;
|
||||
final materialPropertyRegEx = ~/new MaterialProperty *\( *(.+?) *\)\s*{\s*((?:\w+ *= *-?(\d|\.)+;\s*)*)}/gi;
|
||||
final addMaterialMappingRegEx = ~/addMaterialMapping *\( *"(.+?)" *, *(.+?) *\)/gi;
|
||||
|
||||
class MisParser {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue