A lot of changes in almost all files

This commit is contained in:
MihailRis
2022-02-28 02:30:15 +03:00
committed by GitHub
parent cd3e737385
commit bc9d29cf68
28 changed files with 3485 additions and 476 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
#include <iostream>
#include <assert.h>
#include "LightSolver.h"
#include "Lightmap.h"
@@ -60,7 +61,7 @@ void LightSolver::solve(){
};
while (!remqueue.empty()){
lightentry entry = remqueue.front();
const lightentry entry = remqueue.front();
remqueue.pop();
for (size_t i = 0; i < 6; i++) {
+20 -24
View File
@@ -6,22 +6,15 @@
#include "../voxels/voxel.h"
#include "../voxels/Block.h"
Chunks* Lighting::chunks = nullptr;
LightSolver* Lighting::solverR = nullptr;
LightSolver* Lighting::solverG = nullptr;
LightSolver* Lighting::solverB = nullptr;
LightSolver* Lighting::solverS = nullptr;
int Lighting::initialize(Chunks* chunks){
Lighting::chunks = chunks;
Lighting::Lighting(Chunks* chunks){
this->chunks = chunks;
solverR = new LightSolver(chunks, 0);
solverG = new LightSolver(chunks, 1);
solverB = new LightSolver(chunks, 2);
solverS = new LightSolver(chunks, 3);
return 0;
}
void Lighting::finalize(){
Lighting::~Lighting(){
delete solverR, solverG, solverB, solverS;
}
@@ -37,11 +30,11 @@ void Lighting::clear(){
}
}
void Lighting::onChunkLoaded(int cx, int cy, int cz){
void Lighting::onChunkLoaded(int cx, int cy, int cz, bool sky){
Chunk* chunk = chunks->getChunk(cx, cy, cz);
Chunk* chunkUpper = chunks->getChunk(cx, cy+1, cz);
Chunk* chunkLower = chunks->getChunk(cx, cy-1, cz);
if (chunkLower){
if (chunkLower && sky){
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
int gx = x + cx * CHUNK_W;
@@ -65,7 +58,7 @@ void Lighting::onChunkLoaded(int cx, int cy, int cz){
break;
voxel* vox = &(current->voxels[(y * CHUNK_D + z) * CHUNK_W + x]);//chunks->get(gx,gy+y,gz);
Block* block = Block::blocks[vox->id];
if (!block->lightPassing)
if (!block->skyLightPassing)
break;
//current->lightmap->setS(x,y,z, 0);
current->modified = true;
@@ -76,7 +69,7 @@ void Lighting::onChunkLoaded(int cx, int cy, int cz){
}
}
}
if (chunkUpper){
if (chunkUpper && sky){
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
int gx = x + cx * CHUNK_W;
@@ -99,7 +92,7 @@ void Lighting::onChunkLoaded(int cx, int cy, int cz){
break;
voxel* vox = &(current->voxels[(y * CHUNK_D + z) * CHUNK_W + x]);//chunks->get(gx,gy+y,gz);
Block* block = Block::blocks[vox->id];
if (!block->lightPassing)
if (!block->skyLightPassing)
break;
current->lightmap->setS(x,y,z, 15);
current->modified = true;
@@ -110,7 +103,7 @@ void Lighting::onChunkLoaded(int cx, int cy, int cz){
}
}
}
} else {
} else if (sky){
for (int z = 0; z < CHUNK_D; z++){
for (int x = 0; x < CHUNK_W; x++){
int gx = x + cx * CHUNK_W;
@@ -129,11 +122,11 @@ void Lighting::onChunkLoaded(int cx, int cy, int cz){
break;
voxel* vox = &(current->voxels[(y * CHUNK_D + z) * CHUNK_W + x]);//chunks->get(gx,gy+y,gz);
Block* block = Block::blocks[vox->id];
if (!block->lightPassing)
if (!block->skyLightPassing)
break;
current->lightmap->setS(x,y,z, 15);
current->modified = true;
//solverS->add(gx,y+ncy*CHUNK_H,gz);
solverS->add(gx,y+ncy*CHUNK_H,gz);
}
}
}
@@ -163,10 +156,13 @@ void Lighting::onChunkLoaded(int cx, int cy, int cz){
int gx = x + cx * CHUNK_W;
int gy = y + cy * CHUNK_H;
int gz = z + cz * CHUNK_D;
solverR->add(gx,gy,gz);
solverG->add(gx,gy,gz);
solverB->add(gx,gy,gz);
solverS->add(gx,gy,gz);
if (chunks->getLight(x,y,z)){
solverR->add(gx,gy,gz);
solverG->add(gx,gy,gz);
solverB->add(gx,gy,gz);
if (sky)
solverS->add(gx,gy,gz);
}
}
}
}
@@ -199,7 +195,7 @@ void Lighting::onBlockSet(int x, int y, int z, int id){
if (chunks->getLight(x,y+1,z, 3) == 0xF){
for (int i = y; i >= 0; i--){
voxel* vox = chunks->get(x,i,z);
if (vox == nullptr || vox->id != 0)
if (vox == nullptr || vox->id != 0 && Block::blocks[id]->skyLightPassing)
break;
solverS->add(x,i,z, 0xF);
}
@@ -220,7 +216,7 @@ void Lighting::onBlockSet(int x, int y, int z, int id){
solverR->remove(x,y,z);
solverG->remove(x,y,z);
solverB->remove(x,y,z);
if (!block->lightPassing){
if (!block->skyLightPassing){
solverS->remove(x,y,z);
for (int i = y-1; i >= 0; i--){
solverS->remove(x,i,z);
+10 -10
View File
@@ -5,18 +5,18 @@ class Chunks;
class LightSolver;
class Lighting {
static Chunks* chunks;
static LightSolver* solverR;
static LightSolver* solverG;
static LightSolver* solverB;
static LightSolver* solverS;
Chunks* chunks = nullptr;
LightSolver* solverR = nullptr;
LightSolver* solverG = nullptr;
LightSolver* solverB = nullptr;
LightSolver* solverS = nullptr;
public:
static int initialize(Chunks* chunks);
static void finalize();
Lighting(Chunks* chunks);
~Lighting();
static void clear();
static void onChunkLoaded(int cx, int cy, int cz);
static void onBlockSet(int x, int y, int z, int id);
void clear();
void onChunkLoaded(int cx, int cy, int cz, bool sky);
void onBlockSet(int x, int y, int z, int id);
};
#endif /* LIGHTING_LIGHTING_H_ */
+6
View File
@@ -10,3 +10,9 @@ Lightmap::Lightmap(){
Lightmap::~Lightmap(){
delete[] map;
}
void Lightmap::set(const Lightmap* lightmap) {
for (unsigned int i = 0; i < CHUNK_VOL; i++){
map[i] = lightmap->map[i];
}
}
+6
View File
@@ -9,6 +9,12 @@ public:
Lightmap();
~Lightmap();
void set(const Lightmap* lightmap);
inline unsigned short get(int x, int y, int z){
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x]);
}
inline unsigned char get(int x, int y, int z, int channel){
return (map[y*CHUNK_D*CHUNK_W+z*CHUNK_W+x] >> (channel << 2)) & 0xF;
}