From 5fdf7e3a12f786b3de510d5f9c6e8539487d437b Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 3 Jul 2018 19:58:24 -0400 Subject: [PATCH] Updated annotations module --- annotations/src/io/anuke/annotations/Annotations.java | 11 +++++++++++ annotations/src/io/anuke/annotations/MethodEntry.java | 6 +++++- .../annotations/RemoteMethodAnnotationProcessor.java | 2 +- .../src/io/anuke/annotations/RemoteReadGenerator.java | 2 +- .../io/anuke/annotations/RemoteWriteGenerator.java | 2 ++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/annotations/src/io/anuke/annotations/Annotations.java b/annotations/src/io/anuke/annotations/Annotations.java index b405c437b9..325663f951 100644 --- a/annotations/src/io/anuke/annotations/Annotations.java +++ b/annotations/src/io/anuke/annotations/Annotations.java @@ -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()}.
@@ -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.*/ diff --git a/annotations/src/io/anuke/annotations/MethodEntry.java b/annotations/src/io/anuke/annotations/MethodEntry.java index fd01caa772..ee47fccb4a 100644 --- a/annotations/src/io/anuke/annotations/MethodEntry.java +++ b/annotations/src/io/anuke/annotations/MethodEntry.java @@ -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 diff --git a/annotations/src/io/anuke/annotations/RemoteMethodAnnotationProcessor.java b/annotations/src/io/anuke/annotations/RemoteMethodAnnotationProcessor.java index 9635bf4226..037ec8129a 100644 --- a/annotations/src/io/anuke/annotations/RemoteMethodAnnotationProcessor.java +++ b/annotations/src/io/anuke/annotations/RemoteMethodAnnotationProcessor.java @@ -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); diff --git a/annotations/src/io/anuke/annotations/RemoteReadGenerator.java b/annotations/src/io/anuke/annotations/RemoteReadGenerator.java index a089619d89..ae2ab83de7 100644 --- a/annotations/src/io/anuke/annotations/RemoteReadGenerator.java +++ b/annotations/src/io/anuke/annotations/RemoteReadGenerator.java @@ -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)"); diff --git a/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java b/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java index 5c4b4d5a76..1d80dcbc67 100644 --- a/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java +++ b/annotations/src/io/anuke/annotations/RemoteWriteGenerator.java @@ -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