diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 5739ae78..b813b349 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2143,6 +2143,9 @@ Frametime reporting work Raycast allocation fix Fix single block shader +(06/09/2025) +Cursor object pooling + diff --git a/src/main/java/electrosphere/controls/cursor/CursorState.java b/src/main/java/electrosphere/controls/cursor/CursorState.java index d41e5c16..8dd15ab2 100644 --- a/src/main/java/electrosphere/controls/cursor/CursorState.java +++ b/src/main/java/electrosphere/controls/cursor/CursorState.java @@ -22,6 +22,7 @@ import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityTags; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.equip.ClientToolbarState; +import electrosphere.mem.JomlPool; import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.mask.ActorTextureMask; import electrosphere.renderer.meshgen.BlockMeshgen; @@ -205,17 +206,19 @@ public class CursorState { camera != null && Globals.cursorState.playerCursor != null ){ - Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); - Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); - Vector3d cursorPos = collisionEngine.rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + Vector3d eyePos = JomlPool.getD(); + eyePos.set(CameraEntityUtils.getCameraEye(camera)).mul(-1.0); + Vector3d centerPos = JomlPool.getD(); + centerPos.set(CameraEntityUtils.getCameraCenter(camera)); + Vector3d cursorPos = collisionEngine.rayCastPosition(centerPos, eyePos, CollisionEngine.DEFAULT_INTERACT_DISTANCE); if(cursorPos == null){ - cursorPos = new Vector3d(centerPos).add(new Vector3d(eyePos).normalize().mul(-CollisionEngine.DEFAULT_INTERACT_DISTANCE)); + cursorPos = centerPos.add(eyePos.normalize().mul(CollisionEngine.DEFAULT_INTERACT_DISTANCE)); } EntityUtils.setPosition(Globals.cursorState.playerCursor, cursorPos); //clamp block cursor to nearest voxel if(clampToExistingBlock){ - cursorPos = cursorPos.add(new Vector3d(eyePos).normalize().mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER)); + cursorPos = cursorPos.add(eyePos.normalize().mul(BlockChunkData.BLOCK_SIZE_MULTIPLIER)); } cursorPos.set(this.clampPositionToNearestBlock(cursorPos)); if(Globals.cursorState.playerBlockCursor != null){ @@ -227,6 +230,10 @@ public class CursorState { CursorState.nudgeGridAlignment(cursorPos,gridAlignmentData); } EntityUtils.setPosition(CursorState.playerGridAlignedCursor, cursorPos); + + //release to pool + JomlPool.release(eyePos); + JomlPool.release(centerPos); } Globals.profiler.endCpuSample(); }