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; boolean isFinal() default true;
/** If true, entities are recycled. */ /** If true, entities are recycled. */
boolean pooled() default false; 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; boolean serialize() default true;
/** Whether to generate IO code */ /** Whether to generate IO code. This is for advanced usage only. */
boolean genio() default true; boolean genio() default true;
} }

View File

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

View File

@@ -287,8 +287,9 @@ public class EntityProcess extends BaseProcessor{
.addModifiers(Modifier.PUBLIC) .addModifiers(Modifier.PUBLIC)
.addStatement("return $S + $L", name + "#", "id").build()); .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; EntityIO io = new EntityIO(type.name(), builder, serializer, rootDirectory.child("annotations/src/main/resources/revisions").child(name));
boolean hasIO = ann.genio() && ann.serialize(); //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 //add all methods from components
for(ObjectMap.Entry<String, Array<Smethod>> entry : methods){ 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 //SPECIAL CASE: I/O code
//note that serialization is generated even for non-serializing entities for manual usage //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")); io.write(mbuilder, first.name().equals("write"));
} }
//SPECIAL CASE: sync I/O code //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); io.writeSync(mbuilder, first.name().equals("writeSync"), syncedFields);
} }
//SPECIAL CASE: sync I/O code for writing to/from a manual buffer //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); io.writeSyncManual(mbuilder, first.name().equals("writeSyncManual"), syncedFields);
} }
@@ -369,7 +370,7 @@ public class EntityProcess extends BaseProcessor{
io.writeInterpolate(mbuilder, syncedFields); 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")){ if(first.name().equals("snapSync")){
mbuilder.addStatement("updateSpacing = 16"); mbuilder.addStatement("updateSpacing = 16");
mbuilder.addStatement("lastUpdated = $T.millis()", Time.class); mbuilder.addStatement("lastUpdated = $T.millis()", Time.class);

View File

@@ -16,7 +16,7 @@ public class TypeIOResolver{
* Maps fully qualified class names to their serializers. * Maps fully qualified class names to their serializers.
*/ */
public static ClassSerializer resolve(BaseProcessor processor){ 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)){ for(Stype type : processor.types(TypeIOHandler.class)){
//look at all TypeIOHandler methods //look at all TypeIOHandler methods
Array<Smethod> methods = type.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()){ }else if(params.size == 1 && params.first().tname().toString().equals("arc.util.io.Reads") && !meth.isVoid()){
//1 param, one is reader, returns type //1 param, one is reader, returns type
out.readers.put(meth.retn().toString(), type.fullName() + "." + meth.name()); 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. */ /** Information about read/write methods for class types. */
public static class ClassSerializer{ 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.writers = writers;
this.readers = readers; this.readers = readers;
} this.mutatorReaders = mutatorReaders;
public boolean has(String type){
return writers.containsKey(type) && readers.containsKey(type);
} }
} }
} }

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:tile,type:Tilec,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:tile,type:Tilec,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:baseRotation,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:requests,type:arc.struct.Queue<mindustry.entities.units.BuildRequest>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:baseRotation,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:requests,type:arc.struct.Queue<mindustry.entities.units.BuildRequest>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:mineTile,type:mindustry.world.Tile,size:-1},{name:requests,type:arc.struct.Queue<mindustry.entities.units.BuildRequest>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:mineTile,type:mindustry.world.Tile,size:-1},{name:requests,type:arc.struct.Queue<mindustry.entities.units.BuildRequest>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:requests,type:arc.struct.Queue<mindustry.entities.units.BuildRequest>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:requests,type:arc.struct.Queue<mindustry.entities.units.BuildRequest>,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -0,0 +1 @@
{fields:[{name:collided,type:arc.struct.IntArray,size:-1},{name:damage,type:float,size:4},{name:data,type:java.lang.Object,size:-1},{name:lifetime,type:float,size:4},{name:owner,type:Entityc,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:time,type:float,size:4},{name:type,type:mindustry.entities.bullet.BulletType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -0,0 +1 @@
{fields:[{name:color,type:arc.graphics.Color,size:-1},{name:lifetime,type:float,size:4},{name:region,type:arc.graphics.g2d.TextureRegion,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -0,0 +1 @@
{fields:[{name:color,type:arc.graphics.Color,size:-1},{name:data,type:java.lang.Object,size:-1},{name:effect,type:mindustry.entities.Effect,size:-1},{name:lifetime,type:float,size:4},{name:offsetX,type:float,size:4},{name:offsetY,type:float,size:4},{name:parent,type:Posc,size:-1},{name:rotation,type:float,size:4},{name:time,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:baseRotation,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:baseRotation,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:mineTile,type:mindustry.world.Tile,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:mineTile,type:mindustry.world.Tile,size:-1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -0,0 +1 @@
{fields:[{name:admin,type:boolean,size:1},{name:color,type:arc.graphics.Color,size:-1},{name:mouseX,type:float,size:4},{name:mouseY,type:float,size:4},{name:name,type:java.lang.String,size:-1},{name:shooting,type:boolean,size:1},{name:team,type:mindustry.game.Team,size:-1},{name:typing,type:boolean,size:1},{name:unit,type:Unitc,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -0,0 +1 @@
{fields:[{name:cons,type:mindustry.world.modules.ConsumeModule,size:-1},{name:health,type:float,size:4},{name:items,type:mindustry.world.modules.ItemModule,size:-1},{name:liquids,type:mindustry.world.modules.LiquidModule,size:-1},{name:power,type:mindustry.world.modules.PowerModule,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -1 +1 @@
{fields:[{name:armor,type:float,size:4},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]} {fields:[{name:armor,type:float,size:4},{name:controller,type:mindustry.entities.units.UnitController,size:-1},{name:elevation,type:float,size:4},{name:health,type:float,size:4},{name:isShooting,type:boolean,size:1},{name:rotation,type:float,size:4},{name:shield,type:float,size:4},{name:spawnedByCore,type:boolean,size:1},{name:stack,type:mindustry.type.ItemStack,size:-1},{name:statuses,type:arc.struct.Array<mindustry.entities.units.StatusEntry>,size:-1},{name:team,type:mindustry.game.Team,size:-1},{name:type,type:mindustry.type.UnitType,size:-1},{name:vel,type:arc.math.geom.Vec2,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}

View File

@@ -567,7 +567,7 @@ public class NetClient implements ApplicationListener{
Call.onClientShapshot(lastSent++, Call.onClientShapshot(lastSent++,
unit.x(), unit.y(), unit.x(), unit.y(),
player.mouseX(), player.mouseY(), player.unit().aimX(), player.unit().aimY(),
unit.rotation(), unit.rotation(),
unit instanceof Legsc ? ((Legsc)unit).baseRotation() : 0, unit instanceof Legsc ? ((Legsc)unit).baseRotation() : 0,
unit.vel().x, unit.vel().y, unit.vel().x, unit.vel().y,

View File

@@ -551,6 +551,7 @@ public class NetServer implements ApplicationListener{
player.mouseX(pointerX); player.mouseX(pointerX);
player.mouseY(pointerY); player.mouseY(pointerY);
player.typing(chatting); player.typing(chatting);
player.shooting(shooting);
player.unit().controlWeapons(shooting, shooting); player.unit().controlWeapons(shooting, shooting);
player.unit().aim(pointerX, pointerY); player.unit().aim(pointerX, pointerY);

View File

@@ -28,17 +28,17 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
static final float deathDelay = 30f; static final float deathDelay = 30f;
@NonNull @ReadOnly Unitc unit = Nulls.unit; @NonNull @ReadOnly Unitc unit = Nulls.unit;
transient @Nullable NetConnection con;
@ReadOnly Team team = Team.sharded; @ReadOnly Team team = Team.sharded;
String name = "noname"; String name = "noname";
@Nullable NetConnection con; boolean admin, typing, shooting;
boolean admin, typing;
Color color = new Color(); Color color = new Color();
float mouseX, mouseY; float mouseX, mouseY;
float deathTimer;
String lastText = ""; transient float deathTimer;
float textFadeTime; transient String lastText = "";
transient float textFadeTime;
public boolean isBuilder(){ public boolean isBuilder(){
return unit instanceof Builderc; return unit instanceof Builderc;
@@ -64,7 +64,16 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
@Replace @Replace
public float clipSize(){ public float clipSize(){
return 20; return unit.isNull() ? 20 : unit.type().hitsize * 2f;
}
@Override
public void afterSync(){
unit.aim(mouseX, mouseY);
//this is only necessary when the thing being controlled isn't synced
unit.isShooting(shooting);
//extra precaution, necessary for non-synced things
unit.controller(this);
} }
@Override @Override
@@ -113,6 +122,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
public void unit(Unitc unit){ public void unit(Unitc unit){
if(unit == null) throw new IllegalArgumentException("Unit cannot be null. Use clearUnit() instead."); if(unit == null) throw new IllegalArgumentException("Unit cannot be null. Use clearUnit() instead.");
if(this.unit == unit) return;
if(this.unit != Nulls.unit){ if(this.unit != Nulls.unit){
//un-control the old unit //un-control the old unit
this.unit.controller(this.unit.type().createController()); this.unit.controller(this.unit.type().createController());

View File

@@ -17,6 +17,7 @@ abstract class SyncComp implements Entityc{
void writeSync(Writes write){} void writeSync(Writes write){}
void readSyncManual(FloatBuffer buffer){} void readSyncManual(FloatBuffer buffer){}
void writeSyncManual(FloatBuffer buffer){} void writeSyncManual(FloatBuffer buffer){}
void afterSync(){}
void interpolate(){} void interpolate(){}
@Override @Override

View File

@@ -5,7 +5,7 @@ import mindustry.annotations.Annotations.*;
@Component @Component
abstract class TimerComp{ abstract class TimerComp{
Interval timer = new Interval(6); transient Interval timer = new Interval(6);
public boolean timer(int index, float time){ public boolean timer(int index, float time){
return timer.get(index, time); return timer.get(index, time);

View File

@@ -23,7 +23,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
@Import float x, y, rotation, elevation, maxHealth; @Import float x, y, rotation, elevation, maxHealth;
private transient UnitController controller; private UnitController controller;
private UnitType type; private UnitType type;
boolean spawnedByCore; boolean spawnedByCore;

View File

@@ -22,7 +22,8 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
/** weapon mount array, never null */ /** weapon mount array, never null */
@ReadOnly transient WeaponMount[] mounts = {}; @ReadOnly transient WeaponMount[] mounts = {};
@ReadOnly transient float range, aimX, aimY; @ReadOnly transient float range, aimX, aimY;
@ReadOnly transient boolean isRotate, isShooting; @ReadOnly transient boolean isRotate;
boolean isShooting;
void setWeaponRotation(float rotation){ void setWeaponRotation(float rotation){
for(WeaponMount mount : mounts){ for(WeaponMount mount : mounts){

View File

@@ -5,6 +5,7 @@ import arc.math.geom.*;
import arc.struct.*; import arc.struct.*;
import arc.util.io.*; import arc.util.io.*;
import arc.util.pooling.*; import arc.util.pooling.*;
import mindustry.ai.types.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.entities.bullet.*; import mindustry.entities.bullet.*;
@@ -15,6 +16,7 @@ import mindustry.net.Administration.*;
import mindustry.net.Packets.*; import mindustry.net.Packets.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
import mindustry.world.blocks.*;
import java.io.*; import java.io.*;
import java.nio.*; import java.nio.*;
@@ -26,8 +28,6 @@ import static mindustry.Vars.*;
@TypeIOHandler @TypeIOHandler
public class TypeIO{ public class TypeIO{
//TODO read/write enums like commands!
public static void writeObject(Writes write, Object object){ public static void writeObject(Writes write, Object object){
if(object == null){ if(object == null){
write.b((byte)0); write.b((byte)0);
@@ -87,6 +87,32 @@ public class TypeIO{
} }
} }
//only for players!
public static void writeUnit(Writes write, Unitc unit){
write.b(unit.isNull() ? 0 : unit instanceof BlockUnitc ? 1 : 2);
//block units are special
if(unit instanceof BlockUnitc){
write.i(((BlockUnitc)unit).tile().pos());
}else{
write.i(unit.id());
}
}
public static Unitc readUnit(Reads read){
byte type = read.b();
int id = read.i();
//nothing
if(type == 0) return Nulls.unit;
if(type == 2){ //standard unit
Unitc unit = Groups.unit.getByID(id);
return unit == null ? Nulls.unit : unit;
}else if(type == 1){ //block
Tilec tile = world.ent(id);
return tile instanceof ControlBlock ? ((ControlBlock)tile).unit() : Nulls.unit;
}
return Nulls.unit;
}
public static void writeEntity(Writes write, Entityc entity){ public static void writeEntity(Writes write, Entityc entity){
write.i(entity == null ? -1 : entity.id()); write.i(entity == null ? -1 : entity.id());
} }
@@ -184,6 +210,33 @@ public class TypeIO{
return reqs; return reqs;
} }
public static void writeController(Writes write, UnitController control){
//no real unit controller state is written, only the type
if(control instanceof Playerc){
write.b(0);
write.i(((Playerc)control).id());
}else{
write.b(1);
}
}
public static UnitController readController(Reads read, UnitController prev){
byte type = read.b();
if(type == 0){ //is player
int id = read.i();
Playerc player = Groups.player.getByID(id);
//local players will cause problems if assigned, since they may not know they are controlling the unit
if(player == null || player.isLocal()) return prev;
return player;
}else{
//there are two cases here:
//1: prev controller was not a player, carry on
//2: prev controller was a player, so replace this controller with *anything else*
//...since AI doesn't update clientside it doesn't matter what
return prev instanceof Playerc ? new GroundAI() : prev;
}
}
public static void writeKick(Writes write, KickReason reason){ public static void writeKick(Writes write, KickReason reason){
write.b((byte)reason.ordinal()); write.b((byte)reason.ordinal());
} }
@@ -215,6 +268,10 @@ public class TypeIO{
} }
} }
public static Vec2 readVec2(Reads read, Vec2 base){
return base.set(read.f(), read.f());
}
public static Vec2 readVec2(Reads read){ public static Vec2 readVec2(Reads read){
return new Vec2(read.f(), read.f()); return new Vec2(read.f(), read.f());
} }
@@ -233,6 +290,10 @@ public class TypeIO{
write.i(stack.amount); write.i(stack.amount);
} }
public static ItemStack readItems(Reads read, ItemStack stack){
return stack.set(readItem(read), read.i());
}
public static ItemStack readItems(Reads read){ public static ItemStack readItems(Reads read){
return new ItemStack(readItem(read), read.i()); return new ItemStack(readItem(read), read.i());
} }
@@ -277,6 +338,10 @@ public class TypeIO{
return new Color(read.i()); return new Color(read.i());
} }
public static Color readColor(Reads read, Color color){
return color.set(read.i());
}
public static void writeLiquid(Writes write, Liquid liquid){ public static void writeLiquid(Writes write, Liquid liquid){
write.s(liquid == null ? -1 : liquid.id); write.s(liquid == null ? -1 : liquid.id);
} }
@@ -314,18 +379,17 @@ public class TypeIO{
public static void writeString(Writes write, String string){ public static void writeString(Writes write, String string){
if(string != null){ if(string != null){
byte[] bytes = string.getBytes(charset); write.b(1);
write.s((short)bytes.length); write.str(string);
write.b(bytes);
}else{ }else{
write.s((short)-1); write.b(0);
} }
} }
public static String readString(Reads read){ public static String readString(Reads read){
short slength = read.s(); byte exists = read.b();
if(slength != -1){ if(exists != 0){
return new String(read.b(new byte[slength]), charset); return read.str();
}else{ }else{
return null; return null;
} }

View File

@@ -21,6 +21,12 @@ public class ItemStack implements Comparable<ItemStack>{
item = Items.copper; item = Items.copper;
} }
public ItemStack set(Item item, int amount){
this.item = item;
this.amount = amount;
return this;
}
public ItemStack copy(){ public ItemStack copy(){
return new ItemStack(item, amount); return new ItemStack(item, amount);
} }

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=88bbf067bd128651ebfa797ba64425658258e2c7 archash=ca7245cbd7cd13b4343da2f2b105d4fc44058df2