Client entity culling
This commit is contained in:
parent
260043092d
commit
efa2afa822
@ -3,10 +3,16 @@ package electrosphere.client.scene;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.joml.Vector3d;
|
||||||
|
|
||||||
import electrosphere.collision.CollisionEngine;
|
import electrosphere.collision.CollisionEngine;
|
||||||
|
import electrosphere.engine.Globals;
|
||||||
|
import electrosphere.entity.ClientEntityUtils;
|
||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
|
import electrosphere.entity.EntityUtils;
|
||||||
import electrosphere.entity.Scene;
|
import electrosphere.entity.Scene;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
|
import electrosphere.server.terrain.manager.ServerTerrainChunk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around the scene object to provide lots of much needed client-specific utility
|
* Wrapper around the scene object to provide lots of much needed client-specific utility
|
||||||
@ -94,4 +100,17 @@ public class ClientSceneWrapper {
|
|||||||
return collisionEngine;
|
return collisionEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroys all entities outside simulation range
|
||||||
|
*/
|
||||||
|
public void destroyEntitiesOutsideSimRange(){
|
||||||
|
double cullRadius = Globals.drawCellManager.getDrawRadius() + ServerTerrainChunk.CHUNK_DIMENSION;
|
||||||
|
for(Entity entity : scene.getEntityList()){
|
||||||
|
Vector3d position = EntityUtils.getPosition(entity);
|
||||||
|
if(Globals.playerEntity != null && EntityUtils.getPosition(Globals.playerEntity).distance(position) > cullRadius){
|
||||||
|
EntityUtils.cleanUpEntity(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ public class ClientFunctions {
|
|||||||
public static void runClientFunctions(){
|
public static void runClientFunctions(){
|
||||||
ClientTerrainManager.generateTerrainChunkGeometry();
|
ClientTerrainManager.generateTerrainChunkGeometry();
|
||||||
updateSkyboxPos();
|
updateSkyboxPos();
|
||||||
|
Globals.clientSceneWrapper.destroyEntitiesOutsideSimRange();
|
||||||
// updateCellManager();
|
// updateCellManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -423,6 +423,15 @@ public class DrawCellManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the draw radius
|
||||||
|
* @return the draw radius
|
||||||
|
*/
|
||||||
|
public double getDrawRadius(){
|
||||||
|
return drawRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public
|
// public
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user