main menu glitch fix + refactor

This commit is contained in:
MihailRis
2024-05-19 10:38:30 +03:00
parent 997cff04d1
commit ffdeac5c1f
4 changed files with 72 additions and 76 deletions
+4 -1
View File
@@ -83,8 +83,11 @@ void LevelScreen::saveWorldPreview() {
// camera special copy for world preview // camera special copy for world preview
Camera camera = *player->camera; Camera camera = *player->camera;
camera.setFov(glm::radians(70.0f)); camera.setFov(glm::radians(70.0f));
DrawContext pctx(nullptr, {Window::width, Window::height}, batch.get());
Viewport viewport(previewSize * 1.5, previewSize); Viewport viewport(previewSize * 1.5, previewSize);
DrawContext ctx(nullptr, viewport, batch.get()); DrawContext ctx(&pctx, viewport, batch.get());
worldRenderer->draw(ctx, &camera, false, postProcessing.get()); worldRenderer->draw(ctx, &camera, false, postProcessing.get());
auto image = postProcessing->toImage(); auto image = postProcessing->toImage();
+15 -22
View File
@@ -1,30 +1,23 @@
#include "VoxelsVolume.hpp" #include "VoxelsVolume.hpp"
VoxelsVolume::VoxelsVolume(int x, int y, int z, int w, int h, int d) VoxelsVolume::VoxelsVolume(
: x(x), y(y), z(z), w(w), h(h), d(d) { int x, int y, int z, int w, int h, int d
voxels = new voxel[w * h * d]; ) : x(x), y(y), z(z), w(w), h(h), d(d),
for (int i = 0; i < w * h * d; i++) { voxels(std::make_unique<voxel[]>(w * h * d)),
voxels[i].id = BLOCK_VOID; lights(std::make_unique<light_t[]>(w * h * d))
} {
lights = new light_t[w * h * d]; for (int i = 0; i < w * h * d; i++) {
voxels[i].id = BLOCK_VOID;
}
} }
VoxelsVolume::VoxelsVolume(int w, int h, int d) VoxelsVolume::VoxelsVolume(int w, int h, int d) : VoxelsVolume(0, 0, 0, w, h, d)
: x(0), y(0), z(0), w(w), h(h), d(d) { {}
voxels = new voxel[w * h * d];
for (int i = 0; i < w * h * d; i++) {
voxels[i].id = BLOCK_VOID;
}
lights = new light_t[w * h * d];
}
VoxelsVolume::~VoxelsVolume() { VoxelsVolume::~VoxelsVolume() {}
delete[] lights;
delete[] voxels;
}
void VoxelsVolume::setPosition(int x, int y, int z) { void VoxelsVolume::setPosition(int x, int y, int z) {
this->x = x; this->x = x;
this->y = y; this->y = y;
this->z = z; this->z = z;
} }
+44 -44
View File
@@ -6,62 +6,62 @@
#include "voxel.hpp" #include "voxel.hpp"
class VoxelsVolume { class VoxelsVolume {
int x, y, z; int x, y, z;
int w, h, d; int w, h, d;
voxel* voxels; std::unique_ptr<voxel[]> voxels;
light_t* lights; std::unique_ptr<light_t[]> lights;
public: public:
VoxelsVolume(int w, int h, int d); VoxelsVolume(int w, int h, int d);
VoxelsVolume(int x, int y, int z, int w, int h, int d); VoxelsVolume(int x, int y, int z, int w, int h, int d);
virtual ~VoxelsVolume(); virtual ~VoxelsVolume();
void setPosition(int x, int y, int z); void setPosition(int x, int y, int z);
int getX() const { int getX() const {
return x; return x;
} }
int getY() const { int getY() const {
return y; return y;
} }
int getZ() const { int getZ() const {
return z; return z;
} }
int getW() const { int getW() const {
return w; return w;
} }
int getH() const { int getH() const {
return h; return h;
} }
int getD() const { int getD() const {
return d; return d;
} }
voxel* getVoxels() const { voxel* getVoxels() const {
return voxels; return voxels.get();
} }
light_t* getLights() const { light_t* getLights() const {
return lights; return lights.get();
} }
inline blockid_t pickBlockId(int bx, int by, int bz) const { 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) { if (bx < x || by < y || bz < z || bx >= x + w || by >= y + h || bz >= z + d) {
return BLOCK_VOID; return BLOCK_VOID;
} }
return voxels[vox_index(bx - x, by - y, bz - z, w, d)].id; return voxels[vox_index(bx - x, by - y, bz - z, w, d)].id;
} }
inline light_t pickLight(int bx, int by, int bz) const { 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) { if (bx < x || by < y || bz < z || bx >= x + w || by >= y + h || bz >= z + d) {
return 0; return 0;
} }
return lights[vox_index(bx - x, by - y, bz - z, w, d)]; return lights[vox_index(bx - x, by - y, bz - z, w, d)];
} }
}; };
#endif // VOXELS_VOXELSVOLUME_HPP_ #endif // VOXELS_VOXELSVOLUME_HPP_
+9 -9
View File
@@ -3,17 +3,17 @@
#include "../typedefs.hpp" #include "../typedefs.hpp"
const int BLOCK_DIR_NORTH = 0x0; inline constexpr int BLOCK_DIR_NORTH = 0x0;
const int BLOCK_DIR_WEST = 0x1; inline constexpr int BLOCK_DIR_WEST = 0x1;
const int BLOCK_DIR_SOUTH = 0x2; inline constexpr int BLOCK_DIR_SOUTH = 0x2;
const int BLOCK_DIR_EAST = 0x3; inline constexpr int BLOCK_DIR_EAST = 0x3;
const int BLOCK_DIR_UP = 0x4; inline constexpr int BLOCK_DIR_UP = 0x4;
const int BLOCK_DIR_DOWN = 0x5; inline constexpr int BLOCK_DIR_DOWN = 0x5;
// limited to 8 block orientations // limited to 8 block orientations
const int BLOCK_ROT_MASK = 0b0000'0111; inline constexpr int BLOCK_ROT_MASK = 0b0000'0111;
// reserved bits // reserved bits
const int BLOCK_RESERVED_MASK = 0b1111'1000; inline constexpr int BLOCK_RESERVED_MASK = 0b1111'1000;
struct voxel { struct voxel {
blockid_t id; blockid_t id;
@@ -28,4 +28,4 @@ struct voxel {
} }
}; };
#endif /* VOXELS_VOXEL_HPP_ */ #endif // VOXELS_VOXEL_HPP_