summaryrefslogtreecommitdiff
path: root/doc/api/init.texi
blob: 7060d1dd01d8d4ceeb55cc81d1c7164a66ae5ce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@node Booting
@section Booting

@menu
* Window Creation::             Opening a window.
* The Game Loop::               The core of the engine.
@end menu

@node Window Creation
@subsection Window Creation

@example
(use-modules (sly window))
@end example

Sly uses the windowing features of SDL 1.2 under the hood, which
currently restricts Sly applications to using only a single window.
SDL2 support will come in a future release.

The window data structure:

@deffn {Scheme Procedure} make-window [@var{#:title}] [@var{#:resolution}] [@var{#:fullscreen?}]
Create a new window object.  @code{title} is a string to display in
the window's title bar.  @code{resolution} is a 2D vector that
specifies the dimensions of the window in pixels.  @code{fullscreen?}
is a boolean that toggles fullscreen mode.
@end deffn

@deffn {Scheme Procedure} window? @var{obj}
Return @code{#t} if @code{obj} is a window.
@end deffn

@deffn {Scheme Procedure} window-title @var{window}
Return the title of @code{window}.
@end deffn

@deffn {Scheme Procedure} window-resolution  @var{window}
Return the resolution of @code{window}.
@end deffn

@deffn {Scheme Procedure} window-fullscreen?  @var{window}
Return @code{#t} if @code{window} is set to fullscreen mode.
@end deffn

The following signals hold the state of the current window:

@defvr {Scheme Signal} window-width
The width of the current window.
@end defvr

@defvr {Scheme Signal} window-height
The height of the current window.
@end defvr

@defvr {Scheme Signal} window-size
The size of the current window as a 2D vector.
@end defvr

In addition to signals, the following hooks are triggered upon certain
changes to window state:

@defvr {Scheme Variable} window-resize-hook
This hook is run when the current window is resized.  Procedures added
to this hook should accept two arguments: Numbers @code{width} and
@code{height}, the new dimensions of the window in pixels.
@end defvr

@defvr {Scheme Variable} window-close-hook
This hook is run when the close button is clicked.  Note that this
event is simply a request from the user to close the window, it does
not mean that the window has actually been closed.  Procedures added
to this hook should accept no arguments.
@end defvr

The following procedures are used to open/close windows:

@deffn {Scheme Procedure} open-window [@var{window}]
Open the game window using the settings in @code{window}.
@end deffn

@deffn {Scheme Procedure} close-window
Close the currently open window.
@end deffn

@deffn {Scheme Syntax} with-window @var{window} @var{body} @dots{}
Evaluate @code{body} in the context of @code{window}.  @code{window}
is opened before evaluating @code{body}, and closed afterwards.
@end deffn

@node The Game Loop
@subsection The Game Loop

@defvr {Scheme Variable} draw-hook
This hook is run every time the game loop wants to render.  Procedures
added to this hook should accept two arguments: @code{dt}, the time in
seconds since the last render call; and @code{alpha}, a number in the
range [0,1] that indicates how far in between two discrete updates of
the game state the loop is in.  The @code{alpha} value is important
for smoothing animated values to avoid the ``temporal aliasing''
effect that causes choppy looking animations.
@end defvr

@defvr {Scheme Variable} after-game-loop-error-hook
This hook is run every time the game loop catches an error.
Procedures added to this hook should accept no arguments.
@end defvr

@deffn {Scheme Procedure} run-game-loop [@var{#:frame-rate}] [@var{#:tick-rate}] [@var{#:max-ticks-per-frame}]
Start the game loop.  @code{frame-rate} specifies the optimal number
of frames to draw per second.  @code{tick-rate} specifies the optimal
game logic updates per second.  Both @code{frame-rate} and
@code{tick-rate} are 60 by default.  @code{max-ticks-per-frame} is the
maximum number of times the game loop will update game state in a
single frame.  When this upper bound is reached due to poor
performance, the game will start to slow down instead of becoming
completely unresponsive and possibly crashing.
@end deffn

@deffn {Scheme Procedure} stop-game-loop
Abort the game loop.
@end deffn