more vector pooling

This commit is contained in:
austin 2025-05-25 15:16:50 -04:00
parent feac1383da
commit 45a4115675
5 changed files with 54 additions and 7 deletions

View File

@ -1987,6 +1987,7 @@ Performance improvements
- Behavior tree addition/subtraction from scene optimization
- Reduce bones on LOD human model
- Shallow clone on physics cell creation
- More vector pool usage
Increase human move speed
LOD components re-attach physics

View File

@ -6,6 +6,8 @@ import java.util.List;
import org.joml.Quaterniond;
import org.joml.Vector3d;
import electrosphere.mem.VectorPool;
/**
* Converts data structures between formats saved to disk vs formats used in engine
*/
@ -43,12 +45,12 @@ public class DataFormatUtil {
*/
public static Vector3d getDoubleListAsVector(List<Double> values){
if(values == null){
return new Vector3d();
return VectorPool.getD();
}
if(values.size() > 0){
return new Vector3d(values.get(0),values.get(1),values.get(2));
return VectorPool.getD(values.get(0),values.get(1),values.get(2));
} else {
return new Vector3d();
return VectorPool.getD();
}
}

View File

@ -6,6 +6,7 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.logger.LoggerInterface;
import electrosphere.mem.VectorPool;
import electrosphere.renderer.actor.Actor;
import electrosphere.server.datacell.ServerDataCell;
import electrosphere.server.datacell.utils.ServerEntityTagUtils;
@ -346,7 +347,7 @@ public class AttachUtils {
Vector3d parentScale
){
//transform bone space
Vector3d position = new Vector3d(offsetVector);
Vector3d position = VectorPool.getD(offsetVector);
position = position.rotate(new Quaterniond(boneRotation));
position = position.add(bonePosition);
position = position.mul(parentScale);

View File

@ -26,6 +26,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.attach.AttachUtils;
import electrosphere.entity.state.hitbox.HitboxCollectionState.HitboxState.HitboxShapeType;
import electrosphere.logger.LoggerInterface;
import electrosphere.mem.VectorPool;
import electrosphere.server.datacell.Realm;
import electrosphere.server.entity.poseactor.PoseActor;
import electrosphere.util.math.SpatialMathUtils;
@ -461,22 +462,29 @@ public class HitboxCollectionState {
Quaterniond offsetRotation = new Quaterniond();
//the bone's transform
Vector3d bonePositionD = new Vector3d();
Vector3d bonePositionD = VectorPool.getD();
if(bonePosition != null){
bonePositionD = new Vector3d(bonePosition);
bonePositionD.set(bonePosition);
}
Quaterniond boneRotation = new Quaterniond();
//the parent's transform
Vector3d parentPosition = EntityUtils.getPosition(parent);
Quaterniond parentRotation = EntityUtils.getRotation(parent);
Vector3d parentScale = new Vector3d(EntityUtils.getScale(parent));
Vector3d parentScale = VectorPool.getD();
parentScale.set(EntityUtils.getScale(parent));
//calculate
Vector3d hitboxPos = AttachUtils.calculateBoneAttachmentLocalPosition(offsetPosition, offsetRotation, bonePositionD, boneRotation, parentPosition, parentRotation, parentScale);
//actually set value
PhysicsEntityUtils.setGeometryOffsetPosition(collisionEngine, geom, hitboxPos, new Quaterniond());
//free vecs used in computation
VectorPool.release(bonePositionD);
VectorPool.release(parentScale);
VectorPool.release(hitboxPos);
}
/**

View File

@ -73,6 +73,41 @@ public class VectorPool {
return rVal;
}
/**
* Gets a Vector3d from the pool. Allocates if no free one is available.
* @param source The source to copy from
* @return A Vector3d
*/
public static Vector3d getD(Vector3d source){
Vector3d rVal = null;
lock.lock();
if(vec3dPool.size() > 0){
rVal = vec3dPool.remove(0);
} else {
rVal = new Vector3d();
}
rVal.set(source);
lock.unlock();
return rVal;
}
/**
* Gets a Vector3d from the pool. Allocates if no free one is available.
* @return A Vector3d
*/
public static Vector3d getD(double x, double y, double z){
Vector3d rVal = null;
lock.lock();
if(vec3dPool.size() > 0){
rVal = vec3dPool.remove(0);
} else {
rVal = new Vector3d();
}
rVal.set(x,y,z);
lock.unlock();
return rVal;
}
/**
* Releases a Vector3d back into the pool
* @param data The object to release