mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 05:01:38 +00:00
more array reuse
This commit is contained in:
parent
8d35663f3d
commit
44c15ab011
4 changed files with 22 additions and 20 deletions
|
|
@ -262,6 +262,7 @@ class Marble extends GameObject {
|
||||||
public var bestContact:CollisionInfo;
|
public var bestContact:CollisionInfo;
|
||||||
|
|
||||||
static var contactScratch:Array<CollisionEntity> = [];
|
static var contactScratch:Array<CollisionEntity> = [];
|
||||||
|
static var surfaceScratch:Array<CollisionSurface> = [];
|
||||||
|
|
||||||
var queuedContacts:Array<CollisionInfo> = [];
|
var queuedContacts:Array<CollisionInfo> = [];
|
||||||
var appliedImpulses:Array<{impulse:Vector, contactImpulse:Bool}> = [];
|
var appliedImpulses:Array<{impulse:Vector, contactImpulse:Bool}> = [];
|
||||||
|
|
@ -1320,7 +1321,7 @@ class Marble extends GameObject {
|
||||||
// var iterationFound = false;
|
// var iterationFound = false;
|
||||||
for (obj in foundObjs) {
|
for (obj in foundObjs) {
|
||||||
// Its an MP so bruh
|
// Its an MP so bruh
|
||||||
if (obj.go != null && !obj.go.isCollideable)
|
if (obj.go == this || (obj.go != null && !obj.go.isCollideable))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var isDts = obj.go is DtsObject;
|
var isDts = obj.go is DtsObject;
|
||||||
|
|
@ -1348,11 +1349,12 @@ class Marble extends GameObject {
|
||||||
Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 2);
|
Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 2);
|
||||||
|
|
||||||
var currentFinalPos = position.add(relVel.multiply(finalT)); // localpos.add(relLocalVel.multiply(finalT));
|
var currentFinalPos = position.add(relVel.multiply(finalT)); // localpos.add(relLocalVel.multiply(finalT));
|
||||||
var surfaces = @:privateAccess obj.grid != null ? @:privateAccess obj.grid.boundingSearch(boundThing) : (obj.bvh == null ? obj.octree.boundingSearch(boundThing)
|
surfaceScratch.resize(0);
|
||||||
.map(x -> cast x) : obj.bvh.boundingSearch(boundThing));
|
@:privateAccess obj.grid.boundingSearch(boundThing, surfaceScratch);
|
||||||
|
var surfaces = surfaceScratch;
|
||||||
|
|
||||||
for (surf in surfaces) {
|
for (surf in surfaces) {
|
||||||
var surface:CollisionSurface = cast surf;
|
var surface:CollisionSurface = surf;
|
||||||
|
|
||||||
currentFinalPos = position.add(relVel.multiply(finalT));
|
currentFinalPos = position.add(relVel.multiply(finalT));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
|
|
||||||
public var octree:Octree;
|
public var octree:Octree;
|
||||||
|
|
||||||
public var bvh:BVHTree<CollisionSurface>;
|
// public var bvh:BVHTree<CollisionSurface>;
|
||||||
|
|
||||||
var grid:Grid;
|
var grid:Grid;
|
||||||
|
|
||||||
public var surfaces:Array<CollisionSurface>;
|
public var surfaces:Array<CollisionSurface>;
|
||||||
|
|
@ -67,12 +66,12 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
// Generates the bvh
|
// Generates the bvh
|
||||||
public function finalize() {
|
public function finalize() {
|
||||||
this.generateBoundingBox();
|
this.generateBoundingBox();
|
||||||
#if hl
|
// #if hl
|
||||||
this.bvh = new BVHTree();
|
// this.bvh = new BVHTree();
|
||||||
for (surface in this.surfaces) {
|
// for (surface in this.surfaces) {
|
||||||
this.bvh.add(surface);
|
// this.bvh.add(surface);
|
||||||
}
|
// }
|
||||||
#end
|
// #end
|
||||||
var bbox = new Bounds();
|
var bbox = new Bounds();
|
||||||
for (surface in this.surfaces)
|
for (surface in this.surfaces)
|
||||||
bbox.add(surface.boundingBox);
|
bbox.add(surface.boundingBox);
|
||||||
|
|
@ -90,7 +89,8 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
}
|
}
|
||||||
go = null;
|
go = null;
|
||||||
surfaces = null;
|
surfaces = null;
|
||||||
bvh = null;
|
grid = null;
|
||||||
|
// bvh = null;
|
||||||
octree = null;
|
octree = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,6 +200,8 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static var surfaceSearchPool:Array<CollisionSurface> = [];
|
||||||
|
|
||||||
public function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState, contacts:Array<CollisionInfo>) {
|
public function sphereIntersection(collisionEntity:SphereCollisionEntity, timeState:TimeState, contacts:Array<CollisionInfo>) {
|
||||||
var position = collisionEntity.transform.getPosition();
|
var position = collisionEntity.transform.getPosition();
|
||||||
var radius = collisionEntity.radius + 0.001;
|
var radius = collisionEntity.radius + 0.001;
|
||||||
|
|
@ -215,7 +217,9 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
var invScale = invMatrix.getScale();
|
var invScale = invMatrix.getScale();
|
||||||
var sphereRadius = new Vector(radius * invScale.x, radius * invScale.y, radius * invScale.z);
|
var sphereRadius = new Vector(radius * invScale.x, radius * invScale.y, radius * invScale.z);
|
||||||
sphereBounds.addSpherePos(localPos.x, localPos.y, localPos.z, Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 1.1);
|
sphereBounds.addSpherePos(localPos.x, localPos.y, localPos.z, Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 1.1);
|
||||||
var surfaces = grid.boundingSearch(sphereBounds); // bvh == null ? octree.boundingSearch(sphereBounds).map(x -> cast x) : bvh.boundingSearch(sphereBounds);
|
surfaceSearchPool.resize(0);
|
||||||
|
grid.boundingSearch(sphereBounds, surfaceSearchPool);
|
||||||
|
var surfaces = surfaceSearchPool;
|
||||||
var invtform = invMatrix.clone();
|
var invtform = invMatrix.clone();
|
||||||
invtform.transpose();
|
invtform.transpose();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class CollisionWorld {
|
||||||
+ rayDirection.x * rayLength, rayStart.y
|
+ rayDirection.x * rayLength, rayStart.y
|
||||||
+ rayDirection.y * rayLength, rayStart.z
|
+ rayDirection.y * rayLength, rayStart.z
|
||||||
+ rayDirection.z * rayLength);
|
+ rayDirection.z * rayLength);
|
||||||
this.intersectionList.splice(0, this.intersectionList.length);
|
this.intersectionList.resize(0);
|
||||||
|
|
||||||
this.grid.boundingSearch(bounds, this.intersectionList);
|
this.grid.boundingSearch(bounds, this.intersectionList);
|
||||||
dynamicGrid.boundingSearch(bounds, this.intersectionList);
|
dynamicGrid.boundingSearch(bounds, this.intersectionList);
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ class Grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
// searchbox should be in LOCAL coordinates
|
// searchbox should be in LOCAL coordinates
|
||||||
public function boundingSearch(searchbox:Bounds) {
|
public function boundingSearch(searchbox:Bounds, foundSurfaces:Array<CollisionSurface>) {
|
||||||
var queryMinX = Math.max(searchbox.xMin, bounds.xMin);
|
var queryMinX = Math.max(searchbox.xMin, bounds.xMin);
|
||||||
var queryMinY = Math.max(searchbox.yMin, bounds.yMin);
|
var queryMinY = Math.max(searchbox.yMin, bounds.yMin);
|
||||||
var queryMaxX = Math.min(searchbox.xMax, bounds.xMax);
|
var queryMaxX = Math.min(searchbox.xMax, bounds.xMax);
|
||||||
|
|
@ -94,8 +94,6 @@ class Grid {
|
||||||
if (yEnd > CELL_SIZE)
|
if (yEnd > CELL_SIZE)
|
||||||
yEnd = CELL_SIZE;
|
yEnd = CELL_SIZE;
|
||||||
|
|
||||||
var foundSurfaces = [];
|
|
||||||
|
|
||||||
searchKey++;
|
searchKey++;
|
||||||
|
|
||||||
// Insert the surface references from [xStart, yStart, zStart] to [xEnd, yEnd, zEnd] into the map
|
// Insert the surface references from [xStart, yStart, zStart] to [xEnd, yEnd, zEnd] into the map
|
||||||
|
|
@ -113,8 +111,6 @@ class Grid {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundSurfaces;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function elegantPair(x:Int, y:Int) {
|
function elegantPair(x:Int, y:Int) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue