physics spawning LOD
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-24 22:01:29 -04:00
parent 8957d96809
commit 272a1268a0
6 changed files with 39 additions and 3 deletions

View File

@ -1971,6 +1971,7 @@ Performance improvements
- Multiple visual LOD levels - Multiple visual LOD levels
- AI does not simulate for low-lod server entities - AI does not simulate for low-lod server entities
- Nearby entity lookup caching per frame - Nearby entity lookup caching per frame
- Far-away entities do not spawn physics by default
Lod emitter service checker function Lod emitter service checker function

View File

@ -181,6 +181,10 @@ public class ServerGroundMovementTree implements BehaviorTree {
} }
} }
DBody body = PhysicsEntityUtils.getDBody(parent); DBody body = PhysicsEntityUtils.getDBody(parent);
//TODO: eventually handle non-rigid-body entities
if(body == null){
return;
}
DVector3C linearVelocity = body.getLinearVel(); DVector3C linearVelocity = body.getLinearVel();
// //

View File

@ -512,7 +512,9 @@ public class CommonEntityUtils {
// //
if(rawType.getCollidable() != null){ if(rawType.getCollidable() != null){
CollidableTemplate physicsTemplate = rawType.getCollidable(); CollidableTemplate physicsTemplate = rawType.getCollidable();
PhysicsEntityUtils.serverAttachCollidableTemplate(realm, entity, physicsTemplate); if(Globals.serverState.lodEmitterService.isFullLod(position)){
PhysicsEntityUtils.serverAttachCollidableTemplate(realm, entity, physicsTemplate);
}
ServerLODComponent.attachTree(entity); ServerLODComponent.attachTree(entity);
} }
// //

View File

@ -64,6 +64,7 @@ public class MainServerFunctions {
private static void simulateServices(){ private static void simulateServices(){
Globals.profiler.beginCpuSample("MainServerFunctions.simulateServices"); Globals.profiler.beginCpuSample("MainServerFunctions.simulateServices");
Globals.serverState.structureScanningService.simulate(); Globals.serverState.structureScanningService.simulate();
Globals.serverState.lodEmitterService.simulate();
Globals.profiler.endCpuSample(); Globals.profiler.endCpuSample();
} }

View File

@ -42,6 +42,7 @@ public class PlayerCharacterCreation {
// //
//spawn entity in world //spawn entity in world
Vector3d spawnPoint = PlayerCharacterCreation.solveSpawnPoint(realm, connectionHandler); Vector3d spawnPoint = PlayerCharacterCreation.solveSpawnPoint(realm, connectionHandler);
Globals.serverState.lodEmitterService.addTempVec(spawnPoint);
Entity newPlayerEntity = CreatureUtils.serverSpawnBasicCreature(realm,new Vector3d(spawnPoint.x,spawnPoint.y,spawnPoint.z),raceName,template); Entity newPlayerEntity = CreatureUtils.serverSpawnBasicCreature(realm,new Vector3d(spawnPoint.x,spawnPoint.y,spawnPoint.z),raceName,template);
// //

View File

@ -7,7 +7,6 @@ import java.util.concurrent.locks.ReentrantLock;
import org.joml.Vector3d; import org.joml.Vector3d;
import electrosphere.engine.Globals;
import electrosphere.engine.signal.Signal.SignalType; import electrosphere.engine.signal.Signal.SignalType;
import electrosphere.engine.signal.SignalServiceImpl; import electrosphere.engine.signal.SignalServiceImpl;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
@ -24,6 +23,13 @@ public class LODEmitterService extends SignalServiceImpl {
*/ */
private List<Entity> emitters = new LinkedList<Entity>(); private List<Entity> emitters = new LinkedList<Entity>();
/**
* List of temporary vecs for emitter checking - are cleared every frame
* <p>
* Intention with this is that it can be used to guarantee a player character has physics generated
*/
private List<Vector3d> tempVecs = new LinkedList<Vector3d>();
/** /**
* Lock for thread-safeing the service * Lock for thread-safeing the service
*/ */
@ -68,19 +74,40 @@ public class LODEmitterService extends SignalServiceImpl {
lock.unlock(); lock.unlock();
} }
/**
* Clears the temp vecs
*/
public void simulate(){
this.tempVecs.clear();
}
/**
* Adds a temporary vector
* @param tempVec The temporary vector
*/
public void addTempVec(Vector3d tempVec){
this.tempVecs.add(tempVec);
}
/** /**
* Checks if a given position would be full LOD * Checks if a given position would be full LOD
* @param position The position * @param position The position
* @return true if it is full lod, false otherwise * @return true if it is full lod, false otherwise
*/ */
public boolean isFullLod(Vector3d position){ public boolean isFullLod(Vector3d position){
for(Entity emitter : Globals.serverState.lodEmitterService.getEmitters()){ for(Entity emitter : this.getEmitters()){
Vector3d emitterLoc = EntityUtils.getPosition(emitter); Vector3d emitterLoc = EntityUtils.getPosition(emitter);
double dist = position.distance(emitterLoc); double dist = position.distance(emitterLoc);
if(dist < ServerLODComponent.FULL_RES){ if(dist < ServerLODComponent.FULL_RES){
return true; return true;
} }
} }
for(Vector3d tempVec : this.tempVecs){
double dist = position.distance(tempVec);
if(dist < ServerLODComponent.FULL_RES){
return true;
}
}
return false; return false;
} }