From a49f73f6c403d2f7af2e399facb48268c1aab56c Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Fri, 27 Dec 2019 00:47:26 -0800 Subject: [PATCH] Added networking for object entities Added networking for object entities Casted cof component in flatbuffers to ensure they are sign extended properly (0xFF was not becoming 0xFFFFFFFF which is a special value) Added additional check in CofManager#setComponent to ignore change if redundant Increased output packet queue to 1024 -- will eventually group all sync packets into a single packet --- .../riiablo/engine/client/ClientNetworkReceiver.java | 10 ++++------ core/src/com/riiablo/engine/server/CofManager.java | 1 + .../riiablo/engine/server/SerializationManager.java | 2 +- .../com/riiablo/engine/server/ServerEntityFactory.java | 1 + server/d2gs/src/com/riiablo/server/d2gs/D2GS.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java b/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java index 3e829b48..e87539e3 100644 --- a/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java +++ b/core/src/com/riiablo/engine/client/ClientNetworkReceiver.java @@ -219,9 +219,8 @@ public class ClientNetworkReceiver extends IntervalSystem { case OBJ: { DS1ObjectWrapperP ds1ObjectWrapper = findTable(sync, SyncData.DS1ObjectWrapperP, new DS1ObjectWrapperP()); if (ds1ObjectWrapper != null) { -// String objectType = Riiablo.files.obj.getType1(ds1ObjectWrapper.act(), ds1ObjectWrapper.id()); -// int entityId = factory.createObject(map, null, null, object, 0, 0); -// return entityId; + PositionP position = findTable(sync, SyncData.PositionP, new PositionP()); + return factory.createObject(ds1ObjectWrapper.act(), ds1ObjectWrapper.type(), ds1ObjectWrapper.id(), position.x(), position.y()); } return Engine.INVALID_ENTITY; @@ -232,8 +231,7 @@ public class ClientNetworkReceiver extends IntervalSystem { PositionP position = findTable(sync, SyncData.PositionP, new PositionP()); String objectType = Riiablo.files.MonPreset.getPlace(ds1ObjectWrapper.act(), ds1ObjectWrapper.id()); MonStats.Entry monstats = Riiablo.files.monstats.get(objectType); - int entityId = factory.createMonster(monstats, position.x(), position.y()); - return entityId; + return factory.createMonster(monstats, position.x(), position.y()); } return Engine.INVALID_ENTITY; @@ -270,7 +268,7 @@ public class ClientNetworkReceiver extends IntervalSystem { case SyncData.CofComponentsP: { CofComponentsP data = (CofComponentsP) sync.data(new CofComponentsP(), i); for (int j = 0, s0 = data.componentLength(); j < s0; j++) { - cofs.setComponent(entityId, j, data.component(j)); + cofs.setComponent(entityId, j, (byte) data.component(j)); } break; } diff --git a/core/src/com/riiablo/engine/server/CofManager.java b/core/src/com/riiablo/engine/server/CofManager.java index 04dc643c..d6ac84b0 100644 --- a/core/src/com/riiablo/engine/server/CofManager.java +++ b/core/src/com/riiablo/engine/server/CofManager.java @@ -61,6 +61,7 @@ public class CofManager extends BaseEntitySystem { public int setComponent(int id, int c, int code) { int[] component = mCofComponents.get(id).component; if (component[c] == code) return Dirty.NONE; + if (code == CofComponents.COMPONENT_NULL && component[c] == CofComponents.COMPONENT_LIT) return Dirty.NONE; component[c] = code; return mCofDirtyComponents.create(id).flags |= (1 << c); } diff --git a/core/src/com/riiablo/engine/server/SerializationManager.java b/core/src/com/riiablo/engine/server/SerializationManager.java index 186d3b1c..863f9427 100644 --- a/core/src/com/riiablo/engine/server/SerializationManager.java +++ b/core/src/com/riiablo/engine/server/SerializationManager.java @@ -151,7 +151,7 @@ public class SerializationManager extends PassiveSystem { CofComponentsSerializer serializer = (CofComponentsSerializer) serializers.get(clazz); CofComponentsP table = serializer.getTable(sync, i); for (int j = 0, s = table.componentLength(); j < s; j++) { - cofs.setComponent(entityId, j, table.component(j)); + cofs.setComponent(entityId, j, (byte) table.component(j)); } // if (DEBUG_DESERIALIZE) Gdx.app.log(TAG, " " + DebugUtils.toByteArray(ArrayUtils.toByteArray(mCofComponents.get(entityId).component))); break; diff --git a/core/src/com/riiablo/engine/server/ServerEntityFactory.java b/core/src/com/riiablo/engine/server/ServerEntityFactory.java index 990d12e4..21112574 100644 --- a/core/src/com/riiablo/engine/server/ServerEntityFactory.java +++ b/core/src/com/riiablo/engine/server/ServerEntityFactory.java @@ -133,6 +133,7 @@ public class ServerEntityFactory extends EntityFactory { } mSize.create(id); // single size doesn't make any sense in this case because this is a rect + mNetworked.create(id); return id; } diff --git a/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java b/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java index 25694f32..eeedb472 100644 --- a/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java +++ b/server/d2gs/src/com/riiablo/server/d2gs/D2GS.java @@ -150,7 +150,7 @@ public class D2GS extends ApplicationAdapter { final BlockingQueue packets = new ArrayBlockingQueue<>(32); final Collection cache = new ArrayList<>(); - final BlockingQueue outPackets = new ArrayBlockingQueue<>(32); + final BlockingQueue outPackets = new ArrayBlockingQueue<>(1024); final IntIntMap player = new IntIntMap(); FileHandle home;