minor optimizations + MAX_WORK_PER_FRAME increased

This commit is contained in:
MihailRis
2024-05-17 21:46:56 +03:00
parent 7957a12b84
commit 064b4516f2
2 changed files with 46 additions and 44 deletions
+3 -3
View File
@@ -19,7 +19,7 @@
#include <memory> #include <memory>
#include <iostream> #include <iostream>
const uint MAX_WORK_PER_FRAME = 64; const uint MAX_WORK_PER_FRAME = 128;
const uint MIN_SURROUNDING = 9; const uint MIN_SURROUNDING = 9;
ChunksController::ChunksController(Level* level, uint padding) ChunksController::ChunksController(Level* level, uint padding)
@@ -59,7 +59,7 @@ bool ChunksController::loadVisible(){
for (uint z = padding; z < d-padding; z++){ for (uint z = padding; z < d-padding; z++){
for (uint x = padding; x < w-padding; x++){ for (uint x = padding; x < w-padding; x++){
int index = z * w + x; int index = z * w + x;
auto chunk = chunks->chunks[index]; auto& chunk = chunks->chunks[index];
if (chunk != nullptr){ if (chunk != nullptr){
if (chunk->isLoaded() && !chunk->isLighted()) { if (chunk->isLoaded() && !chunk->isLighted()) {
if (buildLights(chunk)) { if (buildLights(chunk)) {
@@ -79,7 +79,7 @@ bool ChunksController::loadVisible(){
} }
} }
auto chunk = chunks->chunks[nearZ * w + nearX]; const auto& chunk = chunks->chunks[nearZ * w + nearX];
if (chunk != nullptr) { if (chunk != nullptr) {
return false; return false;
} }
+5 -3
View File
@@ -44,12 +44,14 @@ public:
ubyte getLight(int32_t x, int32_t y, int32_t z, int channel); ubyte getLight(int32_t x, int32_t y, int32_t z, int channel);
void set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states); void set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states);
voxel* rayCast(glm::vec3 start, voxel* rayCast(
glm::vec3 start,
glm::vec3 dir, glm::vec3 dir,
float maxLength, float maxLength,
glm::vec3& end, glm::vec3& end,
glm::ivec3& norm, glm::ivec3& norm,
glm::ivec3& iend); glm::ivec3& iend
);
glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist); glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist);
@@ -68,4 +70,4 @@ public:
void saveAndClear(); void saveAndClear();
}; };
#endif /* VOXELS_CHUNKS_HPP_ */ #endif // VOXELS_CHUNKS_HPP_