Skip to content

Commit

Permalink
Sort by distance from region center instead of origin
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Oct 21, 2023
1 parent 4349eb8 commit 2cff885
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public SortedRenderLists build(Vec3d cameraPos) {
for (int i = 0; i < this.lists.size(); i++) {
ChunkRenderList renderList = this.lists.get(i);
RenderRegion region = renderList.getRegion();
double dx = cameraPos.x - region.getOriginX();
double dy = cameraPos.y - region.getOriginY();
double dz = cameraPos.z - region.getOriginZ();
double dx = cameraPos.x - region.getCenterX();
double dy = cameraPos.y - region.getCenterY();
double dz = cameraPos.z - region.getCenterZ();
renderList.setDistanceFromCamera((dx * dx) + (dy * dy) + (dz * dz));
}
this.lists.sort(LIST_DISTANCE_COMPARATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ public int getOriginZ() {
return this.getChunkZ() << 4;
}

public int getCenterX() {
return (this.getChunkX() + REGION_WIDTH / 2) << 4;
}

public int getCenterY() {
return (this.getChunkY() + REGION_HEIGHT / 2) << 4;
}

public int getCenterZ() {
return (this.getChunkZ() + REGION_LENGTH / 2) << 4;
}

public void delete(CommandList commandList) {
for (var storage : this.sectionRenderData.values()) {
storage.delete();
Expand Down

0 comments on commit 2cff885

Please sign in to comment.