diff --git a/casestodesignfor b/casestodesignfor index 730dfcb..c97c204 100644 --- a/casestodesignfor +++ b/casestodesignfor @@ -1,11 +1,10 @@ Spawn a tree -Lets say there's a concept of macros within the networking framework -You call the spawn foliage function specifying the type of tree -the spawn foliage function manually calls the server side macro to create a tree +Server calls function to spawn entity, passes in identifier for tree type +spawn entity function creates server packets to spawn entity on client(s) This macro sends a packet to all clients in the chunk to create this tree entity -Each client creates the tree with the client equivalent of the create tree function +Each client creates the tree with the client equivalent of the create entity function Player joins a chunk that has a tree that is on fire The macro is called to spawn a tree, just for that player (how do we tell to call macro for this entity and not generic spawn entity function?) @@ -23,4 +22,20 @@ the delete entity function server side sends a special packet to client that tri A player joins a chunk with a player entity in it The server sends a packet to create a new human The server sends the human template packet for that entity ID -The server iterates over every synchronized behavior tree and sends the status of each variable that is synchronized within that tree \ No newline at end of file +The server iterates over every synchronized behavior tree and sends the status of each variable that is synchronized within that tree + +Writing on a sign in game + + +Buying an item from a store while another player is also interacting with that store + + +A chat log +A character playing an instrument +Creating a particle +Playing a sound +Creating an effect generally (ie fire) +Creating a speech bubble over a character +Playing an animation +Writing a book on the client side +Fetching book contents from server(lazy load?) \ No newline at end of file diff --git a/spawningnotes.md b/spawningnotes.md new file mode 100644 index 0000000..3efffd6 --- /dev/null +++ b/spawningnotes.md @@ -0,0 +1,11 @@ +~~want to define categories of entities (creature, particle, effect, sound, etc)~~ +^^ why? +categories would make sense within a class based architecture because oop, but we have an ECS +instead, having preset entity templates (think human template, oak template, elf template, etc) defined in json that all go into the same entity spawning pipeline +this allows more thorough testing of main things (setting model, adding hp, etc), and more unique combinations of things (item that can walk around) + + +lets say in initial handshake with server, after agreeing with client which mods it needs to have loaded, + client runs through those mods entity lists and composes a list of all entity files and iterates through them + each entity template it hits is given an integer id that is used for creation packets +now, when server spawns an entity it sends that integer id that was automatically generated to the client to spawn it in diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index 5b89536..222bbb4 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -11,7 +11,6 @@ import java.util.Map; import org.jboss.forge.roaster.Roaster; import org.jboss.forge.roaster.model.source.JavaClassSource; -import electrosphere.main.codegen.CodeGen; import electrosphere.main.structure.ProjectStructure; import electrosphere.main.targets.TargetFile; @@ -20,11 +19,8 @@ import electrosphere.main.targets.TargetFile; */ public class Main { - static String topLevelFolderPath = "C:\\Users\\satellite\\Documents\\Renderer\\src\\main\\java\\electrosphere"; - - static String[] targetFiles = new String[]{ - "C:\\Users\\satellite\\Documents\\Renderer\\src\\main\\java\\electrosphere\\entity\\state\\idle\\IdleTree.java", - }; + 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 int bTreeIterator = 0; @@ -32,7 +28,7 @@ public class Main { public static Map bTreeIdMap = new HashMap(); public static void main(String args[]){ - List targets = getFilesToModify(topLevelFolderPath); + List targets = getFilesToModify(topLevelFolderPathMac); ProjectStructure structure = new ProjectStructure(targets); structure.parseRichStructure(); structure.generate(); diff --git a/src/main/java/electrosphere/main/structure/BehaviorTree.java b/src/main/java/electrosphere/main/structure/BehaviorTree.java index 62a0163..fa7a7d1 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.Utilities; /** * Represents a behavior tree in the source code @@ -70,5 +71,37 @@ public class BehaviorTree { public TargetFile getTargetFile(){ return targetFile; } + + /* + * The attach methods are for server side to enforce packets being sent to client to properly attach/detatch every time + */ + public String getAttachMethodName(){ + String rVal = ""; + rVal = "attach" + Utilities.camelCase(name); + return rVal; + } + + public String getAttachMethodContent(){ + String rVal = ""; + return rVal; + } + + public String getDetachMethodName(){ + String rVal = ""; + rVal = "detach" + Utilities.camelCase(name); + return rVal; + } + + public String getDetachMethodContent(){ + String rVal = ""; + return rVal; + } + + + + + + + } diff --git a/src/main/java/electrosphere/main/structure/EntityValueTrackingService.java b/src/main/java/electrosphere/main/structure/EntityValueTrackingService.java new file mode 100644 index 0000000..16336fc --- /dev/null +++ b/src/main/java/electrosphere/main/structure/EntityValueTrackingService.java @@ -0,0 +1,9 @@ +package electrosphere.main.structure; + +/** + * This should represent a service placed in project source folder that tracks which trees are attached to which entities and which values they have + * This service is principally used for when a player joins a chunk that has already been loaded and we need to know what to send to the new player + */ +public class EntityValueTrackingService { + +} diff --git a/src/main/java/electrosphere/main/structure/ProjectStructure.java b/src/main/java/electrosphere/main/structure/ProjectStructure.java index 842913f..b3e154e 100644 --- a/src/main/java/electrosphere/main/structure/ProjectStructure.java +++ b/src/main/java/electrosphere/main/structure/ProjectStructure.java @@ -9,7 +9,6 @@ import org.jboss.forge.roaster.model.source.FieldSource; import org.jboss.forge.roaster.model.source.JavaClassSource; import org.jboss.forge.roaster.model.source.JavaEnumSource; import org.jboss.forge.roaster.model.source.JavaSource; -import org.jboss.forge.roaster.model.source.MethodSource; import electrosphere.main.targets.TargetFile; import electrosphere.main.util.ClassSourceUtils; @@ -102,8 +101,11 @@ public class ProjectStructure { for(BehaviorTree tree : behaviorTrees){ 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, tree.getAttachMethodName(), tree.getAttachMethodContent()); + ClassSourceUtils.addOrReplaceMethod(this, tree, tree.getDetachMethodName(), tree.getDetachMethodContent()); } } } diff --git a/src/main/java/electrosphere/main/structure/SynchronizedField.java b/src/main/java/electrosphere/main/structure/SynchronizedField.java index b218209..ab8e3bc 100644 --- a/src/main/java/electrosphere/main/structure/SynchronizedField.java +++ b/src/main/java/electrosphere/main/structure/SynchronizedField.java @@ -33,6 +33,17 @@ public class SynchronizedField { this.targetFile = targetFile; } + public String getGetterName(){ + String rVal = ""; + rVal = "get" + Utilities.camelCase(fieldName); + return rVal; + } + + public String getServerGetterContent(){ + String rVal = ""; + return rVal; + } + public String getSetterName(){ String rVal = ""; rVal = "set" + Utilities.camelCase(fieldName); diff --git a/src/main/java/electrosphere/main/structure/TranslatorService.java b/src/main/java/electrosphere/main/structure/TranslatorService.java new file mode 100644 index 0000000..cc4273e --- /dev/null +++ b/src/main/java/electrosphere/main/structure/TranslatorService.java @@ -0,0 +1,8 @@ +package electrosphere.main.structure; + +/** + * This should represent a file placed in project source that translates enums to ints and vice-versa + */ +public class TranslatorService { + +} diff --git a/src/main/java/electrosphere/main/util/ClassSourceUtils.java b/src/main/java/electrosphere/main/util/ClassSourceUtils.java index 61896be..59fefd8 100644 --- a/src/main/java/electrosphere/main/util/ClassSourceUtils.java +++ b/src/main/java/electrosphere/main/util/ClassSourceUtils.java @@ -1,11 +1,12 @@ package electrosphere.main.util; +import java.io.File; + import org.jboss.forge.roaster.model.source.JavaClassSource; import org.jboss.forge.roaster.model.source.MethodSource; import electrosphere.main.structure.BehaviorTree; import electrosphere.main.structure.ProjectStructure; -import electrosphere.main.targets.TargetFile; /** * Utilities for modifying the source code of a class @@ -27,10 +28,43 @@ public class ClassSourceUtils { if(methodSource == null){ } else { - ClassSourceUtils.addOrReplaceMethod(this, tree, field.getSetterName(), field.getServerSetterContent()); - System.out.println(new StringBuilder(tree.targetFile.getModifiedContent()).insert(setterMethod.getStartPosition(), "asdf").toString()); + 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()); } } + /** + * Generates the first part of a class declaration file + * @param name The name 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"; + rVal = rVal + (isPublic ? "public " : ""); + rVal = rVal + "class " + name + " {\n"; + return rVal; + } + + + /** + * When passed in a file object, returns the package declaration that would be used in code to import that source file + * @param fileObj The raw java file object + * @return The package declaration + */ + public static String getPackageSourcePath(File fileObj){ + String rVal = ""; + throw new UnsupportedOperationException(); + } + + /** + * Generates the footer of a class declaration file + * @return The string containing the class footer + */ + public static String generateClassEnd(){ + return "}\n"; + } + } diff --git a/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java b/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java new file mode 100644 index 0000000..8b43ed7 --- /dev/null +++ b/src/main/java/electrosphere/main/util/TemplateInjectionUtils.java @@ -0,0 +1,29 @@ +package electrosphere.main.util; + +import java.util.Arrays; +import java.util.List; + +/** + * Tools for taking files that represent source file fragments and injecting strings to replace portions of the fragment + */ +public class TemplateInjectionUtils { + + /** + * Loads a fragment from a source file and replaces all strings with provided ones + * @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 = ""; + List replaceStringList = Arrays.asList(replaceStrings); + int iterator = 0; + for(String replaceString : replaceStringList){ + rVal = rVal.replace(iterator + "REPLACE_ME", replaceString); + iterator++; + } + return rVal; + } + + +}