private void sendEntities(NetData.NetMessage.Builder message) { TIntIterator dirtyIterator = netDirty.iterator(); while (dirtyIterator.hasNext()) { int netId = dirtyIterator.next(); EntityRef entity = networkSystem.getEntity(netId); if (isOwned(entity)) { Set<Class<? extends Component>> emptyComponentClassSet = Collections.emptySet(); EntityData.PackedEntity entityData = entitySerializer.serialize( entity, emptyComponentClassSet, changedComponents.get(netId), emptyComponentClassSet, new ClientComponentFieldCheck()); if (entityData != null) { message.addUpdateEntity( NetData.UpdateEntityMessage.newBuilder().setEntity(entityData).setNetId(netId)); } } } netDirty.clear(); }
@Override public void update(boolean netTick) { processReceivedChunks(); if (entityManager != null) { if (netTick) { NetData.NetMessage.Builder message = NetData.NetMessage.newBuilder(); message.setTime(time.getGameTimeInMs()); sendEntities(message); sendEvents(message); send(message.build()); } else if (!queuedOutgoingEvents.isEmpty()) { NetData.NetMessage.Builder message = NetData.NetMessage.newBuilder(); message.setTime(time.getGameTimeInMs()); sendEvents(message); send(message.build()); } processMessages(); } }
private void sendEvents(NetData.NetMessage.Builder message) { for (NetData.EventMessage event : queuedOutgoingEvents) { message.addEvent(event); } queuedOutgoingEvents.clear(); }