Flecs 3.2 is out!

Sander Mertens
6 min readMar 27, 2023

--

3.2 assemblies make it possible to create procedural assets

What is Flecs?

Flecs is an Entity Component System (FAQ) for C and C++ that helps with building games, simulations and more. The core features of Flecs are:

  • Store data for millions of entities in data structures optimized for CPU cache efficiency and composition-first design
  • Find entities for game systems with a high performance query engine that can run in time critical game loops
  • Run code using a multithreaded scheduler that seamlessly combines game systems from reusable modules
  • Builtin support for hierarchies, prefabs and more with entity relationships which speed up game code and reduce boiler plate
  • An ecosystem of tools to profile, visualize, document and debug projects

Flecs is fully open source and licensed under the MIT license. Check out the Github repository here:

Link to the 3.2 release:

Who is using Flecs?

Flecs is used in projects ranging from those built by indie developers to large commercial multiplayer games. Projects are built with existing engines like Unreal, Godot and Unity, as well as brand new engines that use Vulkan, OpenGL, bgfx, sokol and SDL. Some projects aren’t games at all, and use Flecs as a fast in-memory database!

Flecs from the start has been designed with portability in mind. It not just runs on all major platforms, projects also use it with different programming languages. The last few months have seen a lot of active community development on language bindings for C#, Zig, Lua and Rust

An exciting project that has recently added support for Flecs is zig-gamedev, which is a promising game development ecosystem for Zig:

https://github.com/michal-z/zig-gamedev

Release Highlights

Here is a summary of the biggest changes since the v3.1 release:

  • Relationship flattening. Flecs 3.2 expands the use cases where Entity Relationships can be used with relationship flattening! This feature stores entities with different parents in the same table, which can significantly reduce memory fragmentation.
    The best part is that existing systems don’t need to be updated to support relationship flattening, and that features such as breadth first ordering and relationship traversal still work! Entities in flattened tables can still be iterated in a CPU-cache friendly way which fully supports (auto) vectorization.
    This is still an experimental feature, so expect many improvements in the near future. Check the relationship manual to find out how to use it, and what the current limitations are.
After flattening, the number of tables in this scene is reduced from 46.000 to 960
  • New graph query engine. One advantage of using entity relationships is that games can run complex, graph traversing queries in realtime. The query engine responsible for this has been entirely rewritten in Flecs 3.2, and is now up to 4 orders of magnitude faster!
    Some of the ways in which the new engine improves upon the old design is an improved runtime, a memoization cache for graph traversal, better utilization of new Flecs data structures and improved generation of query plans.
Example of a query that traverses multiple edges of an entity graph
  • Assemblies. Assemblies are a new feature that make it possible to create procedural assets. An assembly is a template that when instantiated generates entities and components from a number of input parameters. Assemblies can be nested, which makes it possible to compose them into larger, more complicated assets.
    Learn more about how to write assemblies in the new interactive Flecs Script tutorial, or check out some of the example assets in the playground repository!
An example of a procedural fence assembly
  • Opaque types. The Flecs reflection framework has been extended with the ability to serialize and deserialize opaque types! An opaque type is a type of which the layout isn’t known by the reflection framework, like std::string and std::vector. The new opaque type feature enables these and many other types to now be both serialized and deserialized!
  • World serialization. Another improvement of the reflection framework: it is now possible to serialize and deserialize an entire ECS world from and to JSON! This has been a much requested feature, and makes it a lot easier to save and load the state of a game.
    The JSON world serializer is built entirely on top of the existing reflection framework, which means world serialization isn’t limited to JSON, and custom/binary formats can also be implemented.
  • Fuzzy Name Matching. The new rule engine introduced support for (fuzzy) entity name matching! This can be useful when building UI widgets that need auto-completion, or when a query needs to match an entity that isn’t guaranteed to exist at query creation time.
An example of a query that uses fuzzy name matching
  • Core performance improvements. The 3.1.4 release was one of the biggest improvements in performance in Flecs since v2.0. Almost all ECS operations got faster by double digit points!
    The improvements were realized through a large number of changes, from a faster map implementation, to improved core data structures such as the sparse set and component index and smarter implementations of core ECS operations.
    The Flecs benchmark project has also been updated with more benchmarks, and recent measurements: https://github.com/SanderMertens/ecs_benchmark
  • 3D canvas in the Explorer. The explorer has seen many improvements, amongst which a new 3D canvas widget! This widget shows the content of an emscripten canvas, while a number of improvements to the REST API now make it possible for the explorer to communicate directly with web assembly applications!
    This means that you can now edit components, change Flecs scripts and see the results in realtime without having to write a single letter of C/C++ code! Try it out with the new Flecs playground, city demo or tower defense example:
The new Flecs playground now has an interactive 3D canvas
The city demo opened in the explorer
The tower defense demo opened in the explorer
  • Flecs hub updates. The modules in flecs-hub have seen a bunch of updates, from the addition of a time of day system and grid layout in flecs-game, to support for shadows, atmosphere rendering, improved bloom and shader files in flecs-systems-sokol. The goal of flecs-hub is to provide example implementations of common game systems, and to explore how new ECS features can be used in real life.
Atmosphere and shadow rendering by https://github.com/flecs-hub/flecs-systems-sokol

That’s all folks! If you’d like to support out Flecs, check out the GitHub repository and give it a ⭐️!

If you have any questions, suggestions or projects you’d like to share with others, join the Flecs Discord:

--

--

Sander Mertens

Author of Flecs, an Entity Component System for C and C++