コード例 #1
0
 @Override
 public boolean isInViewVolume(Point playerChunkBase, Point testChunkBase, int viewDistance) {
   if (playerChunkBase == null) {
     return false;
   }
   int distance =
       Math.abs(playerChunkBase.getChunkX() - testChunkBase.getChunkX())
           + Math.abs(playerChunkBase.getChunkZ() - testChunkBase.getChunkZ());
   return distance <= viewDistance;
 }
コード例 #2
0
  private void initChunkRaw(Point p) {
    int x = p.getChunkX();
    int y = p.getChunkY(); // + SEALEVEL_CHUNK;
    int z = p.getChunkZ();

    RepositionManager rm = getRepositionManager();

    int cY = rm.convertChunkY(y);

    if (cY < 0 || cY >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TSyncIntHashSet column = initializedChunks.get(x, z);
    if (column == null) {
      column = new TSyncIntHashSet();
      synchronized (initChunkLock) {
        TSyncIntHashSet oldColumn = initializedChunks.putIfAbsent(x, z, column);
        if (oldColumn != null) {
          column = oldColumn;
        }
      }
    }
    column.add(y);
  }
コード例 #3
0
  @Override
  protected void initChunk(Point p) {

    int x = p.getChunkX();
    int y = p.getChunkY(); // + SEALEVEL_CHUNK;
    int z = p.getChunkZ();

    if (y < 0 || y >= p.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    TSyncIntHashSet column = initializedChunks.get(x, z);
    if (column == null) {
      column = new TSyncIntHashSet();
      synchronized (initChunkLock) {
        TSyncIntHashSet oldColumn = initializedChunks.putIfAbsent(x, z, column);
        if (oldColumn != null) {
          column = oldColumn;
        }
      }
    }
    column.add(y);
  }
コード例 #4
0
ファイル: WorldRenderer.java プロジェクト: MyWifeRules/Spout
  /**
   * Updates the list of chunks around the player.
   *
   * @param force Forces the update
   * @return True if the list was changed
   */
  public boolean updateNearbyChunkMeshes(boolean force) {
    if (world == null) {
      world = client.getDefaultWorld();
      if (world != null)
        System.out.println("World updated to " + world.getName() + "-" + world.getUID());
    }

    if (world == null) {
      try {
        Thread.sleep(5);
      } catch (InterruptedException e) {
      }
      return false;
    }

    int chunkViewDistance = client.getActivePlayer().getViewDistance() / 16;

    Point currentPos = client.getActivePlayer().getTransform().getPosition();

    int currentChunkX = currentPos.getChunkX();
    int currentChunkY = currentPos.getChunkY();
    int currentChunkZ = currentPos.getChunkZ();

    if (currentChunkX == lastChunkX
        && currentChunkY == lastChunkY
        && currentChunkZ == lastChunkZ
        && !force
        && !firstUpdate) {
      return false;
    }
    // just add all visible chunks

    if (chunkRenderers.size() == 0 || force) {
      chunkRenderers.clear();

      int cubeMinX = currentChunkX - chunkViewDistance;
      int cubeMinY = currentChunkY - chunkViewDistance;
      int cubeMinZ = currentChunkZ - chunkViewDistance;

      int cubeMaxX = currentChunkX + chunkViewDistance;
      int cubeMaxY = currentChunkY + chunkViewDistance;
      int cubeMaxZ = currentChunkZ + chunkViewDistance;

      Vector3 batchMin =
          ChunkMeshBatch.getBatchCoordinates(new Vector3(cubeMinX, cubeMinY, cubeMinZ));
      Vector3 batchMax =
          ChunkMeshBatch.getBatchCoordinates(new Vector3(cubeMaxX, cubeMaxY, cubeMaxZ));

      for (int x = batchMin.getFloorX(); x <= batchMax.getFloorX(); x++) {
        for (int y = batchMin.getFloorY(); y <= batchMax.getFloorY(); y++) {
          for (int z = batchMin.getFloorZ(); z <= batchMax.getFloorZ(); z++) {
            Vector3 chunkCoords = ChunkMeshBatch.getChunkCoordinates(new Vector3(x, y, z));
            ChunkMeshBatch batch =
                new ChunkMeshBatch(
                    material,
                    world,
                    chunkCoords.getFloorX(),
                    chunkCoords.getFloorY(),
                    chunkCoords.getFloorZ());
            addChunkMeshBatch(batch);
            batch.update();

            System.out.println(batch);
          }
        }
      }
    } else {
      Cube oldView =
          new Cube(
              new Point(
                  world,
                  lastChunkX - chunkViewDistance,
                  lastChunkY - chunkViewDistance,
                  lastChunkZ - chunkViewDistance),
              chunkViewDistance * 2);
      Cube newView =
          new Cube(
              new Point(
                  world,
                  currentChunkX - chunkViewDistance,
                  currentChunkY - chunkViewDistance,
                  currentChunkZ - chunkViewDistance),
              chunkViewDistance * 2);

      Vector3 min = oldView.getBase().min(newView.getBase());
      Vector3 max =
          oldView.getBase().add(oldView.getSize()).max(newView.getBase().add(newView.getSize()));

      // Shared area
      Vector3 ignoreMin = oldView.getBase().max(newView.getBase());
      Vector3 ignoreMax =
          oldView.getBase().add(oldView.getSize()).min(newView.getBase().add(newView.getSize()));
      Cuboid ignore = new Cuboid(new Point(ignoreMin, world), ignoreMax.subtract(ignoreMin));

      for (int x = min.getFloorX(); x < max.getFloorX(); x++) {
        for (int y = min.getFloorY(); y < max.getFloorY(); y++) {
          for (int z = min.getFloorZ(); z < max.getFloorZ(); z++) {
            Vector3 vec = new Vector3(x, y, z);
            if (ignore.contains(vec)) {
              continue;
            }

            Vector3 pos = ChunkMeshBatch.getChunkCoordinates(vec);

            if (oldView.contains(vec)) {
              ChunkMeshBatch c =
                  chunkRenderersByPosition.get(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
              removeChunkMeshBatch(c);
              continue;
            }

            if (newView.contains(vec)) {
              ChunkMeshBatch c =
                  new ChunkMeshBatch(
                      material, world, pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
              addChunkMeshBatch(c);
              c.update();
            }
          }
        }
      }
    }

    firstUpdate = false;
    lastChunkX = currentChunkX;
    lastChunkY = currentChunkY;
    lastChunkZ = currentChunkZ;

    return true;
  }