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