flecs

SanderMertens活跃维护

用 C/C++ 写的高性能实体组件系统(ECS),面向数据导向设计,帮游戏和引擎开发者把对象逻辑拆成实体与组件,跑得更快、扩展更顺。

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

v4.2.0发布于 2026-11-04 05:48 UTC8,829star +7 / 7 天630fork同步于 2026-11-10 11:31 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/SanderMertens/flecs.git
硬件要求按 README 说明

README 未说明显存或 GPU 要求;纯 C/C++ 库,可跨平台编译,并可用 emscripten 在浏览器中运行

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

轻量零依赖的 C/C++ ECS 框架,用实体组件系统支撑百万级实体的游戏与仿真

用 C/C++ 写的高性能实体组件系统(ECS),面向数据导向设计,帮游戏和引擎开发者把对象逻辑拆成实体与组件,跑得更快、扩展更顺。

核心能力

  • 提供零依赖 C99 API 与不使用 STL 容器的 C++17 类型安全 API
  • 首个完整支持实体关系的开源 ECS,原生支持层级与预制体
  • 采用缓存友好的 archetype/SoA 存储,每帧可处理百万级实体
  • 用无锁调度器在多 CPU 核心上并行运行系统
  • 内置反射框架、JSON 序列化与带 join 的查询语言

容易踩的坑

README 未给出包管理器或 CMake 安装命令,需自行将源码集成进构建;C++ 用户需 C++17 编译器;语言绑定由社区维护,可能未跟进 master 最新提交

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v4.2.0
  1. v4.2.0Flecs v4.2.0最新正式版2026-11-04 · 2026-11-04 05:48 UTC

    Release announcement

    https://ajmmertens.medium.com/flecs-4-2-is-out-09435e80fdd1

    Release notes

    This version includes the following improvements:

    • [core] Flush stage commands in ecs_fini
    • [core] Detect WebAssembly targets other than Emscripten (thanks @andrewgazelka!)
    • [core] Default to Any term for observers without terms
    • [core] Rename (OnInstantiate, Override) trait to (OnInstantiate, Copy)
    • [core] Add ecs_ref_from_ptr()
    • [core] Lock tables for OnAdd/OnRemove hooks and observers
    • [core] Only allow DontFragment With targets on DontFragment components
    • [core] Reduce overhead of disabling entities
    • [core] Optimize performance and memory usage of table graph storage
    • [core] Allow changing components of instantiated prefab by clearing stale IsA edges
    • [core] Do not silence warnings in user code
    • [core] Add Sparse and DontFragment support to ecs_each_id
    • [core] Return empty iterator from ecs_children for Wildcard and Any parents
    • [core] Rename ecs_is_deferred to ecs_is_stage
    • [script] Warn when a script inherits from Prefab instead of declaring a prefab
    • [core] Emit ChildOf events for entities created with ecs_new_w_parent
    • [core] Remove implicit defer mode from core
    • [core] Implement component inheritance as storage feature
    • [core] Allow setting cmp/equals hooks on in-use components
    • [core] Copy inherited DontFragment components to instantiated prefab children that have no IsA relationship with the prefab child
    • [core] Events only propagate down a subtree when an observer with an up term exists for the id
    • [core] Observers skip the query engine for tables that cannot match by type and resolve single up(IsA) terms through the base table
    • [core] Skip observer maps that hold only up notify observers when forwarding events
    • [core] Create named childr
  2. v4.1.6Flecs v4.1.62026-06-29 · 2026-06-29 02:09 UTC
    查看更新说明

    Highlights

    // NEW: include statements
    include assets.flecs
    
    // NEW: functions
    fn color(x: i32, z: i32) -> Rgba {
        {x, 0, z, 1.0}
    }
    
    for x in 0..10 {
        for z in 0..10 {
            "e_{x}_{z}" {
                // NEW: assign expressions to components directly
                Rgb: color(x, z).rgb // NEW: swizzle operators
            }
        }
    }
    
    • Multiple inspector panels in the explorer:

    • New entities can now be created from the explorer:

    • New dialog for adding components:

    Release notes

    This version includes the following improvements:

    • [core] Add optimized function for moving small component values across tables
    • [core] Improve performance of reparenting for non-fragmenting hierarchies
    • [core] Throw error when changing children of already instantiated prefab
    • [core] Create default range for already created entities when calling ecs_entity_range_new()
    • [core] Throw INVALID_OPERATION assert when parenting to not-alive parent
    • [core] Allow for overriding component hooks to support hot reloading
    • [core] Reduce the size of ecs_ref_t
    • [core] Introduce new update() API for modifying existing systems/observers
    • [core] Do not assert when entities have non-unique names
    • [core] Always run exclusive access checks when feature is enabled
    • [core] Implement new range API that correctly handles recycling
    • [core] Allow for specifying offset for ecs_delete_empty_tables() function
    • [core] Improve error message when using ecs_field for sparse component
    • [cpp] Replace usage of NULL with nullptr in C++ API headers
    • [cpp] Replace deprecated std::is_trivial
    • [cpp] Implement query group iterator for C++ API
    • [[cpp](https://github.com
  3. v4.1.5Flecs v4.1.52026-03-15 · 2026-03-15 23:45 UTC
    查看更新说明

    Highlights

    • New non-fragmenting hierarchy storage which significantly boosts asset hierarchy performance.
    • Reduced binary footprint of C++ component registration
    • Lots of hardening bugfixes for issues detected by the AFL fuzzer (1500 new tests since the last release!).
    • New math and Perlin noise functions for Flecs Script.
    • Added support for vector type operations in Flecs script:
    const a = Position: {10, 20}
    const b = Position: {1, 2}
    const c: a + b // {a.x + b.x, a.y + b.y}
    
    • C++ API improvements:

    New function to iterate all entities in the world:

    world.each([](flecs::entity e) {
      // ...
    });
    

    System components can now be deduced from each() arguments:

    world.system("Move")
      .each([](Position& p, const Velocity& v) {
        // ...
      });
    

    Improved APIs for creating hierarchies:

    flecs::entity p = world.entity(world, "p");
    
    // Create child for ChildOf (fragmenting) hierarchy
    flecs::entity child_a = world.entity(world, p, "a");
    
    // Create child for Parent (non-fragmenting) hierarchy
    flecs::entity child_b = world.entity(world, flecs::Parent{p}, "b");
    

    Release notes

    This version includes the following bugfixes:

    • [core] Fix issue where ref could return wrong value during recursive entity cleanup.
    • [core] Fix issue with deferred calls to modified() for DontFragment components.
    • [core] Fix issue where it wasn't possible to inherit from entity with Relationship trait.
    • [core] Fix issue with cloning entity symbols.
    • [core] Fix issue with removing sparse pair with recycled target.
    • [core] Fix issue with overriding existing exclusive relationships.
    • [core] Fix issue with combining relationship constraints with component disabling.
    • [core] Return 0 for negative indices in ecs_get_target().
    • [core] Fix ecs_table_get_target() bounds check to reject negative and >=count indices.
    • [core] Fix issue with deleting sparse component while deferring is suspended.
    • [core] Fix issue with using has()/get() from hooks.
    • [core] Fix issue where deferred setting after removing on a prefab instance could fail.
    • [core] Fix issues with sparse components and overriding.
    • [core] Fix race condition in component registration code.
    • [core] Fix assert when toggling component before adding it to any entity.
    • [[core]](https://
  4. v4.1.4Flecs v4.1.42025-12-12 · 2025-12-12 22:18 UTC
    查看更新说明

    Highlights

    • Small release to fix a few bugs that got identified shortly after releasing 4.1.3

    Release notes

    This version includes the following bugfixes:

    • [core] Revert change for supporting types with destructive move semantics (caused crash)
    • [core] Fix issues with ordered children trait and nested prefabs
    • [core] Fix issues with ordered children trait and prefab slots
    • [core] Fix assert when reclaiming component record (using world.shrink()) for large component id

    This version includes the following improvements:

    • [core] Add ecs_get_version() function (thanks @tabdroid-1!)
    • [docs] Correct bazel test example in building flecs manual
    • [docs] Fix documentation for ECS_QUERY, ECS_QUERY_DEFINE and ecs_query macros

    New Contributors

    Full Changelog: https://github.com/SanderMertens/flecs/compare/v4.1.3...v4.1.4

  5. v4.1.3Flecs v4.1.32025-12-06 · 2025-12-06 23:49 UTC
    查看更新说明

    Highlights

    • Improved RAM utilization (create fewer component records, reclaim more data from component vectors, smaller entity administration)
    • A new Building Flecs manual!

    Release notes

    This version includes the following bugfixes:

    • [core] Fix issue with reparenting named ordered children
    • [core] Fix issue with ecs_ref_get and ecs_shrink
    • [core] Fix issue where order or instantiated prefab children could be wrong
    • [core] Fix assert for DontFragment relationship during world cleanup
    • [core] Fix issue with how dtors get called for types that don't support non-destructive moves (thanks @Watermelon914!)
    • [os_api] Add missing WIN32_LEAN_AND_MEAN before new windows.h include
    • [queries] Fix assert when using set_varfor query with one cascad term
    • [meta] Fix corruption with deserializing into enum with non-32 bits underlying type

    This version includes the following improvements:

    • [cpp] Allow set_ptr to be used for pairs (thanks @Reddy-dev!)
    • [cpp] Add owns_second() and auto_override_second() methods (thanks @Reddy-dev!)
    • [core] Don't always create (T, *), (*, T) component records (only create when used)
    • [core] Don't create component record when registering trait
    • [core] Don't create component record for ChildOf
    • [core] Prevent creation of (*, 0) component record
    • [core] Reclaim component vectors to actual count instead of power of 2
    • [core] Reclaim memory from map data structures on world.shrink()
    • [core] Reclaim memory from empty component records during world.shrink()
    • [core] Remove redundant component record lookup in observable code
    • [core] Add convenience macro's for iterating component records and queries
    • [core] Remve redundant ecs_map_params_t type and functions
    • [core] Remove redundant if (table) check in table cache
    • [core] Remove redundant check on cache initialized in ecs_table_cache_get
    • [core] Remove ecs_record_t::cr field
    • [core] Increase the maximum size of error strings
    • [core] Prevent modifications to map while iterating
    • [core] Don't call flecs_notify_on_add when creating entity in root table
    • [core] Add ecs_is_defer_suspended() function
    • [observers] Remove redundant check in flecs_emit
    • [queries] Add traversal tests for (ChildOf, _)
    • [queries] Add performance tracing to ecs_query_init
    • [os_api] Use ecs_os_free() instead of free() in flecs_dump_backtrace()
    • [stats] Track memory of new locked components map
    • [docs] Add Rescue Ops: Wildfire to README
    • [docs] Rename custom_runner examples to run_callback
    • [docs] Remove outdated references to .singleton() API
    • [docs] Add new "Building Flecs" manual (previously on quickstart)

    Breaking changes:

    • None

    New Contributors

    Full Changelog: https://github.com/SanderMertens/flecs/compare/v4.1.2...v4.1.3

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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++:

    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!

    Tempest Rising

    Tempest Rising

    Territory Control 2

    image

    Polyzonia

    image

    Resistance is Brutal

    image

    Appulse

    image

    Rescue Ops: Wildfire

    image

    Age of Respair

    image

    FEAST

    image

    Gloam Vault

    image

    Antimatcher

    image

    Writ of Battle

    image

    Extermination Shock

    image

    The Forge

    image

    ECS survivors

    image

    8402

    image

    Tome Tumble Tournament

    image

    Sol Survivor

    image

    After Sun

    image

    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.

    ModuleDescription
    flecs.components.cglmComponent registration for cglm (math) types
    flecs.components.inputComponents that describe keyboard and mouse input
    flecs.components.transformComponents that describe position, rotation and scale
    flecs.components.physicsComponents that describe physics and movement
    flecs.components.geometryComponents that describe geometry
    flecs.components.graphicsComponents used for computer graphics
    flecs.components.guiComponents used to describe GUI components
    flecs.systems.transformHierarchical transforms for scene graphs
    flecs.systems.physicsSystems for moving objects and collision detection
    flecs.systems.sokolSokol-based renderer
    flecs.gameGeneric 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!