diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index 7f805e27..bed9de27 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -83,8 +83,11 @@ void LevelScreen::saveWorldPreview() { // camera special copy for world preview Camera camera = *player->camera; camera.setFov(glm::radians(70.0f)); + + DrawContext pctx(nullptr, {Window::width, Window::height}, batch.get()); + 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()); auto image = postProcessing->toImage(); diff --git a/src/voxels/VoxelsVolume.cpp b/src/voxels/VoxelsVolume.cpp index 73bff62c..5da88add 100644 --- a/src/voxels/VoxelsVolume.cpp +++ b/src/voxels/VoxelsVolume.cpp @@ -1,30 +1,23 @@ #include "VoxelsVolume.hpp" -VoxelsVolume::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) { - 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( + int x, int y, int z, int w, int h, int d +) : x(x), y(y), z(z), w(w), h(h), d(d), + voxels(std::make_unique(w * h * d)), + lights(std::make_unique(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) - : 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(int w, int h, int d) : VoxelsVolume(0, 0, 0, w, h, d) +{} -VoxelsVolume::~VoxelsVolume() { - delete[] lights; - delete[] voxels; -} +VoxelsVolume::~VoxelsVolume() {} void VoxelsVolume::setPosition(int x, int y, int z) { - this->x = x; - this->y = y; - this->z = z; + this->x = x; + this->y = y; + this->z = z; } diff --git a/src/voxels/VoxelsVolume.hpp b/src/voxels/VoxelsVolume.hpp index 30406891..d6e6474a 100644 --- a/src/voxels/VoxelsVolume.hpp +++ b/src/voxels/VoxelsVolume.hpp @@ -6,62 +6,62 @@ #include "voxel.hpp" class VoxelsVolume { - int x, y, z; - int w, h, d; - voxel* voxels; - light_t* lights; + int x, y, z; + int w, h, d; + std::unique_ptr voxels; + std::unique_ptr lights; public: - VoxelsVolume(int w, int h, int d); - VoxelsVolume(int x, int y, int z, int w, int h, int d); - virtual ~VoxelsVolume(); + VoxelsVolume(int w, int h, int d); + VoxelsVolume(int x, int y, int z, int w, int h, int d); + virtual ~VoxelsVolume(); - void setPosition(int x, int y, int z); + void setPosition(int x, int y, int z); - int getX() const { - return x; - } + int getX() const { + return x; + } - int getY() const { - return y; - } + int getY() const { + return y; + } - int getZ() const { - return z; - } + int getZ() const { + return z; + } - int getW() const { - return w; - } + int getW() const { + return w; + } - int getH() const { - return h; - } + int getH() const { + return h; + } - int getD() const { - return d; - } + int getD() const { + return d; + } - voxel* getVoxels() const { - return voxels; - } + voxel* getVoxels() const { + return voxels.get(); + } - light_t* getLights() const { - return lights; - } + 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) { - return BLOCK_VOID; - } - return voxels[vox_index(bx - x, by - y, bz - z, w, d)].id; - } + 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 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)]; - } + 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)]; + } }; #endif // VOXELS_VOXELSVOLUME_HPP_ diff --git a/src/voxels/voxel.hpp b/src/voxels/voxel.hpp index a39e6305..db2c8138 100644 --- a/src/voxels/voxel.hpp +++ b/src/voxels/voxel.hpp @@ -3,17 +3,17 @@ #include "../typedefs.hpp" -const int BLOCK_DIR_NORTH = 0x0; -const int BLOCK_DIR_WEST = 0x1; -const int BLOCK_DIR_SOUTH = 0x2; -const int BLOCK_DIR_EAST = 0x3; -const int BLOCK_DIR_UP = 0x4; -const int BLOCK_DIR_DOWN = 0x5; +inline constexpr int BLOCK_DIR_NORTH = 0x0; +inline constexpr int BLOCK_DIR_WEST = 0x1; +inline constexpr int BLOCK_DIR_SOUTH = 0x2; +inline constexpr int BLOCK_DIR_EAST = 0x3; +inline constexpr int BLOCK_DIR_UP = 0x4; +inline constexpr int BLOCK_DIR_DOWN = 0x5; // limited to 8 block orientations -const int BLOCK_ROT_MASK = 0b0000'0111; +inline constexpr int BLOCK_ROT_MASK = 0b0000'0111; // reserved bits -const int BLOCK_RESERVED_MASK = 0b1111'1000; +inline constexpr int BLOCK_RESERVED_MASK = 0b1111'1000; struct voxel { blockid_t id; @@ -28,4 +28,4 @@ struct voxel { } }; -#endif /* VOXELS_VOXEL_HPP_ */ +#endif // VOXELS_VOXEL_HPP_