vector pooling work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
da3ada73d0
commit
03035aa1fb
@ -1989,7 +1989,7 @@ Performance improvements
|
|||||||
Increase human move speed
|
Increase human move speed
|
||||||
LOD components re-attach physics
|
LOD components re-attach physics
|
||||||
Memory improvements
|
Memory improvements
|
||||||
- Gridded data cell physics cell pooling
|
- Rely on vector pool more
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import electrosphere.entity.EntityDataStrings;
|
|||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.btree.BehaviorTree;
|
import electrosphere.entity.btree.BehaviorTree;
|
||||||
import electrosphere.entity.types.common.CommonEntityUtils;
|
import electrosphere.entity.types.common.CommonEntityUtils;
|
||||||
|
import electrosphere.mem.VectorPool;
|
||||||
import electrosphere.util.math.SpatialMathUtils;
|
import electrosphere.util.math.SpatialMathUtils;
|
||||||
|
|
||||||
import org.joml.Matrix4d;
|
import org.joml.Matrix4d;
|
||||||
@ -220,17 +221,27 @@ public class CameraEntityUtils {
|
|||||||
* @return The view matrix for the camera
|
* @return The view matrix for the camera
|
||||||
*/
|
*/
|
||||||
public static Matrix4d getCameraViewMatrix(Entity camera){
|
public static Matrix4d getCameraViewMatrix(Entity camera){
|
||||||
Vector3d cameraCenter = new Vector3d(0,0,0);//getViewMatrixCenterOffset(camera);
|
//alloc
|
||||||
Vector3d cameraEye = new Vector3d(cameraCenter).add(getCameraEye(camera));
|
Vector3d cameraCenter = VectorPool.getD();
|
||||||
Vector3d cameraUp = SpatialMathUtils.getUpVector();
|
Vector3d cameraEye = VectorPool.getD();
|
||||||
|
Vector3d cameraUp = VectorPool.getD();
|
||||||
|
|
||||||
|
//perform math
|
||||||
|
cameraCenter.set(0,0,0);
|
||||||
|
cameraEye.set(cameraCenter).add(getCameraEye(camera));
|
||||||
|
SpatialMathUtils.makeUpVector(cameraUp);
|
||||||
//!!before you make the same mistake I made, cameraEye is NOT NECESSARILY normalized/unit vector
|
//!!before you make the same mistake I made, cameraEye is NOT NECESSARILY normalized/unit vector
|
||||||
//the orbital distance and offset are included in this vector
|
//the orbital distance and offset are included in this vector
|
||||||
cameraEye = new Vector3d(getCameraEye(camera));
|
|
||||||
Matrix4d rVal = new Matrix4d().setLookAt(
|
Matrix4d rVal = new Matrix4d().setLookAt(
|
||||||
cameraEye, //eye
|
cameraEye, //eye
|
||||||
cameraCenter, //center
|
cameraCenter, //center
|
||||||
cameraUp // up
|
cameraUp // up
|
||||||
).scale(1.0f, 1.0f, 1.0f);
|
).scale(1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
|
//free
|
||||||
|
VectorPool.release(cameraCenter);
|
||||||
|
VectorPool.release(cameraEye);
|
||||||
|
VectorPool.release(cameraUp);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import electrosphere.client.entity.camera.CameraEntityUtils;
|
|||||||
import electrosphere.client.entity.crosshair.Crosshair;
|
import electrosphere.client.entity.crosshair.Crosshair;
|
||||||
import electrosphere.engine.Globals;
|
import electrosphere.engine.Globals;
|
||||||
import electrosphere.entity.EntityUtils;
|
import electrosphere.entity.EntityUtils;
|
||||||
|
import electrosphere.mem.VectorPool;
|
||||||
import electrosphere.net.parser.net.message.EntityMessage;
|
import electrosphere.net.parser.net.message.EntityMessage;
|
||||||
import electrosphere.renderer.ui.events.MouseEvent;
|
import electrosphere.renderer.ui.events.MouseEvent;
|
||||||
import electrosphere.util.math.SpatialMathUtils;
|
import electrosphere.util.math.SpatialMathUtils;
|
||||||
@ -113,7 +114,8 @@ public class CameraHandler {
|
|||||||
|
|
||||||
Vector3d characterPos = EntityUtils.getPosition(Globals.clientState.playerEntity);
|
Vector3d characterPos = EntityUtils.getPosition(Globals.clientState.playerEntity);
|
||||||
Vector3d targetPos = Crosshair.getTargetPosition();
|
Vector3d targetPos = Crosshair.getTargetPosition();
|
||||||
Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize();
|
Vector3d diffed = VectorPool.getD();
|
||||||
|
diffed.set(targetPos).sub(characterPos).mul(-1).normalize();
|
||||||
cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize();
|
cameraRotationVector.set((float)diffed.x, 0.5f, (float)diffed.z).normalize();
|
||||||
|
|
||||||
yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x));
|
yaw = (float)Math.toDegrees(Math.atan2(diffed.z, diffed.x));
|
||||||
@ -121,6 +123,7 @@ public class CameraHandler {
|
|||||||
CameraEntityUtils.setCameraPitch(Globals.clientState.playerCamera, pitch);
|
CameraEntityUtils.setCameraPitch(Globals.clientState.playerCamera, pitch);
|
||||||
CameraEntityUtils.setCameraYaw(Globals.clientState.playerCamera, yaw);
|
CameraEntityUtils.setCameraYaw(Globals.clientState.playerCamera, yaw);
|
||||||
|
|
||||||
|
VectorPool.release(diffed);
|
||||||
} else {
|
} else {
|
||||||
CameraEntityUtils.setCameraPitch(Globals.clientState.playerCamera, pitch);
|
CameraEntityUtils.setCameraPitch(Globals.clientState.playerCamera, pitch);
|
||||||
CameraEntityUtils.setCameraYaw(Globals.clientState.playerCamera, yaw);
|
CameraEntityUtils.setCameraYaw(Globals.clientState.playerCamera, yaw);
|
||||||
@ -133,15 +136,27 @@ public class CameraHandler {
|
|||||||
cameraRotationVector.normalize();
|
cameraRotationVector.normalize();
|
||||||
}
|
}
|
||||||
if(trackPlayerEntity && Globals.clientState.playerEntity != null){
|
if(trackPlayerEntity && Globals.clientState.playerEntity != null){
|
||||||
|
//free previous vec
|
||||||
|
Vector3d oldCenter = CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera);
|
||||||
Vector3d entityPos = EntityUtils.getPosition(Globals.clientState.playerEntity);
|
Vector3d entityPos = EntityUtils.getPosition(Globals.clientState.playerEntity);
|
||||||
CameraEntityUtils.setCameraCenter(Globals.clientState.playerCamera, new Vector3d(entityPos).add(CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.clientState.playerCamera)));
|
Vector3d newCenter = VectorPool.getD();
|
||||||
|
newCenter.set(entityPos).add(CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.clientState.playerCamera));
|
||||||
|
CameraEntityUtils.setCameraCenter(Globals.clientState.playerCamera, newCenter);
|
||||||
|
VectorPool.release(oldCenter);
|
||||||
}
|
}
|
||||||
//update view matrix offset
|
//update view matrix offset
|
||||||
float xFactor = (float)Math.cos(yaw / 180.0f * Math.PI);
|
float xFactor = (float)Math.cos(yaw / 180.0f * Math.PI);
|
||||||
float yFactor = (float)Math.sin(yaw / 180.0f * Math.PI);
|
float yFactor = (float)Math.sin(yaw / 180.0f * Math.PI);
|
||||||
|
|
||||||
|
//update offset
|
||||||
Vector3d radialOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.clientState.playerCamera);
|
Vector3d radialOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.clientState.playerCamera);
|
||||||
Vector3d trueOffset = new Vector3d(radialOffset).mul(xFactor,1.0f,yFactor);
|
Vector3d oldOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.clientState.playerCamera);
|
||||||
|
Vector3d trueOffset = VectorPool.getD();
|
||||||
|
trueOffset.set(radialOffset).mul(xFactor,1.0f,yFactor);
|
||||||
CameraEntityUtils.setOrbitalCameraRadialOffset(Globals.clientState.playerCamera, trueOffset);
|
CameraEntityUtils.setOrbitalCameraRadialOffset(Globals.clientState.playerCamera, trueOffset);
|
||||||
|
VectorPool.release(oldOffset);
|
||||||
|
|
||||||
|
//update rotation vec
|
||||||
cameraRotationVector.mul(CameraEntityUtils.getOrbitalCameraDistance(Globals.clientState.playerCamera));
|
cameraRotationVector.mul(CameraEntityUtils.getOrbitalCameraDistance(Globals.clientState.playerCamera));
|
||||||
CameraEntityUtils.setCameraEye(Globals.clientState.playerCamera, cameraRotationVector);
|
CameraEntityUtils.setCameraEye(Globals.clientState.playerCamera, cameraRotationVector);
|
||||||
|
|
||||||
|
|||||||
@ -197,6 +197,7 @@ public class CursorState {
|
|||||||
* Updates the position of the player's in world cursor
|
* Updates the position of the player's in world cursor
|
||||||
*/
|
*/
|
||||||
public void updatePlayerCursor(){
|
public void updatePlayerCursor(){
|
||||||
|
Globals.profiler.beginCpuSample("CursorState.updatePlayerCursor");
|
||||||
CollisionEngine collisionEngine = Globals.clientState.clientSceneWrapper.getCollisionEngine();
|
CollisionEngine collisionEngine = Globals.clientState.clientSceneWrapper.getCollisionEngine();
|
||||||
Entity camera = Globals.clientState.playerCamera;
|
Entity camera = Globals.clientState.playerCamera;
|
||||||
if(
|
if(
|
||||||
@ -225,6 +226,7 @@ public class CursorState {
|
|||||||
}
|
}
|
||||||
EntityUtils.getPosition(CursorState.playerGridAlignedCursor).set(cursorPos);
|
EntityUtils.getPosition(CursorState.playerGridAlignedCursor).set(cursorPos);
|
||||||
}
|
}
|
||||||
|
Globals.profiler.endCpuSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -164,11 +164,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
*/
|
*/
|
||||||
private Map<Long,PhysicsDataCell> posPhysicsMap = new HashMap<Long,PhysicsDataCell>();
|
private Map<Long,PhysicsDataCell> posPhysicsMap = new HashMap<Long,PhysicsDataCell>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Pooling for physics data cells
|
|
||||||
*/
|
|
||||||
private LinkedList<PhysicsDataCell> cellPool = new LinkedList<PhysicsDataCell>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of data cells cleaned up in the most recent frame
|
* Number of data cells cleaned up in the most recent frame
|
||||||
*/
|
*/
|
||||||
@ -389,7 +384,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
//the server will not be able to synchronize it properly.
|
//the server will not be able to synchronize it properly.
|
||||||
ServerEntityUtils.initiallyPositionEntity(parent,blockEntity,realPos);
|
ServerEntityUtils.initiallyPositionEntity(parent,blockEntity,realPos);
|
||||||
ServerEntityUtils.initiallyPositionEntity(parent,terrainEntity,realPos);
|
ServerEntityUtils.initiallyPositionEntity(parent,terrainEntity,realPos);
|
||||||
PhysicsDataCell cell = this.getPhysicsDataCell(worldPos, terrainEntity, blockEntity);
|
PhysicsDataCell cell = PhysicsDataCell.createPhysicsCell(terrainEntity, blockEntity);
|
||||||
cell.setTerrainChunk(terrainChunk);
|
cell.setTerrainChunk(terrainChunk);
|
||||||
cell.setBlockChunk(blockChunkData);
|
cell.setBlockChunk(blockChunkData);
|
||||||
cell.generatePhysics();
|
cell.generatePhysics();
|
||||||
@ -614,7 +609,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
this.groundDataCells.remove(key);
|
this.groundDataCells.remove(key);
|
||||||
PhysicsDataCell releasedCell = this.posPhysicsMap.remove(key);
|
PhysicsDataCell releasedCell = this.posPhysicsMap.remove(key);
|
||||||
if(releasedCell != null){
|
if(releasedCell != null){
|
||||||
this.cellPool.add(releasedCell);
|
|
||||||
releasedCell.destroyEntities();
|
releasedCell.destroyEntities();
|
||||||
}
|
}
|
||||||
this.cellPositionMap.remove(cell);
|
this.cellPositionMap.remove(cell);
|
||||||
@ -622,23 +616,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
this.cellPlayerlessFrameMap.remove(cell);
|
this.cellPlayerlessFrameMap.remove(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a physics data cell from the pool
|
|
||||||
* @return The physics data cell
|
|
||||||
*/
|
|
||||||
private PhysicsDataCell getPhysicsDataCell(Vector3i worldPos, Entity physicsEntity, Entity blockPhysicsEntity){
|
|
||||||
PhysicsDataCell rVal = null;
|
|
||||||
loadedCellsLock.lock();
|
|
||||||
if(cellPool.size() > 0){
|
|
||||||
rVal = this.cellPool.poll();
|
|
||||||
rVal.reset(worldPos, physicsEntity, blockPhysicsEntity);
|
|
||||||
} else {
|
|
||||||
rVal = PhysicsDataCell.createPhysicsCell(physicsEntity, blockPhysicsEntity);
|
|
||||||
}
|
|
||||||
loadedCellsLock.unlock();
|
|
||||||
return rVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get data cell at a given real point in this realm
|
* Get data cell at a given real point in this realm
|
||||||
* @param point The real point
|
* @param point The real point
|
||||||
@ -840,7 +817,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager
|
|||||||
ServerEntityUtils.initiallyPositionEntity(realm,blockEntity,realPos);
|
ServerEntityUtils.initiallyPositionEntity(realm,blockEntity,realPos);
|
||||||
ServerEntityUtils.initiallyPositionEntity(realm,terrainEntity,realPos);
|
ServerEntityUtils.initiallyPositionEntity(realm,terrainEntity,realPos);
|
||||||
|
|
||||||
PhysicsDataCell targetCell = this.getPhysicsDataCell(worldPos, terrainEntity, blockEntity);
|
PhysicsDataCell targetCell = PhysicsDataCell.createPhysicsCell(terrainEntity, blockEntity);
|
||||||
if(cell == null){
|
if(cell == null){
|
||||||
posPhysicsMap.put(key, targetCell);
|
posPhysicsMap.put(key, targetCell);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -86,6 +86,13 @@ public class PhysicsDataCell {
|
|||||||
this.blockPhysicsEntity = null;
|
this.blockPhysicsEntity = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees the data in this cell
|
||||||
|
*/
|
||||||
|
public void free(){
|
||||||
|
this.destroyEntities();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the state of the physics data cell
|
* Resets the state of the physics data cell
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -45,6 +45,14 @@ public class SpatialMathUtils {
|
|||||||
return new Vector3d(0,1,0);
|
return new Vector3d(0,1,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the target vector to point up
|
||||||
|
* @param target The target vector
|
||||||
|
*/
|
||||||
|
public static void makeUpVector(Vector3d target){
|
||||||
|
target.set(0,1,0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the origin vector of the engine
|
* Gets the origin vector of the engine
|
||||||
* @return The origin vector
|
* @return The origin vector
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user