diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index d25b2f4f..ceacaafd 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -48,6 +48,7 @@ import electrosphere.net.server.player.Player; import electrosphere.net.server.player.PlayerManager; import electrosphere.net.synchronization.ClientSynchronizationManager; import electrosphere.net.synchronization.EntityValueTrackingService; +import electrosphere.net.synchronization.ServerSynchronizationManager; import electrosphere.renderer.RenderUtils; import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.actor.instance.InstanceManager; @@ -142,6 +143,7 @@ public class Globals { // public static Thread serverThread; public static Server server; + public static ServerSynchronizationManager serverSynchronizationManager = new ServerSynchronizationManager(); public static boolean RUN_SERVER = true; // diff --git a/src/main/java/electrosphere/entity/state/movement/jump/ClientJumpTree.java b/src/main/java/electrosphere/entity/state/movement/jump/ClientJumpTree.java index a7d174f6..27eb763a 100644 --- a/src/main/java/electrosphere/entity/state/movement/jump/ClientJumpTree.java +++ b/src/main/java/electrosphere/entity/state/movement/jump/ClientJumpTree.java @@ -3,6 +3,8 @@ package electrosphere.entity.state.movement.jump; import electrosphere.net.parser.net.message.SynchronizationMessage; import electrosphere.net.synchronization.BehaviorTreeIdEnums; +import electrosphere.net.synchronization.ServerSynchronizationManager; + import org.ode4j.math.DVector3C; import org.ode4j.ode.DBody; @@ -14,7 +16,6 @@ import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; -import electrosphere.entity.state.gravity.GravityUtils; import electrosphere.game.data.creature.type.movement.JumpMovementSystem; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizableEnum; @@ -79,8 +80,8 @@ public class ClientJumpTree implements BehaviorTree { Globals.clientConnection.queueOutgoingMessage( SynchronizationMessage.constructClientRequestBTreeActionMessage( Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), - BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID, - 0 + BehaviorTreeIdEnums.BTREE_CLIENTJUMPTREE_ID, + ServerSynchronizationManager.SERVER_SYNC_START ) ); } @@ -97,19 +98,12 @@ public class ClientJumpTree implements BehaviorTree { } FirstPersonTree.conditionallyPlayAnimation(Globals.firstPersonEntity, jumpData.getAnimationJump()); } - currentFrame++; - currentJumpForce = currentJumpForce * jumpFalloff; //stop body falling if it is DBody body = PhysicsEntityUtils.getDBody(parent); DVector3C linearVelocity = body.getLinearVel(); body.setLinearVel(linearVelocity.get0(), 0, linearVelocity.get2()); //push parent up body.addForce(0, currentJumpForce, 0); - //potentially disable - if(currentFrame >= jumpFrames){ - state = JumpState.AWAITING_LAND; - GravityUtils.clientAttemptActivateGravity(parent); - } break; case INACTIVE: break; @@ -293,8 +287,8 @@ public class ClientJumpTree implements BehaviorTree { Globals.clientConnection.queueOutgoingMessage( SynchronizationMessage.constructClientRequestBTreeActionMessage( Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), - BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID, - 1 + BehaviorTreeIdEnums.BTREE_CLIENTJUMPTREE_ID, + ServerSynchronizationManager.SERVER_SYNC_INTERRUPT ) ); } diff --git a/src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java b/src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java index dda62414..abe65d13 100644 --- a/src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java +++ b/src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java @@ -16,7 +16,6 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.AnimationPriorities; -import electrosphere.entity.state.gravity.GravityUtils; import electrosphere.entity.state.movement.jump.ClientJumpTree.JumpState; import electrosphere.game.data.creature.type.movement.JumpMovementSystem; import electrosphere.net.synchronization.annotation.SyncedField; @@ -58,9 +57,8 @@ public class ServerJumpTree implements BehaviorTree { public void start(){ if(state == JumpState.INACTIVE){ this.setState(JumpState.ACTIVE); - currentFrame = 0; - currentJumpForce = jumpForce; - GravityUtils.serverAttemptActivateGravity(parent); + this.setCurrentFrame(0); + this.setCurrentJumpForce(jumpForce); } } @@ -69,26 +67,25 @@ public class ServerJumpTree implements BehaviorTree { PoseActor poseActor = EntityUtils.getPoseActor(parent); switch(state){ case ACTIVE: - if(poseActor != null){ - String animationToPlay = determineCorrectAnimation(); - if(!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animationToPlay)){ - poseActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.MOVEMENT_MODIFIER)); - poseActor.incrementAnimationTime(0.0001); + if(poseActor != null){ + String animationToPlay = determineCorrectAnimation(); + if(!poseActor.isPlayingAnimation() || !poseActor.isPlayingAnimation(animationToPlay)){ + poseActor.playAnimation(animationToPlay,AnimationPriorities.getValue(AnimationPriorities.MOVEMENT_MODIFIER)); + poseActor.incrementAnimationTime(0.0001); + } + } + this.setCurrentFrame(this.getCurrentFrame()+1); + this.setCurrentJumpForce(currentJumpForce * jumpFalloff); + //stop body falling if it is + DBody body = PhysicsEntityUtils.getDBody(parent); + DVector3C linearVelocity = body.getLinearVel(); + body.setLinearVel(linearVelocity.get0(), 0, linearVelocity.get2()); + //push parent up + body.addForce(0, currentJumpForce, 0); + //potentially disable + if(currentFrame >= jumpFrames){ + this.setState(JumpState.AWAITING_LAND); } - } - currentFrame++; - currentJumpForce = currentJumpForce * jumpFalloff; - //stop body falling if it is - DBody body = PhysicsEntityUtils.getDBody(parent); - DVector3C linearVelocity = body.getLinearVel(); - body.setLinearVel(linearVelocity.get0(), 0, linearVelocity.get2()); - //push parent up - body.addForce(0, currentJumpForce, 0); - //potentially disable - if(currentFrame >= jumpFrames){ - state = JumpState.AWAITING_LAND; - GravityUtils.serverAttemptActivateGravity(parent); - } break; case INACTIVE: break; diff --git a/src/main/java/electrosphere/net/server/protocol/SynchronizationProtocol.java b/src/main/java/electrosphere/net/server/protocol/SynchronizationProtocol.java index 18a32913..0ff896f1 100644 --- a/src/main/java/electrosphere/net/server/protocol/SynchronizationProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/SynchronizationProtocol.java @@ -1,5 +1,6 @@ package electrosphere.net.server.protocol; +import electrosphere.engine.Globals; import electrosphere.net.parser.net.message.SynchronizationMessage; import electrosphere.net.server.ServerConnectionHandler; import electrosphere.net.template.ServerProtocolTemplate; @@ -32,8 +33,9 @@ public class SynchronizationProtocol implements ServerProtocolTemplate messages = new CopyOnWriteArrayList(); + + /** + * Pushes a message into the queue to be processed + * @param message The message + */ + public void pushMessage(SynchronizationMessage message){ + this.messages.add(message); + } + + /** + * Processes all messages in the queue and then clears the queue + */ + public void processMessages(){ + List messagesToClear = new LinkedList(); + for(SynchronizationMessage message : messages){ + //attempt to handle the message + messagesToClear.add(message); + switch(message.getMessageSubtype()){ + case CLIENTREQUESTBTREEACTION: { + Entity entity = EntityLookupUtils.getEntityById(message.getentityId()); + updateEntityState(entity,message.getbTreeId(),message); + } break; + case UPDATECLIENTSTATE: + case UPDATECLIENTDOUBLESTATE: + case UPDATECLIENTFLOATSTATE: + case UPDATECLIENTINTSTATE: + case UPDATECLIENTLONGSTATE: + case UPDATECLIENTSTRINGSTATE: + case ATTACHTREE: + case DETATCHTREE: + case LOADSCENE: + //silently ignore + break; + } + } + for(SynchronizationMessage message : messagesToClear){ + messages.remove(message); + } + } + + /** + *

Automatically generated

+ *

+ * Updates the state of a given behavior tree on a given entity + *

+ * @param entity The entity + * @param bTreeId The id of the behavior tree + * @param message The raw synchronization message holding the update data + */ + private void updateEntityState(Entity entity, int bTreeId, SynchronizationMessage message){ + switch(bTreeId){ + case BehaviorTreeIdEnums.BTREE_CLIENTJUMPTREE_ID: { + ServerJumpTree serverJumpTree = ServerJumpTree.getServerJumpTree(entity); + serverJumpTree.start(); + } break; + } + } + } diff --git a/src/main/java/electrosphere/server/MainServerFunctions.java b/src/main/java/electrosphere/server/MainServerFunctions.java index fc7e28ed..35fdce16 100644 --- a/src/main/java/electrosphere/server/MainServerFunctions.java +++ b/src/main/java/electrosphere/server/MainServerFunctions.java @@ -19,6 +19,9 @@ public class MainServerFunctions { if(Globals.server != null){ Globals.server.synchronousPacketHandling(); } + if(Globals.serverSynchronizationManager != null){ + Globals.serverSynchronizationManager.processMessages(); + } Globals.profiler.endCpuSample(); //