Search in sources :

Example 1 with ServerComponentFieldCheck

use of org.terasology.engine.network.serialization.ServerComponentFieldCheck in project Terasology by MovingBlocks.

the class NetClient method sendDirtyEntities.

private void sendDirtyEntities(NetData.NetMessage.Builder message) {
    TIntIterator dirtyIterator = netDirty.iterator();
    while (dirtyIterator.hasNext()) {
        int netId = dirtyIterator.next();
        EntityRef entity = networkSystem.getEntity(netId);
        if (!entity.exists()) {
            logger.error("Sending non-existent entity update for netId {}", netId);
        }
        boolean isOwner = networkSystem.getOwner(entity) == this;
        EntityData.PackedEntity entityData = entitySerializer.serialize(entity, addedComponents.get(netId), dirtyComponents.get(netId), removedComponents.get(netId), new ServerComponentFieldCheck(isOwner, false));
        if (entityData != null) {
            message.addUpdateEntity(NetData.UpdateEntityMessage.newBuilder().setEntity(entityData).setNetId(netId));
        }
    }
    netDirty.clear();
    addedComponents.clear();
    removedComponents.clear();
    dirtyComponents.clear();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) EntityData(org.terasology.protobuf.EntityData) ServerComponentFieldCheck(org.terasology.engine.network.serialization.ServerComponentFieldCheck) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 2 with ServerComponentFieldCheck

use of org.terasology.engine.network.serialization.ServerComponentFieldCheck in project Terasology by MovingBlocks.

the class NetClient method sendInitialEntities.

private void sendInitialEntities(NetData.NetMessage.Builder message) {
    int[] initial = netInitial.toArray();
    netInitial.clear();
    Arrays.sort(initial);
    for (int netId : initial) {
        netRelevant.add(netId);
        EntityRef entity = networkSystem.getEntity(netId);
        if (!entity.hasComponent(NetworkComponent.class)) {
            logger.error("Sending net entity with no network component: {} - {}", netId, entity);
            continue;
        }
        // Note: Send owner->server fields on initial create
        Client owner = networkSystem.getOwner(entity);
        EntityData.PackedEntity entityData = entitySerializer.serialize(entity, true, new ServerComponentFieldCheck(owner == this, true)).build();
        NetData.CreateEntityMessage.Builder createMessage = NetData.CreateEntityMessage.newBuilder().setEntity(entityData);
        BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
        if (blockComponent != null) {
            createMessage.setBlockPos(NetMessageUtil.convert(blockComponent.getPosition()));
        }
        message.addCreateEntity(createMessage);
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityData(org.terasology.protobuf.EntityData) ServerComponentFieldCheck(org.terasology.engine.network.serialization.ServerComponentFieldCheck) Client(org.terasology.engine.network.Client) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 ServerComponentFieldCheck (org.terasology.engine.network.serialization.ServerComponentFieldCheck)2 EntityData (org.terasology.protobuf.EntityData)2 TIntIterator (gnu.trove.iterator.TIntIterator)1 Client (org.terasology.engine.network.Client)1 NetworkComponent (org.terasology.engine.network.NetworkComponent)1 BlockComponent (org.terasology.engine.world.block.BlockComponent)1