Updated saving to DataOutput/Input
This commit is contained in:
@@ -30,10 +30,7 @@ import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -574,7 +571,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
//region read and write methods
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutputStream stream) throws IOException {
|
||||
public void writeSave(DataOutput stream) throws IOException {
|
||||
stream.writeBoolean(isLocal);
|
||||
|
||||
if(isLocal){
|
||||
@@ -589,7 +586,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSave(DataInputStream stream) throws IOException {
|
||||
public void readSave(DataInput stream) throws IOException {
|
||||
boolean local = stream.readBoolean();
|
||||
|
||||
if(local){
|
||||
@@ -598,7 +595,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
}
|
||||
}
|
||||
|
||||
private void readSaveSuper(DataInputStream stream) throws IOException {
|
||||
private void readSaveSuper(DataInput stream) throws IOException {
|
||||
super.readSave(stream);
|
||||
|
||||
byte uamount = stream.readByte();
|
||||
@@ -610,12 +607,12 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
public void write(DataOutput buffer) {
|
||||
//todo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer, long time) {
|
||||
public void read(DataInput buffer, long time) {
|
||||
//todo
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.state;
|
||||
@@ -96,7 +96,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutputStream stream) throws IOException {
|
||||
public void writeSave(DataOutput stream) throws IOException {
|
||||
stream.writeByte(team.ordinal());
|
||||
stream.writeFloat(x);
|
||||
stream.writeFloat(y);
|
||||
@@ -107,7 +107,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSave(DataInputStream stream) throws IOException {
|
||||
public void readSave(DataInput stream) throws IOException {
|
||||
byte team = stream.readByte();
|
||||
float x = stream.readFloat();
|
||||
float y = stream.readFloat();
|
||||
|
||||
@@ -6,9 +6,7 @@ import io.anuke.mindustry.type.AmmoType;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
|
||||
public class UnitInventory {
|
||||
private Array<AmmoEntry> ammos = new Array<>();
|
||||
@@ -31,7 +29,7 @@ public class UnitInventory {
|
||||
infiniteAmmo = infinite;
|
||||
}
|
||||
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
public void write(DataOutput stream) throws IOException {
|
||||
stream.writeInt(item == null ? 0 : item.amount);
|
||||
stream.writeByte(item == null ? 0 : item.item.id);
|
||||
stream.writeBoolean(infiniteAmmo);
|
||||
@@ -43,7 +41,7 @@ public class UnitInventory {
|
||||
}
|
||||
}
|
||||
|
||||
public void read(DataInputStream stream) throws IOException {
|
||||
public void read(DataInput stream) throws IOException {
|
||||
int iamount = stream.readInt();
|
||||
byte iid = stream.readByte();
|
||||
infiniteAmmo = stream.readBoolean();
|
||||
|
||||
@@ -15,7 +15,9 @@ import io.anuke.ucore.entities.trait.SolidTrait;
|
||||
import io.anuke.ucore.entities.trait.VelocityTrait;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.bulletGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
@@ -70,19 +72,19 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer data) {
|
||||
data.putFloat(x);
|
||||
data.putFloat(y);
|
||||
data.put((byte)team.ordinal());
|
||||
data.put((byte)type.id);
|
||||
public void write(DataOutput data) throws IOException{
|
||||
data.writeFloat(x);
|
||||
data.writeFloat(y);
|
||||
data.writeByte(team.ordinal());
|
||||
data.writeByte(type.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer data, long time) {
|
||||
x = data.getFloat();
|
||||
y = data.getFloat();
|
||||
team = Team.values()[data.get()];
|
||||
type = BulletType.getByID(data.get());
|
||||
public void read(DataInput data, long time) throws IOException{
|
||||
x = data.readFloat();
|
||||
y = data.readFloat();
|
||||
team = Team.values()[data.readByte()];
|
||||
type = BulletType.getByID(data.readByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,8 +18,8 @@ import io.anuke.ucore.entities.impl.TimedEntity;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
@@ -115,14 +115,14 @@ public class Fire extends TimedEntity implements SaveTrait, Poolable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutputStream stream) throws IOException {
|
||||
public void writeSave(DataOutput stream) throws IOException {
|
||||
stream.writeInt(tile.packedPosition());
|
||||
stream.writeFloat(lifetime);
|
||||
stream.writeFloat(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSave(DataInputStream stream) throws IOException {
|
||||
public void readSave(DataInput stream) throws IOException {
|
||||
this.loadedPosition = stream.readInt();
|
||||
this.lifetime = stream.readFloat();
|
||||
this.time = stream.readFloat();
|
||||
|
||||
@@ -20,7 +20,9 @@ import io.anuke.ucore.entities.trait.VelocityTrait;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.itemGroup;
|
||||
import static io.anuke.mindustry.Vars.itemSize;
|
||||
@@ -156,16 +158,16 @@ public class ItemDrop extends SolidEntity implements SyncTrait, DrawTrait, Veloc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer data) {
|
||||
data.putFloat(x);
|
||||
data.putFloat(y);
|
||||
data.put((byte)item.id);
|
||||
public void write(DataOutput data) throws IOException{
|
||||
data.writeFloat(x);
|
||||
data.writeFloat(y);
|
||||
data.writeByte(item.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer data, long time) {
|
||||
x = data.getFloat();
|
||||
y = data.getFloat();
|
||||
item = Item.getByID(data.get());
|
||||
public void read(DataInput data, long time) throws IOException{
|
||||
x = data.readFloat();
|
||||
y = data.readFloat();
|
||||
item = Item.getByID(data.readByte());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.puddleGroup;
|
||||
@@ -202,7 +202,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutputStream stream) throws IOException {
|
||||
public void writeSave(DataOutput stream) throws IOException {
|
||||
stream.writeInt(tile.packedPosition());
|
||||
stream.writeFloat(x);
|
||||
stream.writeFloat(y);
|
||||
@@ -212,7 +212,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSave(DataInputStream stream) throws IOException {
|
||||
public void readSave(DataInput stream) throws IOException {
|
||||
this.loadedPosition = stream.readInt();
|
||||
this.x = stream.readFloat();
|
||||
this.y = stream.readFloat();
|
||||
|
||||
@@ -2,12 +2,12 @@ package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import io.anuke.ucore.entities.trait.Entity;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**Marks an entity as serializable.*/
|
||||
public interface SaveTrait extends Entity{
|
||||
void writeSave(DataOutputStream stream) throws IOException;
|
||||
void readSave(DataInputStream stream) throws IOException;
|
||||
void writeSave(DataOutput stream) throws IOException;
|
||||
void readSave(DataInput stream) throws IOException;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import com.badlogic.gdx.Gdx;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
import io.anuke.ucore.entities.trait.Entity;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.threads;
|
||||
|
||||
@@ -36,6 +38,6 @@ public interface SyncTrait extends Entity {
|
||||
Interpolator getInterpolator();
|
||||
|
||||
//Read and write sync data, usually position
|
||||
void write(ByteBuffer data);
|
||||
void read(ByteBuffer data, long time);
|
||||
void write(DataOutput data) throws IOException;
|
||||
void read(DataInput data, long time) throws IOException;
|
||||
}
|
||||
|
||||
@@ -21,10 +21,7 @@ import io.anuke.ucore.util.Geometry;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
import io.anuke.ucore.util.Timer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -236,13 +233,13 @@ public abstract class BaseUnit extends Unit{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSave(DataOutputStream stream) throws IOException {
|
||||
public void writeSave(DataOutput stream) throws IOException {
|
||||
super.writeSave(stream);
|
||||
stream.writeByte(type.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSave(DataInputStream stream) throws IOException {
|
||||
public void readSave(DataInput stream) throws IOException {
|
||||
super.readSave(stream);
|
||||
byte type = stream.readByte();
|
||||
|
||||
@@ -251,12 +248,12 @@ public abstract class BaseUnit extends Unit{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer data) {
|
||||
public void write(DataOutput data) {
|
||||
//todo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer data, long time) {
|
||||
public void read(DataInput data, long time) {
|
||||
//todo
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user