From d66764e9b4c2ef57f8fe37952ca1dd6db15816e0 Mon Sep 17 00:00:00 2001 From: falsycat Date: Thu, 10 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Implemented the exception handling for sjplayer's standalone app. --- .../src/sjplayer/ScriptRuntimeException.d | 2 -- sjplayer/src/sjplayer/package.d | 5 +++- sjplayer/standalone/main.d | 24 +++++++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/sjplayer/src/sjplayer/ScriptRuntimeException.d b/sjplayer/src/sjplayer/ScriptRuntimeException.d index 0eaf3a7..303a961 100644 --- a/sjplayer/src/sjplayer/ScriptRuntimeException.d +++ b/sjplayer/src/sjplayer/ScriptRuntimeException.d @@ -1,8 +1,6 @@ /// License: MIT module sjplayer.ScriptRuntimeException; -import sjscript; - /// class ScriptRuntimeException : Exception { public: diff --git a/sjplayer/src/sjplayer/package.d b/sjplayer/src/sjplayer/package.d index 8cc3f53..ae563c8 100644 --- a/sjplayer/src/sjplayer/package.d +++ b/sjplayer/src/sjplayer/package.d @@ -6,8 +6,11 @@ import gl4d; import sjscript; public { + import sjscript : ScriptException; + import sjplayer.Context, - sjplayer.ProgramSet; + sjplayer.ProgramSet, + sjplayer.ScriptRuntimeException; } /// diff --git a/sjplayer/standalone/main.d b/sjplayer/standalone/main.d index ca78a5d..fc3dade 100644 --- a/sjplayer/standalone/main.d +++ b/sjplayer/standalone/main.d @@ -20,15 +20,22 @@ int main(string[] args) { auto music = sfMusic_createFromFile(music_file.toStringz).enforce; scope(exit) sfMusic_destroy(music); - sfMusic_play(music); auto programs = new ProgramSet; scope(exit) programs.destroy(); - auto context = script_file.readText. - CreateContextFromText(vec2i(600, 600), programs); + Context context; + try { + context = script_file.readText. + CreateContextFromText(vec2i(600, 600), programs); + } catch (ScriptException e) { + "[parsing exception] %s at (%d,%d)". + writefln(e.msg, e.pos.stline+1, e.pos.stchar+1); + return 1; + } scope(exit) context.destroy(); + sfMusic_play(music); while (true) { sfEvent e; sfWindow_pollEvent(win, &e); @@ -39,7 +46,14 @@ int main(string[] args) { context.actor.Accelarate(GetAccelarationInput()); - context.OperateScheduledControllers(beat); + try { + context.OperateScheduledControllers(beat); + } catch (ScriptRuntimeException e) { + "[runtime exception] %s at (%d,%d)". + writefln(e.msg, e.srcline+1, e.srcchar+1); + return 1; + } + context.actor.Update(); context.posteffect.Update(); @@ -48,7 +62,7 @@ int main(string[] args) { "damage: %f (%f)".writefln(dmg.damage, beat); } if (dmg.nearness != 0) { - "nearness: %f (%f)".writefln(dmg.nearness, beat); + "nearby: %f (%f)".writefln(dmg.nearness, beat); } gl.Clear(GL_COLOR_BUFFER_BIT);