From 9f1e5e9ae66bae7cb1f1925cd264a251570f90e6 Mon Sep 17 00:00:00 2001 From: unknown <> Date: Sat, 24 Feb 2024 21:38:05 -0500 Subject: [PATCH] Initial server->client full flow implementation --- .gitignore | 3 +- pom.xml | 27 ++- src/main/java/electrosphere/main/Main.java | 35 +++- .../main/structure/BTreeIdEnum.java | 74 +++++++ .../main/structure/BehaviorTree.java | 41 +++- .../ClientSynchronizationManager.java | 61 ++++++ .../main/structure/ProjectStructure.java | 180 ++++++++++++++---- .../main/structure/SynchronizedField.java | 23 ++- .../main/structure/SynchronizedType.java | 75 ++++++++ .../main/targets/TargetFile.java | 62 +++++- .../main/util/ClassSourceUtils.java | 131 +++++++++++-- .../main/util/TemplateInjectionUtils.java | 25 ++- .../electrosphere/main/util/Utilities.java | 2 +- .../resources/btree/EntityFetchMethod.java | 10 + src/main/resources/client/AttachBTree.java | 20 ++ src/main/resources/client/DetachBTree.java | 11 ++ src/main/resources/client/SetterDouble.java | 1 - src/main/resources/client/SetterEnum.java | 1 - src/main/resources/client/SetterFloat.java | 1 - src/main/resources/client/SetterInt.java | 1 - src/main/resources/client/SetterString.java | 1 - .../resources/client/UpdateEntityState.java | 14 ++ src/main/resources/enum/EnumToShort.java | 15 ++ src/main/resources/enum/ShortToEnum.java | 13 ++ src/main/resources/server/AttachBTree.java | 21 ++ src/main/resources/server/DetachBTree.java | 11 ++ src/main/resources/server/Getter.java | 9 + src/main/resources/server/Setter.java | 12 +- src/main/resources/server/SetterDouble.java | 1 - src/main/resources/server/SetterEnum.java | 1 - src/main/resources/server/SetterFloat.java | 1 - src/main/resources/server/SetterInt.java | 1 - src/main/resources/server/SetterString.java | 1 - walkthroughOfServerToClient.md | 2 +- 34 files changed, 775 insertions(+), 112 deletions(-) create mode 100644 src/main/java/electrosphere/main/structure/BTreeIdEnum.java create mode 100644 src/main/java/electrosphere/main/structure/ClientSynchronizationManager.java create mode 100644 src/main/resources/btree/EntityFetchMethod.java create mode 100644 src/main/resources/client/AttachBTree.java create mode 100644 src/main/resources/client/DetachBTree.java delete mode 100644 src/main/resources/client/SetterDouble.java delete mode 100644 src/main/resources/client/SetterEnum.java delete mode 100644 src/main/resources/client/SetterFloat.java delete mode 100644 src/main/resources/client/SetterInt.java delete mode 100644 src/main/resources/client/SetterString.java create mode 100644 src/main/resources/client/UpdateEntityState.java create mode 100644 src/main/resources/enum/EnumToShort.java create mode 100644 src/main/resources/enum/ShortToEnum.java create mode 100644 src/main/resources/server/AttachBTree.java create mode 100644 src/main/resources/server/DetachBTree.java create mode 100644 src/main/resources/server/Getter.java delete mode 100644 src/main/resources/server/SetterDouble.java delete mode 100644 src/main/resources/server/SetterEnum.java delete mode 100644 src/main/resources/server/SetterFloat.java delete mode 100644 src/main/resources/server/SetterInt.java delete mode 100644 src/main/resources/server/SetterString.java diff --git a/.gitignore b/.gitignore index 77c9be0..fc00ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /.settings /.classpath /.project -/.vscode \ No newline at end of file +/.vscode +/dependency-reduced-pom.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml index d33316e..fb8c169 100644 --- a/pom.xml +++ b/pom.xml @@ -34,25 +34,22 @@ - maven-assembly-plugin - 3.0.0 - - - jar-with-dependencies - - - - electrosphere.main.Main - - - + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 - make-assembly - package + package - single + shade + + + + electrosphere.main.Main + + + diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index 222bbb4..5571efa 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -19,19 +19,25 @@ import electrosphere.main.targets.TargetFile; */ public class Main { - static String topLevelFolderPathWindows = "C:\\Users\\satellite\\Documents\\Renderer\\src\\main\\java\\electrosphere"; - static String topLevelFolderPathMac = "/Users/satellite/p/Renderer/src/main/java/electrosphere"; + public static String topLevelFolderPathWindows = "C:\\Users\\satellite\\Documents\\Renderer"; + static String topLevelFolderPathMac = "/Users/satellite/p/Renderer"; public static int bTreeIterator = 0; + //hard-coded white list files to always parse + static final String[] ALWAYS_PARSED_CLASSES = new String[]{ + "ClientSynchronizationManager" + }; + //maps the btree annotation "name" to an id public static Map bTreeIdMap = new HashMap(); public static void main(String args[]){ - List targets = getFilesToModify(topLevelFolderPathMac); - ProjectStructure structure = new ProjectStructure(targets); + List targets = getFilesToModify(topLevelFolderPathWindows + "/src/main/java/electrosphere"); + ProjectStructure structure = new ProjectStructure(targets, new File(topLevelFolderPathWindows)); structure.parseRichStructure(); structure.generate(); + structure.writeFiles(); } /** @@ -39,7 +45,7 @@ public class Main { * @param content * @return */ - static JavaClassSource parseJavaFile(String content){ + public static JavaClassSource parseJavaFile(String content){ return Roaster.parse(JavaClassSource.class, content); } @@ -66,7 +72,10 @@ public class Main { String content = ""; try { content = Files.readString(currentFile.toPath()); - if(content.contains("@SynchronizedBehaviorTree")){ + if( + content.contains("@SynchronizedBehaviorTree") || + isHardCodedAlwaysParse(currentFile.getName()) + ){ //parse JavaClassSource source = parseJavaFile(content); rVal.add(new TargetFile(currentFile.getAbsolutePath(), content, currentFile.getName(), source)); @@ -91,4 +100,18 @@ public class Main { return rVal; } + /** + * Checks if a given file is a hard coded case to parse + * @param fullFileName The full file name + * @return true if should parse, false otherwise + */ + private static boolean isHardCodedAlwaysParse(String fullFileName){ + for(String hardCodedCase : ALWAYS_PARSED_CLASSES){ + if(fullFileName.contains(hardCodedCase)){ + return true; + } + } + return false; + } + } diff --git a/src/main/java/electrosphere/main/structure/BTreeIdEnum.java b/src/main/java/electrosphere/main/structure/BTreeIdEnum.java new file mode 100644 index 0000000..48e94ce --- /dev/null +++ b/src/main/java/electrosphere/main/structure/BTreeIdEnum.java @@ -0,0 +1,74 @@ +package electrosphere.main.structure; + +import java.io.File; +import java.io.IOException; + +import com.google.common.io.Files; + +import electrosphere.main.util.ClassSourceUtils; + +/** + * A class that is a list of every behavior tree and its associated id + */ +public class BTreeIdEnum { + + //The class name of this class + public static final String CLASSNAME = "BehaviorTreeIdEnums"; + + //The location of the file + public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java"; + + /** + * Gets the qualified path for the b tree id enum + * @param structure The project structure + * @return The qualified path + */ + public static String getQualifiedPath(ProjectStructure structure){ + File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); + return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME; + } + + /** + * Gets the import declaration for this class + * @param structure The project structure + * @return The import declaration + */ + public static String getImport(ProjectStructure structure){ + return "import " + getQualifiedPath(structure) + ";"; + } + + /** + * Generates a b tree id enum file + * @param structure The project structure + */ + public static void generate(ProjectStructure structure){ + + String source = ""; + File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile(); + source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile)); + source = source + "\n"; + source = source + ClassSourceUtils.generateClassHeader("BehaviorTreeIdEnums", "List of enums for each automatically synchronized behavior tree.", true); + source = source + "\n"; + for(BehaviorTree tree : structure.behaviorTrees){ + source = source + " public static final int " + getTreeIdEnum(tree) + " = " + tree.id + ";\n"; + } + source = source + "\n"; + source = source + ClassSourceUtils.generateClassEnd(); + try { + Files.write(source.getBytes(), outFile); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /** + * Gets the enum name for this behavior tree + * @param tree the tree + * @return the name + */ + public static String getTreeIdEnum(BehaviorTree tree){ + return "BTREE_" + tree.name.toUpperCase() + "_ID"; + } + +} diff --git a/src/main/java/electrosphere/main/structure/BehaviorTree.java b/src/main/java/electrosphere/main/structure/BehaviorTree.java index fa7a7d1..d4d4d82 100644 --- a/src/main/java/electrosphere/main/structure/BehaviorTree.java +++ b/src/main/java/electrosphere/main/structure/BehaviorTree.java @@ -3,6 +3,7 @@ package electrosphere.main.structure; import java.util.List; import electrosphere.main.targets.TargetFile; +import electrosphere.main.util.TemplateInjectionUtils; import electrosphere.main.util.Utilities; /** @@ -16,6 +17,9 @@ public class BehaviorTree { //The name of this tree String name; + //the name of the class containing this tree + String className; + //The name of the tree corresponding to this one String correspondingTreeName; @@ -32,6 +36,7 @@ public class BehaviorTree { * Constructor * @param id * @param name + * @param className * @param correspondingTreeName * @param isServer * @param synchronizedFields @@ -39,6 +44,7 @@ public class BehaviorTree { public BehaviorTree( int id, String name, + String className, String correspondingTreeName, boolean isServer, List synchronizedFields, @@ -46,6 +52,7 @@ public class BehaviorTree { ){ this.id = id; this.name = name; + this.className = className; this.correspondingTreeName = correspondingTreeName; this.isServer = isServer; this.synchronizedFields = synchronizedFields; @@ -56,6 +63,10 @@ public class BehaviorTree { return name; } + public String getClassName(){ + return className; + } + public String getCorrespondingTreeName(){ return correspondingTreeName; } @@ -77,23 +88,41 @@ public class BehaviorTree { */ public String getAttachMethodName(){ String rVal = ""; - rVal = "attach" + Utilities.camelCase(name); + rVal = "attachTree"; return rVal; } - public String getAttachMethodContent(){ - String rVal = ""; + public String getAttachMethodContent(boolean isServer){ + String templateSource = "/server/AttachBTree.java"; + if(!isServer){ + templateSource = "/client/AttachBTree.java"; + } + String rVal = TemplateInjectionUtils.getFragmentWithReplacement(templateSource, this.name.toUpperCase(), "TREE_" + this.name.toUpperCase(), className); return rVal; } public String getDetachMethodName(){ String rVal = ""; - rVal = "detach" + Utilities.camelCase(name); + rVal = "detachTree"; return rVal; } - public String getDetachMethodContent(){ - String rVal = ""; + public String getDetachMethodContent(boolean isServer){ + String templateSource = "/server/DetachBTree.java"; + if(!isServer){ + templateSource = "/client/DetachBTree.java"; + } + String rVal = TemplateInjectionUtils.getFragmentWithReplacement(templateSource, this.name.toUpperCase()); + return rVal; + } + + public String getEntityFetchMethodName(){ + String rVal = "get" + className; + return rVal; + } + + public String getEntityFetchMethodContent(){ + String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/EntityFetchMethod.java", this.className, "TREE_" + this.name.toUpperCase()); return rVal; } diff --git a/src/main/java/electrosphere/main/structure/ClientSynchronizationManager.java b/src/main/java/electrosphere/main/structure/ClientSynchronizationManager.java new file mode 100644 index 0000000..f1f9b81 --- /dev/null +++ b/src/main/java/electrosphere/main/structure/ClientSynchronizationManager.java @@ -0,0 +1,61 @@ +package electrosphere.main.structure; + +import electrosphere.main.targets.TargetFile; +import electrosphere.main.util.ClassSourceUtils; +import electrosphere.main.util.TemplateInjectionUtils; + +public class ClientSynchronizationManager { + + + //The class name of this class + public static final String CLASSNAME = "ClientSynchronizationManager"; + + //The location of the file + public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java"; + + + /** + * Updates the ClientSynchronizationManager with latest data in specific functions + * @param structure + * @param clientSynchronizationManager + */ + public static void update(ProjectStructure structure, TargetFile clientSynchronizationManager){ + String updateCases = ""; + for(BehaviorTree tree : structure.behaviorTrees){ + //counterintuitively, want to only update client for server behavior tree ids + if(tree.isServer()){ + BehaviorTree clientEquivalent = structure.getTree(tree.correspondingTreeName); + updateCases = updateCases + " case BehaviorTreeIdEnums." + BTreeIdEnum.getTreeIdEnum(tree) + ": {\n"; + updateCases = updateCases + " switch(message.getfieldId()){\n"; + for(SynchronizedField field : tree.synchronizedFields){ + String treeName = clientEquivalent.getClassName(); + switch(field.typeName){ + case "int": + case "long": + case "float": + case "double": + case "String": + { + throw new UnsupportedOperationException("Trying to parse type that is not supported yet"); + } + default: { + SynchronizedType type = structure.getType(field.typeName); + String typeClass = type.getTargetFile().getSource().getName(); + updateCases = updateCases + " case " + field.id + ":{\n"; + updateCases = updateCases + " " + treeName + " tree = " + treeName + ".get" + treeName + "(entity);\n"; + updateCases = updateCases + " tree." + field.getSetterName() + "(" + typeClass + "." + type.getFromShortConversionMethodName() + "((short)message.getbTreeValue()));\n"; + updateCases = updateCases + " } break;\n"; + } break; + } + } + updateCases = updateCases + " }\n"; + updateCases = updateCases + " } break;\n"; + + //guarantee import + ClassSourceUtils.importClass(structure, clientSynchronizationManager, tree.getTargetFile().getQualifiedPath()); + } + } + String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/client/UpdateEntityState.java", updateCases); + ClassSourceUtils.addOrReplaceMethod(structure, clientSynchronizationManager, "updateEntityState", fullReplacementText); + } +} diff --git a/src/main/java/electrosphere/main/structure/ProjectStructure.java b/src/main/java/electrosphere/main/structure/ProjectStructure.java index b3e154e..c7e4dc2 100644 --- a/src/main/java/electrosphere/main/structure/ProjectStructure.java +++ b/src/main/java/electrosphere/main/structure/ProjectStructure.java @@ -1,5 +1,6 @@ package electrosphere.main.structure; +import java.io.File; import java.util.LinkedList; import java.util.List; @@ -17,6 +18,9 @@ import electrosphere.main.util.ClassSourceUtils; * Container for overall structure of the project */ public class ProjectStructure { + + //The root folder of the project + File rootFolder; //The list of files to parse @@ -31,12 +35,17 @@ public class ProjectStructure { //All types (enums) that can be synchronized List synchronizedTypes = new LinkedList(); + //the client synchronization manager + TargetFile clientSynchronizationManager; + /** * Constructor * @param targetFiles The target files to iterate on + * @param rootFolder The root folder of the project */ - public ProjectStructure(List targetFiles){ + public ProjectStructure(List targetFiles, File rootFolder){ this.targetFiles = targetFiles; + this.rootFolder = rootFolder; } @@ -50,45 +59,69 @@ public class ProjectStructure { for(TargetFile target : targetFiles){ AnnotationSource mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree"); - String bTreeName = mainAnnotation.getStringValue("name"); - String bTreeCorrespondingName = mainAnnotation.getStringValue("correspondingTree"); - boolean isServer = Boolean.parseBoolean(mainAnnotation.getStringValue("isServer")); + //parse btrees + if(mainAnnotation != null){ + String bTreeName = mainAnnotation.getStringValue("name"); + String bTreeCorrespondingName = mainAnnotation.getStringValue("correspondingTree"); + boolean isServer = Boolean.parseBoolean(mainAnnotation.getStringValue("isServer")); - //parse sync'd fields - List syncedFields = new LinkedList(); - for(FieldSource fieldSource : target.getSource().getFields()){ - AnnotationSource syncAnnotation = fieldSource.getAnnotation("SyncedField"); - if(syncAnnotation != null){ - String fieldName = fieldSource.getName(); - String typeName = fieldSource.getType().getName(); - SynchronizedField field = new SynchronizedField(synchronizedFieldIterator,fieldName,typeName,target); - this.synchronizedFields.add(field); - syncedFields.add(field); - synchronizedFieldIterator++; - } - } - - //parse sync'd enum types - for(JavaSource fieldSource : target.getSource().getNestedTypes()){ - if(fieldSource instanceof JavaEnumSource){ - JavaEnumSource enumSource = (JavaEnumSource)fieldSource; - AnnotationSource annotation = enumSource.getAnnotation("SynchronizableEnum"); - if(annotation != null){ - List values = new LinkedList(); - for(EnumConstantSource constants: enumSource.getEnumConstants()){ - values.add(constants.getName()); - } - SynchronizedType type = new SynchronizedType(typeIterator, enumSource.getName(), values,target); - synchronizedTypes.add(type); - typeIterator++; + //parse sync'd fields + List syncedFields = new LinkedList(); + for(FieldSource fieldSource : target.getSource().getFields()){ + AnnotationSource syncAnnotation = fieldSource.getAnnotation("SyncedField"); + if(syncAnnotation != null){ + String fieldName = fieldSource.getName(); + String typeName = fieldSource.getType().getName(); + SynchronizedField field = new SynchronizedField(synchronizedFieldIterator,fieldName,typeName,target); + this.synchronizedFields.add(field); + syncedFields.add(field); + synchronizedFieldIterator++; } } - } - BehaviorTree newBehaviorTree = new BehaviorTree(behaviorTreeIdIterator,bTreeName,bTreeCorrespondingName,isServer,syncedFields,target); - behaviorTrees.add(newBehaviorTree); - behaviorTreeIdIterator++; + //parse sync'd enum types + for(JavaSource fieldSource : target.getSource().getNestedTypes()){ + if(fieldSource instanceof JavaEnumSource){ + JavaEnumSource enumSource = (JavaEnumSource)fieldSource; + AnnotationSource annotation = enumSource.getAnnotation("SynchronizableEnum"); + if(annotation != null){ + List values = new LinkedList(); + for(EnumConstantSource constants: enumSource.getEnumConstants()){ + values.add(constants.getName()); + } + SynchronizedType type = new SynchronizedType(typeIterator, enumSource.getName(), values,target); + synchronizedTypes.add(type); + typeIterator++; + } + } + } + + BehaviorTree newBehaviorTree = new BehaviorTree( + behaviorTreeIdIterator, + bTreeName, + target.getSource().getName(), + bTreeCorrespondingName, + isServer, + syncedFields, + target + ); + behaviorTrees.add(newBehaviorTree); + behaviorTreeIdIterator++; + + //push behavior tree to each field + for(SynchronizedField field : syncedFields){ + field.setParent(newBehaviorTree); + } + } + + // + //specific cases + + //client synchronization manager + if(target.getName().contains("ClientSynchronizationManager")){ + this.clientSynchronizationManager = target; + } } } @@ -99,15 +132,84 @@ public class ProjectStructure { public void generate(){ //generate in-class functions for btrees for(BehaviorTree tree : behaviorTrees){ + //server side getter + setter if(tree.isServer){ for(SynchronizedField field : tree.synchronizedFields){ - ClassSourceUtils.addOrReplaceMethod(this, tree, field.getGetterName(), field.getServerGetterContent()); - ClassSourceUtils.addOrReplaceMethod(this, tree, field.getSetterName(), field.getServerSetterContent()); + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent()); + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this)); + ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils"); + ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.parser.net.message.SynchronizationMessage"); } - ClassSourceUtils.addOrReplaceMethod(this, tree, tree.getAttachMethodName(), tree.getAttachMethodContent()); - ClassSourceUtils.addOrReplaceMethod(this, tree, tree.getDetachMethodName(), tree.getDetachMethodContent()); + //attach + detatch methods + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent(true)); + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent(true)); + } else { + //attach + detatch methods + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent(false)); + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent(false)); + } + //guarantee entity fetch method + ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent()); + //guarantee imports of required files (btree enum, etc) + ClassSourceUtils.importClass(this, tree.getTargetFile(), BTreeIdEnum.getQualifiedPath(this)); + } + //generate enums for all synchronized types + for(SynchronizedType type : synchronizedTypes){ + ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent()); + ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent()); + } + BTreeIdEnum.generate(this); + //client sync manager + ClientSynchronizationManager.update(this, clientSynchronizationManager); + } + + /** + * Writes all files that had content change to disk + */ + public void writeFiles(){ + for(TargetFile file : this.targetFiles){ + if(file.isModified()){ + file.write(); } } } + + + /** + * Gets the root folder as a file object + * @return The root folder + */ + public File getRootFolder(){ + return this.rootFolder; + } + + /** + * Gets a synchronized type from a name + * @param typeName The name of the type + * @return The synchronized type if it exists, null otherwise + */ + public SynchronizedType getType(String typeName){ + for(SynchronizedType type : this.synchronizedTypes){ + if(type.name.equals(typeName)){ + return type; + } + } + return null; + } + + /** + * Gets a behavior tree from its name + * @param typeName The name of the tree + * @return The tree if it exists, null otherwise + */ + public BehaviorTree getTree(String typeName){ + for(BehaviorTree tree : this.behaviorTrees){ + if(tree.name.equals(typeName)){ + return tree; + } + } + return null; + } + } diff --git a/src/main/java/electrosphere/main/structure/SynchronizedField.java b/src/main/java/electrosphere/main/structure/SynchronizedField.java index ab8e3bc..061c21a 100644 --- a/src/main/java/electrosphere/main/structure/SynchronizedField.java +++ b/src/main/java/electrosphere/main/structure/SynchronizedField.java @@ -1,6 +1,7 @@ package electrosphere.main.structure; import electrosphere.main.targets.TargetFile; +import electrosphere.main.util.TemplateInjectionUtils; import electrosphere.main.util.Utilities; /** @@ -20,11 +21,16 @@ public class SynchronizedField { //The file this type appears in TargetFile targetFile; + //The parent behavior tree + BehaviorTree parent; + /** * Constructor * @param id + * @param parent * @param fieldName * @param typeName + * @param targetFile */ public SynchronizedField(int id, String fieldName, String typeName, TargetFile targetFile){ this.id = id; @@ -40,7 +46,7 @@ public class SynchronizedField { } public String getServerGetterContent(){ - String rVal = ""; + String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName); return rVal; } @@ -50,8 +56,19 @@ public class SynchronizedField { return rVal; } - public String getServerSetterContent(){ - String rVal = ""; + /** + * Gets parent tree of this field + * @param tree + */ + public void setParent(BehaviorTree tree){ + this.parent = tree; + } + + public String getServerSetterContent(ProjectStructure structure){ + SynchronizedType type = structure.getType(typeName); + String packetContentFiller = " int value = " + type.getContainingClassName() + "." + type.getToShortConversionMethodName() + "(state);\n"; + packetContentFiller = packetContentFiller + " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), " + parent.id + ", " + id + ", value));"; + String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller); return rVal; } diff --git a/src/main/java/electrosphere/main/structure/SynchronizedType.java b/src/main/java/electrosphere/main/structure/SynchronizedType.java index 06ed6da..a76b4ca 100644 --- a/src/main/java/electrosphere/main/structure/SynchronizedType.java +++ b/src/main/java/electrosphere/main/structure/SynchronizedType.java @@ -3,6 +3,8 @@ package electrosphere.main.structure; import java.util.List; import electrosphere.main.targets.TargetFile; +import electrosphere.main.util.TemplateInjectionUtils; +import electrosphere.main.util.Utilities; /** * An enum type that should have code generated for serializing/deserializing it @@ -40,4 +42,77 @@ public class SynchronizedType { this.targetFile = targetFile; } + /** + * Gets the target file + * @return The target file + */ + public TargetFile getTargetFile(){ + return this.targetFile; + } + + /** + * Gets the name of the function that converts this synchronized type TO a short + * @return The name + */ + public String getToShortConversionMethodName(){ + return "get" + Utilities.camelCase(name) + "EnumAsShort"; + } + + /** + * Gets the content of the function that converts this synchronized type TO a short + * @return The content + */ + public String getToShortConversionMethodContent(){ + //get enum switch array + String enumSwitchArray = ""; + int i = 0; + for(String value : values){ + enumSwitchArray = enumSwitchArray + " case " + value + ":\n"; + enumSwitchArray = enumSwitchArray + " return " + i + ";\n"; + i++; + } + //chop off last newline + enumSwitchArray = enumSwitchArray.substring(0, enumSwitchArray.length() - 1); + String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/enum/EnumToShort.java", this.name, this.name, enumSwitchArray); + return rVal; + } + + /** + * Gets the name of the function that converts this synchronized type FROM a short + * @return The name + */ + public String getFromShortConversionMethodName(){ + return "get" + Utilities.camelCase(name) + "ShortAsEnum"; + } + + /** + * Gets the content of the function that converts this synchronized type TO a short + * @return The content + */ + public String getFromShortConversionMethodContent(){ + //get enum switch array + String enumSwitchArray = ""; + int i = 0; + for(String value : values){ + enumSwitchArray = enumSwitchArray + " case " + i + ":\n"; + enumSwitchArray = enumSwitchArray + " return " + this.name + "." + value + ";\n"; + i++; + } + //add default case + enumSwitchArray = enumSwitchArray + " default:\n"; + enumSwitchArray = enumSwitchArray + " return " + this.name + "." + values.get(0) + ";\n"; + //chop off last newline + enumSwitchArray = enumSwitchArray.substring(0, enumSwitchArray.length() - 1); + String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/enum/ShortToEnum.java", this.name, this.name, enumSwitchArray); + return rVal; + } + + /** + * Gets the name of the class containing the declaration of this type + * @return + */ + public String getContainingClassName(){ + return getTargetFile().getName().substring(0, getTargetFile().getName().length() - 5); + } + } diff --git a/src/main/java/electrosphere/main/targets/TargetFile.java b/src/main/java/electrosphere/main/targets/TargetFile.java index dac0952..82b7b02 100644 --- a/src/main/java/electrosphere/main/targets/TargetFile.java +++ b/src/main/java/electrosphere/main/targets/TargetFile.java @@ -1,7 +1,14 @@ package electrosphere.main.targets; +import java.io.File; +import java.io.IOException; + import org.jboss.forge.roaster.model.source.JavaClassSource; +import com.google.common.io.Files; + +import electrosphere.main.Main; + /** * A file that will have netcode generation performed on it */ @@ -12,12 +19,15 @@ public class TargetFile { //the original content of the file String originalContent; //The content, with any modifications made by the netcode generator - String modifiedContent; + StringBuilder modifiedContent; //the Roaster parsed source for the file JavaClassSource source; //the name of the file String name; + //holds whether the file was edited + boolean modified = false; + /** * Constructor * @param path @@ -28,7 +38,7 @@ public class TargetFile { public TargetFile(String path, String content, String name, JavaClassSource source){ this.path = path; this.originalContent = content; - this.modifiedContent = content; + this.modifiedContent = new StringBuilder(content); this.name = name; this.source = source; } @@ -61,7 +71,7 @@ public class TargetFile { * Gets the modified content of the file * @return The modified content */ - public String getModifiedContent(){ + public StringBuilder getModifiedContent(){ return modifiedContent; } @@ -70,7 +80,51 @@ public class TargetFile { * @param content The new modified content of the file */ public void setModifiedContent(String content){ - this.modifiedContent = content; + this.setModified(true); + this.modifiedContent = new StringBuilder(content); + } + + /** + * Re-parses the modified content + */ + public void reparse(){ + this.source = Main.parseJavaFile(this.modifiedContent.toString()); + } + + /** + * Sets the modified state of the file + * @param modified true if modified, false otherwise + */ + private void setModified(boolean modified){ + this.modified = modified; + } + + /** + * Gets the modified state of the file + * @returntrue if modified, false otherwise + */ + public boolean isModified(){ + return this.modified; + } + + /** + * Writes the modified content of the file to disk + */ + public void write(){ + try { + Files.write(this.modifiedContent.toString().getBytes(), new File(this.path)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Gets the qualified path for this file + * @return The qualified path + */ + public String getQualifiedPath(){ + String rVal = this.source.getQualifiedName(); + return rVal; } } diff --git a/src/main/java/electrosphere/main/util/ClassSourceUtils.java b/src/main/java/electrosphere/main/util/ClassSourceUtils.java index 59fefd8..184a0cb 100644 --- a/src/main/java/electrosphere/main/util/ClassSourceUtils.java +++ b/src/main/java/electrosphere/main/util/ClassSourceUtils.java @@ -1,48 +1,103 @@ package electrosphere.main.util; import java.io.File; +import java.util.List; +import org.jboss.forge.roaster.model.source.Import; import org.jboss.forge.roaster.model.source.JavaClassSource; import org.jboss.forge.roaster.model.source.MethodSource; +import electrosphere.main.structure.BTreeIdEnum; import electrosphere.main.structure.BehaviorTree; import electrosphere.main.structure.ProjectStructure; +import electrosphere.main.targets.TargetFile; /** * Utilities for modifying the source code of a class */ public class ClassSourceUtils { + + //The default indent for a method, field, etc + static final int DEFAULT_INDENT = 4; /** * Adds to replaces a method in a given behavior tree * @param structure The project structure - * @param tree The tree + * @param targetFile The targetFile * @param methodName The name of the method * @param methodContent The content of the method that you want to insert or replace with */ - public static void addOrReplaceMethod(ProjectStructure structure, BehaviorTree tree, String methodName, String methodContent){ - boolean hasMethod; - //search for setter - MethodSource methodSource = tree.getTargetFile().getSource().getMethod(methodName); - if(methodSource == null){ - - } else { - throw new UnsupportedOperationException(); - // ClassSourceUtils.addOrReplaceMethod(this, tree, field.getSetterName(), field.getServerSetterContent()); - // System.out.println(new StringBuilder(tree.targetFile.getModifiedContent()).insert(setterMethod.getStartPosition(), "asdf").toString()); - // System.out.println(setterMethod.getStartPosition()); + public static void addOrReplaceMethod(ProjectStructure structure, TargetFile targetFile, String methodName, String methodContent){ + //search for method + List> methods = targetFile.getSource().getMethods(); + MethodSource methodSource = null; + for(MethodSource methodRaw : methods){ + if(methodRaw.getName().equals(methodName)){ + if(methodSource != null){ + throw new UnknownError("Two methods in a source file have the same name. This is unsupported by the addOrReplaceMethod function at this time!"); + } + methodSource = methodRaw; + } } + StringBuilder modifiedContent = targetFile.getModifiedContent(); + if(methodSource == null){ + int endOfClass = findEndOfClass(modifiedContent.toString()); + String indentedFragment = TemplateInjectionUtils.indentFragment(methodContent, DEFAULT_INDENT); + //must newline + String finalInsertion = indentedFragment + "\n"; + modifiedContent.insert(endOfClass, finalInsertion); + } else { + //methodStart is literally the first character of the function's name + int methodStart = methodSource.getStartPosition(); + int indent = getCurrentIndent(modifiedContent.toString(),methodStart - 1); + int methodEnd = methodSource.getEndPosition(); + String indentedFragment = TemplateInjectionUtils.indentFragment(methodContent, indent).trim(); + modifiedContent.replace(methodStart, methodEnd, indentedFragment); + } + targetFile.setModifiedContent(modifiedContent.toString()); + targetFile.reparse(); + } + + /** + * Finds the end of a class file + * @param sourceRaw The raw source + * @return The index of the final curly brace + */ + private static int findEndOfClass(String sourceRaw){ + int curr = sourceRaw.length() - 1; + while(sourceRaw.charAt(curr) != '}'){ + curr--; + } + return curr; + } + + /** + * Gets the current indent of the source file at a given location + * @param sourceRaw The source file + * @param position The position + * @return The indent + */ + private static int getCurrentIndent(String sourceRaw, int position){ + int indent = 0; + int curr = position; + while(sourceRaw.charAt(curr) != '\n'){ + curr--; + indent++; + } + return indent; } /** * Generates the first part of a class declaration file * @param name The name of the class + * @param description The description of the class * @param isPublic True if public, false otherwise * @return The string containing the class header */ - public static String generateClassHeader(String name, boolean isPublic){ - String rVal = "\t"; + public static String generateClassHeader(String name, String description, boolean isPublic){ + String rVal = "/**\n * " + description + "\n */\n"; + rVal = rVal + ""; rVal = rVal + (isPublic ? "public " : ""); rVal = rVal + "class " + name + " {\n"; return rVal; @@ -54,9 +109,31 @@ public class ClassSourceUtils { * @param fileObj The raw java file object * @return The package declaration */ - public static String getPackageSourcePath(File fileObj){ + public static String getPackageSourcePath(ProjectStructure structure, File fileObj){ String rVal = ""; - throw new UnsupportedOperationException(); + rVal = structure.getRootFolder().toURI().relativize(fileObj.toURI()).getPath(); + //delete past last forwardslash + int lastSlashIndex = rVal.length() - 1; + while(rVal.charAt(lastSlashIndex) != '/'){ + lastSlashIndex--; + } + rVal = rVal.substring(0, lastSlashIndex); + //delete intro part + rVal = rVal.replace("src/main/java/", ""); + rVal = rVal.replace("/","."); + return rVal; + } + + /** + * Gets the package declaration for a given package path + * @param structure The project structure + * @param packagePath The package path + * @return The declaration line + */ + public static String getPackageDeclaration(ProjectStructure structure, String packagePath){ + String rVal = ""; + rVal = "package " + packagePath + ";\n"; + return rVal; } /** @@ -67,4 +144,26 @@ public class ClassSourceUtils { return "}\n"; } + /** + * Guarantees that a given path is imported + * @param structure The project structure + * @param tree The tree + * @param qualifiedPath The qualified name to import + */ + public static void importClass(ProjectStructure structure, TargetFile targetFile, String qualifiedPath){ + StringBuilder modifiedContent = targetFile.getModifiedContent(); + List imports = targetFile.getSource().getImports(); + boolean present = false; + for(Import currentImport : imports){ + String importName = currentImport.getQualifiedName(); + if(importName.equals(qualifiedPath)){ + present = true; + } + } + if(!present){ + Utilities.insertIntoSource(modifiedContent, "import " + qualifiedPath + ";", 3); + targetFile.setModifiedContent(modifiedContent.toString()); + } + } + } diff --git a/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java b/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java index 8b43ed7..24b5578 100644 --- a/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java +++ b/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java @@ -2,6 +2,9 @@ package electrosphere.main.util; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; + +import com.sun.tools.javac.Main; /** * Tools for taking files that represent source file fragments and injecting strings to replace portions of the fragment @@ -9,21 +12,37 @@ import java.util.List; public class TemplateInjectionUtils { /** - * Loads a fragment from a source file and replaces all strings with provided ones + * Loads a fragment from a source file and replaces all strings with provided ones. Used specifically for filling out template files baked into this tool. * @param sourceFile The source file relative path * @param replaceStrings The list of strings to replace * @return The properly updated string */ public static String getFragmentWithReplacement(String sourceFile, String ... replaceStrings){ - String rVal = ""; + String rVal = Utilities.readBakedResourceToString(TemplateInjectionUtils.class.getResourceAsStream(sourceFile)); List replaceStringList = Arrays.asList(replaceStrings); int iterator = 0; for(String replaceString : replaceStringList){ - rVal = rVal.replace(iterator + "REPLACE_ME", replaceString); + rVal = rVal.replace("REPLACE_" + iterator + "_ME", replaceString); iterator++; } return rVal; } + /** + * Indents a fragment based on an indentation amount + * @param fragment The fragment + * @param indentAmount The indentation required (in spaces) + * @return The indented fragment + */ + public static String indentFragment(String fragment, int indentAmount){ + return Arrays.asList(fragment.split("\n")).stream().map((String line) -> { + String indent = ""; + for(int i = 0; i < indentAmount; i++){ + indent = indent + " "; + } + return indent + line; + }).collect(Collectors.joining("\n")); + } + } diff --git a/src/main/java/electrosphere/main/util/Utilities.java b/src/main/java/electrosphere/main/util/Utilities.java index 06eb7c8..bbf4448 100644 --- a/src/main/java/electrosphere/main/util/Utilities.java +++ b/src/main/java/electrosphere/main/util/Utilities.java @@ -96,7 +96,7 @@ public class Utilities { //now move backwards to find the previous line with content on it characterPosition = characterPosition - 1; while(true){ - if(source.charAt(characterPosition)=='\n' && source.charAt(characterPosition + 1)==' '){ + if(source.charAt(characterPosition)=='\n' && source.charAt(characterPosition + 1)!='\n'){ break; } characterPosition--; diff --git a/src/main/resources/btree/EntityFetchMethod.java b/src/main/resources/btree/EntityFetchMethod.java new file mode 100644 index 0000000..a41e7fd --- /dev/null +++ b/src/main/resources/btree/EntityFetchMethod.java @@ -0,0 +1,10 @@ +/** + *

+ * Gets the REPLACE_0_ME of the entity + *

+ * @param entity the entity + * @return The REPLACE_0_ME + */ +public static REPLACE_0_ME getREPLACE_0_ME(Entity entity){ + return (REPLACE_0_ME)entity.getData(EntityDataStrings.REPLACE_1_ME); +} \ No newline at end of file diff --git a/src/main/resources/client/AttachBTree.java b/src/main/resources/client/AttachBTree.java new file mode 100644 index 0000000..029a5dd --- /dev/null +++ b/src/main/resources/client/AttachBTree.java @@ -0,0 +1,20 @@ +/** + *

(initially) Automatically generated

+ *

More parameters can be safely added to this method

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + */ +public static REPLACE_2_ME attachTree(Entity parent){ + REPLACE_2_ME rVal = new REPLACE_2_ME(parent); + //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.REPLACE_1_ME, rVal); + Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_REPLACE_0_ME_ID); + return rVal; +} \ No newline at end of file diff --git a/src/main/resources/client/DetachBTree.java b/src/main/resources/client/DetachBTree.java new file mode 100644 index 0000000..f546705 --- /dev/null +++ b/src/main/resources/client/DetachBTree.java @@ -0,0 +1,11 @@ +/** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @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_REPLACE_0_ME_ID); +} \ No newline at end of file diff --git a/src/main/resources/client/SetterDouble.java b/src/main/resources/client/SetterDouble.java deleted file mode 100644 index 8cddfcd..0000000 --- a/src/main/resources/client/SetterDouble.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyDoubleMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/client/SetterEnum.java b/src/main/resources/client/SetterEnum.java deleted file mode 100644 index bb7dd8c..0000000 --- a/src/main/resources/client/SetterEnum.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyEnumMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, getEnumIntValueREPLACENAMECAMEL(REPLACENAMENOTCAMEL)) \ No newline at end of file diff --git a/src/main/resources/client/SetterFloat.java b/src/main/resources/client/SetterFloat.java deleted file mode 100644 index 1bd80b0..0000000 --- a/src/main/resources/client/SetterFloat.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyFloatMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/client/SetterInt.java b/src/main/resources/client/SetterInt.java deleted file mode 100644 index 94da8b2..0000000 --- a/src/main/resources/client/SetterInt.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyIntMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/client/SetterString.java b/src/main/resources/client/SetterString.java deleted file mode 100644 index bc8ee76..0000000 --- a/src/main/resources/client/SetterString.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyStringMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/client/UpdateEntityState.java b/src/main/resources/client/UpdateEntityState.java new file mode 100644 index 0000000..42eed16 --- /dev/null +++ b/src/main/resources/client/UpdateEntityState.java @@ -0,0 +1,14 @@ +/** + *

Automatically generated

+ *

+ * Updates the state of a given behavior tree on a given entity + *

+ * @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 + } +} \ No newline at end of file diff --git a/src/main/resources/enum/EnumToShort.java b/src/main/resources/enum/EnumToShort.java new file mode 100644 index 0000000..a30408a --- /dev/null +++ b/src/main/resources/enum/EnumToShort.java @@ -0,0 +1,15 @@ +/** + *

Automatically generated

+ *

+ * Converts this enum type to an equivalent short value + *

+ * @param enumVal The enum value + * @return The short value + */ +public static short getREPLACE_0_MEEnumAsShort(REPLACE_1_ME enumVal){ + switch(enumVal){ +REPLACE_2_ME + default: + return 0; + } +} \ No newline at end of file diff --git a/src/main/resources/enum/ShortToEnum.java b/src/main/resources/enum/ShortToEnum.java new file mode 100644 index 0000000..5914261 --- /dev/null +++ b/src/main/resources/enum/ShortToEnum.java @@ -0,0 +1,13 @@ +/** + *

Automatically generated

+ *

+ * Converts a short to the equivalent enum value + *

+ * @param shortVal The short value + * @return The enum value + */ +public static REPLACE_1_ME getREPLACE_0_MEShortAsEnum(short shortVal){ + switch(shortVal){ +REPLACE_2_ME + } +} \ No newline at end of file diff --git a/src/main/resources/server/AttachBTree.java b/src/main/resources/server/AttachBTree.java new file mode 100644 index 0000000..985dc13 --- /dev/null +++ b/src/main/resources/server/AttachBTree.java @@ -0,0 +1,21 @@ +/** + *

(initially) Automatically generated

+ *

More parameters can be safely added to this method

+ *

+ * Attaches this tree to the entity. + *

+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + */ +public static REPLACE_2_ME attachTree(Entity parent){ + REPLACE_2_ME rVal = new REPLACE_2_ME(parent); + //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.REPLACE_1_ME, rVal); + Globals.entityValueTrackingService.attachTreeToEntity(parent, BehaviorTreeIdEnums.BTREE_REPLACE_0_ME_ID); + return rVal; +} \ No newline at end of file diff --git a/src/main/resources/server/DetachBTree.java b/src/main/resources/server/DetachBTree.java new file mode 100644 index 0000000..f546705 --- /dev/null +++ b/src/main/resources/server/DetachBTree.java @@ -0,0 +1,11 @@ +/** + *

Automatically generated

+ *

+ * Detatches this tree from the entity. + *

+ * @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_REPLACE_0_ME_ID); +} \ No newline at end of file diff --git a/src/main/resources/server/Getter.java b/src/main/resources/server/Getter.java new file mode 100644 index 0000000..88214ef --- /dev/null +++ b/src/main/resources/server/Getter.java @@ -0,0 +1,9 @@ +/** + *

Automatically generated

+ *

+ * Gets REPLACE_0_ME. + *

+ */ +public REPLACE_2_ME getREPLACE_1_ME(){ + return REPLACE_0_ME; +} \ No newline at end of file diff --git a/src/main/resources/server/Setter.java b/src/main/resources/server/Setter.java index ef2cf4f..701278e 100644 --- a/src/main/resources/server/Setter.java +++ b/src/main/resources/server/Setter.java @@ -1,13 +1,11 @@ /** *

Automatically generated

*

- * Sets REPLACENAMENOTCAMEL and handles the synchronization logic for it. + * Sets REPLACE_0_ME and handles the synchronization logic for it. *

- * @param REPLACENAMENOTCAMEL The value to set REPLACENAMENOTCAMEL to. + * @param REPLACE_0_ME The value to set REPLACE_0_ME to. */ -public void setREPLACENAMECAMEL(REPLACETYPE REPLACENAMENOTCAMEL){ - this.REPLACENAMENOTCAMEL = REPLACENAMENOTCAMEL; - Globals.entityDataCellMapper.getEntityDataCell(parent).broadcastNetworkMessage( - REPLACEMESSAGECONSTRUCTOR - ); +public void setREPLACE_1_ME(REPLACE_2_ME REPLACE_0_ME){ + this.REPLACE_0_ME = REPLACE_0_ME; +REPLACE_3_ME } \ No newline at end of file diff --git a/src/main/resources/server/SetterDouble.java b/src/main/resources/server/SetterDouble.java deleted file mode 100644 index 8cddfcd..0000000 --- a/src/main/resources/server/SetterDouble.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyDoubleMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/server/SetterEnum.java b/src/main/resources/server/SetterEnum.java deleted file mode 100644 index bb7dd8c..0000000 --- a/src/main/resources/server/SetterEnum.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyEnumMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, getEnumIntValueREPLACENAMECAMEL(REPLACENAMENOTCAMEL)) \ No newline at end of file diff --git a/src/main/resources/server/SetterFloat.java b/src/main/resources/server/SetterFloat.java deleted file mode 100644 index 1bd80b0..0000000 --- a/src/main/resources/server/SetterFloat.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyFloatMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/server/SetterInt.java b/src/main/resources/server/SetterInt.java deleted file mode 100644 index 94da8b2..0000000 --- a/src/main/resources/server/SetterInt.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyIntMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/src/main/resources/server/SetterString.java b/src/main/resources/server/SetterString.java deleted file mode 100644 index bc8ee76..0000000 --- a/src/main/resources/server/SetterString.java +++ /dev/null @@ -1 +0,0 @@ -EntityMessage.constructsetBTreePropertyStringMessage(parent.getId(), Main.getCurrentFrame(), REPLACEBTREEID, REPLACEPROPERTYID, REPLACENAMENOTCAMEL) \ No newline at end of file diff --git a/walkthroughOfServerToClient.md b/walkthroughOfServerToClient.md index d1c984c..a37be45 100644 --- a/walkthroughOfServerToClient.md +++ b/walkthroughOfServerToClient.md @@ -24,7 +24,7 @@ Client receives a behavior tree update packet client sends this packet to a behavior tree synchronization manager -the manager finds the client with the correct id +the manager finds the entity with the correct id it then does a lookup against a table generated by the code gen tool the table points behavior tree id to class