mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-03 13:30:25 +07:00
Updated annotations module
This commit is contained in:
parent
60deb9205b
commit
5fdf7e3a12
@ -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.*/
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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)");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user