This project aims to create a full 2D game engine for the SDL2 library.
The AssetManager
has a set of Locators and Loaders.
A locator is used to check if the requested asset exists. It will return a pointer to the asset location.
Example:
FileLocator
: check if the requested asset exists on-disk.ZipLocator
: check if the requested asset exists in a ZIP archive (todo).URLLocator
: check if the requested asset exists at a URL (todo).
A loader is used to load the asset from the pointer returned by the locator.
Example:
ImageLoader
: using SDL2_image, loads an image.FontLoader
: using SDL2_ttf, loads a TTF font.JSONLoader
: loads a JSON file.AudioLoader
: loads a sound file (todo).
Asset requests are made using an AssetDescriptor
. The descriptor holds all
informations about the asset (ie: name, font size, bit rate, ...).
The manager holds a cache of asset and descriptors. If a descriptor has already been loaded, the same asset is returned.
Map keys, mouse buttons and controller buttons to a named action, and then check in your code if the action is triggered or not.
The SceneManager
keeps track of all your game's scenes. It handles the scene
loading and unloading, and notify the scene's graph of inputs, updates, and draw
requests.
The scene graph is a tree of node, each one implementing a specific task:
- when a node enters the tree, it will be notified.
- when all node's children have entered the tree, the node will be notified.
- when a node leaves the tree, it will be notified.
- when the scene receives an input, all nodes of the graph handling inputs will receive it.
- when the scene must be updated, all nodes of the graph handling updates will be notified.
- when the scene must be drawn, all nodes of the graph handling drawing will be notified.
Example of nodes:
PositionNode
: handle relative and absolute positionSpriteNode
: loads an asset and draw at a positionAnimatedSpriteNode
: loads multiple asset, change the frame on update, draw at a positionAreaNode
: notified when overlaps with anotherAreaNode
- ...
In order to create a Scene
, you just need to inherit from it, and creates your
nodes in the load()
method, and delete them in the unload()
method.
Specific nodes in the scene graph are used for collision detection:
BodyNode
: is notified for a collisionBoundingBoxNode
: as a child of theBodyNode
, defines a bounding box used to filter out nodes in the collision detectionCollisionShapeNode
: as a child of theBodyNode
, defines the shape used to check for accurate collision
2-step collision detection:
- for each
BodyNode
, check if at least one childBoundingBoxNode
is overlapping - for each
BodyNode
with at least oneBoundingBoxNode
overlapping, construct theContactManifold
for each childCollisionShapeNode
Finally, the BodyNode
is notified of a collision by receiving the resulting ContactManifold
.
If you want to initialize libraries (ie: Stemworks API) and unload them at shutdown,
just inherit from Initializer
and add it to the engine instance.
At the moment, the following initializers are enabled by default:
- SDL2
- SDL2_image
- SDL2_ttf
- SDL Window/Renderer creation
The engine instance is initialized with a configuration object, used to customize how the engine will works. Feel free to use it to customize:
- actions (for configurable controls in your game)
- some of your nodes
- ...
NB: The configuration object does not handle loading from a file and saves.
You need cmake
and a compiler supporting the C++14 standard.
$ mkdir __build__
$ cd __build__
$ cmake ..
$ make
This project is released under the MIT License.