コード例 #1
0
  @Override
  public void deserializeWorld(EntityData.World world) {
    entityManager.setNextId(world.getNextEntityId());
    for (Integer deadId : world.getFreedEntityIdList()) {
      entityManager.getFreedIds().add(deadId);
    }

    for (EntityData.Prefab prefabData : world.getPrefabList()) {
      if (!prefabManager.exists(prefabData.getName())) {
        deserializePrefab(prefabData);
      }
    }

    for (int index = 0; index < world.getComponentClassCount(); ++index) {
      ComponentMetadata componentMetadata =
          componentLibrary.getMetadata(world.getComponentClass(index));
      if (componentMetadata != null) {
        componentIdTable.put(index, componentMetadata.getType());
      }
    }

    for (EntityData.Entity entityData : world.getEntityList()) {
      deserializeEntity(entityData);
    }
  }
コード例 #2
0
  @Override
  public EntityData.World serializeWorld() {
    final EntityData.World.Builder world = EntityData.World.newBuilder();
    writeIdInfo(world);

    if (isUsingLookupTables()) {
      writeComponentTypeTable(world);
    }

    for (Prefab prefab : prefabManager.listPrefabs()) {
      world.addPrefab(serializePrefab(prefab));
    }

    for (EntityRef entity : entityManager.iteratorEntities()) {
      world.addEntity(serializeEntity(entity));
    }
    return world.build();
  }