cursor object pooling
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-06-09 14:30:03 -04:00
parent 0bb66aa0b4
commit f6f6bfa15c
2 changed files with 15 additions and 5 deletions

View File

@ -2143,6 +2143,9 @@ Frametime reporting work
Raycast allocation fix Raycast allocation fix
Fix single block shader Fix single block shader
(06/09/2025)
Cursor object pooling

View File

@ -22,6 +22,7 @@ import electrosphere.entity.EntityCreationUtils;
import electrosphere.entity.EntityTags; import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.equip.ClientToolbarState; import electrosphere.entity.state.equip.ClientToolbarState;
import electrosphere.mem.JomlPool;
import electrosphere.renderer.actor.Actor; import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.actor.mask.ActorTextureMask; import electrosphere.renderer.actor.mask.ActorTextureMask;
import electrosphere.renderer.meshgen.BlockMeshgen; import electrosphere.renderer.meshgen.BlockMeshgen;
@ -205,17 +206,19 @@ public class CursorState {
camera != null && camera != null &&
Globals.cursorState.playerCursor != null Globals.cursorState.playerCursor != null
){ ){
Vector3d eyePos = new Vector3d(CameraEntityUtils.getCameraEye(camera)); Vector3d eyePos = JomlPool.getD();
Vector3d centerPos = new Vector3d(CameraEntityUtils.getCameraCenter(camera)); eyePos.set(CameraEntityUtils.getCameraEye(camera)).mul(-1.0);
Vector3d cursorPos = collisionEngine.rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1.0), CollisionEngine.DEFAULT_INTERACT_DISTANCE); Vector3d centerPos = JomlPool.getD();
centerPos.set(CameraEntityUtils.getCameraCenter(camera));
Vector3d cursorPos = collisionEngine.rayCastPosition(centerPos, eyePos, CollisionEngine.DEFAULT_INTERACT_DISTANCE);
if(cursorPos == null){ 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); EntityUtils.setPosition(Globals.cursorState.playerCursor, cursorPos);
//clamp block cursor to nearest voxel //clamp block cursor to nearest voxel
if(clampToExistingBlock){ 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)); cursorPos.set(this.clampPositionToNearestBlock(cursorPos));
if(Globals.cursorState.playerBlockCursor != null){ if(Globals.cursorState.playerBlockCursor != null){
@ -227,6 +230,10 @@ public class CursorState {
CursorState.nudgeGridAlignment(cursorPos,gridAlignmentData); CursorState.nudgeGridAlignment(cursorPos,gridAlignmentData);
} }
EntityUtils.setPosition(CursorState.playerGridAlignedCursor, cursorPos); EntityUtils.setPosition(CursorState.playerGridAlignedCursor, cursorPos);
//release to pool
JomlPool.release(eyePos);
JomlPool.release(centerPos);
} }
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }