diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 776bdd38..646cbc06 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2140,6 +2140,7 @@ Work to reduce allocations Prevent mouse event re-allocation every frame More allocation work Frametime reporting work +Raycast allocation fix diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java index 4e732823..33189ccb 100644 --- a/src/main/java/electrosphere/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/collision/CollisionEngine.java @@ -938,6 +938,7 @@ public class CollisionEngine { * @return The position, in world coordinates, of the closest collision of the way, or null if it did not collide with anything. */ public Vector3d rayCastPosition(Vector3d start, Vector3d direction, double length){ + Globals.profiler.beginCpuSample("CollisionEngine.rayCastPosition"); spaceLock.lock(); Vector3d unitDir = new Vector3d(direction).normalize(); //create the ray @@ -951,6 +952,7 @@ public class CollisionEngine { //destroy ray ray.destroy(); spaceLock.unlock(); + Globals.profiler.endCpuSample(); return data.collisionPosition; } diff --git a/src/main/java/electrosphere/collision/RayCastCallback.java b/src/main/java/electrosphere/collision/RayCastCallback.java index e68b09c5..4d933490 100644 --- a/src/main/java/electrosphere/collision/RayCastCallback.java +++ b/src/main/java/electrosphere/collision/RayCastCallback.java @@ -57,6 +57,11 @@ void RayCallback(void *Data, dGeomID Geometry1, dGeomID Geometry2) { //This should be reset every time a ray cast is called in collision engine by calling setLength in this object. double shortestLength = REALLY_LONG_DISTANCE; + /** + * The contact buffer + */ + DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS); + @Override public void call(Object data, DGeom o1, DGeom o2) { RayCastCallbackData rayCastData = (RayCastCallbackData)data; @@ -107,8 +112,8 @@ void RayCallback(void *Data, dGeomID Geometry1, dGeomID Geometry2) { (o1 instanceof DRay && collidable2 != null && rayCastData.collidableTypeMask.contains(collidable2.getType())) || (o2 instanceof DRay && collidable1 != null && rayCastData.collidableTypeMask.contains(collidable1.getType())) ){ - //creates a buffer to store potential collisions - DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS); // up to MAX_CONTACTS contacts per box-box + //reset contact buffer + contacts.nullify(); //calculate collisions int numc = OdeHelper.collide(o1,o2,MAX_CONTACTS,contacts.getGeomBuffer()); //create DContacts based on each collision that occurs diff --git a/src/main/java/electrosphere/renderer/meshgen/BlockMeshgen.java b/src/main/java/electrosphere/renderer/meshgen/BlockMeshgen.java index 916da364..dff88196 100644 --- a/src/main/java/electrosphere/renderer/meshgen/BlockMeshgen.java +++ b/src/main/java/electrosphere/renderer/meshgen/BlockMeshgen.java @@ -424,10 +424,10 @@ public class BlockMeshgen { BlockMeshgen.meshifyBox(meshGenStore,quad1,zEnd,quad1.type,scalingFactor); quad1 = quad2; - // BlockSingleShape blockSingleShape = BlockMeshgen.copyDataToShape(meshGenStore, vertCount, faceCount); - // vertCount = meshGenStore.getVertCount(); - // faceCount = meshGenStore.getFaceCount(); - // rVal.shapeData.add(blockSingleShape); + BlockSingleShape blockSingleShape = BlockMeshgen.copyDataToShape(meshGenStore, vertCount, faceCount); + vertCount = meshGenStore.getVertCount(); + faceCount = meshGenStore.getFaceCount(); + rVal.shapeData.add(blockSingleShape); break; } } @@ -435,10 +435,10 @@ public class BlockMeshgen { } if(quad1 != null){ BlockMeshgen.meshifyBox(meshGenStore,quad1,zEnd,quad1.type,scalingFactor); - // BlockSingleShape blockSingleShape = BlockMeshgen.copyDataToShape(meshGenStore, vertCount, faceCount); - // vertCount = meshGenStore.getVertCount(); - // faceCount = meshGenStore.getFaceCount(); - // rVal.shapeData.add(blockSingleShape); + BlockSingleShape blockSingleShape = BlockMeshgen.copyDataToShape(meshGenStore, vertCount, faceCount); + vertCount = meshGenStore.getVertCount(); + faceCount = meshGenStore.getFaceCount(); + rVal.shapeData.add(blockSingleShape); } //