Better IO
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user