Renderer/src/main/java/electrosphere/server/simulation/MicroSimulation.java

118 lines
4.5 KiB
Java

package electrosphere.server.simulation;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.client.targeting.crosshair.Crosshair;
import electrosphere.collision.hitbox.HitboxManager;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.scene.EntityDescriptor;
import electrosphere.entity.state.ParticleTree;
import electrosphere.entity.state.attack.ClientAttackTree;
import electrosphere.entity.state.collidable.ClientCollidableTree;
import electrosphere.entity.state.collidable.ServerCollidableTree;
import electrosphere.entity.state.idle.IdleTree;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.state.life.LifeState;
import electrosphere.entity.state.life.LifeUtils;
import electrosphere.entity.state.movement.SprintTree;
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree;
import electrosphere.entity.types.particle.ParticleUtils;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.actor.Actor;
import electrosphere.server.datacell.ServerDataCell;
import java.sql.Time;
import org.joml.Vector3d;
import org.joml.Vector3f;
/**
*
* @author amaterasu
*/
public class MicroSimulation {
boolean isReady = false;
public MicroSimulation(){
isReady = false;
}
public void simulate(ServerDataCell dataCell, HitboxManager hitboxManager){
if(dataCell.isReady()){
//simulate ai
Globals.aiManager.simulate();
//update actor animations
for(Entity currentEntity : dataCell.getScene().getEntitiesWithTag(EntityTags.DRAWABLE)){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//increment animations
if(currentActor.isPlayingAnimation()){
currentActor.incrementAnimationTime(Globals.timekeeper.getSimFrameTime() / Main.targetFrameRate);
}
}
//update first person model animations
if(Globals.firstPersonEntity != null){
//fetch actor
Actor currentActor = EntityUtils.getActor(Globals.firstPersonEntity);
//increment animations
if(currentActor.isPlayingAnimation()){
currentActor.incrementAnimationTime(Globals.timekeeper.getSimFrameTime() / Main.targetFrameRate);
}
}
//make items play idle animation
for(Entity item : dataCell.getScene().getEntitiesWithTag(EntityTags.ITEM)){
ItemUtils.updateItemActorAnimation(item);
}
//particle state updates
for(Entity particle : dataCell.getScene().getEntitiesWithTag(EntityTags.PARTICLE)){
// ParticleTree tree = ParticleUtils.getParticleTree(particle);
// tree.simulate(Main.deltaFrames);
ParticleUtils.makeParticleBillboardFaceCamera(particle);
}
//update attached entity positions
AttachUtils.serverUpdateAttachedEntityPositions(dataCell);
//update hitbox positions
for(Entity currentHitbox : hitboxManager.getAllHitboxes()){
HitboxUtils.serverUpdatePosition(currentHitbox);
}
//collide hitboxes
for(Entity currentHitbox : hitboxManager.getAllHitboxes()){
if(isReady){
HitboxUtils.serverCollideEntities(currentHitbox);
}
}
//simulate behavior trees
dataCell.getScene().simulateBehaviorTrees((float)Globals.timekeeper.getSimFrameTime());
//sum collidable impulses
for(Entity collidable : dataCell.getScene().getEntitiesWithTag(EntityTags.COLLIDABLE)){
ServerCollidableTree.getServerCollidableTree(collidable).simulate((float)Globals.timekeeper.getSimFrameTime());
}
}
}
public boolean isReady(){
return isReady;
}
public void setReady(boolean ready){
isReady = ready;
}
public void freeze(){
isReady = false;
}
public void unfreeze(){
isReady = true;
}
}