move tree and idle to use unified animation object

This commit is contained in:
austin 2024-07-28 17:31:06 -04:00
parent cc2ff6a93a
commit e6fc720299
9 changed files with 52 additions and 51 deletions

View File

@ -429,8 +429,11 @@
"onDamageIFrames" : 30
},
"idleData": {
"idleAnimation" : "Idle1",
"firstPersonIdleAnimation" : "Idle"
"animation": {
"nameFirstPerson" : "Idle",
"nameThirdPerson" : "Idle1",
"priorityCategory" : "IDLE"
}
},
"modelPath" : "Models/creatures/person2/person2_1.glb",
"viewModelData" : {

View File

@ -166,7 +166,7 @@ public class StateTransitionUtil {
state.startedAnimation = false;
} else if(state.animation != null && (!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animation))){
//play animation for state
poseActor.playAnimation(animation, true);
poseActor.playAnimation(animation);
poseActor.incrementAnimationTime(0.0001);
state.startedAnimation = true;
} else if(state.animation == null && state.onComplete != null){

View File

@ -267,7 +267,7 @@ public class ServerAttackTree implements BehaviorTree {
case ATTACK: {
if(entityPoseActor != null && currentMove != null){
if(!entityPoseActor.isPlayingAnimation() || !entityPoseActor.isPlayingAnimation(currentMove.getAnimationAttack())){
entityPoseActor.playAnimation(currentMove.getAnimationAttack(),true);
entityPoseActor.playAnimation(currentMove.getAnimationAttack());
entityPoseActor.incrementAnimationTime(0.0001);
}
}

View File

@ -2,7 +2,6 @@ package electrosphere.entity.state.idle;
import electrosphere.net.synchronization.BehaviorTreeIdEnums;
import electrosphere.entity.state.AnimationPriorities;
import electrosphere.entity.state.attack.ClientAttackTree;
import electrosphere.entity.state.client.firstPerson.FirstPersonTree;
import electrosphere.entity.state.movement.AirplaneMovementTree;
@ -94,14 +93,17 @@ public class ClientIdleTree implements BehaviorTree {
if(entityActor != null){
if(
idleData != null &&
(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(idleData.getIdleAnimation())) &&
(Globals.assetManager.fetchModel(entityActor.getModelPath()) != null && Globals.assetManager.fetchModel(entityActor.getModelPath()).getAnimation(idleData.getIdleAnimation()) != null)
(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(idleData.getAnimation())) &&
(
Globals.assetManager.fetchModel(entityActor.getModelPath()) != null &&
Globals.assetManager.fetchModel(entityActor.getModelPath()).getAnimation(idleData.getAnimation().getNameThirdPerson()) != null
)
){
entityActor.playAnimation(idleData.getIdleAnimation(),AnimationPriorities.getValue(AnimationPriorities.IDLE));
entityActor.playAnimation(idleData.getAnimation(),true);
entityActor.incrementAnimationTime(0.0001);
}
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, idleData.getFirstPersonIdleAnimation(), AnimationPriorities.getValue(AnimationPriorities.IDLE));
FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, idleData.getAnimation());
}
break;
case NOT_IDLE:

View File

@ -2,7 +2,6 @@ package electrosphere.entity.state.idle;
import electrosphere.net.synchronization.FieldIdEnums;
import electrosphere.entity.state.AnimationPriorities;
import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState;
import electrosphere.entity.state.attack.ServerAttackTree;
import electrosphere.entity.state.idle.ClientIdleTree.IdleTreeState;
@ -15,12 +14,12 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.data.creature.type.IdleData;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.net.parser.net.message.SynchronizationMessage;
import electrosphere.net.synchronization.BehaviorTreeIdEnums;
import electrosphere.net.synchronization.annotation.SyncedField;
import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree;
import electrosphere.renderer.anim.Animation;
import electrosphere.server.datacell.utils.DataCellSearchUtils;
import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
import electrosphere.server.poseactor.PoseActor;
@ -39,15 +38,19 @@ public class ServerIdleTree implements BehaviorTree {
Entity parent;
//The idle data
IdleData idleData;
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>();
/**
* Creates a server idle tree
* @param e The entity to attach it to
*/
public ServerIdleTree(Entity e){
public ServerIdleTree(Entity e, IdleData idleData){
state = IdleTreeState.IDLE;
parent = e;
this.idleData = idleData;
}
/**
@ -60,19 +63,30 @@ public class ServerIdleTree implements BehaviorTree {
return state;
}
/**
* Starts idling
*/
public void start(){
//TODO: check if can start moving
state = IdleTreeState.IDLE;
setState(IdleTreeState.IDLE);
}
/**
* Interrupts the idle animation
*/
public void interrupt(){
state = IdleTreeState.NOT_IDLE;
setState(IdleTreeState.NOT_IDLE);
}
/**
* Stops the idle animation
*/
public void stop(){
state = IdleTreeState.NOT_IDLE;
setState(IdleTreeState.NOT_IDLE);
}
/**
* Simulates the idle tree
*/
public void simulate(float deltaTime){
PoseActor poseActor = EntityUtils.getPoseActor(parent);
@ -91,9 +105,9 @@ public class ServerIdleTree implements BehaviorTree {
case IDLE:
if(poseActor != null){
if(
(!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(Animation.ANIMATION_IDLE_1))
(!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(idleData.getAnimation()))
){
poseActor.playAnimation(Animation.ANIMATION_IDLE_1,AnimationPriorities.getValue(AnimationPriorities.IDLE));
poseActor.playAnimation(idleData.getAnimation());
poseActor.incrementAnimationTime(0.0001);
}
}
@ -156,8 +170,8 @@ public class ServerIdleTree implements BehaviorTree {
* @param entity The entity to attach to
* @param tree The behavior tree to attach
*/
public static ServerIdleTree attachTree(Entity parent){
ServerIdleTree rVal = new ServerIdleTree(parent);
public static ServerIdleTree attachTree(Entity parent, IdleData idleData){
ServerIdleTree rVal = new ServerIdleTree(parent, idleData);
//put manual code here (setting params, etc)

View File

@ -673,7 +673,9 @@ public class CreatureUtils {
ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.LIFE_STATE);
}
//idle tree & generic stuff all creatures have
ServerIdleTree.attachTree(rVal);
if(rawType.getIdleData() != null){
ServerIdleTree.attachTree(rVal, rawType.getIdleData());
}
CreatureUtils.setFacingVector(rVal, MathUtils.getOriginVector());
rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);

View File

@ -18,7 +18,6 @@ import electrosphere.entity.state.gravity.ClientGravityTree;
import electrosphere.entity.state.gravity.ServerGravityTree;
import electrosphere.entity.state.hitbox.HitboxCollectionState;
import electrosphere.entity.state.idle.ClientIdleTree;
import electrosphere.entity.state.idle.ServerIdleTree;
import electrosphere.entity.state.inventory.ClientInventoryState;
import electrosphere.entity.state.inventory.InventoryUtils;
import electrosphere.entity.state.inventory.ServerInventoryState;
@ -198,8 +197,6 @@ public class ObjectUtils {
if(rawType.getHitboxData() != null){
HitboxCollectionState.attachHitboxState(realm.getHitboxManager(), true, rVal, rawType.getHitboxData());
}
//idle tree & generic stuff all objects have
ServerIdleTree.attachTree(rVal);
//required for synchronization manager

View File

@ -1,30 +1,21 @@
package electrosphere.game.data.creature.type;
import electrosphere.game.data.common.TreeDataAnimation;
/**
* Data about how the creature will behave when in idle state
*/
public class IdleData {
//the animation that plays when the creature is idle
String idleAnimation;
//the animation that plays when the creature idles in first person
String firstPersonIdleAnimation;
TreeDataAnimation animation;
/**
* the animation that plays when the creature is idle
* @return
* The animation that plays when the creature is idle
* @return The animation
*/
public String getIdleAnimation(){
return idleAnimation;
}
/**
* the animation that plays when the creature idles in first person
* @return
*/
public String getFirstPersonIdleAnimation(){
return firstPersonIdleAnimation;
public TreeDataAnimation getAnimation(){
return animation;
}
}

View File

@ -169,15 +169,10 @@ public class PoseActor {
* @param animation The animation data
* @param isThirdPerson true if is third person, false if is first person
*/
public void playAnimation(TreeDataAnimation animation, boolean isThirdPerson){
public void playAnimation(TreeDataAnimation animation){
//Get the animation's name
String animationName = "";
if(isThirdPerson){
animationName = animation.getNameThirdPerson();
} else {
animationName = animation.getNameFirstPerson();
}
String animationName = animation.getNameThirdPerson();
//Get the animation's priority
int priority = AnimationPriorities.getValue(AnimationPriorities.DEFAULT);
@ -202,12 +197,9 @@ public class PoseActor {
}
}
if(group != null && isThirdPerson == true){
if(group != null){
boneMask.addAll(group.getBoneNamesThirdPerson());
}
if(group != null && isThirdPerson == false){
boneMask.addAll(group.getBoneNamesFirstPerson());
}
}
} else if(this.boneGroups == null){
LoggerInterface.loggerRenderer.WARNING("Trying to play animation on pose actor that uses bone groups, but the actor's bone group isn't defined!");