@Override public void onBeforeDeactivation(EntityRef entity, Collection<Component> components) { entitySetDeltaRecorder.onBeforeDeactivation(entity, components); }
@Override public void onEntityComponentAdded(EntityRef entity, Class<? extends Component> component) { entitySetDeltaRecorder.onEntityComponentAdded(entity, component); }
@Override public void onEntityComponentChange(EntityRef entity, Class<? extends Component> component) { entitySetDeltaRecorder.onEntityComponentChange(entity, component); }
private void applyDeltaToPrivateEntityManager() { deltaToSave.getEntityDeltas().forEachEntry((entityId, delta) -> { if (entityId >= privateEntityManager.getNextId()) { privateEntityManager.setNextId(entityId + 1); deltaToSave.getDestroyedEntities().forEach(entityId -> { if (entityId >= privateEntityManager.getNextId()) { privateEntityManager.setNextId(entityId + 1); deltaToSave.getEntityDeltas().forEachEntry((entityId, delta) -> { if (privateEntityManager.isActiveEntity(entityId)) { EntityRef entity = privateEntityManager.getEntity(entityId); }); final List<EntityRef> entitiesToDestroy = Lists.newArrayList(); deltaToSave.getDestroyedEntities().forEach(entityId -> { EntityRef entityToDestroy; if (privateEntityManager.isActiveEntity(entityId)) { deltaToSave.bindAllDelayedEntityRefsTo(privateEntityManager); deltaToSave.getDeactivatedEntities().forEach(entityId -> { EntityRef entityRef = privateEntityManager.getEntity(entityId); privateEntityManager.deactivateForStorage(entityRef);
public void onEntityComponentRemoved(EntityRef entity, Class<? extends Component> component) { if (entity.isPersistent()) { EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity); entityDelta.removeComponent(component); } }
private void startAutoSaving() { logger.info("Auto Saving - Creating game snapshot"); PerformanceMonitor.startActivity("Auto Saving"); ComponentSystemManager componentSystemManager = CoreRegistry.get(ComponentSystemManager.class); for (ComponentSystem sys : componentSystemManager.iterateAll()) { sys.preAutoSave(); } saveTransaction = createSaveTransaction(); saveThreadManager.offer(saveTransaction); for (ComponentSystem sys : componentSystemManager.iterateAll()) { sys.postAutoSave(); } scheduleNextAutoSave(); PerformanceMonitor.endActivity(); entitySetDeltaRecorder = new EntitySetDeltaRecorder(this.entityRefReplacingComponentLibrary); logger.info("Auto Saving - Snapshot created: Writing phase starts"); }
@Override public void onEntityComponentRemoved(EntityRef entity, Class<? extends Component> component) { entitySetDeltaRecorder.onEntityComponentRemoved(entity, component); }
public void onReactivation(EntityRef entity, Collection<Component> components) { if (entity.isPersistent()) { EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity); for (Component component : components) { Component componentSnapshot = componentLibrary.copy(component); entityDelta.setChangedComponent(componentSnapshot); } } }
private void startSaving() { logger.info("Saving - Creating game snapshot"); PerformanceMonitor.startActivity("Saving"); ComponentSystemManager componentSystemManager = CoreRegistry.get(ComponentSystemManager.class); for (ComponentSystem sys : componentSystemManager.iterateAll()) { sys.preSave(); } saveRequested = false; saveTransaction = createSaveTransaction(); saveThreadManager.offer(saveTransaction); if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.NOT_ACTIVATED) { saveGamePreviewImage(); } for (ComponentSystem sys : componentSystemManager.iterateAll()) { sys.postSave(); } PerformanceMonitor.endActivity(); entitySetDeltaRecorder = new EntitySetDeltaRecorder(this.entityRefReplacingComponentLibrary); logger.info("Saving - Snapshot created: Writing phase starts"); }
public void onEntityComponentChange(EntityRef entity, Class<? extends Component> componentClass) { if (entity.isPersistent()) { EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity); Component component = entity.getComponent(componentClass); Component componentSnapshot = componentLibrary.copy(component); entityDelta.setChangedComponent(componentSnapshot); } }
ReadWriteStorageManager(Path savePath, ModuleEnvironment environment, EngineEntityManager entityManager, BlockManager blockManager, BiomeManager biomeManager, ExtraBlockDataManager extraDataManager, boolean storeChunksInZips, RecordAndReplaySerializer recordAndReplaySerializer, RecordAndReplayUtils recordAndReplayUtils, RecordAndReplayCurrentStatus recordAndReplayCurrentStatus) throws IOException { super(savePath, environment, entityManager, blockManager, biomeManager, extraDataManager, storeChunksInZips); entityManager.subscribeForDestruction(this); entityManager.subscribeForChanges(this); // TODO Ensure that the component library and the type serializer library are thread save (e.g. immutable) this.privateEntityManager = createPrivateEntityManager(entityManager.getComponentLibrary()); Files.createDirectories(getStoragePathProvider().getStoragePathDirectory()); this.saveTransactionHelper = new SaveTransactionHelper(getStoragePathProvider()); this.saveThreadManager = TaskMaster.createFIFOTaskMaster("Saving", 1); this.config = CoreRegistry.get(Config.class); this.entityRefReplacingComponentLibrary = privateEntityManager.getComponentLibrary() .createCopyUsingCopyStrategy(EntityRef.class, new DelayedEntityRefCopyStrategy(this)); this.entitySetDeltaRecorder = new EntitySetDeltaRecorder(this.entityRefReplacingComponentLibrary); this.recordAndReplaySerializer = recordAndReplaySerializer; this.recordAndReplayUtils = recordAndReplayUtils; this.recordAndReplayCurrentStatus = recordAndReplayCurrentStatus; }
public void onEntityComponentAdded(EntityRef entity, Class<? extends Component> componentClass) { if (entity.isPersistent()) { onEntityComponentChange(entity, componentClass); } }