[update] Implemented the exception handling for sjplayer's standalone app.
This commit is contained in:
parent
111c98bea2
commit
d66764e9b4
@ -1,8 +1,6 @@
|
|||||||
/// License: MIT
|
/// License: MIT
|
||||||
module sjplayer.ScriptRuntimeException;
|
module sjplayer.ScriptRuntimeException;
|
||||||
|
|
||||||
import sjscript;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
class ScriptRuntimeException : Exception {
|
class ScriptRuntimeException : Exception {
|
||||||
public:
|
public:
|
||||||
|
@ -6,8 +6,11 @@ import gl4d;
|
|||||||
import sjscript;
|
import sjscript;
|
||||||
|
|
||||||
public {
|
public {
|
||||||
|
import sjscript : ScriptException;
|
||||||
|
|
||||||
import sjplayer.Context,
|
import sjplayer.Context,
|
||||||
sjplayer.ProgramSet;
|
sjplayer.ProgramSet,
|
||||||
|
sjplayer.ScriptRuntimeException;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
@ -20,15 +20,22 @@ int main(string[] args) {
|
|||||||
|
|
||||||
auto music = sfMusic_createFromFile(music_file.toStringz).enforce;
|
auto music = sfMusic_createFromFile(music_file.toStringz).enforce;
|
||||||
scope(exit) sfMusic_destroy(music);
|
scope(exit) sfMusic_destroy(music);
|
||||||
sfMusic_play(music);
|
|
||||||
|
|
||||||
auto programs = new ProgramSet;
|
auto programs = new ProgramSet;
|
||||||
scope(exit) programs.destroy();
|
scope(exit) programs.destroy();
|
||||||
|
|
||||||
auto context = script_file.readText.
|
Context context;
|
||||||
|
try {
|
||||||
|
context = script_file.readText.
|
||||||
CreateContextFromText(vec2i(600, 600), programs);
|
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();
|
scope(exit) context.destroy();
|
||||||
|
|
||||||
|
sfMusic_play(music);
|
||||||
while (true) {
|
while (true) {
|
||||||
sfEvent e;
|
sfEvent e;
|
||||||
sfWindow_pollEvent(win, &e);
|
sfWindow_pollEvent(win, &e);
|
||||||
@ -39,7 +46,14 @@ int main(string[] args) {
|
|||||||
|
|
||||||
context.actor.Accelarate(GetAccelarationInput());
|
context.actor.Accelarate(GetAccelarationInput());
|
||||||
|
|
||||||
|
try {
|
||||||
context.OperateScheduledControllers(beat);
|
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.actor.Update();
|
||||||
context.posteffect.Update();
|
context.posteffect.Update();
|
||||||
|
|
||||||
@ -48,7 +62,7 @@ int main(string[] args) {
|
|||||||
"damage: %f (%f)".writefln(dmg.damage, beat);
|
"damage: %f (%f)".writefln(dmg.damage, beat);
|
||||||
}
|
}
|
||||||
if (dmg.nearness != 0) {
|
if (dmg.nearness != 0) {
|
||||||
"nearness: %f (%f)".writefln(dmg.nearness, beat);
|
"nearby: %f (%f)".writefln(dmg.nearness, beat);
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.Clear(GL_COLOR_BUFFER_BIT);
|
gl.Clear(GL_COLOR_BUFFER_BIT);
|
||||||
|
Reference in New Issue
Block a user