mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 22:41:49 +00:00
stabilize delays of chunks meshes building
This commit is contained in:
parent
f47ccd5f30
commit
88544183d0
13 changed files with 335 additions and 191 deletions
|
|
@ -4,17 +4,25 @@
|
|||
#include "typedefs.hpp"
|
||||
#include "voxel.hpp"
|
||||
|
||||
class VoxelsVolume {
|
||||
int x, y, z;
|
||||
int w, h, d;
|
||||
std::unique_ptr<voxel[]> voxels;
|
||||
std::unique_ptr<light_t[]> lights;
|
||||
public:
|
||||
VoxelsVolume(int w, int h, int d);
|
||||
VoxelsVolume(int x, int y, int z, int w, int h, int d);
|
||||
virtual ~VoxelsVolume();
|
||||
#include <cstring>
|
||||
|
||||
void setPosition(int x, int y, int z);
|
||||
class VoxelsVolume {
|
||||
public:
|
||||
static inline constexpr size_t MAX_VOXELS = CHUNK_VOL * 2;
|
||||
|
||||
VoxelsVolume(int w, int h, int d)
|
||||
: VoxelsVolume(0, 0, 0, w, h, d) {}
|
||||
|
||||
VoxelsVolume(int x, int y, int z, int w, int h, int d)
|
||||
: x(x), y(y), z(z), w(w), h(h), d(d) {
|
||||
std::memset(voxels.get(), 0xFF, sizeof(voxel) * w * h * d);
|
||||
}
|
||||
|
||||
void setPosition(int x, int y, int z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
int getX() const {
|
||||
return x;
|
||||
|
|
@ -40,11 +48,11 @@ public:
|
|||
return d;
|
||||
}
|
||||
|
||||
voxel* getVoxels() const {
|
||||
voxel* getVoxels() {
|
||||
return voxels.get();
|
||||
}
|
||||
|
||||
light_t* getLights() const {
|
||||
light_t* getLights() {
|
||||
return lights.get();
|
||||
}
|
||||
|
||||
|
|
@ -72,4 +80,83 @@ public:
|
|||
}
|
||||
return lights[vox_index(bx - x, by - y, bz - z, w, d)];
|
||||
}
|
||||
private:
|
||||
int x, y, z;
|
||||
int w, h, d;
|
||||
std::unique_ptr<voxel[]> voxels;
|
||||
std::unique_ptr<light_t[]> lights;
|
||||
};
|
||||
|
||||
|
||||
template <int w, int h, int d>
|
||||
class StaticVoxelsVolume {
|
||||
public:
|
||||
static inline constexpr size_t size = w * h * d;
|
||||
static inline constexpr int width = w;
|
||||
static inline constexpr int height = h;
|
||||
static inline constexpr int depth = d;
|
||||
|
||||
StaticVoxelsVolume()
|
||||
: StaticVoxelsVolume(0, 0, 0) {}
|
||||
|
||||
StaticVoxelsVolume(int x, int y, int z)
|
||||
: x(x), y(y), z(z) {
|
||||
std::memset(voxels, 0xFF, sizeof(voxel) * size);
|
||||
}
|
||||
|
||||
void setPosition(int x, int y, int z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
int getX() const {
|
||||
return x;
|
||||
}
|
||||
|
||||
int getY() const {
|
||||
return y;
|
||||
}
|
||||
|
||||
int getZ() const {
|
||||
return z;
|
||||
}
|
||||
|
||||
voxel* getVoxels() {
|
||||
return voxels;
|
||||
}
|
||||
|
||||
light_t* getLights() {
|
||||
return lights;
|
||||
}
|
||||
|
||||
inline blockid_t pickBlockId(int bx, int by, int bz) const {
|
||||
if (bx < x || by < y || bz < z || bx >= x + w || by >= y + h ||
|
||||
bz >= z + d) {
|
||||
return BLOCK_VOID;
|
||||
}
|
||||
return voxels[vox_index(bx - x, by - y, bz - z, w, d)].id;
|
||||
}
|
||||
|
||||
|
||||
inline voxel pickBlock(int bx, int by, int bz) const {
|
||||
if (bx < x || by < y || bz < z || bx >= x + w || by >= y + h ||
|
||||
bz >= z + d) {
|
||||
return {BLOCK_VOID, {}};
|
||||
}
|
||||
return voxels[vox_index(bx - x, by - y, bz - z, w, d)];
|
||||
}
|
||||
|
||||
inline light_t pickLight(int bx, int by, int bz) const {
|
||||
if (bx < x || by < y || bz < z || bx >= x + w || by >= y + h ||
|
||||
bz >= z + d) {
|
||||
return 0;
|
||||
}
|
||||
return lights[vox_index(bx - x, by - y, bz - z, w, d)];
|
||||
}
|
||||
private:
|
||||
int x, y, z;
|
||||
voxel voxels[size];
|
||||
light_t lights[size];
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue