Sync progress

This commit is contained in:
Anuken
2020-05-24 15:38:40 -04:00
parent 7c06ba94c1
commit e16aa5a74a
27 changed files with 139 additions and 44 deletions

View File

@@ -80,9 +80,11 @@ public class Annotations{
boolean isFinal() default true;
/** If true, entities are recycled. */
boolean pooled() default false;
/** Whether to serialize (makes the serialize method return this value) */
/** Whether to serialize (makes the serialize method return this value).
* If true, this entity is automatically put into save files.
* If false, no serialization code is generated at all. */
boolean serialize() default true;
/** Whether to generate IO code */
/** Whether to generate IO code. This is for advanced usage only. */
boolean genio() default true;
}

View File

@@ -133,6 +133,8 @@ public class EntityIO{
io(field.type, "this." + (sf != null ? field.name + targetSuf : field.name) + " = ");
}
st("afterSync()");
}
}
@@ -196,6 +198,8 @@ public class EntityIO{
}
}else if(serializer.writers.containsKey(type) && write){
st("$L(write, $L)", serializer.writers.get(type), field);
}else if(serializer.mutatorReaders.containsKey(type) && !write && !field.replace(" = ", "").contains(" ")){
st("$L$L(read, $L)", field, serializer.mutatorReaders.get(type), field.replace(" = ", ""));
}else if(serializer.readers.containsKey(type) && !write){
st("$L$L(read)", field, serializer.readers.get(type));
}else if(type.endsWith("[]")){ //it's a 1D array

View File

@@ -287,8 +287,9 @@ public class EntityProcess extends BaseProcessor{
.addModifiers(Modifier.PUBLIC)
.addStatement("return $S + $L", name + "#", "id").build());
EntityIO io = ann.serialize() ? new EntityIO(type.name(), builder, serializer, rootDirectory.child("annotations/src/main/resources/revisions").child(name)) : null;
boolean hasIO = ann.genio() && ann.serialize();
EntityIO io = new EntityIO(type.name(), builder, serializer, rootDirectory.child("annotations/src/main/resources/revisions").child(name));
//entities with no sync comp and no serialization gen no code
boolean hasIO = ann.genio() && (components.contains(s -> s.name().contains("Sync")) || ann.serialize());
//add all methods from components
for(ObjectMap.Entry<String, Array<Smethod>> entry : methods){
@@ -347,20 +348,20 @@ public class EntityProcess extends BaseProcessor{
}
}
if(io != null){
if(hasIO){
//SPECIAL CASE: I/O code
//note that serialization is generated even for non-serializing entities for manual usage
if((first.name().equals("read") || first.name().equals("write")) && hasIO){
if((first.name().equals("read") || first.name().equals("write"))){
io.write(mbuilder, first.name().equals("write"));
}
//SPECIAL CASE: sync I/O code
if((first.name().equals("readSync") || first.name().equals("writeSync")) && hasIO){
if((first.name().equals("readSync") || first.name().equals("writeSync"))){
io.writeSync(mbuilder, first.name().equals("writeSync"), syncedFields);
}
//SPECIAL CASE: sync I/O code for writing to/from a manual buffer
if((first.name().equals("readSyncManual") || first.name().equals("writeSyncManual")) && hasIO){
if((first.name().equals("readSyncManual") || first.name().equals("writeSyncManual"))){
io.writeSyncManual(mbuilder, first.name().equals("writeSyncManual"), syncedFields);
}
@@ -369,7 +370,7 @@ public class EntityProcess extends BaseProcessor{
io.writeInterpolate(mbuilder, syncedFields);
}
//snap to target position
//SPECIAL CASE: method to snap to target position after being read for the first time
if(first.name().equals("snapSync")){
mbuilder.addStatement("updateSpacing = 16");
mbuilder.addStatement("lastUpdated = $T.millis()", Time.class);

View File

@@ -16,7 +16,7 @@ public class TypeIOResolver{
* Maps fully qualified class names to their serializers.
*/
public static ClassSerializer resolve(BaseProcessor processor){
ClassSerializer out = new ClassSerializer(new ObjectMap<>(), new ObjectMap<>());
ClassSerializer out = new ClassSerializer(new ObjectMap<>(), new ObjectMap<>(), new ObjectMap<>());
for(Stype type : processor.types(TypeIOHandler.class)){
//look at all TypeIOHandler methods
Array<Smethod> methods = type.methods();
@@ -29,6 +29,9 @@ public class TypeIOResolver{
}else if(params.size == 1 && params.first().tname().toString().equals("arc.util.io.Reads") && !meth.isVoid()){
//1 param, one is reader, returns type
out.readers.put(meth.retn().toString(), type.fullName() + "." + meth.name());
}else if(params.size == 2 && params.first().tname().toString().equals("arc.util.io.Reads") && !meth.isVoid() && meth.ret() == meth.params().get(1).mirror()){
//2 params, one is reader, other is type, returns type - these are made to reduce garbage allocated
out.mutatorReaders.put(meth.retn().toString(), type.fullName() + "." + meth.name());
}
}
}
@@ -39,15 +42,12 @@ public class TypeIOResolver{
/** Information about read/write methods for class types. */
public static class ClassSerializer{
public final ObjectMap<String, String> writers, readers;
public final ObjectMap<String, String> writers, readers, mutatorReaders;
public ClassSerializer(ObjectMap<String, String> writers, ObjectMap<String, String> readers){
public ClassSerializer(ObjectMap<String, String> writers, ObjectMap<String, String> readers, ObjectMap<String, String> mutatorReaders){
this.writers = writers;
this.readers = readers;
}
public boolean has(String type){
return writers.containsKey(type) && readers.containsKey(type);
this.mutatorReaders = mutatorReaders;
}
}
}