]> gitweb.factorcode.org Git - factor.git/blob - extra/game/loop/loop-docs.factor
document game.loop
[factor.git] / extra / game / loop / loop-docs.factor
1 ! (c)2009 Joe Groff bsd license
2 USING: help.markup help.syntax kernel math ui.gadgets.worlds ;
3 IN: game.loop
4
5 HELP: <game-loop>
6 { $values
7     { "tick-interval-micros" integer } { "delegate" "a " { $link "game.loop-delegates" } }
8     { "loop" game-loop }
9 }
10 { $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-micros" } " microseconds, and " { $link draw* } " on the delegate as frequently as possible. The " { $link start-loop } " and " { $link stop-loop } " words start and stop the game loop." } ;
11
12 HELP: benchmark-frames-per-second
13 { $values
14     { "loop" game-loop }
15     { "n" float }
16 }
17 { $description "Returns the average number of times per second the game loop has called " { $link draw* } " on its delegate since the game loop was started with " { $link start-loop } " or since the benchmark counters have been reset with " { $link reset-loop-benchmark } "." } ;
18
19 HELP: benchmark-ticks-per-second
20 { $values
21     { "loop" game-loop }
22     { "n" float }
23 }
24 { $description "Returns the average number of times per second the game loop has called " { $link tick* } " on its delegate since the game loop was started with " { $link start-loop } " or since the benchmark counters have been reset with " { $link reset-loop-benchmark } "." } ;
25
26 { reset-loop-benchmark benchmark-frames-per-second benchmark-ticks-per-second } related-words
27
28 HELP: draw*
29 { $values
30     { "tick-slice" float } { "delegate" "a " { $link "game.loop-delegates" } }
31 }
32 { $description "This generic word is called by a " { $link game-loop } " on its " { $snippet "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-micros" } " time period has passed since " { $link tick* } " was most recently called on the delegate." } ;
33
34 HELP: game-loop
35 { $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." } ;
36
37 HELP: game-loop-error
38 { $values
39     { "game-loop" game-loop } { "error" "an error object" }
40 }
41 { $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." } ;
42
43 HELP: reset-loop-benchmark
44 { $values
45     { "loop" game-loop }
46 }
47 { $description "Resets the benchmark counters on a " { $link game-loop } ". Subsequent calls to " { $link benchmark-frames-per-second } " and " { $link benchmark-ticks-per-second } " will measure their values from the point " { $snippet "reset-loop-benchmark" } " was called." } ;
48
49 HELP: start-loop
50 { $values
51     { "loop" game-loop }
52 }
53 { $description "Starts running a " { $link game-loop } "." } ;
54
55 HELP: stop-loop
56 { $values
57     { "loop" game-loop }
58 }
59 { $description "Stops running a " { $link game-loop } "." } ;
60
61 { start-loop stop-loop } related-words
62
63 HELP: tick*
64 { $values
65     { "delegate" "a " { $link "game.loop-delegates" } }
66 }
67 { $description "This generic word is called by a " { $link game-loop } " on its " { $snippet "delegate" } " object at regular intervals while the game loop is running. The game loop's " { $snippet "tick-interval-micros" } " attribute determines the number of microseconds between invocations of " { $snippet "tick*" } "." } ;
68
69 { draw* tick* } related-words
70
71 ARTICLE: "game.loop-delegates" "Game loop delegate"
72 "A " { $link game-loop } " object requires a " { $snippet "delegate" } " that implements the logic that controls the game. A game loop delegate can be any object that provides two methods for the following generic words:"
73 { $subsections
74     tick*
75     draw*
76 }
77 { $snippet "tick*" } " will be called at a regular interval determined by the game loop's " { $snippet "tick-interval-micros" } " attribute. " { $snippet "draw*" } " will be invoked in a tight loop, updating as frequently as possible." ;
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 delegate object with methods on the " { $link tick* } " and " { $link draw* } " methods, the game loop will invoke the " { $snippet "tick*" } " method at regular intervals while invoking the " { $snippet "draw*" } " method as frequently as possible. Game loop objects must first be constructed:"
81 { $subsections
82     "game.loop-delegates"
83     <game-loop>
84 }
85 "Once constructed, the game loop can be started and stopped:"
86 { $subsections
87     start-loop
88     stop-loop
89 }
90 "The game loop maintains performance counters for measuring drawing frames and ticks per second:"
91 { $subsections
92     reset-loop-benchmark
93     benchmark-frames-per-second
94     benchmark-ticks-per-second
95 }
96 "The game loop manages errors that occur in the delegate's methods during the course of the game loop:"
97 { $subsections
98     game-loop-error
99 }
100 "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." ;
101
102 ABOUT: "game.loop"