many things

This commit is contained in:
Anuken
2019-05-06 14:34:21 -04:00
parent 20fbe2fbbe
commit 51f9ad5a2c
50 changed files with 424 additions and 613 deletions
@@ -72,6 +72,11 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
}
}
@Override
public byte version(){
return 0;
}
@Override
public float lifetime(){
return lifetime;
@@ -151,7 +156,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
}
@Override
public void readSave(DataInput stream) throws IOException{
public void readSave(DataInput stream, byte version) throws IOException{
this.loadedPosition = stream.readInt();
this.lifetime = stream.readFloat();
this.time = stream.readFloat();
@@ -143,6 +143,11 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
return liquid.flammability * amount;
}
@Override
public byte version(){
return 0;
}
@Override
public void hitbox(Rectangle rectangle){
rectangle.setCenter(x, y).setSize(tilesize);
@@ -245,7 +250,7 @@ public class Puddle extends SolidEntity implements SaveTrait, Poolable, DrawTrai
}
@Override
public void readSave(DataInput stream) throws IOException{
public void readSave(DataInput stream, byte version) throws IOException{
this.loadedPosition = stream.readInt();
this.x = stream.readFloat();
this.y = stream.readFloat();
@@ -4,4 +4,5 @@ package io.anuke.mindustry.entities.traits;
* Marks an entity as serializable.
*/
public interface SaveTrait extends Entity, TypeTrait, Saveable{
byte version();
}
@@ -4,6 +4,5 @@ import java.io.*;
public interface Saveable{
void writeSave(DataOutput stream) throws IOException;
void readSave(DataInput stream) throws IOException;
void readSave(DataInput stream, byte version) throws IOException;
}
@@ -41,15 +41,6 @@ public interface SyncTrait extends Entity, TypeTrait{
return true;
}
/** Whether this entity is clipped and not synced when out of viewport. */
default boolean isClipped(){
return true;
}
default float clipSize(){
return (this instanceof DrawTrait ? ((DrawTrait)this).drawSize() : 8f);
}
//Read and write sync data, usually position
void write(DataOutput data) throws IOException;
@@ -23,9 +23,7 @@ public interface TypeTrait{
lastRegisteredID[0]++;
}
/**
* Registers a syncable type by ID.
*/
/**Gets a syncable type by ID.*/
static Supplier<? extends TypeTrait> getTypeByID(int id){
if(id == -1){
throw new IllegalArgumentException("Attempt to retrieve invalid entity type ID! Did you forget to set it in ContentLoader.registerTypes()?");
@@ -304,11 +304,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return type.hitsize * 10;
}
@Override
public float clipSize(){
return isBoss() ? 10000000000f : super.clipSize();
}
@Override
public void onDeath(){
Call.onUnitDeath(this);
@@ -336,6 +331,11 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return unitGroups[team.ordinal()];
}
@Override
public byte version(){
return 0;
}
@Override
public void writeSave(DataOutput stream) throws IOException{
super.writeSave(stream);
@@ -344,8 +344,8 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
}
@Override
public void readSave(DataInput stream) throws IOException{
super.readSave(stream);
public void readSave(DataInput stream, byte version) throws IOException{
super.readSave(stream, version);
byte type = stream.readByte();
this.spawner = stream.readInt();
@@ -363,7 +363,9 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
@Override
public void read(DataInput data) throws IOException{
float lastx = x, lasty = y, lastrot = rotation;
super.readSave(data);
super.readSave(data, version());
this.type = content.getByID(ContentType.unit, data.readByte());
this.spawner = data.readInt();
@@ -817,8 +817,8 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
//region read and write methods
@Override
public boolean isClipped(){
return false;
public byte version(){
return 0;
}
@Override
@@ -833,7 +833,7 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
}
@Override
public void readSave(DataInput stream) throws IOException{
public void readSave(DataInput stream, byte version) throws IOException{
boolean local = stream.readBoolean();
if(local){
@@ -844,14 +844,14 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
lastSpawner = (SpawnerTrait)stile.entity;
}
Player player = headless ? this : Vars.player;
player.readSaveSuper(stream);
player.readSaveSuper(stream, version);
player.mech = content.getByID(ContentType.mech, mechid);
player.dead = false;
}
}
private void readSaveSuper(DataInput stream) throws IOException{
super.readSave(stream);
private void readSaveSuper(DataInput stream, byte version) throws IOException{
super.readSave(stream, version);
add();
}
@@ -873,7 +873,9 @@ public class Player extends Unit implements BuilderTrait, ShooterTrait{
@Override
public void read(DataInput buffer) throws IOException{
float lastx = x, lasty = y, lastrot = rotation, lastvx = velocity.x, lastvy = velocity.y;
super.readSave(buffer);
super.readSave(buffer, version());
name = TypeIO.readStringData(buffer);
byte bools = buffer.readByte();
isAdmin = (bools & 1) != 0;
@@ -124,7 +124,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
}
@CallSuper
public void read(DataInput stream) throws IOException{
public void read(DataInput stream, byte revision) throws IOException{
health = stream.readUnsignedShort();
byte tr = stream.readByte();
byte team = Pack.leftByte(tr);
@@ -139,6 +139,11 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
if(cons != null) cons.read(stream);
}
/** Returns the version of this TileEntity IO code.*/
public byte version(){
return 0;
}
public boolean collide(Bullet other){
return true;
}
@@ -138,7 +138,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
@Override
public void readSave(DataInput stream) throws IOException{
public void readSave(DataInput stream, byte version) throws IOException{
byte team = stream.readByte();
boolean dead = stream.readBoolean();
float x = stream.readFloat();
@@ -150,7 +150,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
byte itemID = stream.readByte();
short itemAmount = stream.readShort();
this.status.readSave(stream);
this.status.readSave(stream, version);
this.item.amount = itemAmount;
this.item.item = content.item(itemID);
this.dead = dead;
@@ -130,7 +130,7 @@ public class Statuses implements Saveable{
}
@Override
public void readSave(DataInput stream) throws IOException{
public void readSave(DataInput stream, byte version) throws IOException{
for(StatusEntry effect : statuses){
Pools.free(effect);
}