default load-speed set to 4 + minor refactor

This commit is contained in:
MihailRis 2024-01-24 20:43:52 +03:00
parent 58fbb96f2c
commit 5687e55094
5 changed files with 17 additions and 15 deletions

View File

@ -9,7 +9,6 @@
#include <glm/ext.hpp>
using glm::ivec2;
using std::shared_ptr;
ChunksRenderer::ChunksRenderer(Level* level, const ContentGfxCache* cache, const EngineSettings& settings) : level(level) {
const int MAX_FULL_CUBES = 3000;
@ -20,10 +19,10 @@ ChunksRenderer::~ChunksRenderer() {
delete renderer;
}
shared_ptr<Mesh> ChunksRenderer::render(Chunk* chunk) {
std::shared_ptr<Mesh> ChunksRenderer::render(Chunk* chunk) {
chunk->setModified(false);
Mesh* mesh = renderer->render(chunk, level->chunksStorage);
auto sptr = shared_ptr<Mesh>(mesh);
auto sptr = std::shared_ptr<Mesh>(mesh);
meshes[ivec2(chunk->x, chunk->z)] = sptr;
return sptr;
}
@ -35,7 +34,7 @@ void ChunksRenderer::unload(Chunk* chunk) {
}
}
shared_ptr<Mesh> ChunksRenderer::getOrRender(Chunk* chunk) {
std::shared_ptr<Mesh> ChunksRenderer::getOrRender(Chunk* chunk) {
auto found = meshes.find(ivec2(chunk->x, chunk->z));
if (found != meshes.end() && !chunk->isModified()){
return found->second;
@ -43,7 +42,7 @@ shared_ptr<Mesh> ChunksRenderer::getOrRender(Chunk* chunk) {
return render(chunk);
}
shared_ptr<Mesh> ChunksRenderer::get(Chunk* chunk) {
std::shared_ptr<Mesh> ChunksRenderer::get(Chunk* chunk) {
auto found = meshes.find(ivec2(chunk->x, chunk->z));
if (found != meshes.end()) {
return found->second;

View File

@ -40,18 +40,17 @@ void Lighting::clear(){
}
}
void Lighting::prebuildSkyLight(int cx, int cz){
const Block* const* blockDefs = content->getIndices()->getBlockDefs();
void Lighting::prebuildSkyLight(Chunk* chunk, const ContentIndices* indices){
auto* blockDefs = indices->getBlockDefs();
Chunk* chunk = chunks->getChunk(cx, cz);
int highestPoint = 0;
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
for (int y = CHUNK_H-1;;y--){
if (y < 0)
break;
voxel* vox = &(chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x]);
const Block* block = blockDefs[vox->id];
voxel& vox = chunk->voxels[(y * CHUNK_D + z) * CHUNK_W + x];
const Block* block = blockDefs[vox.id];
if (!block->skyLightPassing) {
if (highestPoint < y)
highestPoint = y;

View File

@ -2,6 +2,8 @@
#define LIGHTING_LIGHTING_H_
class Content;
class ContentIndices;
class Chunk;
class Chunks;
class LightSolver;
@ -17,10 +19,11 @@ public:
~Lighting();
void clear();
void prebuildSkyLight(int cx, int cz);
void buildSkyLight(int cx, int cz);
void onChunkLoaded(int cx, int cz, bool expand);
void onBlockSet(int x, int y, int z, int id);
static void prebuildSkyLight(Chunk* chunk, const ContentIndices* indices);
};
#endif /* LIGHTING_LIGHTING_H_ */

View File

@ -4,6 +4,7 @@
#include <memory>
#include <iostream>
#include "../content/Content.h"
#include "../voxels/Block.h"
#include "../voxels/Chunk.h"
#include "../voxels/Chunks.h"
@ -63,7 +64,7 @@ bool ChunksController::loadVisible(){
int index = z * w + x;
auto chunk = chunks->chunks[index];
if (chunk != nullptr){
if (!chunk->isLighted()) {
if (chunk->isLoaded() && !chunk->isLighted()) {
int surrounding = 0;
for (int oz = -1; oz <= 1; oz++){
for (int ox = -1; ox <= 1; ox++){
@ -112,11 +113,11 @@ bool ChunksController::loadVisible(){
);
chunk->setUnsaved(true);
}
chunk->updateHeights();
if (!chunk->isLoadedLights()) {
lighting->prebuildSkyLight(chunk->x, chunk->z);
Lighting::prebuildSkyLight(chunk.get(), level->content->getIndices());
}
chunk->setLoaded(true);
return true;
}

View File

@ -25,7 +25,7 @@ struct DisplaySettings {
struct ChunksSettings {
/* Max milliseconds that engine uses for chunks loading only */
uint loadSpeed = 10;
uint loadSpeed = 4;
/* Radius of chunks loading zone (chunk is unit) */
uint loadDistance = 22;
/* Buffer zone where chunks are not unloading (chunk is unit)*/