Exemplo n.º 1
0
  @Override
  public boolean step() {
    NetworkSystem networkSystem = context.get(NetworkSystem.class);
    WorldAtlas atlas =
        new WorldAtlasImpl(context.get(Config.class).getRendering().getMaxTextureAtlasResolution());
    context.put(WorldAtlas.class, atlas);

    BlockManagerImpl blockManager;
    if (networkSystem.getMode().isAuthority()) {
      blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), true);
      blockManager.subscribe(context.get(NetworkSystem.class));
    } else {
      blockManager = new BlockManagerImpl(atlas, context.get(AssetManager.class), false);
    }
    context.put(BlockManager.class, blockManager);
    context
        .get(TypeSerializationLibrary.class)
        .add(Block.class, new BlockTypeHandler(blockManager));
    context
        .get(TypeSerializationLibrary.class)
        .add(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));

    blockManager.initialise(
        gameManifest.getRegisteredBlockFamilies(), gameManifest.getBlockIdMap());

    return true;
  }
Exemplo n.º 2
0
  /**
   * Runs the engine, including its main loop. This method is called only once per application
   * startup, which is the reason the GameState provided is the -initial- state rather than a
   * generic game state.
   *
   * @param initialState In at least one context (the PC facade) the GameState implementation
   *     provided as input may vary, depending if the application has or hasn't been started
   *     headless.
   */
  @Override
  public synchronized void run(GameState initialState) {
    Preconditions.checkState(!running);
    running = true;
    initialize();
    changeStatus(StandardGameStatus.RUNNING);

    try {
      rootContext.put(GameEngine.class, this);
      changeState(initialState);

      mainLoop(); // -THE- MAIN LOOP. Most of the application time and resources are spent here.
    } catch (RuntimeException e) {
      logger.error("Uncaught exception, attempting clean game shutdown", e);
      throw e;
    } finally {
      try {
        cleanup();
      } catch (RuntimeException t) {
        logger.error("Clean game shutdown after an uncaught exception failed", t);
      }
      running = false;
      shutdownRequested = false;
      changeStatus(StandardGameStatus.UNSTARTED);
    }
  }
Exemplo n.º 3
0
  private void initialize() {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    Stopwatch totalInitTime = Stopwatch.createStarted();
    try {
      logger.info("Initializing Terasology...");
      logEnvironmentInfo();

      // TODO: Need to get everything thread safe and get rid of the concept of "GameThread" as much
      // as possible.
      GameThread.setToCurrentThread();

      preInitSubsystems();

      initManagers();

      initSubsystems();

      changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_MANAGEMENT);
      initAssets();

      EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
      rootContext.put(EnvironmentSwitchHandler.class, environmentSwitcher);

      environmentSwitcher.handleSwitchToGameEnvironment(rootContext);

      postInitSubsystems();

      verifyInitialisation();

      /**
       * Prevent objects being put in engine context after init phase. Engine states should
       * use/create a child context.
       */
      CoreRegistry.setContext(null);
    } catch (RuntimeException e) {
      logger.error("Failed to initialise Terasology", e);
      cleanup();
      throw e;
    }

    double seconds = 0.001 * totalInitTime.elapsed(TimeUnit.MILLISECONDS);
    logger.info("Initialization completed in {}sec.", String.format("%.2f", seconds));
  }
Exemplo n.º 4
0
  private void initAssets() {
    DefaultBlockFamilyFactoryRegistry familyFactoryRegistry =
        new DefaultBlockFamilyFactoryRegistry();
    rootContext.put(BlockFamilyFactoryRegistry.class, familyFactoryRegistry);

    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.registerCoreAssetType(
        Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, false, "prefabs");
    assetTypeManager.registerCoreAssetType(
        BlockShape.class, (AssetFactory<BlockShape, BlockShapeData>) BlockShapeImpl::new, "shapes");
    assetTypeManager.registerCoreAssetType(
        BlockSounds.class,
        (AssetFactory<BlockSounds, BlockSoundsData>) BlockSounds::new,
        "blockSounds");
    assetTypeManager.registerCoreAssetType(
        BlockTile.class, (AssetFactory<BlockTile, TileData>) BlockTile::new, "blockTiles");
    assetTypeManager.registerCoreAssetType(
        BlockFamilyDefinition.class,
        (AssetFactory<BlockFamilyDefinition, BlockFamilyDefinitionData>) BlockFamilyDefinition::new,
        "blocks");
    assetTypeManager.registerCoreFormat(
        BlockFamilyDefinition.class,
        new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager(), familyFactoryRegistry));
    assetTypeManager.registerCoreAssetType(
        UISkin.class, (AssetFactory<UISkin, UISkinData>) UISkin::new, "skins");
    assetTypeManager.registerCoreAssetType(
        BehaviorTree.class,
        (AssetFactory<BehaviorTree, BehaviorTreeData>) BehaviorTree::new,
        false,
        "behaviors");
    assetTypeManager.registerCoreAssetType(
        UIElement.class, (AssetFactory<UIElement, UIData>) UIElement::new, "ui");

    for (EngineSubsystem subsystem : allSubsystems) {
      subsystem.registerCoreAssetTypes(assetTypeManager);
    }
  }
Exemplo n.º 5
0
  private void initManagers() {

    changeStatus(TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER);
    ModuleManager moduleManager = new ModuleManagerImpl();
    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(
        TypeSerializationLibrary.class,
        new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary));

    changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_TYPES);
    assetTypeManager = new ModuleAwareAssetTypeManager();
    rootContext.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
    rootContext.put(AssetManager.class, assetTypeManager.getAssetManager());
  }
Exemplo n.º 6
0
 @Override
 public void initialise(GameEngine engine, Context rootContext) {
   rootContext.put(ParameterAdapterManager.class, ParameterAdapterManager.createCore());
 }