package electrosphere.game.state; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.Entity; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.AttackTree; import electrosphere.entity.state.IdleTree; import electrosphere.entity.state.movement.MovementTree; import electrosphere.entity.state.ParticleTree; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.entity.types.hitbox.HitboxUtils; import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.life.LifeState; import electrosphere.entity.types.life.LifeUtils; import electrosphere.entity.types.particle.ParticleUtils; import electrosphere.main.Globals; import static electrosphere.main.Main.deltaTime; import electrosphere.renderer.Actor; /** * * @author amaterasu */ public class MicroSimulation { boolean isReady = false; public MicroSimulation(){ isReady = true; } public void simulate(){ //simulate bullet physics engine step Globals.collisionEngine.simulatePhysics(deltaTime); //update dynamic entity positions calculated by bullet // Globals.collisionEngine.updateDynamicObjectTransforms(); //list dynamic object positions // Globals.collisionEngine.listBodyPositions(); //simulate ai Globals.aiManager.simulate(); //update actor animations for(Entity currentEntity : Globals.entityManager.getDrawable()){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); //increment animations if(currentActor.getCurrentAnimation() != null){ currentActor.incrementAnimationTime(deltaTime); } } //make items play idle animation for(Entity item : Globals.entityManager.getItemEntities()){ ItemUtils.updateItemActorAnimation(item); } //simulate creature behavior trees for(Entity currentMoveable : Globals.entityManager.getMoveable()){ MovementTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable); behaviorTree.simulate(); } //attacker behavior tree for(Entity currentAttacker : Globals.entityManager.getAttackerEntities()){ AttackTree attackTree = CreatureUtils.getAttackTree(currentAttacker); attackTree.simulate(); } //idle behavior tree for(Entity currentIdler : Globals.entityManager.getCreatureEntities()){ IdleTree idleTree = CreatureUtils.getIdleTree(currentIdler); idleTree.simulate(); } //life state updates for(Entity lifeStateEntity : Globals.entityManager.getLifeStateEntities()){ LifeState lifeState = LifeUtils.getLifeState(lifeStateEntity); lifeState.simulate(); } //particle state updates for(Entity particle : Globals.entityManager.getParticles()){ ParticleTree tree = ParticleUtils.getParticleTree(particle); tree.simulate(); ParticleUtils.makeParticleBillboardFaceCamera(particle); } //update attached entity positions AttachUtils.updateAttachedEntityPositions(); //update hitbox positions for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){ HitboxUtils.updatePosition(currentHitbox); } //collide hitboxes for(Entity currentHitbox : Globals.hitboxManager.getAllHitboxes()){ if(isReady){ HitboxUtils.collideEntities(currentHitbox); } } } public boolean isReady(){ return isReady; } public void freeze(){ isReady = false; } public void unfreeze(){ isReady = true; } }