Autogeneration of some IO code

This commit is contained in:
Anuken
2020-02-13 13:30:30 -05:00
parent 47f075133f
commit ad248e2e20
40 changed files with 163 additions and 74 deletions

View File

@@ -24,6 +24,12 @@ public class Annotations{
public @interface Replace{ public @interface Replace{
} }
/** Indicates that a component field is imported from other components. */
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.SOURCE)
public @interface Import{
}
/** Indicates that a component field is read-only. */ /** Indicates that a component field is read-only. */
@Target({ElementType.FIELD, ElementType.METHOD}) @Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@@ -70,6 +76,7 @@ public class Annotations{
Class[] value(); Class[] value();
boolean isFinal() default true; boolean isFinal() default true;
boolean pooled() default false; boolean pooled() default false;
boolean serialize() default true;
} }
/** Indicates an internal interface for entity components. */ /** Indicates an internal interface for entity components. */

View File

@@ -0,0 +1,55 @@
package mindustry.annotations.entity;
import arc.util.*;
import com.squareup.javapoet.*;
import com.squareup.javapoet.MethodSpec.*;
import mindustry.annotations.*;
import javax.lang.model.element.*;
public class EntityIO{
final TypeElement contentElem = BaseProcessor.elementu.getTypeElement("mindustry.ctype.Content");
final MethodSpec.Builder builder;
final boolean write;
EntityIO(Builder builder, boolean write){
this.builder = builder;
this.write = write;
}
void io(TypeName type, String field) throws Exception{
TypeElement element = BaseProcessor.elementu.getTypeElement(type.toString());
if(type.isPrimitive()){
s(type.toString(), field);
}else if(type.toString().equals("java.lang.String")){
s("UTF", field);
}else if(element != null && BaseProcessor.typeu.isSubtype(element.asType(), contentElem.asType())){
if(write){
s("short", field + ".id");
}else{
st(field + " = mindustry.Vars.content.getByID(mindustry.ctype.ContentType.$L, input.readShort())", BaseProcessor.simpleName(type.toString()).toLowerCase().replace("type", ""));
}
}
}
private void cont(String text, Object... fmt){
builder.beginControlFlow(text, fmt);
}
private void cont(){
builder.endControlFlow();
}
private void st(String text, Object... args){
builder.addStatement(text, args);
}
private void s(String type, String field){
if(write){
builder.addStatement("output.write$L($L)", Strings.capitalize(type), field);
}else{
builder.addStatement("$L = input.read$L()", field, Strings.capitalize(type));
}
}
}

View File

