mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
speed load
This commit is contained in:
parent
d9a1615950
commit
44c019d5cf
5 changed files with 76 additions and 50 deletions
|
|
@ -86,6 +86,7 @@ class TriangleEdge {
|
||||||
class DifCache {
|
class DifCache {
|
||||||
var dif:Dif;
|
var dif:Dif;
|
||||||
var difTriangles:Map<String, Array<DifBuilderTriangle>>;
|
var difTriangles:Map<String, Array<DifBuilderTriangle>>;
|
||||||
|
var prims:Map<String, Polygon>;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
}
|
}
|
||||||
|
|
@ -850,10 +851,13 @@ class DifBuilder {
|
||||||
collider.finalize();
|
collider.finalize();
|
||||||
itr.collider = collider;
|
itr.collider = collider;
|
||||||
}
|
}
|
||||||
|
var buildNewCache = false;
|
||||||
if (cache == null) {
|
if (cache == null) {
|
||||||
cache = new DifCache();
|
cache = new DifCache();
|
||||||
cache.difTriangles = mats;
|
cache.difTriangles = mats;
|
||||||
cache.dif = dif;
|
cache.dif = dif;
|
||||||
|
cache.prims = [];
|
||||||
|
buildNewCache = true;
|
||||||
difCache.set(cachePath, cache);
|
difCache.set(cachePath, cache);
|
||||||
}
|
}
|
||||||
function canFindTex(tex:String) {
|
function canFindTex(tex:String) {
|
||||||
|
|
@ -908,49 +912,59 @@ class DifBuilder {
|
||||||
|
|
||||||
var time = Console.time();
|
var time = Console.time();
|
||||||
for (grp => tris in mats) {
|
for (grp => tris in mats) {
|
||||||
var points = [];
|
var prim:Polygon = null;
|
||||||
var normals = [];
|
|
||||||
var uvs = [];
|
if (!buildNewCache && cache != null) {
|
||||||
var t = [];
|
prim = cache.prims.get(grp);
|
||||||
var b = [];
|
} else {
|
||||||
var n = [];
|
var points = [];
|
||||||
for (tri in tris) {
|
var normals = [];
|
||||||
var p1 = new Point(-tri.p1.x, tri.p1.y, tri.p1.z);
|
var uvs = [];
|
||||||
var p2 = new Point(-tri.p2.x, tri.p2.y, tri.p2.z);
|
var t = [];
|
||||||
var p3 = new Point(-tri.p3.x, tri.p3.y, tri.p3.z);
|
var b = [];
|
||||||
var n1 = new Point(-tri.normal1.x, tri.normal1.y, tri.normal1.z);
|
var n = [];
|
||||||
var n2 = new Point(-tri.normal2.x, tri.normal2.y, tri.normal2.z);
|
for (tri in tris) {
|
||||||
var n3 = new Point(-tri.normal3.x, tri.normal3.y, tri.normal3.z);
|
var p1 = new Point(-tri.p1.x, tri.p1.y, tri.p1.z);
|
||||||
var uv1 = new UV(tri.uv1.x, tri.uv1.y);
|
var p2 = new Point(-tri.p2.x, tri.p2.y, tri.p2.z);
|
||||||
var uv2 = new UV(tri.uv2.x, tri.uv2.y);
|
var p3 = new Point(-tri.p3.x, tri.p3.y, tri.p3.z);
|
||||||
var uv3 = new UV(tri.uv3.x, tri.uv3.y);
|
var n1 = new Point(-tri.normal1.x, tri.normal1.y, tri.normal1.z);
|
||||||
points.push(p3);
|
var n2 = new Point(-tri.normal2.x, tri.normal2.y, tri.normal2.z);
|
||||||
points.push(p2);
|
var n3 = new Point(-tri.normal3.x, tri.normal3.y, tri.normal3.z);
|
||||||
points.push(p1);
|
var uv1 = new UV(tri.uv1.x, tri.uv1.y);
|
||||||
normals.push(n3);
|
var uv2 = new UV(tri.uv2.x, tri.uv2.y);
|
||||||
normals.push(n2);
|
var uv3 = new UV(tri.uv3.x, tri.uv3.y);
|
||||||
normals.push(n1);
|
points.push(p3);
|
||||||
uvs.push(uv3);
|
points.push(p2);
|
||||||
uvs.push(uv2);
|
points.push(p1);
|
||||||
uvs.push(uv1);
|
normals.push(n3);
|
||||||
t.push(new Point(-tri.t3.x, tri.t3.y, tri.t3.z));
|
normals.push(n2);
|
||||||
t.push(new Point(-tri.t2.x, tri.t2.y, tri.t2.z));
|
normals.push(n1);
|
||||||
t.push(new Point(-tri.t1.x, tri.t1.y, tri.t1.z));
|
uvs.push(uv3);
|
||||||
b.push(new Point(-tri.b3.x, tri.b3.y, tri.b3.z));
|
uvs.push(uv2);
|
||||||
b.push(new Point(-tri.b2.x, tri.b2.y, tri.b2.z));
|
uvs.push(uv1);
|
||||||
b.push(new Point(-tri.b1.x, tri.b1.y, tri.b1.z));
|
t.push(new Point(-tri.t3.x, tri.t3.y, tri.t3.z));
|
||||||
n.push(new Point(-tri.n3.x, tri.n3.y, tri.n3.z));
|
t.push(new Point(-tri.t2.x, tri.t2.y, tri.t2.z));
|
||||||
n.push(new Point(-tri.n2.x, tri.n2.y, tri.n2.z));
|
t.push(new Point(-tri.t1.x, tri.t1.y, tri.t1.z));
|
||||||
n.push(new Point(-tri.n1.x, tri.n1.y, tri.n1.z));
|
b.push(new Point(-tri.b3.x, tri.b3.y, tri.b3.z));
|
||||||
|
b.push(new Point(-tri.b2.x, tri.b2.y, tri.b2.z));
|
||||||
|
b.push(new Point(-tri.b1.x, tri.b1.y, tri.b1.z));
|
||||||
|
n.push(new Point(-tri.n3.x, tri.n3.y, tri.n3.z));
|
||||||
|
n.push(new Point(-tri.n2.x, tri.n2.y, tri.n2.z));
|
||||||
|
n.push(new Point(-tri.n1.x, tri.n1.y, tri.n1.z));
|
||||||
|
}
|
||||||
|
prim = new Polygon(points);
|
||||||
|
prim.uvs = uvs;
|
||||||
|
prim.normals = normals;
|
||||||
|
prim.tangents = t;
|
||||||
|
prim.bitangents = b;
|
||||||
|
prim.texMatNormals = n;
|
||||||
|
if (buildNewCache) {
|
||||||
|
cache.prims.set(grp, prim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var prim = new Polygon(points);
|
|
||||||
prim.uvs = uvs;
|
|
||||||
prim.normals = normals;
|
|
||||||
prim.tangents = t;
|
|
||||||
prim.bitangents = b;
|
|
||||||
prim.texMatNormals = n;
|
|
||||||
var material:Material;
|
|
||||||
var texture:Texture;
|
var texture:Texture;
|
||||||
|
var material:Material;
|
||||||
var exactName = StringTools.replace(grp.toLowerCase(), "textures/", "");
|
var exactName = StringTools.replace(grp.toLowerCase(), "textures/", "");
|
||||||
if (canFindTex(grp) || shaderMaterialDict.exists(exactName)) {
|
if (canFindTex(grp) || shaderMaterialDict.exists(exactName)) {
|
||||||
material = h3d.mat.Material.create();
|
material = h3d.mat.Material.create();
|
||||||
|
|
@ -996,12 +1010,16 @@ class DifBuilder {
|
||||||
// material.mainPass.addShader(new h3d.shader.pbr.PropsValues(1, 0, 0, 1));
|
// material.mainPass.addShader(new h3d.shader.pbr.PropsValues(1, 0, 0, 1));
|
||||||
if (Debug.wireFrame)
|
if (Debug.wireFrame)
|
||||||
material.mainPass.wireframe = true;
|
material.mainPass.wireframe = true;
|
||||||
|
|
||||||
var mesh = new Mesh(prim, material, itr);
|
var mesh = new Mesh(prim, material, itr);
|
||||||
}
|
}
|
||||||
var interval = Console.time() - time;
|
var interval = Console.time() - time;
|
||||||
Console.log('Geometry build time ${interval}');
|
Console.log('Geometry build time ${interval}');
|
||||||
|
|
||||||
|
time = Console.time();
|
||||||
shaderWorker.run();
|
shaderWorker.run();
|
||||||
|
interval = Console.time() - time;
|
||||||
|
Console.log('Shader building time ${interval}');
|
||||||
});
|
});
|
||||||
for (f in loadtexs) {
|
for (f in loadtexs) {
|
||||||
worker.loadFile(f);
|
worker.loadFile(f);
|
||||||
|
|
|
||||||
|
|
@ -1542,13 +1542,6 @@ class MarbleWorld extends Scheduler {
|
||||||
|
|
||||||
public function addBonusTime(t:Float) {
|
public function addBonusTime(t:Float) {
|
||||||
this.bonusTime += t;
|
this.bonusTime += t;
|
||||||
if (t > 0) {
|
|
||||||
this.playGui.addMiddleMessage('-${t}s', 0x99ff99);
|
|
||||||
} else if (t < 0) {
|
|
||||||
this.playGui.addMiddleMessage('+${- t}s', 0xff9999);
|
|
||||||
} else {
|
|
||||||
this.playGui.addMiddleMessage('+0s', 0xcccccc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the current interpolated orientation quaternion. */
|
/** Get the current interpolated orientation quaternion. */
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ class PreviewWorld extends Scheduler {
|
||||||
var sky:Sky;
|
var sky:Sky;
|
||||||
|
|
||||||
var itrAddTime:Float = 0;
|
var itrAddTime:Float = 0;
|
||||||
|
var ssAddTime:Float = 0;
|
||||||
|
|
||||||
var _loadToken = 0;
|
var _loadToken = 0;
|
||||||
var _cubemapNeedsUpdate:Bool = false;
|
var _cubemapNeedsUpdate:Bool = false;
|
||||||
|
|
@ -210,6 +211,7 @@ class PreviewWorld extends Scheduler {
|
||||||
addScenery(difficulty, fwd);
|
addScenery(difficulty, fwd);
|
||||||
});
|
});
|
||||||
itrAddTime = 0;
|
itrAddTime = 0;
|
||||||
|
ssAddTime = 0;
|
||||||
for (elem in itrpaths) {
|
for (elem in itrpaths) {
|
||||||
worker.addTask(fwd -> {
|
worker.addTask(fwd -> {
|
||||||
if (_loadToken != curToken)
|
if (_loadToken != curToken)
|
||||||
|
|
@ -227,14 +229,20 @@ class PreviewWorld extends Scheduler {
|
||||||
worker.addTask(fwd -> {
|
worker.addTask(fwd -> {
|
||||||
if (_loadToken != curToken)
|
if (_loadToken != curToken)
|
||||||
fwd();
|
fwd();
|
||||||
else
|
else {
|
||||||
addStaticShape(cast elem, curToken, fwd);
|
var startTime = Console.time();
|
||||||
|
addStaticShape(cast elem, curToken, () -> {
|
||||||
|
ssAddTime += Console.time() - startTime;
|
||||||
|
fwd();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
worker.addTask(fwd -> {
|
worker.addTask(fwd -> {
|
||||||
timeState.timeSinceLoad = 0;
|
timeState.timeSinceLoad = 0;
|
||||||
timeState.dt = 0;
|
timeState.dt = 0;
|
||||||
Console.log('ITR ADD TIME: ' + itrAddTime);
|
Console.log('ITR ADD TIME: ' + itrAddTime);
|
||||||
|
Console.log('SS ADD TIME: ' + ssAddTime);
|
||||||
fwd();
|
fwd();
|
||||||
});
|
});
|
||||||
worker.run();
|
worker.run();
|
||||||
|
|
@ -347,11 +355,14 @@ class PreviewWorld extends Scheduler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.interiors.push(obj);
|
this.interiors.push(obj);
|
||||||
|
var t = Console.time();
|
||||||
obj.init(null, () -> {
|
obj.init(null, () -> {
|
||||||
if (token != _loadToken) {
|
if (token != _loadToken) {
|
||||||
onFinish();
|
onFinish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var interval = Console.time() - t;
|
||||||
|
Console.log('Init interior: ${interval}ms');
|
||||||
if (obj.useInstancing)
|
if (obj.useInstancing)
|
||||||
this.instanceManager.addObject(obj);
|
this.instanceManager.addObject(obj);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class ResourceLoader {
|
||||||
static var imageCache:Map<String, Resource<Image>> = new Map();
|
static var imageCache:Map<String, Resource<Image>> = new Map();
|
||||||
static var audioCache:Map<String, Resource<Sound>> = new Map();
|
static var audioCache:Map<String, Resource<Sound>> = new Map();
|
||||||
static var zipFilesystem:Map<String, BytesFileEntry> = new Map();
|
static var zipFilesystem:Map<String, BytesFileEntry> = new Map();
|
||||||
|
public static var loadedFiles:Map<String, Bool> = new Map(); // For js, don't load files more than once
|
||||||
|
|
||||||
public static var initialized = false;
|
public static var initialized = false;
|
||||||
|
|
||||||
|
|
@ -312,6 +313,7 @@ class ResourceLoader {
|
||||||
if (zipFilesystem.exists(path.toLowerCase())) {
|
if (zipFilesystem.exists(path.toLowerCase())) {
|
||||||
return new hxd.res.Any(loader, zipFilesystem.get(path.toLowerCase()));
|
return new hxd.res.Any(loader, zipFilesystem.get(path.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
loadedFiles.set(path, true); // Loaded
|
||||||
return ResourceLoader.loader.load(path);
|
return ResourceLoader.loader.load(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ class ResourceLoaderWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadFile(path:String) {
|
public function loadFile(path:String) {
|
||||||
|
if (ResourceLoader.loadedFiles.exists(path))
|
||||||
|
return;
|
||||||
#if (!android)
|
#if (!android)
|
||||||
paralleltasks.push(fwd -> {
|
paralleltasks.push(fwd -> {
|
||||||
ResourceLoader.load(path).entry.load(fwd);
|
ResourceLoader.load(path).entry.load(fwd);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue