mirror of
https://github.com/kichikuou/system3-sdl2.git
synced 2026-09-30 10:58:07 +03:00
Emscripten: Expose sys_restart() function
This commit is contained in:
+20
-8
@@ -15,6 +15,7 @@
|
||||
#endif
|
||||
|
||||
SDL_Window* g_window;
|
||||
NACT* g_nact;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -36,13 +37,13 @@ int main(int argc, char *argv[])
|
||||
g_window = SDL_CreateWindow("Scenario Decoder SYSTEM3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 400, flags);
|
||||
|
||||
// system3 初期化
|
||||
NACT* nact = NACT::create(config);
|
||||
g_nact = NACT::create(config);
|
||||
|
||||
if (!config.save_dir.empty()) {
|
||||
std::string path = config.save_dir;
|
||||
if (path[path.size() - 1] == '@') {
|
||||
path.pop_back();
|
||||
const char* gid = nact->get_game_id();
|
||||
const char* gid = g_nact->get_game_id();
|
||||
if (gid) {
|
||||
path += gid;
|
||||
#ifdef WIN32
|
||||
@@ -55,17 +56,17 @@ int main(int argc, char *argv[])
|
||||
FILEIO::SetSaveDir(path);
|
||||
}
|
||||
|
||||
const char* title = nact->get_title();
|
||||
const char* title = g_nact->get_title();
|
||||
if (title) {
|
||||
char buf[128];
|
||||
sprintf_s(buf, 128, "Scenario Decoder SYSTEM%d: %s", nact->sys_ver, title);
|
||||
sprintf_s(buf, 128, "Scenario Decoder SYSTEM%d: %s", g_nact->sys_ver, title);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
EM_ASM_ARGS({ xsystem35.shell.setWindowTitle(UTF8ToString($0)); }, buf);
|
||||
#else
|
||||
SDL_SetWindowTitle(g_window, buf);
|
||||
#endif
|
||||
} else {
|
||||
WARNING("Cannot determine game id. crc32_a: %08x, crc32_b: %08x", nact->crc32_a, nact->crc32_b);
|
||||
WARNING("Cannot determine game id. crc32_a: %08x, crc32_b: %08x", g_nact->crc32_a, g_nact->crc32_b);
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -77,10 +78,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
bool restart = true;
|
||||
while (restart) {
|
||||
restart = nact->mainloop();
|
||||
delete nact;
|
||||
restart = g_nact->mainloop();
|
||||
delete g_nact;
|
||||
if (restart)
|
||||
nact = NACT::create(config);
|
||||
g_nact = NACT::create(config);
|
||||
}
|
||||
|
||||
SDL_DestroyWindow(g_window);
|
||||
@@ -88,3 +89,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
||||
extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
void sys_restart()
|
||||
{
|
||||
g_nact->quit(true);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+7
-1
@@ -137,6 +137,12 @@ bool NACT::mainloop()
|
||||
return restart_after_terminate;
|
||||
}
|
||||
|
||||
void NACT::quit(bool restart)
|
||||
{
|
||||
terminate = true;
|
||||
restart_after_terminate = restart;
|
||||
}
|
||||
|
||||
// コマンドパーサ
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE // Prevent inlining, because this function is listed in ASYNCIFY_ADD
|
||||
@@ -150,7 +156,7 @@ void NACT::execute()
|
||||
// 致命的なエラー発生 or 正常終了
|
||||
if(fatal_error) {
|
||||
if(!post_quit) {
|
||||
terminate = true;
|
||||
quit(false);
|
||||
}
|
||||
post_quit = true;
|
||||
return;
|
||||
|
||||
@@ -253,6 +253,7 @@ protected:
|
||||
public:
|
||||
bool mainloop();
|
||||
void sys_sleep(int ms);
|
||||
void quit(bool restart);
|
||||
|
||||
int get_screen_height();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ void NACT::pump_events()
|
||||
|
||||
switch (e.type) {
|
||||
case SDL_QUIT:
|
||||
terminate = true;
|
||||
quit(false);
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
|
||||
@@ -175,10 +175,10 @@ bool NACT::handle_platform_event(const SDL_Event& e)
|
||||
save_screenshot(ags);
|
||||
break;
|
||||
case ID_RESTART:
|
||||
terminate = restart_after_terminate = true;
|
||||
quit(true);
|
||||
break;
|
||||
case ID_EXIT:
|
||||
terminate = true;
|
||||
quit(false);
|
||||
break;
|
||||
case ID_SCREEN_WINDOW:
|
||||
SDL_SetWindowFullscreen(g_window, 0);
|
||||
|
||||
Reference in New Issue
Block a user