Some checks failed
		
		
	
	studiorailgun/Renderer/pipeline/head There was a failure building this commit
				
			
		
			
				
	
	
		
			128 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			128 lines
		
	
	
		
			4.6 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package electrosphere.client.sim;
 | |
| 
 | |
| import electrosphere.engine.Globals;
 | |
| import electrosphere.engine.Main;
 | |
| import electrosphere.entity.Entity;
 | |
| import electrosphere.entity.EntityTags;
 | |
| import electrosphere.entity.EntityUtils;
 | |
| import electrosphere.entity.state.collidable.ClientCollidableTree;
 | |
| import electrosphere.entity.types.attach.AttachUtils;
 | |
| import electrosphere.entity.types.hitbox.HitboxUtils;
 | |
| import electrosphere.entity.types.item.ItemUtils;
 | |
| import electrosphere.entity.types.particle.ParticleUtils;
 | |
| import electrosphere.game.client.targeting.crosshair.Crosshair;
 | |
| import electrosphere.renderer.actor.Actor;
 | |
| 
 | |
| public class ClientSimulation {
 | |
| 
 | |
|     boolean isReady = false;
 | |
|     boolean loadTerrain = false;
 | |
|     
 | |
|     public ClientSimulation(){
 | |
|         isReady = false;
 | |
|     }
 | |
|     
 | |
|     public void simulate(){
 | |
|         //simulate bullet physics engine step
 | |
|         Globals.clientSceneWrapper.getCollisionEngine().simulatePhysics(Main.deltaFrames);
 | |
|         //update actor animations
 | |
|         for(Entity currentEntity : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.DRAWABLE)){
 | |
|             //fetch actor
 | |
|             Actor currentActor = EntityUtils.getActor(currentEntity);
 | |
|             //increment animations
 | |
|             if(currentActor.isPlayingAnimation()){
 | |
|                 currentActor.incrementAnimationTime(Main.deltaFrames / Main.targetFrameRate);
 | |
|             }
 | |
|         }
 | |
|         //make items play idle animation
 | |
|         for(Entity item : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.ITEM)){
 | |
|             ItemUtils.updateItemActorAnimation(item);
 | |
|         }
 | |
|         //particle state updates
 | |
|         for(Entity particle : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.PARTICLE)){
 | |
|             // ParticleTree tree = ParticleUtils.getParticleTree(particle);
 | |
|             // tree.simulate(Main.deltaFrames);
 | |
|             ParticleUtils.makeParticleBillboardFaceCamera(particle);
 | |
|         }
 | |
|         //update attached entity positions
 | |
|         AttachUtils.clientUpdateAttachedEntityPositions();
 | |
|         //update hitbox positions
 | |
|         for(Entity currentHitbox : Globals.clientHitboxManager.getAllHitboxes()){
 | |
|             HitboxUtils.clientUpdatePosition(currentHitbox);
 | |
|         }
 | |
|         //collide hitboxes
 | |
|         for(Entity currentHitbox : Globals.clientHitboxManager.getAllHitboxes()){
 | |
|             if(isReady){
 | |
|                 HitboxUtils.clientCollideEntities(currentHitbox);
 | |
|             }
 | |
|         }
 | |
|         //tally collidables and offset position accordingly
 | |
|         // for(Entity currentCollidable : Globals.entityManager.getEntitiesWithTag(EntityTags.COLLIDABLE)){
 | |
|         //     CollidableTree tree = CollidableTree.getCollidableTree(currentCollidable);
 | |
|         //     tree.simulate(Main.deltaFrames);
 | |
|         // }
 | |
|         //targeting crosshair
 | |
|         Crosshair.checkTargetable();
 | |
|         Crosshair.updateTargetCrosshairPosition();
 | |
|         //simulate behavior trees
 | |
|         Globals.clientSceneWrapper.getScene().simulateBehaviorTrees(Main.deltaFrames);
 | |
|         //sum collidable impulses
 | |
|         for(Entity collidable : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.COLLIDABLE)){
 | |
|             ClientCollidableTree.getClientCollidableTree(collidable).simulate(Main.deltaFrames);
 | |
|         }
 | |
|         //clear collidable impulse lists
 | |
|         Globals.clientSceneWrapper.getCollisionEngine().clearCollidableImpulseLists();
 | |
|         //delete all client side entities that aren't in visible chunks
 | |
|         if(Globals.clientEntityCullingManager != null){
 | |
|             Globals.clientEntityCullingManager.clearOutOfBoundsEntities();
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Gets whether the client simulation is ready to execute
 | |
|      * @return True if ready to execute, false otherwise
 | |
|      */
 | |
|     public boolean isReady(){
 | |
|         return isReady;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Sets the ready status of the client simulation
 | |
|      * @param ready True if ready to simulate, false otherwise
 | |
|      */
 | |
|     public void setReady(boolean ready){
 | |
|         isReady = ready;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Freezes simulation (sets ready to false)
 | |
|      */
 | |
|     public void freeze(){
 | |
|         isReady = false;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Unfreezes simulation (sets ready to true)
 | |
|      */
 | |
|     public void unfreeze(){
 | |
|         isReady = true;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Gets whether the client simulation is loading terrain
 | |
|      * @return True if loading terrain, false otherwise
 | |
|      */
 | |
|     public boolean isLoadingTerrain(){
 | |
|         return this.loadTerrain;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Sets whether the client should load terrain or not
 | |
|      * @param loadTerrain True if should load terrain, false otherwise
 | |
|      */
 | |
|     public void setLoadingTerrain(boolean loadTerrain){
 | |
|         this.loadTerrain = loadTerrain;
 | |
|     }
 | |
| 
 | |
| }
 |