Annotation processing done, more work on local multiplayer input
This commit is contained in:
@@ -4,6 +4,8 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Method;
|
||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.annotations.Annotations.Local;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
@@ -39,10 +41,7 @@ public class Invoke {
|
||||
method.invoke(null, args);
|
||||
}
|
||||
InvokePacket packet = new InvokePacket();
|
||||
packet.args = args;
|
||||
packet.type = type;
|
||||
packet.method = method;
|
||||
packet.args = args;
|
||||
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
@@ -170,12 +169,5 @@ public class Invoke {
|
||||
|
||||
}
|
||||
|
||||
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Remote{}
|
||||
|
||||
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Local{}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Method;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.annotations.Annotations.Local;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.net.Invoke.Local;
|
||||
import io.anuke.mindustry.net.Invoke.Remote;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.gen.CallEvent;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NetEvents {
|
||||
|
||||
@Remote
|
||||
@Local
|
||||
public static void friendlyFireChange(boolean enabled){
|
||||
state.friendlyFire = enabled;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.gen.CallEvent;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
@@ -33,28 +34,28 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class InvokePacket implements Packet{
|
||||
public Object[] args;
|
||||
public Method method;
|
||||
public Class type;
|
||||
public byte type;
|
||||
|
||||
public ByteBuffer writeBuffer;
|
||||
public int writeLength;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
IOUtils.writeString(buffer, method.getName());
|
||||
IOUtils.writeString(buffer, type.getName());
|
||||
Invoke.writeObjects(buffer, args);
|
||||
type = buffer.get();
|
||||
|
||||
if(Net.client()){
|
||||
CallEvent.readPacket(buffer, type);
|
||||
}else{
|
||||
buffer.position(buffer.position() + writeLength);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
String methodname = IOUtils.readString(buffer);
|
||||
String typename = IOUtils.readString(buffer);
|
||||
|
||||
try {
|
||||
type = Invoke.findClass(typename);
|
||||
method = Invoke.getMethod(type, methodname);
|
||||
args = Invoke.readObjects(buffer, method.getParameterTypes());
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
buffer.put(type);
|
||||
writeBuffer.position(0);
|
||||
for(int i = 0; i < writeLength; i ++){
|
||||
buffer.put(writeBuffer.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user