/** {@inheritDoc} */
 public TFloatList inverseGrep(TFloatProcedure condition) {
   TFloatList ret = new TFloatLinkedList();
   for (TFloatLink l = head; got(l); l = l.getNext()) {
     if (!condition.execute(l.getValue())) ret.add(l.getValue());
   }
   return ret;
 }
 public TFloatLinkedList(TFloatList list) {
   no_entry_value = list.getNoEntryValue();
   //
   for (TFloatIterator iterator = list.iterator(); iterator.hasNext(); ) {
     float next = iterator.next();
     add(next);
   }
 }
  /** {@inheritDoc} */
  @Override
  public boolean equals(Object other) {
    if (other == this) {
      return true;
    }
    if (!(other instanceof TFloatList)) return false;

    TFloatList that = (TFloatList) other;
    if (size() != that.size()) return false;

    for (int i = 0; i < size(); i++) {
      if (get(i) != that.get(i)) {
        return false;
      }
    }
    return true;
  }
예제 #4
0
파일: Text.java 프로젝트: lmaky/lwjgl-game
  @Override
  public void init() {
    int len = text.length();

    TFloatList verticles = new TFloatArrayList(12 * len);
    TFloatList textCoords = new TFloatArrayList(8 * len);
    TIntList indices = new TIntArrayList(6 * len);

    float textureWidth = gameFont.getFontTextureWidth();
    float position = 0.0f;

    for (int i = 0; i < len; i++) {
      Glyph glyph = gameFont.getGlyphs().get(text.charAt(i));

      add(verticles, position, 0.0f, 0.0f);
      add(verticles, position, glyph.getHeight(), 0.0f);
      add(verticles, glyph.getWidth() + position, glyph.getHeight(), 0.0f);
      add(verticles, glyph.getWidth() + position, 0.0f, 0.0f);

      position += glyph.getWidth();

      float textCoordX1 = glyph.getX() / textureWidth;
      float textCoordX2 = (glyph.getX() + glyph.getWidth()) / textureWidth;

      add(textCoords, textCoordX1, 0.0f);
      add(textCoords, textCoordX1, 1.0f);
      add(textCoords, textCoordX2, 1.0f);
      add(textCoords, textCoordX2, 0.0f);

      int firstIndice = i * 4;
      indices.add(firstIndice + 0);
      indices.add(firstIndice + 1);
      indices.add(firstIndice + 3);
      indices.add(firstIndice + 3);
      indices.add(firstIndice + 1);
      indices.add(firstIndice + 2);
    }
    mesh = new Mesh(verticles.toArray(), textCoords.toArray(), indices.toArray());
    mesh.setTextureId(gameFont.getFontTextureId());
  }
  private int calculateTotal(int base, TFloatList multipliers, TIntList modifiers) {
    // For now, add all modifiers and multiply by all multipliers. Negative modifiers cap to zero,
    // but negative
    // multipliers remain (so damage can be flipped to healing)

    float total = base;
    TIntIterator modifierIter = modifiers.iterator();
    while (modifierIter.hasNext()) {
      total += modifierIter.next();
    }
    total = Math.max(0, total);
    if (total == 0) {
      return 0;
    }
    TFloatIterator multiplierIter = multipliers.iterator();
    while (multiplierIter.hasNext()) {
      total *= multiplierIter.next();
    }
    return TeraMath.floorToInt(total);
  }
