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

perf: improve performance of facet providers #16

Merged
merged 6 commits into from Feb 24, 2021
Merged

Conversation

pollend
Copy link
Member

@pollend pollend commented Feb 7, 2021

here are some minor improvements to improve cave generation. A Hashset does not seem ideal in this case especially when we can take advantage of locality. Math.hypot seems really expensive what I was looking at and reduced some of GC for that hashset that was used.


for (Vector3ic pos : facet.getWorldRegion()) {
float depth = elevationFacet.getWorld(pos.x(), pos.z()) - pos.y();
float frequencyReduction = (float) Math.max(0, 0.3 - Math.max(depth, 0) / 400); //0: no reduction, 0.7: pretty much no caves. Also somewhat increases the tendency of caves to loop rather than continuing indefinitely.
int i = facet.getWorldIndex(pos);
float noiseValue = (float) Math.hypot(caveNoiseValues[0][i], caveNoiseValues[1][i]+frequencyReduction);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is significantly slower.

@pollend pollend changed the title perf: improve perforace of caveFact and CaveSurfaceFacet Providers perf: improve performance of caveFact and CaveSurfaceFacet Providers Feb 23, 2021
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
Vector3i belowPos = new Vector3i(pos.x + x, pos.y - 1, pos.z + z);
Vector3i belowPos = new Vector3i(pos.x() + x, pos.y() - 1, pos.z() + z);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could reuse a tmp vector here if I see it correctly

@skaldarnar skaldarnar changed the title perf: improve performance of caveFact and CaveSurfaceFacet Providers perf: improve performance of facet providers Feb 24, 2021
@skaldarnar skaldarnar merged commit 86df543 into develop Feb 24, 2021
@skaldarnar skaldarnar deleted the perf/generation branch February 24, 2021 13:53
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.

None yet

3 participants