Skip to content
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

Short circuit chasm noise checks to reduce redundant noise computation. #413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qf200011
Copy link

@qf200011 qf200011 commented Jul 7, 2024

The chasm exporter determines if a block is considered a chasm by performing 3 perlin noise checks and taking the minimum of the three:

final double cavernLikelyhood = Math.min(perlinNoise3.getPerlinNoise(px, py, pz) - bias, Math.min(Math.sin(perlinNoise.getPerlinNoise(px, py, pz) * 25), Math.cos(perlinNoise2.getPerlinNoise(px, py, pz) * 25)) / 2) + 0.5f; // [3] tunnellike

This is done a second time but with a different seed and therefore different perlin noise objects:

final double cavernLikelyhood2 = Math.min(perlinNoise6.getPerlinNoise(px, py, pz) - bias, Math.min(Math.sin(perlinNoise4.getPerlinNoise(px, py, pz) * 25), Math.cos(perlinNoise5.getPerlinNoise(px, py, pz) * 25)) / 2) + 0.5f; // [3] tunnellike

These are eventually used to determine if the point is considered a chasm

processBlock(chunk, x, y, z, (cavernLikelyhood > CHASM_CHANCE) || (cavernLikelyhood2 > CHASM_CHANCE));

What this functionality is effectively doing is checking if all the perlin noises succeed the check against chasm_chance. The problem is that if one of perlin noise checks fails, we still check the other two. Additionally, if the first group of three succeeds, we still check the other group of three regardless.

This is largely an issue since getting perlin noise is very expensive. By making the change to short circuit the individual conditions, I saw the chasm layer CPU time drop by 70% and significantly speed up the export process as a whole.

This change affects both the carve and decorate action but they are largely the same change.This is largely an issue since getting perlin noise is very expensive. By making the change to short circuit the individual conditions, I saw the chasm layer CPU time drop by 70% and significantly speed up the export process as a whole.

This change affects both the carve and decorate action but they are largely the same change. This change affects both the carve and decorate action but they are largely the same change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant