fix raycast overalloc
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-06-08 22:12:49 -04:00
parent 028ac3ebb6
commit 385e01821e
4 changed files with 18 additions and 10 deletions

View File

@ -2140,6 +2140,7 @@ Work to reduce allocations
Prevent mouse event re-allocation every frame
More allocation work
Frametime reporting work
Raycast allocation fix

View File

@ -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;
}

View File

@ -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

View File

@ -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);
}
//