server-synchronized jump
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
335ead8341
commit
d409c3adef
@ -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;
|
||||
|
||||
//
|
||||
|
||||
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<Synchroni
|
||||
@Override
|
||||
public void handleSyncMessage(ServerConnectionHandler connectionHandler, SynchronizationMessage message) {
|
||||
switch(message.getMessageSubtype()){
|
||||
case CLIENTREQUESTBTREEACTION:
|
||||
// throw new UnsupportedOperationException("Not implemented yet!");
|
||||
case CLIENTREQUESTBTREEACTION:{
|
||||
Globals.serverSynchronizationManager.pushMessage(message);
|
||||
} break;
|
||||
case UPDATECLIENTSTATE:
|
||||
case UPDATECLIENTSTRINGSTATE:
|
||||
case UPDATECLIENTDOUBLESTATE:
|
||||
|
||||
@ -1,8 +1,88 @@
|
||||
package electrosphere.net.synchronization;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.state.movement.jump.ServerJumpTree;
|
||||
import electrosphere.net.parser.net.message.SynchronizationMessage;
|
||||
import electrosphere.server.datacell.utils.EntityLookupUtils;
|
||||
|
||||
/**
|
||||
* Server service to handle synchronization packets from client (principally, requesting to start btrees)
|
||||
*/
|
||||
public class ServerSynchronizationManager {
|
||||
|
||||
/**
|
||||
* Signal to start the specified tree
|
||||
*/
|
||||
public static final int SERVER_SYNC_START = 0;
|
||||
|
||||
/**
|
||||
* Signal to interrupt the specified tree
|
||||
*/
|
||||
public static final int SERVER_SYNC_INTERRUPT = 1;
|
||||
|
||||
|
||||
//The list of messages to loop through
|
||||
List<SynchronizationMessage> messages = new CopyOnWriteArrayList<SynchronizationMessage>();
|
||||
|
||||
/**
|
||||
* 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<SynchronizationMessage> messagesToClear = new LinkedList<SynchronizationMessage>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Automatically generated </p>
|
||||
* <p>
|
||||
* Updates the state of a given behavior tree on a given entity
|
||||
* </p>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,9 @@ public class MainServerFunctions {
|
||||
if(Globals.server != null){
|
||||
Globals.server.synchronousPacketHandling();
|
||||
}
|
||||
if(Globals.serverSynchronizationManager != null){
|
||||
Globals.serverSynchronizationManager.processMessages();
|
||||
}
|
||||
Globals.profiler.endCpuSample();
|
||||
|
||||
//
|
||||
|
||||
Loading…
Reference in New Issue
Block a user