-
-
Notifications
You must be signed in to change notification settings - Fork 138
Further optimize getBiome #637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HaHaWTH
wants to merge
1
commit into
ver/1.21.11
Choose a base branch
from
opt/get-biome
base: ver/1.21.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,10 @@ Original project: https://github.com/fxmorin/carpet-fixes | |
| Optimized the getBiome call to be 25% - 75% faster | ||
| This is a fully vanilla optimization. | ||
|
|
||
| Co-authored-by: HaHaWTH <[email protected]> | ||
|
|
||
| diff --git a/net/minecraft/world/level/biome/BiomeManager.java b/net/minecraft/world/level/biome/BiomeManager.java | ||
| index 73962e79a0f3d892e3155443a1b84508b0f4042e..a48175a7ebb1788ace46395621ed78d910178a53 100644 | ||
| index 73962e79a0f3d892e3155443a1b84508b0f4042e..93cbe1d76efd97899ea520a92e88b94639824174 100644 | ||
| --- a/net/minecraft/world/level/biome/BiomeManager.java | ||
| +++ b/net/minecraft/world/level/biome/BiomeManager.java | ||
| @@ -14,6 +14,7 @@ public class BiomeManager { | ||
|
|
@@ -21,9 +23,11 @@ index 73962e79a0f3d892e3155443a1b84508b0f4042e..a48175a7ebb1788ace46395621ed78d9 | |
|
|
||
| public BiomeManager(BiomeManager.NoiseBiomeSource noiseBiomeSource, long biomeZoomSeed) { | ||
| this.noiseBiomeSource = noiseBiomeSource; | ||
| @@ -29,39 +30,67 @@ public class BiomeManager { | ||
| @@ -28,40 +29,73 @@ public class BiomeManager { | ||
| return new BiomeManager(newSource, this.biomeZoomSeed); | ||
| } | ||
|
|
||
| + private static final double[] QUART_OFFSETS = new double[]{0.0, 0.25, 0.5, 0.75}; // Leaf - Optimized getBiome method - eliminate divisions | ||
| public Holder<Biome> getBiome(BlockPos pos) { | ||
| - int i = pos.getX() - 2; | ||
| - int i1 = pos.getY() - 2; | ||
|
|
@@ -43,9 +47,13 @@ index 73962e79a0f3d892e3155443a1b84508b0f4042e..a48175a7ebb1788ace46395621ed78d9 | |
| + int x = xMinus2 >> 2; // BlockPos to BiomePos | ||
| + int y = yMinus2 >> 2; | ||
| + int z = zMinus2 >> 2; | ||
| + double quartX = (double) (xMinus2 & 3) / 4.0; // quartLocal divided by 4 | ||
| + double quartY = (double) (yMinus2 & 3) / 4.0; // 0/4, 1/4, 2/4, 3/4 | ||
| + double quartZ = (double) (zMinus2 & 3) / 4.0; // [0, 0.25, 0.5, 0.75] | ||
| + // Leaf start - Optimized getBiome method - eliminate divisions | ||
| + // any integer & 3 falls in [0,1,2,3] | ||
| + // then the division by 4 result is deterministic [0, 0.25, 0.5, 0.75] | ||
| + double quartX = QUART_OFFSETS[xMinus2 & 3]; | ||
| + double quartY = QUART_OFFSETS[yMinus2 & 3]; | ||
| + double quartZ = QUART_OFFSETS[zMinus2 & 3]; | ||
| + // Leaf end - Optimized getBiome method - eliminate divisions | ||
| + int smallestX = 0; | ||
| + double smallestDist = Double.POSITIVE_INFINITY; | ||
| + for (int biomeX = 0; biomeX < 8; ++biomeX) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.