small improvements
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-25 19:11:08 -04:00
parent de6876bf2f
commit a413b9aa79
6 changed files with 59 additions and 38 deletions

View File

@ -1992,6 +1992,8 @@ Performance improvements
- Undo most object pooling
- ServerBlockChunkDiskMap uses short pool
- Client leverages block chunk short pool
- Client doesn't load physics on entities by default
- Block chunk disk map writes files without allocating a buffer
Increase human move speed
LOD components re-attach physics
VectorPool->JomlPool

View File

@ -187,6 +187,12 @@ public class CollisionEngine {
* Number of geometries
*/
private int geomCount = 0;
/**
* buffer for storing potential collisions
*/
private DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS);
/**
* Constructor
@ -432,8 +438,8 @@ public class CollisionEngine {
Globals.profiler.beginAggregateCpuSample("CollisionEngine.nearCallback - Full collision phase");
try {
//creates a buffer to store potential collisions
DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS); // up to MAX_CONTACTS contacts per box-box
//null out the contact buffer
contacts.nullify();
SurfaceParams surfaceParams = c1.getSurfaceParams();
for (int i=0; i<MAX_CONTACTS; i++) {
DContact contact = contacts.get(i);

View File

@ -52,6 +52,11 @@ public class PhysicsEntityUtils {
*/
static final double WORLD_MARGIN = 0.001;
/**
* Distance after which client does not generate collidables by default
*/
public static final double CLIENT_LOD_DIST = 50;
/**
* [CLIENT ONLY] Attaches a collidable template to a given entity
* @param rVal The entity

View File

@ -3,9 +3,11 @@ package electrosphere.entity.state.lod;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.PhysicsUtils;
import electrosphere.data.entity.collidable.CollidableTemplate;
import electrosphere.data.entity.common.CommonEntityType;
import electrosphere.engine.Globals;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.Entity;
import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums;
import electrosphere.entity.btree.BehaviorTree;
@ -37,6 +39,18 @@ public class ClientLODComponent implements BehaviorTree {
@Override
public void simulate(float deltaTime) {
if(this.lodLevel == ServerLODComponent.FULL_RES){
CommonEntityType commonData = CommonEntityUtils.getCommonData(this.parent);
if(
commonData.getCollidable() != null &&
PhysicsEntityUtils.getCollidable(this.parent) == null &&
Globals.clientState.playerEntity != null &&
EntityUtils.getPosition(Globals.clientState.playerEntity).distance(EntityUtils.getPosition(this.parent)) < ServerLODComponent.LOD_RADIUS
){
CollidableTemplate physicsTemplate = commonData.getCollidable();
PhysicsEntityUtils.clientAttachCollidableTemplate(this.parent, physicsTemplate);
}
}
if(cachedLodLevel != lodLevel){
cachedLodLevel = lodLevel;
if(cachedLodLevel == ServerLODComponent.FULL_RES){

View File

@ -188,8 +188,6 @@ public class CommonEntityUtils {
//
//
if(rawType.getCollidable() != null){
CollidableTemplate physicsTemplate = rawType.getCollidable();
PhysicsEntityUtils.clientAttachCollidableTemplate(entity, physicsTemplate);
ClientLODComponent.attachTree(entity);
}

View File

@ -1,6 +1,7 @@
package electrosphere.server.physics.block.diskmap;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
@ -214,43 +215,38 @@ public class ServerBlockChunkDiskMap {
} else {
fileName = BLOCK_DATA_DIR + chunkKey + "b.dat";
}
//generate binary for the file
short[] type = chunkData.getType();
short[] metadata = chunkData.getMetadata();
//allocate buffer
ByteBuffer buffer = null;
if(chunkData.getHomogenousValue() == BlockChunkData.NOT_HOMOGENOUS){
buffer = ByteBuffer.allocate(ServerBlockChunkDiskMap.FILE_HEADER + BlockChunkData.TOTAL_DATA_WIDTH * 2 * 2);
} else {
buffer = ByteBuffer.allocate(ServerBlockChunkDiskMap.FILE_HEADER + 2);
}
//push data
if(chunkData.getHomogenousValue() == BlockChunkData.NOT_HOMOGENOUS){
//put header
buffer.putInt(HEADER_NON_HOMOGENOUS);
//put data
ShortBuffer shortView = buffer.asShortBuffer();
for(int i = 0; i < BlockChunkData.TOTAL_DATA_WIDTH; i++){
shortView.put(type[i]);
}
for(int i = 0; i < BlockChunkData.TOTAL_DATA_WIDTH; i++){
shortView.put(metadata[i]);
}
} else {
//put header
buffer.putInt(HEADER_HOMOGENOUS);
//put data
buffer.putShort(chunkData.getHomogenousValue());
}
//compress
ByteArrayOutputStream out = new ByteArrayOutputStream();
DeflaterOutputStream deflaterInputStream = new DeflaterOutputStream(out);
DeflaterOutputStream deflaterOutStream = new DeflaterOutputStream(out);
DataOutputStream dataOut = new DataOutputStream(deflaterOutStream);
try {
deflaterInputStream.write(buffer.array());
deflaterInputStream.flush();
deflaterInputStream.close();
//generate binary for the file
short[] type = chunkData.getType();
short[] metadata = chunkData.getMetadata();
//push data
if(chunkData.getHomogenousValue() == BlockChunkData.NOT_HOMOGENOUS){
//put header
dataOut.writeInt(HEADER_NON_HOMOGENOUS);
//put data
for(int i = 0; i < BlockChunkData.TOTAL_DATA_WIDTH; i++){
dataOut.writeShort(type[i]);
}
for(int i = 0; i < BlockChunkData.TOTAL_DATA_WIDTH; i++){
dataOut.writeShort(metadata[i]);
}
} else {
//put header
dataOut.writeInt(HEADER_HOMOGENOUS);
//put data
dataOut.writeShort(chunkData.getHomogenousValue());
}
dataOut.flush();
dataOut.close();
//write to disk
FileUtils.saveBinaryToSavePath(Globals.serverState.currentSave.getName(), fileName, out.toByteArray());
//save to the map of filenames