Reorganized client code to be ready for isometrics

Preparing the namespacing for multi-dementional/isometric renderers
and the like. Just some fancy formatting for the moment.
This commit is contained in:
Rebekah 2024-02-19 07:04:11 -05:00
parent 639e867fd4
commit a9bc6895ed
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5

View File

@ -222,7 +222,7 @@ enum CardinalDirections {
kDown*/
};
class FalseChunk {
class FalseChunk { // TODO, Hurry and figure out how to render a 3x3 of chunks, then move it around to a different area. Get the whole "Treadmilling" correct! we need to hurry to deprecate this or at least figure out its purpose with the server/client code interactions.
public:
// "typedefs" or templates go here lol
static constexpr std::size_t _chunk_array_size = cChunkDef::Width * cChunkDef::Width;
@ -502,7 +502,7 @@ public:
BlockType GetVoxelType(std::size_t v) const {
return raw_chunk_data[v];
}
class AxisIterator {
class AxisIterator { // missing the y axis
bool end_flagged = false;
ChunkVecType cur;
@ -598,7 +598,7 @@ public:
glez::color::black // bedrock
};
static constexpr bool gfx_mesher_debuglog = false;
std::vector<ChunkMeshedQuad> MeshChunk(MesherComplexity cmplxity) const {
std::vector<ChunkMeshedQuad> MeshSingleDepthLayerOfChunk(MesherComplexity cmplxity, int depth = 0) const { // Only good for the TOP/BOTTOM face of the bottom row. Doesnt check if air is in front of the face.
bool is_chunk_only_air = this->IsEmpty();
if (is_chunk_only_air)
return {}; // Your fault you didnt check it first...
@ -780,14 +780,14 @@ public:
}
};
} // namespace qubel
namespace test {
class QubelMeshingTestWindow : public CBaseWindow {
class WindowSettings : public CBaseWindow {
public:
CCheckbox* activate;
CCheckbox* wireframe;
CDropdown* dropdown;
QubelMeshingTestWindow(IWidget* parent)
WindowSettings(IWidget* parent)
: CBaseWindow(parent, "qubelmesh_test_settings") {
this->always_visible = false;
this->hover = false;
@ -819,69 +819,8 @@ public:
this->Add<CCheckbox>("binary_meshing", false);
}
};
using namespace qubel;
class QubelMeshingTestRenderingWindow : public CBaseWindow {
public:
const CTitleBar* titlebar;
const QubelMeshingTestWindow* settings;
FalseChunk world_slice;
class ChunkRenderer : public CBaseWidget {
public:
static constexpr std::pair<int, int> min_size = { 856, 480 };
const FalseChunk* world_slice;
const QubelMeshingTestWindow* settings;
ChunkRenderer(IWidget* parent, QubelMeshingTestWindow* settings, FalseChunk* world_slice)
: CBaseWidget("qubelmesh_test_renderer_sceneoutput", parent)
, world_slice(world_slice)
, settings(settings) {
assert(settings && world_slice);
settings->dropdown->SetCallback([&](CDropdown*, int value) {
current_render_quads.clear();
});
this->SetSize(ChunkRenderer::min_size.first, ChunkRenderer::min_size.second);
}
std::vector<FalseChunk::ChunkMeshedQuad> current_render_quads;
virtual void Draw(ICanvas* the_drawing_machine) override {
this->CBaseWidget::Draw(the_drawing_machine);
const auto ConvertGLMVecToSTDPairVec = [](const geo::Vec2& vec_in) -> std::pair<int, int> {
return std::pair<int, int>(vec_in.x, vec_in.y);
};
const auto ConvertGLMQuadToSTDPairQuad = [&](const geo::Box<geo::Vec2>& box_in) -> Canvas::TranslationMatrix {
return Canvas::TranslationMatrix(ConvertGLMVecToSTDPairVec(box_in.origin), ConvertGLMVecToSTDPairVec(box_in.GetSize()));
};
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads)
the_drawing_machine->Rect(ConvertGLMQuadToSTDPairQuad(kinda_a_vert.quad), kinda_a_vert.clr);
if (this->settings->wireframe->Value()) {
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads) {
the_drawing_machine->Rect({ ConvertGLMQuadToSTDPairQuad(kinda_a_vert.quad) }, glez::color::black, Canvas::RectType::Outline);
the_drawing_machine->Line({ ConvertGLMQuadToSTDPairQuad(kinda_a_vert.quad) }, glez::color::black);
}
}
}
virtual void Update() override {
this->CBaseWidget::Update();
if (current_render_quads.empty()) {
if (world_slice->IsEmpty())
return;
current_render_quads = world_slice->MeshChunk(FalseChunk::MesherComplexity(settings->dropdown->Value()));
if (FalseChunk::gfx_mesher_debuglog) {
std::pair<int, int> found_size;
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads) {
const auto max_coord = kinda_a_vert.quad.GetMax();
if (max_coord.x > found_size.first)
found_size.first = max_coord.x;
if (max_coord.y > found_size.second)
found_size.second = max_coord.y;
}
std::cout << "Created mesh with pixel size: " << found_size.first << ", " << found_size.second << std::endl;
}
}
}
};
ChunkRenderer* render_scene;
} // namespace test
namespace two_d {
class SkyRenderer : public CBaseWidget {
static constexpr bool debug_log = false;
@ -1005,10 +944,159 @@ public:
return air_color;
}
};
SkyRenderer* skybox;
} // namespace two_d
namespace topdown {
class ChunkRenderer : public CBaseWidget {
public:
static constexpr std::pair<int, int> min_size = { 856, 480 };
const FalseChunk* world_slice;
const test::WindowSettings* settings;
ChunkRenderer(IWidget* parent, test::WindowSettings* settings, FalseChunk* world_slice)
: CBaseWidget("qubelmesh_test_renderer_sceneoutput", parent)
, world_slice(world_slice)
, settings(settings) {
assert(settings && world_slice);
settings->dropdown->SetCallback([&](CDropdown*, int value) {
current_render_quads.clear();
});
this->SetSize(ChunkRenderer::min_size.first, ChunkRenderer::min_size.second);
}
std::vector<FalseChunk::ChunkMeshedQuad> current_render_quads;
virtual void Draw(ICanvas* the_drawing_machine) override {
this->CBaseWidget::Draw(the_drawing_machine);
const auto ConvertGLMVecToSTDPairVec = [](const geo::Vec2& vec_in) -> std::pair<int, int> {
return std::pair<int, int>(vec_in.x, vec_in.y);
};
const auto ConvertGLMQuadToSTDPairQuad = [&](const geo::Box<geo::Vec2>& box_in) -> Canvas::TranslationMatrix {
return Canvas::TranslationMatrix(ConvertGLMVecToSTDPairVec(box_in.origin), ConvertGLMVecToSTDPairVec(box_in.GetSize()));
};
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads)
the_drawing_machine->Rect(ConvertGLMQuadToSTDPairQuad(kinda_a_vert.quad), kinda_a_vert.clr);
if (this->settings->wireframe->Value()) {
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads) {
the_drawing_machine->Rect({ ConvertGLMQuadToSTDPairQuad(kinda_a_vert.quad) }, glez::color::black, Canvas::RectType::Outline);
the_drawing_machine->Line({ ConvertGLMQuadToSTDPairQuad(kinda_a_vert.quad) }, glez::color::black);
}
}
}
virtual void Update() override {
this->CBaseWidget::Update();
if (current_render_quads.empty()) {
if (world_slice->IsEmpty())
return;
current_render_quads = world_slice->MeshSingleDepthLayerOfChunk(FalseChunk::MesherComplexity(settings->dropdown->Value()));
if (FalseChunk::gfx_mesher_debuglog) {
std::pair<int, int> found_size;
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads) {
const auto max_coord = kinda_a_vert.quad.GetMax();
if (max_coord.x > found_size.first)
found_size.first = max_coord.x;
if (max_coord.y > found_size.second)
found_size.second = max_coord.y;
}
std::cout << "Created mesh with pixel size: " << found_size.first << ", " << found_size.second << std::endl;
}
}
}
};
class RenderingWindow : public CBaseWindow {
public:
const CTitleBar* titlebar;
const test::WindowSettings* settings;
FalseChunk world_slice;
two_d::SkyRenderer* skybox;
public:
QubelMeshingTestRenderingWindow(IWidget* parent, QubelMeshingTestWindow* settings)
RenderingWindow(IWidget* parent, test::WindowSettings* settings)
: CBaseWindow(parent, "qubelmesh_test_renderer_frame")
, settings(settings) {
assert(settings);
this->always_visible = false;
this->hover = false;
this->SetPositionMode(PositionMode::FLOATING);
this->SetMaxSize(1270, 1000);
this->zindex = -999;
titlebar = this->Add<CTitleBar>("QubelWorld Mesh Test uwu~");
/*render_scene =*/this->Add<ChunkRenderer>(settings, &world_slice);
skybox = this->Add<two_d::SkyRenderer>();
}
~RenderingWindow() { }
virtual bool AlwaysVisible() const override {
return this->settings->activate->Value();
}
virtual bool IsVisible() const override {
return this->settings->activate->Value() && this->CBaseWindow::IsVisible();
}
};
} // namespace topdown
// Isometric needs some extra stuff to make it work at all. We need a way to render block textures to a isometric block represented as a texture.
// Once we have textures with these isoblocks, it should be a matter of positioning the texture in the correct spot for each block..
// We will require this eventually for the block selector as well as a potential isometric renderer should we want to impliment it.
/*namespace isometric {
class RenderingWindow : public CBaseWindow {
public:
const CTitleBar* titlebar;
const test::WindowSettings* settings;
class IsometricBlockRenderer : public CBaseWidget {
public:
static constexpr std::pair<int, int> min_size = { 856, 480 };
const QubelTestWindowSettings* settings;
glez::texture texture;
IsometricBlockRenderer(IWidget* parent, QubelTestWindowSettings* settings)
: CBaseWidget("qubelmesh_test_renderer_isometric_block_test", parent)
, settings(settings) {
assert(settings && world_slice);
this->texture = glez::texture::loadFromMemory(embeded_logo_png_rgba.data.begin, embeded_logo_png_rgba.data.size, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height);
this->SetSize(500, 500);
}
virtual void Draw(ICanvas* the_drawing_machine) override {
this->CBaseWidget::Draw(the_drawing_machine);
o
TranslationMatrix
Offset(TranslationMatrix tm) {
return { this->offset + tm.first, tm.second };
// virtual void Rect(TranslationMatrix tm, glez::rgba color, glez::texture& tx) override {
this->parent->Rect({ tm->GetOffset() + tm.first, tm.second }, color, tx);
}
}
virtual void Update() override {
this->CBaseWidget::Update();
if (current_render_quads.empty()) {
if (world_slice->IsEmpty())
return;
current_render_quads = world_slice->MeshChunk(FalseChunk::MesherComplexity(settings->dropdown->Value()));
if (FalseChunk::gfx_mesher_debuglog) {
std::pair<int, int> found_size;
for (const FalseChunk::ChunkMeshedQuad& kinda_a_vert : current_render_quads) {
const auto max_coord = kinda_a_vert.quad.GetMax();
if (max_coord.x > found_size.first)
found_size.first = max_coord.x;
if (max_coord.y > found_size.second)
found_size.second = max_coord.y;
}
std::cout << "Created mesh with pixel size: " << found_size.first << ", " << found_size.second << std::endl;
}
}
}
};
IsometricBlockRenderer* renderer_isometric_block;
SkyRenderer* renderer_skybox;
public:
MeshingTestRenderingWindow(IWidget* parent, QubelMeshingTestWindow* settings)
: CBaseWindow(parent, "qubelmesh_test_renderer_frame")
, settings(settings) {
assert(settings);
@ -1029,10 +1117,10 @@ public:
virtual bool IsVisible() const override {
return this->settings->activate->Value() && this->CBaseWindow::IsVisible();
}
public:
// std::chrono::time_point<std::chrono::system_clock> last_update;
};
} // namespace isometric*/
} // namespace qubel
int start_nyqubel_client() {
auto client_rendering_thread = std::thread([&]() {
@ -1057,13 +1145,13 @@ int start_nyqubel_client() {
canvas->Add<ncc::Logo>()->SetOffset(500, 525);
auto mesh_test_settings_window = canvas->Add<QubelMeshingTestWindow>();
auto mesh_test_rendering_window = canvas->Add<QubelMeshingTestRenderingWindow>(mesh_test_settings_window);
mesh_test_settings_window->SetOffset(2000, 400);
mesh_test_rendering_window->SetOffset(3000, 800);
auto test_settings_window = canvas->Add<qubel::test::WindowSettings>();
auto rendering_window = canvas->Add<qubel::topdown::RenderingWindow>(test_settings_window);
test_settings_window->SetOffset(2000, 400);
rendering_window->SetOffset(3000, 800);
bool client_exiting = false;
mesh_test_settings_window->Add<CBaseButton>("exit_button", "Press to Quit-rite", [&](CBaseButton*) {
test_settings_window->Add<CBaseButton>("exit_button", "Press to Quit-rite", [&](CBaseButton*) {
client_exiting = true;
std::cout << "User Requested Client quit." << std::endl;
});