test clouds

This commit is contained in:
MihailRis 2026-02-11 01:09:30 +03:00
parent cf69d3e8f4
commit e24a5db97a
7 changed files with 409 additions and 69 deletions

View file

@ -0,0 +1,55 @@
#include "VoxelsVolume.hpp"
#include "constants.hpp"
#include "content/Content.hpp"
#include "voxels/Block.hpp"
#include <assert.h>
void VoxelsVolume::compressInto(VoxelsVolume& dst, const Content& content) const {
assert(dst.w < w && dst.h < h && dst.d < d);
assert(w % dst.w == 0 && h % dst.h == 0 && d % dst.d == 0);
int stepW = w / dst.w;
int stepH = h / dst.h;
int stepD = d / dst.d;
int height = dst.h;
int depth = dst.d;
int width = dst.w;
auto dstVoxels = dst.getVoxels();
auto dstLights = dst.getLights();
const auto& blockDefs = content.getIndices()->blocks;
for (int y = 0; y < height; y++) {
for (int z = 0; z < depth; z++) {
for (int x = 0; x < width; x++) {
voxel selectedVoxel {BLOCK_AIR, {}};
light_t light = 0;
for (int ly = 0; ly < stepH; ly++) {
for (int lz = 0; lz < stepD; lz++) {
for (int lx = 0; lx < stepW; lx++) {
size_t srcIndex = vox_index(
x * stepW + lx, y * stepH + ly, z * stepD, w, d
);
auto vox = voxels[srcIndex];
if (vox.id == BLOCK_VOID) {
continue;
}
const auto& def = blockDefs.require(vox.id);
if (def.rt.solid) {
selectedVoxel = std::move(vox);
} else if (light == 0) {
light = lights[srcIndex];
}
}
}
}
size_t dstIndex = vox_index(x, y, z, dst.w, dst.d);
dstLights[dstIndex] = light;
dstVoxels[dstIndex] = std::move(selectedVoxel);
}
}
}
}

View file

@ -6,15 +6,17 @@
#include <cstring>
class Content;
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) {
: x(x), y(y), z(z), w(w), h(h), d(d),
voxels(std::make_unique<voxel[]>(w * h * d)),
lights(std::make_unique<light_t[]>(w * h * d)) {
std::memset(voxels.get(), 0xFF, sizeof(voxel) * w * h * d);
}
@ -52,10 +54,18 @@ public:
return voxels.get();
}
const voxel* getVoxels() const {
return voxels.get();
}
light_t* getLights() {
return lights.get();
}
const light_t* getLights() const {
return lights.get();
}
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) {
@ -80,6 +90,8 @@ public:
}
return lights[vox_index(bx - x, by - y, bz - z, w, d)];
}
void compressInto(VoxelsVolume& dst, const Content& content) const;
private:
int x, y, z;
int w, h, d;