From f20d7a43b1a8dd1349f0edaee6ef90eed20cbfd1 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 4 May 2020 22:51:21 +0530 Subject: [PATCH] Remove main update loop --- binding-mruby/binding-mruby.cpp | 37 ++++----------------------------- src/main.cpp | 15 +++---------- 2 files changed, 7 insertions(+), 45 deletions(-) diff --git a/binding-mruby/binding-mruby.cpp b/binding-mruby/binding-mruby.cpp index 5b824df..24d5dfe 100644 --- a/binding-mruby/binding-mruby.cpp +++ b/binding-mruby/binding-mruby.cpp @@ -50,10 +50,6 @@ #include "mrb-ext/marshal.h" #include "mrb-ext/file-helper.h" -#ifdef __EMSCRIPTEN__ -#include -#endif - #include static void mrbBindingExecute(); @@ -253,14 +249,6 @@ runMrbFile(mrb_state *mrb, const char *filename) fclose(f); } -mrb_state * static_mrb; -mrb_state * static_scriptmrb; -mrbc_context * static_ctx; - -void main_update_loop() { - mrb_load_nstring_cxt(static_mrb, "main_update_loop", 16, NULL); -} - static void runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) { @@ -368,23 +356,8 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) return; } } - static_mrb = mrb; - static_scriptmrb = scriptMrb; -#ifdef __EMSCRIPTEN__ - /* Use loop for emscripten */ - main_update_loop(); - checkException(static_mrb); - emscripten_set_main_loop(main_update_loop, 0, 0); -#else - while (true) { - main_update_loop(); - SDL_Delay(3); - if (static_mrb->exc) - break; - } mrb_close(scriptMrb); -#endif } static void mrbBindingExecute() @@ -401,19 +374,18 @@ static void mrbBindingExecute() mrbBindingInit(mrb); - static_ctx = mrbc_context_new(mrb); - static_ctx->capture_errors = 1; + mrbc_context * ctx = mrbc_context_new(mrb); + ctx->capture_errors = 1; const Config &conf = shState->rtData().config; const std::string &customScript = conf.customScript; (void) runMrbFile; // FIXME mrbFile support on ice for now if (!customScript.empty()) - runCustomScript(mrb, static_ctx, customScript.c_str()); + runCustomScript(mrb, ctx, customScript.c_str()); else - runRMXPScripts(mrb, static_ctx); + runRMXPScripts(mrb, ctx); -#ifndef __EMSCRIPTEN__ checkException(mrb); shState->rtData().rqTermAck.set(); @@ -421,7 +393,6 @@ static void mrbBindingExecute() mrbc_context_free(mrb, ctx); mrb_close(mrb); -#endif } static void mrbBindingTerminate() diff --git a/src/main.cpp b/src/main.cpp index c67b91f..6aa66b9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -137,10 +137,12 @@ int rgssThreadFun(void *userdata) return 0; } + bool vsync = conf.vsync || conf.syncToRefreshrate; + SDL_GL_SetSwapInterval(vsync ? 1 : 0); + /* Start script execution */ scriptBinding->execute(); -#ifndef __EMSCRIPTEN__ threadData->rqTermAck.set(); threadData->ethread->requestTerminate(); @@ -148,10 +150,6 @@ int rgssThreadFun(void *userdata) alcDestroyContext(alcCtx); SDL_GL_DeleteContext(glCtx); -#endif - - bool vsync = conf.vsync || conf.syncToRefreshrate; - SDL_GL_SetSwapInterval(vsync ? 1 : 0); return 0; } @@ -331,15 +329,8 @@ int main(int argc, char *argv[]) /* Start event processing */ eventThread.process(rtData); -#ifdef __EMSCRIPTEN__ - ::rgssThreadFun(&rtData); - printf("Exiting main function\n"); - return 0; -#endif - /* Start RGSS thread */ rgssThreadFun(&rtData); - return 0; /* Request RGSS thread to stop */ rtData.rqTerm.set();