73 lines
2.5 KiB
C++
73 lines
2.5 KiB
C++
#include "surrounding.hpp"
|
|
|
|
#include "../world/Chunk.hpp"
|
|
|
|
using namespace geometry;
|
|
namespace contouring::surrounding {
|
|
bool load(faces &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &chunks) {
|
|
{
|
|
const auto it = chunks.find(chunkPos);
|
|
if (it == chunks.end())
|
|
return false;
|
|
|
|
out[CENTER] = it->second;
|
|
}
|
|
for (size_t i = 0; i < CENTER; i++) {
|
|
const auto it = chunks.find(chunkPos + g_face_offsets[i]);
|
|
if (it == chunks.end())
|
|
return false;
|
|
|
|
out[i] = it->second;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::pair<ushort, ushort> getNeighborIdx(ushort idx, Face face) {
|
|
switch (face) {
|
|
case Face::Forward:
|
|
if (idx % CHUNK_LENGTH >= CHUNK_LENGTH - 1)
|
|
return {static_cast<int>(Face::Forward), idx - (CHUNK_LENGTH - 1)};
|
|
return {CENTER, idx + 1};
|
|
|
|
case Face::Backward:
|
|
if (idx % CHUNK_LENGTH <= 0)
|
|
return {static_cast<int>(Face::Backward), idx + (CHUNK_LENGTH - 1)};
|
|
return {CENTER, idx - 1};
|
|
|
|
case Face::Up:
|
|
if ((idx / CHUNK_LENGTH) % CHUNK_LENGTH >= CHUNK_LENGTH - 1)
|
|
return {static_cast<int>(Face::Up), idx - (CHUNK_LENGTH2 - CHUNK_LENGTH)};
|
|
return {CENTER, idx + CHUNK_LENGTH};
|
|
|
|
case Face::Down:
|
|
if ((idx / CHUNK_LENGTH) % CHUNK_LENGTH <= 0)
|
|
return {static_cast<int>(Face::Down), idx + (CHUNK_LENGTH2 - CHUNK_LENGTH)};
|
|
return {CENTER, idx - CHUNK_LENGTH};
|
|
|
|
case Face::Right:
|
|
if (idx / CHUNK_LENGTH2 >= CHUNK_LENGTH - 1)
|
|
return {static_cast<int>(Face::Right), idx - (CHUNK_SIZE - CHUNK_LENGTH2)};
|
|
return {CENTER, idx + CHUNK_LENGTH2};
|
|
|
|
case Face::Left:
|
|
if (idx / CHUNK_LENGTH2 <= 0)
|
|
return {static_cast<int>(Face::Left), idx + (CHUNK_SIZE - CHUNK_LENGTH2)};
|
|
return {CENTER, idx - CHUNK_LENGTH2};
|
|
|
|
default:
|
|
return {CENTER, idx};
|
|
}
|
|
}
|
|
|
|
bool load(corners &out, const chunk_pos &chunkPos, const robin_hood::unordered_map<chunk_pos, std::shared_ptr<world::Chunk>> &chunks) {
|
|
for (size_t i = 0; i < 8; i++) {
|
|
const auto it = chunks.find(chunkPos + g_corner_offsets[i]);
|
|
if (it == chunks.end())
|
|
return false;
|
|
|
|
out[i] = it->second;
|
|
}
|
|
return true;
|
|
}
|
|
}
|