Simplify main().

This commit is contained in:
Relintai 2024-01-13 15:47:27 +01:00
parent e21dcb59c8
commit 5b13577a54
3 changed files with 18 additions and 11 deletions

View File

@ -1,19 +1,9 @@
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#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);

View File

@ -1,4 +1,9 @@
//--STRIP
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#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();

View File

@ -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;
}