Convert gravity tree
This commit is contained in:
		
							parent
							
								
									b3949e8583
								
							
						
					
					
						commit
						45e0c98ee1
					
				| @ -88,9 +88,9 @@ import electrosphere.entity.state.inventory.InventoryUtils; | |||||||
| import electrosphere.entity.state.inventory.UnrelationalInventoryState; | import electrosphere.entity.state.inventory.UnrelationalInventoryState; | ||||||
| import electrosphere.entity.state.ironsight.IronSightTree; | import electrosphere.entity.state.ironsight.IronSightTree; | ||||||
| import electrosphere.entity.state.movement.GroundMovementTree; | import electrosphere.entity.state.movement.GroundMovementTree; | ||||||
|  | import electrosphere.entity.state.movement.JumpTree; | ||||||
| import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing; | import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing; | ||||||
| import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState; | import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState; | ||||||
| import electrosphere.entity.state.movement.JumpTree; |  | ||||||
| import electrosphere.entity.state.movement.SprintTree; | import electrosphere.entity.state.movement.SprintTree; | ||||||
| import electrosphere.entity.types.camera.CameraEntityUtils; | import electrosphere.entity.types.camera.CameraEntityUtils; | ||||||
| import electrosphere.entity.types.creature.CreatureUtils; | import electrosphere.entity.types.creature.CreatureUtils; | ||||||
|  | |||||||
| @ -129,8 +129,8 @@ public class EntityDataStrings { | |||||||
|     Gravity Entity |     Gravity Entity | ||||||
|     */ |     */ | ||||||
|     public static final String GRAVITY_ENTITY = "gravityEntity"; |     public static final String GRAVITY_ENTITY = "gravityEntity"; | ||||||
|     public static final String CLIENT_GRAVITY_TREE = "clientGravityTree"; |     public static final String TREE_GRAVITY = "treeGravity"; | ||||||
|     public static final String SERVER_GRAVITY_TREE = "serverGravityTree"; |     public static final String TREE_SERVERGRAVITY = "treeServerGravity"; | ||||||
|      |      | ||||||
|     /* |     /* | ||||||
|     Collision Entity |     Collision Entity | ||||||
|  | |||||||
| @ -71,14 +71,14 @@ public class ClientCollidableTree implements BehaviorTree { | |||||||
| //                System.out.println("Position: " + position); | //                System.out.println("Position: " + position); | ||||||
|             } |             } | ||||||
|             if(impulse.type.matches(Collidable.TYPE_ITEM)){ |             if(impulse.type.matches(Collidable.TYPE_ITEM)){ | ||||||
|                 if(parent.containsKey(EntityDataStrings.CLIENT_GRAVITY_TREE)){ |                 if(ClientGravityTree.getClientGravityTree(parent)!=null){ | ||||||
|                     ((ClientGravityTree)parent.getData(EntityDataStrings.CLIENT_GRAVITY_TREE)).start(); |                     ClientGravityTree.getClientGravityTree(parent).start(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if(impulse.type.matches(Collidable.TYPE_CREATURE)){ |             if(impulse.type.matches(Collidable.TYPE_CREATURE)){ | ||||||
| //                System.out.println(System.currentTimeMillis() + " creature hit!"); | //                System.out.println(System.currentTimeMillis() + " creature hit!"); | ||||||
|                 if(parent.containsKey(EntityDataStrings.CLIENT_GRAVITY_TREE)){ |                 if(ClientGravityTree.getClientGravityTree(parent)!=null){ | ||||||
|                     ((ClientGravityTree)parent.getData(EntityDataStrings.CLIENT_GRAVITY_TREE)).start(); |                     ClientGravityTree.getClientGravityTree(parent).start(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if( |             if( | ||||||
|  | |||||||
| @ -73,14 +73,14 @@ public class ServerCollidableTree implements BehaviorTree { | |||||||
| //                System.out.println("Position: " + position); | //                System.out.println("Position: " + position); | ||||||
|             } |             } | ||||||
|             if(impulse.type.matches(Collidable.TYPE_ITEM)){ |             if(impulse.type.matches(Collidable.TYPE_ITEM)){ | ||||||
|                 if(parent.containsKey(EntityDataStrings.SERVER_GRAVITY_TREE)){ |                 if(ServerGravityTree.getServerGravityTree(parent)!=null){ | ||||||
|                     ((ServerGravityTree)parent.getData(EntityDataStrings.SERVER_GRAVITY_TREE)).start(); |                     ServerGravityTree.getServerGravityTree(parent).start(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if(impulse.type.matches(Collidable.TYPE_CREATURE)){ |             if(impulse.type.matches(Collidable.TYPE_CREATURE)){ | ||||||
| //                System.out.println(System.currentTimeMillis() + " creature hit!"); | //                System.out.println(System.currentTimeMillis() + " creature hit!"); | ||||||
|                 if(parent.containsKey(EntityDataStrings.SERVER_GRAVITY_TREE)){ |                 if(ServerGravityTree.getServerGravityTree(parent)!=null){ | ||||||
|                     ((ServerGravityTree)parent.getData(EntityDataStrings.SERVER_GRAVITY_TREE)).start(); |                     ServerGravityTree.getServerGravityTree(parent).start(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if( |             if( | ||||||
|  | |||||||
| @ -1,5 +1,8 @@ | |||||||
| package electrosphere.entity.state.gravity; | package electrosphere.entity.state.gravity; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | import electrosphere.net.synchronization.BehaviorTreeIdEnums; | ||||||
|  | 
 | ||||||
| import java.util.LinkedList; | import java.util.LinkedList; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.concurrent.CopyOnWriteArrayList; | import java.util.concurrent.CopyOnWriteArrayList; | ||||||
| @ -13,6 +16,7 @@ import org.ode4j.ode.DBody; | |||||||
| import electrosphere.collision.collidable.Collidable; | import electrosphere.collision.collidable.Collidable; | ||||||
| import electrosphere.engine.Globals; | import electrosphere.engine.Globals; | ||||||
| import electrosphere.entity.Entity; | import electrosphere.entity.Entity; | ||||||
|  | import electrosphere.entity.EntityDataStrings; | ||||||
| import electrosphere.entity.EntityUtils; | import electrosphere.entity.EntityUtils; | ||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.state.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.ClientCollidableTree; | import electrosphere.entity.state.collidable.ClientCollidableTree; | ||||||
| @ -20,18 +24,23 @@ import electrosphere.entity.state.collidable.Impulse; | |||||||
| import electrosphere.entity.state.movement.FallTree; | import electrosphere.entity.state.movement.FallTree; | ||||||
| import electrosphere.entity.state.movement.JumpTree; | import electrosphere.entity.state.movement.JumpTree; | ||||||
| import electrosphere.net.parser.net.message.EntityMessage; | import electrosphere.net.parser.net.message.EntityMessage; | ||||||
|  | import electrosphere.net.synchronization.annotation.SyncedField; | ||||||
|  | import electrosphere.net.synchronization.annotation.SynchronizableEnum; | ||||||
|  | import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; | ||||||
| 
 | 
 | ||||||
|  | @SynchronizedBehaviorTree(name = "gravity", isServer = false, correspondingTree="serverGravity") | ||||||
| /** | /** | ||||||
|  * |  * Tree for making the entity fall if there's nothing underneath it | ||||||
|  * @author amaterasu |  | ||||||
|  */ |  */ | ||||||
| public class ClientGravityTree implements BehaviorTree { | public class ClientGravityTree implements BehaviorTree { | ||||||
|      |      | ||||||
|  |     @SynchronizableEnum | ||||||
|     public static enum GravityTreeState { |     public static enum GravityTreeState { | ||||||
|         ACTIVE, |         ACTIVE, | ||||||
|         NOT_ACTIVE, |         NOT_ACTIVE, | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     @SyncedField | ||||||
|     GravityTreeState state; |     GravityTreeState state; | ||||||
|      |      | ||||||
|     Entity parent; |     Entity parent; | ||||||
| @ -47,7 +56,7 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
|      |      | ||||||
|     List<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>(); |     List<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>(); | ||||||
|      |      | ||||||
|     public ClientGravityTree(Entity e, Collidable collidable, DBody body, int fallFrame){ |     private ClientGravityTree(Entity e, Collidable collidable, DBody body, int fallFrame){ | ||||||
|         state = GravityTreeState.ACTIVE; |         state = GravityTreeState.ACTIVE; | ||||||
|         parent = e; |         parent = e; | ||||||
|         this.body = body; |         this.body = body; | ||||||
| @ -60,6 +69,12 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
| //        this.collidable = collidable; | //        this.collidable = collidable; | ||||||
| //    } | //    } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Gets state. | ||||||
|  |      * </p> | ||||||
|  |      */ | ||||||
|     public GravityTreeState getState(){ |     public GravityTreeState getState(){ | ||||||
|         return state; |         return state; | ||||||
|     } |     } | ||||||
| @ -234,4 +249,92 @@ public class ClientGravityTree implements BehaviorTree { | |||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * <p> (initially) Automatically generated </p> | ||||||
|  |      * <p> More parameters can be safely added to this method</p> | ||||||
|  |      * <p> | ||||||
|  |      * Attaches this tree to the entity. | ||||||
|  |      * </p> | ||||||
|  |      * @param entity The entity to attach to | ||||||
|  |      * @param tree The behavior tree to attach | ||||||
|  |      */ | ||||||
|  |     public static ClientGravityTree attachTree(Entity parent, Collidable collidable, DBody body, int fallFrame){ | ||||||
|  |         ClientGravityTree rVal = new ClientGravityTree(parent, collidable, body, fallFrame); | ||||||
|  |         //put manual code here (setting params, etc) | ||||||
|  |      | ||||||
|  |      | ||||||
|  |         //!!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_GRAVITY, rVal); | ||||||
|  |         Globals.clientScene.registerBehaviorTree(rVal); | ||||||
|  |         Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_GRAVITY_ID); | ||||||
|  |         return rVal; | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Detatches this tree from the entity. | ||||||
|  |      * </p> | ||||||
|  |      * @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_GRAVITY_ID); | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> | ||||||
|  |      * Gets the ClientGravityTree of the entity | ||||||
|  |      * </p> | ||||||
|  |      * @param entity the entity | ||||||
|  |      * @return The ClientGravityTree | ||||||
|  |      */ | ||||||
|  |     public static ClientGravityTree getClientGravityTree(Entity entity){ | ||||||
|  |         return (ClientGravityTree)entity.getData(EntityDataStrings.TREE_GRAVITY); | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Converts this enum type to an equivalent short value | ||||||
|  |      * </p> | ||||||
|  |      * @param enumVal The enum value | ||||||
|  |      * @return The short value | ||||||
|  |      */ | ||||||
|  |     public static short getGravityTreeStateEnumAsShort(GravityTreeState enumVal){ | ||||||
|  |         switch(enumVal){ | ||||||
|  |             case ACTIVE: | ||||||
|  |                 return 0; | ||||||
|  |             case NOT_ACTIVE: | ||||||
|  |                 return 1; | ||||||
|  |             default: | ||||||
|  |                 return 0; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Converts a short to the equivalent enum value | ||||||
|  |      * </p> | ||||||
|  |      * @param shortVal The short value | ||||||
|  |      * @return The enum value | ||||||
|  |      */ | ||||||
|  |     public static GravityTreeState getGravityTreeStateShortAsEnum(short shortVal){ | ||||||
|  |         switch(shortVal){ | ||||||
|  |             case 0: | ||||||
|  |                 return GravityTreeState.ACTIVE; | ||||||
|  |             case 1: | ||||||
|  |                 return GravityTreeState.NOT_ACTIVE; | ||||||
|  |             default: | ||||||
|  |                 return GravityTreeState.ACTIVE; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Sets state and handles the synchronization logic for it. | ||||||
|  |      * </p> | ||||||
|  |      * @param state The value to set state to. | ||||||
|  |      */ | ||||||
|  |     public void setState(GravityTreeState state){ | ||||||
|  |         this.state = state; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -7,28 +7,28 @@ public class GravityUtils { | |||||||
|      |      | ||||||
|     public static void clientAttemptActivateGravity(Entity target){ |     public static void clientAttemptActivateGravity(Entity target){ | ||||||
|         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ |         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ | ||||||
|             ClientGravityTree tree = (ClientGravityTree)target.getData(EntityDataStrings.CLIENT_GRAVITY_TREE); |             ClientGravityTree tree = ClientGravityTree.getClientGravityTree(target); | ||||||
|             tree.start(); |             tree.start(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static void serverAttemptActivateGravity(Entity target){ |     public static void serverAttemptActivateGravity(Entity target){ | ||||||
|         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ |         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ | ||||||
|             ServerGravityTree tree = (ServerGravityTree)target.getData(EntityDataStrings.SERVER_GRAVITY_TREE); |             ServerGravityTree tree = ServerGravityTree.getServerGravityTree(target); | ||||||
|             tree.start(); |             tree.start(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static void clientAttemptDeactivateGravity(Entity target){ |     public static void clientAttemptDeactivateGravity(Entity target){ | ||||||
|         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ |         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ | ||||||
|             ClientGravityTree tree = (ClientGravityTree)target.getData(EntityDataStrings.CLIENT_GRAVITY_TREE); |             ClientGravityTree tree = ClientGravityTree.getClientGravityTree(target); | ||||||
|             tree.stop(); |             tree.stop(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static void serverAttemptDeactivateGravity(Entity target){ |     public static void serverAttemptDeactivateGravity(Entity target){ | ||||||
|         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ |         if(target.containsKey(EntityDataStrings.GRAVITY_ENTITY)){ | ||||||
|             ServerGravityTree tree = (ServerGravityTree)target.getData(EntityDataStrings.SERVER_GRAVITY_TREE); |             ServerGravityTree tree = ServerGravityTree.getServerGravityTree(target); | ||||||
|             tree.stop(); |             tree.stop(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -1,5 +1,13 @@ | |||||||
| package electrosphere.entity.state.gravity; | package electrosphere.entity.state.gravity; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | import electrosphere.entity.EntityDataStrings; | ||||||
|  | 
 | ||||||
|  | import electrosphere.net.synchronization.BehaviorTreeIdEnums; | ||||||
|  | import electrosphere.net.parser.net.message.SynchronizationMessage; | ||||||
|  | import electrosphere.server.datacell.utils.DataCellSearchUtils; | ||||||
|  | import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils; | ||||||
|  | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.concurrent.CopyOnWriteArrayList; | import java.util.concurrent.CopyOnWriteArrayList; | ||||||
| 
 | 
 | ||||||
| @ -16,22 +24,21 @@ import electrosphere.entity.EntityUtils; | |||||||
| import electrosphere.entity.state.BehaviorTree; | import electrosphere.entity.state.BehaviorTree; | ||||||
| import electrosphere.entity.state.collidable.Impulse; | import electrosphere.entity.state.collidable.Impulse; | ||||||
| import electrosphere.entity.state.collidable.ServerCollidableTree; | import electrosphere.entity.state.collidable.ServerCollidableTree; | ||||||
|  | import electrosphere.entity.state.gravity.ClientGravityTree.GravityTreeState; | ||||||
| import electrosphere.entity.state.movement.ServerFallTree; | import electrosphere.entity.state.movement.ServerFallTree; | ||||||
| import electrosphere.entity.state.movement.ServerJumpTree; | import electrosphere.entity.state.movement.ServerJumpTree; | ||||||
| import electrosphere.net.parser.net.message.EntityMessage; | import electrosphere.net.parser.net.message.EntityMessage; | ||||||
|  | import electrosphere.net.synchronization.annotation.SyncedField; | ||||||
|  | import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; | ||||||
| import electrosphere.server.datacell.Realm; | import electrosphere.server.datacell.Realm; | ||||||
| 
 | 
 | ||||||
|  | @SynchronizedBehaviorTree(name = "serverGravity", isServer = true, correspondingTree="gravity") | ||||||
| /** | /** | ||||||
|  * |  * Tree for making the entity fall if there's nothing underneath it | ||||||
|  * @author amaterasu |  | ||||||
|  */ |  */ | ||||||
| public class ServerGravityTree implements BehaviorTree { | public class ServerGravityTree implements BehaviorTree { | ||||||
|      |      | ||||||
|     public static enum GravityTreeState { |     @SyncedField | ||||||
|         ACTIVE, |  | ||||||
|         NOT_ACTIVE, |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     GravityTreeState state; |     GravityTreeState state; | ||||||
|      |      | ||||||
|     Entity parent; |     Entity parent; | ||||||
| @ -47,7 +54,7 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
|      |      | ||||||
|     List<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>(); |     List<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>(); | ||||||
|      |      | ||||||
|     public ServerGravityTree(Entity e, Collidable collidable, DBody body, int fallFrame){ |     private ServerGravityTree(Entity e, Collidable collidable, DBody body, int fallFrame){ | ||||||
|         state = GravityTreeState.ACTIVE; |         state = GravityTreeState.ACTIVE; | ||||||
|         parent = e; |         parent = e; | ||||||
|         this.body = body; |         this.body = body; | ||||||
| @ -60,24 +67,30 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
| //        this.collidable = collidable; | //        this.collidable = collidable; | ||||||
| //    } | //    } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Gets state. | ||||||
|  |      * </p> | ||||||
|  |      */ | ||||||
|     public GravityTreeState getState(){ |     public GravityTreeState getState(){ | ||||||
|         return state; |         return state; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public void start(){ |     public void start(){ | ||||||
|         //TODO: check if can start moving |         //TODO: check if can start moving | ||||||
|         state = GravityTreeState.ACTIVE; |         setState(GravityTreeState.ACTIVE); | ||||||
|         if(state == GravityTreeState.NOT_ACTIVE){ |         if(state == GravityTreeState.NOT_ACTIVE){ | ||||||
|             frameCurrent = 0; |             frameCurrent = 0; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public void interrupt(){ |     public void interrupt(){ | ||||||
|         state = GravityTreeState.NOT_ACTIVE; |         setState(GravityTreeState.NOT_ACTIVE); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public void stop(){ |     public void stop(){ | ||||||
|         state = GravityTreeState.NOT_ACTIVE; |         setState(GravityTreeState.NOT_ACTIVE); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     static final float gravityConstant = 0.2f; |     static final float gravityConstant = 0.2f; | ||||||
| @ -130,7 +143,7 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
|         switch(state){ |         switch(state){ | ||||||
|             case ACTIVE: |             case ACTIVE: | ||||||
|                 if(hadGroundCollision()){ |                 if(hadGroundCollision()){ | ||||||
|                     state = GravityTreeState.NOT_ACTIVE; |                     setState(GravityTreeState.NOT_ACTIVE); | ||||||
|                     if(!hadStructureCollision()){ |                     if(!hadStructureCollision()){ | ||||||
| //                        position.set(new Vector3d(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z)); | //                        position.set(new Vector3d(position.x,Globals.commonWorldData.getElevationAtPoint(position) + 0.0001f,position.z)); | ||||||
|                     } |                     } | ||||||
| @ -229,4 +242,58 @@ public class ServerGravityTree implements BehaviorTree { | |||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Sets state and handles the synchronization logic for it. | ||||||
|  |      * </p> | ||||||
|  |      * @param state The value to set state to. | ||||||
|  |      */ | ||||||
|  |     public void setState(GravityTreeState state){ | ||||||
|  |         this.state = state; | ||||||
|  |         int value = ClientGravityTree.getGravityTreeStateEnumAsShort(state); | ||||||
|  |         DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), 1, 1, value)); | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> (initially) Automatically generated </p> | ||||||
|  |      * <p> More parameters can be safely added to this method</p> | ||||||
|  |      * <p> | ||||||
|  |      * Attaches this tree to the entity. | ||||||
|  |      * </p> | ||||||
|  |      * @param entity The entity to attach to | ||||||
|  |      * @param tree The behavior tree to attach | ||||||
|  |      */ | ||||||
|  |     public static ServerGravityTree attachTree(Entity parent, Collidable collidable, DBody body, int fallFrame){ | ||||||
|  |         ServerGravityTree rVal = new ServerGravityTree(parent,collidable,body,fallFrame); | ||||||
|  |         //put manual code here (setting params, etc) | ||||||
|  |      | ||||||
|  |      | ||||||
|  |         //!!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_SERVERGRAVITY, rVal); | ||||||
|  |         Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_SERVERGRAVITY_ID); | ||||||
|  |         return rVal; | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Detatches this tree from the entity. | ||||||
|  |      * </p> | ||||||
|  |      * @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_SERVERGRAVITY_ID); | ||||||
|  |     } | ||||||
|  |     /** | ||||||
|  |      * <p> | ||||||
|  |      * Gets the ServerGravityTree of the entity | ||||||
|  |      * </p> | ||||||
|  |      * @param entity the entity | ||||||
|  |      * @return The ServerGravityTree | ||||||
|  |      */ | ||||||
|  |     public static ServerGravityTree getServerGravityTree(Entity entity){ | ||||||
|  |         return (ServerGravityTree)entity.getData(EntityDataStrings.TREE_SERVERGRAVITY); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -43,14 +43,16 @@ public class IdleTree implements BehaviorTree { | |||||||
|         parent = e; |         parent = e; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Gets state. | ||||||
|  |      * </p> | ||||||
|  |      */ | ||||||
|     public IdleTreeState getState(){ |     public IdleTreeState getState(){ | ||||||
|         return state; |         return state; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setState(IdleTreeState state){ |  | ||||||
|         this.state = state; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
|     public void interrupt(){ |     public void interrupt(){ | ||||||
|         state = IdleTreeState.NOT_IDLE; |         state = IdleTreeState.NOT_IDLE; | ||||||
| @ -137,6 +139,7 @@ public class IdleTree implements BehaviorTree { | |||||||
|         //!!WARNING!! from here below should not be touched |         //!!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 |         //This was generated automatically to properly alert various systems that the btree exists and should be tracked | ||||||
|         parent.putData(EntityDataStrings.TREE_IDLE, rVal); |         parent.putData(EntityDataStrings.TREE_IDLE, rVal); | ||||||
|  |         Globals.clientScene.registerBehaviorTree(rVal); | ||||||
|         Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_IDLE_ID); |         Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_IDLE_ID); | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| @ -186,4 +189,14 @@ public class IdleTree implements BehaviorTree { | |||||||
|     public static IdleTree getIdleTree(Entity entity){ |     public static IdleTree getIdleTree(Entity entity){ | ||||||
|         return (IdleTree)entity.getData(EntityDataStrings.TREE_IDLE); |         return (IdleTree)entity.getData(EntityDataStrings.TREE_IDLE); | ||||||
|     } |     } | ||||||
|  |     /** | ||||||
|  |      * <p> Automatically generated </p> | ||||||
|  |      * <p> | ||||||
|  |      * Sets state and handles the synchronization logic for it. | ||||||
|  |      * </p> | ||||||
|  |      * @param state The value to set state to. | ||||||
|  |      */ | ||||||
|  |     public void setState(IdleTreeState state){ | ||||||
|  |         this.state = state; | ||||||
|  |     } | ||||||
| } | } | ||||||
| @ -185,7 +185,7 @@ public class ServerIdleTree implements BehaviorTree { | |||||||
|     public void setState(IdleTreeState state){ |     public void setState(IdleTreeState state){ | ||||||
|         this.state = state; |         this.state = state; | ||||||
|         int value = IdleTree.getIdleTreeStateEnumAsShort(state); |         int value = IdleTree.getIdleTreeStateEnumAsShort(state); | ||||||
|         DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), 1, 1, value)); |         DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), 3, 3, value)); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ import electrosphere.renderer.actor.Actor; | |||||||
| 
 | 
 | ||||||
| public class JumpTree implements BehaviorTree { | public class JumpTree implements BehaviorTree { | ||||||
| 
 | 
 | ||||||
|     static enum JumpState { |     public static enum JumpState { | ||||||
|         INACTIVE, |         INACTIVE, | ||||||
|         ACTIVE, |         ACTIVE, | ||||||
|         AWAITING_LAND, |         AWAITING_LAND, | ||||||
|  | |||||||
| @ -260,11 +260,8 @@ public class CreatureUtils { | |||||||
|                 case "GRAVITY": |                 case "GRAVITY": | ||||||
|                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); |                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); | ||||||
|                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                     ClientGravityTree gravityTree = new ClientGravityTree(rVal,collidable,collisionObject,30); |                     ClientGravityTree.attachTree(rVal, collidable, collisionObject, 30); | ||||||
|     //                    gravityTree.setCollisionObject(collisionObject, collidable); |  | ||||||
|                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); |                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); | ||||||
|                     rVal.putData(EntityDataStrings.CLIENT_GRAVITY_TREE, gravityTree); |  | ||||||
|                     Globals.clientScene.registerBehaviorTree(gravityTree); |  | ||||||
|                     break; |                     break; | ||||||
|                 case "TARGETABLE": |                 case "TARGETABLE": | ||||||
|                 Globals.clientScene.registerEntityToTag(rVal, EntityTags.TARGETABLE); |                 Globals.clientScene.registerEntityToTag(rVal, EntityTags.TARGETABLE); | ||||||
| @ -559,11 +556,8 @@ public class CreatureUtils { | |||||||
|                 case "GRAVITY": { |                 case "GRAVITY": { | ||||||
|                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); |                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); | ||||||
|                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                     ServerGravityTree gravityTree = new ServerGravityTree(rVal,collidable,collisionObject,30); |                     ServerGravityTree.attachTree(rVal, collidable, collisionObject, 30); | ||||||
|     //                    gravityTree.setCollisionObject(collisionObject, collidable); |  | ||||||
|                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); |                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); | ||||||
|                     rVal.putData(EntityDataStrings.SERVER_GRAVITY_TREE, gravityTree); |  | ||||||
|                     ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, gravityTree); |  | ||||||
|                 } break; |                 } break; | ||||||
|                 case "TARGETABLE": { |                 case "TARGETABLE": { | ||||||
|                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); |                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); | ||||||
|  | |||||||
| @ -80,11 +80,8 @@ public class ItemUtils { | |||||||
|                 case "GRAVITY": |                 case "GRAVITY": | ||||||
|                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); |                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); | ||||||
|                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                     ClientGravityTree gravityTree = new ClientGravityTree(rVal,collidable,collisionObject,30); |                     ClientGravityTree.attachTree(rVal, collidable, collisionObject, 30); | ||||||
| //                    gravityTree.setCollisionObject(collisionObject, collidable); |  | ||||||
|                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); |                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); | ||||||
|                     rVal.putData(EntityDataStrings.CLIENT_GRAVITY_TREE, gravityTree); |  | ||||||
|                     Globals.clientSceneWrapper.getScene().registerBehaviorTree(gravityTree); |  | ||||||
|                     break; |                     break; | ||||||
|                 case "TARGETABLE": |                 case "TARGETABLE": | ||||||
|                     Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.TARGETABLE); |                     Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.TARGETABLE); | ||||||
| @ -153,11 +150,8 @@ public class ItemUtils { | |||||||
|                 case "GRAVITY": |                 case "GRAVITY": | ||||||
|                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); |                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); | ||||||
|                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                     ServerGravityTree gravityTree = new ServerGravityTree(rVal,collidable,collisionObject,30); |                     ServerGravityTree.attachTree(rVal, collidable, collisionObject, 30); | ||||||
| //                    gravityTree.setCollisionObject(collisionObject, collidable); |  | ||||||
|                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); |                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); | ||||||
|                     rVal.putData(EntityDataStrings.SERVER_GRAVITY_TREE, gravityTree); |  | ||||||
|                     ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, gravityTree); |  | ||||||
|                     break; |                     break; | ||||||
|                 case "TARGETABLE": |                 case "TARGETABLE": | ||||||
|                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); |                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); | ||||||
|  | |||||||
| @ -90,11 +90,8 @@ public class ObjectUtils { | |||||||
|                 case "GRAVITY": |                 case "GRAVITY": | ||||||
|                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); |                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); | ||||||
|                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                     ClientGravityTree gravityTree = new ClientGravityTree(rVal,collidable,collisionObject,30); |                     ClientGravityTree.attachTree(rVal, collidable, collisionObject, 30); | ||||||
| //                    gravityTree.setCollisionObject(collisionObject, collidable); |  | ||||||
|                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); |                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); | ||||||
|                     rVal.putData(EntityDataStrings.CLIENT_GRAVITY_TREE, gravityTree); |  | ||||||
|                     Globals.clientSceneWrapper.getScene().registerBehaviorTree(gravityTree); |  | ||||||
|                     break; |                     break; | ||||||
|                 case "TARGETABLE": |                 case "TARGETABLE": | ||||||
|                     Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.TARGETABLE); |                     Globals.clientSceneWrapper.getScene().registerEntityToTag(rVal, EntityTags.TARGETABLE); | ||||||
| @ -187,11 +184,8 @@ public class ObjectUtils { | |||||||
|                 case "GRAVITY": |                 case "GRAVITY": | ||||||
|                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); |                     Collidable collidable = (Collidable)rVal.getData(EntityDataStrings.PHYSICS_COLLIDABLE); | ||||||
|                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); |                     DBody collisionObject = (DBody)rVal.getData(EntityDataStrings.PHYSICS_COLLISION_BODY); | ||||||
|                     ServerGravityTree gravityTree = new ServerGravityTree(rVal,collidable,collisionObject,30); |                     ServerGravityTree.attachTree(rVal, collidable, collisionObject, 30); | ||||||
| //                    gravityTree.setCollisionObject(collisionObject, collidable); |  | ||||||
|                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); |                     rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true); | ||||||
|                     rVal.putData(EntityDataStrings.SERVER_GRAVITY_TREE, gravityTree); |  | ||||||
|                     ServerBehaviorTreeUtils.attachBTreeToEntity(rVal, gravityTree); |  | ||||||
|                     break; |                     break; | ||||||
|                 case "TARGETABLE": |                 case "TARGETABLE": | ||||||
|                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); |                     ServerEntityTagUtils.attachTagToEntity(rVal, EntityTags.TARGETABLE); | ||||||
|  | |||||||
| @ -5,7 +5,9 @@ package electrosphere.net.synchronization; | |||||||
|  */ |  */ | ||||||
| public class BehaviorTreeIdEnums { | public class BehaviorTreeIdEnums { | ||||||
| 
 | 
 | ||||||
|     public static final int BTREE_IDLE_ID = 0; |     public static final int BTREE_GRAVITY_ID = 0; | ||||||
|     public static final int BTREE_SERVERIDLE_ID = 1; |     public static final int BTREE_SERVERGRAVITY_ID = 1; | ||||||
|  |     public static final int BTREE_IDLE_ID = 2; | ||||||
|  |     public static final int BTREE_SERVERIDLE_ID = 3; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,6 +1,9 @@ | |||||||
| package electrosphere.net.synchronization; | package electrosphere.net.synchronization; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | import electrosphere.entity.state.gravity.ClientGravityTree; | ||||||
|  | import electrosphere.entity.state.gravity.ServerGravityTree; | ||||||
|  | 
 | ||||||
| import electrosphere.entity.state.idle.ServerIdleTree; | import electrosphere.entity.state.idle.ServerIdleTree; | ||||||
| 
 | 
 | ||||||
| import electrosphere.entity.state.idle.IdleTree; | import electrosphere.entity.state.idle.IdleTree; | ||||||
| @ -70,9 +73,17 @@ public class ClientSynchronizationManager { | |||||||
|      */ |      */ | ||||||
|     private void updateEntityState(Entity entity, int bTreeId, SynchronizationMessage message){ |     private void updateEntityState(Entity entity, int bTreeId, SynchronizationMessage message){ | ||||||
|         switch(bTreeId){ |         switch(bTreeId){ | ||||||
|             case BehaviorTreeIdEnums.BTREE_SERVERIDLE_ID: { |             case BehaviorTreeIdEnums.BTREE_SERVERGRAVITY_ID: { | ||||||
|                 switch(message.getfieldId()){ |                 switch(message.getfieldId()){ | ||||||
|                     case 1:{ |                     case 1:{ | ||||||
|  |                         ClientGravityTree tree = ClientGravityTree.getClientGravityTree(entity); | ||||||
|  |                         tree.setState(ClientGravityTree.getGravityTreeStateShortAsEnum((short)message.getbTreeValue())); | ||||||
|  |                     } break; | ||||||
|  |                 } | ||||||
|  |             } break; | ||||||
|  |             case BehaviorTreeIdEnums.BTREE_SERVERIDLE_ID: { | ||||||
|  |                 switch(message.getfieldId()){ | ||||||
|  |                     case 3:{ | ||||||
|                         IdleTree tree = IdleTree.getIdleTree(entity); |                         IdleTree tree = IdleTree.getIdleTree(entity); | ||||||
|                         tree.setState(IdleTree.getIdleTreeStateShortAsEnum((short)message.getbTreeValue())); |                         tree.setState(IdleTree.getIdleTreeStateShortAsEnum((short)message.getbTreeValue())); | ||||||
|                     } break; |                     } break; | ||||||
|  | |||||||
| @ -12,4 +12,15 @@ import java.lang.annotation.Target; | |||||||
|  */ |  */ | ||||||
| public @interface SyncedField { | public @interface SyncedField { | ||||||
| 
 | 
 | ||||||
|  |     //how often should the server broadcast update messages, in frames | ||||||
|  |     public String updateInterval() default ""; | ||||||
|  | 
 | ||||||
|  |     //the states that this should periodically update under | ||||||
|  |     //when provided, this field will only send updates from server when the behavior tree has the states listed | ||||||
|  |     public String[] periodicUpdateStates() default ""; | ||||||
|  | 
 | ||||||
|  |     //when true, the server will bundle the current spatial information of the entity alongside the variable update | ||||||
|  |     //ie when idle state changes (to idle from not idle), tell the client the position of the entity when this update happened alongside the actual state update | ||||||
|  |     public boolean updatePositionOnStateChange() default false; | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user