Tiny C99 Entity-Component-System (ECS) library. Read the Tutorial.
Originally created for use in a game I am developping using C99: Codename Firesaga. Title pending.
ECSs are an alternative way to organize data and functions to Object-Oriented programming (OOP).
- OOP: Objects/Classes contain data and methods. Methods act on objects. Children classes inherit methods and data structure from parents.
- ECS: Components are purely data. Any number of components can be attached to an entity. Entities are acted upon by systems.
Videogame Example:
- Enemy Entity: AIControlled component, Sprite Component, Physics Component
- Bullet Entity: Sprite Component, Physics Component, DamageonHit Component
- Main Character Entity: UserControlled Component, Sprite Component, Physics Component
In tnecs, an entity is an uint64_t
index.
A component is user-defined struct
.
A system is a user-defined function
.
All live inside the world
.
The systems iterate over the entities that have a user-defined set of components, inclusively or exclusively, in phases.
Phases are user-defined uint8_t
.
System execution order is first-come first-served by default.
For more in-depth discussion about tnecs' design, see the On Design.
Add tnecs.c
and tnecs.h
to your source code.
Make the simplest possible C99 ECS library, only with the minimum necessary features. Compile with tcc
.
- Thread Safety?
- Compatible: compiles with
tcc
,gcc
andclang
- Cross-platform: Windows, Linux, Android (termux)
- Small: <1700 lines, 2 files.
- Fast: see benchmarks in test.c
- Simple: C99 API
- Independent: only dependent on C99 standard libraries
- FOSS: Free and Open Source
Sanders Mertens for his blog on ECS design. He created many other resources on ECSs.
Copyright (c) 2021 Average Bear Games, Made by Gabriel Taillon