Better IO
This commit is contained in:
@@ -121,8 +121,7 @@ public class NetClient implements ApplicationListener{
|
||||
});
|
||||
|
||||
net.handleClient(InvokePacket.class, packet -> {
|
||||
packet.writeBuffer.position(0);
|
||||
RemoteReadClient.readPacket(packet.writeBuffer, packet.type);
|
||||
RemoteReadClient.readPacket(packet.reader(), packet.type);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -377,7 +376,7 @@ public class NetClient implements ApplicationListener{
|
||||
}
|
||||
|
||||
//read the entity
|
||||
entity.read(input);
|
||||
entity.read(Reads.get(input));
|
||||
|
||||
if(created && entity.interpolator().target != null){
|
||||
//set initial starting position
|
||||
@@ -407,7 +406,7 @@ public class NetClient implements ApplicationListener{
|
||||
Log.warn("Missing entity at {0}. Skipping block snapshot.", tile);
|
||||
break;
|
||||
}
|
||||
tile.entity.read(input, tile.entity.version());
|
||||
tile.entity.read(Reads.get(input), tile.entity.version());
|
||||
}
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
@@ -435,9 +434,9 @@ public class NetClient implements ApplicationListener{
|
||||
Tile tile = world.tile(pos);
|
||||
|
||||
if(tile != null && tile.entity != null){
|
||||
tile.entity.items().read(input);
|
||||
tile.entity.items().read(Reads.get(input));
|
||||
}else{
|
||||
new ItemModule().read(input);
|
||||
new ItemModule().read(Reads.get(input));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ public class NetServer implements ApplicationListener{
|
||||
private boolean closing = false;
|
||||
private Interval timer = new Interval();
|
||||
|
||||
private ByteBuffer writeBuffer = ByteBuffer.allocate(127);
|
||||
private ByteBufferOutput outputBuffer = new ByteBufferOutput(writeBuffer);
|
||||
private ReusableByteOutStream writeBuffer = new ReusableByteOutStream(127);
|
||||
private Writes outputBuffer = new Writes(new DataOutputStream(writeBuffer));
|
||||
|
||||
/** Stream for writing player sync data to. */
|
||||
private ReusableByteOutStream syncStream = new ReusableByteOutStream();
|
||||
@@ -214,7 +214,7 @@ public class NetServer implements ApplicationListener{
|
||||
}
|
||||
|
||||
try{
|
||||
writeBuffer.position(0);
|
||||
writeBuffer.reset();
|
||||
player.write(outputBuffer);
|
||||
}catch(Throwable t){
|
||||
t.printStackTrace();
|
||||
@@ -237,7 +237,7 @@ public class NetServer implements ApplicationListener{
|
||||
net.handleServer(InvokePacket.class, (con, packet) -> {
|
||||
if(con.player == null) return;
|
||||
try{
|
||||
RemoteReadServer.readPacket(packet.writeBuffer, packet.type, con.player);
|
||||
RemoteReadServer.readPacket(packet.reader(), packet.type, con.player);
|
||||
}catch(ValidateException e){
|
||||
Log.debug("Validation failed for '{0}': {1}", e.player, e.getMessage());
|
||||
}catch(RuntimeException e){
|
||||
@@ -704,7 +704,7 @@ public class NetServer implements ApplicationListener{
|
||||
sent ++;
|
||||
|
||||
dataStream.writeInt(entity.tile().pos());
|
||||
entity.write(dataStream);
|
||||
entity.write(Writes.get(dataStream));
|
||||
|
||||
if(syncStream.size() > maxSnapshotSize){
|
||||
dataStream.close();
|
||||
@@ -730,7 +730,7 @@ public class NetServer implements ApplicationListener{
|
||||
|
||||
for(CoreEntity entity : cores){
|
||||
dataStream.writeInt(entity.tile().pos());
|
||||
entity.items().write(dataStream);
|
||||
entity.items().write(Writes.get(dataStream));
|
||||
}
|
||||
|
||||
dataStream.close();
|
||||
@@ -749,7 +749,7 @@ public class NetServer implements ApplicationListener{
|
||||
//write all entities now
|
||||
dataStream.writeInt(entity.id()); //write id
|
||||
dataStream.writeByte(entity.classId()); //write type ID
|
||||
entity.write(dataStream); //write entity
|
||||
entity.write(Writes.get(dataStream)); //write entity
|
||||
|
||||
sent++;
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.player;
|
||||
|
||||
@Component
|
||||
@@ -53,11 +52,11 @@ abstract class EntityComp{
|
||||
abstract boolean serialize();
|
||||
|
||||
@MethodPriority(1)
|
||||
void read(DataInput input) throws IOException{
|
||||
void read(Reads read){
|
||||
afterRead();
|
||||
}
|
||||
|
||||
void write(DataOutput output) throws IOException{
|
||||
void write(Writes write){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import mindustry.gen.*;
|
||||
|
||||
@Component
|
||||
abstract class MassComp implements Velc{
|
||||
float mass = 1f;
|
||||
transient float mass = 1f;
|
||||
|
||||
public void impulse(float x, float y){
|
||||
vel().add(x / mass, y / mass);
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
@@ -13,8 +14,6 @@ import mindustry.world.*;
|
||||
import mindustry.world.consumers.*;
|
||||
import mindustry.world.modules.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@EntityDef(value = {Tilec.class}, isFinal = false, genio = false, serialize = false)
|
||||
@@ -63,30 +62,30 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
public void write(DataOutput output) throws IOException{
|
||||
output.writeFloat(health());
|
||||
output.writeByte(tile.rotation());
|
||||
output.writeByte(tile.getTeamID());
|
||||
if(items != null) items.write(output);
|
||||
if(power != null) power.write(output);
|
||||
if(liquids != null) liquids.write(output);
|
||||
if(cons != null) cons.write(output);
|
||||
public void write(Writes write){
|
||||
write.f(health());
|
||||
write.b(tile.rotation());
|
||||
write.b(tile.getTeamID());
|
||||
if(items != null) items.write(write);
|
||||
if(power != null) power.write(write);
|
||||
if(liquids != null) liquids.write(write);
|
||||
if(cons != null) cons.write(write);
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void read(DataInput input, byte revision) throws IOException{
|
||||
health(input.readFloat());
|
||||
byte rotation = input.readByte();
|
||||
byte team = input.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
health(read.f());
|
||||
byte rotation = read.b();
|
||||
byte team = read.b();
|
||||
|
||||
tile.setTeam(Team.get(team));
|
||||
tile.rotation(rotation);
|
||||
|
||||
if(items != null) items.read(input);
|
||||
if(power != null) power.read(input);
|
||||
if(liquids != null) liquids.read(input);
|
||||
if(cons != null) cons.read(input);
|
||||
if(items != null) items.read(read);
|
||||
if(power != null) power.read(read);
|
||||
if(liquids != null) liquids.read(read);
|
||||
if(cons != null) cons.read(read);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,7 @@ abstract class VelComp implements Posc{
|
||||
@Import float x, y;
|
||||
|
||||
final Vec2 vel = new Vec2();
|
||||
float drag = 0f;
|
||||
transient float drag = 0f;
|
||||
|
||||
//velocity needs to be called first, as it affects delta and lastPosition
|
||||
@MethodPriority(-1)
|
||||
|
||||
@@ -125,7 +125,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
if(tile.entity != null){
|
||||
writeChunk(stream, true, out -> {
|
||||
out.writeByte(tile.entity.version());
|
||||
tile.entity.write(out);
|
||||
tile.entity.write(Writes.get(out));
|
||||
});
|
||||
}else{
|
||||
//write consecutive non-entity blocks
|
||||
@@ -188,7 +188,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
try{
|
||||
readChunk(stream, true, in -> {
|
||||
byte revision = in.readByte();
|
||||
tile.entity.read(in, revision);
|
||||
tile.entity.read(Reads.get(in), revision);
|
||||
});
|
||||
}catch(Exception e){
|
||||
throw new IOException("Failed to read tile entity of block: " + block, e);
|
||||
@@ -231,7 +231,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
|
||||
writeChunk(stream, true, out -> {
|
||||
out.writeByte(entity.classId());
|
||||
entity.write(out);
|
||||
entity.write(Writes.get(out));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -253,7 +253,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
||||
readChunk(stream, true, in -> {
|
||||
byte typeid = in.readByte();
|
||||
Syncc sync = (Syncc)EntityMapping.map(typeid).get();
|
||||
sync.read(in);
|
||||
sync.read(Reads.get(in));
|
||||
sync.add();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.io;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
@@ -19,60 +20,53 @@ import static mindustry.Vars.*;
|
||||
|
||||
/** Class for specifying read/write methods for code generation. */
|
||||
@SuppressWarnings("unused")
|
||||
@TypeIOHandler
|
||||
public class TypeIO{
|
||||
|
||||
@WriteClass(Entityc.class)
|
||||
public static void writeEntity(ByteBuffer buffer, Entityc entity){
|
||||
buffer.putInt(entity == null ? -1 : entity.id());
|
||||
public static void writeEntity(Writes write, Entityc entity){
|
||||
write.i(entity == null ? -1 : entity.id());
|
||||
}
|
||||
|
||||
@ReadClass(Entityc.class)
|
||||
public static <T extends Entityc> T readEntity(ByteBuffer buffer){
|
||||
return (T)Groups.all.getByID(buffer.getInt());
|
||||
public static <T extends Entityc> T readEntity(Reads read){
|
||||
return (T)Groups.all.getByID(read.i());
|
||||
}
|
||||
|
||||
@WriteClass(Tile.class)
|
||||
public static void writeTile(ByteBuffer buffer, Tile tile){
|
||||
buffer.putInt(tile == null ? Pos.get(-1, -1) : tile.pos());
|
||||
public static void writeTile(Writes write, Tile tile){
|
||||
write.i(tile == null ? Pos.get(-1, -1) : tile.pos());
|
||||
}
|
||||
|
||||
@ReadClass(Tile.class)
|
||||
public static Tile readTile(ByteBuffer buffer){
|
||||
return world.tile(buffer.getInt());
|
||||
public static Tile readTile(Reads read){
|
||||
return world.tile(read.i());
|
||||
}
|
||||
|
||||
@WriteClass(Block.class)
|
||||
public static void writeBlock(ByteBuffer buffer, Block block){
|
||||
buffer.putShort(block.id);
|
||||
public static void writeBlock(Writes write, Block block){
|
||||
write.s(block.id);
|
||||
}
|
||||
|
||||
@ReadClass(Block.class)
|
||||
public static Block readBlock(ByteBuffer buffer){
|
||||
return content.block(buffer.getShort());
|
||||
public static Block readBlock(Reads read){
|
||||
return content.block(read.s());
|
||||
}
|
||||
|
||||
@WriteClass(BuildRequest[].class)
|
||||
public static void writeRequests(ByteBuffer buffer, BuildRequest[] requests){
|
||||
buffer.putShort((short)requests.length);
|
||||
public static void writeRequests(Writes write, BuildRequest[] requests){
|
||||
write.s((short)requests.length);
|
||||
for(BuildRequest request : requests){
|
||||
buffer.put(request.breaking ? (byte)1 : 0);
|
||||
buffer.putInt(Pos.get(request.x, request.y));
|
||||
write.b(request.breaking ? (byte)1 : 0);
|
||||
write.i(Pos.get(request.x, request.y));
|
||||
if(!request.breaking){
|
||||
buffer.putShort(request.block.id);
|
||||
buffer.put((byte)request.rotation);
|
||||
buffer.put(request.hasConfig ? (byte)1 : 0);
|
||||
buffer.putInt(request.config);
|
||||
write.s(request.block.id);
|
||||
write.b((byte)request.rotation);
|
||||
write.b(request.hasConfig ? (byte)1 : 0);
|
||||
write.i(request.config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ReadClass(BuildRequest[].class)
|
||||
public static BuildRequest[] readRequests(ByteBuffer buffer){
|
||||
short reqamount = buffer.getShort();
|
||||
public static BuildRequest[] readRequests(Reads read){
|
||||
short reqamount = read.s();
|
||||
BuildRequest[] reqs = new BuildRequest[reqamount];
|
||||
for(int i = 0; i < reqamount; i++){
|
||||
byte type = buffer.get();
|
||||
int position = buffer.getInt();
|
||||
byte type = read.b();
|
||||
int position = read.i();
|
||||
BuildRequest currentRequest;
|
||||
|
||||
if(world.tile(position) == null){
|
||||
@@ -82,10 +76,10 @@ public class TypeIO{
|
||||
if(type == 1){ //remove
|
||||
currentRequest = new BuildRequest(Pos.x(position), Pos.y(position));
|
||||
}else{ //place
|
||||
short block = buffer.getShort();
|
||||
byte rotation = buffer.get();
|
||||
boolean hasConfig = buffer.get() == 1;
|
||||
int config = buffer.getInt();
|
||||
short block = read.s();
|
||||
byte rotation = read.b();
|
||||
boolean hasConfig = read.b() == 1;
|
||||
int config = read.i();
|
||||
currentRequest = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.block(block));
|
||||
if(hasConfig){
|
||||
currentRequest.configure(config);
|
||||
@@ -98,163 +92,152 @@ public class TypeIO{
|
||||
return reqs;
|
||||
}
|
||||
|
||||
@WriteClass(KickReason.class)
|
||||
public static void writeKick(ByteBuffer buffer, KickReason reason){
|
||||
buffer.put((byte)reason.ordinal());
|
||||
public static void writeKick(Writes write, KickReason reason){
|
||||
write.b((byte)reason.ordinal());
|
||||
}
|
||||
|
||||
@ReadClass(KickReason.class)
|
||||
public static KickReason readKick(ByteBuffer buffer){
|
||||
return KickReason.values()[buffer.get()];
|
||||
public static KickReason readKick(Reads read){
|
||||
return KickReason.values()[read.b()];
|
||||
}
|
||||
|
||||
@WriteClass(Rules.class)
|
||||
public static void writeRules(ByteBuffer buffer, Rules rules){
|
||||
public static void writeRules(Writes write, Rules rules){
|
||||
String string = JsonIO.write(rules);
|
||||
byte[] bytes = string.getBytes(charset);
|
||||
buffer.putInt(bytes.length);
|
||||
buffer.put(bytes);
|
||||
write.i(bytes.length);
|
||||
write.b(bytes);
|
||||
}
|
||||
|
||||
@ReadClass(Rules.class)
|
||||
public static Rules readRules(ByteBuffer buffer){
|
||||
int length = buffer.getInt();
|
||||
byte[] bytes = new byte[length];
|
||||
buffer.get(bytes);
|
||||
String string = new String(bytes, charset);
|
||||
public static Rules readRules(Reads read){
|
||||
int length = read.i();
|
||||
String string = new String(read.b(new byte[length]), charset);
|
||||
return JsonIO.read(Rules.class, string);
|
||||
}
|
||||
|
||||
@WriteClass(Team.class)
|
||||
public static void writeTeam(ByteBuffer buffer, Team reason){
|
||||
buffer.put((byte) (int)reason.id);
|
||||
public static void writeTeam(Writes write, Team reason){
|
||||
write.b((byte) (int)reason.id);
|
||||
}
|
||||
|
||||
@ReadClass(Team.class)
|
||||
public static Team readTeam(ByteBuffer buffer){
|
||||
return Team.get(buffer.get());
|
||||
public static Team readTeam(Reads read){
|
||||
return Team.get(read.b());
|
||||
}
|
||||
|
||||
@WriteClass(UnitCommand.class)
|
||||
public static void writeUnitCommand(ByteBuffer buffer, UnitCommand reason){
|
||||
buffer.put((byte)reason.ordinal());
|
||||
public static void writeUnitCommand(Writes write, UnitCommand reason){
|
||||
write.b((byte)reason.ordinal());
|
||||
}
|
||||
|
||||
@ReadClass(UnitCommand.class)
|
||||
public static UnitCommand readUnitCommand(ByteBuffer buffer){
|
||||
return UnitCommand.all[buffer.get()];
|
||||
public static UnitCommand readUnitCommand(Reads read){
|
||||
return UnitCommand.all[read.b()];
|
||||
}
|
||||
|
||||
@WriteClass(AdminAction.class)
|
||||
public static void writeAction(ByteBuffer buffer, AdminAction reason){
|
||||
buffer.put((byte)reason.ordinal());
|
||||
public static void writeAction(Writes write, AdminAction reason){
|
||||
write.b((byte)reason.ordinal());
|
||||
}
|
||||
|
||||
@ReadClass(AdminAction.class)
|
||||
public static AdminAction readAction(ByteBuffer buffer){
|
||||
return AdminAction.values()[buffer.get()];
|
||||
public static AdminAction readAction(Reads read){
|
||||
return AdminAction.values()[read.b()];
|
||||
}
|
||||
|
||||
@WriteClass(UnitType.class)
|
||||
public static void writeUnitDef(ByteBuffer buffer, UnitType effect){
|
||||
buffer.putShort(effect.id);
|
||||
public static void writeUnitDef(Writes write, UnitType effect){
|
||||
write.s(effect.id);
|
||||
}
|
||||
|
||||
@ReadClass(UnitType.class)
|
||||
public static UnitType readUnitDef(ByteBuffer buffer){
|
||||
return content.getByID(ContentType.unit, buffer.getShort());
|
||||
public static UnitType readUnitDef(Reads read){
|
||||
return content.getByID(ContentType.unit, read.s());
|
||||
}
|
||||
|
||||
@WriteClass(Color.class)
|
||||
public static void writeColor(ByteBuffer buffer, Color color){
|
||||
buffer.putInt(Color.rgba8888(color));
|
||||
public static void writeColor(Writes write, Color color){
|
||||
write.i(Color.rgba8888(color));
|
||||
}
|
||||
|
||||
@ReadClass(Color.class)
|
||||
public static Color readColor(ByteBuffer buffer){
|
||||
return new Color(buffer.getInt());
|
||||
public static Color readColor(Reads read){
|
||||
return new Color(read.i());
|
||||
}
|
||||
|
||||
@WriteClass(Liquid.class)
|
||||
public static void writeLiquid(ByteBuffer buffer, Liquid liquid){
|
||||
buffer.putShort(liquid == null ? -1 : liquid.id);
|
||||
public static void writeLiquid(Writes write, Liquid liquid){
|
||||
write.s(liquid == null ? -1 : liquid.id);
|
||||
}
|
||||
|
||||
@ReadClass(Liquid.class)
|
||||
public static Liquid readLiquid(ByteBuffer buffer){
|
||||
short id = buffer.getShort();
|
||||
public static Liquid readLiquid(Reads read){
|
||||
short id = read.s();
|
||||
return id == -1 ? null : content.liquid(id);
|
||||
}
|
||||
|
||||
@WriteClass(BulletType.class)
|
||||
public static void writeBulletType(ByteBuffer buffer, BulletType type){
|
||||
buffer.putShort(type.id);
|
||||
public static void writeBulletType(Writes write, BulletType type){
|
||||
write.s(type.id);
|
||||
}
|
||||
|
||||
@ReadClass(BulletType.class)
|
||||
public static BulletType readBulletType(ByteBuffer buffer){
|
||||
return content.getByID(ContentType.bullet, buffer.getShort());
|
||||
public static BulletType readBulletType(Reads read){
|
||||
return content.getByID(ContentType.bullet, read.s());
|
||||
}
|
||||
|
||||
@WriteClass(Item.class)
|
||||
public static void writeItem(ByteBuffer buffer, Item item){
|
||||
buffer.putShort(item == null ? -1 : item.id);
|
||||
public static void writeItem(Writes write, Item item){
|
||||
write.s(item == null ? -1 : item.id);
|
||||
}
|
||||
|
||||
@ReadClass(Item.class)
|
||||
public static Item readItem(ByteBuffer buffer){
|
||||
short id = buffer.getShort();
|
||||
public static Item readItem(Reads read){
|
||||
short id = read.s();
|
||||
return id == -1 ? null : content.item(id);
|
||||
}
|
||||
|
||||
@WriteClass(String.class)
|
||||
public static void writeString(ByteBuffer buffer, String string){
|
||||
public static void writeString(Writes write, String string){
|
||||
if(string != null){
|
||||
byte[] bytes = string.getBytes(charset);
|
||||
buffer.putShort((short)bytes.length);
|
||||
buffer.put(bytes);
|
||||
write.s((short)bytes.length);
|
||||
write.b(bytes);
|
||||
}else{
|
||||
buffer.putShort((short)-1);
|
||||
write.s((short)-1);
|
||||
}
|
||||
}
|
||||
|
||||
@ReadClass(String.class)
|
||||
public static String readString(ByteBuffer buffer){
|
||||
short slength = buffer.getShort();
|
||||
public static String readString(Reads read){
|
||||
short slength = read.s();
|
||||
if(slength != -1){
|
||||
return new String(read.b(new byte[slength]), charset);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeString(ByteBuffer write, String string){
|
||||
if(string != null){
|
||||
byte[] bytes = string.getBytes(charset);
|
||||
write.putShort((short)bytes.length);
|
||||
write.put(bytes);
|
||||
}else{
|
||||
write.putShort((short)-1);
|
||||
}
|
||||
}
|
||||
|
||||
public static String readString(ByteBuffer read){
|
||||
short slength = read.getShort();
|
||||
if(slength != -1){
|
||||
byte[] bytes = new byte[slength];
|
||||
buffer.get(bytes);
|
||||
read.get(bytes);
|
||||
return new String(bytes, charset);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@WriteClass(byte[].class)
|
||||
public static void writeBytes(ByteBuffer buffer, byte[] bytes){
|
||||
buffer.putShort((short)bytes.length);
|
||||
buffer.put(bytes);
|
||||
public static void writeBytes(Writes write, byte[] bytes){
|
||||
write.s((short)bytes.length);
|
||||
write.b(bytes);
|
||||
}
|
||||
|
||||
@ReadClass(byte[].class)
|
||||
public static byte[] readBytes(ByteBuffer buffer){
|
||||
short length = buffer.getShort();
|
||||
byte[] bytes = new byte[length];
|
||||
buffer.get(bytes);
|
||||
return bytes;
|
||||
public static byte[] readBytes(Reads read){
|
||||
short length = read.s();
|
||||
return read.b(new byte[length]);
|
||||
}
|
||||
|
||||
@WriteClass(TraceInfo.class)
|
||||
public static void writeTraceInfo(ByteBuffer buffer, TraceInfo trace){
|
||||
writeString(buffer, trace.ip);
|
||||
writeString(buffer, trace.uuid);
|
||||
buffer.put(trace.modded ? (byte)1 : 0);
|
||||
buffer.put(trace.mobile ? (byte)1 : 0);
|
||||
public static void writeTraceInfo(Writes write, TraceInfo trace){
|
||||
writeString(write, trace.ip);
|
||||
writeString(write, trace.uuid);
|
||||
write.b(trace.modded ? (byte)1 : 0);
|
||||
write.b(trace.mobile ? (byte)1 : 0);
|
||||
}
|
||||
|
||||
@ReadClass(TraceInfo.class)
|
||||
public static TraceInfo readTraceInfo(ByteBuffer buffer){
|
||||
return new TraceInfo(readString(buffer), readString(buffer), buffer.get() == 1, buffer.get() == 1);
|
||||
public static TraceInfo readTraceInfo(Reads read){
|
||||
return new TraceInfo(readString(read), readString(read), read.b() == 1, read.b() == 1);
|
||||
}
|
||||
|
||||
public static void writeStringData(DataOutput buffer, String string) throws IOException{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package mindustry.net;
|
||||
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.io.*;
|
||||
import mindustry.maps.Map;
|
||||
import mindustry.net.Administration.*;
|
||||
@@ -26,7 +27,7 @@ public class NetworkIO{
|
||||
stream.writeFloat(state.wavetime);
|
||||
|
||||
stream.writeInt(player.id());
|
||||
player.write(stream);
|
||||
player.write(Writes.get(stream));
|
||||
|
||||
SaveIO.getSaveWriter().writeContentHeader(stream);
|
||||
SaveIO.getSaveWriter().writeMap(stream);
|
||||
@@ -48,7 +49,7 @@ public class NetworkIO{
|
||||
Groups.all.clear();
|
||||
int id = stream.readInt();
|
||||
player.reset();
|
||||
player.read(stream);
|
||||
player.read(Reads.get(stream));
|
||||
player.id(id);
|
||||
player.add();
|
||||
|
||||
|
||||
@@ -2,10 +2,12 @@ package mindustry.net;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.serialization.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.io.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
|
||||
/**
|
||||
@@ -65,31 +67,29 @@ public class Packets{
|
||||
}
|
||||
|
||||
public static class InvokePacket implements Packet{
|
||||
private static ReusableByteInStream bin;
|
||||
private static Reads read = new Reads(new DataInputStream(bin = new ReusableByteInStream()));
|
||||
|
||||
public byte type, priority;
|
||||
|
||||
public ByteBuffer writeBuffer;
|
||||
public int writeLength;
|
||||
public byte[] bytes;
|
||||
public int length;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer){
|
||||
type = buffer.get();
|
||||
priority = buffer.get();
|
||||
writeLength = buffer.getShort();
|
||||
short writeLength = buffer.getShort();
|
||||
byte[] bytes = new byte[writeLength];
|
||||
buffer.get(bytes);
|
||||
writeBuffer = ByteBuffer.wrap(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer){
|
||||
buffer.put(type);
|
||||
buffer.put(priority);
|
||||
buffer.putShort((short)writeLength);
|
||||
|
||||
writeBuffer.position(0);
|
||||
for(int i = 0; i < writeLength; i++){
|
||||
buffer.put(writeBuffer.get());
|
||||
}
|
||||
buffer.putShort((short)length);
|
||||
buffer.put(bytes, 0, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,6 +106,11 @@ public class Packets{
|
||||
public boolean isUnimportant(){
|
||||
return priority == 2;
|
||||
}
|
||||
|
||||
public Reads reader(){
|
||||
bin.setBytes(bytes);
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
/** Marks the beginning of a stream. */
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package mindustry.world;
|
||||
|
||||
import mindustry.annotations.Annotations.Struct;
|
||||
import arc.util.Time;
|
||||
import mindustry.gen.BufferItem;
|
||||
import mindustry.type.Item;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -46,22 +47,22 @@ public class DirectionalItemBuffer{
|
||||
indexes[buffer] --;
|
||||
}
|
||||
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
public void write(Writes write){
|
||||
for(int i = 0; i < 4; i++){
|
||||
stream.writeByte(indexes[i]);
|
||||
stream.writeByte(buffers[i].length);
|
||||
write.b(indexes[i]);
|
||||
write.b(buffers[i].length);
|
||||
for(long l : buffers[i]){
|
||||
stream.writeLong(l);
|
||||
write.l(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
for(int i = 0; i < 4; i++){
|
||||
indexes[i] = stream.readByte();
|
||||
byte length = stream.readByte();
|
||||
indexes[i] = read.b();
|
||||
byte length = read.b();
|
||||
for(int j = 0; j < length; j++){
|
||||
long value = stream.readLong();
|
||||
long value = read.l();
|
||||
if(j < buffers[i].length){
|
||||
buffers[i][j] = value;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package mindustry.world;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.type.Item;
|
||||
|
||||
import java.io.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
|
||||
@@ -60,19 +59,19 @@ public class ItemBuffer{
|
||||
index--;
|
||||
}
|
||||
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeByte((byte)index);
|
||||
stream.writeByte((byte)buffer.length);
|
||||
public void write(Writes write){
|
||||
write.b((byte)index);
|
||||
write.b((byte)buffer.length);
|
||||
for(long l : buffer){
|
||||
stream.writeLong(l);
|
||||
write.l(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void read(DataInput stream) throws IOException{
|
||||
index = stream.readByte();
|
||||
byte length = stream.readByte();
|
||||
public void read(Reads read){
|
||||
index = read.b();
|
||||
byte length = read.b();
|
||||
for(int i = 0; i < length; i++){
|
||||
long l = stream.readLong();
|
||||
long l = read.l();
|
||||
if(i < buffer.length){
|
||||
buffer[i] = l;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
@@ -347,37 +348,37 @@ public class BuildBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeShort(previous == null ? -1 : previous.id);
|
||||
stream.writeShort(cblock == null ? -1 : cblock.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.s(previous == null ? -1 : previous.id);
|
||||
write.s(cblock == null ? -1 : cblock.id);
|
||||
|
||||
if(accumulator == null){
|
||||
stream.writeByte(-1);
|
||||
write.b(-1);
|
||||
}else{
|
||||
stream.writeByte(accumulator.length);
|
||||
write.b(accumulator.length);
|
||||
for(int i = 0; i < accumulator.length; i++){
|
||||
stream.writeFloat(accumulator[i]);
|
||||
stream.writeFloat(totalAccumulator[i]);
|
||||
write.f(accumulator[i]);
|
||||
write.f(totalAccumulator[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
progress = stream.readFloat();
|
||||
short pid = stream.readShort();
|
||||
short rid = stream.readShort();
|
||||
byte acsize = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
short pid = read.s();
|
||||
short rid = read.s();
|
||||
byte acsize = read.b();
|
||||
|
||||
if(acsize != -1){
|
||||
accumulator = new float[acsize];
|
||||
totalAccumulator = new float[acsize];
|
||||
for(int i = 0; i < acsize; i++){
|
||||
accumulator[i] = stream.readFloat();
|
||||
totalAccumulator[i] = stream.readFloat();
|
||||
accumulator[i] = read.f();
|
||||
totalAccumulator[i] = read.f();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.defense;
|
||||
|
||||
import arc.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.Graphics.*;
|
||||
import arc.Graphics.Cursor.*;
|
||||
@@ -92,15 +93,15 @@ public class Door extends Wall{
|
||||
public boolean open = false;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeBoolean(open);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.bool(open);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
open = stream.readBoolean();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
open = read.bool();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -171,23 +172,23 @@ public class ForceProjector extends Block{
|
||||
float phaseHeat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeBoolean(broken);
|
||||
stream.writeFloat(buildup);
|
||||
stream.writeFloat(radscl);
|
||||
stream.writeFloat(warmup);
|
||||
stream.writeFloat(phaseHeat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.bool(broken);
|
||||
write.f(buildup);
|
||||
write.f(radscl);
|
||||
write.f(warmup);
|
||||
write.f(phaseHeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
broken = stream.readBoolean();
|
||||
buildup = stream.readFloat();
|
||||
radscl = stream.readFloat();
|
||||
warmup = stream.readFloat();
|
||||
phaseHeat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
broken = read.bool();
|
||||
buildup = read.f();
|
||||
radscl = read.f();
|
||||
warmup = read.f();
|
||||
phaseHeat = read.f();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.Color;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -126,17 +127,17 @@ public class MendProjector extends Block{
|
||||
float phaseHeat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(heat);
|
||||
stream.writeFloat(phaseHeat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(heat);
|
||||
write.f(phaseHeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
heat = stream.readFloat();
|
||||
phaseHeat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
heat = read.f();
|
||||
phaseHeat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.Color;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.Mathf;
|
||||
import arc.util.Time;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
@@ -124,17 +125,17 @@ public class OverdriveProjector extends Block{
|
||||
float phaseHeat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(heat);
|
||||
stream.writeFloat(phaseHeat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(heat);
|
||||
write.f(phaseHeat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
heat = stream.readFloat();
|
||||
phaseHeat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
heat = read.f();
|
||||
phaseHeat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mindustry.world.blocks.defense.turrets;
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
@@ -151,23 +152,23 @@ public class ItemTurret extends CooledTurret{
|
||||
|
||||
public class ItemTurretEntity extends TurretEntity{
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(ammo.size);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(ammo.size);
|
||||
for(AmmoEntry entry : ammo){
|
||||
ItemEntry i = (ItemEntry)entry;
|
||||
stream.writeByte(i.item.id);
|
||||
stream.writeShort(i.amount);
|
||||
write.b(i.item.id);
|
||||
write.s(i.amount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
byte amount = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
byte amount = read.b();
|
||||
for(int i = 0; i < amount; i++){
|
||||
Item item = Vars.content.item(stream.readByte());
|
||||
short a = stream.readShort();
|
||||
Item item = Vars.content.item(read.b());
|
||||
short a = read.s();
|
||||
totalAmmo += a;
|
||||
ammo.add(new ItemEntry(item, a));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import arc.math.Angles;
|
||||
import arc.math.Mathf;
|
||||
import arc.math.geom.Vec2;
|
||||
import arc.util.Time;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.Fx;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.entities.bullet.BulletType;
|
||||
@@ -320,17 +321,17 @@ public abstract class Turret extends Block{
|
||||
public Posc target;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(reload);
|
||||
stream.writeFloat(rotation);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(reload);
|
||||
write.f(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
reload = stream.readFloat();
|
||||
rotation = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
reload = read.f();
|
||||
rotation = read.f();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
@@ -41,15 +42,15 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
||||
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
buffer.write(stream);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
buffer.write(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
buffer.read(stream);
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buffer.read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
@@ -351,23 +352,23 @@ public class Conveyor extends Block implements Autotiler{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(len);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(len);
|
||||
|
||||
for(int i = 0; i < len; i++){
|
||||
stream.writeInt(Pack.intBytes((byte)ids[i].id, (byte)(xs[i] * 127), (byte)(ys[i] * 255 - 128), (byte)0));
|
||||
write.i(Pack.intBytes((byte)ids[i].id, (byte)(xs[i] * 127), (byte)(ys[i] * 255 - 128), (byte)0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
int amount = stream.readInt();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
int amount = read.i();
|
||||
len = Math.min(amount, capacity);
|
||||
|
||||
for(int i = 0; i < amount; i++){
|
||||
int val = stream.readInt();
|
||||
int val = read.i();
|
||||
byte id = (byte)(val >> 24);
|
||||
float x = (float)((byte)(val >> 16)) / 127f;
|
||||
float y = ((float)((byte)(val >> 8)) + 128f) / 255f;
|
||||
|
||||
@@ -8,6 +8,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -375,27 +376,27 @@ public class ItemBridge extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(link);
|
||||
stream.writeFloat(uptime);
|
||||
stream.writeByte(incoming.size);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(link);
|
||||
write.f(uptime);
|
||||
write.b(incoming.size);
|
||||
|
||||
IntSetIterator it = incoming.iterator();
|
||||
|
||||
while(it.hasNext){
|
||||
stream.writeInt(it.next());
|
||||
write.i(it.next());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
link = stream.readInt();
|
||||
uptime = stream.readFloat();
|
||||
byte links = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
link = read.i();
|
||||
uptime = read.f();
|
||||
byte links = read.b();
|
||||
for(int i = 0; i < links; i++){
|
||||
incoming.add(stream.readInt());
|
||||
incoming.add(read.i());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.util.Time;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.gen.BufferItem;
|
||||
import mindustry.type.Item;
|
||||
@@ -9,8 +10,6 @@ import mindustry.world.DirectionalItemBuffer;
|
||||
import mindustry.world.Tile;
|
||||
import mindustry.world.meta.BlockGroup;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -89,15 +88,15 @@ public class Junction extends Block{
|
||||
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed);
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
buffer.write(stream);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
buffer.write(write);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
buffer.read(stream);
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buffer.read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.struct.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.pooling.Pool.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.content.*;
|
||||
@@ -332,19 +333,19 @@ public class MassDriver extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(link);
|
||||
stream.writeFloat(rotation);
|
||||
stream.writeByte((byte)state.ordinal());
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(link);
|
||||
write.f(rotation);
|
||||
write.b((byte)state.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
link = stream.readInt();
|
||||
rotation = stream.readFloat();
|
||||
state = DriverState.values()[stream.readByte()];
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
link = read.i();
|
||||
rotation = read.f();
|
||||
state = DriverState.values()[read.b()];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.world.blocks.distribution;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
@@ -124,10 +125,10 @@ public class OverflowGate extends Block{
|
||||
float time;
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(25, 50f).read(stream);
|
||||
new DirectionalItemBuffer(25, 50f).read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.math.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.type.*;
|
||||
@@ -156,18 +157,18 @@ public class Sorter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeShort(sortItem == null ? -1 : sortItem.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.s(sortItem == null ? -1 : sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
sortItem = content.item(stream.readShort());
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
sortItem = content.item(read.s());
|
||||
|
||||
if(revision == 1){
|
||||
new DirectionalItemBuffer(20, 45f).read(stream);
|
||||
new DirectionalItemBuffer(20, 45f).read(read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mindustry.world.blocks.logic;
|
||||
|
||||
import arc.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import arc.Input.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
@@ -9,7 +8,9 @@ import arc.math.geom.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.net.*;
|
||||
@@ -17,8 +18,6 @@ import mindustry.ui.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
import mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class MessageBlock extends Block{
|
||||
@@ -150,15 +149,15 @@ public class MessageBlock extends Block{
|
||||
public String[] lines = {""};
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeUTF(message);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.str(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
message = stream.readUTF();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
message = read.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
@@ -165,15 +166,15 @@ public class ImpactReactor extends PowerGenerator{
|
||||
public float warmup;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(warmup);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
warmup = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.world.*;
|
||||
@@ -80,15 +81,15 @@ public class LightBlock extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeInt(color);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.i(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
color = stream.readInt();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
color = read.i();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.game.EventType.*;
|
||||
@@ -186,15 +187,15 @@ public class NuclearReactor extends PowerGenerator{
|
||||
public float flash;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(heat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
heat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
heat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mindustry.world.blocks.power;
|
||||
import arc.Core;
|
||||
import arc.struct.EnumSet;
|
||||
import arc.util.Strings;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.Pal;
|
||||
import mindustry.ui.Bar;
|
||||
@@ -59,15 +60,15 @@ public class PowerGenerator extends PowerDistributor{
|
||||
public float productionEfficiency = 0.0f;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(productionEfficiency);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(productionEfficiency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
productionEfficiency = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
productionEfficiency = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
@@ -120,15 +121,15 @@ public class Cultivator extends GenericCrafter{
|
||||
public float boost;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(warmup);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
warmup = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -151,17 +152,17 @@ public class GenericCrafter extends Block{
|
||||
public float warmup;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeFloat(warmup);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.f(warmup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
progress = stream.readFloat();
|
||||
warmup = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
warmup = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.type.*;
|
||||
@@ -101,15 +102,15 @@ public class ItemSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeShort(outputItem == null ? -1 : outputItem.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.s(outputItem == null ? -1 : outputItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
outputItem = content.item(stream.readShort());
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
outputItem = content.item(read.s());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
@@ -97,15 +98,15 @@ public class LiquidSource extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(source == null ? -1 : source.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(source == null ? -1 : source.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
byte id = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
byte id = read.b();
|
||||
source = id == -1 ? null : content.liquid(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.entities.units.*;
|
||||
import mindustry.type.*;
|
||||
@@ -138,15 +139,15 @@ public class Unloader extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(sortItem == null ? -1 : sortItem.id);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(sortItem == null ? -1 : sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
byte id = stream.readByte();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
byte id = read.b();
|
||||
sortItem = id == -1 ? null : content.items().get(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -126,15 +127,15 @@ public class CommandCenter extends Block{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeByte(command.ordinal());
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.b(command.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
command = UnitCommand.all[stream.readByte()];
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
command = UnitCommand.all[read.b()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -140,19 +141,19 @@ public class MechPad extends Block{
|
||||
float heat;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeFloat(time);
|
||||
stream.writeFloat(heat);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(progress);
|
||||
write.f(time);
|
||||
write.f(heat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
progress = stream.readFloat();
|
||||
time = stream.readFloat();
|
||||
heat = stream.readFloat();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
progress = read.f();
|
||||
time = read.f();
|
||||
heat = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import arc.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
@@ -189,17 +190,17 @@ public class UnitFactory extends Block{
|
||||
int spawned;
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
super.write(stream);
|
||||
stream.writeFloat(buildTime);
|
||||
stream.writeInt(spawned);
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
write.f(buildTime);
|
||||
write.i(spawned);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream, byte revision) throws IOException{
|
||||
super.read(stream, revision);
|
||||
buildTime = stream.readFloat();
|
||||
spawned = stream.readInt();
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
buildTime = read.f();
|
||||
spawned = read.i();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import java.io.*;
|
||||
import arc.util.io.*;
|
||||
|
||||
/** A class that represents compartmentalized tile entity state. */
|
||||
public abstract class BlockModule{
|
||||
public abstract void write(DataOutput stream) throws IOException;
|
||||
|
||||
public abstract void read(DataInput stream) throws IOException;
|
||||
public abstract void write(Writes write);
|
||||
public abstract void read(Reads read);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.consumers.Consume;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ConsumeModule extends BlockModule{
|
||||
private boolean valid, optionalValid;
|
||||
private final Tilec entity;
|
||||
@@ -59,12 +58,12 @@ public class ConsumeModule extends BlockModule{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeBoolean(valid);
|
||||
public void write(Writes write){
|
||||
write.bool(valid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
valid = stream.readBoolean();
|
||||
public void read(Reads read){
|
||||
valid = read.bool();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.Item;
|
||||
import mindustry.type.ItemStack;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -121,32 +121,32 @@ public class ItemModule extends BlockModule{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
public void write(Writes write){
|
||||
byte amount = 0;
|
||||
for(int item : items){
|
||||
if(item > 0) amount++;
|
||||
}
|
||||
|
||||
stream.writeByte(amount); //amount of items
|
||||
write.b(amount); //amount of items
|
||||
|
||||
for(int i = 0; i < items.length; i++){
|
||||
if(items[i] > 0){
|
||||
stream.writeByte(i); //item ID
|
||||
stream.writeInt(items[i]); //item amount
|
||||
write.b(i); //item ID
|
||||
write.i(items[i]); //item amount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
//just in case, reset items
|
||||
Arrays.fill(items, 0);
|
||||
byte count = stream.readByte();
|
||||
byte count = read.b();
|
||||
total = 0;
|
||||
|
||||
for(int j = 0; j < count; j++){
|
||||
int itemid = stream.readByte();
|
||||
int itemamount = stream.readInt();
|
||||
int itemid = read.b();
|
||||
int itemamount = read.i();
|
||||
items[content.item(itemid).id] = itemamount;
|
||||
total += itemamount;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.type.Liquid;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static mindustry.Vars.content;
|
||||
@@ -83,31 +83,31 @@ public class LiquidModule extends BlockModule{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
public void write(Writes write){
|
||||
byte amount = 0;
|
||||
for(float liquid : liquids){
|
||||
if(liquid > 0) amount++;
|
||||
}
|
||||
|
||||
stream.writeByte(amount); //amount of liquids
|
||||
write.b(amount); //amount of liquids
|
||||
|
||||
for(int i = 0; i < liquids.length; i++){
|
||||
if(liquids[i] > 0){
|
||||
stream.writeByte(i); //liquid ID
|
||||
stream.writeFloat(liquids[i]); //item amount
|
||||
write.b(i); //liquid ID
|
||||
write.f(liquids[i]); //item amount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
Arrays.fill(liquids, 0);
|
||||
total = 0f;
|
||||
byte count = stream.readByte();
|
||||
byte count = read.b();
|
||||
|
||||
for(int j = 0; j < count; j++){
|
||||
int liquidid = stream.readByte();
|
||||
float amount = stream.readFloat();
|
||||
int liquidid = read.b();
|
||||
float amount = read.f();
|
||||
liquids[liquidid] = amount;
|
||||
if(amount > 0){
|
||||
current = content.liquid(liquidid);
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package mindustry.world.modules;
|
||||
|
||||
import arc.struct.IntArray;
|
||||
import arc.util.io.*;
|
||||
import mindustry.world.blocks.power.PowerGraph;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PowerModule extends BlockModule{
|
||||
/**
|
||||
* In case of unbuffered consumers, this is the percentage (1.0f = 100%) of the demanded power which can be supplied.
|
||||
@@ -18,22 +15,22 @@ public class PowerModule extends BlockModule{
|
||||
public IntArray links = new IntArray();
|
||||
|
||||
@Override
|
||||
public void write(DataOutput stream) throws IOException{
|
||||
stream.writeShort(links.size);
|
||||
public void write(Writes write){
|
||||
write.s(links.size);
|
||||
for(int i = 0; i < links.size; i++){
|
||||
stream.writeInt(links.get(i));
|
||||
write.i(links.get(i));
|
||||
}
|
||||
stream.writeFloat(status);
|
||||
write.f(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(DataInput stream) throws IOException{
|
||||
public void read(Reads read){
|
||||
links.clear();
|
||||
short amount = stream.readShort();
|
||||
short amount = read.s();
|
||||
for(int i = 0; i < amount; i++){
|
||||
links.add(stream.readInt());
|
||||
links.add(read.i());
|
||||
}
|
||||
status = stream.readFloat();
|
||||
status = read.f();
|
||||
if(Float.isNaN(status) || Float.isInfinite(status)) status = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user