Ejemplo n.º 1
0
 public void render2d(GL2 g) {
   for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
     EntityData key = e.getKey();
     TileEntity entity = e.getValue();
     g.glPushMatrix();
     switch (key.getType()) {
       case VBORDER:
         g.glRotatef(90, 0, 0, 1);
         BorderData vBorder = (BorderData) entity;
         if (Globals.upCamera) {
           vBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
       case HBORDER:
         BorderData hBorder = (BorderData) entity;
         if (Globals.upCamera) {
           hBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
     }
     g.glPopMatrix();
     g.glColor3f(1, 1, 1);
   }
 }
Ejemplo n.º 2
0
  public boolean setDataProperty(EntityData data) {
    if (!Objects.equals(data, this.getDataProperties().get(data.getId()))) {
      this.getDataProperties().put(data);

      this.sendData(
          this.hasSpawned.values().stream().toArray(Player[]::new),
          new EntityMetadata().put(this.dataProperties.get(data.getId())));

      return true;
    }

    return false;
  }
Ejemplo n.º 3
0
  private void readSubEntities() throws IOException {
    entityData.subEntities = new SubEntityData[header.num_meshes];

    for (int i = 0; i < header.num_meshes; ++i) {
      // create all subentities

      SubEntityData subEntity = new SubEntityData();
      byte[] buffer = new byte[SUBENTITY_SIZE];
      readBytes += in.read(buffer);

      int pos = 0;
      pos++;
      pos++;
      int firstVertex = toInt(buffer, (pos++) * 4);
      int numVertices = toInt(buffer, (pos++) * 4);
      int firstTriangle = toInt(buffer, (pos++) * 4);
      int numTriangles = toInt(buffer, (pos++) * 4);

      subEntity.name = texts.get(textPos++);
      subEntity.material = texts.get(textPos++);
      subEntity.firstTriangleIndex = firstTriangle;
      subEntity.firstVertexIndex = firstVertex;
      subEntity.countTriangles = numTriangles;
      subEntity.countVertices = numVertices;

      subEntity.vertexData = new float[numVertices * vertexLayout.getByteStride()];
      subEntity.triangleData = new short[numTriangles * 3];
      subEntity.boneData = new float[numVertices * Mesh.BONE_BYTE_STRIDE];

      entityData.subEntities[i] = subEntity;
    }
  }
Ejemplo n.º 4
0
  private void readSkeleton() throws IOException {
    entityData.skeletonData = new SkeletonData();

    if (header.ofs_joints == readBytes) {
      byte[] buffer = new byte[JOINT_SIZE * header.num_joints];
      readBytes += in.read(buffer);

      int pos = 0;

      for (int i = 0; i < header.num_joints; ++i) {

        BoneData bone = new BoneData();
        entityData.skeletonData.bones.add(bone);

        pos++;
        bone.name = texts.get(textPos++);
        bone.parentIndex = toInt(buffer, (pos++) * 4);

        bone.pos = new Vector3();
        bone.pos.x = toFloat(buffer, (pos++) * 4);
        bone.pos.y = toFloat(buffer, (pos++) * 4);
        bone.pos.z = toFloat(buffer, (pos++) * 4);

        bone.rot = new Quaternion();
        bone.rot.x = toFloat(buffer, (pos++) * 4);
        bone.rot.y = toFloat(buffer, (pos++) * 4);
        bone.rot.z = toFloat(buffer, (pos++) * 4);
        bone.rot.w = toFloat(buffer, (pos++) * 4);

        pos += 3; // Scale info not supported yet
      }
    }

    if (header.ofs_poses == readBytes) {
      // Dont know why the f**k I would need these...
      byte[] buffer = new byte[POSE_SIZE * header.num_poses];
      readBytes += in.read(buffer);

      int pos = 0;

      entityData.skeletonData.poses = new PoseData[header.num_poses];

      for (int i = 0; i < header.num_poses; ++i) {
        PoseData pose = new PoseData();
        entityData.skeletonData.poses[i] = pose;

        pose.parent = toInt(buffer, (pos++) * 4);
        pose.channelmask = toInt(buffer, (pos++) * 4);
        for (int j = 0; j < 10; ++j) {
          pose.channeloffset[j] = toFloat(buffer, (pos++) * 4);
        }
        for (int j = 0; j < 10; ++j) {
          pose.channelscale[j] = toFloat(buffer, (pos++) * 4);
        }
      }
    }
  }
Ejemplo n.º 5
0
  public static byte[] writeMetadata(Map<Integer, EntityData> data) {
    BinaryStream stream = new BinaryStream();
    for (int bottom : data.keySet()) {
      EntityData d = data.get(bottom);
      stream.putByte((byte) (((d.getType() << 5) | (bottom & 0x1F)) & 0xff));
      switch (d.getType()) {
        case Entity.DATA_TYPE_BYTE:
          stream.putByte(((ByteEntityData) d).getData());
          break;
        case Entity.DATA_TYPE_SHORT:
          stream.putLShort(((ShortEntityData) d).getData());
          break;
        case Entity.DATA_TYPE_INT:
          stream.putLInt(((IntEntityData) d).getData());
          break;
        case Entity.DATA_TYPE_FLOAT:
          stream.putLFloat(((FloatEntityData) d).getData());
          break;
        case Entity.DATA_TYPE_STRING:
          String s = ((StringEntityData) d).getData();
          stream.putLShort(s.getBytes(StandardCharsets.UTF_8).length);
          stream.put(s.getBytes(StandardCharsets.UTF_8));
          break;
        case Entity.DATA_TYPE_SLOT:
          SlotEntityData slot = (SlotEntityData) d;
          stream.putLShort(slot.id);
          stream.putByte(slot.meta);
          stream.putLShort(slot.count);
          break;
        case Entity.DATA_TYPE_POS:
          PositionEntityData pos = (PositionEntityData) d;
          stream.putLInt(pos.x);
          stream.putLInt(pos.y);
          stream.putLInt(pos.z);
          break;
        case Entity.DATA_TYPE_LONG:
          stream.putLLong(((LongEntityData) d).getData());
          break;
      }
    }

    stream.putByte((byte) 0x7f);
    return stream.getBuffer();
  }
 public void setAlterNode(EntityData graphDataNode) {
   //        if (graphDataNode != null) { // if the nodes has been reloaded then it must always be
   // updated here
   // todo: it might be better to use a hashmap of all current nodes
   alterNode = graphDataNode;
   if (alterUniqueIdentifier == null) {
     alterUniqueIdentifier = alterNode.getUniqueIdentifier();
   }
   //        }
 }
Ejemplo n.º 7
0
 @Override
 public void loadTo(SpriteEntity sprite) {
   super.loadTo(sprite);
   sprite.setPosition(x, y);
   sprite.setSize(width, height);
   sprite.setOrigin(originX, originY);
   sprite.setRotation(rotation);
   sprite.setScale(scaleX, scaleY);
   sprite.setColor(tint);
   sprite.setFlip(flipX, flipY);
 }
Ejemplo n.º 8
0
  @Override
  public void saveFrom(SpriteEntity sprite, VisAssetDescriptor assetDescriptor) {
    super.saveFrom(sprite, assetDescriptor);
    x = sprite.getX();
    y = sprite.getY();

    width = sprite.getWidth();
    height = sprite.getHeight();

    originX = sprite.getOriginX();
    originY = sprite.getOriginY();

    rotation = sprite.getRotation();

    scaleX = sprite.getScaleX();
    scaleY = sprite.getScaleY();

    tint = sprite.getColor().cpy();

    flipX = sprite.isFlipX();
    flipY = sprite.isFlipY();
  }
Ejemplo n.º 9
0
  public void serialize(Document doc, Element root) {
    Element tile = doc.createElement("tile");
    tile.setAttribute("x", Integer.toString(x));
    tile.setAttribute("y", Integer.toString(y));
    tile.setAttribute("height", Float.toString(height));
    tile.setAttribute("caveHeight", Float.toString(caveHeight));
    tile.setAttribute("caveSize", Float.toString(caveSize));
    root.appendChild(tile);

    ground.serialize(doc, tile);
    cave.serialize(doc, tile);
    if (label != null) {
      label.serialize(doc, tile, false);
    }
    if (caveLabel != null) {
      caveLabel.serialize(doc, tile, true);
    }

    final HashMap<Integer, Element> levels = new HashMap<>();

    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      final EntityData key = e.getKey();
      final TileEntity entity = e.getValue();
      final int floor = key.getFloor();

      Element level = levels.get(floor);
      if (level == null) {
        level = doc.createElement("level");
        level.setAttribute("value", Integer.toString(key.getFloor()));
        levels.put(key.getFloor(), level);
        tile.appendChild(level);
      }

      switch (key.getType()) {
        case FLOORROOF:
          entity.serialize(doc, level);
          break;
        case HWALL:
        case HFENCE:
          Element hWall = doc.createElement("hWall");
          entity.serialize(doc, hWall);
          level.appendChild(hWall);
          break;
        case VWALL:
        case VFENCE:
          Element vWall = doc.createElement("vWall");
          entity.serialize(doc, vWall);
          level.appendChild(vWall);
          break;
        case HBORDER:
          Element hDeco = doc.createElement("hBorder");
          entity.serialize(doc, hDeco);
          level.appendChild(hDeco);
          break;
        case VBORDER:
          Element vDeco = doc.createElement("vBorder");
          entity.serialize(doc, vDeco);
          level.appendChild(vDeco);
          break;
        case OBJECT:
          ObjectEntityData objectData = (ObjectEntityData) key;
          Element objectElement = doc.createElement("object");
          objectElement.setAttribute("position", objectData.getLocation().toString());
          entity.serialize(doc, objectElement);
          level.appendChild(objectElement);
          break;
      }
    }
  }
