Skip to content

Architecture overview

Nikolai Wuttke edited this page Sep 2, 2019 · 23 revisions

Structure and layers

RigelEngine consists of a collection of packages (directories below the src directory), and a top-level package (all the files which are directly inside the src directory) which implements the actual executable based on the other packages. See src/README.md for an overview of what each package is about.

Ihe architecture can be further divided into a few layers:

  • platform layer and rendering backend
  • top-level infrastructure, which runs the main loop and manages different game modes
  • the in-game engine, based on the Entity-Component-System architecture
  • gameplay code.

Platform layer and rendering

The project is based on SDL for platform abstraction and window creation, and OpenGL for rendering. Audio is implemented using SDL Mixer.

Rendering

A 2D rendering API is implemented on top of OpenGL. See Rendering Backend for more information. The API is provided to higher layers in form of the rigel::renderer::Renderer class. There is exactly one instance of this class at run-time. The dependency is passed on to clients with a pointer to that instance.

Audio

The audio API exposed by this layer is much simpler compared to rendering, consisting of just a few functions to play a sound effect or start playing a song. Clients get access to audio via a pointer to a rigel::IGameServiceProvider object.

Main loop

After startup is finished, everything is driven by the main loop. The main loop keeps running until the user quits the game. Each iteration of the loop represents one frame rendered to the screen.

Each frame, the main loop retrieves events like keyboard input from SDL, calls into the current game mode for rendering, and then presents the results on screen by swapping OpenGL's buffers. A game mode can request switching to a new game mode. See Game mode management for more info.

Timing

At the main loop level, timing is done in a variable timestep fashion, by giving the current game mode a delta time (time elapsed since the last frame). The in-game code implements a fixed timestep scheme on top of that, though.

Fade-in and fade-out effects

The main loop layer also provides a mechanism for fading out and fading in the entire screen. This is exposed by functions fadeInScreen and fadeOutScreen in IGameServiceProvider. These functions are blocking: They return after the fade has completed. They can be called at any time during a frame.

Engine

Gameplay code

Resource management