mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41: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);
|
||||
}
|
||||
|
||||
void LightSolver::solve(){
|
||||
void LightSolver::solve() {
|
||||
const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
|
|
@ -66,47 +66,48 @@ void LightSolver::solve(){
|
|||
};
|
||||
|
||||
while (!remqueue.empty()){
|
||||
const lightentry entry = remqueue.front();
|
||||
lightentry entry = std::move(remqueue.front());
|
||||
remqueue.pop();
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int imul3 = i*3;
|
||||
int imul3 = i * 3;
|
||||
int x = entry.x+coords[imul3];
|
||||
int y = entry.y+coords[imul3+1];
|
||||
int z = entry.z+coords[imul3+2];
|
||||
|
||||
Chunk* chunk = chunks.getChunkByVoxel(x,y,z);
|
||||
if (chunk) {
|
||||
int lx = x - chunk->x * CHUNK_W;
|
||||
int lz = z - chunk->z * CHUNK_D;
|
||||
chunk->flags.modified = true;
|
||||
if (chunk == nullptr) {
|
||||
continue;
|
||||
}
|
||||
int lx = x - chunk->x * CHUNK_W;
|
||||
int lz = z - chunk->z * CHUNK_D;
|
||||
chunk->flags.modified = true;
|
||||
|
||||
assert(chunk->lightmap != nullptr);
|
||||
auto& lightmap = *chunk->lightmap;
|
||||
assert(chunk->lightmap != nullptr);
|
||||
auto& lightmap = *chunk->lightmap;
|
||||
|
||||
ubyte light = lightmap.get(lx,y,lz, channel);
|
||||
if (light != 0 && light == entry.light-1){
|
||||
voxel* vox = chunks.get(x, y, z);
|
||||
if (vox && vox->id != 0) {
|
||||
const Block* block = blockDefs[vox->id];
|
||||
if (uint8_t emission = block->emission[channel]) {
|
||||
addqueue.push(lightentry {x, y, z, emission});
|
||||
lightmap.set(lx, y, lz, channel, emission);
|
||||
}
|
||||
else lightmap.set(lx, y, lz, channel, 0);
|
||||
ubyte light = lightmap.get(lx,y,lz, channel);
|
||||
if (light != 0 && light == entry.light-1) {
|
||||
voxel* vox = chunks.get(x, y, z);
|
||||
if (vox && vox->id != 0) {
|
||||
const Block* block = blockDefs[vox->id];
|
||||
if (uint8_t emission = block->emission[channel]) {
|
||||
addqueue.push(lightentry {x, y, z, emission});
|
||||
lightmap.set(lx, y, lz, channel, emission);
|
||||
}
|
||||
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()){
|
||||
const lightentry entry = addqueue.front();
|
||||
lightentry entry = std::move(addqueue.front());
|
||||
addqueue.pop();
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
#include "util/array_queue.hpp"
|
||||
|
||||
class Chunks;
|
||||
class ContentIndices;
|
||||
|
|
@ -14,8 +14,8 @@ struct lightentry {
|
|||
};
|
||||
|
||||
class LightSolver {
|
||||
std::queue<lightentry> addqueue;
|
||||
std::queue<lightentry> remqueue;
|
||||
util::array_queue<lightentry> addqueue;
|
||||
util::array_queue<lightentry> remqueue;
|
||||
const Block* const* blockDefs;
|
||||
Chunks& chunks;
|
||||
int channel;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue