TestGame build

This commit is contained in:
2025-06-09 20:11:03 -05:00
parent 410b52c6bb
commit aae8ff5c3f
6 changed files with 140 additions and 21 deletions

View File

@@ -28,7 +28,6 @@ CPMAddPackage(NAME mcolor
CPMAddPackage(NAME jlog
URL https://git.redacted.cc/josh/jlog/archive/Prerelease-18.zip)
CPMAddPackage(NAME Event
URL https://git.redacted.cc/josh/Event/archive/Release-12.zip)
@@ -42,10 +41,10 @@ CPMAddPackage(NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-32.zip)
CPMAddPackage(NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-55.zip)
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-58.zip)
CPMAddPackage(NAME JUI
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.zip)
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-6.2.zip)
if (UNIX)

View File

@@ -13,7 +13,7 @@ class LayerView : public JUI::Window
public:
LayerView() : JUI::Window()
{
this->SetTitle("Layers");
this->Title("Layers");
Name("LayerView");
scroller = new JUI::ScrollingRect(this->Content());

View File

@@ -127,7 +127,7 @@ protected:
/// @warning If the index is out of bounds, the returned coordinates might be invalid (e.g. negative)
Vector2i IndexToCell(int index) const;
inline int CellToIndex(int cx, int cy);
inline int CellToIndex(int cx, int cy) const;
/// Fill the tile-id lookup table with their respective partial-sprite bounding boxes.
void ComputeQuads();

View File

@@ -10,7 +10,7 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
{
// TODO: Implement JUI structure that makes blocks of text easy to impelement.
auto window = new JUI::Window(parent);
window->SetTitle("About Editor2D");
window->Title("About Editor2D");
window->Size({350_px, 375_px});
window->MinSize({350, 375});
@@ -21,9 +21,9 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
auto line_item = [&] (const std::string& text, int size = 20, const Color4& color = Colors::White) {
auto* content = new JUI::TextRect(layout);
content->Size({100_percent, JUI::UDim(size+5, 0)});
content->SetContent(text);
content->SetTextSize(size);
content->SetTextColor(color);
content->Content(text);
content->TextSize(size);
content->TextColor(color);
content->BGColor(Colors::Transparent);
content->AlignCenterHorizontally();
content->BorderWidth(0);
@@ -60,9 +60,9 @@ JUI::Window* EditorApp::CreateAppInfoDialogWindow(JUI::Widget* parent)
auto btn_item = [&] (const std::string& text) -> JUI::TextButton* {
JUI::TextButton* btn = new JUI::TextButton(btn_layout);
btn->SetContent(text);
btn->Content(text);
btn->Size({32_percent, 100_percent});
btn->SetTextColor(Colors::Black);
btn->TextColor(Colors::Black);
btn->Center();
return btn;
};
@@ -233,7 +233,7 @@ JUI::Window* EditorApp::CreateTilesetViewerWindow(JUI::Widget* parent)
using namespace JUI;
auto* wind = new Window(parent);
wind->SetTitle("Tileset Viewer");
wind->Title("Tileset Viewer");
wind->Size(JUI::UDim2::FromPixels(loaded_tilesheet->GetDimensions().x, loaded_tilesheet->GetDimensions().y+20));
wind->SetResizable(false);
@@ -343,7 +343,7 @@ void EditorApp::CreateWidgets()
topbar = new JUI::UtilityBar(scene);
auto* file = topbar->AddSubmenu("File");
file->SetFont(JGL::Fonts::Jupiteroid);
file->Font(JGL::Fonts::Jupiteroid);
auto* new_map = file->AddButton("New Map", [this] () mutable {

View File

@@ -139,7 +139,7 @@ Vector2i Tileset::IndexToCell(int index) const
return {index % rows, index / rows};
}
int Tileset::CellToIndex(int cx, int cy)
int Tileset::CellToIndex(int cx, int cy) const
{
return cy*rows + cx;
}

View File

@@ -2,11 +2,33 @@
#include "ReWindow/Logger.h"
#include <Data/Level.hpp>
#include <JGL/JGL.h>
#include <JUI/Widgets/FpsGraph.hpp>
#include <JUI/Widgets/Scene.hpp>
#include <JUI/Widgets/Window.hpp>
class GameEntity
{
};
class Player : public GameEntity
{
};
class TestGameAppWindow : public ReWindow::OpenGLWindow
{
public:
Level* level;
Level* loaded_level = nullptr;
Tileset* loaded_tileset = nullptr;
JGL::Texture* loaded_tilesheet = nullptr;
JUI::Scene* scene = nullptr;
bool data_ready = false;
TestGameAppWindow() : ReWindow::OpenGLWindow("TestGameAppWindow", 1024, 768, 2, 1)
{
@@ -15,6 +37,110 @@ public:
{
}
void Load()
{
using namespace JUI::UDimLiterals;
scene = new JUI::Scene();
auto* fps_graph_window = new JUI::Window(scene);
fps_graph_window->Size({500_px, 50_px});
auto* fps_graph = new JUI::FpsGraph(fps_graph_window->Content());
fps_graph->Size({500_px, 50_px});
// TODO: More sophisticated order-of-operations is required.
// 1. Initialize elements of widgets that are independent of the level itself / the level depends on.
// 2. Initialize the level.
// 3. Initialize widgets that are dependent on the level itself.
loaded_level = new Level(std::filesystem::path("level.json"));
loaded_tileset = new Tileset(std::filesystem::path(loaded_level->tileset_path));
loaded_tilesheet = new JGL::Texture(loaded_tileset->texture_path, FilteringMode::NEAREST);
for (auto layer : loaded_level->layers)
layer->Load();
data_ready = true;
}
bool Open() override
{
if (!OpenGLWindow::Open()) return false;
auto size = GetSize();
auto vec_size = Vector2i(size.x, size.y);
if (!JGL::Init(vec_size, 0.f, 1.f))
return false;
JGL::Update(vec_size);
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glDepthMask(GL_TRUE);
// TODO: Delete when we update to the next release of JGL
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // NOTE: This MUST be called for text rendering to work properly!!!
Load();
}
void Update(float elapsed)
{
scene->Update(elapsed);
}
void DrawLayer(const Layer* layer) const
{
for (int gx = 0; gx < layer->rows; gx++)
{
for (int gy = 0; gy < layer->cols; gy++)
{
auto quad_idx = layer->cells[gx][gy];
Vector2 pos(gx*layer->cell_width, gy*layer->cell_height);
if (quad_idx < 0)
continue;
auto quad = loaded_tileset->quads[quad_idx];
J2D::DrawPartialSprite(loaded_tilesheet, pos, Vector2(quad.x, quad.y), Vector2(quad.w, quad.h));
}
}
}
void DrawLevel(const Level* level) const
{
for (const auto* layer : level->layers)
{
DrawLayer(layer);
}
}
void Draw()
{
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
J2D::Begin();
if (data_ready)
DrawLevel(loaded_level);
J2D::End();
scene->Draw();
}
void OnRefresh(float elapsed) override
{
Update(elapsed);
Draw();
SwapBuffers();
}
};
int main()
@@ -26,16 +152,10 @@ int main()
bool success = app->Open();
if (!success)
{
return -1;
}
while (app->IsOpen())
{
app->ManagedRefresh();
}
app->Close();