A simple Entity Component System library made for learning purposes. It is header-only, so just have to copy the content of the src
folder and include <met/met.hpp>
to check it out. It does require a C++ 17 version of your compiler though.
Made by students, the project purposes are to be easy to understand and thoroughly documented. It is seen as an entry point for users and developers. We provide both a post-mortem to explain the inner-working of the library, and many exercices to get started with ECS.
The API is heavly based on ENTT by skypjack, you should check it out if you're looking for a highly performant and production-ready library.
Violets are blue, roses are red, and when I met ecs, my world rebooted 🌐
ECS (Entity Component System) is way to organize your data and your logic which radicaly changes from traditional Object-Oriented Programming. It is seen as both a way to improve performance and to ease maintenance. Well-suited for games, it is designed to handle operations on large groups.
ECS is made out of 3 pieces that can be summarized with these simple rules :
- Entities are unique identifiers
- Components are plain datatypes (Positions, Colors, etc...)
- Entities can possess zero or more components
- Systems are logic executed on entities with matching component sets
#include <met/met.hpp>
struct Position {
float x;
float y;
};
struct Velocity {
float dx;
float dy;
};
int main() {
met::registry registry;
auto entity = registry.create();
Position pos = { 2, 3 };
registry.assign<position>(entity, pos);
Velocity vel = { 5, 8 };
registry.assign<position>(entity, vel);
registry.view<Position, Velocity>().each([](met::entity id, Position& pos, Velocity& vel) {
pos.x += 2;
std::cout << "pos " << pos.x << " " << pos.y << std::endl;
std::cout << "vel " << vel.dx << " " << vel.dy << std::endl;
});
// ...
}
Some exercices has been created to use ECS step by step.
The post-mortem offers a view on ECS possible implementations and explain everything there is to know about this library.
You need to have CMake and a C++ compiler which handles C++ 17.
sudo apt-get install build-essential cmake
You can install Visual Studio to get the MSVC compiler, and you can download CMake from their website.