From bcd1c86318c4e89110874e1d89a6869acec7cca5 Mon Sep 17 00:00:00 2001 From: dawsh Date: Mon, 23 Jun 2025 21:12:07 -0500 Subject: [PATCH] Organization --- include/TestGame/TestGameApp.hpp | 41 +++--------------------- src/TestGame/TestGameApp.cpp | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/include/TestGame/TestGameApp.hpp b/include/TestGame/TestGameApp.hpp index 01fedcd..0d2b6ae 100644 --- a/include/TestGame/TestGameApp.hpp +++ b/include/TestGame/TestGameApp.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace TestGame { @@ -100,44 +101,12 @@ namespace TestGame /// This is performed after translating the origin to the center of the screen. void ApplyCameraTransformation(); - void DrawLevel(const Level* level) const - { - for (const auto* layer : level->layers) - { - DrawLayer(layer); - } - } + void DrawLevel(const Level* level) const; - /// Draw objects with the camera projection, as if they are in world-space. - void DrawWorldSpace() { + /// Draw objects with the camera projection, as if they are in world-space. + void DrawWorldSpace(); - if (!data_ready) return; // Don't try to draw the level if not loaded. - - DrawLevel(loaded_level); - - for (auto* entity : entities) { - entity->Draw(); - } - } - - void Render() { - glClearColor(0, 0, 0, 1); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - J2D::Begin(); - { - glPushMatrix(); - { - ApplyCameraTransformation(); - DrawWorldSpace(); - } - glPopMatrix(); - } - - J2D::End(); - - scene->Draw(); - - } + void Render(); #pragma region ReWindow Overrides void OnRefresh(float elapsed) override diff --git a/src/TestGame/TestGameApp.cpp b/src/TestGame/TestGameApp.cpp index dda4cd3..e88ee05 100644 --- a/src/TestGame/TestGameApp.cpp +++ b/src/TestGame/TestGameApp.cpp @@ -18,6 +18,22 @@ TestGame::TestGameAppWindow::~TestGameAppWindow() { } +template +struct Range { + T min; + T max; +}; + +template +T map(T value, T in_min, T in_max, T out_min, T out_max) { + return (value - in_min) / (in_max - in_min) * (out_max - out_min) + out_min; +} + +template +T map(T value, const Range& in, const Range& out) { + return map(value, in.min, in.max, out.min, out.max); +} + void TestGame::TestGameAppWindow::CreateUI() { using namespace JUI::UDimLiterals; @@ -299,3 +315,41 @@ void TestGame::TestGameAppWindow::ApplyCameraTransformation() { glScalef(camera.scale.current, camera.scale.current, 1); glTranslatef(-camera.translation.current.x, -camera.translation.current.y, 0); } + +void TestGame::TestGameAppWindow::DrawLevel(const Level *level) const { + /// Draw top layers last. + for (const auto* layer : std::ranges::views::reverse(level->layers)) + { + DrawLayer(layer); + } +} + +void TestGame::TestGameAppWindow::DrawWorldSpace() { + + if (!data_ready) return; // Don't try to draw the level if not loaded. + + DrawLevel(loaded_level); + + for (auto* entity : entities) { + entity->Draw(); + } +} + +void TestGame::TestGameAppWindow::Render() { + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + J2D::Begin(); + { + glPushMatrix(); + { + ApplyCameraTransformation(); + DrawWorldSpace(); + } + glPopMatrix(); + } + + J2D::End(); + + scene->Draw(); + +}