work on synchronization
This commit is contained in:
parent
b0dfee6be0
commit
b7d993ddbb
21
docs/src/codegen/codegen.md
Normal file
21
docs/src/codegen/codegen.md
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
## Behavior Trees
|
||||
|
||||
|
||||
## Synchronized Fields
|
||||
|
||||
## Supported Types
|
||||
The types that are supported
|
||||
|
||||
### Enums
|
||||
How to work with enums
|
||||
|
||||
### Frequencies
|
||||
ie can we toggle how often it updates, or debounce it
|
||||
|
||||
|
||||
## Usage Notes
|
||||
|
||||
### Assumptions
|
||||
- The first line of all parsed files is the package declaration for the package that this file is inside of (ie the behavior tree electrosphere.whatever.myTree has "package electrosphere.whatever" at the top)
|
||||
This is so that imports generation in the helper functions file can be performed accurately
|
||||
@ -43,6 +43,7 @@ import electrosphere.net.monitor.NetMonitor;
|
||||
import electrosphere.net.server.Server;
|
||||
import electrosphere.net.server.player.Player;
|
||||
import electrosphere.net.server.player.PlayerManager;
|
||||
import electrosphere.net.synchronization.EntityValueTrackingService;
|
||||
import electrosphere.renderer.Material;
|
||||
import electrosphere.renderer.RenderUtils;
|
||||
import electrosphere.renderer.RenderingEngine;
|
||||
@ -155,6 +156,11 @@ public class Globals {
|
||||
public static RealmManager realmManager;
|
||||
public static EntityDataCellMapper entityDataCellMapper;
|
||||
|
||||
//
|
||||
//behavior tree tracking service
|
||||
//
|
||||
public static EntityValueTrackingService entityValueTrackingService;
|
||||
|
||||
//
|
||||
//Player manager
|
||||
//
|
||||
@ -394,6 +400,8 @@ public class Globals {
|
||||
gameConfigCurrent = gameConfigDefault;
|
||||
//player manager
|
||||
playerManager = new PlayerManager();
|
||||
//behavior tree tracking service
|
||||
entityValueTrackingService = new EntityValueTrackingService();
|
||||
//net monitor
|
||||
if(Globals.userSettings.getNetRunNetMonitor()){
|
||||
netMonitor = new NetMonitor();
|
||||
|
||||
@ -9,11 +9,12 @@ import electrosphere.engine.Globals;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.annotation.SyncedField;
|
||||
import electrosphere.entity.annotation.SynchronizedBehaviorTree;
|
||||
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
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;
|
||||
import electrosphere.renderer.actor.Actor;
|
||||
import electrosphere.renderer.anim.Animation;
|
||||
|
||||
@ -22,17 +23,24 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.joml.Vector3d;
|
||||
|
||||
|
||||
@SynchronizedBehaviorTree(name = "idle", isServer = false)
|
||||
@SynchronizedBehaviorTree(name = "idle", isServer = false, correspondingTree="serverIdle")
|
||||
/**
|
||||
* Tree for playing an idle animation when an entity isn't doing anything
|
||||
*/
|
||||
public class IdleTree implements BehaviorTree {
|
||||
|
||||
@SynchronizableEnum
|
||||
public static enum IdleTreeState {
|
||||
IDLE,
|
||||
NOT_IDLE,
|
||||
}
|
||||
|
||||
@SyncedField(isEnum = true, enumId = 0)
|
||||
@SyncedField
|
||||
IdleTreeState state;
|
||||
|
||||
@SyncedField
|
||||
int test;
|
||||
|
||||
Entity parent;
|
||||
|
||||
CopyOnWriteArrayList<EntityMessage> networkMessageQueue = new CopyOnWriteArrayList<EntityMessage>();
|
||||
|
||||
@ -3,6 +3,7 @@ package electrosphere.entity.state.idle;
|
||||
import electrosphere.entity.state.BehaviorTree;
|
||||
import electrosphere.entity.state.attack.ServerAttackTree;
|
||||
import electrosphere.entity.state.attack.ServerAttackTree.AttackTreeState;
|
||||
import electrosphere.entity.state.idle.IdleTree.IdleTreeState;
|
||||
import electrosphere.entity.state.movement.AirplaneMovementTree;
|
||||
import electrosphere.entity.state.movement.ServerGroundMovementTree;
|
||||
import electrosphere.engine.Globals;
|
||||
@ -10,11 +11,12 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.engine.Main;
|
||||
import electrosphere.entity.annotation.SyncedField;
|
||||
import electrosphere.entity.annotation.SynchronizedBehaviorTree;
|
||||
import electrosphere.entity.state.movement.ServerGroundMovementTree.MovementTreeState;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.net.synchronization.BehaviorTreeIdEnums;
|
||||
import electrosphere.net.synchronization.annotation.SyncedField;
|
||||
import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree;
|
||||
import electrosphere.renderer.actor.Actor;
|
||||
import electrosphere.renderer.anim.Animation;
|
||||
|
||||
@ -24,14 +26,12 @@ import org.joml.Vector3d;
|
||||
|
||||
|
||||
@SynchronizedBehaviorTree(name = "serverIdle", isServer = true)
|
||||
/**
|
||||
* Tree for playing an idle animation when an entity isn't doing anything
|
||||
*/
|
||||
public class ServerIdleTree {
|
||||
|
||||
public static enum IdleTreeState {
|
||||
IDLE,
|
||||
NOT_IDLE,
|
||||
}
|
||||
|
||||
@SyncedField(isEnum = true, enumId = 0)
|
||||
@SyncedField
|
||||
IdleTreeState state;
|
||||
|
||||
Entity parent;
|
||||
@ -175,4 +175,28 @@ public class ServerIdleTree {
|
||||
networkMessageQueue.add(networkMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Automatically generated </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 void attachTree(Entity entity, BehaviorTree tree){
|
||||
Globals.entityValueTrackingService.attachTreeToEntity(entity, BehaviorTreeIdEnums.BTREE_SERVERIDLE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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_SERVERIDLE_ID);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package electrosphere.net.synchronization;
|
||||
|
||||
/**
|
||||
* List of enums for each automatically synchronized behavior tree.
|
||||
*/
|
||||
public class BehaviorTreeIdEnums {
|
||||
|
||||
public static final int BTREE_IDLE_ID = 0;
|
||||
public static final int BTREE_SERVERIDLE_ID = 1;
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package electrosphere.net.synchronization;
|
||||
|
||||
/**
|
||||
* Takes in raw behavior tree packets from server and pushes their values into respective behavior trees in entities
|
||||
*/
|
||||
public class ClientSynchronizationManager {
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package electrosphere.net.sync;
|
||||
package electrosphere.net.synchronization;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -1,4 +1,4 @@
|
||||
package electrosphere.net.sync;
|
||||
package electrosphere.net.synchronization;
|
||||
|
||||
import electrosphere.entity.state.idle.IdleTree.IdleTreeState;
|
||||
|
||||
@ -1,21 +1,15 @@
|
||||
package electrosphere.entity.annotation;
|
||||
package electrosphere.net.synchronization.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.FIELD)
|
||||
/**
|
||||
* A field in a synchronized behavior tree that is synchronized between the server and the client.
|
||||
*/
|
||||
public @interface SyncedField {
|
||||
|
||||
//True if the field is an enum
|
||||
boolean isEnum() default false;
|
||||
|
||||
//if the field is an enum, this value is MANDETORY. Determines what id will be set to when serialized/deserialized
|
||||
int enumId() default 0;
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package electrosphere.net.synchronization.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.TYPE)
|
||||
/**
|
||||
* Annotation that delineates an enum that should be synchronized over the network
|
||||
*/
|
||||
public @interface SynchronizableEnum {
|
||||
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
package electrosphere.entity.annotation;
|
||||
package electrosphere.net.synchronization.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@Target(ElementType.TYPE)
|
||||
/**
|
||||
* A behavior tree that will have modifications by code generation.
|
||||
@ -19,4 +19,7 @@ public @interface SynchronizedBehaviorTree {
|
||||
//True if this is a server-side behavior tree
|
||||
public boolean isServer() default false;
|
||||
|
||||
//The corresponding behavior tree. If this is a server tree, it is the corresponding client tree. If this is a client tree, it is the corresponding server tree
|
||||
public String correspondingTree() default "";
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user