@@ -1,4 +1,4 @@
package mindustry.annotations.impl; package mindustry.annotations.entity;
import arc.files.*; import arc.files.*;
import arc.func.*; import arc.func.*;
@@ -118,7 +118,7 @@ public class EntityProcess extends BaseProcessor{
.build())).addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT).build()); .build())).addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT).build());
} }
for(Svar field : component.fields().select(e -> !e.is(Modifier.STATIC) && !e.is(Modifier.PRIVATE) && !e.is(Modifier.TRANSIENT))){ for(Svar field : component.fields().select(e -> !e.is(Modifier.STATIC) && !e.is(Modifier.PRIVATE) && !e.has(Import.class))){
String cname = field.name(); String cname = field.name();
//getter //getter
@@ -221,19 +221,32 @@ public class EntityProcess extends BaseProcessor{
Array<GroupDefinition> groups = groupDefs.select(g -> (!g.components.isEmpty() && !g.components.contains(s -> !components.contains(s))) || g.manualInclusions.contains(type)); Array<GroupDefinition> groups = groupDefs.select(g -> (!g.components.isEmpty() && !g.components.contains(s -> !components.contains(s))) || g.manualInclusions.contains(type));
ObjectMap<String, Array<Smethod>> methods = new ObjectMap<>(); ObjectMap<String, Array<Smethod>> methods = new ObjectMap<>();
ObjectMap<FieldSpec, Svar> specVariables = new ObjectMap<>(); ObjectMap<FieldSpec, Svar> specVariables = new ObjectMap<>();
ObjectSet<String> usedFields = new ObjectSet<>();
//add serialize() boolean
builder.addMethod(MethodSpec.methodBuilder("serialize").addModifiers(Modifier.PUBLIC, Modifier.FINAL).returns(boolean.class).addStatement("return " + ann.serialize()).build());
//add all components //add all components
for(Stype comp : components){ for(Stype comp : components){
//write fields to the class; ignoring transient ones //write fields to the class; ignoring transient ones
Array<Svar> fields = comp.fields().select(f -> !f.is(Modifier.TRANSIENT)); Array<Svar> fields = comp.fields().select(f -> !f.has(Import.class));
for(Svar f : fields){ for(Svar f : fields){
if(!usedFields.add(f.name())){
err("Field '" + f.name() + "' of component '" + comp.name() + "' re-defines a field in entity '" + type.name() + "'");
continue;
}
FieldSpec.Builder fbuilder = FieldSpec.builder(f.tname(), f.name()); FieldSpec.Builder fbuilder = FieldSpec.builder(f.tname(), f.name());
//keep statics/finals //keep statics/finals
if(f.is(Modifier.STATIC)){ if(f.is(Modifier.STATIC)){
fbuilder.addModifiers(Modifier.STATIC); fbuilder.addModifiers(Modifier.STATIC);
if(f.is(Modifier.FINAL)) fbuilder.addModifiers(Modifier.FINAL); if(f.is(Modifier.FINAL)) fbuilder.addModifiers(Modifier.FINAL);
} }
//add transient modifier for serialization
if(f.is(Modifier.TRANSIENT)){
fbuilder.addModifiers(Modifier.TRANSIENT);
}
//add initializer if it exists //add initializer if it exists
if(varInitializers.containsKey(f)){ if(varInitializers.containsKey(f)){
fbuilder.initializer(varInitializers.get(f)); fbuilder.initializer(varInitializers.get(f));
@@ -312,6 +325,18 @@ public class EntityProcess extends BaseProcessor{
} }
} }
//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")){
EntityIO writer = new EntityIO(mbuilder, first.name().equals("write"));
//write or read each non-transient field
for(FieldSpec spec : builder.fieldSpecs){
if(!spec.hasModifier(Modifier.TRANSIENT) && !spec.hasModifier(Modifier.STATIC) && !spec.hasModifier(Modifier.FINAL)){
writer.io(spec.type, "this." + spec.name);
}
}
}
for(Smethod elem : entry.value){ for(Smethod elem : entry.value){
if(elem.is(Modifier.ABSTRACT) || elem.is(Modifier.NATIVE) || !methodBlocks.containsKey(elem)) continue; if(elem.is(Modifier.ABSTRACT) || elem.is(Modifier.NATIVE) || !methodBlocks.containsKey(elem)) continue;

View File

@@ -6,22 +6,22 @@ import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
public class UnitTypes implements ContentList{ public class UnitTypes implements ContentList{
public static UnitDef public static UnitType
draug, spirit, phantom, draug, spirit, phantom,
wraith, ghoul, revenant, lich, reaper, wraith, ghoul, revenant, lich, reaper,
crawler, titan, fortress, eruptor, chaosArray, eradicator; crawler, titan, fortress, eruptor, chaosArray, eradicator;
public static @EntityDef({Unitc.class, Legsc.class}) UnitDef dagger; public static @EntityDef({Unitc.class, Legsc.class}) UnitType dagger;
public static @EntityDef({Unitc.class, WaterMovec.class}) UnitDef vanguard; public static @EntityDef({Unitc.class, WaterMovec.class}) UnitType vanguard;
public static UnitDef alpha, delta, tau, omega, dart, javelin, trident, glaive; public static UnitType alpha, delta, tau, omega, dart, javelin, trident, glaive;
public static UnitDef starter; public static UnitType starter;
@Override @Override
public void load(){ public void load(){
dagger = new UnitDef("dagger"){{ dagger = new UnitType("dagger"){{
speed = 1f; speed = 1f;
drag = 0.3f; drag = 0.3f;
hitsize = 8f; hitsize = 8f;
@@ -36,7 +36,7 @@ public class UnitTypes implements ContentList{
}}); }});
}}; }};
vanguard = new UnitDef("vanguard"){{ vanguard = new UnitType("vanguard"){{
speed = 1.3f; speed = 1.3f;
drag = 0.1f; drag = 0.1f;
hitsize = 8f; hitsize = 8f;

View File

@@ -261,7 +261,7 @@ public class ContentLoader{
return getBy(ContentType.zone); return getBy(ContentType.zone);
} }
public Array<UnitDef> units(){ public Array<UnitType> units(){
return getBy(ContentType.unit); return getBy(ContentType.unit);
} }
} }

View File

@@ -30,7 +30,7 @@ public class WaveInfoDialog extends FloatingDialog{
private Table table, preview; private Table table, preview;
private int start = 0; private int start = 0;
private UnitDef lastType = UnitTypes.dagger; private UnitType lastType = UnitTypes.dagger;
private float updateTimer, updatePeriod = 1f; private float updateTimer, updatePeriod = 1f;
public WaveInfoDialog(MapEditor editor){ public WaveInfoDialog(MapEditor editor){
@@ -221,7 +221,7 @@ public class WaveInfoDialog extends FloatingDialog{
dialog.setFillParent(true); dialog.setFillParent(true);
dialog.cont.pane(p -> { dialog.cont.pane(p -> {
int i = 0; int i = 0;
for(UnitDef type : content.units()){ for(UnitType type : content.units()){
p.addButton(t -> { p.addButton(t -> {
t.left(); t.left();
t.addImage(type.icon(mindustry.ui.Cicon.medium)).size(40f).padRight(2f); t.addImage(type.icon(mindustry.ui.Cicon.medium)).size(40f).padRight(2f);
@@ -256,7 +256,7 @@ public class WaveInfoDialog extends FloatingDialog{
for(int j = 0; j < spawned.length; j++){ for(int j = 0; j < spawned.length; j++){
if(spawned[j] > 0){ if(spawned[j] > 0){
UnitDef type = content.getByID(ContentType.unit, j); UnitType type = content.getByID(ContentType.unit, j);
table.addImage(type.icon(Cicon.medium)).size(8f * 4f).padRight(4); table.addImage(type.icon(Cicon.medium)).size(8f * 4f).padRight(4);
table.add(spawned[j] + "x").color(Color.lightGray).padRight(6); table.add(spawned[j] + "x").color(Color.lightGray).padRight(6);
table.row(); table.row();

View File

@@ -11,8 +11,8 @@ import static mindustry.Vars.*;
abstract class BoundedComp implements Velc, Posc, Healthc, Flyingc{ abstract class BoundedComp implements Velc, Posc, Healthc, Flyingc{
static final float warpDst = 180f; static final float warpDst = 180f;
transient float x, y; @Import float x, y;
transient Vec2 vel; @Import Vec2 vel;
@Override @Override
public void update(){ public void update(){

View File

@@ -4,10 +4,9 @@ import arc.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.*;
import arc.struct.Queue; import arc.struct.Queue;
import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*; import mindustry.content.*;
@@ -27,10 +26,10 @@ import static mindustry.Vars.*;
abstract class BuilderComp implements Unitc{ abstract class BuilderComp implements Unitc{
static final Vec2[] tmptr = new Vec2[]{new Vec2(), new Vec2(), new Vec2(), new Vec2()}; static final Vec2[] tmptr = new Vec2[]{new Vec2(), new Vec2(), new Vec2(), new Vec2()};
transient float x, y, rotation; @Import float x, y, rotation;
Queue<BuildRequest> requests = new Queue<>(); Queue<BuildRequest> requests = new Queue<>();
float buildSpeed = 1f; transient float buildSpeed = 1f;
//boolean building; //boolean building;
void updateBuilding(){ void updateBuilding(){

View File

@@ -6,7 +6,7 @@ import mindustry.gen.*;
@Component @Component
abstract class ChildComp implements Posc{ abstract class ChildComp implements Posc{
transient float x, y; @Import float x, y;
@Nullable Posc parent; @Nullable Posc parent;
float offsetX, offsetY; float offsetX, offsetY;

View File

@@ -9,7 +9,7 @@ import mindustry.gen.*;
@EntityDef(value = {Decalc.class}, pooled = true) @EntityDef(value = {Decalc.class}, pooled = true)
@Component @Component
abstract class DecalComp implements Drawc, Timedc, Rotc, Posc, DrawLayerFloorc{ abstract class DecalComp implements Drawc, Timedc, Rotc, Posc, DrawLayerFloorc{
transient float x, y, rotation; @Import float x, y, rotation;
Color color = new Color(1, 1, 1, 1); Color color = new Color(1, 1, 1, 1);
TextureRegion region; TextureRegion region;

View File

@@ -7,7 +7,7 @@ import static mindustry.Vars.collisions;
@Component @Component
abstract class ElevationMoveComp implements Velc, Posc, Flyingc, Hitboxc{ abstract class ElevationMoveComp implements Velc, Posc, Flyingc, Hitboxc{
transient float x, y; @Import float x, y;
@Replace @Replace
@Override @Override

View File

@@ -12,8 +12,8 @@ import static mindustry.Vars.player;
@Component @Component
@BaseComponent @BaseComponent
abstract class EntityComp{ abstract class EntityComp{
private boolean added; private transient boolean added;
int id = EntityGroup.nextId(); transient int id = EntityGroup.nextId();
boolean isAdded(){ boolean isAdded(){
return added; return added;
@@ -49,6 +49,9 @@ abstract class EntityComp{
@InternalImpl @InternalImpl
abstract int classId(); abstract int classId();
@InternalImpl
abstract boolean serialize();
void read(DataInput input) throws IOException{ void read(DataInput input) throws IOException{
//TODO dynamic io //TODO dynamic io
} }

View File

@@ -18,7 +18,7 @@ import static mindustry.Vars.*;
abstract class FireComp implements Timedc, Posc, Firec{ abstract class FireComp implements Timedc, Posc, Firec{
private static final float spreadChance = 0.05f, fireballChance = 0.07f; private static final float spreadChance = 0.05f, fireballChance = 0.07f;
transient float time, lifetime, x, y; @Import float time, lifetime, x, y;
Tile tile; Tile tile;
private Block block; private Block block;

View File

@@ -12,12 +12,12 @@ import static mindustry.Vars.net;
@Component @Component
abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
transient float x, y; @Import float x, y;
transient Vec2 vel; @Import Vec2 vel;
float elevation; float elevation;
float drownTime; float drownTime;
float splashTimer; transient float splashTimer;
boolean isGrounded(){ boolean isGrounded(){
return elevation < 0.001f; return elevation < 0.001f;

View File

@@ -9,7 +9,8 @@ import mindustry.gen.*;
abstract class HealthComp implements Entityc{ abstract class HealthComp implements Entityc{
static final float hitDuration = 9f; static final float hitDuration = 9f;
float health, maxHealth = 1f, hitTime; transient float hitTime;
float health, maxHealth = 1f;
boolean dead; boolean dead;
boolean isValid(){ boolean isValid(){

View File

@@ -7,7 +7,7 @@ import mindustry.gen.*;
@Component @Component
abstract class HitboxComp implements Posc, QuadTreeObject{ abstract class HitboxComp implements Posc, QuadTreeObject{
transient float x, y; @Import float x, y;
float hitSize; float hitSize;
float lastX, lastY; float lastX, lastY;

View File

@@ -8,7 +8,7 @@ import mindustry.type.*;
@Component @Component
abstract class ItemsComp implements Posc{ abstract class ItemsComp implements Posc{
@ReadOnly ItemStack stack = new ItemStack(); @ReadOnly ItemStack stack = new ItemStack();
float itemTime; transient float itemTime;
abstract int itemCapacity(); abstract int itemCapacity();

View File

@@ -7,9 +7,10 @@ import mindustry.gen.*;
@Component @Component
abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc, Unitc, Legsc, ElevationMovec{ abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc, Unitc, Legsc, ElevationMovec{
transient float x, y; @Import float x, y;
float baseRotation, walkTime; float baseRotation;
transient float walkTime;
@Override @Override
public void update(){ public void update(){

View File

@@ -18,9 +18,9 @@ import static mindustry.Vars.*;
@Component @Component
abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc{ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc{
transient float x, y, rotation; @Import float x, y, rotation;
float mineTimer; transient float mineTimer;
@Nullable Tile mineTile; @Nullable Tile mineTile;
abstract boolean canMine(Item item); abstract boolean canMine(Item item);

View File

@@ -23,8 +23,7 @@ import static mindustry.Vars.*;
@EntityDef({Playerc.class}) @EntityDef({Playerc.class})
@Component @Component
abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
@NonNull @NonNull @ReadOnly Unitc unit = Nulls.unit;
@ReadOnly Unitc unit = Nulls.unit;
@ReadOnly Team team = Team.sharded; @ReadOnly Team team = Team.sharded;
String name = "noname"; String name = "noname";
@@ -33,7 +32,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
Color color = new Color(); Color color = new Color();
float mouseX, mouseY; float mouseX, mouseY;
@Nullable String lastText; String lastText = "";
float textFadeTime; float textFadeTime;
public boolean isBuilder(){ public boolean isBuilder(){
@@ -51,7 +50,6 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
public void reset(){ public void reset(){
team = state.rules.defaultTeam; team = state.rules.defaultTeam;
admin = typing = false; admin = typing = false;
lastText = null;
textFadeTime = 0f; textFadeTime = 0f;
if(!dead()){ if(!dead()){
unit.controller(unit.type().createController()); unit.controller(unit.type().createController());

View File

@@ -25,7 +25,7 @@ abstract class PuddleComp implements Posc, DrawLayerFloorOverc{
private static final Rect rect2 = new Rect(); private static final Rect rect2 = new Rect();
private static int seeds; private static int seeds;
transient float x, y; @Import float x, y;
float amount, lastRipple, accepting, updateTime; float amount, lastRipple, accepting, updateTime;
int generation; int generation;

View File

@@ -7,7 +7,7 @@ import mindustry.net.*;
@Component @Component
abstract class SyncComp implements Posc{ abstract class SyncComp implements Posc{
transient float x, y; @Import float x, y;
Interpolator interpolator = new Interpolator(); Interpolator interpolator = new Interpolator();

View File

@@ -9,7 +9,7 @@ import static mindustry.Vars.state;
@Component @Component
abstract class TeamComp implements Posc{ abstract class TeamComp implements Posc{
transient float x, y; @Import float x, y;
Team team = Team.sharded; Team team = Team.sharded;

View File

@@ -20,10 +20,10 @@ import static mindustry.Vars.*;
@Component @Component
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, Drawc, Boundedc, abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, Drawc, Boundedc,
DrawLayerGroundc, DrawLayerFlyingc, DrawLayerGroundShadowsc, DrawLayerFlyingShadowsc{ DrawLayerGroundc, DrawLayerFlyingc, DrawLayerGroundShadowsc, DrawLayerFlyingShadowsc{
transient float x, y, rotation; @Import float x, y, rotation;
private UnitController controller; private UnitController controller;
private UnitDef type; private UnitType type;
@Override @Override
public float clipSize(){ public float clipSize(){
@@ -52,7 +52,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
} }
@Override @Override
public void set(UnitDef def, UnitController controller){ public void set(UnitType def, UnitController controller){
type(type); type(type);
controller(controller); controller(controller);
} }
@@ -75,7 +75,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
} }
@Override @Override
public void type(UnitDef type){ public void type(UnitType type){
this.type = type; this.type = type;
maxHealth(type.health); maxHealth(type.health);
heal(); heal();
@@ -86,7 +86,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
} }
@Override @Override
public UnitDef type(){ public UnitType type(){
return type; return type;
} }

View File

@@ -7,7 +7,7 @@ import mindustry.gen.*;
@Component @Component
abstract class VelComp implements Posc{ abstract class VelComp implements Posc{
transient float x, y; @Import float x, y;
final Vec2 vel = new Vec2(); final Vec2 vel = new Vec2();
float drag = 0f; float drag = 0f;

View File

@@ -11,7 +11,7 @@ import static mindustry.Vars.collisions;
//just a proof of concept //just a proof of concept
@Component @Component
abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc{ abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc{
transient float x, y; @Import float x, y;
@Replace @Replace
@Override @Override

View File

@@ -12,7 +12,7 @@ import mindustry.type.*;
@Component @Component
abstract class WeaponsComp implements Teamc, Posc, Rotc{ abstract class WeaponsComp implements Teamc, Posc, Rotc{
transient float x, y, rotation; @Import float x, y, rotation;
/** minimum cursor distance from player, fixes 'cross-eyed' shooting */ /** minimum cursor distance from player, fixes 'cross-eyed' shooting */
static final float minAimDst = 20f; static final float minAimDst = 20f;
@@ -22,7 +22,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
/** weapon mount array, never null */ /** weapon mount array, never null */
@ReadOnly WeaponMount[] mounts = {}; @ReadOnly WeaponMount[] mounts = {};
void setupWeapons(UnitDef def){ void setupWeapons(UnitType def){
mounts = new WeaponMount[def.weapons.size]; mounts = new WeaponMount[def.weapons.size];
for(int i = 0; i < mounts.length; i++){ for(int i = 0; i < mounts.length; i++){
mounts[i] = new WeaponMount(def.weapons.get(i)); mounts[i] = new WeaponMount(def.weapons.get(i));

View File

@@ -5,7 +5,6 @@ import mindustry.core.GameState.*;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
@@ -328,9 +327,9 @@ public class EventType{
//TODO rename //TODO rename
public static class MechChangeEvent{ public static class MechChangeEvent{
public final Playerc player; public final Playerc player;
public final UnitDef mech; public final UnitType mech;
public MechChangeEvent(Playerc player, UnitDef mech){ public MechChangeEvent(Playerc player, UnitType mech){
this.player = player; this.player = player;
this.mech = mech; this.mech = mech;
} }

View File

@@ -19,7 +19,7 @@ public class SpawnGroup implements Serializable{
public static final int never = Integer.MAX_VALUE; public static final int never = Integer.MAX_VALUE;
/** The unit type spawned */ /** The unit type spawned */
public UnitDef type; public UnitType type;
/** When this spawn should end */ /** When this spawn should end */
public int end = never; public int end = never;
/** When this spawn should start */ /** When this spawn should start */
@@ -37,7 +37,7 @@ public class SpawnGroup implements Serializable{
/** Items this unit spawns with. Null to disable. */ /** Items this unit spawns with. Null to disable. */
public ItemStack items; public ItemStack items;
public SpawnGroup(UnitDef type){ public SpawnGroup(UnitType type){
this.type = type; this.type = type;
} }

View File

@@ -30,7 +30,7 @@ public class MenuRenderer implements Disposable{
private float time = 0f; private float time = 0f;
private float flyerRot = 45f; private float flyerRot = 45f;
private int flyers = Mathf.chance(0.2) ? Mathf.random(35) : Mathf.random(15); private int flyers = Mathf.chance(0.2) ? Mathf.random(35) : Mathf.random(15);
private UnitDef flyerType = Structs.select(UnitTypes.wraith, UnitTypes.wraith, UnitTypes.ghoul, UnitTypes.phantom, UnitTypes.phantom, UnitTypes.revenant); private UnitType flyerType = Structs.select(UnitTypes.wraith, UnitTypes.wraith, UnitTypes.ghoul, UnitTypes.phantom, UnitTypes.phantom, UnitTypes.revenant);
public MenuRenderer(){ public MenuRenderer(){
Time.mark(); Time.mark();

View File

@@ -224,6 +224,8 @@ public abstract class SaveVersion extends SaveFileReader{
stream.writeInt(Groups.sync.size()); stream.writeInt(Groups.sync.size());
for(Syncc entity : Groups.sync){ for(Syncc entity : Groups.sync){
if(!entity.serialize()) continue;
writeChunk(stream, true, out -> { writeChunk(stream, true, out -> {
out.writeByte(entity.classId()); out.writeByte(entity.classId());
entity.write(out); entity.write(out);

View File

@@ -155,13 +155,13 @@ public class TypeIO{
return AdminAction.values()[buffer.get()]; return AdminAction.values()[buffer.get()];
} }
@WriteClass(UnitDef.class) @WriteClass(UnitType.class)
public static void writeUnitDef(ByteBuffer buffer, UnitDef effect){ public static void writeUnitDef(ByteBuffer buffer, UnitType effect){
buffer.putShort(effect.id); buffer.putShort(effect.id);
} }
@ReadClass(UnitDef.class) @ReadClass(UnitType.class)
public static UnitDef readUnitDef(ByteBuffer buffer){ public static UnitType readUnitDef(ByteBuffer buffer){
return content.getByID(ContentType.unit, buffer.getShort()); return content.getByID(ContentType.unit, buffer.getShort());
} }

View File

@@ -274,14 +274,14 @@ public class ContentParser{
return block; return block;
}, },
ContentType.unit, (TypeParser<UnitDef>)(mod, name, value) -> { ContentType.unit, (TypeParser<UnitType>)(mod, name, value) -> {
readBundle(ContentType.unit, name, value); readBundle(ContentType.unit, name, value);
//TODO fix //TODO fix
UnitDef unit; UnitType unit;
if(locate(ContentType.unit, name) == null){ if(locate(ContentType.unit, name) == null){
Class<Unitc> type = resolve(legacyUnitMap.get(Strings.capitalize(getType(value)), getType(value)), "mindustry.entities.type.base"); Class<Unitc> type = resolve(legacyUnitMap.get(Strings.capitalize(getType(value)), getType(value)), "mindustry.entities.type.base");
unit = new UnitDef(mod + "-" + name); unit = new UnitType(mod + "-" + name);
}else{ }else{
unit = locate(ContentType.unit, name); unit = locate(ContentType.unit, name);
} }

View File

@@ -21,8 +21,7 @@ import mindustry.world.blocks.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
//TODO change to UnitType or Shell or something public class UnitType extends UnlockableContent{
public class UnitDef extends UnlockableContent{
static final float shadowTX = -12, shadowTY = -13, shadowColor = Color.toFloatBits(0, 0, 0, 0.22f); static final float shadowTX = -12, shadowTY = -13, shadowColor = Color.toFloatBits(0, 0, 0, 0.22f);
public @NonNull Prov<? extends UnitController> defaultController = AIController::new; public @NonNull Prov<? extends UnitController> defaultController = AIController::new;
@@ -53,7 +52,7 @@ public class UnitDef extends UnlockableContent{
public Array<Weapon> weapons = new Array<>(); public Array<Weapon> weapons = new Array<>();
public TextureRegion baseRegion, legRegion, region, cellRegion, occlusionRegion; public TextureRegion baseRegion, legRegion, region, cellRegion, occlusionRegion;
public UnitDef(String name){ public UnitType(String name){
super(name); super(name);
if(EntityMapping.map(name) != null){ if(EntityMapping.map(name) != null){

View File

@@ -131,7 +131,7 @@ public class ContentDisplay{
table.row(); table.row();
} }
public static void displayUnit(Table table, UnitDef unit){ public static void displayUnit(Table table, UnitType unit){
table.table(title -> { table.table(title -> {
title.addImage(unit.icon(Cicon.xlarge)).size(8 * 6); title.addImage(unit.icon(Cicon.xlarge)).size(8 * 6);
title.add("[accent]" + unit.localizedName).padLeft(5); title.add("[accent]" + unit.localizedName).padLeft(5);

View File

@@ -12,7 +12,7 @@ import static mindustry.Vars.net;
public class RespawnBlock{ public class RespawnBlock{
public static void drawRespawn(Tile tile, float heat, float progress, float time, Playerc player, UnitDef to){ public static void drawRespawn(Tile tile, float heat, float progress, float time, Playerc player, UnitType to){
progress = Mathf.clamp(progress); progress = Mathf.clamp(progress);
Draw.color(Pal.darkMetal); Draw.color(Pal.darkMetal);

View File

@@ -20,7 +20,7 @@ import mindustry.world.modules.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class CoreBlock extends StorageBlock{ public class CoreBlock extends StorageBlock{
public UnitDef mech = UnitTypes.starter; public UnitType mech = UnitTypes.starter;
public CoreBlock(String name){ public CoreBlock(String name){
super(name); super(name);

View File

@@ -20,7 +20,7 @@ import static mindustry.Vars.*;
//TODO remove //TODO remove
public class MechPad extends Block{ public class MechPad extends Block{
public @NonNull UnitDef mech; public @NonNull UnitType mech;
public float buildTime = 60 * 5; public float buildTime = 60 * 5;
public MechPad(String name){ public MechPad(String name){

View File

@@ -22,7 +22,7 @@ import java.io.*;
import static mindustry.Vars.net; import static mindustry.Vars.net;
public class UnitFactory extends Block{ public class UnitFactory extends Block{
public UnitDef unitType; public UnitType unitType;
public float produceTime = 1000f; public float produceTime = 1000f;
public float launchVelocity = 0f; public float launchVelocity = 0f;
public TextureRegion topRegion; public TextureRegion topRegion;

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=dccfeeeffbf4e66b815306306b55472dcd123f61 archash=d271474a36e1b68887bdb7520bf683c5aa832e79