Updated annotations module

This commit is contained in:
Anuken 2018-07-03 19:58:24 -04:00
parent 60deb9205b
commit 5fdf7e3a12
5 changed files with 20 additions and 3 deletions

View File

@ -28,6 +28,8 @@ public class Annotations {
boolean unreliable() default false;
/**The simple class name where this method is placed.*/
String in() default "Call";
/**Priority of this event.*/
PacketPriority priority() default PacketPriority.normal;
}
/**Specifies that this method will be used to write classes of the type returned by {@link #value()}.<br>
@ -48,6 +50,15 @@ public class Annotations {
Class<?> value();
}
public enum PacketPriority {
/**Gets put in a queue and processed if not connected.*/
normal,
/**Gets handled immediately, regardless of connection status.*/
high,
/**Does not get handled unless client is connected.*/
low
}
/**A set of two booleans, one specifying server and one specifying client.*/
public enum Loc {
/**Method can only be invoked on the client from the server.*/

View File

@ -1,6 +1,7 @@
package io.anuke.annotations;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.PacketPriority;
import io.anuke.annotations.Annotations.Variant;
import javax.lang.model.element.ExecutableElement;
@ -26,9 +27,11 @@ public class MethodEntry {
public final int id;
/**The element method associated with this entry.*/
public final ExecutableElement element;
/**The assigned packet priority. Only used in clients.*/
public final PacketPriority priority;
public MethodEntry(String className, String targetMethod, Loc where, Variant target,
Loc local, boolean unreliable, boolean forward, int id, ExecutableElement element) {
Loc local, boolean unreliable, boolean forward, int id, ExecutableElement element, PacketPriority priority) {
this.className = className;
this.forward = forward;
this.targetMethod = targetMethod;
@ -38,6 +41,7 @@ public class MethodEntry {
this.id = id;
this.element = element;
this.unreliable = unreliable;
this.priority = priority;
}
@Override

View File

@ -114,7 +114,7 @@ public class RemoteMethodAnnotationProcessor extends AbstractProcessor {
//create and add entry
MethodEntry method = new MethodEntry(entry.name, Utils.getMethodName(element), annotation.targets(), annotation.variants(),
annotation.called(), annotation.unreliable(), annotation.forward(), lastMethodID++, (ExecutableElement) element);
annotation.called(), annotation.unreliable(), annotation.forward(), lastMethodID++, (ExecutableElement) element, annotation.priority());
entry.methods.add(method);
methods.add(method);

View File

@ -117,7 +117,7 @@ public class RemoteReadGenerator {
if(entry.forward && entry.where.isServer && needsPlayer){
//call forwarded method
readBlock.addStatement(packageName + "." + entry.className + "." + entry.element.getSimpleName() +
"__forward(player.clientid" + (varResult.length() == 0 ? "" : ", ") + varResult.toString() + ")");
"__forward(player.con.id" + (varResult.length() == 0 ? "" : ", ") + varResult.toString() + ")");
}
readBlock.nextControlFlow("catch (java.lang.Exception e)");

View File

@ -132,6 +132,8 @@ public class RemoteWriteGenerator {
method.addStatement("$1N packet = $2N.obtain($1N.class)", "io.anuke.mindustry.net.Packets.InvokePacket", "com.badlogic.gdx.utils.Pools");
//assign buffer
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
//assign priority
method.addStatement("packet.priority = (byte)" + methodEntry.priority.ordinal());
//assign method ID
method.addStatement("packet.type = (byte)" + methodEntry.id);
//rewind buffer