From ebcf0865ee61b708ea0a8ebffcfac7aeb4da6876 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 3 Sep 2024 22:36:30 -0400 Subject: [PATCH] server sync sprint tree --- assets/Data/creatures/human.json | 2 +- docs/src/progress/renderertodo.md | 7 + .../controls/ControlHandler.java | 6 +- .../entity/EntityDataStrings.java | 4 +- .../groundmove/ClientGroundMovementTree.java | 3 + .../groundmove/ServerGroundMovementTree.java | 3 + .../movement/sprint/ClientSprintTree.java | 231 ++++++++++++++---- .../movement/sprint/ServerSprintTree.java | 163 ++++++++++-- .../entity/types/creature/CreatureUtils.java | 17 +- .../game/data/creature/type/SprintSystem.java | 46 +++- .../client/ClientSynchronizationManager.java | 9 + .../enums/BehaviorTreeIdEnums.java | 2 + .../synchronization/enums/FieldIdEnums.java | 2 + .../server/ServerSynchronizationManager.java | 12 + .../transport/StateCollection.java | 14 ++ 15 files changed, 424 insertions(+), 97 deletions(-) diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index 5ef32376..633730d7 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -151,7 +151,7 @@ "priorityCategory" : "CORE_MOVEMENT" }, "sprintSystem" : { - "maxVelocity" : 0.058, + "modifier" : 1.4, "staminaMax" : 500, "animationStartUp" : { "nameThirdPerson" : "Sprint", diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 150c70a2..ba9d3981 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -671,6 +671,13 @@ Fix level editor entity tree not re-rendering when an entity is deleted Fix server entity not rotation when first person camera rotates Entity details debug menu Data View +(09/03/2024) +Documentation reorganization +Better jenkins documentation +Include jenkins dockerfile in repo +Better model for gameobjects +Server synchronization of sprint tree + # TODO diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index 1cac9962..50bd28b1 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -824,7 +824,7 @@ public class ControlHandler { mainGameControlList.add(controls.get(INPUT_CODE_SPRINT)); controls.get(INPUT_CODE_SPRINT).setOnPress(new ControlMethod(){public void execute(){ if(Globals.playerEntity != null){ - ClientSprintTree sprintTree = CreatureUtils.clientGetSprintTree(Globals.playerEntity); + ClientSprintTree sprintTree = ClientSprintTree.getClientSprintTree(Globals.playerEntity); if(sprintTree != null){ sprintTree.start(); } @@ -832,9 +832,9 @@ public class ControlHandler { }}); controls.get(INPUT_CODE_SPRINT).setOnRelease(new ControlMethod(){public void execute(){ if(Globals.playerEntity != null){ - ClientSprintTree sprintTree = CreatureUtils.clientGetSprintTree(Globals.playerEntity); + ClientSprintTree sprintTree = ClientSprintTree.getClientSprintTree(Globals.playerEntity); if(sprintTree != null){ - sprintTree.stop(); + sprintTree.interrupt(); } } }}); diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 7c9df61a..8b4e9944 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -56,8 +56,8 @@ public class EntityDataStrings { public static final String SERVER_MOVEMENT_BT = "serverMovementBT"; public static final String TREE_CLIENTGROUNDMOVEMENTTREE = "treeClientGroundMovementTree"; public static final String TREE_SERVERGROUNDMOVEMENTTREE = "treeServerGroundMovementTree"; - public static final String CLIENT_SPRINT_TREE = "clientSprintBT"; - public static final String SERVER_SPRINT_TREE = "serverSprintBT"; + public static final String TREE_CLIENTSPRINTTREE = "treeClientSprintTree"; + public static final String TREE_SERVERSPRINTTREE = "treeServerSprintTree"; public static final String DATA_STRING_FACING_VECTOR = "facingVector"; public static final String DATA_STRING_VELOCITY = "velocity"; public static final String DATA_STRING_ACCELERATION = "acceleration"; diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java index 9a864d95..5940b7c0 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java @@ -503,6 +503,9 @@ public class ClientGroundMovementTree implements BehaviorTree { if(ClientWalkTree.getClientWalkTree(parent) != null && ClientWalkTree.getClientWalkTree(parent).isWalking()){ walkModifier = ClientWalkTree.getClientWalkTree(parent).getModifier(); } + if(ClientSprintTree.getClientSprintTree(parent) != null && ClientSprintTree.getClientSprintTree(parent).isSprinting()){ + sprintModifier = ClientSprintTree.getClientSprintTree(parent).getSprintSystem().getModifier(); + } return velocity * sprintModifier * walkModifier; } diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index cceaeed3..a2bbf4b2 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -454,6 +454,9 @@ public class ServerGroundMovementTree implements BehaviorTree { if(ServerWalkTree.getServerWalkTree(parent) != null && ServerWalkTree.getServerWalkTree(parent).isWalking()){ walkModifier = ServerWalkTree.getServerWalkTree(parent).getModifier(); } + if(ServerSprintTree.getServerSprintTree(parent) != null && ServerSprintTree.getServerSprintTree(parent).isSprinting()){ + sprintModifier = ServerSprintTree.getServerSprintTree(parent).getSprintSystem().getModifier(); + } return velocity * sprintModifier * walkModifier; } diff --git a/src/main/java/electrosphere/entity/state/movement/sprint/ClientSprintTree.java b/src/main/java/electrosphere/entity/state/movement/sprint/ClientSprintTree.java index fe2ec4a2..2528489d 100644 --- a/src/main/java/electrosphere/entity/state/movement/sprint/ClientSprintTree.java +++ b/src/main/java/electrosphere/entity/state/movement/sprint/ClientSprintTree.java @@ -1,82 +1,217 @@ package electrosphere.entity.state.movement.sprint; + +import electrosphere.engine.Globals; +import electrosphere.entity.EntityDataStrings; +import electrosphere.net.synchronization.server.ServerSynchronizationManager; +import electrosphere.net.parser.net.message.SynchronizationMessage; +import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums; import electrosphere.entity.Entity; import electrosphere.entity.btree.BehaviorTree; -import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; -import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; +import electrosphere.game.data.creature.type.SprintSystem; +import electrosphere.net.synchronization.annotation.SyncedField; +import electrosphere.net.synchronization.annotation.SynchronizableEnum; +import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; /** * Client sprint tree */ +@SynchronizedBehaviorTree( + name = "clientSprintTree", + isServer = false, + correspondingTree = "serverSprintTree", + genStartInt = true +) public class ClientSprintTree implements BehaviorTree { + @SynchronizableEnum public static enum SprintTreeState { SPRINTING, NOT_SPRINTING, } - SprintTreeState state; - - ClientGroundMovementTree groundMovementTree; + + @SyncedField + SprintTreeState state = SprintTreeState.NOT_SPRINTING; + + /** + * The data for the sprint system + */ + SprintSystem sprintData; + /** + * The parent entity + */ Entity parent; - int staminaCurrent = 0; - int staminaMax = 1; - - float maxVelocity; - - public ClientSprintTree(Entity e, float maxVelocity, int staminaMax){ - state = SprintTreeState.NOT_SPRINTING; - parent = e; - this.maxVelocity = maxVelocity; - this.staminaMax = staminaMax; - } - + /** + * Gets the state of the tree + * @return The state + */ public SprintTreeState getState(){ return state; } + /** + *

Automatically generated

+ *

+ * Requests that the server start this btree + *

+ */ public void start(){ - if(staminaCurrent > 0){ - // System.out.println("Starting sprinting"); - state = SprintTreeState.SPRINTING; - } - } - - public void stop(){ - state = SprintTreeState.NOT_SPRINTING; + Globals.clientConnection.queueOutgoingMessage( + SynchronizationMessage.constructClientRequestBTreeActionMessage( + Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), + BehaviorTreeIdEnums.BTREE_CLIENTSPRINTTREE_ID, + ServerSynchronizationManager.SERVER_SYNC_START + ) + ); } @Override public void simulate(float deltaTime){ - switch(state){ - case SPRINTING: - if(groundMovementTree != null && groundMovementTree.getState() != MovementTreeState.IDLE){ - staminaCurrent--; - if(staminaCurrent < 1){ - state = SprintTreeState.NOT_SPRINTING; - } - } - break; - case NOT_SPRINTING: - staminaCurrent++; - if(staminaCurrent > staminaMax){ - staminaCurrent = staminaMax; - } - break; + } + + /** + * Gets the sprint system + * @return The sprint system + */ + public SprintSystem getSprintSystem(){ + return sprintData; + } + + /** + * Checks if the entity is sprinting + * @return true if it is sprinting, false otherwise + */ + public boolean isSprinting(){ + return this.state == SprintTreeState.SPRINTING; + } + + + /** + *

(initially) Automatically generated

+ *

Private constructor to enforce using the attach methods

+ *

+ * Constructor + *

+ * @param parent The parent entity of this tree + * @param params Optional parameters that can be provided when attaching the tree. All custom data required for creating this tree should be passed in this varargs. + */ + private ClientSprintTree(Entity parent, Object ... params){ + if(params.length < 1 || (params[0] instanceof SprintSystem) == false){ + throw new IllegalArgumentException("Trying to create client walk tree with invalid arguments!"); + } + this.parent = parent; + this.sprintData = (SprintSystem)params[0]; + } + + + /** + *

(initially) Automatically generated

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ClientSprintTree attachTree(Entity parent, Object ... params){ + ClientSprintTree rVal = new ClientSprintTree(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + parent.putData(EntityDataStrings.TREE_CLIENTSPRINTTREE, rVal); + Globals.clientSceneWrapper.getScene().registerBehaviorTree(rVal); + Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_CLIENTSPRINTTREE_ID); + return rVal; + } + + /** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + Globals.entityValueTrackingService.detatchTreeFromEntity(entity, BehaviorTreeIdEnums.BTREE_CLIENTSPRINTTREE_ID); + } + + /** + *

+ * Gets the ClientSprintTree of the entity + *

+ * @param entity the entity + * @return The ClientSprintTree + */ + public static ClientSprintTree getClientSprintTree(Entity entity){ + return (ClientSprintTree)entity.getData(EntityDataStrings.TREE_CLIENTSPRINTTREE); + } + + /** + *

Automatically generated

+ *

+ * Requests that the server start this btree + *

+ */ + public void interrupt(){ + Globals.clientConnection.queueOutgoingMessage( + SynchronizationMessage.constructClientRequestBTreeActionMessage( + Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), + BehaviorTreeIdEnums.BTREE_CLIENTSPRINTTREE_ID, + ServerSynchronizationManager.SERVER_SYNC_INTERRUPT + ) + ); + } + + /** + *

Automatically generated

+ *

+ * Converts a short to the equivalent enum value + *

+ * @param shortVal The short value + * @return The enum value + */ + public static SprintTreeState getSprintTreeStateShortAsEnum(short shortVal){ + switch(shortVal){ + case 0: + return SprintTreeState.SPRINTING; + case 1: + return SprintTreeState.NOT_SPRINTING; + default: + return SprintTreeState.SPRINTING; } } - - public void setGroundMovementTree(ClientGroundMovementTree groundMovementTree){ - this.groundMovementTree = groundMovementTree; + + /** + *

Automatically generated

+ *

+ * Converts this enum type to an equivalent short value + *

+ * @param enumVal The enum value + * @return The short value + */ + public static short getSprintTreeStateEnumAsShort(SprintTreeState enumVal){ + switch(enumVal){ + case SPRINTING: + return 0; + case NOT_SPRINTING: + return 1; + default: + return 0; + } } - //get max velocity - public float getMaxVelocity() { - return maxVelocity; + /** + *

Automatically generated

+ *

+ * Sets state and handles the synchronization logic for it. + *

+ * @param state The value to set state to. + */ + public void setState(SprintTreeState state){ + this.state = state; } - - } diff --git a/src/main/java/electrosphere/entity/state/movement/sprint/ServerSprintTree.java b/src/main/java/electrosphere/entity/state/movement/sprint/ServerSprintTree.java index b69c6894..b0c21443 100644 --- a/src/main/java/electrosphere/entity/state/movement/sprint/ServerSprintTree.java +++ b/src/main/java/electrosphere/entity/state/movement/sprint/ServerSprintTree.java @@ -1,51 +1,78 @@ package electrosphere.entity.state.movement.sprint; + +import electrosphere.net.synchronization.enums.FieldIdEnums; +import electrosphere.server.datacell.utils.DataCellSearchUtils; +import electrosphere.net.parser.net.message.SynchronizationMessage; +import electrosphere.engine.Globals; +import electrosphere.entity.EntityDataStrings; +import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums; +import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; import electrosphere.entity.Entity; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; +import electrosphere.entity.state.movement.sprint.ClientSprintTree.SprintTreeState; +import electrosphere.game.data.creature.type.SprintSystem; +import electrosphere.net.synchronization.annotation.SyncedField; +import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; /** * Server sprint tree */ +@SynchronizedBehaviorTree( + name = "serverSprintTree", + isServer = true, + correspondingTree = "clientSprintTree" +) public class ServerSprintTree implements BehaviorTree { - public static enum SprintTreeState { - SPRINTING, - NOT_SPRINTING, - } - - SprintTreeState state; + @SyncedField + SprintTreeState state = SprintTreeState.NOT_SPRINTING; + /** + * The data for the sprint system + */ + SprintSystem sprintData; + + /** + * Gets the ground movement tree associated with this sprint tree + */ ServerGroundMovementTree groundMovementTree; + /** + * Gets the parent entity + */ Entity parent; + /** + * The current stamina for the tree + */ int staminaCurrent = 0; - int staminaMax = 1; - - float maxVelocity; - - public ServerSprintTree(Entity e, float maxVelocity, int staminaMax){ - state = SprintTreeState.NOT_SPRINTING; - parent = e; - this.maxVelocity = maxVelocity; - this.staminaMax = staminaMax; - } + /** + * Gets the state of the tree + * @return The state of the tree + */ public SprintTreeState getState(){ return state; } + /** + * Starts the sprint component + */ public void start(){ if(staminaCurrent > 0){ // System.out.println("Starting sprinting"); - state = SprintTreeState.SPRINTING; + this.setState(SprintTreeState.SPRINTING); } } - public void stop(){ - state = SprintTreeState.NOT_SPRINTING; + /** + * Interrupts the sprint component + */ + public void interrupt(){ + this.setState(SprintTreeState.NOT_SPRINTING); } @Override @@ -61,22 +88,108 @@ public class ServerSprintTree implements BehaviorTree { break; case NOT_SPRINTING: staminaCurrent++; - if(staminaCurrent > staminaMax){ - staminaCurrent = staminaMax; + if(staminaCurrent > sprintData.getStaminaMax()){ + staminaCurrent = sprintData.getStaminaMax(); } break; } } + + /** + * Gets the sprint system + * @return The sprint system + */ + public SprintSystem getSprintSystem(){ + return sprintData; + } + /** + * Sets the ground movement tree associated with this sprint tree + * @param groundMovementTree The ground movement tree + */ public void setServerGroundMovementTree(ServerGroundMovementTree groundMovementTree){ this.groundMovementTree = groundMovementTree; } - //get max velocity - public float getMaxVelocity() { - return maxVelocity; + /** + * Checks if the entity is sprinting + * @return true if it is sprinting, false otherwise + */ + public boolean isSprinting(){ + return this.state == SprintTreeState.SPRINTING; + } + + /** + *

(initially) Automatically generated

+ *

Private constructor to enforce using the attach methods

+ *

+ * Constructor + *

+ * @param parent The parent entity of this tree + * @param params Optional parameters that can be provided when attaching the tree. All custom data required for creating this tree should be passed in this varargs. + */ + private ServerSprintTree(Entity parent, Object ... params){ + if(params.length < 1 || (params[0] instanceof SprintSystem) == false){ + throw new IllegalArgumentException("Trying to create client walk tree with invalid arguments!"); + } + this.parent = parent; + this.sprintData = (SprintSystem)params[0]; } - + /** + *

(initially) Automatically generated

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ServerSprintTree attachTree(Entity parent, Object ... params){ + ServerSprintTree rVal = new ServerSprintTree(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + ServerBehaviorTreeUtils.attachBTreeToEntity(parent, rVal); + parent.putData(EntityDataStrings.TREE_SERVERSPRINTTREE, rVal); + Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID); + return rVal; + } + + /** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + Globals.entityValueTrackingService.detatchTreeFromEntity(entity, BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID); + } + + /** + *

+ * Gets the ServerSprintTree of the entity + *

+ * @param entity the entity + * @return The ServerSprintTree + */ + public static ServerSprintTree getServerSprintTree(Entity entity){ + return (ServerSprintTree)entity.getData(EntityDataStrings.TREE_SERVERSPRINTTREE); + } + + /** + *

Automatically generated

+ *

+ * Sets state and handles the synchronization logic for it. + *

+ * @param state The value to set state to. + */ + public void setState(SprintTreeState state){ + this.state = state; + int value = ClientSprintTree.getSprintTreeStateEnumAsShort(state); + DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID, FieldIdEnums.TREE_SERVERSPRINTTREE_SYNCEDFIELD_STATE_ID, value)); + } + } diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 470eab63..a27308a9 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -148,7 +148,7 @@ public class CreatureUtils { //sprint system if(groundMovementSystem.getSprintSystem() != null){ SprintSystem sprintSystem = groundMovementSystem.getSprintSystem(); - ClientSprintTree sprintTree = new ClientSprintTree(rVal,sprintSystem.getMaxVelocity(),sprintSystem.getStaminaMax()); + ClientSprintTree sprintTree = ClientSprintTree.attachTree(rVal, sprintSystem); if(sprintSystem.getAnimationStartUp()!= null){ moveTree.setAnimationSprintStartUp(sprintSystem.getAnimationStartUp().getNameThirdPerson()); } @@ -158,10 +158,7 @@ public class CreatureUtils { if(sprintSystem.getAnimationWindDown()!= null){ moveTree.setAnimationSprintWindDown(sprintSystem.getAnimationWindDown().getNameThirdPerson()); } - sprintTree.setGroundMovementTree(moveTree); moveTree.setSprintTree(sprintTree); - rVal.putData(EntityDataStrings.CLIENT_SPRINT_TREE,sprintTree); - Globals.clientScene.registerBehaviorTree(sprintTree); Globals.clientScene.registerEntityToTag(rVal, EntityTags.SPRINTABLE); } //round out end of move system @@ -420,7 +417,7 @@ public class CreatureUtils { //sprint system if(groundMovementSystem.getSprintSystem() != null){ SprintSystem sprintSystem = groundMovementSystem.getSprintSystem(); - ServerSprintTree sprintTree = new ServerSprintTree(rVal,sprintSystem.getMaxVelocity(),sprintSystem.getStaminaMax()); + ServerSprintTree sprintTree = ServerSprintTree.attachTree(rVal, sprintSystem); if(sprintSystem.getAnimationStartUp()!= null){ moveTree.setAnimationSprintStartUp(sprintSystem.getAnimationStartUp().getNameThirdPerson()); } @@ -432,8 +429,6 @@ public class CreatureUtils { } sprintTree.setServerGroundMovementTree(moveTree); moveTree.setServerSprintTree(sprintTree); - rVal.putData(EntityDataStrings.SERVER_SPRINT_TREE,sprintTree); - ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, sprintTree); ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.SPRINTABLE); } //round out end of move system @@ -843,14 +838,6 @@ public class CreatureUtils { public static ClientIdleTree getIdleTree(Entity e){ return (ClientIdleTree)e.getData(EntityDataStrings.TREE_IDLE); } - - public static ClientSprintTree clientGetSprintTree(Entity e){ - return (ClientSprintTree)e.getData(EntityDataStrings.CLIENT_SPRINT_TREE); - } - - public static ServerSprintTree serverGetSprintTree(Entity e){ - return (ServerSprintTree)e.getData(EntityDataStrings.SERVER_SPRINT_TREE); - } public static void setCreatureTemplate(Entity e, CreatureTemplate template){ e.putData(EntityDataStrings.CREATURE_TEMPLATE, template); diff --git a/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java b/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java index b4b1fe43..527d3859 100644 --- a/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java +++ b/src/main/java/electrosphere/game/data/creature/type/SprintSystem.java @@ -6,28 +6,68 @@ import electrosphere.game.data.common.TreeDataAnimation; * Sprint data */ public class SprintSystem { + + /** + * The animation to play on starting to sprint + */ TreeDataAnimation animationStartUp; + + /** + * The main animation to play while sprinting + */ TreeDataAnimation animationMain; + + /** + * The animation to play while winding down from sprinting + */ TreeDataAnimation animationWindDown; - float maxVelocity; + + /** + * The modifier applied to the movement speed while sprinting + */ + float modifier; + + /** + * The maximum stamina + */ int staminaMax; + /** + * Gets The animation to play on starting to sprint + * @return The animation to play on starting to sprint + */ public TreeDataAnimation getAnimationStartUp() { return animationStartUp; } + /** + * Gets The main animation to play while sprinting + * @return The main animation to play while sprinting + */ public TreeDataAnimation getAnimationMain() { return animationMain; } + /** + * Gets The animation to play while winding down from sprinting + * @return The animation to play while winding down from sprinting + */ public TreeDataAnimation getAnimationWindDown() { return animationWindDown; } - public float getMaxVelocity() { - return maxVelocity; + /** + * Gets The modifier applied to the movement speed while sprinting + * @return The modifier applied to the movement speed while sprinting + */ + public float getModifier() { + return modifier; } + /** + * Gets The maximum stamina + * @return The maximum stamina + */ public int getStaminaMax() { return staminaMax; } diff --git a/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java b/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java index 57ecc84b..59c3611f 100644 --- a/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java +++ b/src/main/java/electrosphere/net/synchronization/client/ClientSynchronizationManager.java @@ -1,6 +1,7 @@ package electrosphere.net.synchronization.client; +import electrosphere.entity.state.movement.sprint.ClientSprintTree; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.movement.jump.ClientJumpTree; import electrosphere.entity.state.movement.walk.ClientWalkTree; @@ -226,6 +227,14 @@ public class ClientSynchronizationManager { } break; } } break; + case BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID: { + switch(message.getfieldId()){ + case FieldIdEnums.TREE_SERVERSPRINTTREE_SYNCEDFIELD_STATE_ID:{ + ClientSprintTree tree = ClientSprintTree.getClientSprintTree(entity); + tree.setState(ClientSprintTree.getSprintTreeStateShortAsEnum((short)message.getbTreeValue())); + } break; + } + } break; case BehaviorTreeIdEnums.BTREE_SERVERWALKTREE_ID: { switch(message.getfieldId()){ case FieldIdEnums.TREE_SERVERWALKTREE_SYNCEDFIELD_STATE_ID:{ diff --git a/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java b/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java index 1f7f36d4..a3eb5318 100644 --- a/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java +++ b/src/main/java/electrosphere/net/synchronization/enums/BehaviorTreeIdEnums.java @@ -21,6 +21,8 @@ public class BehaviorTreeIdEnums { public static final int BTREE_SERVERGROUNDMOVEMENTTREE_ID = 11; public static final int BTREE_CLIENTJUMPTREE_ID = 14; public static final int BTREE_SERVERJUMPTREE_ID = 15; + public static final int BTREE_CLIENTSPRINTTREE_ID = 18; + public static final int BTREE_SERVERSPRINTTREE_ID = 19; public static final int BTREE_CLIENTWALKTREE_ID = 16; public static final int BTREE_SERVERWALKTREE_ID = 17; diff --git a/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java b/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java index 806a9ec6..2640d505 100644 --- a/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java +++ b/src/main/java/electrosphere/net/synchronization/enums/FieldIdEnums.java @@ -29,6 +29,8 @@ public class FieldIdEnums { public static final int TREE_SERVERJUMPTREE_SYNCEDFIELD_STATE_ID = 19; public static final int TREE_SERVERJUMPTREE_SYNCEDFIELD_CURRENTFRAME_ID = 20; public static final int TREE_SERVERJUMPTREE_SYNCEDFIELD_CURRENTJUMPFORCE_ID = 21; + public static final int TREE_CLIENTSPRINTTREE_SYNCEDFIELD_STATE_ID = 26; + public static final int TREE_SERVERSPRINTTREE_SYNCEDFIELD_STATE_ID = 27; public static final int TREE_CLIENTWALKTREE_SYNCEDFIELD_STATE_ID = 24; public static final int TREE_SERVERWALKTREE_SYNCEDFIELD_STATE_ID = 25; diff --git a/src/main/java/electrosphere/net/synchronization/server/ServerSynchronizationManager.java b/src/main/java/electrosphere/net/synchronization/server/ServerSynchronizationManager.java index c5ba5782..476c9f76 100644 --- a/src/main/java/electrosphere/net/synchronization/server/ServerSynchronizationManager.java +++ b/src/main/java/electrosphere/net/synchronization/server/ServerSynchronizationManager.java @@ -1,6 +1,7 @@ package electrosphere.net.synchronization.server; +import electrosphere.entity.state.movement.sprint.ServerSprintTree; import electrosphere.logger.LoggerInterface; import java.util.LinkedList; @@ -99,6 +100,17 @@ public class ServerSynchronizationManager { } break; } } break; + case BehaviorTreeIdEnums.BTREE_CLIENTSPRINTTREE_ID: { + ServerSprintTree tree = ServerSprintTree.getServerSprintTree(entity); + switch(message.getbTreeValue()){ + case ServerSynchronizationManager.SERVER_SYNC_START: { + tree.start(); + } break; + case ServerSynchronizationManager.SERVER_SYNC_INTERRUPT: { + tree.interrupt(); + } break; + } + } break; case BehaviorTreeIdEnums.BTREE_CLIENTWALKTREE_ID: { ServerWalkTree tree = ServerWalkTree.getServerWalkTree(entity); switch(message.getbTreeValue()){ diff --git a/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java b/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java index ac032f97..198c2d49 100644 --- a/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java +++ b/src/main/java/electrosphere/net/synchronization/transport/StateCollection.java @@ -1,6 +1,8 @@ package electrosphere.net.synchronization.transport; +import electrosphere.entity.state.movement.sprint.ServerSprintTree; +import electrosphere.entity.state.movement.sprint.ClientSprintTree; import electrosphere.entity.state.equip.ClientEquipState; import java.util.LinkedList; import java.util.List; @@ -102,6 +104,10 @@ public class StateCollection { collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERJUMPTREE_ID,FieldIdEnums.TREE_SERVERJUMPTREE_SYNCEDFIELD_CURRENTFRAME_ID,tree.getCurrentFrame())); collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERJUMPTREE_ID,FieldIdEnums.TREE_SERVERJUMPTREE_SYNCEDFIELD_CURRENTJUMPFORCE_ID,tree.getCurrentJumpForce())); } break; + case BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID: { + ServerSprintTree tree = ServerSprintTree.getServerSprintTree(entity); + collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID,FieldIdEnums.TREE_SERVERSPRINTTREE_SYNCEDFIELD_STATE_ID,ClientSprintTree.getSprintTreeStateEnumAsShort(tree.getState()))); + } break; case BehaviorTreeIdEnums.BTREE_SERVERWALKTREE_ID: { ServerWalkTree tree = ServerWalkTree.getServerWalkTree(entity); collection.setValue(new SynchronizedFieldValue(BehaviorTreeIdEnums.BTREE_SERVERWALKTREE_ID,FieldIdEnums.TREE_SERVERWALKTREE_SYNCEDFIELD_STATE_ID,ClientWalkTree.getWalkStateEnumAsShort(tree.getState()))); @@ -199,6 +205,14 @@ public class StateCollection { } break; } } break; + case BehaviorTreeIdEnums.BTREE_SERVERSPRINTTREE_ID: { + ClientSprintTree tree = ClientSprintTree.getClientSprintTree(entity); + switch(syncedValue.getFieldId()){ + case(FieldIdEnums.TREE_SERVERSPRINTTREE_SYNCEDFIELD_STATE_ID): { + tree.setState(ClientSprintTree.getSprintTreeStateShortAsEnum(((Double)syncedValue.getValue()).shortValue())); + } break; + } + } break; case BehaviorTreeIdEnums.BTREE_SERVERWALKTREE_ID: { ClientWalkTree tree = ClientWalkTree.getClientWalkTree(entity); switch(syncedValue.getFieldId()){