mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-07-13 01:07:43 +07:00
Added support for creating entities for preexisting characters on new client instances
This commit is contained in:
34
core/gen/com/riiablo/net/packet/d2gs/Class.java
Normal file
34
core/gen/com/riiablo/net/packet/d2gs/Class.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
package com.riiablo.net.packet.d2gs;
|
||||||
|
|
||||||
|
import com.google.flatbuffers.FlatBufferBuilder;
|
||||||
|
import com.google.flatbuffers.Table;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public final class Class extends Table {
|
||||||
|
public static Class getRootAsClass(ByteBuffer _bb) { return getRootAsClass(_bb, new Class()); }
|
||||||
|
public static Class getRootAsClass(ByteBuffer _bb, Class obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
|
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; vtable_start = bb_pos - bb.getInt(bb_pos); vtable_size = bb.getShort(vtable_start); }
|
||||||
|
public Class __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||||
|
|
||||||
|
public int type() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) & 0xFF : 0; }
|
||||||
|
|
||||||
|
public static int createClass(FlatBufferBuilder builder,
|
||||||
|
int type) {
|
||||||
|
builder.startObject(1);
|
||||||
|
Class.addType(builder, type);
|
||||||
|
return Class.endClass(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startClass(FlatBufferBuilder builder) { builder.startObject(1); }
|
||||||
|
public static void addType(FlatBufferBuilder builder, int type) { builder.addByte(0, (byte)type, (byte)0); }
|
||||||
|
public static int endClass(FlatBufferBuilder builder) {
|
||||||
|
int o = builder.endObject();
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
40
core/gen/com/riiablo/net/packet/d2gs/Player.java
Normal file
40
core/gen/com/riiablo/net/packet/d2gs/Player.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
package com.riiablo.net.packet.d2gs;
|
||||||
|
|
||||||
|
import com.google.flatbuffers.FlatBufferBuilder;
|
||||||
|
import com.google.flatbuffers.Table;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public final class Player extends Table {
|
||||||
|
public static Player getRootAsPlayer(ByteBuffer _bb) { return getRootAsPlayer(_bb, new Player()); }
|
||||||
|
public static Player getRootAsPlayer(ByteBuffer _bb, Player obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
|
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; vtable_start = bb_pos - bb.getInt(bb_pos); vtable_size = bb.getShort(vtable_start); }
|
||||||
|
public Player __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||||
|
|
||||||
|
public int charClass() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) & 0xFF : 0; }
|
||||||
|
public String charName() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; }
|
||||||
|
public ByteBuffer charNameAsByteBuffer() { return __vector_as_bytebuffer(6, 1); }
|
||||||
|
public ByteBuffer charNameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 6, 1); }
|
||||||
|
|
||||||
|
public static int createPlayer(FlatBufferBuilder builder,
|
||||||
|
int charClass,
|
||||||
|
int charNameOffset) {
|
||||||
|
builder.startObject(2);
|
||||||
|
Player.addCharName(builder, charNameOffset);
|
||||||
|
Player.addCharClass(builder, charClass);
|
||||||
|
return Player.endPlayer(builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startPlayer(FlatBufferBuilder builder) { builder.startObject(2); }
|
||||||
|
public static void addCharClass(FlatBufferBuilder builder, int charClass) { builder.addByte(0, (byte)charClass, (byte)0); }
|
||||||
|
public static void addCharName(FlatBufferBuilder builder, int charNameOffset) { builder.addOffset(1, charNameOffset, 0); }
|
||||||
|
public static int endPlayer(FlatBufferBuilder builder) {
|
||||||
|
int o = builder.endObject();
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,14 +5,16 @@ package com.riiablo.net.packet.d2gs;
|
|||||||
public final class SyncData {
|
public final class SyncData {
|
||||||
private SyncData() { }
|
private SyncData() { }
|
||||||
public static final byte NONE = 0;
|
public static final byte NONE = 0;
|
||||||
public static final byte CofComponents = 1;
|
public static final byte Class = 1;
|
||||||
public static final byte CofTransforms = 2;
|
public static final byte CofComponents = 2;
|
||||||
public static final byte CofAlphas = 3;
|
public static final byte CofTransforms = 3;
|
||||||
public static final byte Position = 4;
|
public static final byte CofAlphas = 4;
|
||||||
public static final byte Velocity = 5;
|
public static final byte Position = 5;
|
||||||
public static final byte Angle = 6;
|
public static final byte Velocity = 6;
|
||||||
|
public static final byte Angle = 7;
|
||||||
|
public static final byte Player = 8;
|
||||||
|
|
||||||
public static final String[] names = { "NONE", "CofComponents", "CofTransforms", "CofAlphas", "Position", "Velocity", "Angle", };
|
public static final String[] names = { "NONE", "Class", "CofComponents", "CofTransforms", "CofAlphas", "Position", "Velocity", "Angle", "Player", };
|
||||||
|
|
||||||
public static String name(int e) { return names[e]; }
|
public static String name(int e) { return names[e]; }
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,18 @@ public class Class extends Component {
|
|||||||
public int getComponent(String comp) {
|
public int getComponent(String comp) {
|
||||||
return COMPS.get(comp.toLowerCase(), -1);
|
return COMPS.get(comp.toLowerCase(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Type valueOf(int i) {
|
||||||
|
switch (i) {
|
||||||
|
case 0: return OBJ;
|
||||||
|
case 1: return MON;
|
||||||
|
case 2: return PLR;
|
||||||
|
case 3: return ITM;
|
||||||
|
case 4: return WRP;
|
||||||
|
case 5: return MIS;
|
||||||
|
default: throw new AssertionError("Unknown type id: " + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type type;
|
public Type type;
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
namespace com.riiablo.net.packet.d2gs;
|
namespace com.riiablo.net.packet.d2gs;
|
||||||
|
|
||||||
union SyncData {
|
union SyncData {
|
||||||
|
Class,
|
||||||
CofComponents,
|
CofComponents,
|
||||||
CofTransforms,
|
CofTransforms,
|
||||||
CofAlphas,
|
CofAlphas,
|
||||||
Position,
|
Position,
|
||||||
Velocity,
|
Velocity,
|
||||||
Angle,
|
Angle,
|
||||||
|
Player,
|
||||||
}
|
}
|
||||||
|
|
||||||
table Sync {
|
table Sync {
|
||||||
@ -14,6 +16,10 @@ table Sync {
|
|||||||
data:[SyncData];
|
data:[SyncData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table Class {
|
||||||
|
type:uint8;
|
||||||
|
}
|
||||||
|
|
||||||
table CofComponents {
|
table CofComponents {
|
||||||
component:[uint8];
|
component:[uint8];
|
||||||
}
|
}
|
||||||
@ -40,3 +46,8 @@ table Angle {
|
|||||||
x:float32;
|
x:float32;
|
||||||
y:float32;
|
y:float32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table Player {
|
||||||
|
charClass:uint8;
|
||||||
|
charName:string;
|
||||||
|
}
|
@ -170,10 +170,32 @@ public class NetworkedGameScreen extends GameScreen {
|
|||||||
engine.delete(entityId);
|
engine.delete(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private com.riiablo.net.packet.d2gs.Player findPlayer(Sync s) {
|
||||||
|
for (int i = 0, len = s.dataTypeLength(); i < len; i++) {
|
||||||
|
if (s.dataType(i) == SyncData.Player) {
|
||||||
|
return (com.riiablo.net.packet.d2gs.Player) s.data(new com.riiablo.net.packet.d2gs.Player(), i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private void Synchronize(D2GS packet) {
|
private void Synchronize(D2GS packet) {
|
||||||
Sync s = (Sync) packet.data(new Sync());
|
Sync s = (Sync) packet.data(new Sync());
|
||||||
int entityId = sync.get(s.entityId());
|
int entityId = sync.get(s.entityId());
|
||||||
if (entityId == Engine.INVALID_ENTITY) return;
|
if (entityId == Engine.INVALID_ENTITY) {
|
||||||
|
com.riiablo.net.packet.d2gs.Player player = findPlayer(s);
|
||||||
|
CharData charData = new CharData().createD2S(player.charName(), CharacterClass.get(player.charClass()));
|
||||||
|
|
||||||
|
// TODO: assert entity id is player
|
||||||
|
// TODO: add support for other entity types
|
||||||
|
Vector2 origin = map.find(Map.ID.TOWN_ENTRY_1);
|
||||||
|
if (origin == null) origin = map.find(Map.ID.TOWN_ENTRY_2);
|
||||||
|
if (origin == null) origin = map.find(Map.ID.TP_LOCATION);
|
||||||
|
Map.Zone zone = map.getZone(origin);
|
||||||
|
entityId = factory.createPlayer(map, zone, charData, origin);
|
||||||
|
sync.put(s.entityId(), entityId);
|
||||||
|
}
|
||||||
|
|
||||||
int flags1 = Dirty.NONE;
|
int flags1 = Dirty.NONE;
|
||||||
int flags2 = Dirty.NONE;
|
int flags2 = Dirty.NONE;
|
||||||
|
@ -378,6 +378,10 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
BroadcastConnect(packet.id, connection, charData, entityId);
|
BroadcastConnect(packet.id, connection, charData, entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Synchronize(int id, int entityId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void BroadcastConnect(int id, Connection connection, CharData charData, int entityId) {
|
private void BroadcastConnect(int id, Connection connection, CharData charData, int entityId) {
|
||||||
FlatBufferBuilder builder = new FlatBufferBuilder();
|
FlatBufferBuilder builder = new FlatBufferBuilder();
|
||||||
int charNameOffset = builder.createString(charData.getD2S().header.name);
|
int charNameOffset = builder.createString(charData.getD2S().header.name);
|
||||||
@ -437,10 +441,6 @@ public class D2GS extends ApplicationAdapter {
|
|||||||
sync.sync(entityId, (Sync) packet.data.data(new Sync()));
|
sync.sync(entityId, (Sync) packet.data.data(new Sync()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Synchronize(int id, int entityId) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static String generateClientName() {
|
static String generateClientName() {
|
||||||
return String.format("Client-%08X", MathUtils.random(1, Integer.MAX_VALUE - 1));
|
return String.format("Client-%08X", MathUtils.random(1, Integer.MAX_VALUE - 1));
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,15 @@ import com.artemis.systems.IteratingSystem;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.IntIntMap;
|
import com.badlogic.gdx.utils.IntIntMap;
|
||||||
|
import com.riiablo.CharData;
|
||||||
import com.riiablo.engine.server.CofManager;
|
import com.riiablo.engine.server.CofManager;
|
||||||
import com.riiablo.engine.server.component.Angle;
|
import com.riiablo.engine.server.component.Angle;
|
||||||
|
import com.riiablo.engine.server.component.Class;
|
||||||
import com.riiablo.engine.server.component.CofAlphas;
|
import com.riiablo.engine.server.component.CofAlphas;
|
||||||
import com.riiablo.engine.server.component.CofComponents;
|
import com.riiablo.engine.server.component.CofComponents;
|
||||||
import com.riiablo.engine.server.component.CofTransforms;
|
import com.riiablo.engine.server.component.CofTransforms;
|
||||||
import com.riiablo.engine.server.component.Networked;
|
import com.riiablo.engine.server.component.Networked;
|
||||||
|
import com.riiablo.engine.server.component.Player;
|
||||||
import com.riiablo.engine.server.component.Position;
|
import com.riiablo.engine.server.component.Position;
|
||||||
import com.riiablo.engine.server.component.Velocity;
|
import com.riiablo.engine.server.component.Velocity;
|
||||||
import com.riiablo.net.packet.d2gs.D2GSData;
|
import com.riiablo.net.packet.d2gs.D2GSData;
|
||||||
@ -36,6 +39,8 @@ public class NetworkSynchronizer extends IteratingSystem {
|
|||||||
protected ComponentMapper<Position> mPosition;
|
protected ComponentMapper<Position> mPosition;
|
||||||
protected ComponentMapper<Velocity> mVelocity;
|
protected ComponentMapper<Velocity> mVelocity;
|
||||||
protected ComponentMapper<Angle> mAngle;
|
protected ComponentMapper<Angle> mAngle;
|
||||||
|
protected ComponentMapper<Class> mClass;
|
||||||
|
protected ComponentMapper<Player> mPlayer;
|
||||||
|
|
||||||
protected CofManager cofs;
|
protected CofManager cofs;
|
||||||
|
|
||||||
@ -76,22 +81,29 @@ public class NetworkSynchronizer extends IteratingSystem {
|
|||||||
Vector2 velocity = mVelocity.get(entityId).velocity;
|
Vector2 velocity = mVelocity.get(entityId).velocity;
|
||||||
Vector2 angle = mAngle.get(entityId).target;
|
Vector2 angle = mAngle.get(entityId).target;
|
||||||
|
|
||||||
byte[] dataTypes = new byte[6];
|
CharData charData = mPlayer.get(entityId).data;
|
||||||
dataTypes[0] = SyncData.CofComponents;
|
int charNameOffset = builder.createString(charData.getD2S().header.name);
|
||||||
dataTypes[1] = SyncData.CofTransforms;
|
|
||||||
dataTypes[2] = SyncData.CofAlphas;
|
byte[] dataTypes = new byte[8];
|
||||||
dataTypes[3] = SyncData.Position;
|
dataTypes[0] = SyncData.Class;
|
||||||
dataTypes[4] = SyncData.Velocity;
|
dataTypes[1] = SyncData.CofComponents;
|
||||||
dataTypes[5] = SyncData.Angle;
|
dataTypes[2] = SyncData.CofTransforms;
|
||||||
|
dataTypes[3] = SyncData.CofAlphas;
|
||||||
|
dataTypes[4] = SyncData.Position;
|
||||||
|
dataTypes[5] = SyncData.Velocity;
|
||||||
|
dataTypes[6] = SyncData.Angle;
|
||||||
|
dataTypes[7] = SyncData.Player;
|
||||||
int dataTypesOffset = Sync.createDataTypeVector(builder, dataTypes);
|
int dataTypesOffset = Sync.createDataTypeVector(builder, dataTypes);
|
||||||
|
|
||||||
int[] data = new int[6];
|
int[] data = new int[8];
|
||||||
data[0] = cofComponents;
|
data[0] = com.riiablo.net.packet.d2gs.Class.createClass(builder, mClass.get(entityId).type.ordinal());
|
||||||
data[1] = cofTransforms;
|
data[1] = cofComponents;
|
||||||
data[2] = cofAlphas;
|
data[2] = cofTransforms;
|
||||||
data[3] = com.riiablo.net.packet.d2gs.Position.createPosition(builder, position.x, position.y);
|
data[3] = cofAlphas;
|
||||||
data[4] = com.riiablo.net.packet.d2gs.Velocity.createVelocity(builder, velocity.x, velocity.y);
|
data[4] = com.riiablo.net.packet.d2gs.Position.createPosition(builder, position.x, position.y);
|
||||||
data[5] = com.riiablo.net.packet.d2gs.Angle.createAngle(builder, angle.x, angle.y);
|
data[5] = com.riiablo.net.packet.d2gs.Velocity.createVelocity(builder, velocity.x, velocity.y);
|
||||||
|
data[6] = com.riiablo.net.packet.d2gs.Angle.createAngle(builder, angle.x, angle.y);
|
||||||
|
data[7] = com.riiablo.net.packet.d2gs.Player.createPlayer(builder, charData.getD2S().header.charClass, charNameOffset);
|
||||||
int dataOffset = Sync.createDataVector(builder, data);
|
int dataOffset = Sync.createDataVector(builder, data);
|
||||||
|
|
||||||
Sync.startSync(builder);
|
Sync.startSync(builder);
|
||||||
|
Reference in New Issue
Block a user