]> gitweb.factorcode.org Git - factor.git/blob - extra/game/loop/loop-docs.factor
factor: trim using lists
[factor.git] / extra / game / loop / loop-docs.factor
1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax math ui.gadgets.worlds ;
4 IN: game.loop
5
6 HELP: fps
7 { $values { "fps" real } { "nanos" integer } }
8 { $description "Converts a frames per second value into an interval length in nanoseconds." } ;
9
10 HELP: <game-loop>
11 { $values
12     { "tick-interval-nanos" integer } { "delegate" "a " { $link "game.loop-delegates" } }
13     { "loop" game-loop }
14 }
15 { $description "Constructs a new stopped " { $link game-loop } " object. When started, the game loop will call the " { $link tick* } " method on the " { $snippet "delegate" } " every " { $snippet "tick-interval-nanos" } " nanoseconds, and " { $link draw* } " on the same delegate object as frequently as possible. The " { $link start-loop } " and " { $link stop-loop } " words start and stop the game loop."
16 $nl
17 "To initialize the game loop with separate tick and draw delegates, use " { $link <game-loop*> } "." } ;
18
19 HELP: <game-loop*>
20 { $values
21     { "tick-interval-nanos" integer } { "tick-delegate" "a " { $link "game.loop-delegates" } } { "draw-delegate" "a " { $link "game.loop-delegates" } }
22     { "loop" game-loop }
23 }
24 { $description "Constructs a new stopped " { $link game-loop } " object. When started, the game loop will call the " { $link tick* } " method on the " { $snippet "tick-delegate" } " every " { $snippet "tick-interval-nanos" } " nanoseconds, and " { $link draw* } " on the " { $snippet "draw-delegate" } " as frequently as possible. The " { $link start-loop } " and " { $link stop-loop } " words start and stop the game loop."
25 $nl
26 "The " { $link <game-loop> } " word provides a shorthand for initializing a game loop that uses the same object for the " { $snippet "tick-delegate" } " and " { $snippet "draw-delegate" } "." } ;
27
28 { <game-loop> <game-loop*> } related-words
29
30 HELP: draw*
31 { $values
32     { "tick-slice" float } { "delegate" "a " { $link "game.loop-delegates" } }
33 }
34 { $description "This generic word is called by a " { $link game-loop } " on its " { $snippet "draw-delegate" } " object in a tight loop while the game loop is running. The " { $snippet "tick-slice" } " value represents what fraction of the game loop's " { $snippet "tick-interval-nanos" } " time period has passed since " { $link tick* } " was most recently called on the " { $snippet "tick-delegate" } "." } ;
35
36 HELP: game-loop
37 { $class-description "Objects of the " { $snippet "game-loop" } " class manage game loops. See " { $link "game.loop" } " for an overview of the game loop library. To construct a game loop, use " { $link <game-loop> } ". To start and stop a game loop, use the " { $link start-loop } " and " { $link stop-loop } " words."
38 $nl
39 "The " { $snippet "tick-delegate" } " and " { $snippet "draw-delegate" } " slots of a game loop object determine where the loop sends its " { $link tick* } " and " { $link draw* } " events. These slots can be changed while the game loop is running." } ;
40
41 HELP: game-loop-error
42 { $values
43     { "error" "an error object" } { "game-loop" game-loop }
44 }
45 { $description "If an uncaught error is thrown from inside a game loop delegate's " { $link tick* } " or " { $link draw* } ", the game loop will catch the error, stop the game loop, and rethrow an error of this class." } ;
46
47 HELP: start-loop
48 { $values
49     { "loop" game-loop }
50 }
51 { $description "Starts running a " { $link game-loop } "." } ;
52
53 HELP: stop-loop
54 { $values
55     { "loop" game-loop }
56 }
57 { $description "Stops running a " { $link game-loop } "." } ;
58
59 { start-loop stop-loop } related-words
60
61 HELP: tick*
62 { $values
63     { "delegate" "a " { $link "game.loop-delegates" } }
64 }
65 { $description "This generic word is called by a " { $link game-loop } " on its " { $snippet "tick-delegate" } " object at regular intervals while the game loop is running. The game loop's " { $snippet "tick-interval-nanos" } " attribute determines the number of nanoseconds between invocations of " { $snippet "tick*" } "." } ;
66
67 { draw* tick* } related-words
68
69 ARTICLE: "game.loop-delegates" "Game loop delegate"
70 "A " { $link game-loop } " object requires a " { $snippet "tick-delegate" } " and " { $snippet "draw-delegate" } " that together implement the logic that controls the game. Both delegates can also be the same object. A game loop delegate can be any object that provides two methods for the following generic words:"
71 { $subsections
72     tick*
73     draw*
74 }
75 { $snippet "tick*" } " will be called at a regular interval determined by the game loop's " { $snippet "tick-interval-nanos" } " attribute on the tick delegate. " { $snippet "draw*" } " will be invoked on the draw delegate in a tight loop, updating as frequently as possible."
76 $nl
77 "It is possible to change the " { $snippet "tick-delegate" } " and " { $snippet "draw-delegate" } " slots of a game loop while it is running, for example, to use different delegates to control a game while it's in the menu, paused, or running the main game." ;
78
79 ARTICLE: "game.loop" "Game loops"
80 "The " { $vocab-link "game.loop" } " vocabulary contains the implementation of a game loop. The game loop supports decoupled rendering and game logic timers; given a \"tick delegate\" object with a method on the " { $link tick* } " generic and a \"draw delegate\" with a " { $link draw* } " method, the game loop will invoke the " { $snippet "tick*" } " method on the former at regular intervals while invoking the " { $snippet "draw*" } " method on the latter as frequently as possible. Game loop objects must first be constructed:"
81 { $subsections
82     "game.loop-delegates"
83     <game-loop>
84     <game-loop*>
85 }
86 "Once constructed, the game loop can be started and stopped:"
87 { $subsections
88     start-loop
89     stop-loop
90 }
91 "The game loop catches errors that occur in the delegate's methods during the course of the game loop:"
92 { $subsections
93     game-loop-error
94 }
95 "The " { $vocab-link "game.worlds" } " vocabulary provides a convenient " { $link world } " subclass that integrates the game loop implementation with UI applications, managing the starting and stopping of the loop for you." ;
96
97 ABOUT: "game.loop"