Search in sources :

Example 11 with EntityData

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

the class ServerImpl method sendEntities.

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();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) EntityData(org.terasology.protobuf.EntityData) BlockComponent(org.terasology.world.block.BlockComponent) NetworkComponent(org.terasology.network.NetworkComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponentFieldCheck(org.terasology.network.serialization.ClientComponentFieldCheck)

Example 12 with EntityData

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

the class EntityStorer method store.

public void store(EntityRef entity, String name) {
    if (entity.isActive()) {
        for (EntityRef ownedEntity : helper.listOwnedEntities(entity)) {
            if (!ownedEntity.isAlwaysRelevant() && ownedEntity.isPersistent()) {
                store(ownedEntity);
            }
        }
        EntityData.Entity entityData = serializer.serialize(entity, true, FieldSerializeCheck.NullCheck.<Component>newInstance());
        entityStoreBuilder.addEntity(entityData);
        if (!name.isEmpty()) {
            entityStoreBuilder.addEntityName(name);
            entityStoreBuilder.addEntityNamed(entityData.getId());
        }
        storedEntities.add(entity);
    }
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 13 with EntityData

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

the class EntitySerializerTest method testAlwaysRelevantPersisted.

@Test
public void testAlwaysRelevantPersisted() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    boolean defaultSetting = entity.isAlwaysRelevant();
    EntityScope newScope = defaultSetting ? CHUNK : GLOBAL;
    entity.setScope(newScope);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef newEntity = entitySerializer.deserialize(entityData);
    assertEquals(newScope, newEntity.getScope());
    assertEquals(!defaultSetting, newEntity.isAlwaysRelevant());
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) EntityScope(org.terasology.entitySystem.entity.internal.EntityScope) Test(org.junit.Test)

Example 14 with EntityData

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

the class EntitySerializerTest method testPrefabMaintainedOverSerialization.

@Test
public void testPrefabMaintainedOverSerialization() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef newEntity = entitySerializer.deserialize(entityData);
    assertTrue(newEntity.hasComponent(EntityInfoComponent.class));
    EntityInfoComponent comp = newEntity.getComponent(EntityInfoComponent.class);
    assertEquals(prefab, comp.parentPrefab);
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.entitySystem.entity.EntityRef) EntityInfoComponent(org.terasology.entitySystem.entity.internal.EntityInfoComponent) Test(org.junit.Test)

Example 15 with EntityData

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

the class EntitySerializerTest method testDeltaLoadRemovedComponent.

@Test
public void testDeltaLoadRemovedComponent() throws Exception {
    EntityRef entity = entityManager.create("test:Test");
    entity.removeComponent(StringComponent.class);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef loadedEntity = entitySerializer.deserialize(entityData);
    assertTrue(loadedEntity.exists());
    assertFalse(loadedEntity.hasComponent(StringComponent.class));
}
Also used : StringComponent(org.terasology.entitySystem.stubs.StringComponent) 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