use of org.terasology.engine.core.subsystem.EngineSubsystem in project Terasology by MovingBlocks.
the class TerasologyEngine method cleanup.
public void cleanup() {
logger.info("Shutting down Terasology...");
changeStatus(StandardGameStatus.SHUTTING_DOWN);
if (currentState != null) {
currentState.dispose(true);
currentState = null;
}
Iterator<EngineSubsystem> preshutdownIter = allSubsystems.descendingIterator();
while (preshutdownIter.hasNext()) {
EngineSubsystem subsystem = preshutdownIter.next();
try {
subsystem.preShutdown();
} catch (RuntimeException e) {
logger.error("Error preparing to shutdown {} subsystem", subsystem.getName(), e);
}
}
Iterator<EngineSubsystem> shutdownIter = allSubsystems.descendingIterator();
while (shutdownIter.hasNext()) {
EngineSubsystem subsystem = shutdownIter.next();
try {
subsystem.shutdown();
} catch (RuntimeException e) {
logger.error("Error shutting down {} subsystem", subsystem.getName(), e);
}
}
}
use of org.terasology.engine.core.subsystem.EngineSubsystem in project Terasology by MovingBlocks.
the class TerasologyEngine method postInitSubsystems.
/**
* Gives a chance to subsystems to do something AFTER managers and Time are initialized.
*/
private void postInitSubsystems() {
for (EngineSubsystem subsystem : getSubsystems()) {
changeStatus(() -> "Post-Initialising " + subsystem.getName() + " subsystem");
subsystem.postInitialise(rootContext);
}
}
use of org.terasology.engine.core.subsystem.EngineSubsystem in project Terasology by MovingBlocks.
the class TerasologyEngine method initAssets.
private void initAssets() {
// cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
assetTypeManager.createAssetType(ByteBufferAsset.class, ByteBufferAsset::new, "mesh");
for (EngineSubsystem subsystem : allSubsystems) {
subsystem.registerCoreAssetTypes(assetTypeManager);
}
}
use of org.terasology.engine.core.subsystem.EngineSubsystem 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.engine.core.subsystem.EngineSubsystem in project Terasology by MovingBlocks.
the class Terasology method populateSubsystems.
private void populateSubsystems(TerasologyEngineBuilder builder) {
if (isHeadless) {
builder.add(new HeadlessGraphics()).add(new HeadlessTimer()).add(new HeadlessAudio());
} else {
EngineSubsystem audio = soundEnabled ? new LwjglAudio() : new HeadlessAudio();
builder.add(audio).add(new LwjglGraphics()).add(new LwjglTimer()).add(new LwjglInput()).add(new BindsSubsystem()).add(new OpenVRInput());
builder.add(new DiscordRPCSubSystem());
}
builder.add(new HibernationSubsystem());
}
Aggregations