Catch and wrap game-loop errors and send them through the UI when available. much nicer than having to check the console
parent
b006ecba23
commit
d940e1b91f
|
@ -1,5 +1,5 @@
|
|||
USING: accessors calendar destructors kernel math math.order namespaces
|
||||
system threads ;
|
||||
USING: accessors calendar continuations destructors kernel math
|
||||
math.order namespaces system threads ui ui.gadgets.worlds ;
|
||||
IN: game-loop
|
||||
|
||||
TUPLE: game-loop
|
||||
|
@ -27,6 +27,16 @@ SYMBOL: game-loop
|
|||
|
||||
CONSTANT: MAX-FRAMES-TO-SKIP 5
|
||||
|
||||
DEFER: stop-loop
|
||||
|
||||
TUPLE: game-loop-error game-loop error ;
|
||||
|
||||
: ?ui-error ( error -- )
|
||||
ui-running? [ ui-error ] [ rethrow ] if ;
|
||||
|
||||
: game-loop-error ( game-loop error -- )
|
||||
[ drop stop-loop ] [ \ game-loop-error boa ?ui-error ] 2bi ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: redraw ( loop -- )
|
||||
|
@ -54,7 +64,9 @@ CONSTANT: MAX-FRAMES-TO-SKIP 5
|
|||
[ drop ] if ;
|
||||
|
||||
: run-loop ( loop -- )
|
||||
dup game-loop [ (run-loop) ] with-variable ;
|
||||
dup game-loop
|
||||
[ [ (run-loop) ] [ game-loop-error ] recover ]
|
||||
with-variable ;
|
||||
|
||||
: benchmark-millis ( loop -- millis )
|
||||
millis swap benchmark-time>> - ;
|
||||
|
@ -91,3 +103,6 @@ PRIVATE>
|
|||
M: game-loop dispose
|
||||
stop-loop ;
|
||||
|
||||
USING: vocabs vocabs.loader ;
|
||||
|
||||
"prettyprint" vocab [ "game-loop.prettyprint" require ] when
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
! (c)2009 Joe Groff bsd license
|
||||
USING: accessors debugger game-loop io ;
|
||||
IN: game-loop.prettyprint
|
||||
|
||||
M: game-loop-error error.
|
||||
"An error occurred inside a game loop." print
|
||||
"The game loop has been stopped to prevent runaway errors." print
|
||||
"The error was:" print nl
|
||||
error>> error. ;
|
Loading…
Reference in New Issue