Added networking for dynamic objects

Added networking for dynamic objects
Fixed disconnecting players not being removed from player ids table
NetworkSynchronizer conditionally processes based on if any players are connected
Disabled AIStepper when game is connected to a socket
This commit is contained in:
Collin Smith 2019-12-22 17:38:16 -08:00
parent 5d51a1c160
commit ea040c318e
4 changed files with 11 additions and 4 deletions

View File

@ -113,6 +113,7 @@ public class ServerEntityFactory extends EntityFactory {
int id = createMonster(map, zone, monstats, x, y);
mDS1ObjectWrapper.create(id).set(preset.getDS1(), object);
if (object.path != null) mPathWrapper.create(id).path = object.path;
mNetworked.create(id);
return id;
}

View File

@ -531,8 +531,10 @@ public class GameScreen extends ScreenAdapter implements GameLoadingScreen.Loada
if (!DEBUG_TOUCHPAD && Gdx.app.getType() == Application.ApplicationType.Desktop) {
builder.with(new CursorMovementSystem());
}
if (socket == null) {
builder.with(new AIStepper());
}
builder
.with(new AIStepper())
.with(new Pathfinder())
.with(new SoundEmitterHandler())

View File

@ -459,7 +459,7 @@ public class D2GS extends ApplicationAdapter {
outPackets.offer(broadcast);
world.delete(entityId);
player.put(id, Engine.INVALID_ENTITY);
player.remove(id, Engine.INVALID_ENTITY);
synchronized (clients) {
clients[id] = null;
numClients--;

View File

@ -26,12 +26,16 @@ public class NetworkSynchronizer extends IteratingSystem {
@Wire(name = "player")
protected IntIntMap players;
@Override
protected boolean checkProcessing() {
return players.size > 0;
}
@Override
protected void process(int entityId) {
D2GS sync = sync(entityId);
int id = players.findKey(entityId, -1);
assert id != -1;
boolean success = outPackets.offer(com.riiablo.server.d2gs.D2GS.Packet.obtain(~(1 << id), sync));
boolean success = outPackets.offer(com.riiablo.server.d2gs.D2GS.Packet.obtain(id != -1 ? ~(1 << id) : 0xFFFFFFFF, sync));
assert success;
}