format fix
This commit is contained in:
parent
a93906d0f1
commit
7957a12b84
@ -16,18 +16,20 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
Chunks::Chunks(uint32_t w, uint32_t d,
|
Chunks::Chunks(
|
||||||
|
uint32_t w, uint32_t d,
|
||||||
int32_t ox, int32_t oz,
|
int32_t ox, int32_t oz,
|
||||||
WorldFiles* wfile,
|
WorldFiles* wfile,
|
||||||
LevelEvents* events,
|
LevelEvents* events,
|
||||||
const Content* content)
|
const Content* content
|
||||||
: contentIds(content->getIndices()),
|
) : contentIds(content->getIndices()),
|
||||||
chunks(w*d),
|
chunks(w*d),
|
||||||
chunksSecond(w*d),
|
chunksSecond(w*d),
|
||||||
w(w), d(d), ox(ox), oz(oz),
|
w(w), d(d), ox(ox), oz(oz),
|
||||||
worldFiles(wfile),
|
worldFiles(wfile),
|
||||||
events(events) {
|
events(events)
|
||||||
volume = (size_t)w*(size_t)d;
|
{
|
||||||
|
volume = static_cast<size_t>(w)*static_cast<size_t>(d);
|
||||||
chunksCount = 0;
|
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 cx = floordiv(x, CHUNK_W);
|
||||||
int cy = floordiv(y, CHUNK_H);
|
int cy = floordiv(y, CHUNK_H);
|
||||||
int cz = floordiv(z, CHUNK_D);
|
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;
|
return nullptr;
|
||||||
|
}
|
||||||
auto& chunk = chunks[cz * w + cx]; // not thread safe
|
auto& chunk = chunks[cz * w + cx]; // not thread safe
|
||||||
if (chunk == nullptr)
|
if (chunk == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
}
|
||||||
int lx = x - cx * CHUNK_W;
|
int lx = x - cx * CHUNK_W;
|
||||||
int ly = y - cy * CHUNK_H;
|
int ly = y - cy * CHUNK_H;
|
||||||
int lz = z - cz * CHUNK_D;
|
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->rt.hitboxes[v->rotation()]
|
||||||
: def->hitboxes;
|
: def->hitboxes;
|
||||||
for (const auto& hitbox : boxes) {
|
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 &hitbox;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nullptr;
|
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 cx = floordiv(x, CHUNK_W);
|
||||||
int cy = floordiv(y, CHUNK_H);
|
int cy = floordiv(y, CHUNK_H);
|
||||||
int cz = floordiv(z, CHUNK_D);
|
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;
|
return 0;
|
||||||
|
}
|
||||||
const auto& chunk = chunks[(cy * d + cz) * w + cx];
|
const auto& chunk = chunks[(cy * d + cz) * w + cx];
|
||||||
if (chunk == nullptr)
|
if (chunk == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
int lx = x - cx * CHUNK_W;
|
int lx = x - cx * CHUNK_W;
|
||||||
int ly = y - cy * CHUNK_H;
|
int ly = y - cy * CHUNK_H;
|
||||||
int lz = z - cz * CHUNK_D;
|
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 cx = floordiv(x, CHUNK_W);
|
||||||
int cy = floordiv(y, CHUNK_H);
|
int cy = floordiv(y, CHUNK_H);
|
||||||
int cz = floordiv(z, CHUNK_D);
|
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;
|
return 0;
|
||||||
|
}
|
||||||
const auto& chunk = chunks[(cy * d + cz) * w + cx];
|
const auto& chunk = chunks[(cy * d + cz) * w + cx];
|
||||||
if (chunk == nullptr)
|
if (chunk == nullptr) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
int lx = x - cx * CHUNK_W;
|
int lx = x - cx * CHUNK_W;
|
||||||
int ly = y - cy * CHUNK_H;
|
int ly = y - cy * CHUNK_H;
|
||||||
int lz = z - cz * CHUNK_D;
|
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);
|
chunk->setModified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
voxel* Chunks::rayCast(glm::vec3 start,
|
voxel* Chunks::rayCast(
|
||||||
|
glm::vec3 start,
|
||||||
glm::vec3 dir,
|
glm::vec3 dir,
|
||||||
float maxDist,
|
float maxDist,
|
||||||
glm::vec3& end,
|
glm::vec3& end,
|
||||||
glm::ivec3& norm,
|
glm::ivec3& norm,
|
||||||
glm::ivec3& iend) {
|
glm::ivec3& iend
|
||||||
|
) {
|
||||||
float px = start.x;
|
float px = start.x;
|
||||||
float py = start.y;
|
float py = start.y;
|
||||||
float pz = start.z;
|
float pz = start.z;
|
||||||
@ -230,8 +241,9 @@ voxel* Chunks::rayCast(glm::vec3 start,
|
|||||||
|
|
||||||
while (t <= maxDist){
|
while (t <= maxDist){
|
||||||
voxel* voxel = get(ix, iy, iz);
|
voxel* voxel = get(ix, iy, iz);
|
||||||
if (voxel == nullptr){ return nullptr; }
|
if (voxel == nullptr){
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
const Block* def = contentIds->getBlockDef(voxel->id);
|
const Block* def = contentIds->getBlockDef(voxel->id);
|
||||||
if (def->selectable){
|
if (def->selectable){
|
||||||
end.x = px + t * dx;
|
end.x = px + t * dx;
|
||||||
@ -346,8 +358,9 @@ glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDis
|
|||||||
|
|
||||||
while (t <= maxDist) {
|
while (t <= maxDist) {
|
||||||
voxel* voxel = get(ix, iy, iz);
|
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);
|
const Block* def = contentIds->getBlockDef(voxel->id);
|
||||||
if (def->obstacle) {
|
if (def->obstacle) {
|
||||||
if (!def->rt.solid) {
|
if (!def->rt.solid) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user