예제 #6
0
 /**
  * Loads a .obj file, storing the data in the provided lists. After loading, the input stream will
  * be closed.The number of components for each attribute is returned in a Vector3, x being the
  * number of position components, y the number of texture coord components and z the number of
  * normal components. Note that normal and/or texture coord attributes might be missing from the
  * .obj file. If this is the case, their lists will be empty. The indices are stored in the
  * indices list.
  *
  * @param stream The input stream for the .obj file
  * @param positions The list in which to store the positions
  * @param textureCoords The list in which to store the texture coords
  * @param normals The list in which to store the normals
  * @param indices The list in which to store the indices
  * @return A Vector3 containing, in order, the number of components for the positions, texture
  *     coords and normals
  * @throws MalformedObjFileException If any errors occur during loading
  */
 public static Vector3f load(
     InputStream stream,
     TFloatList positions,
     TFloatList textureCoords,
     TFloatList normals,
     TIntList indices) {
   int positionSize = -1;
   final TFloatList rawTextureCoords = new TFloatArrayList();
   int textureCoordSize = -1;
   final TFloatList rawNormalComponents = new TFloatArrayList();
   int normalSize = -1;
   final TIntList textureCoordIndices = new TIntArrayList();
   final TIntList normalIndices = new TIntArrayList();
   String line = null;
   try (Scanner scanner = new Scanner(stream)) {
     while (scanner.hasNextLine()) {
       line = scanner.nextLine();
       if (line.startsWith(POSITION_LIST_PREFIX + COMPONENT_SEPARATOR)) {
         parseComponents(positions, line);
         if (positionSize == -1) {
           positionSize = positions.size();
         }
       } else if (line.startsWith(TEXTURE_LIST_PREFIX + COMPONENT_SEPARATOR)) {
         parseComponents(rawTextureCoords, line);
         if (textureCoordSize == -1) {
           textureCoordSize = rawTextureCoords.size();
         }
       } else if (line.startsWith(NORMAL_LIST_PREFIX + COMPONENT_SEPARATOR)) {
         parseComponents(rawNormalComponents, line);
         if (normalSize == -1) {
           normalSize = rawNormalComponents.size();
         }
       } else if (line.startsWith(INDEX_LIST_PREFIX + COMPONENT_SEPARATOR)) {
         parseIndices(indices, textureCoordIndices, normalIndices, line);
       }
     }
     line = null;
     final boolean hasTextureCoords;
     final boolean hasNormals;
     if (!textureCoordIndices.isEmpty() && !rawTextureCoords.isEmpty()) {
       textureCoords.fill(0, positions.size() / positionSize * textureCoordSize, 0);
       hasTextureCoords = true;
     } else {
       hasTextureCoords = false;
     }
     if (!normalIndices.isEmpty() && !rawNormalComponents.isEmpty()) {
       normals.fill(0, positions.size() / positionSize * normalSize, 0);
       hasNormals = true;
     } else {
       hasNormals = false;
     }
     if (hasTextureCoords) {
       for (int i = 0; i < textureCoordIndices.size(); i++) {
         final int textureCoordIndex = textureCoordIndices.get(i) * textureCoordSize;
         final int positionIndex = indices.get(i) * textureCoordSize;
         for (int ii = 0; ii < textureCoordSize; ii++) {
           textureCoords.set(positionIndex + ii, rawTextureCoords.get(textureCoordIndex + ii));
         }
       }
     }
     if (hasNormals) {
       for (int i = 0; i < normalIndices.size(); i++) {
         final int normalIndex = normalIndices.get(i) * normalSize;
         final int positionIndex = indices.get(i) * normalSize;
         for (int ii = 0; ii < normalSize; ii++) {
           normals.set(positionIndex + ii, rawNormalComponents.get(normalIndex + ii));
         }
       }
     }
   } catch (Exception ex) {
     throw new MalformedObjFileException(line, ex);
   }
   return new Vector3f(positionSize, textureCoordSize, normalSize).max(0, 0, 0);
 }
예제 #7
0
 private static void parseComponents(TFloatList destination, String line) {
   final String[] components = line.split(COMPONENT_SEPARATOR);
   for (int i = 1; i < components.length; i++) {
     destination.add(Float.parseFloat(components[i]));
   }
 }
