diff --git a/core/gen/com/riiablo/net/packet/d2gs/SyncData.java b/core/gen/com/riiablo/net/packet/d2gs/SyncData.java index 1261c449..59b85dd4 100644 --- a/core/gen/com/riiablo/net/packet/d2gs/SyncData.java +++ b/core/gen/com/riiablo/net/packet/d2gs/SyncData.java @@ -8,8 +8,11 @@ public final class SyncData { public static final byte CofComponents = 1; public static final byte CofTransforms = 2; public static final byte CofAlphas = 3; + public static final byte Position = 4; + public static final byte Velocity = 5; + public static final byte Angle = 6; - public static final String[] names = { "NONE", "CofComponents", "CofTransforms", "CofAlphas", }; + public static final String[] names = { "NONE", "CofComponents", "CofTransforms", "CofAlphas", "Position", "Velocity", "Angle", }; public static String name(int e) { return names[e]; } } diff --git a/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java b/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java index e09d6e37..30ec630e 100644 --- a/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java +++ b/core/src/com/riiablo/engine/client/ClientNetworkSyncronizer.java @@ -8,12 +8,16 @@ import com.artemis.annotations.All; import com.artemis.annotations.Wire; import com.artemis.systems.IntervalSystem; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.net.Socket; import com.riiablo.Riiablo; +import com.riiablo.engine.server.component.Angle; import com.riiablo.engine.server.component.CofAlphas; import com.riiablo.engine.server.component.CofComponents; import com.riiablo.engine.server.component.CofTransforms; import com.riiablo.engine.server.component.Networked; +import com.riiablo.engine.server.component.Position; +import com.riiablo.engine.server.component.Velocity; import com.riiablo.net.packet.d2gs.Connection; import com.riiablo.net.packet.d2gs.D2GS; import com.riiablo.net.packet.d2gs.D2GSData; @@ -34,6 +38,9 @@ public class ClientNetworkSyncronizer extends IntervalSystem { protected ComponentMapper mCofComponents; protected ComponentMapper mCofTransforms; protected ComponentMapper mCofAlphas; + protected ComponentMapper mPosition; + protected ComponentMapper mVelocity; + protected ComponentMapper mAngle; protected NetworkIdManager idManager; @@ -117,21 +124,30 @@ public class ClientNetworkSyncronizer extends IntervalSystem { byte[] transform = mCofTransforms.get(entityId).transform; float[] alpha = mCofAlphas.get(entityId).alpha; + Vector2 position = mPosition.get(entityId).position; + Vector2 velocity = mVelocity.get(entityId).velocity; + Vector2 angle = mAngle.get(entityId).target; int cofComponents = com.riiablo.net.packet.d2gs.CofComponents.createComponentVector(builder, component); int cofTransforms = com.riiablo.net.packet.d2gs.CofTransforms.createTransformVector(builder, transform); int cofAlphas = com.riiablo.net.packet.d2gs.CofAlphas.createAlphaVector(builder, alpha); - byte[] dataTypes = new byte[3]; + byte[] dataTypes = new byte[6]; dataTypes[0] = SyncData.CofComponents; dataTypes[1] = SyncData.CofTransforms; dataTypes[2] = SyncData.CofAlphas; + dataTypes[3] = SyncData.Position; + dataTypes[4] = SyncData.Velocity; + dataTypes[5] = SyncData.Angle; int dataTypesOffset = Sync.createDataTypeVector(builder, dataTypes); - int[] data = new int[3]; + int[] data = new int[6]; data[0] = com.riiablo.net.packet.d2gs.CofComponents.createCofComponents(builder, cofComponents); data[1] = com.riiablo.net.packet.d2gs.CofTransforms.createCofTransforms(builder, cofTransforms); data[2] = com.riiablo.net.packet.d2gs.CofAlphas.createCofAlphas(builder, cofAlphas); + data[3] = com.riiablo.net.packet.d2gs.Position.createPosition(builder, position.x, position.y); + data[4] = com.riiablo.net.packet.d2gs.Velocity.createVelocity(builder, velocity.x, velocity.y); + data[5] = com.riiablo.net.packet.d2gs.Angle.createAngle(builder, angle.x, angle.y); int dataOffset = Sync.createDataVector(builder, data); Sync.startSync(builder); diff --git a/core/src/com/riiablo/net/d2gs/Sync.fbs b/core/src/com/riiablo/net/d2gs/Sync.fbs index b7490995..cb30e9e1 100644 --- a/core/src/com/riiablo/net/d2gs/Sync.fbs +++ b/core/src/com/riiablo/net/d2gs/Sync.fbs @@ -4,6 +4,9 @@ union SyncData { CofComponents, CofTransforms, CofAlphas, + Position, + Velocity, + Angle, } table Sync { @@ -21,4 +24,19 @@ table CofTransforms { table CofAlphas { alpha:[float32]; +} + +table Position { + x:float32; + y:float32; +} + +table Velocity { + x:float32; + y:float32; +} + +table Angle { + x:float32; + y:float32; } \ No newline at end of file diff --git a/core/src/com/riiablo/screen/NetworkedGameScreen.java b/core/src/com/riiablo/screen/NetworkedGameScreen.java index eef5c54c..805fd1db 100644 --- a/core/src/com/riiablo/screen/NetworkedGameScreen.java +++ b/core/src/com/riiablo/screen/NetworkedGameScreen.java @@ -6,6 +6,7 @@ import com.artemis.WorldConfigurationBuilder; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.net.Socket; +import com.badlogic.gdx.physics.box2d.Body; import com.riiablo.CharData; import com.riiablo.CharacterClass; import com.riiablo.Riiablo; @@ -15,11 +16,15 @@ import com.riiablo.engine.client.ClientEntityFactory; import com.riiablo.engine.client.ClientNetworkSyncronizer; import com.riiablo.engine.client.NetworkIdManager; import com.riiablo.engine.server.CofManager; +import com.riiablo.engine.server.component.Angle; +import com.riiablo.engine.server.component.Box2DBody; import com.riiablo.engine.server.component.CofAlphas; import com.riiablo.engine.server.component.CofComponents; import com.riiablo.engine.server.component.CofTransforms; 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.Velocity; import com.riiablo.map.Map; import com.riiablo.net.packet.d2gs.Connection; import com.riiablo.net.packet.d2gs.D2GS; @@ -196,6 +201,32 @@ public class NetworkedGameScreen extends GameScreen { } break; } + case SyncData.Position: { + Vector2 position = engine.getMapper(Position.class).get(entityId).position; + com.riiablo.net.packet.d2gs.Position data = (com.riiablo.net.packet.d2gs.Position) s.data(new com.riiablo.net.packet.d2gs.Position(), i); + position.x = data.x(); + position.y = data.y(); + Body body = engine.getMapper(Box2DBody.class).get(entityId).body; + body.setTransform(position, body.getAngle()); + Gdx.app.log(TAG, " " + position); + break; + } + case SyncData.Velocity: { + Vector2 velocity = engine.getMapper(Velocity.class).get(entityId).velocity; + com.riiablo.net.packet.d2gs.Velocity data = (com.riiablo.net.packet.d2gs.Velocity) s.data(new com.riiablo.net.packet.d2gs.Velocity(), i); + velocity.x = data.x(); + velocity.y = data.y(); + Gdx.app.log(TAG, " " + velocity); + break; + } + case SyncData.Angle: { + Vector2 angle = engine.getMapper(Angle.class).get(entityId).target; + com.riiablo.net.packet.d2gs.Angle data = (com.riiablo.net.packet.d2gs.Angle) s.data(new com.riiablo.net.packet.d2gs.Angle(), i); + angle.x = data.x(); + angle.y = data.y(); + Gdx.app.log(TAG, " " + angle); + break; + } default: Gdx.app.error(TAG, "Unknown packet type: " + SyncData.name(s.dataType(i))); } diff --git a/server/d2gs/src/com/riiablo/server/d2gs/NetworkSynchronizer.java b/server/d2gs/src/com/riiablo/server/d2gs/NetworkSynchronizer.java index 8622b023..fda24ae5 100644 --- a/server/d2gs/src/com/riiablo/server/d2gs/NetworkSynchronizer.java +++ b/server/d2gs/src/com/riiablo/server/d2gs/NetworkSynchronizer.java @@ -7,12 +7,16 @@ import com.artemis.annotations.All; import com.artemis.annotations.Wire; import com.artemis.systems.IteratingSystem; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.IntIntMap; import com.riiablo.engine.server.CofManager; +import com.riiablo.engine.server.component.Angle; import com.riiablo.engine.server.component.CofAlphas; import com.riiablo.engine.server.component.CofComponents; import com.riiablo.engine.server.component.CofTransforms; import com.riiablo.engine.server.component.Networked; +import com.riiablo.engine.server.component.Position; +import com.riiablo.engine.server.component.Velocity; import com.riiablo.net.packet.d2gs.D2GSData; import com.riiablo.net.packet.d2gs.Sync; import com.riiablo.net.packet.d2gs.SyncData; @@ -29,6 +33,9 @@ public class NetworkSynchronizer extends IteratingSystem { protected ComponentMapper mCofComponents; protected ComponentMapper mCofTransforms; protected ComponentMapper mCofAlphas; + protected ComponentMapper mPosition; + protected ComponentMapper mVelocity; + protected ComponentMapper mAngle; protected CofManager cofs; @@ -53,7 +60,6 @@ public class NetworkSynchronizer extends IteratingSystem { int[] component2 = mCofComponents.get(entityId).component; byte[] component = new byte[16]; for (int i = 0; i < 16; i++) component[i] = (byte) component2[i]; - Gdx.app.log(TAG, " " + DebugUtils.toByteArray(component)); int componentOffset = com.riiablo.net.packet.d2gs.CofComponents.createComponentVector(builder, component); int cofComponents = com.riiablo.net.packet.d2gs.CofComponents.createCofComponents(builder, componentOffset); @@ -66,16 +72,26 @@ public class NetworkSynchronizer extends IteratingSystem { int alphaOffset = com.riiablo.net.packet.d2gs.CofAlphas.createAlphaVector(builder, alpha); int cofAlphas = com.riiablo.net.packet.d2gs.CofAlphas.createCofAlphas(builder, alphaOffset); - byte[] dataTypes = new byte[3]; + Vector2 position = mPosition.get(entityId).position; + Vector2 velocity = mVelocity.get(entityId).velocity; + Vector2 angle = mAngle.get(entityId).target; + + byte[] dataTypes = new byte[6]; dataTypes[0] = SyncData.CofComponents; dataTypes[1] = SyncData.CofTransforms; dataTypes[2] = SyncData.CofAlphas; + dataTypes[3] = SyncData.Position; + dataTypes[4] = SyncData.Velocity; + dataTypes[5] = SyncData.Angle; int dataTypesOffset = Sync.createDataTypeVector(builder, dataTypes); - int[] data = new int[3]; + int[] data = new int[6]; data[0] = cofComponents; data[1] = cofTransforms; data[2] = cofAlphas; + data[3] = com.riiablo.net.packet.d2gs.Position.createPosition(builder, position.x, position.y); + data[4] = com.riiablo.net.packet.d2gs.Velocity.createVelocity(builder, velocity.x, velocity.y); + data[5] = com.riiablo.net.packet.d2gs.Angle.createAngle(builder, angle.x, angle.y); int dataOffset = Sync.createDataVector(builder, data); Sync.startSync(builder); @@ -119,6 +135,30 @@ public class NetworkSynchronizer extends IteratingSystem { Gdx.app.log(TAG, " " + Arrays.toString(alpha)); break; } + case SyncData.Position: { + Vector2 position = mPosition.get(entityId).position; + com.riiablo.net.packet.d2gs.Position data = (com.riiablo.net.packet.d2gs.Position) sync.data(new com.riiablo.net.packet.d2gs.Position(), i); + position.x = data.x(); + position.y = data.y(); + Gdx.app.log(TAG, " " + position); + break; + } + case SyncData.Velocity: { + Vector2 velocity = mVelocity.get(entityId).velocity; + com.riiablo.net.packet.d2gs.Velocity data = (com.riiablo.net.packet.d2gs.Velocity) sync.data(new com.riiablo.net.packet.d2gs.Velocity(), i); + velocity.x = data.x(); + velocity.y = data.y(); + Gdx.app.log(TAG, " " + velocity); + break; + } + case SyncData.Angle: { + Vector2 angle = mAngle.get(entityId).target; + com.riiablo.net.packet.d2gs.Angle data = (com.riiablo.net.packet.d2gs.Angle) sync.data(new com.riiablo.net.packet.d2gs.Angle(), i); + angle.x = data.x(); + angle.y = data.y(); + Gdx.app.log(TAG, " " + angle); + break; + } default: Gdx.app.error(TAG, "Unknown packet type: " + SyncData.name(sync.dataType(i))); }