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());
}
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;
}
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);
}
}
Aggregations