server apply collection state work
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
a68e8fc087
commit
d2a26dd3fa
@ -1,7 +1,8 @@
|
|||||||
package electrosphere.main.core.transport;
|
package electrosphere.main.core.transport;
|
||||||
|
|
||||||
import electrosphere.main.core.transport.methods.ApplyStateCollection;
|
import electrosphere.main.core.transport.methods.ClientApplyStateCollection;
|
||||||
import electrosphere.main.core.transport.methods.GetStateCollection;
|
import electrosphere.main.core.transport.methods.GetStateCollection;
|
||||||
|
import electrosphere.main.core.transport.methods.ServerApplyStateCollection;
|
||||||
import electrosphere.main.source.VirtualClass;
|
import electrosphere.main.source.VirtualClass;
|
||||||
import electrosphere.main.targets.TargetFile;
|
import electrosphere.main.targets.TargetFile;
|
||||||
|
|
||||||
@ -31,7 +32,8 @@ public class StateCollection extends VirtualClass {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
this.addMethod(new GetStateCollection());
|
this.addMethod(new GetStateCollection());
|
||||||
this.addMethod(new ApplyStateCollection());
|
this.addMethod(new ClientApplyStateCollection());
|
||||||
|
this.addMethod(new ServerApplyStateCollection());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,11 +11,11 @@ import electrosphere.main.source.VirtualMethod;
|
|||||||
import electrosphere.main.util.TemplateInjectionUtils;
|
import electrosphere.main.util.TemplateInjectionUtils;
|
||||||
import electrosphere.main.util.Utilities;
|
import electrosphere.main.util.Utilities;
|
||||||
|
|
||||||
public class ApplyStateCollection implements VirtualMethod {
|
public class ClientApplyStateCollection implements VirtualMethod {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName(ProjectStructure projectStructure) {
|
public String getName(ProjectStructure projectStructure) {
|
||||||
return "applyStateCollection";
|
return "clientApplyStateCollection";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,7 +46,7 @@ public class ApplyStateCollection implements VirtualMethod {
|
|||||||
updateCases = updateCases + " } break;\n";
|
updateCases = updateCases + " } break;\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/server/ApplyStateCollection.java", updateCases);
|
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/client/ClientApplyStateCollection.java", updateCases);
|
||||||
return fullReplacementText;
|
return fullReplacementText;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -0,0 +1,124 @@
|
|||||||
|
package electrosphere.main.core.transport.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.core.syncfield.SynchronizedField;
|
||||||
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
import electrosphere.main.source.VirtualMethod;
|
||||||
|
import electrosphere.main.util.TemplateInjectionUtils;
|
||||||
|
import electrosphere.main.util.Utilities;
|
||||||
|
|
||||||
|
public class ServerApplyStateCollection implements VirtualMethod {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName(ProjectStructure projectStructure) {
|
||||||
|
return "serverApplyStateCollection";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getContent(ProjectStructure projectStructure) {
|
||||||
|
String updateCases = "";
|
||||||
|
for(BehaviorTree serverTree : projectStructure.getBehaviorTrees()){
|
||||||
|
if(serverTree.isServer() && shouldIncludeTree(projectStructure, serverTree)){
|
||||||
|
String serverTreeName = serverTree.getClassName();
|
||||||
|
BehaviorTree clientEquivalent = projectStructure.getTree(serverTree.getCorrespondingTreeName());
|
||||||
|
updateCases = updateCases + " case BehaviorTreeIdEnums." + BTreeIdEnum.getTreeIdEnum(serverTree) + ": {\n";
|
||||||
|
updateCases = updateCases + " " + serverTreeName + " tree = " + serverTreeName + ".get" + serverTreeName + "(entity);\n";
|
||||||
|
//update each field
|
||||||
|
updateCases = updateCases + " switch(syncedValue.getFieldId()){\n";
|
||||||
|
for(SynchronizedField field : serverTree.getSynchronizedFields()){
|
||||||
|
String fieldIdVariable = "TREE_" + serverTree.getName().toUpperCase() + "_SYNCEDFIELD_" + field.getFieldName().toUpperCase() + "_ID";
|
||||||
|
updateCases = updateCases + " case(FieldIdEnums." + fieldIdVariable + "): {\n";
|
||||||
|
String getFieldValue = "";
|
||||||
|
if(field.isSerialized()){
|
||||||
|
getFieldValue = getFieldValueSerialized(field, getFieldValue);
|
||||||
|
} else {
|
||||||
|
getFieldValue = getFieldValueNonSerialized(field, clientEquivalent, getFieldValue);
|
||||||
|
}
|
||||||
|
updateCases = updateCases + " tree." + field.getSetterName() + "(" + getFieldValue + ");\n";
|
||||||
|
updateCases = updateCases + " } break;\n";
|
||||||
|
}
|
||||||
|
updateCases = updateCases + " }\n";
|
||||||
|
updateCases = updateCases + " } break;\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/server/ServerApplyStateCollection.java", updateCases);
|
||||||
|
return fullReplacementText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the field's value as a serialized string which will itself be serialized
|
||||||
|
* @param field
|
||||||
|
* @param getFieldValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getFieldValueSerialized(SynchronizedField field, String getFieldValue){
|
||||||
|
getFieldValue = "Utilities.deserialize((String)syncedValue.getValue()," + field.getTypeName() + ".class)";
|
||||||
|
return getFieldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the field's value as a number or string directly
|
||||||
|
* @param field
|
||||||
|
* @param getFieldValue
|
||||||
|
* @param clientEquivalent
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getFieldValueNonSerialized(SynchronizedField field, BehaviorTree clientEquivalent, String getFieldValue){
|
||||||
|
switch(field.getTypeName()){
|
||||||
|
case "int": {
|
||||||
|
getFieldValue = "((Double)syncedValue.getValue()).intValue()";
|
||||||
|
} break;
|
||||||
|
case "long": {
|
||||||
|
getFieldValue = "((Double)syncedValue.getValue()).longValue()";
|
||||||
|
} break;
|
||||||
|
case "float": {
|
||||||
|
getFieldValue = "((Double)syncedValue.getValue()).floatValue()";
|
||||||
|
} break;
|
||||||
|
case "double": {
|
||||||
|
getFieldValue = "(double)syncedValue.getValue()";
|
||||||
|
} break;
|
||||||
|
case "String": {
|
||||||
|
getFieldValue = "(String)syncedValue.getValue()";
|
||||||
|
} break;
|
||||||
|
default : {
|
||||||
|
getFieldValue = clientEquivalent.getClassName() + ".get" + Utilities.camelCase(field.getTypeName()) + "ShortAsEnum(((Double)syncedValue.getValue()).shortValue())";
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
return getFieldValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getImports(ProjectStructure projectStructure) {
|
||||||
|
List<String> rVal = new LinkedList<String>();
|
||||||
|
|
||||||
|
//add server trees
|
||||||
|
for(BehaviorTree bTree : projectStructure.getBehaviorTrees()){
|
||||||
|
if(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){
|
||||||
|
return
|
||||||
|
serverTree.getSynchronizedFields() != null &&
|
||||||
|
serverTree.getSynchronizedFields().size() > 0
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
* @param entity The entity
|
* @param entity The entity
|
||||||
* @param collection The state collection
|
* @param collection The state collection
|
||||||
*/
|
*/
|
||||||
public static void applyStateCollection(Entity entity, StateCollection collection){
|
public static void clientApplyStateCollection(Entity entity, StateCollection collection){
|
||||||
for(SynchronizedFieldValue syncedValue : collection.getValues()){
|
for(SynchronizedFieldValue syncedValue : collection.getValues()){
|
||||||
switch(syncedValue.getBehaviorTreeId()){
|
switch(syncedValue.getBehaviorTreeId()){
|
||||||
REPLACE_0_ME
|
REPLACE_0_ME
|
||||||
15
src/main/resources/server/ServerApplyStateCollection.java
Normal file
15
src/main/resources/server/ServerApplyStateCollection.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* <p> Automatically generated </p>
|
||||||
|
* <p>
|
||||||
|
* Applies the state collection to the given entity
|
||||||
|
* </p>
|
||||||
|
* @param entity The entity
|
||||||
|
* @param collection The state collection
|
||||||
|
*/
|
||||||
|
public static void serverApplyStateCollection(Entity entity, StateCollection collection){
|
||||||
|
for(SynchronizedFieldValue syncedValue : collection.getValues()){
|
||||||
|
switch(syncedValue.getBehaviorTreeId()){
|
||||||
|
REPLACE_0_ME
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user