SanderMertens/flecs


A fast entity component system (ECS) for C & C

https://www.flecs.dev

License: Other

Language: C

Keywords: c99, cpp11, cpp14, cpp17, data-oriented, data-oriented-design, ecs, entity-component-system, entity-framework, flecs, game-development, game-engine, game-engine-framework, gamedev, modern-cpp, no-dependencies, portable, production-ready


flecs

Version MIT Documentation actions Discord Chat

Flecs is a fast and lightweight Entity Component System that lets you build games and simulations with millions of entities (join the Discord!). Here are some of the framework's highlights:

Flecs Explorer

To support the project, give it a star 🌟 !

What is an Entity Component System?

ECS is a way of organizing code and data that lets you build games that are larger, more complex and are easier to extend. Something is called an ECS when it:

  • Has entities that uniquely identify objects in a game
  • Has components which are datatypes that can be added to entities
  • Has systems which are functions that run for all entities matching a component query

For more information, check the ECS FAQ!

Show me the code!

C99 example:

typedef struct {
  float x, y;
} Position, Velocity;

void Move(ecs_iter_t *it) {
  Position *p = ecs_field(it, Position, 0);
  Velocity *v = ecs_field(it, Velocity, 1);

  for (int i = 0; i < it->count; i  ) {
    p[i].x  = v[i].x;
    p[i].y  = v[i].y;
  }
}

int main(int argc, char *argv[]) {
  ecs_world_t *ecs = ecs_init();

  ECS_COMPONENT(ecs, Position);
  ECS_COMPONENT(ecs, Velocity);

  ECS_SYSTEM(ecs, Move, EcsOnUpdate, Position, Velocity);

  ecs_entity_t e = ecs_insert(ecs, 
    ecs_value(Position, {10, 20}),
    ecs_value(Velocity, {1, 2}));

  while (ecs_progress(ecs, 0)) { }
}

Same example in C 11:

struct Position {
  float x, y;
};

struct Velocity {
  float x, y;
};

int main(int argc, char *argv[]) {
  flecs::world ecs;

  ecs.system<Position, const Velocity>()
    .each([](Position& p, const Velocity& v) {
      p.x  = v.x;
      p.y  = v.y;
    });

  auto e = ecs.entity()
    .insert([](Position& p, Velocity& v) {
      p = {10, 20};
      v = {1, 2};
    });

  while (ecs.progress()) { }
}

Projects using Flecs

If you have a project you'd like to share, let me know on Discord!

Hytale

We knew that we wanted to build Hytale around an Entity-Component-System (ECS). When we analyzed the options, FLECS rose to the top. FLECS provides the backbone of the Hytale Game Engine. Its flexibility has allowed us to build highly varied gameplay while supporting our vision for empowering Creators.

-- Dann Webster, Hypixel studios

Tempest Rising

Tempest Rising

Territory Control 2

image

The Forge

image

Extermination Shock

image

Tome Tumble Tournament

image

Hyperion Minecraft Server

image

Sol Survivor

image

Equilibrium Engine

image

After Sun

image

Flecs Demo's

https://github.com/SanderMertens/tower_defense Tower Defense

https://github.com/flecs-hub/city City

Flecs Hub

Flecs Hub is a collection of repositories that show how Flecs can be used to build game systems like input handling, hierarchical transforms and rendering.

Module Description
flecs.components.cglm Component registration for cglm (math) types
flecs.components.input Components that describe keyboard and mouse input
flecs.components.transform Components that describe position, rotation and scale
flecs.components.physics Components that describe physics and movement
flecs.components.geometry Components that describe geometry
flecs.components.graphics Components used for computer graphics
flecs.components.gui Components used to describe GUI components
flecs.systems.transform Hierarchical transforms for scene graphs
flecs.systems.physics Systems for moving objects and collision detection
flecs.systems.sokol Sokol-based renderer
flecs.game Generic game systems, like a camera controller

Language bindings

The following language bindings have been developed with Flecs! Note that these are projects built and maintained by helpful community members, and may not always be up to date with the latest commit from master!

Project Statistics

Sourcerank 12
Repository Size 133 MB
Stars 6,351
Forks 441
Watchers 80
Open issues 26
Dependencies 0
Contributors 96
Tags 60
Created
Last updated
Last pushed

Top Contributors See all

Sander Mertens Bruce Mitchener randy408 Indradb WEREMSOFT Alexander Knorre Zero bazhenovc Arn SpaceIm Javier Peletier BeanCheeseBurrito BHolman-LBI Eshnek Benji Mewen Page Mason Bially Indiana Kernick copygirl Garrett Swann

Packages Referencing this Repo

Flecs.NET.Native.Release
Native libraries for flecs
Latest release 4.0.2 - Updated - 6.35K stars
flecs.NET.Native
Native libraries for flecs.
Latest release 3.2.5 - Updated - 6.35K stars
Flecs.NET.Native.Debug
Native libraries for flecs
Latest release 4.0.2 - Updated - 6.35K stars

Recent Tags See all

v4.0.2 September 24, 2024
v4.0.1 August 16, 2024
v4.0.0 July 14, 2024
v3.2.12 July 11, 2024
v4.0.0-beta May 21, 2024
v4.0.2-alpha April 30, 2024
v4.0.1-alpha April 05, 2024
v3.2.11 February 07, 2024
v3.2.10 December 17, 2023
v3.2.9 November 14, 2023
v3.2.8 October 09, 2023
v3.2.7 September 05, 2023
v3.2.6 August 20, 2023
v3.2.5 August 04, 2023
v3.2.4 June 12, 2023

Interesting Forks See all

Reddy-dev/Unreal-Flecs
Unreal Engine Flecs Plugin
C - Other - Updated - 6 stars - 1 forks
Lelfy/flecs
A Multithreaded Entity Component System written for C89 & C99
MIT - Updated - 2 stars

Something wrong with this page? Make a suggestion

Last synced: 2024-10-06 12:20:07 UTC

Login to resync this repository