mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 05:51:51 +00:00
replace deque with array_queue in LightSolver
This commit is contained in:
parent
99f06c9625
commit
5c64d56766
2 changed files with 28 additions and 27 deletions
|
|
@ -55,7 +55,7 @@ void LightSolver::remove(int x, int y, int z) {
|
||||||
lightmap.set(x-chunk->x*CHUNK_W, y, z-chunk->z*CHUNK_D, channel, 0);
|
lightmap.set(x-chunk->x*CHUNK_W, y, z-chunk->z*CHUNK_D, channel, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightSolver::solve(){
|
void LightSolver::solve() {
|
||||||
const int coords[] = {
|
const int coords[] = {
|
||||||
0, 0, 1,
|
0, 0, 1,
|
||||||
0, 0,-1,
|
0, 0,-1,
|
||||||
|
|
@ -66,47 +66,48 @@ void LightSolver::solve(){
|
||||||
};
|
};
|
||||||
|
|
||||||
while (!remqueue.empty()){
|
while (!remqueue.empty()){
|
||||||
const lightentry entry = remqueue.front();
|
lightentry entry = std::move(remqueue.front());
|
||||||
remqueue.pop();
|
remqueue.pop();
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
int imul3 = i*3;
|
int imul3 = i * 3;
|
||||||
int x = entry.x+coords[imul3];
|
int x = entry.x+coords[imul3];
|
||||||
int y = entry.y+coords[imul3+1];
|
int y = entry.y+coords[imul3+1];
|
||||||
int z = entry.z+coords[imul3+2];
|
int z = entry.z+coords[imul3+2];
|
||||||
|
|
||||||
Chunk* chunk = chunks.getChunkByVoxel(x,y,z);
|
Chunk* chunk = chunks.getChunkByVoxel(x,y,z);
|
||||||
if (chunk) {
|
if (chunk == nullptr) {
|
||||||
int lx = x - chunk->x * CHUNK_W;
|
continue;
|
||||||
int lz = z - chunk->z * CHUNK_D;
|
}
|
||||||
chunk->flags.modified = true;
|
int lx = x - chunk->x * CHUNK_W;
|
||||||
|
int lz = z - chunk->z * CHUNK_D;
|
||||||
|
chunk->flags.modified = true;
|
||||||
|
|
||||||
assert(chunk->lightmap != nullptr);
|
assert(chunk->lightmap != nullptr);
|
||||||
auto& lightmap = *chunk->lightmap;
|
auto& lightmap = *chunk->lightmap;
|
||||||
|
|
||||||
ubyte light = lightmap.get(lx,y,lz, channel);
|
ubyte light = lightmap.get(lx,y,lz, channel);
|
||||||
if (light != 0 && light == entry.light-1){
|
if (light != 0 && light == entry.light-1) {
|
||||||
voxel* vox = chunks.get(x, y, z);
|
voxel* vox = chunks.get(x, y, z);
|
||||||
if (vox && vox->id != 0) {
|
if (vox && vox->id != 0) {
|
||||||
const Block* block = blockDefs[vox->id];
|
const Block* block = blockDefs[vox->id];
|
||||||
if (uint8_t emission = block->emission[channel]) {
|
if (uint8_t emission = block->emission[channel]) {
|
||||||
addqueue.push(lightentry {x, y, z, emission});
|
addqueue.push(lightentry {x, y, z, emission});
|
||||||
lightmap.set(lx, y, lz, channel, emission);
|
lightmap.set(lx, y, lz, channel, emission);
|
||||||
}
|
|
||||||
else lightmap.set(lx, y, lz, channel, 0);
|
|
||||||
}
|
}
|
||||||
else lightmap.set(lx, y, lz, channel, 0);
|
else lightmap.set(lx, y, lz, channel, 0);
|
||||||
remqueue.push(lightentry {x, y, z, light});
|
|
||||||
}
|
|
||||||
else if (light >= entry.light){
|
|
||||||
addqueue.push(lightentry {x, y, z, light});
|
|
||||||
}
|
}
|
||||||
|
else lightmap.set(lx, y, lz, channel, 0);
|
||||||
|
remqueue.push(lightentry {x, y, z, light});
|
||||||
|
}
|
||||||
|
else if (light >= entry.light) {
|
||||||
|
addqueue.push(lightentry {x, y, z, light});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!addqueue.empty()){
|
while (!addqueue.empty()){
|
||||||
const lightentry entry = addqueue.front();
|
lightentry entry = std::move(addqueue.front());
|
||||||
addqueue.pop();
|
addqueue.pop();
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <queue>
|
#include "util/array_queue.hpp"
|
||||||
|
|
||||||
class Chunks;
|
class Chunks;
|
||||||
class ContentIndices;
|
class ContentIndices;
|
||||||
|
|
@ -14,8 +14,8 @@ struct lightentry {
|
||||||
};
|
};
|
||||||
|
|
||||||
class LightSolver {
|
class LightSolver {
|
||||||
std::queue<lightentry> addqueue;
|
util::array_queue<lightentry> addqueue;
|
||||||
std::queue<lightentry> remqueue;
|
util::array_queue<lightentry> remqueue;
|
||||||
const Block* const* blockDefs;
|
const Block* const* blockDefs;
|
||||||
Chunks& chunks;
|
Chunks& chunks;
|
||||||
int channel;
|
int channel;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue