Skip to content

Instantly share code, notes, and snippets.

@BalintCsala
Last active July 25, 2020 21:21
Show Gist options
  • Save BalintCsala/80c0c03547c0ea01320bb7d889046814 to your computer and use it in GitHub Desktop.
Save BalintCsala/80c0c03547c0ea01320bb7d889046814 to your computer and use it in GitHub Desktop.
void StructureFeature::createBlueprints(Dimension &dimension, ChunkPos &chunkPos, BiomeSource &biomeSource)
{
std::vector<ChunkPos> chunkPositions;
std::lock_guard<SpinLock> lock1(this->spinLock);
uint chunkX = chunkPos->x - this->bounding_size;
while ((int)chunkX <= chunkPos->x + this->bounding_size)) {
uint chunkY = chunkPos->y - this->bounding_size;
while ((int)chunkY <= chunkPos->y + this->bounding_size) {
ChunkPos newChunkPos((ulong)chunkX,(ulong)chunkY);
if (this->starting_positions.count() == 0) {
this->starting_positions.insert(newChunkPos);
chunkPositions.push_back(newChunkPos);
}
chunkY++;
}
chunkX++;
}
// lock1 dies
if (!chunkPositions.empty()) {
if (*((std::atomic<int> *)this + 0x138)++ == 1) {
std::lock_guard<std::mutex> lock2(this->mutex);
*((std::atomic<bool> *)(this + 0x13c)) = false;
// lock2 dies
}
Level level = dimension->getLevel();
uint seed = level->getSeed();
auto it = chunkPositions.begin();
auto end = chunkPositions.end();
while (it != end) {
ChunkPos chPos = *it;
uint random_seed = chPos->x * this->x_multiplier + chPos->y * this->y_multiplier ^ seed;
Random feature_random(random_seed);
this->addFeature(dimension, feature_random);
++it;
}
if (*((std::atomic<int> *)this + 0x138)-- < 1) {
std::lock_guard<std::mutex> lock3(this->mutex);
*((std::atomic<bool> *)this + 0x13c) = true;
this->condition_variable->notifiy_all();
// lock3 dies
}
}
std::vector<ChunkPos, std::allocator<ChunkPos> >::~vector()(chunkPositions);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment