From 5b13577a54fbca7f6be95f2f3f7c6643437ae0cc Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 13 Jan 2024 15:47:27 +0100 Subject: [PATCH] Simplify main(). --- sfw/main.cpp | 12 +----------- sfw/render_core/application.cpp | 15 +++++++++++++++ sfw/render_core/application.h | 2 ++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/sfw/main.cpp b/sfw/main.cpp index 684c929..e7a681a 100644 --- a/sfw/main.cpp +++ b/sfw/main.cpp @@ -1,19 +1,9 @@ -#ifdef __EMSCRIPTEN__ -#include -#endif // __EMSCRIPTEN__ - #include "game_application.h" int main(int argc, char **argv) { Application *application = memnew(GameApplication()); -#ifdef __EMSCRIPTEN__ - emscripten_set_main_loop(&Application::main_loop_static, 0, 1); -#else - while (application->running) { - application->main_loop(); - } -#endif // __EMSCRIPTEN__ + application->start_main_loop(); memdelete(application); diff --git a/sfw/render_core/application.cpp b/sfw/render_core/application.cpp index cd1ece9..e4f4bc6 100644 --- a/sfw/render_core/application.cpp +++ b/sfw/render_core/application.cpp @@ -1,4 +1,9 @@ //--STRIP + +#ifdef __EMSCRIPTEN__ +#include +#endif // __EMSCRIPTEN__ + #include "render_core/application.h" #include "core/math_defs.h" @@ -30,6 +35,16 @@ void Application::render() { scene->render(); } +void Application::start_main_loop() { +#ifdef __EMSCRIPTEN__ + emscripten_set_main_loop(&Application::main_loop_static, 0, 1); +#else + while (running) { + main_loop(); + } +#endif // __EMSCRIPTEN__ +} + void Application::main_loop() { uint64_t start = STime::time_us(); diff --git a/sfw/render_core/application.h b/sfw/render_core/application.h index 26520c9..57578d6 100644 --- a/sfw/render_core/application.h +++ b/sfw/render_core/application.h @@ -38,6 +38,8 @@ public: virtual void update(float delta); virtual void render(); + void start_main_loop(); + uint64_t get_idle_frames() const { return _idle_frames; }