Example #1
0
  private void initManagers() {

    SplashScreen.getInstance().post("Loading modules ...");
    ModuleManager moduleManager =
        CoreRegistry.putPermanently(ModuleManager.class, new ModuleManagerImpl());

    SplashScreen.getInstance().post("Loading reflections ...");
    ReflectFactory reflectFactory =
        CoreRegistry.putPermanently(ReflectFactory.class, new ReflectionReflectFactory());
    CopyStrategyLibrary copyStrategyLibrary =
        CoreRegistry.putPermanently(
            CopyStrategyLibrary.class, new CopyStrategyLibrary(reflectFactory));

    CoreRegistry.putPermanently(
        TypeSerializationLibrary.class,
        new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary));

    SplashScreen.getInstance().post("Loading assets ...");
    AssetManager assetManager =
        CoreRegistry.putPermanently(
            AssetManager.class, new AssetManagerImpl(moduleManager.getEnvironment()));
    assetManager.setEnvironment(moduleManager.getEnvironment());
    CoreRegistry.putPermanently(CollisionGroupManager.class, new CollisionGroupManager());
    CoreRegistry.putPermanently(WorldGeneratorManager.class, new WorldGeneratorManager());
    CoreRegistry.putPermanently(ComponentSystemManager.class, new ComponentSystemManager());
    CoreRegistry.putPermanently(
        ParameterAdapterManager.class, ParameterAdapterManager.createCore());
    CoreRegistry.putPermanently(NetworkSystem.class, new NetworkSystemImpl(time));
    CoreRegistry.putPermanently(Game.class, new Game(this, time));
    assetManager.setEnvironment(moduleManager.getEnvironment());

    AssetType.registerAssetTypes(assetManager);
    ApplyModulesUtil.applyModules();
  }
  @Override
  protected void setupEmptyAssetManager() {
    ModuleManager moduleManager = CoreRegistry.get(ModuleManager.class);
    AssetManager assetManager = new AssetManager(moduleManager);

    // mock an empy asset factory for all asset types
    for (AssetType type : AssetType.values()) {
      assetManager.setAssetFactory(type, mock(AssetFactory.class));
    }

    CoreRegistry.put(AssetManager.class, assetManager);
  }
  /**
   * Activate all modules. Note: this requires that the {@link ModuleSecurityManager} gives
   * permission to do that
   */
  public void activateAllModules() {
    ModuleManager moduleManager = CoreRegistry.get(ModuleManager.class);
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);

    // activate all modules
    for (Module m : moduleManager.getModules()) {
      moduleManager.enableModule(m);
    }

    moduleManager.applyActiveModules();
    assetManager.clear();
    assetManager.applyOverrides();
  }
Example #4
0
 public <T extends ControlWidget> T addHUDElement(AssetUri uri, Class<T> type, Rect2f region) {
   UIData data = assetManager.loadAssetData(uri, UIData.class);
   if (data != null && type.isInstance(data.getRootWidget())) {
     return addHUDElement(uri, type.cast(data.getRootWidget()), region);
   }
   return null;
 }
  @Override
  protected void setupAssetManager() {
    setupEmptyAssetManager();

    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    AudioManager audioManager = CoreRegistry.get(AudioManager.class);
    AssetType.registerAssetTypes(assetManager);

    CodeSource tsCodeSource = TerasologyEngine.class.getProtectionDomain().getCodeSource();
    assetManager.addAssetSource(
        new ClasspathSource(
            TerasologyConstants.ENGINE_MODULE,
            tsCodeSource,
            TerasologyConstants.ASSETS_SUBDIRECTORY,
            TerasologyConstants.OVERRIDES_SUBDIRECTORY));

    CodeSource thisCodeSource = HeadlessEnvironment.class.getProtectionDomain().getCodeSource();
    assetManager.addAssetSource(
        new ClasspathSource(
            "unittest",
            thisCodeSource,
            TerasologyConstants.ASSETS_SUBDIRECTORY,
            TerasologyConstants.OVERRIDES_SUBDIRECTORY));

    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.SHAPE,
        new AssetFactory<BlockShapeData, BlockShape>() {

          @Override
          public BlockShape buildAsset(AssetUri uri, BlockShapeData data) {
            return new BlockShapeImpl(uri, data);
          }
        });

    assetManager.setAssetFactory(
        AssetType.UI_SKIN,
        new AssetFactory<UISkinData, UISkin>() {
          @Override
          public UISkin buildAsset(AssetUri uri, UISkinData data) {
            return new UISkin(uri, data);
          }
        });

    assetManager.setAssetFactory(AssetType.SOUND, audioManager.getStaticSoundFactory());
    assetManager.setAssetFactory(AssetType.MUSIC, audioManager.getStreamingSoundFactory());
  }
Example #6
0
  public BlockFamily loadWithShape(BlockUri uri) {
    try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(uri.getModuleName())) {
      BlockShape shape = cubeShape;
      if (uri.hasShape()) {
        AssetUri shapeUri = uri.getShapeUri();
        if (!shapeUri.isValid()) {
          return null;
        }
        shape = (BlockShape) Assets.get(shapeUri);
        if (shape == null) {
          return null;
        }
      }
      AssetUri blockDefUri =
          new AssetUri(AssetType.BLOCK_DEFINITION, uri.getModuleName(), uri.getFamilyName());
      BlockDefinition def;
      if (assetManager.getAssetURLs(blockDefUri).isEmpty()) {
        // An auto-block
        def = new BlockDefinition();
      } else {
        def =
            createBlockDefinition(
                inheritData(blockDefUri, readJson(blockDefUri).getAsJsonObject()));
      }

      def.shape = (shape.getURI().toSimpleString());
      if (shape.isCollisionYawSymmetric()) {
        Block block = constructSingleBlock(blockDefUri, def);
        if (block.getDisplayName().isEmpty()) {
          block.setDisplayName(shape.getDisplayName());
        } else if (!shape.getDisplayName().isEmpty()) {
          block.setDisplayName(block.getDisplayName() + " " + shape.getDisplayName());
        }
        return new SymmetricFamily(uri, block, def.categories);
      } else {
        Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
        constructHorizontalBlocks(blockDefUri, def, blockMap);
        for (Block block : blockMap.values()) {
          if (block.getDisplayName().isEmpty()) {
            block.setDisplayName(shape.getDisplayName());
          } else if (!shape.getDisplayName().isEmpty()) {
            block.setDisplayName(block.getDisplayName() + " " + shape.getDisplayName());
          }
        }
        return new HorizontalBlockFamily(uri, blockMap, def.categories);
      }
    } catch (Exception e) {
      logger.error("Error loading block shape {}", uri, e);
    }
    return null;
  }
Example #7
0
 private List<FreeformFamily> loadAutoBlocks() {
   logger.debug("Loading Auto Blocks...");
   List<FreeformFamily> result = Lists.newArrayList();
   for (AssetUri blockTileUri : Assets.list(AssetType.BLOCK_TILE)) {
     if (assetManager
         .getAssetURLs(blockTileUri)
         .get(0)
         .getPath()
         .contains(AUTO_BLOCK_URL_FRAGMENT)) {
       logger.debug("Loading auto block {}", blockTileUri);
       BlockUri uri = new BlockUri(blockTileUri.getModuleName(), blockTileUri.getAssetName());
       result.add(new FreeformFamily(uri));
     }
   }
   return result;
 }
Example #8
0
  private Map<BlockPart, AssetUri> prepareTiles(BlockDefinition blockDef, AssetUri uri) {
    AssetUri tileUri = getDefaultTile(blockDef, uri);

    Map<BlockPart, AssetUri> tileUris = Maps.newEnumMap(BlockPart.class);
    for (BlockPart part : BlockPart.values()) {
      tileUris.put(part, tileUri);
    }

    if (blockDef.tiles != null) {
      for (BlockPart part : BlockPart.values()) {
        String partTile = blockDef.tiles.map.get(part);
        if (partTile != null) {
          tileUri = assetManager.resolve(AssetType.BLOCK_TILE, blockDef.tiles.map.get(part));
          tileUris.put(part, tileUri);
        }
      }
    }
    return tileUris;
  }
Example #9
0
  private void initAssets() {
    AssetManager assetManager = CoreRegistry.get(AssetManager.class);
    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.SHAPE,
        new AssetFactory<BlockShapeData, BlockShape>() {

          @Override
          public BlockShape buildAsset(AssetUri uri, BlockShapeData data) {
            return new BlockShapeImpl(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.UI_SKIN,
        new AssetFactory<UISkinData, UISkin>() {
          @Override
          public UISkin buildAsset(AssetUri uri, UISkinData data) {
            return new UISkin(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.BEHAVIOR,
        new AssetFactory<BehaviorTreeData, BehaviorTree>() {
          @Override
          public BehaviorTree buildAsset(AssetUri uri, BehaviorTreeData data) {
            return new BehaviorTree(uri, data);
          }
        });
    assetManager.setAssetFactory(
        AssetType.UI_ELEMENT,
        new AssetFactory<UIData, UIElement>() {
          @Override
          public UIElement buildAsset(AssetUri uri, UIData data) {
            return new UIElement(uri, data);
          }
        });
  }
Example #10
0
  /** Init. the HUD. */
  public UIScreenHUD() {
    maximize();

    _hearts = new UIImage[10];

    // Create hearts
    for (int i = 0; i < 10; i++) {
      _hearts[i] = new UIImage(AssetManager.loadTexture("engine:icons"));
      _hearts[i].setVisible(true);
      _hearts[i].setTextureSize(new Vector2f(9f, 9f));
      _hearts[i].setTextureOrigin(new Vector2f(52f, 0.0f)); // 106f for poison
      _hearts[i].setSize(new Vector2f(18f, 18f));
      _hearts[i].setVerticalAlign(EVerticalAlign.BOTTOM);
      _hearts[i].setHorizontalAlign(EHorizontalAlign.CENTER);
      _hearts[i].setPosition(new Vector2f(18f * i - 212f, -52f));

      addDisplayElement(_hearts[i]);
    }

    crosshair = new UIImage(AssetManager.loadTexture("engine:gui"));
    crosshair.setTextureSize(new Vector2f(20f, 20f));
    crosshair.setTextureOrigin(new Vector2f(24f, 24f));
    crosshair.setSize(new Vector2f(40f, 40f));
    crosshair.setHorizontalAlign(EHorizontalAlign.CENTER);
    crosshair.setVerticalAlign(EVerticalAlign.CENTER);
    crosshair.setVisible(true);

    debugLine1 = new UIText();
    debugLine1.setPosition(new Vector2f(4, 4));
    debugLine2 = new UIText();
    debugLine2.setPosition(new Vector2f(4, 22));
    debugLine3 = new UIText();
    debugLine3.setPosition(new Vector2f(4, 38));
    debugLine4 = new UIText();
    debugLine4.setPosition(new Vector2f(4, 54));

    toolbar = new UIItemContainer(9);
    toolbar.setVisible(true);
    toolbar.setHorizontalAlign(EHorizontalAlign.CENTER);
    toolbar.setVerticalAlign(EVerticalAlign.BOTTOM);

    minionbar = new UIMinionbar();
    minionbar.setVisible(true);

    messagequeue = new UIMessageQueue();
    messagequeue.setVisible(true);

    buffBar = new UIBuff();
    buffBar.setVisible(true);

    addDisplayElement(crosshair, "crosshair");
    addDisplayElement(debugLine1);
    addDisplayElement(debugLine2);
    addDisplayElement(debugLine3);
    addDisplayElement(debugLine4);

    addDisplayElement(toolbar);
    addDisplayElement(minionbar);
    addDisplayElement(messagequeue);
    addDisplayElement(buffBar);

    CoreRegistry.get(EventSystem.class).registerEventHandler(this);

    update();
    layout();
  }
  @Before
  public void setup() {
    GameThread.setGameThread();
    AssetManager assetManager =
        CoreRegistry.put(
            AssetManager.class,
            new AssetManager(new ModuleManagerImpl(new ModuleSecurityManager())));
    assetManager.setAssetFactory(
        AssetType.PREFAB,
        new AssetFactory<PrefabData, Prefab>() {

          @Override
          public Prefab buildAsset(AssetUri uri, PrefabData data) {
            return new PojoPrefab(uri, data);
          }
        });
    EntitySystemBuilder builder = new EntitySystemBuilder();

    CoreRegistry.put(ComponentSystemManager.class, mock(ComponentSystemManager.class));

    blockManager =
        CoreRegistry.put(
            BlockManager.class,
            new BlockManagerImpl(mock(WorldAtlas.class), new DefaultBlockFamilyFactoryRegistry()));
    NetworkSystem networkSystem = mock(NetworkSystem.class);
    when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
    entityManager = builder.build(moduleManager, networkSystem, new ReflectionReflectFactory());
    worldStub = new WorldProviderCoreStub(BlockManager.getAir());
    worldProvider = new EntityAwareWorldProvider(worldStub, entityManager);

    plainBlock = new Block();
    blockManager.addBlockFamily(
        new SymmetricFamily(new BlockUri("test:plainBlock"), plainBlock), true);

    blockWithString = new Block();
    PrefabData prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent("Test"));
    Assets.generateAsset(
        new AssetUri(AssetType.PREFAB, "test:prefabWithString"), prefabData, Prefab.class);
    blockWithString.setPrefab("test:prefabWithString");
    blockManager.addBlockFamily(
        new SymmetricFamily(new BlockUri("test:blockWithString"), blockWithString), true);

    blockWithDifferentString = new Block();
    prefabData = new PrefabData();
    prefabData.addComponent(new StringComponent("Test2"));
    Assets.generateAsset(
        new AssetUri(AssetType.PREFAB, "test:prefabWithDifferentString"), prefabData, Prefab.class);
    blockWithDifferentString.setPrefab("test:prefabWithDifferentString");
    blockManager.addBlockFamily(
        new SymmetricFamily(
            new BlockUri("test:blockWithDifferentString"), blockWithDifferentString),
        true);

    blockWithRetainedComponent = new Block();
    prefabData = new PrefabData();
    prefabData.addComponent(new RetainedOnBlockChangeComponent(3));
    Assets.generateAsset(
        new AssetUri(AssetType.PREFAB, "test:prefabWithRetainedComponent"),
        prefabData,
        Prefab.class);
    blockWithRetainedComponent.setPrefab("test:prefabWithRetainedComponent");
    blockManager.addBlockFamily(
        new SymmetricFamily(
            new BlockUri("test:blockWithRetainedComponent"), blockWithRetainedComponent),
        true);

    blockInFamilyOne = new Block();
    blockInFamilyOne.setKeepActive(true);
    blockInFamilyOne.setPrefab("test:prefabWithString");
    blockInFamilyTwo = new Block();
    blockInFamilyTwo.setPrefab("test:prefabWithString");
    blockInFamilyTwo.setKeepActive(true);
    blockManager.addBlockFamily(
        new HorizontalBlockFamily(
            new BlockUri("test:blockFamily"),
            ImmutableMap.<Side, Block>of(
                Side.FRONT,
                blockInFamilyOne,
                Side.LEFT,
                blockInFamilyTwo,
                Side.RIGHT,
                blockInFamilyTwo,
                Side.BACK,
                blockInFamilyOne),
            Collections.<String>emptyList()),
        true);

    keepActiveBlock = new Block();
    keepActiveBlock.setKeepActive(true);
    keepActiveBlock.setPrefab("test:prefabWithString");
    blockManager.addBlockFamily(
        new SymmetricFamily(new BlockUri("test:keepActiveBlock"), keepActiveBlock), true);

    worldProvider.initialise();
  }