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 dtsShader:DtsTexture;
|
||||
var glowPassDtsShader:DtsTexture;
|
||||
var baseBounds:h3d.col.Bounds;
|
||||
|
||||
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 {
|
||||
var objects:Array<Array<MeshBatchInfo>> = [];
|
||||
|
||||
var objectMap:Map<String, Int> = [];
|
||||
var scene:Scene;
|
||||
var opaqueinstances = new ReusableList<MeshInstance>();
|
||||
var transparentinstances = new ReusableList<MeshInstance>();
|
||||
|
||||
public function new(scene:Scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
static var tmpBounds = new h3d.col.Bounds();
|
||||
var renderFrustum = scene.camera.frustum;
|
||||
var doFrustumCheck = true;
|
||||
// This sucks holy shit
|
||||
|
|
@ -63,24 +116,24 @@ class InstanceManager {
|
|||
|
||||
for (meshes in objects) {
|
||||
for (minfo in meshes) {
|
||||
var opaqueinstances = [];
|
||||
var transparentinstances = [];
|
||||
opaqueinstances.clear();
|
||||
transparentinstances.clear();
|
||||
// Culling
|
||||
if (minfo.meshbatch != null || minfo.transparencymeshbatch != null) {
|
||||
for (inst in minfo.instances) {
|
||||
// for (frustum in renderFrustums) {
|
||||
// if (frustum.hasBounds(objBounds)) {
|
||||
|
||||
var objBounds = @:privateAccess cast(minfo.meshbatch.primitive, Instanced).baseBounds.clone();
|
||||
objBounds.transform(inst.emptyObj.getAbsPos());
|
||||
tmpBounds.load(minfo.baseBounds);
|
||||
tmpBounds.transform(inst.emptyObj.getAbsPos());
|
||||
|
||||
if (cameraFrustrums == null && !renderFrustum.hasBounds(objBounds))
|
||||
if (cameraFrustrums == null && !renderFrustum.hasBounds(tmpBounds))
|
||||
continue;
|
||||
|
||||
if (cameraFrustrums != null) {
|
||||
var found = false;
|
||||
for (frustrum in cameraFrustrums) {
|
||||
if (frustrum.hasBounds(objBounds)) {
|
||||
if (frustrum.hasBounds(tmpBounds)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -195,6 +248,7 @@ class InstanceManager {
|
|||
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.mesh = isMesh ? cast obj : null;
|
||||
minfo.baseBounds = isMesh ? @:privateAccess cast(minfo.meshbatch.primitive, Instanced).baseBounds : null;
|
||||
|
||||
if (isMesh) {
|
||||
var mat = cast(obj, Mesh).material;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ interface IBVHObject {
|
|||
function rayCast(rayOrigin:Vector, rayDirection:Vector, results:Array<octree.IOctreeObject.RayIntersectionData>):Void;
|
||||
}
|
||||
|
||||
@:generic
|
||||
@:publicFields
|
||||
class BVHNode<T:IBVHObject> {
|
||||
var index:Int;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package octree;
|
||||
|
||||
@:generic
|
||||
class PriorityQueue<T> {
|
||||
var queue:Array<PriorityQueueNode<T>>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package octree;
|
||||
|
||||
@:generic
|
||||
class PriorityQueueNode<T> {
|
||||
public var value:T;
|
||||
public var priority:Float;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue