Search in sources :

Example 1 with ReadWriteStorageManager

use of org.terasology.engine.persistence.internal.ReadWriteStorageManager in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupStorageManager.

@Override
protected void setupStorageManager() throws IOException {
    ModuleManager moduleManager = context.get(ModuleManager.class);
    EngineEntityManager engineEntityManager = context.get(EngineEntityManager.class);
    BlockManager blockManager = context.get(BlockManager.class);
    RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
    Path savePath = PathManager.getInstance().getSavePath("world1");
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    context.put(BlockFamilyLibrary.class, new BlockFamilyLibrary(environment, context));
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(), engineEntityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockFamilyLibrary(org.terasology.engine.world.block.family.BlockFamilyLibrary) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer)

Example 2 with ReadWriteStorageManager

use of org.terasology.engine.persistence.internal.ReadWriteStorageManager in project Terasology by MovingBlocks.

the class TerasologyTestingEnvironment method setup.

@BeforeEach
public void setup() throws Exception {
    context.put(ModuleManager.class, moduleManager);
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    mockTime = mock(EngineTime.class);
    context.put(Time.class, mockTime);
    NetworkSystemImpl networkSystem = new NetworkSystemImpl(mockTime, context);
    context.put(Game.class, new Game());
    context.put(NetworkSystem.class, networkSystem);
    EntitySystemSetupUtil.addReflectionBasedLibraries(context);
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    engineEntityManager = context.get(EngineEntityManager.class);
    // 'mock' added to avoid hiding a field
    BlockManager mockBlockManager = context.get(BlockManager.class);
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    RecordedEventStore recordedEventStore = new RecordedEventStore();
    RecordAndReplayUtils recordAndReplayUtils = new RecordAndReplayUtils();
    context.put(RecordAndReplayUtils.class, recordAndReplayUtils);
    CharacterStateEventPositionMap characterStateEventPositionMap = new CharacterStateEventPositionMap();
    context.put(CharacterStateEventPositionMap.class, characterStateEventPositionMap);
    DirectionAndOriginPosRecorderList directionAndOriginPosRecorderList = new DirectionAndOriginPosRecorderList();
    context.put(DirectionAndOriginPosRecorderList.class, directionAndOriginPosRecorderList);
    RecordAndReplaySerializer recordAndReplaySerializer = new RecordAndReplaySerializer(engineEntityManager, recordedEventStore, recordAndReplayUtils, characterStateEventPositionMap, directionAndOriginPosRecorderList, moduleManager, context.get(TypeRegistry.class));
    context.put(RecordAndReplaySerializer.class, recordAndReplaySerializer);
    Path savePath = PathManager.getInstance().getSavePath("world1");
    context.put(StorageManager.class, new ReadWriteStorageManager(savePath, moduleManager.getEnvironment(), engineEntityManager, mockBlockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus));
    ComponentSystemManager componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    LoadPrefabs prefabLoadStep = new LoadPrefabs(context);
    boolean complete = false;
    prefabLoadStep.begin();
    while (!complete) {
        complete = prefabLoadStep.step();
    }
    context.get(ComponentSystemManager.class).initialise();
    context.put(Console.class, new ConsoleImpl(context));
}
Also used : EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) ConsoleImpl(org.terasology.engine.logic.console.ConsoleImpl) EngineTime(org.terasology.engine.core.EngineTime) RecordedEventStore(org.terasology.engine.recording.RecordedEventStore) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) TypeRegistry(org.terasology.reflection.TypeRegistry) NetworkSystemImpl(org.terasology.engine.network.internal.NetworkSystemImpl) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) Game(org.terasology.engine.game.Game) LoadPrefabs(org.terasology.engine.core.modes.loadProcesses.LoadPrefabs) BlockManager(org.terasology.engine.world.block.BlockManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) CharacterStateEventPositionMap(org.terasology.engine.recording.CharacterStateEventPositionMap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ReadWriteStorageManager

use of org.terasology.engine.persistence.internal.ReadWriteStorageManager in project Terasology by MovingBlocks.

the class InitialiseWorld method step.

@Override
public boolean step() {
    BlockManager blockManager = context.get(BlockManager.class);
    ExtraBlockDataManager extraDataManager = context.get(ExtraBlockDataManager.class);
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    context.put(WorldGeneratorPluginLibrary.class, new DefaultWorldGeneratorPluginLibrary(environment, context));
    WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
    verify(worldInfo.getWorldGenerator().isValid(), "Game manifest did not specify world type.");
    if (worldInfo.getSeed() == null || worldInfo.getSeed().isEmpty()) {
        FastRandom random = new FastRandom();
        worldInfo.setSeed(random.nextString(16));
    }
    logger.info("World seed: \"{}\"", worldInfo.getSeed());
    // TODO: Separate WorldRenderer from world handling in general
    WorldGeneratorManager worldGeneratorManager = context.get(WorldGeneratorManager.class);
    WorldGenerator worldGenerator;
    try {
        worldGenerator = WorldGeneratorManager.createGenerator(worldInfo.getWorldGenerator(), context);
        // setting the world seed will create the world builder
        worldGenerator.setWorldSeed(worldInfo.getSeed());
        context.put(WorldGenerator.class, worldGenerator);
    } catch (UnresolvedWorldGeneratorException e) {
        logger.error("Unable to load world generator {}. Available world generators: {}", worldInfo.getWorldGenerator(), worldGeneratorManager.getWorldGenerators());
        context.get(GameEngine.class).changeState(new StateMainMenu("Failed to resolve world generator."));
        // We need to return true, otherwise the loading state will just call us again immediately
        return true;
    }
    // Init. a new world
    EngineEntityManager entityManager = (EngineEntityManager) context.get(EntityManager.class);
    boolean writeSaveGamesEnabled = context.get(SystemConfig.class).writeSaveGamesEnabled.get();
    // Gets save data from a normal save or from a recording if it is a replay
    Path saveOrRecordingPath = getSaveOrRecordingPath();
    StorageManager storageManager;
    RecordAndReplaySerializer recordAndReplaySerializer = context.get(RecordAndReplaySerializer.class);
    RecordAndReplayUtils recordAndReplayUtils = context.get(RecordAndReplayUtils.class);
    RecordAndReplayCurrentStatus recordAndReplayCurrentStatus = context.get(RecordAndReplayCurrentStatus.class);
    try {
        storageManager = writeSaveGamesEnabled ? new ReadWriteStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager, recordAndReplaySerializer, recordAndReplayUtils, recordAndReplayCurrentStatus) : new ReadOnlyStorageManager(saveOrRecordingPath, environment, entityManager, blockManager, extraDataManager);
    } catch (IOException e) {
        logger.error("Unable to create storage manager!", e);
        context.get(GameEngine.class).changeState(new StateMainMenu("Unable to create storage manager!"));
        // We need to return true, otherwise the loading state will just call us again immediately
        return true;
    }
    context.put(StorageManager.class, storageManager);
    LocalChunkProvider chunkProvider = new LocalChunkProvider(storageManager, entityManager, worldGenerator, blockManager, extraDataManager, Maps.newConcurrentMap());
    RelevanceSystem relevanceSystem = new RelevanceSystem(chunkProvider);
    context.put(RelevanceSystem.class, relevanceSystem);
    context.get(ComponentSystemManager.class).register(relevanceSystem, "engine:relevanceSystem");
    chunkProvider.setRelevanceSystem(relevanceSystem);
    Block unloadedBlock = blockManager.getBlock(BlockManager.UNLOADED_ID);
    WorldProviderCoreImpl worldProviderCore = new WorldProviderCoreImpl(worldInfo, chunkProvider, unloadedBlock, context);
    EntityAwareWorldProvider entityWorldProvider = new EntityAwareWorldProvider(worldProviderCore, context);
    WorldProvider worldProvider = new WorldProviderWrapper(entityWorldProvider, extraDataManager);
    context.put(WorldProvider.class, worldProvider);
    chunkProvider.setBlockEntityRegistry(entityWorldProvider);
    context.put(BlockEntityRegistry.class, entityWorldProvider);
    context.get(ComponentSystemManager.class).register(entityWorldProvider, "engine:BlockEntityRegistry");
    DefaultCelestialSystem celestialSystem = new DefaultCelestialSystem(new BasicCelestialModel(), context);
    context.put(CelestialSystem.class, celestialSystem);
    context.get(ComponentSystemManager.class).register(celestialSystem);
    Skysphere skysphere = new Skysphere(context);
    BackdropProvider backdropProvider = skysphere;
    context.put(BackdropProvider.class, backdropProvider);
    RenderingSubsystemFactory engineSubsystemFactory = context.get(RenderingSubsystemFactory.class);
    WorldRenderer worldRenderer = engineSubsystemFactory.createWorldRenderer(context);
    context.put(WorldRenderer.class, worldRenderer);
    // TODO: These shouldn't be done here, nor so strongly tied to the world renderer
    LocalPlayer localPlayer = new LocalPlayer();
    localPlayer.setRecordAndReplayClasses(context.get(DirectionAndOriginPosRecorderList.class), context.get(RecordAndReplayCurrentStatus.class));
    context.put(LocalPlayer.class, localPlayer);
    context.put(Camera.class, worldRenderer.getActiveCamera());
    return true;
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) UnresolvedWorldGeneratorException(org.terasology.engine.world.generator.UnresolvedWorldGeneratorException) LocalChunkProvider(org.terasology.engine.world.chunks.localChunkProvider.LocalChunkProvider) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) WorldProviderWrapper(org.terasology.engine.world.internal.WorldProviderWrapper) ReadOnlyStorageManager(org.terasology.engine.persistence.internal.ReadOnlyStorageManager) StorageManager(org.terasology.engine.persistence.StorageManager) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ModuleManager(org.terasology.engine.core.module.ModuleManager) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) BackdropProvider(org.terasology.engine.rendering.backdrop.BackdropProvider) RecordAndReplaySerializer(org.terasology.engine.recording.RecordAndReplaySerializer) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) RecordAndReplayUtils(org.terasology.engine.recording.RecordAndReplayUtils) DefaultWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.DefaultWorldGeneratorPluginLibrary) WorldProvider(org.terasology.engine.world.WorldProvider) EntityAwareWorldProvider(org.terasology.engine.world.internal.EntityAwareWorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) Path(java.nio.file.Path) FastRandom(org.terasology.engine.utilities.random.FastRandom) IOException(java.io.IOException) WorldProviderCoreImpl(org.terasology.engine.world.internal.WorldProviderCoreImpl) ExtraBlockDataManager(org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager) DefaultCelestialSystem(org.terasology.engine.world.sun.DefaultCelestialSystem) RenderingSubsystemFactory(org.terasology.engine.core.subsystem.RenderingSubsystemFactory) WorldRenderer(org.terasology.engine.rendering.world.WorldRenderer) BasicCelestialModel(org.terasology.engine.world.sun.BasicCelestialModel) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) EngineEntityManager(org.terasology.engine.entitySystem.entity.internal.EngineEntityManager) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) BlockManager(org.terasology.engine.world.block.BlockManager) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) Skysphere(org.terasology.engine.rendering.backdrop.Skysphere) Block(org.terasology.engine.world.block.Block) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) ReadWriteStorageManager(org.terasology.engine.persistence.internal.ReadWriteStorageManager) ReadOnlyStorageManager(org.terasology.engine.persistence.internal.ReadOnlyStorageManager) RelevanceSystem(org.terasology.engine.world.chunks.localChunkProvider.RelevanceSystem)

Aggregations

Path (java.nio.file.Path)3 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)3 ReadWriteStorageManager (org.terasology.engine.persistence.internal.ReadWriteStorageManager)3 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)3 RecordAndReplaySerializer (org.terasology.engine.recording.RecordAndReplaySerializer)3 RecordAndReplayUtils (org.terasology.engine.recording.RecordAndReplayUtils)3 BlockManager (org.terasology.engine.world.block.BlockManager)3 ExtraBlockDataManager (org.terasology.engine.world.chunks.blockdata.ExtraBlockDataManager)3 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)2 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)2 IOException (java.io.IOException)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 EngineTime (org.terasology.engine.core.EngineTime)1 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)1 LoadPrefabs (org.terasology.engine.core.modes.loadProcesses.LoadPrefabs)1 RenderingSubsystemFactory (org.terasology.engine.core.subsystem.RenderingSubsystemFactory)1 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)1 Game (org.terasology.engine.game.Game)1