Search in sources :

Example 1 with EntityData

use of org.terasology.protobuf.EntityData 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.network.serialization.ServerComponentFieldCheck) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 2 with EntityData

use of org.terasology.protobuf.EntityData in project Terasology by MovingBlocks.

the class EntitySerializerTest method testDeltaAddNewComponent.

@Test
public void testDeltaAddNewComponent() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    entity.addComponent(new IntegerComponent(1));
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(1, entityData.getComponentCount());
    assertEquals(0, entityData.getRemovedComponentCount());
    EntityData.Component componentData = entityData.getComponent(0);
    assertEquals("test:integer", componentData.getType());
    assertEquals(1, componentData.getFieldCount());
    EntityData.NameValue field = componentData.getField(0);
    assertEquals("value", field.getName());
    assertEquals(1, field.getValue().getInteger(0));
}
Also used : IntegerComponent(org.terasology.entitySystem.stubs.IntegerComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 3 with EntityData

use of org.terasology.protobuf.EntityData in project Terasology by MovingBlocks.

the class EntitySerializerTest method testDeltaLoadNoChange.

@Test
public void testDeltaLoadNoChange() throws Exception {
    EntityRef entity = entityManager.create("test:Test");
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef loadedEntity = entitySerializer.deserialize(entityData);
    assertTrue(loadedEntity.exists());
    assertTrue(loadedEntity.hasComponent(StringComponent.class));
    assertEquals("Value", loadedEntity.getComponent(StringComponent.class).value);
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 4 with EntityData

use of org.terasology.protobuf.EntityData in project Terasology by MovingBlocks.

the class EntitySerializerTest method testDeltaRemoveComponent.

@Test
public void testDeltaRemoveComponent() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    entity.removeComponent(StringComponent.class);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(0, entityData.getComponentCount());
    assertEquals(Lists.newArrayList("test:string"), entityData.getRemovedComponentList());
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 5 with EntityData

use of org.terasology.protobuf.EntityData in project Terasology by MovingBlocks.

the class EntitySerializerTest method testDeltaNoUnchangedComponents.

@Test
public void testDeltaNoUnchangedComponents() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    assertEquals(entity.getId(), entityData.getId());
    assertEquals(prefab.getName(), entityData.getParentPrefab());
    assertEquals(0, entityData.getComponentCount());
    assertEquals(0, entityData.getRemovedComponentCount());
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

EntityData (org.terasology.protobuf.EntityData)16 EntityRef (org.terasology.entitySystem.entity.EntityRef)15 Test (org.junit.Test)11 StringComponent (org.terasology.entitySystem.stubs.StringComponent)5 TIntIterator (gnu.trove.iterator.TIntIterator)2 Component (org.terasology.entitySystem.Component)2 EntityInfoComponent (org.terasology.entitySystem.entity.internal.EntityInfoComponent)2 IntegerComponent (org.terasology.entitySystem.stubs.IntegerComponent)2 NetworkComponent (org.terasology.network.NetworkComponent)2 ServerComponentFieldCheck (org.terasology.network.serialization.ServerComponentFieldCheck)2 BlockComponent (org.terasology.world.block.BlockComponent)2 SimpleUri (org.terasology.engine.SimpleUri)1 EntityScope (org.terasology.entitySystem.entity.internal.EntityScope)1 MappedTypeComponent (org.terasology.entitySystem.stubs.MappedTypeComponent)1 Client (org.terasology.network.Client)1 ClientComponentFieldCheck (org.terasology.network.serialization.ClientComponentFieldCheck)1