Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
160 lines
7.8 KiB
Java
160 lines
7.8 KiB
Java
package electrosphere.net.synchronization;
|
|
|
|
|
|
import electrosphere.net.synchronization.FieldIdEnums;
|
|
import electrosphere.entity.state.block.ClientBlockTree;
|
|
import electrosphere.entity.state.block.ServerBlockTree;
|
|
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree;
|
|
import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree;
|
|
import electrosphere.logger.LoggerInterface;
|
|
import electrosphere.entity.state.equip.ClientEquipState;
|
|
import electrosphere.entity.state.attack.ClientAttackTree;
|
|
import electrosphere.entity.state.attack.ServerAttackTree;
|
|
import electrosphere.entity.state.equip.ServerEquipState;
|
|
import electrosphere.entity.state.gravity.ClientGravityTree;
|
|
import electrosphere.entity.state.gravity.ServerGravityTree;
|
|
import electrosphere.entity.state.idle.ServerIdleTree;
|
|
import electrosphere.entity.state.idle.ClientIdleTree;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
import electrosphere.engine.Globals;
|
|
import electrosphere.entity.Entity;
|
|
import electrosphere.net.parser.net.message.SynchronizationMessage;
|
|
|
|
/**
|
|
* Takes in raw behavior tree packets from server and pushes their values into respective behavior trees in entities
|
|
*/
|
|
public class ClientSynchronizationManager {
|
|
|
|
//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){
|
|
if(Globals.clientSceneWrapper.containsServerId(message.getentityId()) && Globals.clientSceneWrapper.getEntityFromServerId(message.getentityId()) != null){
|
|
messagesToClear.add(message);
|
|
switch(message.getMessageSubtype()){
|
|
case UPDATECLIENTSTATE:{
|
|
int bTreeId = message.getbTreeId();
|
|
int entityId = message.getentityId();
|
|
Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId);
|
|
updateEntityState(targetEntity,bTreeId,message);
|
|
} break;
|
|
case UPDATECLIENTSTRINGSTATE:{
|
|
int bTreeId = message.getbTreeId();
|
|
int entityId = message.getentityId();
|
|
Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId);
|
|
updateEntityState(targetEntity,bTreeId,message);
|
|
} break;
|
|
case ATTACHTREE:{
|
|
int bTreeId = message.getbTreeId();
|
|
int bTreeValue = message.getbTreeValue();
|
|
int entityId = message.getentityId();
|
|
} break;
|
|
case DETATCHTREE:{
|
|
int bTreeId = message.getbTreeId();
|
|
int entityId = message.getentityId();
|
|
} break;
|
|
}
|
|
} else if(Globals.clientSceneWrapper.getEntityFromServerId(message.getentityId()) == null){
|
|
String errorMessage =
|
|
"Client received synchronization packet for entity that does not exists on client!\n" +
|
|
"Entity id in network message: " + message.getentityId()
|
|
;
|
|
Globals.clientSceneWrapper.dumpTranslationLayerStatus();
|
|
throw new IllegalStateException(errorMessage);
|
|
}
|
|
}
|
|
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_SERVERATTACKTREE_ID: {
|
|
switch(message.getfieldId()){
|
|
case FieldIdEnums.TREE_SERVERATTACKTREE_SYNCEDFIELD_STATE_ID:{
|
|
ClientAttackTree tree = ClientAttackTree.getClientAttackTree(entity);
|
|
tree.setState(ClientAttackTree.getAttackTreeStateShortAsEnum((short)message.getbTreeValue()));
|
|
} break;
|
|
case FieldIdEnums.TREE_SERVERATTACKTREE_SYNCEDFIELD_DRIFTSTATE_ID:{
|
|
ClientAttackTree tree = ClientAttackTree.getClientAttackTree(entity);
|
|
tree.setDriftState(ClientAttackTree.getAttackTreeDriftStateShortAsEnum((short)message.getbTreeValue()));
|
|
} break;
|
|
case FieldIdEnums.TREE_SERVERATTACKTREE_SYNCEDFIELD_CURRENTMOVEID_ID:{
|
|
ClientAttackTree tree = ClientAttackTree.getClientAttackTree(entity);
|
|
tree.setCurrentMoveId(message.getstringValue());
|
|
} break;
|
|
}
|
|
} break;
|
|
case BehaviorTreeIdEnums.BTREE_SERVERBLOCKTREE_ID: {
|
|
switch(message.getfieldId()){
|
|
case FieldIdEnums.TREE_SERVERBLOCKTREE_SYNCEDFIELD_STATE_ID:{
|
|
ClientBlockTree tree = ClientBlockTree.getClientBlockTree(entity);
|
|
tree.setState(ClientBlockTree.getBlockStateShortAsEnum((short)message.getbTreeValue()));
|
|
} break;
|
|
case FieldIdEnums.TREE_SERVERBLOCKTREE_SYNCEDFIELD_CURRENTBLOCKVARIANT_ID:{
|
|
ClientBlockTree tree = ClientBlockTree.getClientBlockTree(entity);
|
|
tree.setCurrentBlockVariant(message.getstringValue());
|
|
} break;
|
|
}
|
|
} break;
|
|
case BehaviorTreeIdEnums.BTREE_SERVEREQUIPSTATE_ID: {
|
|
switch(message.getfieldId()){
|
|
}
|
|
} break;
|
|
case BehaviorTreeIdEnums.BTREE_SERVERGRAVITY_ID: {
|
|
switch(message.getfieldId()){
|
|
case FieldIdEnums.TREE_SERVERGRAVITY_SYNCEDFIELD_STATE_ID:{
|
|
ClientGravityTree tree = ClientGravityTree.getClientGravityTree(entity);
|
|
tree.setState(ClientGravityTree.getGravityTreeStateShortAsEnum((short)message.getbTreeValue()));
|
|
} break;
|
|
}
|
|
} break;
|
|
case BehaviorTreeIdEnums.BTREE_SERVERIDLE_ID: {
|
|
switch(message.getfieldId()){
|
|
case FieldIdEnums.TREE_SERVERIDLE_SYNCEDFIELD_STATE_ID:{
|
|
ClientIdleTree tree = ClientIdleTree.getClientIdleTree(entity);
|
|
tree.setState(ClientIdleTree.getIdleTreeStateShortAsEnum((short)message.getbTreeValue()));
|
|
} break;
|
|
}
|
|
} break;
|
|
case BehaviorTreeIdEnums.BTREE_SERVERGROUNDMOVEMENTTREE_ID: {
|
|
switch(message.getfieldId()){
|
|
case FieldIdEnums.TREE_SERVERGROUNDMOVEMENTTREE_SYNCEDFIELD_FACING_ID:{
|
|
ClientGroundMovementTree tree = ClientGroundMovementTree.getClientGroundMovementTree(entity);
|
|
tree.setFacing(ClientGroundMovementTree.getMovementRelativeFacingShortAsEnum((short)message.getbTreeValue()));
|
|
} break;
|
|
}
|
|
} break;
|
|
|
|
}
|
|
}
|
|
|
|
}
|