-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
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 -- )
[ 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>> - ;
M: game-loop dispose
stop-loop ;
+USING: vocabs vocabs.loader ;
+
+"prettyprint" vocab [ "game-loop.prettyprint" require ] when
--- /dev/null
+! (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. ;