1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Refactor "Cavegen y biome check"

This commit is contained in:
sfan5 2024-09-06 11:30:10 +02:00 committed by GitHub
parent 486dc3288d
commit 3af226cb06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 29 additions and 51 deletions

View file

@ -149,47 +149,36 @@ BiomeGenOriginal::BiomeGenOriginal(BiomeManager *biomemgr,
// is disabled.
memset(biomemap, 0, sizeof(biome_t) * m_csize.X * m_csize.Z);
// Calculating the bounding position of each biome so we know when we might switch
// First gathering all heights where we might switch
std::vector<s16> temp_transition_heights;
temp_transition_heights.reserve(m_bmgr->getNumObjects() * 2);
// Calculate cache of Y transition points
std::vector<s16> values;
values.reserve(m_bmgr->getNumObjects() * 2);
for (size_t i = 0; i < m_bmgr->getNumObjects(); i++) {
Biome *b = (Biome *)m_bmgr->getRaw(i);
temp_transition_heights.push_back(b->max_pos.Y);
temp_transition_heights.push_back(b->min_pos.Y);
values.push_back(b->max_pos.Y);
values.push_back(b->min_pos.Y);
}
// Sorting the biome transition points
std::sort(temp_transition_heights.begin(), temp_transition_heights.end(), std::greater<int>());
std::sort(values.begin(), values.end(), std::greater<>());
values.erase(std::unique(values.begin(), values.end()), values.end());
// Getting rid of duplicate biome transition points
s16 last = temp_transition_heights[0];
size_t out_pos = 1;
for (size_t i = 1; i < temp_transition_heights.size(); i++){
if (temp_transition_heights[i] != last) {
last = temp_transition_heights[i];
temp_transition_heights[out_pos++] = last;
}
}
biome_transitions = new s16[out_pos];
memcpy(biome_transitions, temp_transition_heights.data(), sizeof(s16) * out_pos);
m_transitions_y = std::move(values);
}
BiomeGenOriginal::~BiomeGenOriginal()
{
delete []biomemap;
delete []biome_transitions;
delete noise_heat;
delete noise_humidity;
delete noise_heat_blend;
delete noise_humidity_blend;
}
s16* BiomeGenOriginal::getBiomeTransitions() const
s16 BiomeGenOriginal::getNextTransitionY(s16 y) const
{
return biome_transitions;
// Find first value that is less than y using binary search
auto it = std::lower_bound(m_transitions_y.begin(), m_transitions_y.end(), y, std::greater_equal<>());
return (it == m_transitions_y.end()) ? S16_MIN : *it;
}
BiomeGen *BiomeGenOriginal::clone(BiomeManager *biomemgr) const