]> gitweb.factorcode.org Git - factor.git/commitdiff
document game.worlds, tweak GAME: syntax
authorJoe Groff <arcata@gmail.com>
Sat, 16 Jan 2010 21:13:13 +0000 (13:13 -0800)
committerJoe Groff <arcata@gmail.com>
Sat, 16 Jan 2010 21:13:13 +0000 (13:13 -0800)
extra/game/worlds/authors.txt [new file with mode: 0644]
extra/game/worlds/summary.txt [new file with mode: 0644]
extra/game/worlds/worlds-docs.factor [new file with mode: 0644]
extra/game/worlds/worlds.factor
extra/gpu/demos/bunny/bunny.factor
extra/gpu/demos/raytrace/raytrace.factor
extra/terrain/terrain.factor

diff --git a/extra/game/worlds/authors.txt b/extra/game/worlds/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/extra/game/worlds/summary.txt b/extra/game/worlds/summary.txt
new file mode 100644 (file)
index 0000000..6a65cd7
--- /dev/null
@@ -0,0 +1 @@
+World class that integrates game loop and game input
diff --git a/extra/game/worlds/worlds-docs.factor b/extra/game/worlds/worlds-docs.factor
new file mode 100644 (file)
index 0000000..e021ed5
--- /dev/null
@@ -0,0 +1,35 @@
+! (c)2009 Joe Groff bsd license
+USING: game.loop help.markup help.syntax kernel math ui ui.gadgets.worlds words ;
+IN: game.worlds
+
+HELP: GAME:
+{ $syntax """GAME: word { attributes }
+    attribute-code ;""" }
+{ $description "Similar to " { $link POSTPONE: MAIN-WINDOW: } ", defines a main entry point " { $snippet "word" } " for the current vocabulary that opens a UI window with the provided " { $snippet "attributes" } ". In addition to the standard " { $link world-attributes } ", additional " { $link game-attributes } " can be specified to specify game-specific attributes. Unlike " { $link POSTPONE: MAIN-WINDOW: } ", the " { $snippet "attributes" } " for " { $snippet "GAME:" } " must provide values for the " { $snippet "world-class" } " and " { $snippet "tick-interval-micros" } " slots." } ;
+
+HELP: game-attributes
+{ $class-description "Extends the " { $link world-attributes } " tuple class with extra attributes for " { $link game-world } "s:" }
+{ $list
+{ { $snippet "tick-interval-micros" } " specifies the number of microseconds between consecutive calls to the world's " { $link tick* } " method by the game loop." }
+} ;
+
+HELP: game-world
+{ $class-description "" } ;
+
+HELP: tick-interval-micros
+{ $values
+    { "world" game-world }
+    { "micros" integer }
+}
+{ $description "Subclasses of " { $link game-world } " can override this class to specify the number of microseconds between consecutive calls to the game world's " { $link tick* } " method by the game loop. Using the " { $link POSTPONE: GAME: } " syntax will define this method for you." } ;
+
+ARTICLE: "game.worlds" "Game worlds"
+"The " { $vocab-link "game.worlds" } " vocabulary provides a " { $link world } " subclass that integrates with " { $vocab-link "game.loop" } " and " { $vocab-link "game.input" } " to quickly provide game infrastructure." 
+{ $subsections
+    game-world
+    game-attributes
+    POSTPONE: GAME:
+}
+;
+
+ABOUT: "game.worlds"
index f614943f0408d2b1f6e4c026656ce954c9af918e..1fd7f53905306282d9ee125afe5dd616bd04ae86 100644 (file)
@@ -1,3 +1,4 @@
+! (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 ;
@@ -25,9 +26,19 @@ M: game-world end-world
 TUPLE: game-attributes < world-attributes
     { tick-interval-micros fixnum read-only } ;
 
+<PRIVATE
+
 : verify-game-attributes ( attributes -- )
-    world-class>> { f world } member?
-    [ "GAME: must be given a custom world-class" throw ] when ;
+    {
+        [
+            world-class>> { f world } member?
+            [ "GAME: must be given a custom world-class" throw ] when
+        ]
+        [
+            tick-interval-micros>> 0 <=
+            [ "GAME: must be given a nonzero tick-interval-micros" throw ] when
+        ]
+    } cleave ;
 
 : define-game-tick-interval-micros ( attributes -- )
     [ world-class>> \ tick-interval-micros create-method ]
@@ -40,11 +51,14 @@ TUPLE: game-attributes < world-attributes
         [ define-game-tick-interval-micros ]
     } cleave ;
 
-: define-game ( word attributes -- )
-    [ [ ] define-main-window ]
-    [ nip define-game-methods ] 2bi ;
+: define-game ( word attributes quot -- )
+    [ define-main-window ]
+    [ drop nip define-game-methods ] 3bi ;
+
+PRIVATE>
 
 SYNTAX: GAME:
     CREATE
     game-attributes parse-main-window-attributes
+    parse-definition
     define-game ;
index 067e9344531b5a6365fd1bb502da3903de65c808..e18d76ed8d9c12fa227e335f4d62cb222f3bbd40 100644 (file)
@@ -308,4 +308,4 @@ GAME: bunny-game {
         { grab-input? t }
         { pref-dim { 1024 768 } }
         { tick-interval-micros $[ 1,000,000 60 /i ] }
-    }
+    } ;
index 8883609bce38faf5525bea2f470696a307b44e09..b474ca1f09dbbab95df6b2d2b9eaea0e0080f603 100644 (file)
@@ -104,4 +104,4 @@ GAME: raytrace-game {
         { grab-input? t }
         { pref-dim { 1024 768 } }
         { tick-interval-micros $[ 1,000,000 60 /i ] }
-    }
+    } ;
index adbeb9c441fa2fb7f062ea2d9f390a819fd7084b..39bc7f3ec8b75d49bf6eb03ab7433c00b341bc9d 100644 (file)
@@ -298,4 +298,4 @@ GAME: terrain-game {
         { grab-input? t }
         { pref-dim { 1024 768 } }
         { tick-interval-micros $[ 1,000,000 60 /i ] }
-    }
+    } ;