Ejemplo n.º 10
0
  private void renderEntities(GL2 g) {
    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      EntityData key = e.getKey();
      final int floor = key.getFloor();
      float colorMod = 1;
      if (Globals.upCamera) {
        switch (Globals.floor - floor) {
          case 0:
            colorMod = 1;
            break;
          case 1:
            colorMod = 0.6f;
            break;
          case 2:
            colorMod = 0.25f;
            break;
          default:
            continue;
        }
      }
      TileEntity entity = e.getValue();
      g.glPushMatrix();
      switch (key.getType()) {
        case FLOORROOF:
          g.glTranslatef(4, 0, 3 * floor + getFloorHeight() / Constants.HEIGHT_MOD);
          g.glColor3f(colorMod, colorMod, colorMod);
          entity.render(g, this);
          break;
        case VWALL:
        case VFENCE:
          g.glTranslatef(0, 0, 3 * floor + getVerticalWallHeight() / Constants.HEIGHT_MOD);
          g.glRotatef(90, 0, 0, 1);
          float vdiff = getVerticalWallHeightDiff() / 47f;
          if (vdiff < 0) {
            g.glTranslatef(0, 0, -vdiff * 4f);
          }
          deform(g, vdiff);

          Wall vwall = (Wall) entity;
          if (Globals.upCamera) {
            vwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          vwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case HWALL:
        case HFENCE:
          g.glTranslatef(0, 0, 3 * floor + getHorizontalWallHeight() / Constants.HEIGHT_MOD);
          float hdiff = getHorizontalWallHeightDiff() / 47f;
          if (hdiff < 0) {
            g.glTranslatef(0, 0, -hdiff * 4f);
          }
          deform(g, hdiff);
          Wall hwall = (Wall) entity;
          if (Globals.upCamera) {
            hwall.data.color.use(g, colorMod);
          } else {
            g.glColor3f(1, 1, 1);
          }
          hwall.render(g, this);
          g.glColor3f(1, 1, 1);
          break;
        case OBJECT:
          ObjectEntityData objData = (ObjectEntityData) key;
          ObjectLocation loc = objData.getLocation();
          GameObject obj = (GameObject) entity;
          g.glColor3f(colorMod, colorMod, colorMod);
          g.glTranslatef(
              loc.getHorizontalAlign(),
              loc.getVerticalAlign(),
              3 * floor
                  + getHeight(loc.getHorizontalAlign() / 4f, loc.getVerticalAlign() / 4f)
                      / Constants.HEIGHT_MOD);
          obj.render(g, this);
          break;
      }
      g.glPopMatrix();
      g.glColor3f(1, 1, 1);
    }
  }