Remove main update loop

This commit is contained in:
Varun Patil 2020-05-04 22:51:21 +05:30
parent b7c8011c52
commit f20d7a43b1
2 changed files with 7 additions and 45 deletions

View File

@ -50,10 +50,6 @@
#include "mrb-ext/marshal.h" #include "mrb-ext/marshal.h"
#include "mrb-ext/file-helper.h" #include "mrb-ext/file-helper.h"
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
#include <stdio.h> #include <stdio.h>
static void mrbBindingExecute(); static void mrbBindingExecute();
@ -253,14 +249,6 @@ runMrbFile(mrb_state *mrb, const char *filename)
fclose(f); 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 static void
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx) runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
{ {
@ -368,23 +356,8 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
return; 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); mrb_close(scriptMrb);
#endif
} }
static void mrbBindingExecute() static void mrbBindingExecute()
@ -401,19 +374,18 @@ static void mrbBindingExecute()
mrbBindingInit(mrb); mrbBindingInit(mrb);
static_ctx = mrbc_context_new(mrb); mrbc_context * ctx = mrbc_context_new(mrb);
static_ctx->capture_errors = 1; ctx->capture_errors = 1;
const Config &conf = shState->rtData().config; const Config &conf = shState->rtData().config;
const std::string &customScript = conf.customScript; const std::string &customScript = conf.customScript;
(void) runMrbFile; // FIXME mrbFile support on ice for now (void) runMrbFile; // FIXME mrbFile support on ice for now
if (!customScript.empty()) if (!customScript.empty())
runCustomScript(mrb, static_ctx, customScript.c_str()); runCustomScript(mrb, ctx, customScript.c_str());
else else
runRMXPScripts(mrb, static_ctx); runRMXPScripts(mrb, ctx);
#ifndef __EMSCRIPTEN__
checkException(mrb); checkException(mrb);
shState->rtData().rqTermAck.set(); shState->rtData().rqTermAck.set();
@ -421,7 +393,6 @@ static void mrbBindingExecute()
mrbc_context_free(mrb, ctx); mrbc_context_free(mrb, ctx);
mrb_close(mrb); mrb_close(mrb);
#endif
} }
static void mrbBindingTerminate() static void mrbBindingTerminate()

View File

@ -137,10 +137,12 @@ int rgssThreadFun(void *userdata)
return 0; return 0;
} }
bool vsync = conf.vsync || conf.syncToRefreshrate;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
/* Start script execution */ /* Start script execution */
scriptBinding->execute(); scriptBinding->execute();
#ifndef __EMSCRIPTEN__
threadData->rqTermAck.set(); threadData->rqTermAck.set();
threadData->ethread->requestTerminate(); threadData->ethread->requestTerminate();
@ -148,10 +150,6 @@ int rgssThreadFun(void *userdata)
alcDestroyContext(alcCtx); alcDestroyContext(alcCtx);
SDL_GL_DeleteContext(glCtx); SDL_GL_DeleteContext(glCtx);
#endif
bool vsync = conf.vsync || conf.syncToRefreshrate;
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
return 0; return 0;
} }
@ -331,15 +329,8 @@ int main(int argc, char *argv[])
/* Start event processing */ /* Start event processing */
eventThread.process(rtData); eventThread.process(rtData);
#ifdef __EMSCRIPTEN__
::rgssThreadFun(&rtData);
printf("Exiting main function\n");
return 0;
#endif
/* Start RGSS thread */ /* Start RGSS thread */
rgssThreadFun(&rtData); rgssThreadFun(&rtData);
return 0;
/* Request RGSS thread to stop */ /* Request RGSS thread to stop */
rtData.rqTerm.set(); rtData.rqTerm.set();