mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 15:01:49 +00:00
cleanup ChunksRenderer
This commit is contained in:
parent
2a2169cff0
commit
7525e31942
2 changed files with 24 additions and 18 deletions
|
|
@ -125,30 +125,30 @@ std::shared_ptr<VoxelsRenderVolume> ChunksRenderer::prepareVoxelsVolume(
|
||||||
return voxelsBuffer;
|
return voxelsBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChunkMesh* ChunksRenderer::render(
|
void ChunksRenderer::renderBlocking(const std::shared_ptr<Chunk>& chunk) {
|
||||||
const std::shared_ptr<Chunk>& chunk, bool important, bool lowPriority
|
glm::ivec2 key(chunk->x, chunk->z);
|
||||||
|
ChunkMesh mesh {};
|
||||||
|
auto voxelsBuffer = prepareVoxelsVolume(*chunk);
|
||||||
|
mesh = renderer->render(chunk.get(), *voxelsBuffer);
|
||||||
|
meshes[key] = std::move(mesh);
|
||||||
|
chunk->flags.modified = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChunksRenderer::render(
|
||||||
|
const std::shared_ptr<Chunk>& chunk, bool lowPriority
|
||||||
) {
|
) {
|
||||||
glm::ivec2 key(chunk->x, chunk->z);
|
glm::ivec2 key(chunk->x, chunk->z);
|
||||||
if (important) {
|
|
||||||
ChunkMesh mesh {};
|
|
||||||
auto voxelsBuffer = prepareVoxelsVolume(*chunk);
|
|
||||||
mesh = renderer->render(chunk.get(), *voxelsBuffer);
|
|
||||||
meshes[key] = std::move(mesh);
|
|
||||||
chunk->flags.modified = false;
|
|
||||||
return &meshes[key];
|
|
||||||
}
|
|
||||||
if (inwork.find(key) != inwork.end() ||
|
if (inwork.find(key) != inwork.end() ||
|
||||||
((inwork.size() >= threadPool.getWorkersCount() ||
|
((inwork.size() >= threadPool.getWorkersCount() ||
|
||||||
enqueuedInFrame >= MAX_CHUNKS_ENQUEUED_IN_FRAME) &&
|
enqueuedInFrame >= MAX_CHUNKS_ENQUEUED_IN_FRAME) &&
|
||||||
lowPriority)) {
|
lowPriority)) {
|
||||||
return nullptr;
|
return;
|
||||||
}
|
}
|
||||||
chunk->flags.modified = false;
|
chunk->flags.modified = false;
|
||||||
enqueuedInFrame++;
|
enqueuedInFrame++;
|
||||||
auto voxelsBuffer = prepareVoxelsVolume(*chunk);
|
auto voxelsBuffer = prepareVoxelsVolume(*chunk);
|
||||||
threadPool.enqueueJob({chunk, std::move(voxelsBuffer)});
|
threadPool.enqueueJob({chunk, std::move(voxelsBuffer)});
|
||||||
inwork[key] = true;
|
inwork[key] = true;
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChunksRenderer::unload(const Chunk* chunk) {
|
void ChunksRenderer::unload(const Chunk* chunk) {
|
||||||
|
|
@ -195,6 +195,8 @@ void ChunksRenderer::update() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
int loadDistance = settings.chunks.loadDistance.get();
|
||||||
|
|
||||||
const int topN = 10;
|
const int topN = 10;
|
||||||
int top = std::min<int>(meshBuildQueue.size(), topN);
|
int top = std::min<int>(meshBuildQueue.size(), topN);
|
||||||
for (int i = 0; i < top; i++) {
|
for (int i = 0; i < top; i++) {
|
||||||
|
|
@ -214,12 +216,16 @@ void ChunksRenderer::update() {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
bool important = distance < CHUNK_W * 1.5f;
|
bool important = distance < CHUNK_W * 1.5f;
|
||||||
bool lowPriority = distance > CHUNK_W * settings.chunks.loadDistance.get() * 0.5;
|
bool lowPriority = distance > CHUNK_W * loadDistance * 0.5;
|
||||||
|
|
||||||
if (chunk->flags.dirtyHeights) {
|
if (chunk->flags.dirtyHeights) {
|
||||||
chunk->updateHeights();
|
chunk->updateHeights();
|
||||||
}
|
}
|
||||||
render(chunk, important, lowPriority);
|
if (important) {
|
||||||
|
renderBlocking(chunk);
|
||||||
|
} else {
|
||||||
|
render(chunk, lowPriority);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public:
|
||||||
const ContentGfxCache& cache,
|
const ContentGfxCache& cache,
|
||||||
const EngineSettings& settings
|
const EngineSettings& settings
|
||||||
);
|
);
|
||||||
virtual ~ChunksRenderer();
|
~ChunksRenderer();
|
||||||
|
|
||||||
void unload(const Chunk* chunk);
|
void unload(const Chunk* chunk);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
@ -88,7 +88,7 @@ private:
|
||||||
|
|
||||||
std::shared_ptr<VoxelsRenderVolume> prepareVoxelsVolume(const Chunk& chunk);
|
std::shared_ptr<VoxelsRenderVolume> prepareVoxelsVolume(const Chunk& chunk);
|
||||||
|
|
||||||
const ChunkMesh* render(
|
void render(const std::shared_ptr<Chunk>& chunk, bool lowPriority);
|
||||||
const std::shared_ptr<Chunk>& chunk, bool important, bool lowPriority
|
|
||||||
);
|
void renderBlocking(const std::shared_ptr<Chunk>& chunk);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue