Renderer/src/main/java/electrosphere/server/simulation/MicroSimulation.java
2023-07-14 22:10:38 -04:00

118 lines
4.5 KiB
Java

package electrosphere.server.simulation;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.client.targeting.crosshair.Crosshair;
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.scene.EntityDescriptor;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.state.ParticleTree;
import electrosphere.entity.state.attack.AttackTree;
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.hitbox.HitboxManager;
import electrosphere.entity.types.hitbox.HitboxUtils;
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.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()){
//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 : dataCell.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 : 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);
}
}
//tally collidables and offset position accordingly
// for(Entity currentCollidable : Globals.entityManager.getEntitiesWithTag(EntityTags.COLLIDABLE)){
// CollidableTree tree = CollidableTree.getCollidableTree(currentCollidable);
// tree.simulate(Main.deltaFrames);
// }
//simulate behavior trees
dataCell.getScene().simulateBehaviorTrees(Main.deltaFrames);
//sum collidable impulses
for(Entity collidable : dataCell.getScene().getEntitiesWithTag(EntityTags.COLLIDABLE)){
ServerCollidableTree.getServerCollidableTree(collidable).simulate(Main.deltaFrames);
}
}
}
public boolean isReady(){
return isReady;
}
public void setReady(boolean ready){
isReady = ready;
}
public void freeze(){
isReady = false;
}
public void unfreeze(){
isReady = true;
}
}