-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add micro-opimisation for populating biomes in chunk sections
This optimisations swaps the order of the Y and Z axis `fori` loops. This is taken from [Rho](https://github.com/jaskarth/rho/blob/main/src/main/java/supercoder79/rho/mixin/MixinNoiseChunkGenerator.java).
- Loading branch information
1 parent
9233fcf
commit d407c92
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/java/io/github/steveplays28/noisium/mixin/ChunkSectionMixin.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.github.steveplays28.noisium.mixin; | ||
|
||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.source.BiomeSupplier; | ||
import net.minecraft.world.biome.source.util.MultiNoiseUtil; | ||
import net.minecraft.world.chunk.ChunkSection; | ||
import net.minecraft.world.chunk.PalettedContainer; | ||
import net.minecraft.world.chunk.ReadableContainer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
@Mixin(ChunkSection.class) | ||
public class ChunkSectionMixin { | ||
@Unique | ||
private static final int sliceSize = 4; | ||
|
||
@Shadow | ||
private ReadableContainer<RegistryEntry<Biome>> biomeContainer; | ||
|
||
/** | ||
* @author Steveplays28 | ||
* @reason Axis order micro-optimisation | ||
*/ | ||
@Overwrite | ||
public void populateBiomes(BiomeSupplier biomeSupplier, MultiNoiseUtil.MultiNoiseSampler sampler, int x, int y, int z) { | ||
PalettedContainer<RegistryEntry<Biome>> palettedContainer = this.biomeContainer.slice(); | ||
|
||
for (int posX = 0; posX < sliceSize; ++posX) { | ||
for (int posZ = 0; posZ < sliceSize; ++posZ) { | ||
for (int posY = 0; posY < sliceSize; ++posY) { | ||
palettedContainer.swapUnsafe(posX, posY, posZ, biomeSupplier.getBiome(x + posX, y + posY, z + posZ, sampler)); | ||
} | ||
} | ||
} | ||
|
||
this.biomeContainer = palettedContainer; | ||
} | ||
} |
This file contains 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