]> gitweb.factorcode.org Git - factor.git/blob - extra/game/loop/loop-docs.factor
Merge branch 'master' of git://factorcode.org/git/factor
[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: fps
6 { $values { "fps" real } { "micros" integer } }
7 { $description "Converts a frames per second value into an interval length in microseconds." } ;
8
9 HELP: <game-loop>
10 { $values
11     { "tick-interval-micros" integer } { "delegate" "a " { $link "game.loop-delegates" } }
12     { "loop" game-loop }
13 }
14 { $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." } ;
15
16 HELP: benchmark-frames-per-second
17 { $values
18     { "loop" game-loop }
19     { "n" float }
20 }
21 { $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 } "." } ;
22
23 HELP: benchmark-ticks-per-second
24 { $values
25     { "loop" game-loop }
26     { "n" float }
27 }
28 { $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 } "." } ;
29
30 { reset-loop-benchmark benchmark-frames-per-second benchmark-ticks-per-second } related-words
31
32 HELP: draw*
33 { $values
34     { "tick-slice" float } { "delegate" "a " { $link "game.loop-delegates" } }
35 }
36 { $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." } ;
37
38 HELP: game-loop
39 { $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." } ;
40
41 HELP: game-loop-error
42 { $values
43     { "game-loop" game-loop } { "error" "an error object" }
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: reset-loop-benchmark
48 { $values
49     { "loop" game-loop }
50 }
51 { $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." } ;
52
53 HELP: start-loop
54 { $values
55     { "loop" game-loop }
56 }
57 { $description "Starts running a " { $link game-loop } "." } ;
58
59 HELP: stop-loop
60 { $values
61     { "loop" game-loop }
62 }
63 { $description "Stops running a " { $link game-loop } "." } ;
64
65 { start-loop stop-loop } related-words
66
67 HELP: tick*
68 { $values
69     { "delegate" "a " { $link "game.loop-delegates" } }
70 }
71 { $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*" } "." } ;
72
73 { draw* tick* } related-words
74
75 ARTICLE: "game.loop-delegates" "Game loop delegate"
76 "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:"
77 { $subsections
78     tick*
79     draw*
80 }
81 { $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." ;
82
83 ARTICLE: "game.loop" "Game loops"
84 "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:"
85 { $subsections
86     "game.loop-delegates"
87     <game-loop>
88 }
89 "Once constructed, the game loop can be started and stopped:"
90 { $subsections
91     start-loop
92     stop-loop
93 }
94 "The game loop maintains performance counters for measuring drawing frames and ticks per second:"
95 { $subsections
96     reset-loop-benchmark
97     benchmark-frames-per-second
98     benchmark-ticks-per-second
99 }
100 "The game loop manages errors that occur in the delegate's methods during the course of the game loop:"
101 { $subsections
102     game-loop-error
103 }
104 "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." ;
105
106 ABOUT: "game.loop"