Organization
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <JUI/Widgets/Slider.hpp>
|
#include <JUI/Widgets/Slider.hpp>
|
||||||
#include <JUI/Base/TextBase.hpp>
|
#include <JUI/Base/TextBase.hpp>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
namespace TestGame
|
namespace TestGame
|
||||||
{
|
{
|
||||||
@@ -100,44 +101,12 @@ namespace TestGame
|
|||||||
/// This is performed after translating the origin to the center of the screen.
|
/// This is performed after translating the origin to the center of the screen.
|
||||||
void ApplyCameraTransformation();
|
void ApplyCameraTransformation();
|
||||||
|
|
||||||
void DrawLevel(const Level* level) const
|
void DrawLevel(const Level* level) const;
|
||||||
{
|
|
||||||
for (const auto* layer : level->layers)
|
|
||||||
{
|
|
||||||
DrawLayer(layer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Draw objects with the camera projection, as if they are in world-space.
|
/// Draw objects with the camera projection, as if they are in world-space.
|
||||||
void DrawWorldSpace() {
|
void DrawWorldSpace();
|
||||||
|
|
||||||
if (!data_ready) return; // Don't try to draw the level if not loaded.
|
void Render();
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma region ReWindow Overrides
|
#pragma region ReWindow Overrides
|
||||||
void OnRefresh(float elapsed) override
|
void OnRefresh(float elapsed) override
|
||||||
|
@@ -18,6 +18,22 @@ TestGame::TestGameAppWindow::~TestGameAppWindow() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct Range {
|
||||||
|
T min;
|
||||||
|
T max;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
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 <typename T>
|
||||||
|
T map(T value, const Range<T>& in, const Range<T>& out) {
|
||||||
|
return map(value, in.min, in.max, out.min, out.max);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestGame::TestGameAppWindow::CreateUI() {
|
void TestGame::TestGameAppWindow::CreateUI() {
|
||||||
using namespace JUI::UDimLiterals;
|
using namespace JUI::UDimLiterals;
|
||||||
@@ -299,3 +315,41 @@ void TestGame::TestGameAppWindow::ApplyCameraTransformation() {
|
|||||||
glScalef(camera.scale.current, camera.scale.current, 1);
|
glScalef(camera.scale.current, camera.scale.current, 1);
|
||||||
glTranslatef(-camera.translation.current.x, -camera.translation.current.y, 0);
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user