From 04d7f1ecf6f78f64c37001b6f3471bdb90b0b246 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 7 Nov 2022 20:30:34 +0100 Subject: Extracted Window to own class --- kurator/CMakeLists.txt | 1 + kurator/src/Session.cpp | 16 +++++++++------- kurator/src/Session.h | 4 +++- kurator/src/Window.cpp | 31 +++++++++++++++++++++++++++++++ kurator/src/Window.h | 17 +++++++++++++++++ kurator/src/main.cpp | 10 ++-------- 6 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 kurator/src/Window.cpp create mode 100644 kurator/src/Window.h diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt index 0250b9d..cf37f69 100644 --- a/kurator/CMakeLists.txt +++ b/kurator/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable( src/Skybox.cpp src/SkyboxTest.cpp src/Title.cpp + src/Window.cpp ) target_link_libraries( ${PROJECT_NAME} diff --git a/kurator/src/Session.cpp b/kurator/src/Session.cpp index 07b19f1..9bb5de3 100644 --- a/kurator/src/Session.cpp +++ b/kurator/src/Session.cpp @@ -19,14 +19,16 @@ Session::set(std::shared_ptr _scene) void -Session::loop() +Session::run() { - if (!scene) - return; - scene->update(GetFrameTime()); - BeginDrawing(); - scene->draw(); - EndDrawing(); + while (!window.should_close()) { + if (!scene) + return; + scene->update(GetFrameTime()); + BeginDrawing(); + scene->draw(); + EndDrawing(); + } } diff --git a/kurator/src/Session.h b/kurator/src/Session.h index cc8a4ee..43f5747 100644 --- a/kurator/src/Session.h +++ b/kurator/src/Session.h @@ -3,6 +3,7 @@ #include #include "Scene.h" +#include "Window.h" namespace kurator @@ -13,8 +14,9 @@ class Session { public: void set(std::shared_ptr _scene); - void loop(); + void run(); private: + Window window; std::shared_ptr scene; }; diff --git a/kurator/src/Window.cpp b/kurator/src/Window.cpp new file mode 100644 index 0000000..5711243 --- /dev/null +++ b/kurator/src/Window.cpp @@ -0,0 +1,31 @@ +#include "Window.h" + +#include + + +namespace kurator +{ + + +Window::Window() +{ + InitWindow(800, 600, "Kurator"); + SetWindowState(FLAG_WINDOW_RESIZABLE); + SetTargetFPS(60); +} + + +Window::~Window() +{ + CloseWindow(); +} + + +bool +Window::should_close() const +{ + return WindowShouldClose(); +} + + +} // namespace kurator diff --git a/kurator/src/Window.h b/kurator/src/Window.h new file mode 100644 index 0000000..2d1e58b --- /dev/null +++ b/kurator/src/Window.h @@ -0,0 +1,17 @@ +#pragma once + + +namespace kurator +{ + + +class Window +{ +public: + Window(); + ~Window(); + bool should_close() const; +}; + + +} // namespace kurator diff --git a/kurator/src/main.cpp b/kurator/src/main.cpp index 112be1a..1a4c325 100644 --- a/kurator/src/main.cpp +++ b/kurator/src/main.cpp @@ -1,7 +1,5 @@ #include -#include - #include "Session.h" #include "Title.h" @@ -9,11 +7,7 @@ int main(int, char*[]) { - InitWindow(800, 600, "Kurator"); auto session = std::make_shared(); - auto title = std::make_shared(session); - session->set(title); - while (!WindowShouldClose()) - session->loop(); - CloseWindow(); + session->set(std::make_shared(session)); + session->run(); } -- cgit v1.1