format: reformat project

Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-03 19:53:48 +03:00
committed by Pugemon
parent 736cd175d5
commit bbf33e8e4d
202 changed files with 7389 additions and 5609 deletions
+31 -34
View File
@@ -1,33 +1,36 @@
#include "ChunksController.hpp"
#include <limits.h>
#include <iostream>
#include <memory>
#include "../content/Content.hpp"
#include "../files/WorldFiles.hpp"
#include "../graphics/core/Mesh.hpp"
#include "../lighting/Lighting.hpp"
#include "../maths/voxmaths.hpp"
#include "../util/timeutil.hpp"
#include "../voxels/Block.hpp"
#include "../voxels/Chunk.hpp"
#include "../voxels/Chunks.hpp"
#include "../voxels/ChunksStorage.hpp"
#include "../voxels/WorldGenerator.hpp"
#include "../world/WorldGenerators.hpp"
#include "../graphics/core/Mesh.hpp"
#include "../lighting/Lighting.hpp"
#include "../files/WorldFiles.hpp"
#include "../world/Level.hpp"
#include "../world/World.hpp"
#include "../maths/voxmaths.hpp"
#include "../util/timeutil.hpp"
#include <limits.h>
#include <memory>
#include <iostream>
#include "../world/WorldGenerators.hpp"
const uint MAX_WORK_PER_FRAME = 128;
const uint MIN_SURROUNDING = 9;
ChunksController::ChunksController(Level* level, uint padding)
: level(level),
chunks(level->chunks.get()),
lighting(level->lighting.get()),
padding(padding),
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
ChunksController::ChunksController(Level* level, uint padding)
: level(level),
chunks(level->chunks.get()),
lighting(level->lighting.get()),
padding(padding),
generator(WorldGenerators::createGenerator(
level->getWorld()->getGenerator(), level->content
)) {
}
ChunksController::~ChunksController() = default;
@@ -48,18 +51,18 @@ void ChunksController::update(int64_t maxDuration) {
}
}
bool ChunksController::loadVisible(){
bool ChunksController::loadVisible() {
const int w = chunks->w;
const int d = chunks->d;
int nearX = 0;
int nearZ = 0;
int minDistance = ((w-padding*2)/2)*((w-padding*2)/2);
for (uint z = padding; z < d-padding; z++){
for (uint x = padding; x < w-padding; x++){
int minDistance = ((w - padding * 2) / 2) * ((w - padding * 2) / 2);
for (uint z = padding; z < d - padding; z++) {
for (uint x = padding; x < w - padding; x++) {
int index = z * w + x;
auto& chunk = chunks->chunks[index];
if (chunk != nullptr){
if (chunk != nullptr) {
if (chunk->flags.loaded && !chunk->flags.lighted) {
if (buildLights(chunk)) {
return true;
@@ -70,7 +73,7 @@ bool ChunksController::loadVisible(){
int lx = x - w / 2;
int lz = z - d / 2;
int distance = (lx * lx + lz * lz);
if (distance < minDistance){
if (distance < minDistance) {
minDistance = distance;
nearX = x;
nearZ = z;
@@ -85,16 +88,15 @@ bool ChunksController::loadVisible(){
const int ox = chunks->ox;
const int oz = chunks->oz;
createChunk(nearX+ox, nearZ+oz);
createChunk(nearX + ox, nearZ + oz);
return true;
}
bool ChunksController::buildLights(const std::shared_ptr<Chunk>& chunk) {
int surrounding = 0;
for (int oz = -1; oz <= 1; oz++){
for (int ox = -1; ox <= 1; ox++){
if (chunks->getChunk(chunk->x+ox, chunk->z+oz))
surrounding++;
for (int oz = -1; oz <= 1; oz++) {
for (int ox = -1; ox <= 1; ox++) {
if (chunks->getChunk(chunk->x + ox, chunk->z + oz)) surrounding++;
}
}
if (surrounding == MIN_SURROUNDING) {
@@ -115,18 +117,13 @@ void ChunksController::createChunk(int x, int z) {
auto& chunkFlags = chunk->flags;
if (!chunkFlags.loaded) {
generator->generate(
chunk->voxels, x, z,
level->getWorld()->getSeed()
);
generator->generate(chunk->voxels, x, z, level->getWorld()->getSeed());
chunkFlags.unsaved = true;
}
chunk->updateHeights();
if (!chunkFlags.loadedLights) {
Lighting::prebuildSkyLight(
chunk.get(), level->content->getIndices()
);
Lighting::prebuildSkyLight(chunk.get(), level->content->getIndices());
}
chunkFlags.loaded = true;
chunkFlags.ready = true;