]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/game/worlds/worlds.factor
factor: trim using lists
[factor.git] / extra / game / worlds / worlds.factor
index cf75d37b39c0c696605ed8482e0fc749a854e509..5fdc110783be0342519daf92ea36a0b6b497220a 100644 (file)
@@ -1,19 +1,19 @@
-! (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 -- )
@@ -38,8 +38,6 @@ M: game-world draw*
     {
         [ audio-engine-device>> ]
         [ audio-engine-voice-count>> ]
-        [ audio-engine-buffer-size>> ]
-        [ audio-engine-buffer-count>> ]
     } cleave <audio-engine>
     [ start-audio* ] keep ; inline
 
@@ -48,39 +46,44 @@ PRIVATE>
 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 ;