support server synchronization manager
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good
This commit is contained in:
parent
2871381d89
commit
e66b36c305
@ -34,6 +34,7 @@ public class Main {
|
|||||||
//hard-coded white list files to always parse
|
//hard-coded white list files to always parse
|
||||||
static final String[] ALWAYS_PARSED_CLASSES = new String[]{
|
static final String[] ALWAYS_PARSED_CLASSES = new String[]{
|
||||||
"ClientSynchronizationManager",
|
"ClientSynchronizationManager",
|
||||||
|
"ServerSynchronizationManager",
|
||||||
"BehaviorTreeIdEnums",
|
"BehaviorTreeIdEnums",
|
||||||
"FieldIdEnums",
|
"FieldIdEnums",
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import electrosphere.main.client.syncmanager.ClientSynchronizationManager;
|
|||||||
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||||
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
|
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
|
||||||
import electrosphere.main.project.ProjectStructure;
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
import electrosphere.main.server.syncmanager.ServerSynchronizationManager;
|
||||||
import electrosphere.main.source.VirtualClass;
|
import electrosphere.main.source.VirtualClass;
|
||||||
import electrosphere.main.targets.TargetFile;
|
import electrosphere.main.targets.TargetFile;
|
||||||
|
|
||||||
@ -71,6 +72,14 @@ public class VirtualProject {
|
|||||||
return this.clientSynchronizationManager;
|
return this.clientSynchronizationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a server synchronization manager file
|
||||||
|
* @param file The target file
|
||||||
|
*/
|
||||||
|
public void createServerSynchronizationManager(TargetFile file){
|
||||||
|
this.classes.add(new ServerSynchronizationManager(file));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a virtual class to the project
|
* Adds a virtual class to the project
|
||||||
* @param virtualClass The virtual class
|
* @param virtualClass The virtual class
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package electrosphere.main.core.btree;
|
package electrosphere.main.core.btree;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||||
import electrosphere.main.source.VirtualClass;
|
import electrosphere.main.source.VirtualClass;
|
||||||
@ -33,6 +36,9 @@ public class BehaviorTree extends VirtualClass {
|
|||||||
//The file this type appears in
|
//The file this type appears in
|
||||||
TargetFile targetFile;
|
TargetFile targetFile;
|
||||||
|
|
||||||
|
//The annotations that were applied to this tree
|
||||||
|
Map<String,Object> annotations = new HashMap<String,Object>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param id
|
* @param id
|
||||||
@ -160,9 +166,22 @@ public class BehaviorTree extends VirtualClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an annotation to the btree
|
||||||
|
* @param annotationName The name of the annotation
|
||||||
|
* @param value The value of the annotation
|
||||||
|
*/
|
||||||
|
public void addAnnotation(String annotationName, Object value){
|
||||||
|
this.annotations.put(annotationName, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the set of annotations applied to this tree
|
||||||
|
* @return The set of annotations
|
||||||
|
*/
|
||||||
|
public Set<String> getAnnotations(){
|
||||||
|
return this.annotations.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -67,6 +67,9 @@ public class BTreeParser {
|
|||||||
isServer,
|
isServer,
|
||||||
target
|
target
|
||||||
);
|
);
|
||||||
|
rVal.addAnnotation("name", bTreeName);
|
||||||
|
rVal.addAnnotation("correspondingTree", bTreeCorrespondingName);
|
||||||
|
rVal.addAnnotation("isServer", isServer);
|
||||||
behaviorTrees.add(rVal);
|
behaviorTrees.add(rVal);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -117,6 +120,7 @@ public class BTreeParser {
|
|||||||
TargetFile targetFile = tree.getTargetFile();
|
TargetFile targetFile = tree.getTargetFile();
|
||||||
if(mainAnnotation.getStringValue("genStartInt") != null){
|
if(mainAnnotation.getStringValue("genStartInt") != null){
|
||||||
boolean genStartInt = Boolean.parseBoolean(mainAnnotation.getStringValue("genStartInt"));
|
boolean genStartInt = Boolean.parseBoolean(mainAnnotation.getStringValue("genStartInt"));
|
||||||
|
tree.addAnnotation("genStartInt", genStartInt);
|
||||||
if(genStartInt){
|
if(genStartInt){
|
||||||
tree.addMethod(new ClientStart(tree.getName(), targetFile.getSource().getName()));
|
tree.addMethod(new ClientStart(tree.getName(), targetFile.getSource().getName()));
|
||||||
tree.addMethod(new ClientInterrupt(tree.getName(), targetFile.getSource().getName()));
|
tree.addMethod(new ClientInterrupt(tree.getName(), targetFile.getSource().getName()));
|
||||||
|
|||||||
@ -60,6 +60,11 @@ public class MainParser {
|
|||||||
if(target.getName().contains("ClientSynchronizationManager")){
|
if(target.getName().contains("ClientSynchronizationManager")){
|
||||||
rVal.createClientSynchronizationManager(target);
|
rVal.createClientSynchronizationManager(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//server synchronization manager
|
||||||
|
if(target.getName().contains("ServerSynchronizationManager")){
|
||||||
|
rVal.createServerSynchronizationManager(target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rVal;
|
return rVal;
|
||||||
|
|||||||
@ -0,0 +1,35 @@
|
|||||||
|
package electrosphere.main.server.syncmanager;
|
||||||
|
|
||||||
|
import electrosphere.main.server.syncmanager.methods.UpdateEntityState;
|
||||||
|
import electrosphere.main.source.VirtualClass;
|
||||||
|
import electrosphere.main.targets.TargetFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The client synchronization manager class
|
||||||
|
*/
|
||||||
|
public class ServerSynchronizationManager extends VirtualClass {
|
||||||
|
|
||||||
|
|
||||||
|
//The target file for the current version of this class
|
||||||
|
TargetFile file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public ServerSynchronizationManager(TargetFile file) {
|
||||||
|
super(
|
||||||
|
file,
|
||||||
|
"ServerSynchronizationManager",
|
||||||
|
true
|
||||||
|
);
|
||||||
|
this.file = file;
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// ADD METHODS HERE
|
||||||
|
//
|
||||||
|
//
|
||||||
|
this.addMethod(new UpdateEntityState());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,74 @@
|
|||||||
|
package electrosphere.main.server.syncmanager.methods;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import electrosphere.main.core.btree.BehaviorTree;
|
||||||
|
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||||
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
import electrosphere.main.source.VirtualMethod;
|
||||||
|
import electrosphere.main.util.TemplateInjectionUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates individual entity tree states
|
||||||
|
*/
|
||||||
|
public class UpdateEntityState implements VirtualMethod {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName(ProjectStructure projectStructure) {
|
||||||
|
return "updateEntityState";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContent(ProjectStructure projectStructure) {
|
||||||
|
String updateCases = "";
|
||||||
|
for(BehaviorTree serverTree : projectStructure.getBehaviorTrees()){
|
||||||
|
//counterintuitively, want to only update client for server behavior tree ids
|
||||||
|
if(serverTree.isServer() && this.shouldIncludeTree(projectStructure, serverTree)){
|
||||||
|
BehaviorTree clientEquivalent = projectStructure.getTree(serverTree.getCorrespondingTreeName());
|
||||||
|
String serverTreeName = serverTree.getClassName();
|
||||||
|
updateCases = updateCases + " case BehaviorTreeIdEnums." + BTreeIdEnum.getTreeIdEnum(clientEquivalent) + ": {\n";
|
||||||
|
updateCases = updateCases + " " + serverTreeName + " tree = " + serverTreeName + ".get" + serverTreeName + "(entity);\n";
|
||||||
|
updateCases = updateCases + " tree.start();\n";
|
||||||
|
updateCases = updateCases + " } break;\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/server/UpdateEntityState.java", updateCases);
|
||||||
|
return fullReplacementText;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getImports(ProjectStructure projectStructure) {
|
||||||
|
List<String> rVal = new LinkedList<String>();
|
||||||
|
|
||||||
|
//add server trees
|
||||||
|
for(BehaviorTree bTree : projectStructure.getBehaviorTrees()){
|
||||||
|
if(bTree.getName().contains("server") && this.shouldIncludeTree(projectStructure,bTree)){
|
||||||
|
rVal.add(bTree.getTargetFile().getQualifiedPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldOverwrite() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this tree should be included in the synchronization manager
|
||||||
|
* @param serverTree The server behavior tree
|
||||||
|
* @return true if should be included, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean shouldIncludeTree(ProjectStructure projectStructure, BehaviorTree serverTree){
|
||||||
|
BehaviorTree clientEquivalent = projectStructure.getTree(serverTree.getCorrespondingTreeName());
|
||||||
|
for(String annotation : clientEquivalent.getAnnotations()){
|
||||||
|
if(annotation.contains("genStartInt")){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@ public void interrupt(){
|
|||||||
Globals.clientConnection.queueOutgoingMessage(
|
Globals.clientConnection.queueOutgoingMessage(
|
||||||
SynchronizationMessage.constructClientRequestBTreeActionMessage(
|
SynchronizationMessage.constructClientRequestBTreeActionMessage(
|
||||||
Globals.clientSceneWrapper.mapClientToServerId(parent.getId()),
|
Globals.clientSceneWrapper.mapClientToServerId(parent.getId()),
|
||||||
BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID,
|
BehaviorTreeIdEnums.REPLACE_0_ME,
|
||||||
ServerSynchronizationManager.SERVER_SYNC_INTERRUPT
|
ServerSynchronizationManager.SERVER_SYNC_INTERRUPT
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ public void start(){
|
|||||||
Globals.clientConnection.queueOutgoingMessage(
|
Globals.clientConnection.queueOutgoingMessage(
|
||||||
SynchronizationMessage.constructClientRequestBTreeActionMessage(
|
SynchronizationMessage.constructClientRequestBTreeActionMessage(
|
||||||
Globals.clientSceneWrapper.mapClientToServerId(parent.getId()),
|
Globals.clientSceneWrapper.mapClientToServerId(parent.getId()),
|
||||||
BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID,
|
BehaviorTreeIdEnums.REPLACE_0_ME,
|
||||||
ServerSynchronizationManager.SERVER_SYNC_START
|
ServerSynchronizationManager.SERVER_SYNC_START
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
14
src/main/resources/server/UpdateEntityState.java
Normal file
14
src/main/resources/server/UpdateEntityState.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* <p> Automatically generated </p>
|
||||||
|
* <p>
|
||||||
|
* Performs actions requested by the client
|
||||||
|
* </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){
|
||||||
|
REPLACE_0_ME
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user