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

View File

@ -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();

View File

@ -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<voxel[]>(w * h * d)),
lights(std::make_unique<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)
: 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;
}

View File

@ -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<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();
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_

View File

@ -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_