physics spawning LOD
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
8957d96809
commit
272a1268a0
@ -1971,6 +1971,7 @@ Performance improvements
|
||||
- Multiple visual LOD levels
|
||||
- AI does not simulate for low-lod server entities
|
||||
- Nearby entity lookup caching per frame
|
||||
- Far-away entities do not spawn physics by default
|
||||
Lod emitter service checker function
|
||||
|
||||
|
||||
|
||||
@ -181,6 +181,10 @@ public class ServerGroundMovementTree implements BehaviorTree {
|
||||
}
|
||||
}
|
||||
DBody body = PhysicsEntityUtils.getDBody(parent);
|
||||
//TODO: eventually handle non-rigid-body entities
|
||||
if(body == null){
|
||||
return;
|
||||
}
|
||||
DVector3C linearVelocity = body.getLinearVel();
|
||||
|
||||
//
|
||||
|
||||
@ -512,7 +512,9 @@ public class CommonEntityUtils {
|
||||
//
|
||||
if(rawType.getCollidable() != null){
|
||||
CollidableTemplate physicsTemplate = rawType.getCollidable();
|
||||
PhysicsEntityUtils.serverAttachCollidableTemplate(realm, entity, physicsTemplate);
|
||||
if(Globals.serverState.lodEmitterService.isFullLod(position)){
|
||||
PhysicsEntityUtils.serverAttachCollidableTemplate(realm, entity, physicsTemplate);
|
||||
}
|
||||
ServerLODComponent.attachTree(entity);
|
||||
}
|
||||
//
|
||||
|
||||
@ -64,6 +64,7 @@ public class MainServerFunctions {
|
||||
private static void simulateServices(){
|
||||
Globals.profiler.beginCpuSample("MainServerFunctions.simulateServices");
|
||||
Globals.serverState.structureScanningService.simulate();
|
||||
Globals.serverState.lodEmitterService.simulate();
|
||||
Globals.profiler.endCpuSample();
|
||||
}
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ public class PlayerCharacterCreation {
|
||||
//
|
||||
//spawn entity in world
|
||||
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);
|
||||
|
||||
//
|
||||
|
||||
@ -7,7 +7,6 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
|
||||
import electrosphere.engine.Globals;
|
||||
import electrosphere.engine.signal.Signal.SignalType;
|
||||
import electrosphere.engine.signal.SignalServiceImpl;
|
||||
import electrosphere.entity.Entity;
|
||||
@ -24,6 +23,13 @@ public class LODEmitterService extends SignalServiceImpl {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@ -68,19 +74,40 @@ public class LODEmitterService extends SignalServiceImpl {
|
||||
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
|
||||
* @param position The position
|
||||
* @return true if it is full lod, false otherwise
|
||||
*/
|
||||
public boolean isFullLod(Vector3d position){
|
||||
for(Entity emitter : Globals.serverState.lodEmitterService.getEmitters()){
|
||||
for(Entity emitter : this.getEmitters()){
|
||||
Vector3d emitterLoc = EntityUtils.getPosition(emitter);
|
||||
double dist = position.distance(emitterLoc);
|
||||
if(dist < ServerLODComponent.FULL_RES){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(Vector3d tempVec : this.tempVecs){
|
||||
double dist = position.distance(tempVec);
|
||||
if(dist < ServerLODComponent.FULL_RES){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user