client sync manager update
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good

This commit is contained in:
austin 2024-07-31 16:17:07 -04:00
parent 8e1559c764
commit 6390c0b0c2
7 changed files with 119 additions and 153 deletions

View File

@ -0,0 +1,35 @@
package electrosphere.main.client.syncmanager;
import electrosphere.main.client.syncmanager.methods.UpdateEntityState;
import electrosphere.main.source.VirtualClass;
import electrosphere.main.targets.TargetFile;
/**
* The client synchronization manager class
*/
public class ClientSynchronizationManager extends VirtualClass {
//The target file for the current version of this class
TargetFile file;
/**
* Constructor
*/
public ClientSynchronizationManager(TargetFile file) {
super(
file,
"ClientSynchronizationManager",
true
);
this.file = file;
//
//
// ADD METHODS HERE
//
//
this.addMethod(new UpdateEntityState());
}
}

View File

@ -1,48 +1,32 @@
package electrosphere.main.client; package electrosphere.main.client.syncmanager.methods;
import java.util.List;
import electrosphere.main.core.btree.BehaviorTree; import electrosphere.main.core.btree.BehaviorTree;
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum; import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.core.syncfield.SynchronizedField;
import electrosphere.main.core.syncfield.SynchronizedType; import electrosphere.main.core.syncfield.SynchronizedType;
import electrosphere.main.project.ProjectStructure; import electrosphere.main.project.ProjectStructure;
import electrosphere.main.source.VirtualClass; import electrosphere.main.source.VirtualMethod;
import electrosphere.main.targets.TargetFile;
import electrosphere.main.util.ClassSourceUtils;
import electrosphere.main.util.TemplateInjectionUtils; import electrosphere.main.util.TemplateInjectionUtils;
/** /**
* The client synchronization manager class * Updates individual entity tree states
*/ */
public class ClientSynchronizationManager extends VirtualClass { public class UpdateEntityState implements VirtualMethod {
@Override
//The target file for the current version of this class public String getName(ProjectStructure projectStructure) {
TargetFile file; return "updateEntityState";
/**
* Constructor
*/
public ClientSynchronizationManager(TargetFile file) {
super(
file,
"ClientSynchronizationManager",
true
);
this.file = file;
} }
/**
* Updates the ClientSynchronizationManager with latest data in specific functions
* @param structure The project texture
*/
@Override @Override
public void updateFile(ProjectStructure structure){ public String getContent(ProjectStructure projectStructure) {
String updateCases = ""; String updateCases = "";
for(BehaviorTree serverTree : structure.getBehaviorTrees()){ for(BehaviorTree serverTree : projectStructure.getBehaviorTrees()){
//counterintuitively, want to only update client for server behavior tree ids //counterintuitively, want to only update client for server behavior tree ids
if(serverTree.isServer()){ if(serverTree.isServer()){
BehaviorTree clientEquivalent = structure.getTree(serverTree.getCorrespondingTreeName()); BehaviorTree clientEquivalent = projectStructure.getTree(serverTree.getCorrespondingTreeName());
updateCases = updateCases + " case BehaviorTreeIdEnums." + BTreeIdEnum.getTreeIdEnum(serverTree) + ": {\n"; updateCases = updateCases + " case BehaviorTreeIdEnums." + BTreeIdEnum.getTreeIdEnum(serverTree) + ": {\n";
updateCases = updateCases + " switch(message.getfieldId()){\n"; updateCases = updateCases + " switch(message.getfieldId()){\n";
for(SynchronizedField field : serverTree.getSynchronizedFields()){ for(SynchronizedField field : serverTree.getSynchronizedFields()){
@ -80,7 +64,7 @@ public class ClientSynchronizationManager extends VirtualClass {
updateCases = updateCases + " } break;\n"; updateCases = updateCases + " } break;\n";
} break; } break;
default: { default: {
SynchronizedType type = structure.getType(field.getTypeName()); SynchronizedType type = projectStructure.getType(field.getTypeName());
String typeClass = type.getTargetFile().getSource().getName(); String typeClass = type.getTargetFile().getSource().getName();
updateCases = updateCases + " case FieldIdEnums." + fieldIdVariable + ":{\n"; updateCases = updateCases + " case FieldIdEnums." + fieldIdVariable + ":{\n";
updateCases = updateCases + " " + treeName + " tree = " + treeName + ".get" + treeName + "(entity);\n"; updateCases = updateCases + " " + treeName + " tree = " + treeName + ".get" + treeName + "(entity);\n";
@ -92,13 +76,23 @@ public class ClientSynchronizationManager extends VirtualClass {
updateCases = updateCases + " }\n"; updateCases = updateCases + " }\n";
updateCases = updateCases + " } break;\n"; updateCases = updateCases + " } break;\n";
//guarantee import // //guarantee import
// ClassSourceUtils.importClass(structure, clientSynchronizationManager, serverTree.getTargetFile().getQualifiedPath()); // ClassSourceUtils.importClass(structure, this.file, structure.getTree(serverTree.getCorrespondingTreeName()).getTargetFile().getQualifiedPath());
ClassSourceUtils.importClass(structure, this.file, structure.getTree(serverTree.getCorrespondingTreeName()).getTargetFile().getQualifiedPath());
} }
} }
ClassSourceUtils.importClass(structure, this.file, "electrosphere.net.synchronization.FieldIdEnums");
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/client/UpdateEntityState.java", updateCases); String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/client/UpdateEntityState.java", updateCases);
ClassSourceUtils.addOrReplaceMethod(structure, this.file, "updateEntityState", fullReplacementText); return fullReplacementText;
} }
@Override
public List<String> getImports(ProjectStructure projectStructure) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
}
@Override
public boolean shouldOverwrite() {
return true;
}
} }

View File

@ -3,7 +3,7 @@ package electrosphere.main.core;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import electrosphere.main.client.ClientSynchronizationManager; 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;

View File

@ -6,7 +6,6 @@ import java.util.List;
import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.core.syncfield.SynchronizedField;
import electrosphere.main.source.VirtualClass; import electrosphere.main.source.VirtualClass;
import electrosphere.main.targets.TargetFile; import electrosphere.main.targets.TargetFile;
import electrosphere.main.util.TemplateInjectionUtils;
/** /**
* Represents a behavior tree in the source code * Represents a behavior tree in the source code
@ -151,15 +150,6 @@ public class BehaviorTree extends VirtualClass {
return rVal; return rVal;
} }
/**
* Gets the content for the fetch method
* @return The content
*/
public String getEntityFetchMethodContent(){
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/EntityFetchMethod.java", this.className, "TREE_" + this.name.toUpperCase());
return rVal;
}
/** /**
* Gets the constructor method's name * Gets the constructor method's name
* @return The constructor method's name * @return The constructor method's name
@ -169,15 +159,6 @@ public class BehaviorTree extends VirtualClass {
return rVal; return rVal;
} }
/**
* Gets the constructor method's content
* @return The content
*/
public String getConstructorMethodContent(){
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/Constructor.java", this.className);
return rVal;
}

View File

@ -3,7 +3,6 @@ package electrosphere.main.core.syncfield;
import java.util.List; import java.util.List;
import electrosphere.main.targets.TargetFile; import electrosphere.main.targets.TargetFile;
import electrosphere.main.util.TemplateInjectionUtils;
import electrosphere.main.util.Utilities; import electrosphere.main.util.Utilities;
/** /**
@ -58,25 +57,6 @@ public class SynchronizedType {
return "get" + Utilities.camelCase(name) + "EnumAsShort"; 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 * Gets the name of the function that converts this synchronized type FROM a short
* @return The name * @return The name
@ -85,28 +65,6 @@ public class SynchronizedType {
return "get" + Utilities.camelCase(name) + "ShortAsEnum"; 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 * Gets the name of the class containing the declaration of this type
* @return * @return

View File

@ -4,14 +4,12 @@ import java.io.File;
import java.util.List; import java.util.List;
import electrosphere.main.Main;
import electrosphere.main.core.VirtualProject; import electrosphere.main.core.VirtualProject;
import electrosphere.main.core.btree.BehaviorTree; import electrosphere.main.core.btree.BehaviorTree;
import electrosphere.main.core.syncfield.SynchronizedField; import electrosphere.main.core.syncfield.SynchronizedField;
import electrosphere.main.core.syncfield.SynchronizedType; import electrosphere.main.core.syncfield.SynchronizedType;
import electrosphere.main.project.parsers.MainParser; import electrosphere.main.project.parsers.MainParser;
import electrosphere.main.targets.TargetFile; import electrosphere.main.targets.TargetFile;
import electrosphere.main.util.ClassSourceUtils;
/** /**
* Container for overall structure of the project * Container for overall structure of the project
@ -59,69 +57,69 @@ public class ProjectStructure {
public void generate(){ public void generate(){
this.virtualProject.generate(this); this.virtualProject.generate(this);
//generate in-class functions for btrees //generate in-class functions for btrees
for(BehaviorTree tree : this.getBehaviorTrees()){ // for(BehaviorTree tree : this.getBehaviorTrees()){
if(Main.LOG){ // if(Main.LOG){
System.out.println("Generating for " + tree.getClassName()); // System.out.println("Generating for " + tree.getClassName());
} // }
//server side getter + setter // //server side getter + setter
if(tree.isServer()){ // if(tree.isServer()){
// for(SynchronizedField field : tree.getSynchronizedFields()){ // // for(SynchronizedField field : tree.getSynchronizedFields()){
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent()); // // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent());
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this)); // // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this));
// } // // }
//attach + detatch methods // //attach + detatch methods
// ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent()); // // ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
// ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent()); // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
//imports // //imports
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.parser.net.message.SynchronizationMessage"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.parser.net.message.SynchronizationMessage");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.ServerBehaviorTreeUtils"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.ServerBehaviorTreeUtils");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.FieldIdEnums"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.FieldIdEnums");
} else { // } else {
// for(SynchronizedField field : tree.getSynchronizedFields()){ // // for(SynchronizedField field : tree.getSynchronizedFields()){
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getClientGetterContent()); // // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getClientGetterContent());
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getClientSetterContent(this)); // // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getClientSetterContent(this));
// } // // }
//attach + detatch methods // //attach + detatch methods
// ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent()); // // ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
// ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent()); // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
//imports // //imports
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals"); // for client scene wrapper // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals"); // for client scene wrapper
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree");
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums");
} // }
//private constructor // //private constructor
// ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getConstructorMethodName(), tree.getConstructorMethodContent()); // // ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getConstructorMethodName(), tree.getConstructorMethodContent());
//guarantee entity fetch method // //guarantee entity fetch method
// ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent()); // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent());
//guarantee imports of required files (btree enum, etc) // //guarantee imports of required files (btree enum, etc)
ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this)); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this));
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings"); // // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
}
//generate enums for all synchronized types
// for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){
// ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent());
// ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
// } // }
// this.virtualProject.getBTreeIdEnum().generate(this); // //generate enums for all synchronized types
// this.virtualProject.getFieldIdEnum().generate(this); // // for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){
// //client sync manager // // ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent());
// this.virtualProject.getClientSynchronizationManager().generate(this); // // ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
// // }
// // this.virtualProject.getBTreeIdEnum().generate(this);
// // this.virtualProject.getFieldIdEnum().generate(this);
// // //client sync manager
// // this.virtualProject.getClientSynchronizationManager().generate(this);
} }
/** /**

View File

@ -79,6 +79,7 @@ public abstract class VirtualClass {
* @param structure The project * @param structure The project
*/ */
public void generate(ProjectStructure structure){ public void generate(ProjectStructure structure){
System.out.println("Generating for " + this.CLASSNAME);
if(this.shouldUpdate){ if(this.shouldUpdate){
this.updateFile(structure); this.updateFile(structure);
} else { } else {
@ -92,7 +93,6 @@ public abstract class VirtualClass {
*/ */
public void updateFile(ProjectStructure structure){ public void updateFile(ProjectStructure structure){
for(VirtualMethod method : this.methods){ for(VirtualMethod method : this.methods){
System.out.println("Replace " + method.getName(structure));
if(method.shouldOverwrite()){ if(method.shouldOverwrite()){
ClassSourceUtils.addOrReplaceMethod(structure, this.targetFile, method.getName(structure), method.getContent(structure)); ClassSourceUtils.addOrReplaceMethod(structure, this.targetFile, method.getName(structure), method.getContent(structure));
} else { } else {