Moved D2GS.Packet to separate Packet class

This commit is contained in:
Collin Smith
2019-12-25 15:44:06 -08:00
parent f285d2666d
commit df14e4c18f
3 changed files with 24 additions and 18 deletions

View File

@ -1,6 +1,5 @@
package com.riiablo.server.d2gs;
import com.google.flatbuffers.ByteBufferUtil;
import com.google.flatbuffers.FlatBufferBuilder;
import com.artemis.ComponentMapper;
@ -531,18 +530,4 @@ public class D2GS extends ApplicationAdapter {
Disconnect(id);
}
}
public static class Packet {
public int id;
public ByteBuffer buffer;
public com.riiablo.net.packet.d2gs.D2GS data;
public static Packet obtain(int id, ByteBuffer buffer) {
Packet packet = new Packet();
packet.id = id;
packet.buffer = buffer;
packet.data = com.riiablo.net.packet.d2gs.D2GS.getRootAsD2GS(ByteBufferUtil.removeSizePrefix(buffer));
return packet;
}
}
}

View File

@ -22,7 +22,7 @@ public class NetworkSynchronizer extends IteratingSystem {
protected SerializationManager serializer;
@Wire(name = "outPackets")
protected BlockingQueue<com.riiablo.server.d2gs.D2GS.Packet> outPackets;
protected BlockingQueue<Packet> outPackets;
@Wire(name = "player")
protected IntIntMap players;
@ -36,8 +36,8 @@ public class NetworkSynchronizer extends IteratingSystem {
protected void process(int entityId) {
ByteBuffer sync = sync(entityId);
int id = players.findKey(entityId, -1);
boolean success = outPackets.offer(com.riiablo.server.d2gs.D2GS.Packet
.obtain(id != -1 ? ~(1 << id) : 0xFFFFFFFF, sync));
Packet packet = Packet.obtain(id != -1 ? ~(1 << id) : 0xFFFFFFFF, sync);
boolean success = outPackets.offer(packet);
assert success;
}

View File

@ -0,0 +1,21 @@
package com.riiablo.server.d2gs;
import com.google.flatbuffers.ByteBufferUtil;
import com.riiablo.net.packet.d2gs.D2GS;
import java.nio.ByteBuffer;
public class Packet {
public int id;
public ByteBuffer buffer;
public D2GS data;
public static Packet obtain(int id, ByteBuffer buffer) {
Packet packet = new Packet();
packet.id = id;
packet.buffer = buffer;
packet.data = D2GS.getRootAsD2GS(ByteBufferUtil.removeSizePrefix(buffer));
return packet;
}
}