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();
}
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);
}
}
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());
}
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);
}
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));
}
Aggregations