diff --git a/sfw/render_core/application.cpp b/sfw/render_core/application.cpp index c7a6ddc..cd1ece9 100644 --- a/sfw/render_core/application.cpp +++ b/sfw/render_core/application.cpp @@ -36,7 +36,7 @@ void Application::main_loop() { AppWindow *w = AppWindow::get_singleton(); if (!w->frame_begin()) { // calls Application::main_loop() - w->shutdown(); + running = false; return; } diff --git a/sfw/render_core/window.cpp b/sfw/render_core/window.cpp index f2c73e0..5c32bb4 100644 --- a/sfw/render_core/window.cpp +++ b/sfw/render_core/window.cpp @@ -145,7 +145,7 @@ void AppWindow::glfw_error_callback(int error, const char *description) { CRASH_MSG(String(description) + " (error " + String::num(error) + ")"); } -void AppWindow::glfw_quit(void) { +void AppWindow::glfw_quit() { glfwTerminate(); } @@ -493,32 +493,10 @@ void AppWindow::frame_swap() { // emscripten_webgl_commit_frame(); } -void AppWindow::shutdown() { - loop_exit(); // finish emscripten loop automatically -} - void AppWindow::reset_viewport() { glViewport(0, 0, width, height); } -int AppWindow::swap() { - // end frame - if (frame_count > 0) { - frame_end(); - frame_swap(); - } - - ++frame_count; - - // begin frame - int ready = frame_begin(); - if (!ready) { - shutdown(); - return 0; - } - return 1; -} - void AppWindow::resize() { #ifdef __EMSCRIPTEN__ EM_ASM(canvas.canResize = 0); @@ -537,37 +515,6 @@ void AppWindow::resize() { #endif /* __EMSCRIPTEN__ */ } -void AppWindow::loop_wrapper(void *loopArg) { - AppWindow *w = AppWindow::get_singleton(); - if (w->frame_begin()) { - w->resize(); - w->render_callback(loopArg); - w->frame_end(); - w->frame_swap(); - } else { - w->shutdown(); - } -} - -void AppWindow::loop(void (*user_function)(void *loopArg), void *loopArg) { -#ifdef __EMSCRIPTEN__ - render_callback = user_function; - emscripten_set_main_loop_arg(window_loop_wrapper, loopArg, 0, 1); -#else - keep_running = true; - while (keep_running) - user_function(loopArg); -#endif /* __EMSCRIPTEN__ */ -} - -void AppWindow::loop_exit() { -#ifdef __EMSCRIPTEN__ - emscripten_cancel_main_loop(); -#else - keep_running = false; -#endif /* __EMSCRIPTEN__ */ -} - Vector2 AppWindow::get_canvas() { #ifdef __EMSCRIPTEN__ int width = EM_ASM_INT_V(return canvas.width); @@ -985,8 +932,6 @@ AppWindow::AppWindow() { _cursorshape = 1; - render_callback = NULL; - width = 0; height = 0; keep_running = true; diff --git a/sfw/render_core/window.h b/sfw/render_core/window.h index 58f850c..e43dc68 100644 --- a/sfw/render_core/window.h +++ b/sfw/render_core/window.h @@ -45,10 +45,6 @@ public: int frame_begin(); void frame_end(); void frame_swap(); - int swap(); // single function that combines above functions (desktop only) - - void loop(void (*function)(void *loopArg), void *loopArg); // run main loop function continuously (emscripten only) - void loop_exit(); // exit from main loop function (emscripten only) void set_title(const char *title); void set_color(unsigned color); @@ -62,9 +58,6 @@ public: double get_time(); double get_delta(); - // bool hook(void (*func)(), void* userdata); // deprecated - // void unhook(void (*func)()); // deprecated - void set_focus(); // window attribute using haz catz language for now int has_focus(); @@ -105,8 +98,6 @@ public: void fps_lock(float fps); void fps_unlock(); - void shutdown(); - void reset_viewport(); Vector2 dpi(); @@ -140,7 +131,6 @@ protected: static void window_hints(unsigned flags); GLFWmonitor *find_monitor(int wx, int wy); void resize(); - static void loop_wrapper(void *loopArg); void glNewFrame(); double get_scale(); void create_default_cursors(); @@ -172,7 +162,6 @@ protected: int _cursorshape = 1; - void (*render_callback)(void *loopArg); Vector2 last_canvas_size; int width;