C++/SDL2 2D Engine
Context and inspiration
Game engines are fun and all, but it’s also known that learning to code from scratch can be very valuable. Indeed, before using my first commercial game engine, I had learned how to code a basic one using C++ and SFML that supported Object Oriented Composition, and it has really helped me to learn Unity thereafter. Though, in summer 2020, after having heard about the merits of the Entity Component System framework, I settled a new challenge and try to build my own. Nevertheless, I decided to not follow a tutorial but take the inspiration from existing open sourced engines and even blogs such as EnTT’s creator skypjack.github.io .
Being able to create even the smallest game inside a custom engine has got to be one of the most satisfying experience in game dev!
A journey in the depths of C++
This project got me deeper that I’ve ever been before using C++. Indeed, in order to have a framework that is satisfying, it’s important to use the most concise syntax possible, and thanks to the power of such a language, it’s always possible to do better. For instance, I used C++11 lambda traits features to be able to send lambda function to the engine from the systems and have it iterate through the right entities to apply the given logic to
// A simple example of system dealing with entities' motion.
void Motion::update(float dt) { engine().foreach([&](Velocity2D& velocity, Transform2D& transform) { transform.position.x += velocity.x * dt; transform.position.y += velocity.y * dt; }); }
New patterns
It was very hard to switch from the Object Oriented Composition used in the usual game engines to ECS, because Components could not depend on each other anymore. However, it forced me to learn to look at game developement with a more data-oriented way, and I earned some precious experience in code architecture. Plus, as Unity’s Job System is improving, it seems great to have studied this pattern, as games need more and more optimizations.