format fix
This commit is contained in:
parent
a93906d0f1
commit
7957a12b84
@ -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,11 +125,13 @@ 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;
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user