-! (c)2009 Joe Groff bsd license
-USING: accessors combinators fry game.input game.loop generic kernel math
-parser sequences ui ui.gadgets ui.gadgets.worlds ui.gestures threads
-words audio.engine destructors ;
+! Copyright (C) 2009 Joe Groff.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors audio.engine combinators concurrency.promises
+destructors game.input game.loop kernel math parser sequences
+threads ui ui.gadgets ui.gadgets.worlds vocabs.parser
+words.constant ;
IN: game.worlds
TUPLE: game-world < world
game-loop
audio-engine
- { tick-interval-micros fixnum }
+ { tick-interval-nanos integer }
{ use-game-input? boolean }
{ use-audio-engine? boolean }
{ audio-engine-device initial: f }
{ audio-engine-voice-count initial: 16 }
- { audio-engine-buffer-size initial: 8192 }
- { audio-engine-buffer-count initial: 2 }
{ tick-slice float initial: 0.0 } ;
GENERIC: begin-game-world ( world -- )
{
[ audio-engine-device>> ]
[ audio-engine-voice-count>> ]
- [ audio-engine-buffer-size>> ]
- [ audio-engine-buffer-count>> ]
} cleave <audio-engine>
[ start-audio* ] keep ; inline
M: game-world begin-world
dup use-game-input?>> [ open-game-input ] when
dup use-audio-engine?>> [ dup open-game-audio-engine >>audio-engine ] when
- dup begin-game-world
- dup [ tick-interval-micros>> ] [ ] bi <game-loop> [ >>game-loop ] keep start-loop
- drop ;
+ dup [ tick-interval-nanos>> ] [ ] bi <game-loop>
+ [ >>game-loop begin-game-world ] keep start-loop ;
M: game-world end-world
- [ [ stop-loop ] when* f ] change-game-loop
+ dup game-loop>> [ stop-loop ] when*
[ end-game-world ]
[ audio-engine>> [ dispose ] when* ]
[ use-game-input?>> [ close-game-input ] when ] tri ;
TUPLE: game-attributes < world-attributes
- { tick-interval-micros fixnum }
+ { tick-interval-nanos integer }
{ use-game-input? boolean initial: f }
{ use-audio-engine? boolean initial: f }
{ audio-engine-device initial: f }
- { audio-engine-voice-count initial: 16 }
- { audio-engine-buffer-size initial: 8192 }
- { audio-engine-buffer-count initial: 2 } ;
+ { audio-engine-voice-count initial: 16 } ;
M: game-world apply-world-attributes
{
- [ tick-interval-micros>> >>tick-interval-micros ]
+ [ tick-interval-nanos>> >>tick-interval-nanos ]
[ use-game-input?>> >>use-game-input? ]
[ use-audio-engine?>> >>use-audio-engine? ]
[ audio-engine-device>> >>audio-engine-device ]
[ audio-engine-voice-count>> >>audio-engine-voice-count ]
- [ audio-engine-buffer-size>> >>audio-engine-buffer-size ]
- [ audio-engine-buffer-count>> >>audio-engine-buffer-count ]
[ call-next-method ]
} cleave ;
+: start-game ( attributes -- game-world )
+ f swap open-window* ;
+
+: wait-game ( attributes -- game-world )
+ f swap open-window* dup promise>> ?promise drop ;
+
+: define-attributes-word ( word tuple -- )
+ [ name>> "-attributes" append create-word-in ] dip define-constant ;
+
SYNTAX: GAME:
- CREATE
- game-attributes parse-main-window-attributes
+ scan-new-word
+ game-attributes parse-window-attributes
+ 2dup define-attributes-word
parse-definition
- define-main-window ;
+ [ define-window ] [ 2drop current-vocab main<< ] 3bi ;