mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 12:41:40 +00:00
speed up loading a lot?
This commit is contained in:
parent
5b9271c6f9
commit
e966a96fb5
3 changed files with 132 additions and 21 deletions
|
|
@ -132,9 +132,13 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
var _loadingLength:Int = 0;
|
var _loadingLength:Int = 0;
|
||||||
|
|
||||||
|
var _resourcesLoaded:Int = 0;
|
||||||
|
|
||||||
var textureResources:Array<Resource<h3d.mat.Texture>> = [];
|
var textureResources:Array<Resource<h3d.mat.Texture>> = [];
|
||||||
var soundResources:Array<Resource<Sound>> = [];
|
var soundResources:Array<Resource<Sound>> = [];
|
||||||
|
|
||||||
|
var lock:Bool = false;
|
||||||
|
|
||||||
public function new(scene:Scene, scene2d:h2d.Scene, mission:Mission) {
|
public function new(scene:Scene, scene2d:h2d.Scene, mission:Mission) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.scene2d = scene2d;
|
this.scene2d = scene2d;
|
||||||
|
|
@ -747,10 +751,28 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
function asyncLoadResources() {
|
function asyncLoadResources() {
|
||||||
if (this.resourceLoadFuncs.length != 0) {
|
if (this.resourceLoadFuncs.length != 0) {
|
||||||
|
// if (lock)
|
||||||
|
// return;
|
||||||
|
|
||||||
var func = this.resourceLoadFuncs.pop();
|
var func = this.resourceLoadFuncs.pop();
|
||||||
|
lock = true;
|
||||||
|
#if hl
|
||||||
func();
|
func();
|
||||||
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
|
lock = false;
|
||||||
|
this._resourcesLoaded++;
|
||||||
|
#end
|
||||||
|
#if js
|
||||||
|
var prom = new js.lib.Promise((resolve, reject) -> {
|
||||||
|
func();
|
||||||
|
lock = false;
|
||||||
|
resolve(true);
|
||||||
|
this.loadingGui.setProgress((1 - resourceLoadFuncs.length / _loadingLength));
|
||||||
|
this._resourcesLoaded++;
|
||||||
|
});
|
||||||
|
#end
|
||||||
} else {
|
} else {
|
||||||
|
if (this._resourcesLoaded < _loadingLength)
|
||||||
|
return;
|
||||||
if (!_ready)
|
if (!_ready)
|
||||||
postInit();
|
postInit();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
19
src/Sky.hx
19
src/Sky.hx
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import hxd.Pixels;
|
||||||
import shaders.Skybox;
|
import shaders.Skybox;
|
||||||
import h3d.shader.pbr.PropsValues;
|
import h3d.shader.pbr.PropsValues;
|
||||||
import h3d.shader.AmbientLight;
|
import h3d.shader.AmbientLight;
|
||||||
|
|
@ -38,13 +39,13 @@ class Sky extends Object {
|
||||||
skyMesh.material.blendMode = None;
|
skyMesh.material.blendMode = None;
|
||||||
// var pbrprops = skyMesh.material.mainPass.getShader(PropsValues);
|
// var pbrprops = skyMesh.material.mainPass.getShader(PropsValues);
|
||||||
// pbrprops.emissiveValue = 1;
|
// pbrprops.emissiveValue = 1;
|
||||||
// pbrprops.roughnessValue = 0;
|
// pbrprops.roughnessValue = 0;`
|
||||||
// pbrprops.occlusionValue = 0;
|
// pbrprops.occlusionValue = 0;
|
||||||
// pbrprops.metalnessValue = 1;
|
// pbrprops.metalnessValue = 1;
|
||||||
|
|
||||||
skyMesh.scale(3500);
|
skyMesh.scale(3500);
|
||||||
var env = new Environment(texture);
|
// var env = new Environment(texture);
|
||||||
env.compute();
|
// env.compute();
|
||||||
// var renderer = cast(level.scene.renderer, h3d.scene.pbr.Renderer);
|
// var renderer = cast(level.scene.renderer, h3d.scene.pbr.Renderer);
|
||||||
var shad = new Skybox(texture);
|
var shad = new Skybox(texture);
|
||||||
skyMesh.material.mainPass.addShader(shad);
|
skyMesh.material.mainPass.addShader(shad);
|
||||||
|
|
@ -75,10 +76,14 @@ class Sky extends Object {
|
||||||
var line = StringTools.trim(lines[i]);
|
var line = StringTools.trim(lines[i]);
|
||||||
var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line);
|
var filenames = ResourceLoader.getFullNamesOf(dmlDirectory + '/' + line);
|
||||||
if (filenames.length == 0) {
|
if (filenames.length == 0) {
|
||||||
skyboxImages.push(new BitmapData(128, 128));
|
var pixels = Texture.fromColor(0).capturePixels(0, 0);
|
||||||
|
skyboxImages.push(pixels);
|
||||||
|
// var tex = new h3d.mat.Texture();
|
||||||
|
// skyboxImages.push(new BitmapData(128, 128));
|
||||||
} else {
|
} else {
|
||||||
var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toBitmap();
|
var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toTexture();
|
||||||
skyboxImages.push(image);
|
var pixels = image.capturePixels(0, 0);
|
||||||
|
skyboxImages.push(pixels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var maxwidth = 0;
|
var maxwidth = 0;
|
||||||
|
|
@ -103,7 +108,7 @@ class Sky extends Object {
|
||||||
|
|
||||||
var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]);
|
var cubemaptexture = new Texture(maxheight, maxwidth, [Cube]);
|
||||||
for (i in 0...6) {
|
for (i in 0...6) {
|
||||||
cubemaptexture.uploadBitmap(skyboxImages[skyboxIndices[i]], 0, i);
|
cubemaptexture.uploadPixels(skyboxImages[skyboxIndices[i]], 0, i);
|
||||||
}
|
}
|
||||||
return cubemaptexture;
|
return cubemaptexture;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
110
src/Util.hx
110
src/Util.hx
|
|
@ -38,46 +38,130 @@ class Util {
|
||||||
return new Vector(lerp(v1.x, v2.x, t), lerp(v1.y, v2.y, t), lerp(v1.z, v2.z, t), lerp(v1.w, v2.w, t));
|
return new Vector(lerp(v1.x, v2.x, t), lerp(v1.y, v2.y, t), lerp(v1.z, v2.z, t), lerp(v1.w, v2.w, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function rotateImage(bitmap:BitmapData, angle:Float) {
|
public static function rotateImage(bitmap:hxd.Pixels, angle:Float) {
|
||||||
bitmap.lock();
|
var curpixels = bitmap.clone();
|
||||||
var curpixels = bitmap.getPixels().clone();
|
|
||||||
if (angle == Math.PI / 2)
|
if (angle == Math.PI / 2)
|
||||||
for (x in 0...curpixels.width) {
|
for (x in 0...curpixels.width) {
|
||||||
for (y in 0...curpixels.height) {
|
for (y in 0...curpixels.height) {
|
||||||
bitmap.setPixel(x, y, curpixels.getPixel(y, curpixels.height - x - 1));
|
var psrc = ((y + (curpixels.height - x - 1) * curpixels.width) * @:privateAccess curpixels.bytesPerPixel) + curpixels.offset;
|
||||||
|
var pdest = ((x + y * curpixels.width) * @:privateAccess curpixels.bytesPerPixel) + curpixels.offset;
|
||||||
|
|
||||||
|
switch (curpixels.format) {
|
||||||
|
case R8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
case BGRA | RGBA | ARGB:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
bitmap.bytes.set(pdest + 2, curpixels.bytes.get(psrc + 2));
|
||||||
|
bitmap.bytes.set(pdest + 3, curpixels.bytes.get(psrc + 3));
|
||||||
|
case RG8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// bitmap.setPixel(x, y, curpixels.getPixel(y, curpixels.height - x - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (angle == -Math.PI / 2)
|
if (angle == -Math.PI / 2)
|
||||||
for (x in 0...curpixels.width) {
|
for (x in 0...curpixels.width) {
|
||||||
for (y in 0...curpixels.height) {
|
for (y in 0...curpixels.height) {
|
||||||
bitmap.setPixel(x, y, curpixels.getPixel(curpixels.width - y - 1, x));
|
var psrc = ((curpixels.width - y - 1) + x * curpixels.width) * @:privateAccess curpixels.bytesPerPixel + curpixels.offset;
|
||||||
|
|
||||||
|
var pdest = ((x + y * curpixels.width) * @:privateAccess curpixels.bytesPerPixel) + curpixels.offset;
|
||||||
|
|
||||||
|
switch (curpixels.format) {
|
||||||
|
case R8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
case BGRA | RGBA | ARGB:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
bitmap.bytes.set(pdest + 2, curpixels.bytes.get(psrc + 2));
|
||||||
|
bitmap.bytes.set(pdest + 3, curpixels.bytes.get(psrc + 3));
|
||||||
|
case RG8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (angle == Math.PI)
|
if (angle == Math.PI)
|
||||||
for (x in 0...curpixels.width) {
|
for (x in 0...curpixels.width) {
|
||||||
for (y in 0...curpixels.height) {
|
for (y in 0...curpixels.height) {
|
||||||
bitmap.setPixel(x, y, curpixels.getPixel(curpixels.width - x - 1, curpixels.height - y - 1));
|
var psrc = ((curpixels.width - x - 1)
|
||||||
|
+ (curpixels.height - y - 1) * curpixels.width) * @:privateAccess curpixels.bytesPerPixel
|
||||||
|
+ curpixels.offset;
|
||||||
|
|
||||||
|
var pdest = ((x + y * curpixels.width) * @:privateAccess curpixels.bytesPerPixel) + curpixels.offset;
|
||||||
|
|
||||||
|
switch (curpixels.format) {
|
||||||
|
case R8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
case BGRA | RGBA | ARGB:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
bitmap.bytes.set(pdest + 2, curpixels.bytes.get(psrc + 2));
|
||||||
|
bitmap.bytes.set(pdest + 3, curpixels.bytes.get(psrc + 3));
|
||||||
|
case RG8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bitmap.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function flipImage(bitmap:BitmapData, hflip:Bool, vflip:Bool) {
|
public static function flipImage(bitmap:hxd.Pixels, hflip:Bool, vflip:Bool) {
|
||||||
bitmap.lock();
|
var curpixels = bitmap.clone();
|
||||||
var curpixels = bitmap.getPixels().clone();
|
|
||||||
if (hflip)
|
if (hflip)
|
||||||
for (x in 0...curpixels.width) {
|
for (x in 0...curpixels.width) {
|
||||||
for (y in 0...curpixels.height) {
|
for (y in 0...curpixels.height) {
|
||||||
bitmap.setPixel(x, y, curpixels.getPixel(curpixels.height - x - 1, y));
|
var psrc = ((curpixels.width - x - 1) + y * curpixels.width) * @:privateAccess curpixels.bytesPerPixel + curpixels.offset;
|
||||||
|
|
||||||
|
var pdest = ((x + y * curpixels.width) * @:privateAccess curpixels.bytesPerPixel) + curpixels.offset;
|
||||||
|
|
||||||
|
switch (curpixels.format) {
|
||||||
|
case R8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
case BGRA | RGBA | ARGB:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
bitmap.bytes.set(pdest + 2, curpixels.bytes.get(psrc + 2));
|
||||||
|
bitmap.bytes.set(pdest + 3, curpixels.bytes.get(psrc + 3));
|
||||||
|
case RG8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vflip)
|
if (vflip)
|
||||||
for (x in 0...curpixels.width) {
|
for (x in 0...curpixels.width) {
|
||||||
for (y in 0...curpixels.height) {
|
for (y in 0...curpixels.height) {
|
||||||
bitmap.setPixel(x, y, curpixels.getPixel(x, curpixels.width - y - 1));
|
var psrc = (x + (curpixels.width - y - 1) * curpixels.width) * @:privateAccess curpixels.bytesPerPixel + curpixels.offset;
|
||||||
|
|
||||||
|
var pdest = ((x + y * curpixels.width) * @:privateAccess curpixels.bytesPerPixel) + curpixels.offset;
|
||||||
|
|
||||||
|
switch (curpixels.format) {
|
||||||
|
case R8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
case BGRA | RGBA | ARGB:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
bitmap.bytes.set(pdest + 2, curpixels.bytes.get(psrc + 2));
|
||||||
|
bitmap.bytes.set(pdest + 3, curpixels.bytes.get(psrc + 3));
|
||||||
|
case RG8:
|
||||||
|
bitmap.bytes.set(pdest, curpixels.bytes.get(psrc));
|
||||||
|
bitmap.bytes.set(pdest + 1, curpixels.bytes.get(psrc + 1));
|
||||||
|
default:
|
||||||
|
null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bitmap.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function splitIgnoreStringLiterals(str:String, splitter:String, strLiteralToken = '"') {
|
public static function splitIgnoreStringLiterals(str:String, splitter:String, strLiteralToken = '"') {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue