108 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package electrosphere.game.collision;
 | |
| 
 | |
| import electrosphere.game.client.terrain.manager.ClientTerrainManager;
 | |
| import electrosphere.game.client.world.ClientWorldData;
 | |
| import electrosphere.game.server.terrain.manager.ServerTerrainManager;
 | |
| import electrosphere.game.server.world.ServerWorldData;
 | |
| import org.joml.Vector3d;
 | |
| import org.joml.Vector3f;
 | |
| 
 | |
| public class CommonWorldData {
 | |
|     
 | |
|     
 | |
|     
 | |
|     ClientWorldData clientWorldData;
 | |
|     ClientTerrainManager clientTerrainManager;
 | |
|     
 | |
|     
 | |
|     
 | |
|     ServerWorldData serverWorldData;
 | |
|     ServerTerrainManager serverTerrainManager;
 | |
|     
 | |
|     
 | |
|     
 | |
|     public CommonWorldData(ClientWorldData clientWorldData, ClientTerrainManager clientTerrainManager){
 | |
|         this.clientWorldData = clientWorldData;
 | |
|         this.clientTerrainManager = clientTerrainManager;
 | |
|     }
 | |
|     
 | |
|     
 | |
|     public CommonWorldData(ServerWorldData serverWorldData, ServerTerrainManager serverTerrainManager){
 | |
|         this.serverWorldData = serverWorldData;
 | |
|         this.serverTerrainManager = serverTerrainManager;
 | |
|     }
 | |
|     
 | |
|     
 | |
|     /**
 | |
|      * IF SERVER, RETURN HEIGHT
 | |
|      * IF CLIENT:
 | |
|      *      IF HAS DATA,
 | |
|      *          RETURN HEIGHT
 | |
|      *      IF DOES NOT HAVE DATA,
 | |
|      *          RETURN 0
 | |
|      * @param position
 | |
|      * @return 
 | |
|      */
 | |
|     public double getElevationAtPoint(Vector3d position){
 | |
|         if(clientWorldData != null){
 | |
|             if(clientTerrainManager.containsHeightmapAtRealPoint(position.x, position.z)){
 | |
|                 return clientTerrainManager.getHeightAtPosition(position.x, position.z);
 | |
|             } else {
 | |
|                 return 0;
 | |
|             }
 | |
|         } else {
 | |
|             return serverTerrainManager.getHeightAtPosition(position.x, position.z);
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     
 | |
|     public Vector3f getWorldBoundMin(){
 | |
|         if(clientWorldData != null){
 | |
|             return clientWorldData.getWorldBoundMin();
 | |
|         } else {
 | |
|             return serverWorldData.getWorldBoundMin();
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     public Vector3f getWorldBoundMax(){
 | |
|         if(clientWorldData != null){
 | |
|             return clientWorldData.getWorldBoundMax();
 | |
|         } else {
 | |
|             return serverWorldData.getWorldBoundMax();
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     public int convertRealToWorld(double real){
 | |
|         if(clientWorldData != null){
 | |
|             return clientWorldData.convertRealToChunkSpace(real);
 | |
|         } else {
 | |
|             return serverWorldData.convertRealToChunkSpace(real);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public int getDynamicInterpolationRatio(){
 | |
|         if(clientWorldData != null){
 | |
|             return clientWorldData.getDynamicInterpolationRatio();
 | |
|         } else {
 | |
|             return serverWorldData.getDynamicInterpolationRatio();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public int getWorldDiscreteSize(){
 | |
|         if(clientWorldData != null){
 | |
|             return clientWorldData.getWorldDiscreteSize();
 | |
|         } else {
 | |
|             return serverWorldData.getWorldSizeDiscrete();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public float getRandomDampener(){
 | |
|         if(clientWorldData != null){
 | |
|             return clientWorldData.getRandomDampener();
 | |
|         } else {
 | |
|             return serverWorldData.getRandomDampener();
 | |
|         }
 | |
|     }
 | |
| 
 | |
| }
 |