예제 #8
0
  public GameMapMesh generateMapMesh(GameMap map) {
    Mesh mesh =
        new Mesh(
            true,
            25 * map.getSize(),
            36 * map.getSize(),
            new VertexAttribute(VertexAttributes.Usage.Position, 3, "a_position"),
            new VertexAttribute(VertexAttributes.Usage.ColorUnpacked, 4, "a_color"),
            new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 3, "a_texcoords"));

    TextureArray textureMap =
        new TextureArray(
            "mp09901.bmp",
            "mp09902.bmp",
            "mp09903.bmp",
            "mp09904.bmp",
            "mp09905.bmp",
            "mp09906.bmp",
            "mp09907.bmp",
            "mp09908.bmp",
            "mp09991.bmp");

    /** Cube vertices */
    short[] indices = {
      0, 2, 1, 0, 3, 2, 4, 5, 6, 4, 6, 7, 8, 9, 10, 8, 10, 11, 12, 15, 14, 12, 14, 13, 16, 17, 18,
      16, 18, 19, 20, 23, 22, 20, 22, 21
    };

    //    F ----- G
    //   /|      /|
    //  E ------H |   ^ Y  Z
    //  | |     | |   |   /
    //  | |B ---|-|C  |  /
    //  |/      |/    | /
    //  A ------D     |------>X

    TFloatList vertList = new TFloatArrayList(9 * 24 * map.getSize());
    TShortList indList = new TShortArrayList(36 * map.getSize());
    int i = 0;
    for (int x = 0; x < map.getWidth(); x++) {
      for (int y = 0; y < map.getLength(); y++) {
        Tile t = map.getTile(x, y);
        if (t == null) continue;
        float size = 0.5f;

        Vector3 pta = new Vector3(x - size, 0, y - size);
        Vector3 ptb = new Vector3(x - size, 0, y + size);
        Vector3 ptc = new Vector3(x + size, 0, y + size);
        Vector3 ptd = new Vector3(x + size, 0, y - size);
        Vector3 pte =
            new Vector3(x - size, 0.1f * t.heightData.get(Tile.Corner.UPPER_SOUTH_WEST), y - size);
        Vector3 ptf =
            new Vector3(x - size, 0.1f * t.heightData.get(Tile.Corner.UPPER_SOUTH_EAST), y + size);
        Vector3 ptg =
            new Vector3(x + size, 0.1f * t.heightData.get(Tile.Corner.UPPER_NORTH_EAST), y + size);
        Vector3 pth =
            new Vector3(x + size, 0.1f * t.heightData.get(Tile.Corner.UPPER_NORTH_WEST), y - size);

        Rect2f[] texReg = new Rect2f[5];
        texReg[0] = getTextureBounds(t.screenData.get(Tile.Screen.UPPER), textureMap);
        texReg[1] = getTextureBounds(t.screenData.get(Tile.Screen.SOUTH), textureMap);
        texReg[2] = getTextureBounds(t.screenData.get(Tile.Screen.NORTH), textureMap);
        texReg[3] = getTextureBounds(t.screenData.get(Tile.Screen.WEST), textureMap);
        texReg[4] = getTextureBounds(t.screenData.get(Tile.Screen.EAST), textureMap);

        int[] texUnits = new int[5];
        texUnits[0] = t.screenData.get(Tile.Screen.UPPER).texUnit;
        texUnits[1] = t.screenData.get(Tile.Screen.SOUTH).texUnit;
        texUnits[2] = t.screenData.get(Tile.Screen.NORTH).texUnit;
        texUnits[3] = t.screenData.get(Tile.Screen.WEST).texUnit;
        texUnits[4] = t.screenData.get(Tile.Screen.EAST).texUnit;

        float[] verts = {
          // bottom (-y)
          pta.x, pta.y, pta.z, 1, 1, 1, 1, 0, 0, 0,
          ptb.x, ptb.y, ptb.z, 1, 1, 1, 1, 0, 0, 0,
          ptc.x, ptc.y, ptc.z, 1, 1, 1, 1, 0, 0, 0,
          ptd.x, ptd.y, ptd.z, 1, 1, 1, 1, 0, 0, 0,

          // top (+y)
          pte.x, pte.y, pte.z, 1, 1, 1, 1, texReg[0].minX(), texReg[0].maxY(), texUnits[0],
          ptf.x, ptf.y, ptf.z, 1, 1, 1, 1, texReg[0].maxX(), texReg[0].maxY(), texUnits[0],
          ptg.x, ptg.y, ptg.z, 1, 1, 1, 1, texReg[0].maxX(), texReg[0].minY(), texUnits[0],
          pth.x, pth.y, pth.z, 1, 1, 1, 1, texReg[0].minX(), texReg[0].minY(), texUnits[0],

          // back (-z) (south)
          pta.x, pta.y, pta.z, 1, 1, 1, 1, texReg[1].maxX(), texReg[1].maxY(), texUnits[1],
          pte.x, pte.y, pte.z, 1, 1, 1, 1, texReg[1].maxX(), texReg[1].minY(), texUnits[1],
          pth.x, pth.y, pth.z, 1, 1, 1, 1, texReg[1].minX(), texReg[1].minY(), texUnits[1],
          ptd.x, ptd.y, ptd.z, 1, 1, 1, 1, texReg[1].minX(), texReg[1].maxY(), texUnits[1],

          // front (+z) (north)
          ptb.x, ptb.y, ptb.z, 1, 1, 1, 1, texReg[2].minX(), texReg[2].maxY(), texUnits[2],
          ptf.x, ptf.y, ptf.z, 1, 1, 1, 1, texReg[2].minX(), texReg[2].minY(), texUnits[2],
          ptg.x, ptg.y, ptg.z, 1, 1, 1, 1, texReg[2].maxX(), texReg[2].minY(), texUnits[2],
          ptc.x, ptc.y, ptc.z, 1, 1, 1, 1, texReg[2].maxX(), texReg[2].maxY(), texUnits[2],

          // left (-x) (west)
          pta.x, pta.y, pta.z, 1, 1, 1, 1, texReg[3].minX(), texReg[3].maxY(), texUnits[3],
          ptb.x, ptb.y, ptb.z, 1, 1, 1, 1, texReg[3].maxX(), texReg[3].maxY(), texUnits[3],
          ptf.x, ptf.y, ptf.z, 1, 1, 1, 1, texReg[3].maxX(), texReg[3].minY(), texUnits[3],
          pte.x, pte.y, pte.z, 1, 1, 1, 1, texReg[3].minX(), texReg[3].minY(), texUnits[3],

          // right (+x) (east)
          ptd.x, ptd.y, ptd.z, 1, 1, 1, 1, texReg[4].maxX(), texReg[4].maxY(), texUnits[4],
          ptc.x, ptc.y, ptc.z, 1, 1, 1, 1, texReg[4].minX(), texReg[4].maxY(), texUnits[4],
          ptg.x, ptg.y, ptg.z, 1, 1, 1, 1, texReg[4].minX(), texReg[4].minY(), texUnits[4],
          pth.x, pth.y, pth.z, 1, 1, 1, 1, texReg[4].maxX(), texReg[4].minY(), texUnits[4],
        };
        vertList.add(verts);
        short[] curIndices = new short[indices.length];
        for (int j = 0; j < indices.length; j++) {
          curIndices[j] = (short) (indices[j] + (24 * i));
        }
        indList.add(curIndices);
        i++;
      }
    }
    mesh.setVertices(vertList.toArray());
    mesh.setIndices(indList.toArray());
    // textureMap.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    mesh.getVertexAttribute(VertexAttributes.Usage.Position).alias = "a_position";
    return new GameMapMesh(mesh, textureMap);
  }
 /** {@inheritDoc} */
 public void sort(int fromIndex, int toIndex) {
   TFloatList tmp = subList(fromIndex, toIndex);
   float[] vals = tmp.toArray();
   Arrays.sort(vals);
   set(fromIndex, vals);
 }