iron out frame timing in attack tree

This commit is contained in:
austin 2022-05-05 01:48:41 -04:00
parent b24041f9a8
commit e35599606b
14 changed files with 156 additions and 63 deletions

View File

@ -265,30 +265,34 @@
"attackMoveId" : "Sword1HSlash1",
"type" : "MELEE_WEAPON_SWING_ONE_HAND",
"attackAnimationName" : "Armature|Sword1HSlash1",
"damageStartFrame" : 30,
"damageEndFrame" : 60,
"windupFrames" : 5,
"attackFrames" : 5,
"cooldownFrames" : 25,
"firesProjectile" : false,
"nextMoveId" : "Sword1HSlash2",
"nextAttackMoveWindowStart" : 0,
"nextAttackMoveWindowEnd" : 1,
"movementStart" : 2,
"movementEnd" : 10,
"movementGoal" : 0.1,
"moveChainWindowStart" : 12,
"moveChainWindowEnd" : 18,
"driftGoal" : 0.02,
"driftFrameStart" : 7,
"driftFrameEnd" : 15,
"initialMove" : true
},
{
"attackMoveId" : "Sword1HSlash2",
"type" : "MELEE_WEAPON_SWING_ONE_HAND",
"attackAnimationName" : "Armature|Sword1HSlash2",
"damageStartFrame" : 30,
"damageEndFrame" : 60,
"windupFrames" : 2,
"attackFrames" : 5,
"cooldownFrames" : 28,
"firesProjectile" : false,
"nextMoveId" : "Sword1HSlash1",
"nextAttackMoveWindowStart" : 0,
"nextAttackMoveWindowEnd" : 1,
"movementStart" : 2,
"movementEnd" : 10,
"movementGoal" : 0.1,
"nextAttackMoveWindowStart" : 10,
"nextAttackMoveWindowEnd" : 18,
"driftGoal" : 0.03,
"driftFrameStart" : 1,
"driftFrameEnd" : 10,
"initialMove" : false
},
{

View File

@ -121,6 +121,8 @@ public class ControlHandler {
public static final String INPUT_CODE_INVENTORY_CLOSE = "inventoryClose";
public static final String INPUT_CODE_INVENTORY_ITEM_MANIPULATE = "inventoryItemManipulate";
public static final String INPUT_CODE_INVENTORY_ITEM_DRAG = "inventoryDrag";
public static final String DEBUG_FRAMESTEP = "framestep";
public static enum ControlsState {
@ -252,6 +254,11 @@ public class ControlHandler {
handler.addControl(INPUT_CODE_INVENTORY_CLOSE, new Control(ControlType.KEY,GLFW_KEY_I));
handler.addControl(INPUT_CODE_INVENTORY_ITEM_MANIPULATE, new Control(ControlType.MOUSE_BUTTON,GLFW_MOUSE_BUTTON_1));
handler.addControl(INPUT_CODE_INVENTORY_ITEM_DRAG, new Control(ControlType.MOUSE_MOVEMENT,0));
/*
framestep controls
*/
handler.addControl(DEBUG_FRAMESTEP, new Control(ControlType.KEY, GLFW_KEY_P));
/*
set state
@ -790,6 +797,11 @@ public class ControlHandler {
// EntityUtils.getPosition(bow).set(1, 5, 2);
// CollisionObjUtils.positionCharacter(bow, new Vector3f(1, 5, 2));
}});
mainGameDebugControlList.add(controls.get(DEBUG_FRAMESTEP));
controls.get(DEBUG_FRAMESTEP).setOnRelease(new ControlMethod(){public void execute(){
Main.setFramestep(1);
}});
// RenderingEngine.incrementOutputFramebuffer();
}

View File

@ -661,9 +661,9 @@ public class LoadingThread extends Thread {
// OpportunisticAttacker.attachToCreature(goblin);
//sword
// Entity sword = ItemUtils.spawnBasicItem("Katana");
// EntityUtils.getPosition(sword).set(new Vector3f(1,0.4f,2));
// EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0)));
Entity sword = ItemUtils.spawnBasicItem("Katana");
EntityUtils.getPosition(sword).set(new Vector3f(1,0.4f,2));
EntityUtils.getRotation(sword).set(new Quaternionf().rotationY((float)(Math.PI/2.0)));

View File

@ -6,6 +6,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.collidable.Impulse;
import electrosphere.entity.state.equip.EquipState;
import electrosphere.entity.state.rotator.RotatorTree;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxUtils;
@ -15,6 +16,7 @@ import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.data.creature.type.attack.AttackMove;
import electrosphere.game.data.creature.type.equip.EquipPoint;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.anim.Animation;
@ -36,8 +38,15 @@ public class AttackTree {
COOLDOWN,
IDLE,
}
//the state of drifting forward during the attack
public static enum AttackTreeDriftState {
DRIFT,
NO_DRIFT,
}
AttackTreeState state;
AttackTreeDriftState driftState;
Entity parent;
@ -45,10 +54,7 @@ public class AttackTree {
long lastUpdateTime = 0;
int frameCurrent;
int damageStartFrame = 1;
int damageEndFrame = 2;
float frameCurrent;
String animationName = "SwingWeapon";
@ -66,6 +72,7 @@ public class AttackTree {
public AttackTree(Entity e){
state = AttackTreeState.IDLE;
driftState = AttackTreeDriftState.NO_DRIFT;
parent = e;
}
@ -94,8 +101,6 @@ public class AttackTree {
currentMove = getNextMove(currentMoveset,currentMove.getNextMoveId());
}
if(currentMove != null){
damageStartFrame = currentMove.getDamageStartFrame();
damageEndFrame = currentMove.getDamageEndFrame();
firesProjectile = currentMove.getFiresProjectile();
if(firesProjectile){
projectileToFire = ItemUtils.getWeaponDataRaw(currentWeapon).getProjectileModel();
@ -138,6 +143,7 @@ public class AttackTree {
}
public void simulate(){
frameCurrent = frameCurrent + Main.deltaFrames;
float velocity = CreatureUtils.getVelocity(parent);
Actor entityActor = EntityUtils.getActor(parent);
Vector3d position = EntityUtils.getPosition(parent);
@ -159,12 +165,12 @@ public class AttackTree {
// System.out.println("Set state STARTUP");
break;
case 1:
frameCurrent = damageStartFrame+1;
frameCurrent = currentMove.getWindupFrames()+1;
state = AttackTreeState.ATTACK;
// System.out.println("Set state MOVE");
break;
case 2:
frameCurrent = damageEndFrame+1;
frameCurrent = currentMove.getWindupFrames()+currentMove.getAttackFrames()+1;
state = AttackTreeState.COOLDOWN;
// System.out.println("Set state SLOWDOWN");
break;
@ -187,10 +193,36 @@ public class AttackTree {
case SETFACING:
case SETPOSITION:
case SETPROPERTY:
case KILL:
case SPAWNCREATURE:
//silently ignore
break;
}
}
//handle the drifting if we're supposed to currently
switch(driftState){
case DRIFT:
if(currentMove != null){
//calculate the vector of movement
CollisionObjUtils.getCollidable(parent).addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), currentMove.getDriftGoal() * Main.deltaFrames, "movement"));
if(frameCurrent > currentMove.getDriftFrameEnd()){
driftState = AttackTreeDriftState.NO_DRIFT;
}
}
break;
case NO_DRIFT:
if(currentMove != null){
if(frameCurrent > currentMove.getDriftFrameStart() && frameCurrent < currentMove.getDriftFrameEnd()){
driftState = AttackTreeDriftState.DRIFT;
}
}
break;
}
// if(state != AttackTreeState.IDLE){
// System.out.println(frameCurrent);
// }
//state machine
switch(state){
@ -201,11 +233,10 @@ public class AttackTree {
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationName)){
entityActor.playAnimation(animationName,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
frameCurrent++;
if(frameCurrent > damageStartFrame){
if(frameCurrent > currentMove.getWindupFrames()){
if(currentMoveCanHold && stillHold){
state = AttackTreeState.HOLD;
} else {
@ -248,7 +279,7 @@ public class AttackTree {
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationName)){
entityActor.playAnimation(animationName,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
if(!stillHold){
@ -288,7 +319,7 @@ public class AttackTree {
break;
case ATTACK:
if(parent.containsKey(EntityDataStrings.ATTACH_CHILDREN_LIST)){
List<Entity> attachedEntities = (List<Entity>)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST);
List<Entity> attachedEntities = AttachUtils.getChildrenList(parent);
for(Entity currentAttached : attachedEntities){
if(currentAttached.containsKey(EntityDataStrings.HITBOX_ASSOCIATED_LIST)){
List<Entity> hitboxes = HitboxUtils.getHitboxAssociatedList(currentAttached);
@ -331,8 +362,7 @@ public class AttackTree {
ProjectileUtils.spawnBasicProjectile(projectileToFire, spawnPosition, arrowRotation, 750, initialVector, 0.03f);
projectileToFire = null;
}
frameCurrent++;
if(frameCurrent > damageEndFrame){
if(frameCurrent > currentMove.getWindupFrames() + currentMove.getAttackFrames()){
state = AttackTreeState.COOLDOWN;
}
if(Globals.RUN_SERVER){
@ -369,7 +399,7 @@ public class AttackTree {
break;
case COOLDOWN:
if(parent.containsKey(EntityDataStrings.ATTACH_CHILDREN_LIST)){
List<Entity> attachedEntities = (List<Entity>)parent.getData(EntityDataStrings.ATTACH_CHILDREN_LIST);
List<Entity> attachedEntities = AttachUtils.getChildrenList(parent);
for(Entity currentAttached : attachedEntities){
if(currentAttached.containsKey(EntityDataStrings.HITBOX_ASSOCIATED_LIST)){
List<Entity> hitboxes = HitboxUtils.getHitboxAssociatedList(currentAttached);
@ -379,8 +409,7 @@ public class AttackTree {
}
}
}
frameCurrent++;
if(frameCurrent > 60){
if(frameCurrent > currentMove.getWindupFrames() + currentMove.getAttackFrames() + currentMove.getCooldownFrames()){
state = AttackTreeState.IDLE;
frameCurrent = 0;
if(parent.containsKey(EntityDataStrings.ROTATOR_TREE)){
@ -458,7 +487,12 @@ public class AttackTree {
if(attackType == null){
return false;
} else if(state != AttackTreeState.IDLE){
if(currentMove.getNextMoveId() != null && !currentMove.getNextMoveId().equals("")){
//checks if we have a next move and if we're in the specified range of frames when we're allowed to chain into it
if(
currentMove.getNextMoveId() != null &&
!currentMove.getNextMoveId().equals("") &&
frameCurrent >= currentMove.getMoveChainWindowStart() && frameCurrent <= currentMove.getMoveChainWindowEnd()
){
rVal = true;
}
} else {

View File

@ -108,7 +108,7 @@ public class IdleTree {
if(entityActor != null){
if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(Animation.ANIMATION_IDLE_1)){
entityActor.playAnimation(Animation.ANIMATION_IDLE_1,3);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
isIdle = true;

View File

@ -183,7 +183,7 @@ public class LifeState implements BehaviorTree {
!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
break;

View File

@ -38,7 +38,7 @@ public class FallTree implements BehaviorTree {
(jumpTree == null || !jumpTree.isJumping())
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
break;
@ -65,7 +65,7 @@ public class FallTree implements BehaviorTree {
!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
}

View File

@ -228,7 +228,7 @@ public class GroundMovementTree {
(fallTree == null || !fallTree.isFalling())
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
//run startup code
@ -313,7 +313,7 @@ public class GroundMovementTree {
(fallTree == null || !fallTree.isFalling())
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
if(velocity != maxNaturalVelocity){
@ -392,7 +392,7 @@ public class GroundMovementTree {
(fallTree == null || !fallTree.isFalling())
){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
//velocity stuff

View File

@ -57,7 +57,7 @@ public class JumpTree implements BehaviorTree {
String animationToPlay = determineCorrectAnimation();
if(!entityActor.isPlayingAnimation() || !entityActor.isPlayingAnimation(animationToPlay)){
entityActor.playAnimation(animationToPlay,1);
entityActor.incrementAnimationTime(0.01);
entityActor.incrementAnimationTime(0.0001);
}
}
currentFrame++;

View File

@ -24,19 +24,27 @@ public class AttackMove {
/*
Damage stuff
*/
int damageStartFrame;
int damageEndFrame;
int windupFrames;
int attackFrames;
int cooldownFrames;
boolean firesProjectile;
/*
move chaining stuff
*/
String nextMoveId;
String movementStart;
String movementEnd;
float movementGoal; // this is the amount we want the animation to push us forward
int moveChainWindowStart; //when do we open the posibility for a chained move
int moveChainWindowEnd; // when do we close the opportunity to chain into the next move
boolean initialMove; // is this the initial move in its movelist?
/*
move drift
this is the term to use when describing forward momentum generated by the attack move
*/
float driftGoal; // this is the amount we want the animation to push us forward
int driftFrameStart; //when do we start drifting
int driftFrameEnd; //when do we stop drifting
public String getAttackMoveId(){
return attackMoveId;
}
@ -57,20 +65,40 @@ public class AttackMove {
return attackAnimationName;
}
public int getDamageStartFrame() {
return damageStartFrame;
public int getWindupFrames() {
return windupFrames;
}
public int getDamageEndFrame() {
return damageEndFrame;
public int getAttackFrames() {
return attackFrames;
}
public int getCooldownFrames(){
return cooldownFrames;
}
public String getNextMoveId() {
return nextMoveId;
}
public float getMovementGoal(){
return movementGoal;
public int getMoveChainWindowStart(){
return moveChainWindowStart;
}
public int getMoveChainWindowEnd(){
return moveChainWindowEnd;
}
public float getDriftGoal(){
return driftGoal;
}
public int getDriftFrameStart(){
return driftFrameStart;
}
public int getDriftFrameEnd(){
return driftFrameEnd;
}
public boolean isInitialMove(){

View File

@ -77,6 +77,9 @@ public class Main {
//target amount of time per frame
public static float targetFrameRate = 60.0f;
static float targetFramePeriod = 1.0f/targetFrameRate;
//framestep variable
static int framestep = 2;
public static void main(String args[]){
@ -242,6 +245,11 @@ public class Main {
Globals.clientConnection.parseMessages();
}
//handle framestep
if(framestep == 1){
framestep = 0;
}
///
@ -258,20 +266,20 @@ public class Main {
///
/// C L I E N T S I M U L A T I O N S T U F F
///
if(Globals.RUN_CLIENT){
if(Globals.RUN_CLIENT && framestep > 0){
ClientFunctions.runBeforeSimulationFunctions();
}
if(Globals.microSimulation != null && Globals.microSimulation.isReady()){
if(Globals.microSimulation != null && Globals.microSimulation.isReady() && framestep > 0){
Globals.microSimulation.simulate();
}
if(Globals.RUN_CLIENT){
if(Globals.RUN_CLIENT && framestep > 0){
ClientFunctions.runClientFunctions();
}
///
/// M A C R O S I M U L A T I O N S T U F F
///
if(Globals.macroSimulation != null && Globals.macroSimulation.isReady()){
if(Globals.macroSimulation != null && Globals.macroSimulation.isReady() && framestep > 0){
Globals.macroSimulation.simulate();
}
@ -340,6 +348,14 @@ public class Main {
// Globals.controlHandler = FileLoadingUtils.loadModelObjectFromBakedJsonFile("/Config/keybinds.json",ControlHandler.class);
}
/**
* Sets the framestep state (2 to resume automatic, 1 to make single step)
* @param framestep 2 - automatic framestep, 1 - single step, 0 - no step
*/
public static void setFramestep(int framestep){
Main.framestep = framestep;
}

View File

@ -105,8 +105,10 @@ public class WindowUtils {
public static void focusWindow(String window){
Element windowEl = Globals.elementManager.getWindow(window);
Globals.elementManager.unregisterWindow(window);
Globals.elementManager.registerWindow(window, windowEl);
if(windowEl != null){
Globals.elementManager.unregisterWindow(window);
Globals.elementManager.registerWindow(window, windowEl);
}
}
}

View File

@ -635,7 +635,6 @@ public class RenderingEngine {
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
currentActor.incrementAnimationTime(0.001);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
@ -675,7 +674,6 @@ public class RenderingEngine {
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
currentActor.incrementAnimationTime(0.001);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform
@ -899,7 +897,6 @@ public class RenderingEngine {
){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
currentActor.incrementAnimationTime(0.001);
//calculate camera-modified vector3f
Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera));
//calculate and apply model transform

View File

@ -89,7 +89,7 @@ public class ActorPanel implements DrawableElement, DraggableElement {
if(currentAnim != null){
if(!actor.isPlayingAnimation() || !actor.isPlayingAnimation(currentAnim)){
actor.playAnimation(currentAnim,3);
actor.incrementAnimationTime(Main.deltaFrames);
actor.incrementAnimationTime(0.0001);
}
}