mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
perf improv
This commit is contained in:
parent
f5be65234f
commit
c6abf52c36
4 changed files with 64 additions and 7 deletions
|
|
@ -29,6 +29,7 @@ class MeshBatchInfo {
|
||||||
var mesh:Mesh;
|
var mesh:Mesh;
|
||||||
var dtsShader:DtsTexture;
|
var dtsShader:DtsTexture;
|
||||||
var glowPassDtsShader:DtsTexture;
|
var glowPassDtsShader:DtsTexture;
|
||||||
|
var baseBounds:h3d.col.Bounds;
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
}
|
}
|
||||||
|
|
@ -44,17 +45,69 @@ class MeshInstance {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:generic
|
||||||
|
class ReusableListIterator<T> {
|
||||||
|
var l:ReusableList<T>;
|
||||||
|
var i = 0;
|
||||||
|
|
||||||
|
public function new(l:ReusableList<T>) {
|
||||||
|
this.l = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function hasNext() {
|
||||||
|
return i != l.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function next() {
|
||||||
|
var ret = @:privateAccess l.array[i];
|
||||||
|
i += 1;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@:allow(ReusableListIterator)
|
||||||
|
@:generic
|
||||||
|
class ReusableList<T> {
|
||||||
|
var array:Array<T>;
|
||||||
|
|
||||||
|
public var length:Int = 0;
|
||||||
|
|
||||||
|
public inline function new() {
|
||||||
|
array = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function push(item:T) {
|
||||||
|
if (array.length == length) {
|
||||||
|
array.push(item);
|
||||||
|
length += 1;
|
||||||
|
} else {
|
||||||
|
array[length] = item;
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function clear() {
|
||||||
|
length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function iterator():ReusableListIterator<T> {
|
||||||
|
return new ReusableListIterator<T>(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class InstanceManager {
|
class InstanceManager {
|
||||||
var objects:Array<Array<MeshBatchInfo>> = [];
|
var objects:Array<Array<MeshBatchInfo>> = [];
|
||||||
|
|
||||||
var objectMap:Map<String, Int> = [];
|
var objectMap:Map<String, Int> = [];
|
||||||
var scene:Scene;
|
var scene:Scene;
|
||||||
|
var opaqueinstances = new ReusableList<MeshInstance>();
|
||||||
|
var transparentinstances = new ReusableList<MeshInstance>();
|
||||||
|
|
||||||
public function new(scene:Scene) {
|
public function new(scene:Scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
|
static var tmpBounds = new h3d.col.Bounds();
|
||||||
var renderFrustum = scene.camera.frustum;
|
var renderFrustum = scene.camera.frustum;
|
||||||
var doFrustumCheck = true;
|
var doFrustumCheck = true;
|
||||||
// This sucks holy shit
|
// This sucks holy shit
|
||||||
|
|
@ -63,24 +116,24 @@ class InstanceManager {
|
||||||
|
|
||||||
for (meshes in objects) {
|
for (meshes in objects) {
|
||||||
for (minfo in meshes) {
|
for (minfo in meshes) {
|
||||||
var opaqueinstances = [];
|
opaqueinstances.clear();
|
||||||
var transparentinstances = [];
|
transparentinstances.clear();
|
||||||
// Culling
|
// Culling
|
||||||
if (minfo.meshbatch != null || minfo.transparencymeshbatch != null) {
|
if (minfo.meshbatch != null || minfo.transparencymeshbatch != null) {
|
||||||
for (inst in minfo.instances) {
|
for (inst in minfo.instances) {
|
||||||
// for (frustum in renderFrustums) {
|
// for (frustum in renderFrustums) {
|
||||||
// if (frustum.hasBounds(objBounds)) {
|
// if (frustum.hasBounds(objBounds)) {
|
||||||
|
|
||||||
var objBounds = @:privateAccess cast(minfo.meshbatch.primitive, Instanced).baseBounds.clone();
|
tmpBounds.load(minfo.baseBounds);
|
||||||
objBounds.transform(inst.emptyObj.getAbsPos());
|
tmpBounds.transform(inst.emptyObj.getAbsPos());
|
||||||
|
|
||||||
if (cameraFrustrums == null && !renderFrustum.hasBounds(objBounds))
|
if (cameraFrustrums == null && !renderFrustum.hasBounds(tmpBounds))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cameraFrustrums != null) {
|
if (cameraFrustrums != null) {
|
||||||
var found = false;
|
var found = false;
|
||||||
for (frustrum in cameraFrustrums) {
|
for (frustrum in cameraFrustrums) {
|
||||||
if (frustrum.hasBounds(objBounds)) {
|
if (frustrum.hasBounds(tmpBounds)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -195,6 +248,7 @@ class InstanceManager {
|
||||||
minfo.instances = [new MeshInstance(obj, object)];
|
minfo.instances = [new MeshInstance(obj, object)];
|
||||||
minfo.meshbatch = isMesh ? new MeshBatch(cast(cast(obj, Mesh).primitive), cast(cast(obj, Mesh)).material.clone(), scene) : null;
|
minfo.meshbatch = isMesh ? new MeshBatch(cast(cast(obj, Mesh).primitive), cast(cast(obj, Mesh)).material.clone(), scene) : null;
|
||||||
minfo.mesh = isMesh ? cast obj : null;
|
minfo.mesh = isMesh ? cast obj : null;
|
||||||
|
minfo.baseBounds = isMesh ? @:privateAccess cast(minfo.meshbatch.primitive, Instanced).baseBounds : null;
|
||||||
|
|
||||||
if (isMesh) {
|
if (isMesh) {
|
||||||
var mat = cast(obj, Mesh).material;
|
var mat = cast(obj, Mesh).material;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ interface IBVHObject {
|
||||||
function rayCast(rayOrigin:Vector, rayDirection:Vector, results:Array<octree.IOctreeObject.RayIntersectionData>):Void;
|
function rayCast(rayOrigin:Vector, rayDirection:Vector, results:Array<octree.IOctreeObject.RayIntersectionData>):Void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:generic
|
||||||
@:publicFields
|
@:publicFields
|
||||||
class BVHNode<T:IBVHObject> {
|
class BVHNode<T:IBVHObject> {
|
||||||
var index:Int;
|
var index:Int;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package octree;
|
package octree;
|
||||||
|
|
||||||
|
@:generic
|
||||||
class PriorityQueue<T> {
|
class PriorityQueue<T> {
|
||||||
var queue:Array<PriorityQueueNode<T>>;
|
var queue:Array<PriorityQueueNode<T>>;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package octree;
|
package octree;
|
||||||
|
|
||||||
|
@:generic
|
||||||
class PriorityQueueNode<T> {
|
class PriorityQueueNode<T> {
|
||||||
public var value:T;
|
public var value:T;
|
||||||
public var priority:Float;
|
public var priority:Float;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue