Example #1
0
  public void update() {
    super.update();

    boolean enableDebug = Config.getInstance().isDebug();
    debugLine1.setVisible(enableDebug);
    debugLine2.setVisible(enableDebug);
    debugLine3.setVisible(enableDebug);
    debugLine4.setVisible(enableDebug);

    if (enableDebug) {
      CameraTargetSystem cameraTarget = CoreRegistry.get(CameraTargetSystem.class);
      double memoryUsage =
          ((double) Runtime.getRuntime().totalMemory() - (double) Runtime.getRuntime().freeMemory())
              / 1048576.0;
      Timer timer = CoreRegistry.get(Timer.class);
      debugLine1.setText(
          String.format(
              "fps: %.2f, mem usage: %.2f MB, total mem: %.2f, max mem: %.2f",
              timer.getFps(),
              memoryUsage,
              Runtime.getRuntime().totalMemory() / 1048576.0,
              Runtime.getRuntime().maxMemory() / 1048576.0));
      debugLine2.setText(String.format("%s", cameraTarget.toString()));
      debugLine3.setText(String.format("%s", CoreRegistry.get(WorldRenderer.class)));
      debugLine4.setText(
          String.format(
              "total vus: %s | active threads: %s",
              ChunkTessellator.getVertexArrayUpdateCount(),
              CoreRegistry.get(GameEngine.class).getActiveTaskCount()));
    }
  }
Example #2
0
  private void updateHealthBar(int currentHealth, int maxHealth) {
    float healthRatio = (float) currentHealth / maxHealth;

    // Show/Hide hearts relatively to the available health points of the player
    for (int i = 0; i < 10; i++) {

      if (i < healthRatio * 10f) _hearts[i].setVisible(true);
      else _hearts[i].setVisible(false);

      // Show Poisoned Status with Green Hearts:
      PoisonedComponent poisoned =
          CoreRegistry.get(LocalPlayer.class).getEntity().getComponent(PoisonedComponent.class);
      entityManager = CoreRegistry.get(EntityManager.class);
      for (EntityRef entity : entityManager.iteratorEntities(PoisonedComponent.class)) {
        if (poisoned.poisonDuration >= 1) _hearts[i].setTextureOrigin(new Vector2f(106f, 0.0f));
        else _hearts[i].setTextureOrigin(new Vector2f(52f, 0.0f));
      }

      for (EntityRef entity : entityManager.iteratorEntities(CuredComponent.class)) {
        // For fixing the Green > Red hearts when cured:
        CuredComponent cured =
            CoreRegistry.get(LocalPlayer.class).getEntity().getComponent(CuredComponent.class);
        entityManager = CoreRegistry.get(EntityManager.class);
        if (cured.cureDuration >= 1) _hearts[i].setTextureOrigin(new Vector2f(52f, 0.0f));
        else _hearts[i].setTextureOrigin(new Vector2f(52f, 0.0f));
      }
    }
  }
Example #3
0
 /**
  * Ugly way to retrieve a name from a prefab
  *
  * @return a ":" seperated string, with name and flavor text.
  */
 public static String getName() {
   PrefabManager prefMan = CoreRegistry.get(PrefabManager.class);
   Prefab prefab = prefMan.getPrefab("miniion:nameslist");
   EntityRef namelist = CoreRegistry.get(EntityManager.class).create(prefab);
   namelist.hasComponent(namesComponent.class);
   namesComponent namecomp = namelist.getComponent(namesComponent.class);
   Random rand = new Random();
   return namecomp.namelist.get(rand.nextInt(namecomp.namelist.size()));
 }
  @Override
  public void applyParameters(ShaderProgram program) {
    super.applyParameters(program);

    DefaultRenderingProcess.FBO sceneOpaque =
        DefaultRenderingProcess.getInstance().getFBO("sceneOpaque");

    int texId = 0;
    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneOpaque.bindTexture();
    program.setInt("texSceneOpaque", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneOpaque.bindDepthTexture();
    program.setInt("texSceneOpaqueDepth", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneOpaque.bindNormalsTexture();
    program.setInt("texSceneOpaqueNormals", texId++);

    DefaultRenderingProcess.FBO sceneTransparent =
        DefaultRenderingProcess.getInstance().getFBO("sceneTransparent");

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneTransparent.bindTexture();
    program.setInt("texSceneTransparent", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneTransparent.bindDepthTexture();
    program.setInt("texSceneTransparentDepth", texId++);

    GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
    sceneTransparent.bindNormalsTexture();
    program.setInt("texSceneTransparentNormals", texId++);

    if (CoreRegistry.get(Config.class).getRendering().isSsao()) {
      DefaultRenderingProcess.FBO ssao =
          DefaultRenderingProcess.getInstance().getFBO("ssaoBlurred1");
      GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
      ssao.bindTexture();
      program.setInt("texSsao", texId++);
    }

    if (CoreRegistry.get(Config.class).getRendering().isOutline()) {
      DefaultRenderingProcess.FBO sobel = DefaultRenderingProcess.getInstance().getFBO("sobel");
      GL13.glActiveTexture(GL13.GL_TEXTURE0 + texId);
      sobel.bindTexture();
      program.setInt("texEdges", texId++);

      program.setFloat("outlineDepthThreshold", (Float) outlineDepthThreshold.getValue());
      program.setFloat("outlineThickness", (Float) outlineThickness.getValue());
    }

    program.setFloat("shoreStart", (Float) shoreStart.getValue());
    program.setFloat("shoreEnd", (Float) shoreEnd.getValue());
  }
  public void renderTransparent() {

    for (EntityRef entity : entityManager.iteratorEntities(MiniaturizerComponent.class)) {
      MiniaturizerComponent min = entity.getComponent(MiniaturizerComponent.class);

      min.blockGrid.render();

      if (min.chunkMesh == null || min.renderPosition == null) continue;

      glPushMatrix();
      Vector3f cameraPosition =
          CoreRegistry.get(WorldRenderer.class).getActiveCamera().getPosition();
      GL11.glTranslated(
          min.renderPosition.x - cameraPosition.x,
          min.renderPosition.y - cameraPosition.y,
          min.renderPosition.z - cameraPosition.z);

      glScalef(
          MiniaturizerComponent.SCALE, MiniaturizerComponent.SCALE, MiniaturizerComponent.SCALE);
      glRotatef(min.orientation, 0, 1, 0);

      ShaderManager.getInstance().enableShader("chunk");
      ShaderManager.getInstance()
          .getShaderProgram("chunk")
          .setFloat("blockScale", MiniaturizerComponent.SCALE);

      min.chunkMesh.render(ChunkMesh.RENDER_PHASE.OPAQUE);
      min.chunkMesh.render(ChunkMesh.RENDER_PHASE.BILLBOARD_AND_TRANSLUCENT);
      min.chunkMesh.render(ChunkMesh.RENDER_PHASE.WATER_AND_ICE);
      glPopMatrix();
    }
  }
Example #6
0
 /** order the minions by id and return the previous one, or the first if none were active! */
 public static void getPreviousMinion(boolean deleteactive) {
   EntityManager entman = CoreRegistry.get(EntityManager.class);
   List<Integer> sortedlist = new ArrayList<Integer>();
   for (EntityRef minion : entman.iteratorEntities(MinionComponent.class)) {
     if (!minion.getComponent(MinionComponent.class).dying) {
       sortedlist.add(minion.getId());
     }
   }
   if (sortedlist.size() == 0) {
     return;
   } else if (deleteactive && sortedlist.size() == 1) {
     activeminion = null;
     return;
   }
   Collections.sort(sortedlist);
   int index = 0;
   if (activeminion != null) {
     index = sortedlist.indexOf(activeminion.getId());
   }
   if (index == 0) {
     index = sortedlist.size() - 1;
   } else {
     index--;
   }
   index = sortedlist.get(index);
   for (EntityRef minion : entman.iteratorEntities(MinionComponent.class)) {
     if (minion.getId() == index) {
       setActiveMinion(minion);
     }
   }
 }
Example #7
0
 /** creates a zonelist component used to save all zones (persist) */
 private static void createZoneList() {
   zonelist = CoreRegistry.get(EntityManager.class).create();
   ZoneListComponent zonecomp = new ZoneListComponent();
   zonelist.addComponent(zonecomp);
   zonelist.setPersisted(true);
   zonelist.saveComponent(zonecomp);
 }
Example #8
0
  @Override
  public void open() {
    toolbar.setEntity(CoreRegistry.get(LocalPlayer.class).getEntity(), 0, 8);
    layout();

    super.open();
  }
  public void updateChunks() {
    ArrayList<Chunk> chunks = CoreRegistry.get(WorldRenderer.class).getChunksInProximity();
    HashSet<RigidBody> newBodies = new HashSet<RigidBody>();

    for (int i = 0; i < 32 && i < chunks.size(); i++) {
      final Chunk chunk = chunks.get(i);

      if (chunk != null) {
        chunk.updateRigidBody();

        RigidBody c = chunk.getRigidBody();

        if (c != null) {
          newBodies.add(c);

          if (!_chunks.contains(c)) {
            _discreteDynamicsWorld.addRigidBody(c);
          }
        }
      }
    }

    for (RigidBody body : _chunks) {
      if (!newBodies.contains(body)) {
        _discreteDynamicsWorld.removeRigidBody(body);
      }
    }

    _chunks = newBodies;
  }
  void update(
      EntityRef localPlayer,
      float delta,
      EntityRef target,
      Vector3i targetBlockPos,
      Vector3f hitPosition,
      Vector3f hitNormal) {
    boolean posInput = positiveInput.getState() == ButtonState.DOWN;
    boolean negInput = negativeInput.getState() == ButtonState.DOWN;

    float targetValue = 0;
    if (!CoreRegistry.get(GUIManager.class).isConsumingInput()) {
      if (posInput) {
        targetValue += 1.0f;
      }
      if (negInput) {
        targetValue -= 1.0f;
      }
    }

    // TODO: Interpolate, based on some settings (immediate, linear, lerp?)

    float newValue = targetValue;

    if (sendEventMode.shouldSendEvent(value, newValue)) {
      event.prepare(id, newValue, delta);
      event.setTarget(target, targetBlockPos, hitPosition, hitNormal);
      localPlayer.send(event);
      sendEventToSubscribers(delta, target);
    }
    value = newValue;
  }
  public void applyParameters(ShaderProgram program) {
    LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class);

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    glBindTexture(GL11.GL_TEXTURE_2D, terrainTex.getId());

    if (localPlayer != null) program.setInt("carryingTorch", localPlayer.isCarryingTorch() ? 1 : 0);
  }
 public BulletPhysicsRenderer(WorldRenderer parent) {
   _broadphase = new DbvtBroadphase();
   _defaultCollisionConfiguration = new DefaultCollisionConfiguration();
   _dispatcher = new CollisionDispatcher(_defaultCollisionConfiguration);
   _sequentialImpulseConstraintSolver = new SequentialImpulseConstraintSolver();
   _discreteDynamicsWorld =
       new DiscreteDynamicsWorld(
           _dispatcher,
           _broadphase,
           _sequentialImpulseConstraintSolver,
           _defaultCollisionConfiguration);
   _discreteDynamicsWorld.setGravity(new Vector3f(0f, -10f, 0f));
   _parent = parent;
   _blockItemFactory =
       new BlockItemFactory(
           CoreRegistry.get(EntityManager.class), CoreRegistry.get(PrefabManager.class));
   _timer = CoreRegistry.get(Timer.class);
 }
 public void refresh() {
   // container.fillInventoryCells(this);
   uiminionlist.removeAll();
   EntityManager entMan = CoreRegistry.get(EntityManager.class);
   for (EntityRef minion : entMan.iteratorEntities(MinionComponent.class)) {
     UIListItem listitem = new UIListItem(minion.getComponent(MinionComponent.class).name, minion);
     listitem.setTextColor(Color.black);
     listitem.addClickListener(minionistener);
     uiminionlist.addItem(listitem);
   }
 }
Example #14
0
  @ReceiveEvent(components = LocalPlayerComponent.class)
  public void onSelectedItemChanged(ChangedComponentEvent event, EntityRef entity) {
    for (UIItemCell cell : toolbar.getCells()) {
      cell.setSelectionRectangleEnable(false);
    }

    LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class);
    LocalPlayerComponent localPlayerComp =
        localPlayer.getEntity().getComponent(LocalPlayerComponent.class);
    toolbar.getCells().get(localPlayerComp.selectedTool).setSelectionRectangleEnable(true);
  }
    // TODO: This won't work in multiplayer
    public float distanceToPlayer() {
      Transform t = new Transform();
      getMotionState().getWorldTransform(t);
      Matrix4f tMatrix = new Matrix4f();
      t.getMatrix(tMatrix);

      Vector3f blockPlayer = new Vector3f();
      tMatrix.get(blockPlayer);
      blockPlayer.sub(new Vector3f(CoreRegistry.get(LocalPlayer.class).getPosition()));

      return blockPlayer.length();
    }
Example #16
0
  public void update(float delta) {
    for (EntityRef entity :
        entityManager.iteratorEntities(
            SimpleAIComponent.class, CharacterMovementComponent.class, LocationComponent.class)) {
      LocationComponent location = entity.getComponent(LocationComponent.class);
      SimpleAIComponent ai = entity.getComponent(SimpleAIComponent.class);
      CharacterMovementComponent moveComp = entity.getComponent(CharacterMovementComponent.class);

      Vector3f worldPos = location.getWorldPosition();
      moveComp.getDrive().set(0, 0, 0);
      // TODO: shouldn't use local player, need some way to find nearest player
      LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class);
      if (localPlayer != null) {
        Vector3f dist = new Vector3f(worldPos);
        dist.sub(localPlayer.getPosition());
        double distanceToPlayer = dist.lengthSquared();

        if (distanceToPlayer > 6 && distanceToPlayer < 16) {
          // Head to player
          ai.movementTarget.set(localPlayer.getPosition());
          ai.followingPlayer = true;
          entity.saveComponent(ai);
        } else {
          // Random walk
          if (Terasology.getInstance().getTimeInMs() - ai.lastChangeOfDirectionAt > 12000
              || ai.followingPlayer) {
            ai.movementTarget.set(
                worldPos.x + random.randomFloat() * 500,
                worldPos.y,
                worldPos.z + random.randomFloat() * 500);
            ai.lastChangeOfDirectionAt = Terasology.getInstance().getTimeInMs();
            ai.followingPlayer = false;
            entity.saveComponent(ai);
          }
        }

        Vector3f targetDirection = new Vector3f();
        targetDirection.sub(ai.movementTarget, worldPos);
        targetDirection.normalize();
        moveComp.setDrive(targetDirection);

        float yaw = (float) Math.atan2(targetDirection.x, targetDirection.z);
        AxisAngle4f axisAngle = new AxisAngle4f(0, 1, 0, yaw);
        location.getLocalRotation().set(axisAngle);
        entity.saveComponent(moveComp);
        entity.saveComponent(location);
      }
    }
  }
Example #17
0
 @Override
 public void initialise() {
   ModIcons.loadIcons();
   guiManager = CoreRegistry.get(GUIManager.class);
   blockItemFactory = new BlockItemFactory(entityManager);
   // experimental popup menu for the minion command tool
   guiManager.registerWindow("activeminiion", UIActiveMinion.class);
   // ui to create summonable cards
   guiManager.registerWindow("cardbook", UICardBook.class);
   // ui to manage summoned minions, selecting one sets it active!
   guiManager.registerWindow("oreobook", UIScreenBookOreo.class);
   // ui to manage zones
   guiManager.registerWindow("zonebook", UIZoneBook.class);
   createZoneList();
   initRecipes();
 }
  @Override
  public void initialise() {
    this.entityManager = CoreRegistry.get(EntityManager.class);
    for (EntityRef blockComp : entityManager.iteratorEntities(BlockComponent.class)) {
      BlockComponent comp = blockComp.getComponent(BlockComponent.class);
      blockComponentLookup.put(new Vector3i(comp.getPosition()), blockComp);
    }

    for (EntityRef entity : entityManager.iteratorEntities(BlockComponent.class)) {
      BlockComponent blockComp = entity.getComponent(BlockComponent.class);
      if (blockComp.temporary) {
        HealthComponent health = entity.getComponent(HealthComponent.class);
        if (health == null
            || health.currentHealth == health.maxHealth
            || health.currentHealth == 0) {
          entity.destroy();
        }
      }
    }
  }
Example #19
0
 private boolean checkSingleZone() {
   WorldProvider worldprovider = CoreRegistry.get(WorldProvider.class);
   Block block = worldprovider.getBlock(MinionSystem.getNewZone().getStartPosition());
   if (block.getURI().getFamily().matches("minionbench")) {
     MinionSystem.getNewZone().zonetype = ZoneType.Work;
     if (MinionSystem.getWorkZoneList() == null) {
       txtzonename.setText("Workzone0");
     } else {
       txtzonename.setText("Workzone" + MinionSystem.getWorkZoneList().size());
     }
     lblzonetype.setText("ZoneType : Workzone");
     newzonefound = true;
   } else if (block.getURI().getFamily().matches("chest")) {
     MinionSystem.getNewZone().zonetype = ZoneType.Storage;
     if (MinionSystem.getWorkZoneList() == null) {
       txtzonename.setText("Storage0");
     } else {
       txtzonename.setText("Storage" + MinionSystem.getWorkZoneList().size());
     }
     lblzonetype.setText("ZoneType : Storage");
     newzonefound = true;
   }
   return newzonefound;
 }
Example #20
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();
  }
Example #21
0
 @Override
 public void initialise() {
   entityManager = CoreRegistry.get(EntityManager.class);
 }
  private void checkForLootedBlocks() {
    LocalPlayer player = CoreRegistry.get(LocalPlayer.class);

    // to send blocks to minions, some needed classes
    EntityRef playerent = player.getEntity();
    LocalPlayerComponent localPlayerComp = playerent.getComponent(LocalPlayerComponent.class);
    MinionBarComponent inventory = null;
    EntityRef closestminion = null;
    if (localPlayerComp.minionMode) {
      inventory = playerent.getComponent(MinionBarComponent.class);
    }

    for (int i = _blocks.size() - 1; i >= 0; i--) {
      BlockRigidBody b = _blocks.get(i);

      if (b._temporary) continue;

      float closestDist = 99999;
      if (inventory != null) {
        // check for the closest minion
        Iterator<EntityRef> it = inventory.MinionSlots.iterator();
        while (it.hasNext()) {
          EntityRef minion = it.next();
          if (b.distanceToEntity(minion) < closestDist) {
            closestDist = b.distanceToEntity(minion);
            closestminion = minion;
          }
        }
      }

      if (localPlayerComp.minionMode) {
        if (closestDist < 8 && !b._picked) {
          b._picked = true;
        }
      } else {
        closestDist = b.distanceToPlayer();
        // Check if the block is close enough to the player
        if (b.distanceToPlayer() < 8.0f && !b._picked) {
          // Mark it as picked and remove it from the simulation
          b._picked = true;
        }
      }

      // Block was marked as being picked
      if (b._picked && closestDist < 32.0f) {
        // Animate the movement in direction of the player
        if (closestDist > 1.0) {
          Transform t = new Transform();
          b.getMotionState().getWorldTransform(t);

          Matrix4f tMatrix = new Matrix4f();
          t.getMatrix(tMatrix);

          Vector3f blockPlayer = new Vector3f();
          tMatrix.get(blockPlayer);
          if (localPlayerComp.minionMode && closestminion != null) {
            LocationComponent minionloc = closestminion.getComponent(LocationComponent.class);
            if (minionloc != null) blockPlayer.sub(minionloc.getWorldPosition());
            else blockPlayer.sub(new Vector3f());
          } else {
            blockPlayer.sub(new Vector3f(player.getPosition()));
          }
          blockPlayer.normalize();
          blockPlayer.scale(-16000f);

          b.applyCentralImpulse(blockPlayer);
        } else {
          // TODO: Handle full inventories
          // TODO: Loot blocks should be entities
          // Block was looted (and reached the player)
          Block block = BlockManager.getInstance().getBlock(b.getType());
          EntityRef blockItem = _blockItemFactory.newInstance(block.getBlockFamily());

          if (localPlayerComp.minionMode) {
            if (closestminion != null) {
              closestminion.send(new ReceiveItemEvent(blockItem));
            }
          } else {
            playerent.send(new ReceiveItemEvent(blockItem));
          }
          ItemComponent itemComp = blockItem.getComponent(ItemComponent.class);
          if (itemComp != null && !itemComp.container.exists()) {
            blockItem.destroy();
          }
          AudioManager.play(new AssetUri(AssetType.SOUND, "engine:Loot"));

          _blocks.remove(i);
          _discreteDynamicsWorld.removeRigidBody(b);
        }
      }
    }
  }
 public void initialise() {
   entityManager = CoreRegistry.get(EntityManager.class);
   worldRenderer = CoreRegistry.get(WorldRenderer.class);
 }