Search in sources :

Example 6 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class StateHeadlessSetup method createGameManifest.

public GameManifest createGameManifest() {
    GameManifest gameManifest = new GameManifest();
    Config config = context.get(Config.class);
    ModuleManager moduleManager = context.get(ModuleManager.class);
    for (Name moduleName : config.getDefaultModSelection().listModules()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
        if (module != null) {
            gameManifest.addModule(module.getId(), module.getVersion());
        } else {
            logger.warn("ModuleRegistry has no latest version for module {}", moduleName);
        }
    }
    WorldGenerationConfig worldGenConfig = config.getWorldGeneration();
    // If no valid default world generator set then try to find one - no option to pick one manually in headless
    if (!worldGenConfig.getDefaultGenerator().isValid()) {
        // find the first gameplay module that is available, it should have a preferred world gen
        for (Name moduleName : config.getDefaultModSelection().listModules()) {
            Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
            if (StandardModuleExtension.isGameplayModule(module)) {
                SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
                worldGenConfig.setDefaultGenerator(defaultWorldGenerator);
                break;
            }
        }
    }
    SimpleUri worldGeneratorUri = worldGenConfig.getDefaultGenerator();
    gameManifest.setTitle(worldGenConfig.getWorldTitle());
    gameManifest.setSeed(worldGenConfig.getDefaultSeed());
    WorldInfo worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD, worldGenConfig.getWorldTitle(), gameManifest.getSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), worldGeneratorUri);
    gameManifest.addWorld(worldInfo);
    return gameManifest;
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Config(org.terasology.engine.config.Config) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleManager(org.terasology.engine.core.module.ModuleManager) Module(org.terasology.gestalt.module.Module) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Name(org.terasology.gestalt.naming.Name)

Example 7 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class StateHeadlessSetup method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    initEntityAndComponentManagers(true);
    createLocalPlayer(context);
    GameManifest gameManifest;
    List<GameInfo> savedGames = GameProvider.getSavedGames();
    if (savedGames.size() > 0) {
        gameManifest = savedGames.get(0).getManifest();
    } else {
        gameManifest = createGameManifest();
    }
    Config config = context.get(Config.class);
    WorldInfo worldInfo = gameManifest.getWorldInfo(TerasologyConstants.MAIN_WORLD);
    config.getUniverseConfig().addWorldManager(worldInfo);
    config.getUniverseConfig().setSpawnWorldTitle(worldInfo.getTitle());
    config.getUniverseConfig().setUniverseSeed(gameManifest.getSeed());
    gameEngine.changeState(new StateLoading(gameManifest, NetworkMode.LISTEN_SERVER));
}
Also used : GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) GameManifest(org.terasology.engine.game.GameManifest) StateLoading(org.terasology.engine.core.modes.StateLoading) WorldGenerationConfig(org.terasology.engine.config.WorldGenerationConfig) Config(org.terasology.engine.config.Config) WorldInfo(org.terasology.engine.world.internal.WorldInfo)

Example 8 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class HeadlessEnvironment method setupWorldProvider.

@Override
protected void setupWorldProvider() {
    WorldProvider worldProvider = mock(WorldProvider.class);
    when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
    when(worldProvider.getTime()).thenReturn(WORLD_TIME);
    context.put(WorldProvider.class, worldProvider);
}
Also used : WorldProvider(org.terasology.engine.world.WorldProvider) WorldInfo(org.terasology.engine.world.internal.WorldInfo)

Example 9 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo 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)

Example 10 with WorldInfo

use of org.terasology.engine.world.internal.WorldInfo in project Terasology by MovingBlocks.

the class ReadWriteStorageManager method addGameManifestToSaveTransaction.

private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    UniverseConfig universeConfig = config.getUniverseConfig();
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);
    GameManifest gameManifest = new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
        gameManifest.addModule(module.getId(), module.getVersion());
    }
    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
        registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<WorldInfo> worlds = universeConfig.getWorlds();
    for (WorldInfo worldInfo : worlds) {
        gameManifest.addWorld(worldInfo);
    }
    WorldGenerator worldGenerator = CoreRegistry.get(WorldGenerator.class);
    if (worldGenerator != null) {
        WorldConfigurator worldConfigurator = worldGenerator.getConfigurator();
        Map<String, Component> params = worldConfigurator.getProperties();
        gameManifest.setModuleConfigs(worldGenerator.getUri(), params);
    }
    saveTransactionBuilder.setGameManifest(gameManifest);
}
Also used : WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) Time(org.terasology.engine.core.Time) UniverseConfig(org.terasology.engine.config.UniverseConfig) ModuleManager(org.terasology.engine.core.module.ModuleManager) Game(org.terasology.engine.game.Game) GameManifest(org.terasology.engine.game.GameManifest) BlockManager(org.terasology.engine.world.block.BlockManager) WorldInfo(org.terasology.engine.world.internal.WorldInfo) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) Module(org.terasology.gestalt.module.Module) Component(org.terasology.gestalt.entitysystem.component.Component) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ClientComponent(org.terasology.engine.network.ClientComponent)

Aggregations

WorldInfo (org.terasology.engine.world.internal.WorldInfo)12 ModuleManager (org.terasology.engine.core.module.ModuleManager)5 GameManifest (org.terasology.engine.game.GameManifest)5 Module (org.terasology.gestalt.module.Module)4 SimpleUri (org.terasology.engine.core.SimpleUri)3 WorldProvider (org.terasology.engine.world.WorldProvider)3 BlockManager (org.terasology.engine.world.block.BlockManager)3 Config (org.terasology.engine.config.Config)2 WorldGenerationConfig (org.terasology.engine.config.WorldGenerationConfig)2 StateLoading (org.terasology.engine.core.modes.StateLoading)2 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 ServerInfoMessage (org.terasology.engine.network.ServerInfoMessage)2 DirectionAndOriginPosRecorderList (org.terasology.engine.recording.DirectionAndOriginPosRecorderList)2 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)2 RecordAndReplaySerializer (org.terasology.engine.recording.RecordAndReplaySerializer)2 RecordAndReplayUtils (org.terasology.engine.recording.RecordAndReplayUtils)2 WorldSetupWrapper (org.terasology.engine.rendering.world.WorldSetupWrapper)2 WorldGenerator (org.terasology.engine.world.generator.WorldGenerator)2 IOException (java.io.IOException)1