format fix

This commit is contained in:
MihailRis 2024-05-17 21:37:02 +03:00
parent a93906d0f1
commit 7957a12b84

View File

@ -16,18 +16,20 @@
#include <limits.h>
#include <vector>
Chunks::Chunks(uint32_t w, uint32_t d,
Chunks::Chunks(
uint32_t w, uint32_t d,
int32_t ox, int32_t oz,
WorldFiles* wfile,
LevelEvents* events,
const Content* content)
: contentIds(content->getIndices()),
const Content* content
) : contentIds(content->getIndices()),
chunks(w*d),
chunksSecond(w*d),
w(w), d(d), ox(ox), oz(oz),
worldFiles(wfile),
events(events) {
volume = (size_t)w*(size_t)d;
events(events)
{
volume = static_cast<size_t>(w)*static_cast<size_t>(d);
chunksCount = 0;
}
@ -37,11 +39,13 @@ voxel* Chunks::get(int32_t x, int32_t y, int32_t z) {
int cx = floordiv(x, CHUNK_W);
int cy = floordiv(y, CHUNK_H);
int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d))
if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d)) {
return nullptr;
}
auto& chunk = chunks[cz * w + cx]; // not thread safe
if (chunk == nullptr)
if (chunk == nullptr) {
return nullptr;
}
int lx = x - cx * CHUNK_W;
int ly = y - cy * CHUNK_H;
int lz = z - cz * CHUNK_D;
@ -67,10 +71,11 @@ const AABB* Chunks::isObstacleAt(float x, float y, float z){
? def->rt.hitboxes[v->rotation()]
: def->hitboxes;
for (const auto& hitbox : boxes) {
if (hitbox.contains({x - ix, y - iy, z - iz}))
if (hitbox.contains({x - ix, y - iy, z - iz})) {
return &hitbox;
}
}
}
return nullptr;
}
@ -101,11 +106,13 @@ ubyte Chunks::getLight(int32_t x, int32_t y, int32_t z, int channel){
int cx = floordiv(x, CHUNK_W);
int cy = floordiv(y, CHUNK_H);
int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d))
if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d)) {
return 0;
}
const auto& chunk = chunks[(cy * d + cz) * w + cx];
if (chunk == nullptr)
if (chunk == nullptr) {
return 0;
}
int lx = x - cx * CHUNK_W;
int ly = y - cy * CHUNK_H;
int lz = z - cz * CHUNK_D;
@ -118,18 +125,20 @@ light_t Chunks::getLight(int32_t x, int32_t y, int32_t z){
int cx = floordiv(x, CHUNK_W);
int cy = floordiv(y, CHUNK_H);
int cz = floordiv(z, CHUNK_D);
if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d))
if (cx < 0 || cy < 0 || cz < 0 || cx >= int(w) || cy >= 1 || cz >= int(d)) {
return 0;
}
const auto& chunk = chunks[(cy * d + cz) * w + cx];
if (chunk == nullptr)
if (chunk == nullptr) {
return 0;
}
int lx = x - cx * CHUNK_W;
int ly = y - cy * CHUNK_H;
int lz = z - cz * CHUNK_D;
return chunk->lightmap.get(lx,ly,lz);
}
Chunk* Chunks::getChunkByVoxel(int32_t x, int32_t y, int32_t z){
Chunk* Chunks::getChunkByVoxel(int32_t x, int32_t y, int32_t z) {
if (y < 0 || y >= CHUNK_H)
return nullptr;
x -= ox * CHUNK_W;
@ -149,7 +158,7 @@ Chunk* Chunks::getChunk(int x, int z){
return chunks[z * w + x].get();
}
void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states){
void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states) {
if (y < 0 || y >= CHUNK_H)
return;
x -= ox * CHUNK_W;
@ -189,12 +198,14 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states){
chunk->setModified(true);
}
voxel* Chunks::rayCast(glm::vec3 start,
voxel* Chunks::rayCast(
glm::vec3 start,
glm::vec3 dir,
float maxDist,
glm::vec3& end,
glm::ivec3& norm,
glm::ivec3& iend) {
glm::ivec3& iend
) {
float px = start.x;
float py = start.y;
float pz = start.z;
@ -230,8 +241,9 @@ voxel* Chunks::rayCast(glm::vec3 start,
while (t <= maxDist){
voxel* voxel = get(ix, iy, iz);
if (voxel == nullptr){ return nullptr; }
if (voxel == nullptr){
return nullptr;
}
const Block* def = contentIds->getBlockDef(voxel->id);
if (def->selectable){
end.x = px + t * dx;
@ -346,8 +358,9 @@ glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDis
while (t <= maxDist) {
voxel* voxel = get(ix, iy, iz);
if (voxel == nullptr) { return glm::vec3(px + t * dx, py + t * dy, pz + t * dz); }
if (voxel == nullptr) {
return glm::vec3(px + t * dx, py + t * dy, pz + t * dz);
}
const Block* def = contentIds->getBlockDef(voxel->id);
if (def->obstacle) {
if (!def->rt.solid) {
@ -414,14 +427,14 @@ void Chunks::translate(int32_t dx, int32_t dz) {
for (uint i = 0; i < volume; i++){
chunksSecond[i] = nullptr;
}
for (uint32_t z = 0; z < d; z++){
for (uint32_t x = 0; x < w; x++){
for (uint32_t z = 0; z < d; z++) {
for (uint32_t x = 0; x < w; x++) {
auto chunk = chunks[z * w + x];
int nx = x - dx;
int nz = z - dz;
if (chunk == nullptr)
continue;
if (nx < 0 || nz < 0 || nx >= int(w) || nz >= int(d)){
if (nx < 0 || nz < 0 || nx >= int(w) || nz >= int(d)) {
events->trigger(EVT_CHUNK_HIDDEN, chunk.get());
regions.put(chunk.get());
chunksCount--;