Search in sources :

Example 1 with AutoReloadAssetTypeManager

use of org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager in project Terasology by MovingBlocks.

the class TerasologyEngine method initManagers.

private void initManagers() {
    changeStatus(TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER);
    TypeRegistry.WHITELISTED_CLASSES = ExternalApiWhitelist.CLASSES.stream().map(Class::getName).collect(Collectors.toSet());
    TypeRegistry.WHITELISTED_PACKAGES = ExternalApiWhitelist.PACKAGES;
    ModuleManager moduleManager = new ModuleManager(rootContext.get(Config.class), classesOnClasspathsToAddToEngine);
    ModuleTypeRegistry typeRegistry = new ModuleTypeRegistry(moduleManager.getEnvironment());
    rootContext.put(ModuleTypeRegistry.class, typeRegistry);
    rootContext.put(TypeRegistry.class, typeRegistry);
    rootContext.put(ModuleManager.class, moduleManager);
    changeStatus(TerasologyEngineStatus.INITIALIZING_LOWLEVEL_OBJECT_MANIPULATION);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    rootContext.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    rootContext.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    rootContext.put(TypeHandlerLibrary.class, TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry));
    changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_TYPES);
    assetTypeManager = new AutoReloadAssetTypeManager();
    rootContext.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    rootContext.put(AssetManager.class, assetTypeManager.getAssetManager());
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) ModuleTypeRegistry(org.terasology.reflection.ModuleTypeRegistry) Config(org.terasology.engine.config.Config) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ModuleManager(org.terasology.engine.core.module.ModuleManager) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)

Example 2 with AutoReloadAssetTypeManager

use of org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager in project Terasology by MovingBlocks.

the class TerasologyEngine method tick.

/**
 * Runs a single "tick" of the engine
 *
 * @return true if the loop requesting a tick should continue running
 */
public boolean tick() {
    if (shutdownRequested) {
        return false;
    }
    if (assetTypeManager instanceof AutoReloadAssetTypeManager) {
        ((AutoReloadAssetTypeManager) assetTypeManager).reloadChangedAssets();
    }
    processPendingState();
    if (currentState == null) {
        shutdown();
        return false;
    }
    Iterator<Float> updateCycles = timeSubsystem.getEngineTime().tick();
    CoreRegistry.setContext(currentState.getContext());
    rootContext.get(NetworkSystem.class).setContext(currentState.getContext());
    for (EngineSubsystem subsystem : allSubsystems) {
        try (Activity ignored = PerformanceMonitor.startActivity(subsystem.getName() + " PreUpdate")) {
            subsystem.preUpdate(currentState, timeSubsystem.getEngineTime().getRealDelta());
        }
    }
    while (updateCycles.hasNext()) {
        // gameTime gets updated here!
        float updateDelta = updateCycles.next();
        try (Activity ignored = PerformanceMonitor.startActivity("Main Update")) {
            currentState.update(updateDelta);
        }
    }
    // Waiting processes are set by modules via GameThread.a/synch() methods.
    GameThread.processWaitingProcesses();
    for (EngineSubsystem subsystem : getSubsystems()) {
        try (Activity ignored = PerformanceMonitor.startActivity(subsystem.getName() + " Subsystem postUpdate")) {
            subsystem.postUpdate(currentState, timeSubsystem.getEngineTime().getRealDelta());
        }
    }
    assetTypeManager.disposedUnusedAssets();
    PerformanceMonitor.rollCycle();
    PerformanceMonitor.startActivity("Other");
    return true;
}
Also used : EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) NetworkSystem(org.terasology.engine.network.NetworkSystem) Activity(org.terasology.engine.monitoring.Activity) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)

Example 3 with AutoReloadAssetTypeManager

use of org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager in project Terasology by MovingBlocks.

the class UniverseSetupScreen method setEnvironment.

/**
 * This method switches the environment of the game to a temporary one needed for
 * creating a game. It creates a new {@link Context} and only puts the minimum classes
 * needed for successful game creation.
 * @param wrapper takes the {@link AdvancedGameSetupScreen} and pushes it into the new context.
 */
public void setEnvironment(UniverseWrapper wrapper) {
    context = new ContextImpl();
    CoreRegistry.setContext(context);
    ReflectFactory reflectFactory = new ReflectionReflectFactory();
    context.put(ReflectFactory.class, reflectFactory);
    CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
    context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
    context.put(NUIManager.class, getManager());
    context.put(UniverseSetupScreen.class, this);
    assetTypeManager = new AutoReloadAssetTypeManager();
    context.put(AssetManager.class, assetTypeManager.getAssetManager());
    context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    context.put(ModuleManager.class, moduleManager);
    context.put(UniverseWrapper.class, wrapper);
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (result.isSuccess()) {
        environment = moduleManager.loadEnvironment(result.getModules(), false);
        context.put(ModuleEnvironment.class, environment);
        context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
        initAssets();
        EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
        context.put(EnvironmentSwitchHandler.class, environmentSwitcher);
        environmentSwitcher.handleSwitchToPreviewEnvironment(context, environment);
    }
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ContextImpl(org.terasology.engine.context.internal.ContextImpl) AutoReloadAssetTypeManager(org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Aggregations

AutoReloadAssetTypeManager (org.terasology.gestalt.assets.module.autoreload.AutoReloadAssetTypeManager)3 CopyStrategyLibrary (org.terasology.reflection.copy.CopyStrategyLibrary)2 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)2 ReflectionReflectFactory (org.terasology.reflection.reflect.ReflectionReflectFactory)2 Config (org.terasology.engine.config.Config)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 EngineSubsystem (org.terasology.engine.core.subsystem.EngineSubsystem)1 Activity (org.terasology.engine.monitoring.Activity)1 NetworkSystem (org.terasology.engine.network.NetworkSystem)1 TempWorldGeneratorPluginLibrary (org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary)1 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)1 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)1 ModuleTypeRegistry (org.terasology.reflection.ModuleTypeRegistry)1