/** * * @param entitiesToSave all persistent entities within the given chunk * @param chunkUnloaded if true the chunk data will be used directly. If deactivate is false then the chunk will be * but in snapshot mode so that concurrent modifications (and possibly future unload) is * possible. */ public CompressedChunkBuilder(EngineEntityManager entityManager, ChunkImpl chunk, Collection<EntityRef> entitiesToSave, boolean chunkUnloaded) { EntityStorer storer = new EntityStorer(entityManager); entitiesToSave.stream().filter(EntityRef::isPersistent).forEach(storer::store); storedEntities = storer.getStoredEntities(); this.entityStore = storer.finaliseStore(); this.chunk = chunk; this.viaSnapshot = !chunkUnloaded; if (viaSnapshot) { this.chunk.createSnapshot(); } }
public void store(EntityRef entity) { store(entity, ""); }
public EntityData.PlayerStore build(EngineEntityManager entityManager) { EntityData.PlayerStore.Builder playerEntityStore = EntityData.PlayerStore.newBuilder(); playerEntityStore.setCharacterPosX(relevanceLocation.x); playerEntityStore.setCharacterPosY(relevanceLocation.y); playerEntityStore.setCharacterPosZ(relevanceLocation.z); playerEntityStore.setHasCharacter(characterEntityId != null); if (characterEntityId != null) { EntityRef character = entityManager.getEntity(characterEntityId); EntityStorer storer = new EntityStorer(entityManager); storer.store(character, PlayerStoreInternal.CHARACTER); storedEntities = storer.getStoredEntities(); playerEntityStore.setStore(storer.finaliseStore()); } else { storedEntities = Sets.newHashSet(); } return playerEntityStore.build(); }
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); } }