$ show SanderMertens/flecs
Flecs is a high-performance Entity Component System (ECS) framework for games and simulations, written in C99 with a C++17 wrapper. It provides a data-oriented storage model where entities are stored in archetype tables with component columns, enabling cache-efficient iteration. The framework includes a powerful query language with support for relationships, inheritance, traversal, grouping, and sorting. It features an extensive addon system covering systems (pipelines), observers, prefabs, reflection/meta, JSON serialization, an embedded scripting language (Flecs Script) with async/await, a REST API with an HTTP server, statistics/metrics, alerts, and more. Flecs has zero external dependencies and is designed for lockless multi-core scheduling. It is used in commercial games and has a large ecosystem of examples and community bindings. Architecture: The library is modular with a core C API and optional addons compiled via preprocessor flags. The C++ API provides a fluent builder pattern for constructing entities, systems, queries, and observers. Key entry points include ecs_init/flecs::world for world creation, ecs_progress for running the game loop, ecs_insert for entity creation, ecs_system for defining systems, ecs_query for cached queries, and ecs_script for running Flecs Script files. Data flows involve creating entities with components, which are stored in tables; systems iterate over matching entities each frame; observers react to component changes; and the script engine allows runtime entity manipulation. External dependencies: None. Flecs is self-contained and uses only standard C library functions.
The LLM identified 7 files worth highlighting for reuse:
A generic hashmap implementation with 64-bit keys and values, supporting chaining, load-factor rehashing, and typed accessor macros. It is self-contained and can be extracted for use in other C projects requiring a lightweight key-value store.
A type-safe dynamic array (vector) with allocator-aware growth and optional type-hook invocation for constructor/destructor/move. It supports element-level operations and sanitize-mode metadata. Reusable in any C project needing a generic growable array.
A growable string buffer with small-string optimization, doubling growth, and list push/pop separators. It provides printf-style formatting and nested list management. Useful for efficient string construction in C programs.
A page-based sparse-dense pair data structure supporting stable pointers, ID recycling with generation counters, and bulk operations. It is self-contained and can be reused for managing sparse collections of entities or resources.
A generic builder base class for the C++ API that provides a fluent interface for constructing entities, systems, queries, observers, and other ECS objects. It demonstrates a reusable pattern for type-safe builder hierarchies with method chaining.
A cursor-based API for runtime reflection and serialization of ECS component data. It allows traversing and modifying struct fields, enum values, and array elements without compile-time type information. The pattern is reusable for any system requiring generic data access.
A recursive-descent expression parser built with a custom macro system (ParserBegin/End, LookAhead, Loop) that generates efficient parsing code. It handles operators, function calls, variables, and constants. The macro pattern is reusable for implementing DSL parsers in C.