Next: , Up: Kernel   [Contents][Index]


5.1.1 The Game Loop

At the very core of Chickadee there is an event loop. This loop, or “kernel”, is responsible for ensuring that the game is updated at the desired interval, handling input devices, rendering the current state of the game world, and handling errors if they occur. The kernel implements what is known as a “fixed timestep” game loop, meaning that the game simulation will be advanced by a fixed interval of time and will never vary from frame to frame, unlike some other styles of game loops. The appropriately named run-game and abort-game procedures are the entry and exit points to the Chickadee game loop.

If you are using chickadee play to launch your game, then calling run-game is already taken care of for you.

Procedure: run-game [#:window-title "Chickadee!"] [#:window-width 640] [#:window-height 480] [#:window-fullscreen? #f] [#:window-resizable? #f] [#:update-hz 60] [#:clear-color] [#:load] [#:update] [#:draw] [#:quit] [#:key-press] [#:key-release] [#:text-input] [#:mouse-press] [#:mouse-release] [#:mouse-move] [#:controller-add] [#:controller-remove] [#:controller-press] [#:controller-release] [#:controller-move] [#:window-keyboard-enter] [#:window-keyboard-leave] [#:window-mouse-enter] [#:window-mouse-leave] [#:window-show] [#:window-hide] [#:window-minimize] [#:window-maximize] [#:window-move] [#:window-resize] [#:error]

Run the Chickadee game loop.

A new graphical window will be opened with window-width x window-height as its dimensions, window-title as its title, and in fullscreen mode if window-fullscreen? is #t. If window-resizable? is #t then the window can be resized by the user. The screen color will be set to clear-color, or a pleasant light blue, by default.

To stop the game loop, simply call abort-game.

Procedure: abort-game

Stop the currently running Chickadee game loop.

The above explanation of the game loop was partially a lie. It’s true that there is a game loop at the center of Chickadee, but run-game is not it’s true entry point. There exists an even lower level procedure, run-game*, in the (chickadee game-loop) module that run-game uses under the hood.

On its own, run-game* does not do very much at all. In order to actually respond to input events, update game state, or render output, the developer must provide an engine. run-game is such an engine, and it’s likely all a developer will need. However, what if a developer wanted to use all of the useful Chickadee features to make a terminal roguelike game instead? Chickadee doesn’t come with a terminal rendering engine, but the developer could write one without having to write their own core game loop.

Procedure: run-game* [#:init] [#:update] [#:render] [#:time] [#:error] [#:update-hz 60]

Start the game loop. This procedure will not return until abort-game is called.

The core game loop is generic and requires four additional procedures to operate:

Procedure: elapsed-time

Return the current value of the system timer in seconds.


Next: , Up: Kernel   [Contents][Index]