Major refactoring of building, sound, inventory
This commit is contained in:
@@ -4,6 +4,7 @@ import com.squareup.javapoet.*;
|
||||
import io.anuke.annotations.Annotations.Local;
|
||||
import io.anuke.annotations.Annotations.RemoteClient;
|
||||
import io.anuke.annotations.Annotations.RemoteServer;
|
||||
import io.anuke.annotations.Annotations.Unreliable;
|
||||
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
@@ -22,7 +23,8 @@ import java.util.Set;
|
||||
@SupportedAnnotationTypes({
|
||||
"io.anuke.annotations.Annotations.RemoteClient",
|
||||
"io.anuke.annotations.Annotations.RemoteServer",
|
||||
"io.anuke.annotations.Annotations.Local"
|
||||
"io.anuke.annotations.Annotations.Local",
|
||||
"io.anuke.annotations.Annotations.Unreliable"
|
||||
})
|
||||
public class AnnotationProcessor extends AbstractProcessor {
|
||||
private static final int maxPacketSize = 128;
|
||||
@@ -39,6 +41,19 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
"rtype rvalue = io.anuke.mindustry.Vars.playerGroup.getByID(rbuffer.getInt())"
|
||||
}
|
||||
});
|
||||
|
||||
put("String", new String[][]{
|
||||
{
|
||||
"rbuffer.putShort((short)rvalue.getBytes().length)",
|
||||
"rbuffer.put(rvalue.getBytes())"
|
||||
},
|
||||
{
|
||||
"short __rvalue_length = rbuffer.getShort()",
|
||||
"byte[] __rvalue_bytes = new byte[__rvalue_length]",
|
||||
"rbuffer.get(__rvalue_bytes)",
|
||||
"rtype rvalue = new rtype(__rvalue_bytes)"
|
||||
}
|
||||
});
|
||||
}};
|
||||
|
||||
private Types typeUtils;
|
||||
@@ -109,6 +124,7 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
|
||||
if(e.getAnnotation(annotation) == null) continue;
|
||||
boolean local = e.getAnnotation(Local.class) != null;
|
||||
boolean unreliable = e.getAnnotation(Unreliable.class) != null;
|
||||
|
||||
ExecutableElement exec = (ExecutableElement)e;
|
||||
|
||||
@@ -211,7 +227,8 @@ public class AnnotationProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
method.addStatement("packet.writeLength = TEMP_BUFFER.position()");
|
||||
method.addStatement("io.anuke.mindustry.net.Net.send(packet, io.anuke.mindustry.net.Net.SendMode.tcp)");
|
||||
method.addStatement("io.anuke.mindustry.net.Net.send(packet, "+
|
||||
(unreliable ? "io.anuke.mindustry.net.Net.SendMode.udp" : "io.anuke.mindustry.net.Net.SendMode.tcp")+")");
|
||||
|
||||
classBuilder.addMethod(method.build());
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ import java.lang.annotation.Target;
|
||||
* {@link RemoteServer}: Marks a method as able to be invoked remotely on a server from a client.<br>
|
||||
* {@link Local}: Makes this method get invoked locally as well as remotely.<br>
|
||||
*<br>
|
||||
* All RemoteClient methods are put in the class CallClient, and all RemoteServer methods are put in the class CallServer.<br>
|
||||
* All RemoteClient methods are put in the class io.anuke.mindustry.gen.CallClient.<br>
|
||||
* All RemoteServer methods are put in the class io.anuke.mindustry.gen.CallServer.<br>
|
||||
*/
|
||||
public class Annotations {
|
||||
|
||||
@@ -35,4 +36,10 @@ public class Annotations {
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface Local{}
|
||||
|
||||
/**Marks a method to be invoked unreliably, e.g. with UDP instead of TCP.
|
||||
* This is faster, but is prone to packet loss and duplication.*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.CLASS)
|
||||
public @interface Unreliable{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user