mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 03:21:49 +00:00
commit
d23306b078
8 changed files with 75 additions and 71 deletions
|
|
@ -133,6 +133,9 @@ console.add_command(
|
|||
"Fill specified zone with blocks",
|
||||
function(args, kwargs)
|
||||
local name, x1,y1,z1, x2,y2,z2 = unpack(args)
|
||||
x1, x2 = math.min(x1, x2), math.max(x1, x2)
|
||||
y1, y2 = math.min(y1, y2), math.max(y1, y2)
|
||||
z1, z2 = math.min(z1, z2), math.max(z1, z2)
|
||||
local id = block.index(name)
|
||||
for y=y1,y2 do
|
||||
for z=z1,z2 do
|
||||
|
|
|
|||
|
|
@ -261,6 +261,7 @@ void LevelScreen::update(float delta) {
|
|||
const Player& player = playerController->getPlayer();
|
||||
const Camera& camera = *player.currentCamera;
|
||||
decorator->update(paused ? 0.0f : delta, camera, weather);
|
||||
renderer->update(camera, delta * !hud->isPause());
|
||||
}
|
||||
|
||||
void LevelScreen::draw(float delta) {
|
||||
|
|
@ -271,7 +272,6 @@ void LevelScreen::draw(float delta) {
|
|||
if (!hud->isPause()) {
|
||||
scripting::on_entities_render(engine.getTime().getDelta());
|
||||
}
|
||||
renderer->update(camera, delta * !hud->isPause());
|
||||
renderer->renderFrame(ctx, camera, hudVisible, *postProcessing);
|
||||
if (!hud->isPause()) {
|
||||
scripting::on_frontend_render();
|
||||
|
|
|
|||
|
|
@ -271,8 +271,7 @@ void Decorator::updateBlockEmitters(const Camera& camera) {
|
|||
remove = true;
|
||||
}
|
||||
} else {
|
||||
iter = blockEmitters.erase(iter);
|
||||
continue;
|
||||
remove = true;
|
||||
}
|
||||
if (util::distance2(iter->first, glm::ivec3(camera.position)) >
|
||||
UPDATE_AREA_DIAMETER * UPDATE_AREA_DIAMETER) {
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ static inline void update_particle(
|
|||
|
||||
void ParticlesRenderer::updateParticles(float delta) {
|
||||
std::vector<const Texture*> unusedTextures;
|
||||
visibleParticles = 0;
|
||||
|
||||
for (auto& [texture, vec] : particles) {
|
||||
if (vec.empty()) {
|
||||
|
|
@ -186,7 +187,6 @@ void ParticlesRenderer::update(const Camera& camera, float delta) {
|
|||
|
||||
void ParticlesRenderer::render(const Camera& camera) {
|
||||
aliveEmitters = emitters.size();
|
||||
visibleParticles = 0;
|
||||
|
||||
bool backlight = settings.backlight.get();
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ void LightSolver::remove(int x, int y, int z) {
|
|||
}
|
||||
|
||||
void LightSolver::solve(Chunk* prevailingChunk) {
|
||||
const int coords[] = {
|
||||
static const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
0, 1, 0,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,8 @@
|
|||
|
||||
static debug::Logger logger("lighting");
|
||||
|
||||
Lighting::Lighting(const Content& content, Chunks& chunks)
|
||||
: content(content), chunks(chunks) {
|
||||
auto& indices = *content.getIndices();
|
||||
Lighting::Lighting(const ContentIndices& indices, Chunks& chunks)
|
||||
: indices(indices), chunks(chunks) {
|
||||
solverR = std::make_unique<LightSolver>(indices, chunks, 0);
|
||||
solverG = std::make_unique<LightSolver>(indices, chunks, 1);
|
||||
solverB = std::make_unique<LightSolver>(indices, chunks, 2);
|
||||
|
|
@ -70,7 +69,7 @@ void Lighting::prebuildSkyLight(Chunk& chunk, const ContentIndices& indices) {
|
|||
}
|
||||
|
||||
void Lighting::buildSkyLight(int cx, int cz){
|
||||
const auto blockDefs = content.getIndices()->blocks.getDefs();
|
||||
const auto blockDefs = indices.blocks.getDefs();
|
||||
|
||||
Chunk* chunk = chunks.getChunk(cx, cz);
|
||||
if (chunk == nullptr) {
|
||||
|
|
@ -110,7 +109,7 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
|||
auto& solverB = *this->solverB;
|
||||
auto& solverS = *this->solverS;
|
||||
|
||||
auto blockDefs = content.getIndices()->blocks.getDefs();
|
||||
auto blockDefs = indices.blocks.getDefs();
|
||||
auto chunk = chunks.getChunk(cx, cz);
|
||||
if (chunk == nullptr) {
|
||||
logger.error() << "attempted to build lights to chunk missing in local matrix";
|
||||
|
|
@ -174,69 +173,72 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand) {
|
|||
}
|
||||
|
||||
void Lighting::onBlockSet(int x, int y, int z, blockid_t id){
|
||||
const auto& block = content.getIndices()->blocks.require(id);
|
||||
solverR->remove(x,y,z);
|
||||
solverG->remove(x,y,z);
|
||||
solverB->remove(x,y,z);
|
||||
const auto& block = indices.blocks.require(id);
|
||||
|
||||
if (id == 0){
|
||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
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) && block.skyLightPassing)
|
||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||
|
||||
if (block.skyLightPassing) {
|
||||
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 ||
|
||||
indices.blocks.require(vox->id).skyLightPassing ==
|
||||
false)
|
||||
break;
|
||||
solverS->add(x,i,z, 0xF);
|
||||
solverS->add(x, i, z, 0xF);
|
||||
}
|
||||
}
|
||||
const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
0, 1, 0,
|
||||
0,-1, 0,
|
||||
1, 0, 0,
|
||||
-1, 0, 0
|
||||
};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int lx = x + coords[i * 3];
|
||||
int ly = y + coords[i * 3 + 1];
|
||||
int lz = z + coords[i * 3 + 2];
|
||||
|
||||
solverR->add(lx, ly, lz);
|
||||
solverG->add(lx, ly, lz);
|
||||
solverB->add(lx, ly, lz);
|
||||
solverS->add(lx, ly, lz);
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
solverS->solve(chunk);
|
||||
}
|
||||
} else {
|
||||
auto chunk = chunks.getChunkByVoxel(glm::ivec3{x, y, z});
|
||||
if (!block.skyLightPassing){
|
||||
solverS->remove(x,y,z);
|
||||
for (int i = y-1; i >= 0; i--){
|
||||
solverS->remove(x,i,z);
|
||||
if (i == 0 || chunks.get(x,i-1,z)->id != 0){
|
||||
break;
|
||||
}
|
||||
solverS->remove(x, y, z);
|
||||
for (int i = y - 1; i >= 0; i--) {
|
||||
voxel* vox = chunks.get(x, i, z);
|
||||
if (vox == nullptr ||
|
||||
indices.blocks.require(vox->id).skyLightPassing == false) {
|
||||
break;
|
||||
}
|
||||
solverS->solve(chunk);
|
||||
}
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
|
||||
if (block.emission[0] || block.emission[1] || block.emission[2]){
|
||||
solverR->add(x,y,z,block.emission[0]);
|
||||
solverG->add(x,y,z,block.emission[1]);
|
||||
solverB->add(x,y,z,block.emission[2]);
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
solverS->remove(x, i, z);
|
||||
}
|
||||
solverS->solve();
|
||||
}
|
||||
|
||||
solverR->remove(x, y, z);
|
||||
solverG->remove(x, y, z);
|
||||
solverB->remove(x, y, z);
|
||||
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
|
||||
static const int coords[] = {
|
||||
0, 0, 1,
|
||||
0, 0,-1,
|
||||
0, 1, 0,
|
||||
0,-1, 0,
|
||||
1, 0, 0,
|
||||
-1, 0, 0
|
||||
};
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int lx = x + coords[i * 3];
|
||||
int ly = y + coords[i * 3 + 1];
|
||||
int lz = z + coords[i * 3 + 2];
|
||||
|
||||
solverR->add(lx, ly, lz);
|
||||
solverG->add(lx, ly, lz);
|
||||
solverB->add(lx, ly, lz);
|
||||
solverS->add(lx, ly, lz);
|
||||
}
|
||||
|
||||
if (block.emission[0]) {
|
||||
solverR->add(x, y, z, block.emission[0]);
|
||||
}
|
||||
if (block.emission[1]) {
|
||||
solverG->add(x, y, z, block.emission[1]);
|
||||
}
|
||||
if (block.emission[2]) {
|
||||
solverB->add(x, y, z, block.emission[2]);
|
||||
}
|
||||
solverR->solve(chunk);
|
||||
solverG->solve(chunk);
|
||||
solverB->solve(chunk);
|
||||
solverS->solve(chunk);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,20 @@
|
|||
|
||||
#include "typedefs.hpp"
|
||||
|
||||
class Content;
|
||||
class ContentIndices;
|
||||
class Chunk;
|
||||
class Chunks;
|
||||
class LightSolver;
|
||||
|
||||
class Lighting {
|
||||
const Content& content;
|
||||
const ContentIndices& indices;
|
||||
Chunks& chunks;
|
||||
std::unique_ptr<LightSolver> solverR;
|
||||
std::unique_ptr<LightSolver> solverG;
|
||||
std::unique_ptr<LightSolver> solverB;
|
||||
std::unique_ptr<LightSolver> solverS;
|
||||
public:
|
||||
Lighting(const Content& content, Chunks& chunks);
|
||||
Lighting(const ContentIndices& indices, Chunks& chunks);
|
||||
~Lighting();
|
||||
|
||||
void clear();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "content/Content.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "engine/EnginePaths.hpp"
|
||||
|
|
@ -41,7 +42,7 @@ LevelController::LevelController(
|
|||
|
||||
if (clientPlayer) {
|
||||
chunks->lighting = std::make_unique<Lighting>(
|
||||
level->content, *clientPlayer->chunks
|
||||
*level->content.getIndices(), *clientPlayer->chunks
|
||||
);
|
||||
}
|
||||
blocks = std::make_unique<BlocksController>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue