Better IO
This commit is contained in:
@@ -218,21 +218,9 @@ public class Annotations{
|
|||||||
* This method must return void and have two parameters, the first being of type {@link java.nio.ByteBuffer} and the second
|
* This method must return void and have two parameters, the first being of type {@link java.nio.ByteBuffer} and the second
|
||||||
* being the type returned by {@link #value()}.
|
* being the type returned by {@link #value()}.
|
||||||
*/
|
*/
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.TYPE)
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface WriteClass{
|
public @interface TypeIOHandler{
|
||||||
Class<?> value();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specifies that this method will be used to read classes of the type returned by {@link #value()}. <br>
|
|
||||||
* This method must return the type returned by {@link #value()},
|
|
||||||
* and have one parameter, being of type {@link java.nio.ByteBuffer}.
|
|
||||||
*/
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
|
||||||
public @interface ReadClass{
|
|
||||||
Class<?> value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package mindustry.annotations.entity;
|
package mindustry.annotations.entity;
|
||||||
|
|
||||||
import arc.util.*;
|
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import com.squareup.javapoet.MethodSpec.*;
|
import com.squareup.javapoet.MethodSpec.*;
|
||||||
import mindustry.annotations.*;
|
import mindustry.annotations.*;
|
||||||
@@ -19,14 +18,14 @@ public class EntityIO{
|
|||||||
void io(TypeName type, String field) throws Exception{
|
void io(TypeName type, String field) throws Exception{
|
||||||
|
|
||||||
if(type.isPrimitive()){
|
if(type.isPrimitive()){
|
||||||
s(type.toString(), field);
|
s(type == TypeName.BOOLEAN ? "bool" : type.toString().charAt(0) + "", field);
|
||||||
}else if(type.toString().equals("java.lang.String")){
|
}else if(type.toString().equals("java.lang.String")){
|
||||||
s("UTF", field);
|
s("str", field);
|
||||||
}else if(instanceOf(type.toString(), "mindustry.ctype.Content")){
|
}else if(instanceOf(type.toString(), "mindustry.ctype.Content")){
|
||||||
if(write){
|
if(write){
|
||||||
s("short", field + ".id");
|
s("s", field + ".id");
|
||||||
}else{
|
}else{
|
||||||
st(field + " = mindustry.Vars.content.getByID(mindustry.ctype.ContentType.$L, input.readShort())", BaseProcessor.simpleName(type.toString()).toLowerCase().replace("type", ""));
|
st(field + " = mindustry.Vars.content.getByID(mindustry.ctype.ContentType.$L, read.s())", BaseProcessor.simpleName(type.toString()).toLowerCase().replace("type", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +44,9 @@ public class EntityIO{
|
|||||||
|
|
||||||
private void s(String type, String field){
|
private void s(String type, String field){
|
||||||
if(write){
|
if(write){
|
||||||
builder.addStatement("output.write$L($L)", Strings.capitalize(type), field);
|
builder.addStatement("write.$L($L)", type, field);
|
||||||
}else{
|
}else{
|
||||||
builder.addStatement("$L = input.read$L()", field, Strings.capitalize(type));
|
builder.addStatement("$L = read.$L()", field, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
package mindustry.annotations.remote;
|
|
||||||
|
|
||||||
import mindustry.annotations.Annotations.*;
|
|
||||||
import mindustry.annotations.*;
|
|
||||||
|
|
||||||
import javax.annotation.processing.*;
|
|
||||||
import javax.lang.model.element.*;
|
|
||||||
import javax.lang.model.type.*;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class finds reader and writer methods annotated by the {@link WriteClass}
|
|
||||||
* and {@link ReadClass} annotations.
|
|
||||||
*/
|
|
||||||
public class IOFinder{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds all class serializers for all types and returns them. Logs errors when necessary.
|
|
||||||
* Maps fully qualified class names to their serializers.
|
|
||||||
*/
|
|
||||||
public HashMap<String, ClassSerializer> findSerializers(RoundEnvironment env){
|
|
||||||
HashMap<String, ClassSerializer> result = new HashMap<>();
|
|
||||||
|
|
||||||
//get methods with the types
|
|
||||||
Set<? extends Element> writers = env.getElementsAnnotatedWith(WriteClass.class);
|
|
||||||
Set<? extends Element> readers = env.getElementsAnnotatedWith(ReadClass.class);
|
|
||||||
|
|
||||||
//look for writers first
|
|
||||||
for(Element writer : writers){
|
|
||||||
WriteClass writean = writer.getAnnotation(WriteClass.class);
|
|
||||||
String typeName = getValue(writean);
|
|
||||||
|
|
||||||
//make sure there's only one read method
|
|
||||||
if(readers.stream().filter(elem -> getValue(elem.getAnnotation(ReadClass.class)).equals(typeName)).count() > 1){
|
|
||||||
BaseProcessor.err("Multiple writer methods for type '" + typeName + "'", writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//make sure there's only one write method
|
|
||||||
long count = readers.stream().filter(elem -> getValue(elem.getAnnotation(ReadClass.class)).equals(typeName)).count();
|
|
||||||
if(count == 0){
|
|
||||||
BaseProcessor.err("Writer method does not have an accompanying reader: ", writer);
|
|
||||||
}else if(count > 1){
|
|
||||||
BaseProcessor.err("Writer method has multiple reader for type: ", writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
Element reader = readers.stream().filter(elem -> getValue(elem.getAnnotation(ReadClass.class)).equals(typeName)).findFirst().get();
|
|
||||||
|
|
||||||
//add to result list
|
|
||||||
result.put(typeName, new ClassSerializer(BaseProcessor.getMethodName(reader), BaseProcessor.getMethodName(writer), typeName));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getValue(WriteClass write){
|
|
||||||
try{
|
|
||||||
Class<?> type = write.value();
|
|
||||||
return type.getName();
|
|
||||||
}catch(MirroredTypeException e){
|
|
||||||
return e.getTypeMirror().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getValue(ReadClass read){
|
|
||||||
try{
|
|
||||||
Class<?> type = read.value();
|
|
||||||
return type.getName();
|
|
||||||
}catch(MirroredTypeException e){
|
|
||||||
return e.getTypeMirror().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Information about read/write methods for a specific class type. */
|
|
||||||
public static class ClassSerializer{
|
|
||||||
/** Fully qualified method name of the reader. */
|
|
||||||
public final String readMethod;
|
|
||||||
/** Fully qualified method name of the writer. */
|
|
||||||
public final String writeMethod;
|
|
||||||
/** Fully qualified class type name. */
|
|
||||||
public final String classType;
|
|
||||||
|
|
||||||
public ClassSerializer(String readMethod, String writeMethod, String classType){
|
|
||||||
this.readMethod = readMethod;
|
|
||||||
this.writeMethod = writeMethod;
|
|
||||||
this.classType = classType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,11 +3,10 @@ package mindustry.annotations.remote;
|
|||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import mindustry.annotations.*;
|
import mindustry.annotations.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.annotations.remote.IOFinder.*;
|
import mindustry.annotations.remote.TypeIOResolver.*;
|
||||||
|
|
||||||
import javax.annotation.processing.*;
|
import javax.annotation.processing.*;
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.tools.Diagnostic.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.*;
|
import java.util.stream.*;
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ public class RemoteProcess extends BaseProcessor{
|
|||||||
private static final String callLocation = "Call";
|
private static final String callLocation = "Call";
|
||||||
|
|
||||||
//class serializers
|
//class serializers
|
||||||
private HashMap<String, ClassSerializer> serializers;
|
private ClassSerializer serializer;
|
||||||
//all elements with the Remote annotation
|
//all elements with the Remote annotation
|
||||||
private Set<? extends Element> elements;
|
private Set<? extends Element> elements;
|
||||||
//map of all classes to generate by name
|
//map of all classes to generate by name
|
||||||
@@ -51,7 +50,7 @@ public class RemoteProcess extends BaseProcessor{
|
|||||||
//round 1: find all annotations, generate *writers*
|
//round 1: find all annotations, generate *writers*
|
||||||
if(round == 1){
|
if(round == 1){
|
||||||
//get serializers
|
//get serializers
|
||||||
serializers = new IOFinder().findSerializers(roundEnv);
|
serializer = TypeIOResolver.resolve(this);
|
||||||
//last method ID used
|
//last method ID used
|
||||||
int lastMethodID = 0;
|
int lastMethodID = 0;
|
||||||
//find all elements with the Remote annotation
|
//find all elements with the Remote annotation
|
||||||
@@ -98,12 +97,12 @@ public class RemoteProcess extends BaseProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create read/write generators
|
//create read/write generators
|
||||||
RemoteWriteGenerator writegen = new RemoteWriteGenerator(serializers);
|
RemoteWriteGenerator writegen = new RemoteWriteGenerator(serializer);
|
||||||
|
|
||||||
//generate the methods to invoke (write)
|
//generate the methods to invoke (write)
|
||||||
writegen.generateFor(classes, packageName);
|
writegen.generateFor(classes, packageName);
|
||||||
}else if(round == 2){ //round 2: generate all *readers*
|
}else if(round == 2){ //round 2: generate all *readers*
|
||||||
RemoteReadGenerator readgen = new RemoteReadGenerator(serializers);
|
RemoteReadGenerator readgen = new RemoteReadGenerator(serializer);
|
||||||
|
|
||||||
//generate server readers
|
//generate server readers
|
||||||
readgen.generateFor(methods.stream().filter(method -> method.where.isClient).collect(Collectors.toList()), readServerName, packageName, true);
|
readgen.generateFor(methods.stream().filter(method -> method.where.isClient).collect(Collectors.toList()), readServerName, packageName, true);
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
package mindustry.annotations.remote;
|
package mindustry.annotations.remote;
|
||||||
|
|
||||||
|
import arc.util.io.*;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import mindustry.annotations.*;
|
import mindustry.annotations.*;
|
||||||
import mindustry.annotations.remote.IOFinder.*;
|
import mindustry.annotations.remote.TypeIOResolver.*;
|
||||||
|
|
||||||
import javax.lang.model.element.Modifier;
|
import javax.lang.model.element.Modifier;
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.nio.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/** Generates code for reading remote invoke packets on the client and server. */
|
/** Generates code for reading remote invoke packets on the client and server. */
|
||||||
public class RemoteReadGenerator{
|
public class RemoteReadGenerator{
|
||||||
private final HashMap<String, ClassSerializer> serializers;
|
private final ClassSerializer serializers;
|
||||||
|
|
||||||
/** Creates a read generator that uses the supplied serializer setup. */
|
/** Creates a read generator that uses the supplied serializer setup. */
|
||||||
public RemoteReadGenerator(HashMap<String, ClassSerializer> serializers){
|
public RemoteReadGenerator(ClassSerializer serializers){
|
||||||
this.serializers = serializers;
|
this.serializers = serializers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ public class RemoteReadGenerator{
|
|||||||
//create main method builder
|
//create main method builder
|
||||||
MethodSpec.Builder readMethod = MethodSpec.methodBuilder("readPacket")
|
MethodSpec.Builder readMethod = MethodSpec.methodBuilder("readPacket")
|
||||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||||
.addParameter(ByteBuffer.class, "buffer") //buffer to read form
|
.addParameter(Reads.class, "read") //buffer to read form
|
||||||
.addParameter(int.class, "id") //ID of method type to read
|
.addParameter(int.class, "id") //ID of method type to read
|
||||||
.returns(void.class);
|
.returns(void.class);
|
||||||
|
|
||||||
@@ -76,26 +76,22 @@ public class RemoteReadGenerator{
|
|||||||
//name of parameter
|
//name of parameter
|
||||||
String varName = var.getSimpleName().toString();
|
String varName = var.getSimpleName().toString();
|
||||||
//captialized version of type name for reading primitives
|
//captialized version of type name for reading primitives
|
||||||
String capName = typeName.equals("byte") ? "" : Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1);
|
String pname = typeName.equals("boolean") ? "bool" : typeName.charAt(0) + "";
|
||||||
|
|
||||||
//write primitives automatically
|
//write primitives automatically
|
||||||
if(BaseProcessor.isPrimitive(typeName)){
|
if(BaseProcessor.isPrimitive(typeName)){
|
||||||
if(typeName.equals("boolean")){
|
readBlock.addStatement("$L $L = read.$L()", typeName, varName, pname);
|
||||||
readBlock.addStatement("boolean " + varName + " = buffer.get() == 1");
|
|
||||||
}else{
|
|
||||||
readBlock.addStatement(typeName + " " + varName + " = buffer.get" + capName + "()");
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
//else, try and find a serializer
|
//else, try and find a serializer
|
||||||
ClassSerializer ser = serializers.getOrDefault(typeName, SerializerResolver.locate(entry.element, var.asType()));
|
String ser = serializers.readers.get(typeName, SerializerResolver.locate(entry.element, var.asType(), false));
|
||||||
|
|
||||||
if(ser == null){ //make sure a serializer exists!
|
if(ser == null){ //make sure a serializer exists!
|
||||||
BaseProcessor.err("No @ReadClass method to read class type '" + typeName + "' in method " + entry.targetMethod, var);
|
BaseProcessor.err("No read method to read class type '" + typeName + "' in method " + entry.targetMethod + "; " + serializers.readers, var);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add statement for reading it
|
//add statement for reading it
|
||||||
readBlock.addStatement(typeName + " " + varName + " = " + ser.readMethod + "(buffer)");
|
readBlock.addStatement(typeName + " " + varName + " = " + ser + "(read)");
|
||||||
}
|
}
|
||||||
|
|
||||||
//append variable name to string builder
|
//append variable name to string builder
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package mindustry.annotations.remote;
|
package mindustry.annotations.remote;
|
||||||
|
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import com.squareup.javapoet.*;
|
import com.squareup.javapoet.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.annotations.*;
|
import mindustry.annotations.*;
|
||||||
import mindustry.annotations.remote.IOFinder.*;
|
import mindustry.annotations.remote.TypeIOResolver.*;
|
||||||
|
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/** Generates code for writing remote invoke packets on the client and server. */
|
/** Generates code for writing remote invoke packets on the client and server. */
|
||||||
public class RemoteWriteGenerator{
|
public class RemoteWriteGenerator{
|
||||||
private final HashMap<String, ClassSerializer> serializers;
|
private final ClassSerializer serializers;
|
||||||
|
|
||||||
/** Creates a write generator that uses the supplied serializer setup. */
|
/** Creates a write generator that uses the supplied serializer setup. */
|
||||||
public RemoteWriteGenerator(HashMap<String, ClassSerializer> serializers){
|
public RemoteWriteGenerator(ClassSerializer serializers){
|
||||||
this.serializers = serializers;
|
this.serializers = serializers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,8 +29,12 @@ public class RemoteWriteGenerator{
|
|||||||
classBuilder.addJavadoc(RemoteProcess.autogenWarning);
|
classBuilder.addJavadoc(RemoteProcess.autogenWarning);
|
||||||
|
|
||||||
//add temporary write buffer
|
//add temporary write buffer
|
||||||
classBuilder.addField(FieldSpec.builder(ByteBuffer.class, "TEMP_BUFFER", Modifier.STATIC, Modifier.PRIVATE, Modifier.FINAL)
|
classBuilder.addField(FieldSpec.builder(ReusableByteOutStream.class, "OUT", Modifier.STATIC, Modifier.PRIVATE, Modifier.FINAL)
|
||||||
.initializer("ByteBuffer.allocate($1L)", RemoteProcess.maxPacketSize).build());
|
.initializer("new ReusableByteOutStream($L)", RemoteProcess.maxPacketSize).build());
|
||||||
|
|
||||||
|
//add writer for that buffer
|
||||||
|
classBuilder.addField(FieldSpec.builder(Writes.class, "WRITE", Modifier.STATIC, Modifier.PRIVATE, Modifier.FINAL)
|
||||||
|
.initializer("new Writes(new $T(OUT))", DataOutputStream.class).build());
|
||||||
|
|
||||||
//go through each method entry in this class
|
//go through each method entry in this class
|
||||||
for(MethodEntry methodEntry : entry.methods){
|
for(MethodEntry methodEntry : entry.methods){
|
||||||
@@ -128,14 +132,12 @@ public class RemoteWriteGenerator{
|
|||||||
|
|
||||||
//add statement to create packet from pool
|
//add statement to create packet from pool
|
||||||
method.addStatement("$1N packet = $2N.obtain($1N.class, $1N::new)", "mindustry.net.Packets.InvokePacket", "arc.util.pooling.Pools");
|
method.addStatement("$1N packet = $2N.obtain($1N.class, $1N::new)", "mindustry.net.Packets.InvokePacket", "arc.util.pooling.Pools");
|
||||||
//assign buffer
|
|
||||||
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
|
|
||||||
//assign priority
|
//assign priority
|
||||||
method.addStatement("packet.priority = (byte)" + methodEntry.priority.ordinal());
|
method.addStatement("packet.priority = (byte)" + methodEntry.priority.ordinal());
|
||||||
//assign method ID
|
//assign method ID
|
||||||
method.addStatement("packet.type = (byte)" + methodEntry.id);
|
method.addStatement("packet.type = (byte)" + methodEntry.id);
|
||||||
//rewind buffer
|
//reset stream
|
||||||
method.addStatement("TEMP_BUFFER.position(0)");
|
method.addStatement("OUT.reset()");
|
||||||
|
|
||||||
method.addTypeVariables(Array.with(elem.getTypeParameters()).map(BaseProcessor::getTVN));
|
method.addTypeVariables(Array.with(elem.getTypeParameters()).map(BaseProcessor::getTVN));
|
||||||
|
|
||||||
@@ -169,15 +171,10 @@ public class RemoteWriteGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(BaseProcessor.isPrimitive(typeName)){ //check if it's a primitive, and if so write it
|
if(BaseProcessor.isPrimitive(typeName)){ //check if it's a primitive, and if so write it
|
||||||
if(typeName.equals("boolean")){ //booleans are special
|
method.addStatement("WRITE.$L($L)", typeName.equals("boolean") ? "bool" : typeName.charAt(0) + "", varName);
|
||||||
method.addStatement("TEMP_BUFFER.put(" + varName + " ? (byte)1 : 0)");
|
|
||||||
}else{
|
|
||||||
method.addStatement("TEMP_BUFFER.put" +
|
|
||||||
capName + "(" + varName + ")");
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
//else, try and find a serializer
|
//else, try and find a serializer
|
||||||
ClassSerializer ser = serializers.getOrDefault(typeName, SerializerResolver.locate(elem, var.asType()));
|
String ser = serializers.writers.get(typeName, SerializerResolver.locate(elem, var.asType(), true));
|
||||||
|
|
||||||
if(ser == null){ //make sure a serializer exists!
|
if(ser == null){ //make sure a serializer exists!
|
||||||
BaseProcessor.err("No @WriteClass method to write class type: '" + typeName + "'", var);
|
BaseProcessor.err("No @WriteClass method to write class type: '" + typeName + "'", var);
|
||||||
@@ -185,7 +182,7 @@ public class RemoteWriteGenerator{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//add statement for writing it
|
//add statement for writing it
|
||||||
method.addStatement(ser.writeMethod + "(TEMP_BUFFER, " + varName + ")");
|
method.addStatement(ser + "(WRITE, " + varName + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(writePlayerSkipCheck){ //write end check
|
if(writePlayerSkipCheck){ //write end check
|
||||||
@@ -193,8 +190,10 @@ public class RemoteWriteGenerator{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//assign packet bytes
|
||||||
|
method.addStatement("packet.bytes = OUT.getBytes()");
|
||||||
//assign packet length
|
//assign packet length
|
||||||
method.addStatement("packet.writeLength = TEMP_BUFFER.position()");
|
method.addStatement("packet.length = OUT.size()");
|
||||||
|
|
||||||
String sendString;
|
String sendString;
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
package mindustry.annotations.remote;
|
package mindustry.annotations.remote;
|
||||||
|
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import mindustry.annotations.remote.IOFinder.*;
|
|
||||||
|
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.lang.model.type.*;
|
import javax.lang.model.type.*;
|
||||||
|
|
||||||
public class SerializerResolver{
|
public class SerializerResolver{
|
||||||
private static final ClassSerializer entitySerializer = new ClassSerializer("mindustry.io.TypeIO.readEntity", "mindustry.io.TypeIO.writeEntity", "Entityc");
|
|
||||||
|
|
||||||
public static ClassSerializer locate(ExecutableElement elem, TypeMirror mirror){
|
public static String locate(ExecutableElement elem, TypeMirror mirror, boolean write){
|
||||||
//generic type
|
//generic type
|
||||||
if(mirror.toString().equals("T")){
|
if((mirror.toString().equals("T") && Array.with(elem.getTypeParameters().get(0).getBounds()).contains(SerializerResolver::isEntity)) ||
|
||||||
TypeParameterElement param = elem.getTypeParameters().get(0);
|
isEntity(mirror)){
|
||||||
if(Array.with(param.getBounds()).contains(SerializerResolver::isEntity)){
|
return write ? "mindustry.io.TypeIO.writeEntity" : "mindustry.io.TypeIO.readEntity";
|
||||||
return entitySerializer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isEntity(mirror)){
|
|
||||||
return entitySerializer;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package mindustry.annotations.remote;
|
||||||
|
|
||||||
|
import arc.struct.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
|
import mindustry.annotations.*;
|
||||||
|
import mindustry.annotations.util.*;
|
||||||
|
|
||||||
|
import javax.lang.model.element.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class finds reader and writer methods.
|
||||||
|
*/
|
||||||
|
public class TypeIOResolver{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all class serializers for all types and returns them. Logs errors when necessary.
|
||||||
|
* Maps fully qualified class names to their serializers.
|
||||||
|
*/
|
||||||
|
public static ClassSerializer resolve(BaseProcessor processor){
|
||||||
|
ClassSerializer out = new ClassSerializer(new ObjectMap<>(), new ObjectMap<>());
|
||||||
|
for(Stype type : processor.types(TypeIOHandler.class)){
|
||||||
|
//look at all TypeIOHandler methods
|
||||||
|
Array<Smethod> methods = type.methods();
|
||||||
|
for(Smethod meth : methods){
|
||||||
|
if(meth.is(Modifier.PUBLIC) && meth.is(Modifier.STATIC)){
|
||||||
|
Array<Svar> params = meth.params();
|
||||||
|
//2 params, second one is type, first is writer
|
||||||
|
if(params.size == 2 && params.first().tname().toString().equals("arc.util.io.Writes")){
|
||||||
|
out.writers.put(params.get(1).tname().toString(), type.fullName() + "." + meth.name());
|
||||||
|
}else if(params.size == 1 && params.first().tname().toString().equals("arc.util.io.Reads") && !meth.isVoid()){
|
||||||
|
//1 param, one is reader, returns type
|
||||||
|
out.readers.put(meth.retn().toString(), type.fullName() + "." + meth.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Information about read/write methods for class types. */
|
||||||
|
public static class ClassSerializer{
|
||||||
|
public final ObjectMap<String, String> writers, readers;
|
||||||
|
|
||||||
|
public ClassSerializer(ObjectMap<String, String> writers, ObjectMap<String, String> readers){
|
||||||
|
this.writers = writers;
|
||||||
|
this.readers = readers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -121,8 +121,7 @@ public class NetClient implements ApplicationListener{
|
|||||||
});
|
});
|
||||||
|
|
||||||
net.handleClient(InvokePacket.class, packet -> {
|
net.handleClient(InvokePacket.class, packet -> {
|
||||||
packet.writeBuffer.position(0);
|
RemoteReadClient.readPacket(packet.reader(), packet.type);
|
||||||
RemoteReadClient.readPacket(packet.writeBuffer, packet.type);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +376,7 @@ public class NetClient implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//read the entity
|
//read the entity
|
||||||
entity.read(input);
|
entity.read(Reads.get(input));
|
||||||
|
|
||||||
if(created && entity.interpolator().target != null){
|
if(created && entity.interpolator().target != null){
|
||||||
//set initial starting position
|
//set initial starting position
|
||||||
@@ -407,7 +406,7 @@ public class NetClient implements ApplicationListener{
|
|||||||
Log.warn("Missing entity at {0}. Skipping block snapshot.", tile);
|
Log.warn("Missing entity at {0}. Skipping block snapshot.", tile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tile.entity.read(input, tile.entity.version());
|
tile.entity.read(Reads.get(input), tile.entity.version());
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -435,9 +434,9 @@ public class NetClient implements ApplicationListener{
|
|||||||
Tile tile = world.tile(pos);
|
Tile tile = world.tile(pos);
|
||||||
|
|
||||||
if(tile != null && tile.entity != null){
|
if(tile != null && tile.entity != null){
|
||||||
tile.entity.items().read(input);
|
tile.entity.items().read(Reads.get(input));
|
||||||
}else{
|
}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 boolean closing = false;
|
||||||
private Interval timer = new Interval();
|
private Interval timer = new Interval();
|
||||||
|
|
||||||
private ByteBuffer writeBuffer = ByteBuffer.allocate(127);
|
private ReusableByteOutStream writeBuffer = new ReusableByteOutStream(127);
|
||||||
private ByteBufferOutput outputBuffer = new ByteBufferOutput(writeBuffer);
|
private Writes outputBuffer = new Writes(new DataOutputStream(writeBuffer));
|
||||||
|
|
||||||
/** Stream for writing player sync data to. */
|
/** Stream for writing player sync data to. */
|
||||||
private ReusableByteOutStream syncStream = new ReusableByteOutStream();
|
private ReusableByteOutStream syncStream = new ReusableByteOutStream();
|
||||||
@@ -214,7 +214,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
writeBuffer.position(0);
|
writeBuffer.reset();
|
||||||
player.write(outputBuffer);
|
player.write(outputBuffer);
|
||||||
}catch(Throwable t){
|
}catch(Throwable t){
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
@@ -237,7 +237,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
net.handleServer(InvokePacket.class, (con, packet) -> {
|
net.handleServer(InvokePacket.class, (con, packet) -> {
|
||||||
if(con.player == null) return;
|
if(con.player == null) return;
|
||||||
try{
|
try{
|
||||||
RemoteReadServer.readPacket(packet.writeBuffer, packet.type, con.player);
|
RemoteReadServer.readPacket(packet.reader(), packet.type, con.player);
|
||||||
}catch(ValidateException e){
|
}catch(ValidateException e){
|
||||||
Log.debug("Validation failed for '{0}': {1}", e.player, e.getMessage());
|
Log.debug("Validation failed for '{0}': {1}", e.player, e.getMessage());
|
||||||
}catch(RuntimeException e){
|
}catch(RuntimeException e){
|
||||||
@@ -704,7 +704,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
sent ++;
|
sent ++;
|
||||||
|
|
||||||
dataStream.writeInt(entity.tile().pos());
|
dataStream.writeInt(entity.tile().pos());
|
||||||
entity.write(dataStream);
|
entity.write(Writes.get(dataStream));
|
||||||
|
|
||||||
if(syncStream.size() > maxSnapshotSize){
|
if(syncStream.size() > maxSnapshotSize){
|
||||||
dataStream.close();
|
dataStream.close();
|
||||||
@@ -730,7 +730,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
|
|
||||||
for(CoreEntity entity : cores){
|
for(CoreEntity entity : cores){
|
||||||
dataStream.writeInt(entity.tile().pos());
|
dataStream.writeInt(entity.tile().pos());
|
||||||
entity.items().write(dataStream);
|
entity.items().write(Writes.get(dataStream));
|
||||||
}
|
}
|
||||||
|
|
||||||
dataStream.close();
|
dataStream.close();
|
||||||
@@ -749,7 +749,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
//write all entities now
|
//write all entities now
|
||||||
dataStream.writeInt(entity.id()); //write id
|
dataStream.writeInt(entity.id()); //write id
|
||||||
dataStream.writeByte(entity.classId()); //write type ID
|
dataStream.writeByte(entity.classId()); //write type ID
|
||||||
entity.write(dataStream); //write entity
|
entity.write(Writes.get(dataStream)); //write entity
|
||||||
|
|
||||||
sent++;
|
sent++;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package mindustry.entities.def;
|
package mindustry.entities.def;
|
||||||
|
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.player;
|
import static mindustry.Vars.player;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@@ -53,11 +52,11 @@ abstract class EntityComp{
|
|||||||
abstract boolean serialize();
|
abstract boolean serialize();
|
||||||
|
|
||||||
@MethodPriority(1)
|
@MethodPriority(1)
|
||||||
void read(DataInput input) throws IOException{
|
void read(Reads read){
|
||||||
afterRead();
|
afterRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(DataOutput output) throws IOException{
|
void write(Writes write){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import mindustry.gen.*;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
abstract class MassComp implements Velc{
|
abstract class MassComp implements Velc{
|
||||||
float mass = 1f;
|
transient float mass = 1f;
|
||||||
|
|
||||||
public void impulse(float x, float y){
|
public void impulse(float x, float y){
|
||||||
vel().add(x / mass, y / mass);
|
vel().add(x / mass, y / mass);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.math.geom.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
@@ -13,8 +14,6 @@ import mindustry.world.*;
|
|||||||
import mindustry.world.consumers.*;
|
import mindustry.world.consumers.*;
|
||||||
import mindustry.world.modules.*;
|
import mindustry.world.modules.*;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@EntityDef(value = {Tilec.class}, isFinal = false, genio = false, serialize = false)
|
@EntityDef(value = {Tilec.class}, isFinal = false, genio = false, serialize = false)
|
||||||
@@ -63,30 +62,30 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
public void write(DataOutput output) throws IOException{
|
public void write(Writes write){
|
||||||
output.writeFloat(health());
|
write.f(health());
|
||||||
output.writeByte(tile.rotation());
|
write.b(tile.rotation());
|
||||||
output.writeByte(tile.getTeamID());
|
write.b(tile.getTeamID());
|
||||||
if(items != null) items.write(output);
|
if(items != null) items.write(write);
|
||||||
if(power != null) power.write(output);
|
if(power != null) power.write(write);
|
||||||
if(liquids != null) liquids.write(output);
|
if(liquids != null) liquids.write(write);
|
||||||
if(cons != null) cons.write(output);
|
if(cons != null) cons.write(write);
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput input, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
health(input.readFloat());
|
health(read.f());
|
||||||
byte rotation = input.readByte();
|
byte rotation = read.b();
|
||||||
byte team = input.readByte();
|
byte team = read.b();
|
||||||
|
|
||||||
tile.setTeam(Team.get(team));
|
tile.setTeam(Team.get(team));
|
||||||
tile.rotation(rotation);
|
tile.rotation(rotation);
|
||||||
|
|
||||||
if(items != null) items.read(input);
|
if(items != null) items.read(read);
|
||||||
if(power != null) power.read(input);
|
if(power != null) power.read(read);
|
||||||
if(liquids != null) liquids.read(input);
|
if(liquids != null) liquids.read(read);
|
||||||
if(cons != null) cons.read(input);
|
if(cons != null) cons.read(read);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ abstract class VelComp implements Posc{
|
|||||||
@Import float x, y;
|
@Import float x, y;
|
||||||
|
|
||||||
final Vec2 vel = new Vec2();
|
final Vec2 vel = new Vec2();
|
||||||
float drag = 0f;
|
transient float drag = 0f;
|
||||||
|
|
||||||
//velocity needs to be called first, as it affects delta and lastPosition
|
//velocity needs to be called first, as it affects delta and lastPosition
|
||||||
@MethodPriority(-1)
|
@MethodPriority(-1)
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
if(tile.entity != null){
|
if(tile.entity != null){
|
||||||
writeChunk(stream, true, out -> {
|
writeChunk(stream, true, out -> {
|
||||||
out.writeByte(tile.entity.version());
|
out.writeByte(tile.entity.version());
|
||||||
tile.entity.write(out);
|
tile.entity.write(Writes.get(out));
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
//write consecutive non-entity blocks
|
//write consecutive non-entity blocks
|
||||||
@@ -188,7 +188,7 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
try{
|
try{
|
||||||
readChunk(stream, true, in -> {
|
readChunk(stream, true, in -> {
|
||||||
byte revision = in.readByte();
|
byte revision = in.readByte();
|
||||||
tile.entity.read(in, revision);
|
tile.entity.read(Reads.get(in), revision);
|
||||||
});
|
});
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
throw new IOException("Failed to read tile entity of block: " + block, 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 -> {
|
writeChunk(stream, true, out -> {
|
||||||
out.writeByte(entity.classId());
|
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 -> {
|
readChunk(stream, true, in -> {
|
||||||
byte typeid = in.readByte();
|
byte typeid = in.readByte();
|
||||||
Syncc sync = (Syncc)EntityMapping.map(typeid).get();
|
Syncc sync = (Syncc)EntityMapping.map(typeid).get();
|
||||||
sync.read(in);
|
sync.read(Reads.get(in));
|
||||||
sync.add();
|
sync.add();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.io;
|
package mindustry.io;
|
||||||
|
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.ctype.*;
|
import mindustry.ctype.*;
|
||||||
import mindustry.entities.bullet.*;
|
import mindustry.entities.bullet.*;
|
||||||
@@ -19,60 +20,53 @@ import static mindustry.Vars.*;
|
|||||||
|
|
||||||
/** Class for specifying read/write methods for code generation. */
|
/** Class for specifying read/write methods for code generation. */
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@TypeIOHandler
|
||||||
public class TypeIO{
|
public class TypeIO{
|
||||||
|
|
||||||
@WriteClass(Entityc.class)
|
public static void writeEntity(Writes write, Entityc entity){
|
||||||
public static void writeEntity(ByteBuffer buffer, Entityc entity){
|
write.i(entity == null ? -1 : entity.id());
|
||||||
buffer.putInt(entity == null ? -1 : entity.id());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Entityc.class)
|
public static <T extends Entityc> T readEntity(Reads read){
|
||||||
public static <T extends Entityc> T readEntity(ByteBuffer buffer){
|
return (T)Groups.all.getByID(read.i());
|
||||||
return (T)Groups.all.getByID(buffer.getInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Tile.class)
|
public static void writeTile(Writes write, Tile tile){
|
||||||
public static void writeTile(ByteBuffer buffer, Tile tile){
|
write.i(tile == null ? Pos.get(-1, -1) : tile.pos());
|
||||||
buffer.putInt(tile == null ? Pos.get(-1, -1) : tile.pos());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Tile.class)
|
public static Tile readTile(Reads read){
|
||||||
public static Tile readTile(ByteBuffer buffer){
|
return world.tile(read.i());
|
||||||
return world.tile(buffer.getInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Block.class)
|
public static void writeBlock(Writes write, Block block){
|
||||||
public static void writeBlock(ByteBuffer buffer, Block block){
|
write.s(block.id);
|
||||||
buffer.putShort(block.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Block.class)
|
public static Block readBlock(Reads read){
|
||||||
public static Block readBlock(ByteBuffer buffer){
|
return content.block(read.s());
|
||||||
return content.block(buffer.getShort());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(BuildRequest[].class)
|
public static void writeRequests(Writes write, BuildRequest[] requests){
|
||||||
public static void writeRequests(ByteBuffer buffer, BuildRequest[] requests){
|
write.s((short)requests.length);
|
||||||
buffer.putShort((short)requests.length);
|
|
||||||
for(BuildRequest request : requests){
|
for(BuildRequest request : requests){
|
||||||
buffer.put(request.breaking ? (byte)1 : 0);
|
write.b(request.breaking ? (byte)1 : 0);
|
||||||
buffer.putInt(Pos.get(request.x, request.y));
|
write.i(Pos.get(request.x, request.y));
|
||||||
if(!request.breaking){
|
if(!request.breaking){
|
||||||
buffer.putShort(request.block.id);
|
write.s(request.block.id);
|
||||||
buffer.put((byte)request.rotation);
|
write.b((byte)request.rotation);
|
||||||
buffer.put(request.hasConfig ? (byte)1 : 0);
|
write.b(request.hasConfig ? (byte)1 : 0);
|
||||||
buffer.putInt(request.config);
|
write.i(request.config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(BuildRequest[].class)
|
public static BuildRequest[] readRequests(Reads read){
|
||||||
public static BuildRequest[] readRequests(ByteBuffer buffer){
|
short reqamount = read.s();
|
||||||
short reqamount = buffer.getShort();
|
|
||||||
BuildRequest[] reqs = new BuildRequest[reqamount];
|
BuildRequest[] reqs = new BuildRequest[reqamount];
|
||||||
for(int i = 0; i < reqamount; i++){
|
for(int i = 0; i < reqamount; i++){
|
||||||
byte type = buffer.get();
|
byte type = read.b();
|
||||||
int position = buffer.getInt();
|
int position = read.i();
|
||||||
BuildRequest currentRequest;
|
BuildRequest currentRequest;
|
||||||
|
|
||||||
if(world.tile(position) == null){
|
if(world.tile(position) == null){
|
||||||
@@ -82,10 +76,10 @@ public class TypeIO{
|
|||||||
if(type == 1){ //remove
|
if(type == 1){ //remove
|
||||||
currentRequest = new BuildRequest(Pos.x(position), Pos.y(position));
|
currentRequest = new BuildRequest(Pos.x(position), Pos.y(position));
|
||||||
}else{ //place
|
}else{ //place
|
||||||
short block = buffer.getShort();
|
short block = read.s();
|
||||||
byte rotation = buffer.get();
|
byte rotation = read.b();
|
||||||
boolean hasConfig = buffer.get() == 1;
|
boolean hasConfig = read.b() == 1;
|
||||||
int config = buffer.getInt();
|
int config = read.i();
|
||||||
currentRequest = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.block(block));
|
currentRequest = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.block(block));
|
||||||
if(hasConfig){
|
if(hasConfig){
|
||||||
currentRequest.configure(config);
|
currentRequest.configure(config);
|
||||||
@@ -98,163 +92,152 @@ public class TypeIO{
|
|||||||
return reqs;
|
return reqs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(KickReason.class)
|
public static void writeKick(Writes write, KickReason reason){
|
||||||
public static void writeKick(ByteBuffer buffer, KickReason reason){
|
write.b((byte)reason.ordinal());
|
||||||
buffer.put((byte)reason.ordinal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(KickReason.class)
|
public static KickReason readKick(Reads read){
|
||||||
public static KickReason readKick(ByteBuffer buffer){
|
return KickReason.values()[read.b()];
|
||||||
return KickReason.values()[buffer.get()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Rules.class)
|
public static void writeRules(Writes write, Rules rules){
|
||||||
public static void writeRules(ByteBuffer buffer, Rules rules){
|
|
||||||
String string = JsonIO.write(rules);
|
String string = JsonIO.write(rules);
|
||||||
byte[] bytes = string.getBytes(charset);
|
byte[] bytes = string.getBytes(charset);
|
||||||
buffer.putInt(bytes.length);
|
write.i(bytes.length);
|
||||||
buffer.put(bytes);
|
write.b(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Rules.class)
|
public static Rules readRules(Reads read){
|
||||||
public static Rules readRules(ByteBuffer buffer){
|
int length = read.i();
|
||||||
int length = buffer.getInt();
|
String string = new String(read.b(new byte[length]), charset);
|
||||||
byte[] bytes = new byte[length];
|
|
||||||
buffer.get(bytes);
|
|
||||||
String string = new String(bytes, charset);
|
|
||||||
return JsonIO.read(Rules.class, string);
|
return JsonIO.read(Rules.class, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Team.class)
|
public static void writeTeam(Writes write, Team reason){
|
||||||
public static void writeTeam(ByteBuffer buffer, Team reason){
|
write.b((byte) (int)reason.id);
|
||||||
buffer.put((byte) (int)reason.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Team.class)
|
public static Team readTeam(Reads read){
|
||||||
public static Team readTeam(ByteBuffer buffer){
|
return Team.get(read.b());
|
||||||
return Team.get(buffer.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(UnitCommand.class)
|
public static void writeUnitCommand(Writes write, UnitCommand reason){
|
||||||
public static void writeUnitCommand(ByteBuffer buffer, UnitCommand reason){
|
write.b((byte)reason.ordinal());
|
||||||
buffer.put((byte)reason.ordinal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(UnitCommand.class)
|
public static UnitCommand readUnitCommand(Reads read){
|
||||||
public static UnitCommand readUnitCommand(ByteBuffer buffer){
|
return UnitCommand.all[read.b()];
|
||||||
return UnitCommand.all[buffer.get()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(AdminAction.class)
|
public static void writeAction(Writes write, AdminAction reason){
|
||||||
public static void writeAction(ByteBuffer buffer, AdminAction reason){
|
write.b((byte)reason.ordinal());
|
||||||
buffer.put((byte)reason.ordinal());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(AdminAction.class)
|
public static AdminAction readAction(Reads read){
|
||||||
public static AdminAction readAction(ByteBuffer buffer){
|
return AdminAction.values()[read.b()];
|
||||||
return AdminAction.values()[buffer.get()];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(UnitType.class)
|
public static void writeUnitDef(Writes write, UnitType effect){
|
||||||
public static void writeUnitDef(ByteBuffer buffer, UnitType effect){
|
write.s(effect.id);
|
||||||
buffer.putShort(effect.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(UnitType.class)
|
public static UnitType readUnitDef(Reads read){
|
||||||
public static UnitType readUnitDef(ByteBuffer buffer){
|
return content.getByID(ContentType.unit, read.s());
|
||||||
return content.getByID(ContentType.unit, buffer.getShort());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Color.class)
|
public static void writeColor(Writes write, Color color){
|
||||||
public static void writeColor(ByteBuffer buffer, Color color){
|
write.i(Color.rgba8888(color));
|
||||||
buffer.putInt(Color.rgba8888(color));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Color.class)
|
public static Color readColor(Reads read){
|
||||||
public static Color readColor(ByteBuffer buffer){
|
return new Color(read.i());
|
||||||
return new Color(buffer.getInt());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Liquid.class)
|
public static void writeLiquid(Writes write, Liquid liquid){
|
||||||
public static void writeLiquid(ByteBuffer buffer, Liquid liquid){
|
write.s(liquid == null ? -1 : liquid.id);
|
||||||
buffer.putShort(liquid == null ? -1 : liquid.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Liquid.class)
|
public static Liquid readLiquid(Reads read){
|
||||||
public static Liquid readLiquid(ByteBuffer buffer){
|
short id = read.s();
|
||||||
short id = buffer.getShort();
|
|
||||||
return id == -1 ? null : content.liquid(id);
|
return id == -1 ? null : content.liquid(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(BulletType.class)
|
public static void writeBulletType(Writes write, BulletType type){
|
||||||
public static void writeBulletType(ByteBuffer buffer, BulletType type){
|
write.s(type.id);
|
||||||
buffer.putShort(type.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(BulletType.class)
|
public static BulletType readBulletType(Reads read){
|
||||||
public static BulletType readBulletType(ByteBuffer buffer){
|
return content.getByID(ContentType.bullet, read.s());
|
||||||
return content.getByID(ContentType.bullet, buffer.getShort());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(Item.class)
|
public static void writeItem(Writes write, Item item){
|
||||||
public static void writeItem(ByteBuffer buffer, Item item){
|
write.s(item == null ? -1 : item.id);
|
||||||
buffer.putShort(item == null ? -1 : item.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(Item.class)
|
public static Item readItem(Reads read){
|
||||||
public static Item readItem(ByteBuffer buffer){
|
short id = read.s();
|
||||||
short id = buffer.getShort();
|
|
||||||
return id == -1 ? null : content.item(id);
|
return id == -1 ? null : content.item(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(String.class)
|
public static void writeString(Writes write, String string){
|
||||||
public static void writeString(ByteBuffer buffer, String string){
|
|
||||||
if(string != null){
|
if(string != null){
|
||||||
byte[] bytes = string.getBytes(charset);
|
byte[] bytes = string.getBytes(charset);
|
||||||
buffer.putShort((short)bytes.length);
|
write.s((short)bytes.length);
|
||||||
buffer.put(bytes);
|
write.b(bytes);
|
||||||
}else{
|
}else{
|
||||||
buffer.putShort((short)-1);
|
write.s((short)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(String.class)
|
public static String readString(Reads read){
|
||||||
public static String readString(ByteBuffer buffer){
|
short slength = read.s();
|
||||||
short slength = buffer.getShort();
|
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){
|
if(slength != -1){
|
||||||
byte[] bytes = new byte[slength];
|
byte[] bytes = new byte[slength];
|
||||||
buffer.get(bytes);
|
read.get(bytes);
|
||||||
return new String(bytes, charset);
|
return new String(bytes, charset);
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(byte[].class)
|
public static void writeBytes(Writes write, byte[] bytes){
|
||||||
public static void writeBytes(ByteBuffer buffer, byte[] bytes){
|
write.s((short)bytes.length);
|
||||||
buffer.putShort((short)bytes.length);
|
write.b(bytes);
|
||||||
buffer.put(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(byte[].class)
|
public static byte[] readBytes(Reads read){
|
||||||
public static byte[] readBytes(ByteBuffer buffer){
|
short length = read.s();
|
||||||
short length = buffer.getShort();
|
return read.b(new byte[length]);
|
||||||
byte[] bytes = new byte[length];
|
|
||||||
buffer.get(bytes);
|
|
||||||
return bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@WriteClass(TraceInfo.class)
|
public static void writeTraceInfo(Writes write, TraceInfo trace){
|
||||||
public static void writeTraceInfo(ByteBuffer buffer, TraceInfo trace){
|
writeString(write, trace.ip);
|
||||||
writeString(buffer, trace.ip);
|
writeString(write, trace.uuid);
|
||||||
writeString(buffer, trace.uuid);
|
write.b(trace.modded ? (byte)1 : 0);
|
||||||
buffer.put(trace.modded ? (byte)1 : 0);
|
write.b(trace.mobile ? (byte)1 : 0);
|
||||||
buffer.put(trace.mobile ? (byte)1 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReadClass(TraceInfo.class)
|
public static TraceInfo readTraceInfo(Reads read){
|
||||||
public static TraceInfo readTraceInfo(ByteBuffer buffer){
|
return new TraceInfo(readString(read), readString(read), read.b() == 1, read.b() == 1);
|
||||||
return new TraceInfo(readString(buffer), readString(buffer), buffer.get() == 1, buffer.get() == 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeStringData(DataOutput buffer, String string) throws IOException{
|
public static void writeStringData(DataOutput buffer, String string) throws IOException{
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package mindustry.net;
|
package mindustry.net;
|
||||||
|
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.gen.*;
|
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
import mindustry.io.*;
|
import mindustry.io.*;
|
||||||
import mindustry.maps.Map;
|
import mindustry.maps.Map;
|
||||||
import mindustry.net.Administration.*;
|
import mindustry.net.Administration.*;
|
||||||
@@ -26,7 +27,7 @@ public class NetworkIO{
|
|||||||
stream.writeFloat(state.wavetime);
|
stream.writeFloat(state.wavetime);
|
||||||
|
|
||||||
stream.writeInt(player.id());
|
stream.writeInt(player.id());
|
||||||
player.write(stream);
|
player.write(Writes.get(stream));
|
||||||
|
|
||||||
SaveIO.getSaveWriter().writeContentHeader(stream);
|
SaveIO.getSaveWriter().writeContentHeader(stream);
|
||||||
SaveIO.getSaveWriter().writeMap(stream);
|
SaveIO.getSaveWriter().writeMap(stream);
|
||||||
@@ -48,7 +49,7 @@ public class NetworkIO{
|
|||||||
Groups.all.clear();
|
Groups.all.clear();
|
||||||
int id = stream.readInt();
|
int id = stream.readInt();
|
||||||
player.reset();
|
player.reset();
|
||||||
player.read(stream);
|
player.read(Reads.get(stream));
|
||||||
player.id(id);
|
player.id(id);
|
||||||
player.add();
|
player.add();
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package mindustry.net;
|
|||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import arc.util.serialization.*;
|
import arc.util.serialization.*;
|
||||||
import mindustry.core.*;
|
import mindustry.core.*;
|
||||||
import mindustry.io.*;
|
import mindustry.io.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,31 +67,29 @@ public class Packets{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class InvokePacket implements Packet{
|
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 byte type, priority;
|
||||||
|
|
||||||
public ByteBuffer writeBuffer;
|
public byte[] bytes;
|
||||||
public int writeLength;
|
public int length;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuffer buffer){
|
public void read(ByteBuffer buffer){
|
||||||
type = buffer.get();
|
type = buffer.get();
|
||||||
priority = buffer.get();
|
priority = buffer.get();
|
||||||
writeLength = buffer.getShort();
|
short writeLength = buffer.getShort();
|
||||||
byte[] bytes = new byte[writeLength];
|
byte[] bytes = new byte[writeLength];
|
||||||
buffer.get(bytes);
|
buffer.get(bytes);
|
||||||
writeBuffer = ByteBuffer.wrap(bytes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer){
|
public void write(ByteBuffer buffer){
|
||||||
buffer.put(type);
|
buffer.put(type);
|
||||||
buffer.put(priority);
|
buffer.put(priority);
|
||||||
buffer.putShort((short)writeLength);
|
buffer.putShort((short)length);
|
||||||
|
buffer.put(bytes, 0, length);
|
||||||
writeBuffer.position(0);
|
|
||||||
for(int i = 0; i < writeLength; i++){
|
|
||||||
buffer.put(writeBuffer.get());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -106,6 +106,11 @@ public class Packets{
|
|||||||
public boolean isUnimportant(){
|
public boolean isUnimportant(){
|
||||||
return priority == 2;
|
return priority == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Reads reader(){
|
||||||
|
bin.setBytes(bytes);
|
||||||
|
return read;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Marks the beginning of a stream. */
|
/** Marks the beginning of a stream. */
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package mindustry.world;
|
package mindustry.world;
|
||||||
|
|
||||||
import mindustry.annotations.Annotations.Struct;
|
import arc.util.*;
|
||||||
import arc.util.Time;
|
import arc.util.io.*;
|
||||||
import mindustry.gen.BufferItem;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.type.Item;
|
import mindustry.gen.*;
|
||||||
|
import mindustry.type.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@@ -46,22 +47,22 @@ public class DirectionalItemBuffer{
|
|||||||
indexes[buffer] --;
|
indexes[buffer] --;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
stream.writeByte(indexes[i]);
|
write.b(indexes[i]);
|
||||||
stream.writeByte(buffers[i].length);
|
write.b(buffers[i].length);
|
||||||
for(long l : buffers[i]){
|
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++){
|
for(int i = 0; i < 4; i++){
|
||||||
indexes[i] = stream.readByte();
|
indexes[i] = read.b();
|
||||||
byte length = stream.readByte();
|
byte length = read.b();
|
||||||
for(int j = 0; j < length; j++){
|
for(int j = 0; j < length; j++){
|
||||||
long value = stream.readLong();
|
long value = read.l();
|
||||||
if(j < buffers[i].length){
|
if(j < buffers[i].length){
|
||||||
buffers[i][j] = value;
|
buffers[i][j] = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package mindustry.world;
|
package mindustry.world;
|
||||||
|
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.type.Item;
|
import arc.util.io.*;
|
||||||
|
import mindustry.type.*;
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.content;
|
import static mindustry.Vars.content;
|
||||||
|
|
||||||
@@ -60,19 +59,19 @@ public class ItemBuffer{
|
|||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
stream.writeByte((byte)index);
|
write.b((byte)index);
|
||||||
stream.writeByte((byte)buffer.length);
|
write.b((byte)buffer.length);
|
||||||
for(long l : buffer){
|
for(long l : buffer){
|
||||||
stream.writeLong(l);
|
write.l(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(DataInput stream) throws IOException{
|
public void read(Reads read){
|
||||||
index = stream.readByte();
|
index = read.b();
|
||||||
byte length = stream.readByte();
|
byte length = read.b();
|
||||||
for(int i = 0; i < length; i++){
|
for(int i = 0; i < length; i++){
|
||||||
long l = stream.readLong();
|
long l = read.l();
|
||||||
if(i < buffer.length){
|
if(i < buffer.length){
|
||||||
buffer[i] = l;
|
buffer[i] = l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
@@ -347,37 +348,37 @@ public class BuildBlock extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(progress);
|
write.f(progress);
|
||||||
stream.writeShort(previous == null ? -1 : previous.id);
|
write.s(previous == null ? -1 : previous.id);
|
||||||
stream.writeShort(cblock == null ? -1 : cblock.id);
|
write.s(cblock == null ? -1 : cblock.id);
|
||||||
|
|
||||||
if(accumulator == null){
|
if(accumulator == null){
|
||||||
stream.writeByte(-1);
|
write.b(-1);
|
||||||
}else{
|
}else{
|
||||||
stream.writeByte(accumulator.length);
|
write.b(accumulator.length);
|
||||||
for(int i = 0; i < accumulator.length; i++){
|
for(int i = 0; i < accumulator.length; i++){
|
||||||
stream.writeFloat(accumulator[i]);
|
write.f(accumulator[i]);
|
||||||
stream.writeFloat(totalAccumulator[i]);
|
write.f(totalAccumulator[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
progress = stream.readFloat();
|
progress = read.f();
|
||||||
short pid = stream.readShort();
|
short pid = read.s();
|
||||||
short rid = stream.readShort();
|
short rid = read.s();
|
||||||
byte acsize = stream.readByte();
|
byte acsize = read.b();
|
||||||
|
|
||||||
if(acsize != -1){
|
if(acsize != -1){
|
||||||
accumulator = new float[acsize];
|
accumulator = new float[acsize];
|
||||||
totalAccumulator = new float[acsize];
|
totalAccumulator = new float[acsize];
|
||||||
for(int i = 0; i < acsize; i++){
|
for(int i = 0; i < acsize; i++){
|
||||||
accumulator[i] = stream.readFloat();
|
accumulator[i] = read.f();
|
||||||
totalAccumulator[i] = stream.readFloat();
|
totalAccumulator[i] = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.world.blocks.defense;
|
package mindustry.world.blocks.defense;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import arc.Graphics.*;
|
import arc.Graphics.*;
|
||||||
import arc.Graphics.Cursor.*;
|
import arc.Graphics.Cursor.*;
|
||||||
@@ -92,15 +93,15 @@ public class Door extends Wall{
|
|||||||
public boolean open = false;
|
public boolean open = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeBoolean(open);
|
write.bool(open);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
open = stream.readBoolean();
|
open = read.bool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
@@ -171,23 +172,23 @@ public class ForceProjector extends Block{
|
|||||||
float phaseHeat;
|
float phaseHeat;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeBoolean(broken);
|
write.bool(broken);
|
||||||
stream.writeFloat(buildup);
|
write.f(buildup);
|
||||||
stream.writeFloat(radscl);
|
write.f(radscl);
|
||||||
stream.writeFloat(warmup);
|
write.f(warmup);
|
||||||
stream.writeFloat(phaseHeat);
|
write.f(phaseHeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
broken = stream.readBoolean();
|
broken = read.bool();
|
||||||
buildup = stream.readFloat();
|
buildup = read.f();
|
||||||
radscl = stream.readFloat();
|
radscl = read.f();
|
||||||
warmup = stream.readFloat();
|
warmup = read.f();
|
||||||
phaseHeat = stream.readFloat();
|
phaseHeat = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import arc.graphics.Color;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.Mathf;
|
import arc.math.Mathf;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.Fx;
|
import mindustry.content.Fx;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
@@ -126,17 +127,17 @@ public class MendProjector extends Block{
|
|||||||
float phaseHeat;
|
float phaseHeat;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(heat);
|
write.f(heat);
|
||||||
stream.writeFloat(phaseHeat);
|
write.f(phaseHeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
heat = stream.readFloat();
|
heat = read.f();
|
||||||
phaseHeat = stream.readFloat();
|
phaseHeat = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import arc.graphics.Color;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.Mathf;
|
import arc.math.Mathf;
|
||||||
import arc.util.Time;
|
import arc.util.Time;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -124,17 +125,17 @@ public class OverdriveProjector extends Block{
|
|||||||
float phaseHeat;
|
float phaseHeat;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(heat);
|
write.f(heat);
|
||||||
stream.writeFloat(phaseHeat);
|
write.f(phaseHeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
heat = stream.readFloat();
|
heat = read.f();
|
||||||
phaseHeat = stream.readFloat();
|
phaseHeat = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mindustry.world.blocks.defense.turrets;
|
|||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.entities.bullet.*;
|
import mindustry.entities.bullet.*;
|
||||||
@@ -151,23 +152,23 @@ public class ItemTurret extends CooledTurret{
|
|||||||
|
|
||||||
public class ItemTurretEntity extends TurretEntity{
|
public class ItemTurretEntity extends TurretEntity{
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeByte(ammo.size);
|
write.b(ammo.size);
|
||||||
for(AmmoEntry entry : ammo){
|
for(AmmoEntry entry : ammo){
|
||||||
ItemEntry i = (ItemEntry)entry;
|
ItemEntry i = (ItemEntry)entry;
|
||||||
stream.writeByte(i.item.id);
|
write.b(i.item.id);
|
||||||
stream.writeShort(i.amount);
|
write.s(i.amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
byte amount = stream.readByte();
|
byte amount = read.b();
|
||||||
for(int i = 0; i < amount; i++){
|
for(int i = 0; i < amount; i++){
|
||||||
Item item = Vars.content.item(stream.readByte());
|
Item item = Vars.content.item(read.b());
|
||||||
short a = stream.readShort();
|
short a = read.s();
|
||||||
totalAmmo += a;
|
totalAmmo += a;
|
||||||
ammo.add(new ItemEntry(item, a));
|
ammo.add(new ItemEntry(item, a));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import arc.math.Angles;
|
|||||||
import arc.math.Mathf;
|
import arc.math.Mathf;
|
||||||
import arc.math.geom.Vec2;
|
import arc.math.geom.Vec2;
|
||||||
import arc.util.Time;
|
import arc.util.Time;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.Fx;
|
import mindustry.content.Fx;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.entities.bullet.BulletType;
|
import mindustry.entities.bullet.BulletType;
|
||||||
@@ -320,17 +321,17 @@ public abstract class Turret extends Block{
|
|||||||
public Posc target;
|
public Posc target;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(reload);
|
write.f(reload);
|
||||||
stream.writeFloat(rotation);
|
write.f(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
reload = stream.readFloat();
|
reload = read.f();
|
||||||
rotation = stream.readFloat();
|
rotation = read.f();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.world.blocks.distribution;
|
package mindustry.world.blocks.distribution;
|
||||||
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
|
||||||
@@ -41,15 +42,15 @@ public class BufferedItemBridge extends ExtendingItemBridge{
|
|||||||
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
|
ItemBuffer buffer = new ItemBuffer(bufferCapacity, speed);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
buffer.write(stream);
|
buffer.write(write);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
buffer.read(stream);
|
buffer.read(read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import arc.math.geom.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
@@ -351,23 +352,23 @@ public class Conveyor extends Block implements Autotiler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeInt(len);
|
write.i(len);
|
||||||
|
|
||||||
for(int i = 0; i < len; i++){
|
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
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
int amount = stream.readInt();
|
int amount = read.i();
|
||||||
len = Math.min(amount, capacity);
|
len = Math.min(amount, capacity);
|
||||||
|
|
||||||
for(int i = 0; i < amount; i++){
|
for(int i = 0; i < amount; i++){
|
||||||
int val = stream.readInt();
|
int val = read.i();
|
||||||
byte id = (byte)(val >> 24);
|
byte id = (byte)(val >> 24);
|
||||||
float x = (float)((byte)(val >> 16)) / 127f;
|
float x = (float)((byte)(val >> 16)) / 127f;
|
||||||
float y = ((float)((byte)(val >> 8)) + 128f) / 255f;
|
float y = ((float)((byte)(val >> 8)) + 128f) / 255f;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
@@ -375,27 +376,27 @@ public class ItemBridge extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeInt(link);
|
write.i(link);
|
||||||
stream.writeFloat(uptime);
|
write.f(uptime);
|
||||||
stream.writeByte(incoming.size);
|
write.b(incoming.size);
|
||||||
|
|
||||||
IntSetIterator it = incoming.iterator();
|
IntSetIterator it = incoming.iterator();
|
||||||
|
|
||||||
while(it.hasNext){
|
while(it.hasNext){
|
||||||
stream.writeInt(it.next());
|
write.i(it.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
link = stream.readInt();
|
link = read.i();
|
||||||
uptime = stream.readFloat();
|
uptime = read.f();
|
||||||
byte links = stream.readByte();
|
byte links = read.b();
|
||||||
for(int i = 0; i < links; i++){
|
for(int i = 0; i < links; i++){
|
||||||
incoming.add(stream.readInt());
|
incoming.add(read.i());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mindustry.world.blocks.distribution;
|
package mindustry.world.blocks.distribution;
|
||||||
|
|
||||||
import arc.util.Time;
|
import arc.util.Time;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.gen.BufferItem;
|
import mindustry.gen.BufferItem;
|
||||||
import mindustry.type.Item;
|
import mindustry.type.Item;
|
||||||
@@ -9,8 +10,6 @@ import mindustry.world.DirectionalItemBuffer;
|
|||||||
import mindustry.world.Tile;
|
import mindustry.world.Tile;
|
||||||
import mindustry.world.meta.BlockGroup;
|
import mindustry.world.meta.BlockGroup;
|
||||||
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static mindustry.Vars.content;
|
import static mindustry.Vars.content;
|
||||||
@@ -89,15 +88,15 @@ public class Junction extends Block{
|
|||||||
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed);
|
DirectionalItemBuffer buffer = new DirectionalItemBuffer(capacity, speed);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
buffer.write(stream);
|
buffer.write(write);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
buffer.read(stream);
|
buffer.read(read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.struct.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import arc.util.pooling.Pool.*;
|
import arc.util.pooling.Pool.*;
|
||||||
import arc.util.pooling.*;
|
import arc.util.pooling.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
@@ -332,19 +333,19 @@ public class MassDriver extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeInt(link);
|
write.i(link);
|
||||||
stream.writeFloat(rotation);
|
write.f(rotation);
|
||||||
stream.writeByte((byte)state.ordinal());
|
write.b((byte)state.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
link = stream.readInt();
|
link = read.i();
|
||||||
rotation = stream.readFloat();
|
rotation = read.f();
|
||||||
state = DriverState.values()[stream.readByte()];
|
state = DriverState.values()[read.b()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package mindustry.world.blocks.distribution;
|
|||||||
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -124,10 +125,10 @@ public class OverflowGate extends Block{
|
|||||||
float time;
|
float time;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
if(revision == 1){
|
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.scene.ui.layout.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
@@ -156,18 +157,18 @@ public class Sorter extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeShort(sortItem == null ? -1 : sortItem.id);
|
write.s(sortItem == null ? -1 : sortItem.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
sortItem = content.item(stream.readShort());
|
sortItem = content.item(read.s());
|
||||||
|
|
||||||
if(revision == 1){
|
if(revision == 1){
|
||||||
new DirectionalItemBuffer(20, 45f).read(stream);
|
new DirectionalItemBuffer(20, 45f).read(read);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package mindustry.world.blocks.logic;
|
package mindustry.world.blocks.logic;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
|
||||||
import arc.Input.*;
|
import arc.Input.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
@@ -9,7 +8,9 @@ import arc.math.geom.*;
|
|||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import arc.util.pooling.*;
|
import arc.util.pooling.*;
|
||||||
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.net.*;
|
import mindustry.net.*;
|
||||||
@@ -17,8 +18,6 @@ import mindustry.ui.*;
|
|||||||
import mindustry.ui.dialogs.*;
|
import mindustry.ui.dialogs.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class MessageBlock extends Block{
|
public class MessageBlock extends Block{
|
||||||
@@ -150,15 +149,15 @@ public class MessageBlock extends Block{
|
|||||||
public String[] lines = {""};
|
public String[] lines = {""};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeUTF(message);
|
write.str(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
message = stream.readUTF();
|
message = read.str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.graphics.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
@@ -165,15 +166,15 @@ public class ImpactReactor extends PowerGenerator{
|
|||||||
public float warmup;
|
public float warmup;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(warmup);
|
write.f(warmup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
warmup = stream.readFloat();
|
warmup = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.graphics.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.world.*;
|
import mindustry.world.*;
|
||||||
@@ -80,15 +81,15 @@ public class LightBlock extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeInt(color);
|
write.i(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
color = stream.readInt();
|
color = read.i();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
@@ -186,15 +187,15 @@ public class NuclearReactor extends PowerGenerator{
|
|||||||
public float flash;
|
public float flash;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(heat);
|
write.f(heat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
heat = stream.readFloat();
|
heat = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package mindustry.world.blocks.power;
|
|||||||
import arc.Core;
|
import arc.Core;
|
||||||
import arc.struct.EnumSet;
|
import arc.struct.EnumSet;
|
||||||
import arc.util.Strings;
|
import arc.util.Strings;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.Pal;
|
import mindustry.graphics.Pal;
|
||||||
import mindustry.ui.Bar;
|
import mindustry.ui.Bar;
|
||||||
@@ -59,15 +60,15 @@ public class PowerGenerator extends PowerDistributor{
|
|||||||
public float productionEfficiency = 0.0f;
|
public float productionEfficiency = 0.0f;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(productionEfficiency);
|
write.f(productionEfficiency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
productionEfficiency = stream.readFloat();
|
productionEfficiency = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.graphics.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
@@ -120,15 +121,15 @@ public class Cultivator extends GenericCrafter{
|
|||||||
public float boost;
|
public float boost;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(warmup);
|
write.f(warmup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
warmup = stream.readFloat();
|
warmup = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.func.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
@@ -151,17 +152,17 @@ public class GenericCrafter extends Block{
|
|||||||
public float warmup;
|
public float warmup;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(progress);
|
write.f(progress);
|
||||||
stream.writeFloat(warmup);
|
write.f(warmup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
progress = stream.readFloat();
|
progress = read.f();
|
||||||
warmup = stream.readFloat();
|
warmup = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
@@ -101,15 +102,15 @@ public class ItemSource extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeShort(outputItem == null ? -1 : outputItem.id);
|
write.s(outputItem == null ? -1 : outputItem.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
outputItem = content.item(stream.readShort());
|
outputItem = content.item(read.s());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import arc.graphics.g2d.*;
|
|||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
@@ -97,15 +98,15 @@ public class LiquidSource extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeByte(source == null ? -1 : source.id);
|
write.b(source == null ? -1 : source.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
byte id = stream.readByte();
|
byte id = read.b();
|
||||||
source = id == -1 ? null : content.liquid(id);
|
source = id == -1 ? null : content.liquid(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.graphics.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
@@ -138,15 +139,15 @@ public class Unloader extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeByte(sortItem == null ? -1 : sortItem.id);
|
write.b(sortItem == null ? -1 : sortItem.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
byte id = stream.readByte();
|
byte id = read.b();
|
||||||
sortItem = id == -1 ? null : content.items().get(id);
|
sortItem = id == -1 ? null : content.items().get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import arc.scene.ui.*;
|
|||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.entities.*;
|
import mindustry.entities.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
@@ -126,15 +127,15 @@ public class CommandCenter extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeByte(command.ordinal());
|
write.b(command.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
command = UnitCommand.all[stream.readByte()];
|
command = UnitCommand.all[read.b()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import arc.math.geom.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.ArcAnnotate.*;
|
import arc.util.ArcAnnotate.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
@@ -140,19 +141,19 @@ public class MechPad extends Block{
|
|||||||
float heat;
|
float heat;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(progress);
|
write.f(progress);
|
||||||
stream.writeFloat(time);
|
write.f(time);
|
||||||
stream.writeFloat(heat);
|
write.f(heat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
progress = stream.readFloat();
|
progress = read.f();
|
||||||
time = stream.readFloat();
|
time = read.f();
|
||||||
heat = stream.readFloat();
|
heat = read.f();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import arc.*;
|
|||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.content.*;
|
import mindustry.content.*;
|
||||||
@@ -189,17 +190,17 @@ public class UnitFactory extends Block{
|
|||||||
int spawned;
|
int spawned;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
super.write(stream);
|
super.write(write);
|
||||||
stream.writeFloat(buildTime);
|
write.f(buildTime);
|
||||||
stream.writeInt(spawned);
|
write.i(spawned);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(Reads read, byte revision){
|
||||||
super.read(stream, revision);
|
super.read(read, revision);
|
||||||
buildTime = stream.readFloat();
|
buildTime = read.f();
|
||||||
spawned = stream.readInt();
|
spawned = read.i();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package mindustry.world.modules;
|
package mindustry.world.modules;
|
||||||
|
|
||||||
import java.io.*;
|
import arc.util.io.*;
|
||||||
|
|
||||||
/** A class that represents compartmentalized tile entity state. */
|
/** A class that represents compartmentalized tile entity state. */
|
||||||
public abstract class BlockModule{
|
public abstract class BlockModule{
|
||||||
public abstract void write(DataOutput stream) throws IOException;
|
public abstract void write(Writes write);
|
||||||
|
public abstract void read(Reads read);
|
||||||
public abstract void read(DataInput stream) throws IOException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package mindustry.world.modules;
|
package mindustry.world.modules;
|
||||||
|
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.world.consumers.Consume;
|
import mindustry.world.consumers.Consume;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class ConsumeModule extends BlockModule{
|
public class ConsumeModule extends BlockModule{
|
||||||
private boolean valid, optionalValid;
|
private boolean valid, optionalValid;
|
||||||
private final Tilec entity;
|
private final Tilec entity;
|
||||||
@@ -59,12 +58,12 @@ public class ConsumeModule extends BlockModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
stream.writeBoolean(valid);
|
write.bool(valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream) throws IOException{
|
public void read(Reads read){
|
||||||
valid = stream.readBoolean();
|
valid = read.bool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package mindustry.world.modules;
|
package mindustry.world.modules;
|
||||||
|
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.type.Item;
|
import mindustry.type.Item;
|
||||||
import mindustry.type.ItemStack;
|
import mindustry.type.ItemStack;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static mindustry.Vars.content;
|
import static mindustry.Vars.content;
|
||||||
@@ -121,32 +121,32 @@ public class ItemModule extends BlockModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
byte amount = 0;
|
byte amount = 0;
|
||||||
for(int item : items){
|
for(int item : items){
|
||||||
if(item > 0) amount++;
|
if(item > 0) amount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.writeByte(amount); //amount of items
|
write.b(amount); //amount of items
|
||||||
|
|
||||||
for(int i = 0; i < items.length; i++){
|
for(int i = 0; i < items.length; i++){
|
||||||
if(items[i] > 0){
|
if(items[i] > 0){
|
||||||
stream.writeByte(i); //item ID
|
write.b(i); //item ID
|
||||||
stream.writeInt(items[i]); //item amount
|
write.i(items[i]); //item amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream) throws IOException{
|
public void read(Reads read){
|
||||||
//just in case, reset items
|
//just in case, reset items
|
||||||
Arrays.fill(items, 0);
|
Arrays.fill(items, 0);
|
||||||
byte count = stream.readByte();
|
byte count = read.b();
|
||||||
total = 0;
|
total = 0;
|
||||||
|
|
||||||
for(int j = 0; j < count; j++){
|
for(int j = 0; j < count; j++){
|
||||||
int itemid = stream.readByte();
|
int itemid = read.b();
|
||||||
int itemamount = stream.readInt();
|
int itemamount = read.i();
|
||||||
items[content.item(itemid).id] = itemamount;
|
items[content.item(itemid).id] = itemamount;
|
||||||
total += itemamount;
|
total += itemamount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package mindustry.world.modules;
|
package mindustry.world.modules;
|
||||||
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.type.Liquid;
|
import mindustry.type.Liquid;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static mindustry.Vars.content;
|
import static mindustry.Vars.content;
|
||||||
@@ -83,31 +83,31 @@ public class LiquidModule extends BlockModule{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
byte amount = 0;
|
byte amount = 0;
|
||||||
for(float liquid : liquids){
|
for(float liquid : liquids){
|
||||||
if(liquid > 0) amount++;
|
if(liquid > 0) amount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.writeByte(amount); //amount of liquids
|
write.b(amount); //amount of liquids
|
||||||
|
|
||||||
for(int i = 0; i < liquids.length; i++){
|
for(int i = 0; i < liquids.length; i++){
|
||||||
if(liquids[i] > 0){
|
if(liquids[i] > 0){
|
||||||
stream.writeByte(i); //liquid ID
|
write.b(i); //liquid ID
|
||||||
stream.writeFloat(liquids[i]); //item amount
|
write.f(liquids[i]); //item amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput stream) throws IOException{
|
public void read(Reads read){
|
||||||
Arrays.fill(liquids, 0);
|
Arrays.fill(liquids, 0);
|
||||||
total = 0f;
|
total = 0f;
|
||||||
byte count = stream.readByte();
|
byte count = read.b();
|
||||||
|
|
||||||
for(int j = 0; j < count; j++){
|
for(int j = 0; j < count; j++){
|
||||||
int liquidid = stream.readByte();
|
int liquidid = read.b();
|
||||||
float amount = stream.readFloat();
|
float amount = read.f();
|
||||||
liquids[liquidid] = amount;
|
liquids[liquidid] = amount;
|
||||||
if(amount > 0){
|
if(amount > 0){
|
||||||
current = content.liquid(liquidid);
|
current = content.liquid(liquidid);
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package mindustry.world.modules;
|
package mindustry.world.modules;
|
||||||
|
|
||||||
import arc.struct.IntArray;
|
import arc.struct.IntArray;
|
||||||
|
import arc.util.io.*;
|
||||||
import mindustry.world.blocks.power.PowerGraph;
|
import mindustry.world.blocks.power.PowerGraph;
|
||||||
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class PowerModule extends BlockModule{
|
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.
|
* 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();
|
public IntArray links = new IntArray();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(Writes write){
|
||||||
stream.writeShort(links.size);
|
write.s(links.size);
|
||||||
for(int i = 0; i < links.size; i++){
|
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
|
@Override
|
||||||
public void read(DataInput stream) throws IOException{
|
public void read(Reads read){
|
||||||
links.clear();
|
links.clear();
|
||||||
short amount = stream.readShort();
|
short amount = read.s();
|
||||||
for(int i = 0; i < amount; i++){
|
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;
|
if(Float.isNaN(status) || Float.isInfinite(status)) status = 0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=d271474a36e1b68887bdb7520bf683c5aa832e79
|
archash=9a946c98476bfbae80840608862e934f4c66b6cd
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
|
import arc.util.io.*;
|
||||||
|
import mindustry.content.*;
|
||||||
import mindustry.game.*;
|
import mindustry.game.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
import mindustry.io.*;
|
import mindustry.io.*;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class IOTests{
|
public class IOTests{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void writeEntities(){
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void writeEnglish(){
|
void writeEnglish(){
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(500);
|
ByteBuffer buffer = ByteBuffer.allocate(500);
|
||||||
|
|||||||
Reference in New Issue
Block a user