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();
+9 -16
View File
@@ -1,27 +1,20 @@
#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),
voxels(std::make_unique<voxel[]>(w * h * d)),
lights(std::make_unique<light_t[]>(w * h * d))
{
for (int i = 0; i < w * h * d; i++) { for (int i = 0; i < w * h * d; i++) {
voxels[i].id = BLOCK_VOID; voxels[i].id = BLOCK_VOID;
} }
lights = new light_t[w * h * d];
} }
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;
+4 -4
View File
@@ -8,8 +8,8 @@
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);
@@ -42,11 +42,11 @@ public:
} }
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 {
+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_