Giter Club home page Giter Club logo

flecs's Introduction

flecs

GitHub version CI build Build Status codecov Documentation Discord Chat

Flecs is a fast and lightweight Entity Component System for C89 / C99 / C++11 that packs a lot of punch in a small footprint:

  • Blazing fast iteration speeds with direct access to raw C arrays across multiple components
  • Support for hierarchies, prefabs, traits, state machines, snapshots and more
  • An efficient lock-free architecture allows for modifying entities across multiple threads
  • Queries with builtin support for sorting, change tracking, read-write permissions and more
  • Systems that are time triggered, rate triggered, run every frame or run only when needed
  • A customizable core that lets you include only the features you need

This is Flecs v2, which is a breaking change from v1. For the last v1 release, see: https://github.com/SanderMertens/flecs/releases/tag/v1.3

If you have questions, suggestions or a Flecs project you'd like to show off, join the Flecs Discord!

What is an Entity Component System?

ECS (Entity Component System) is a design pattern often found in gaming and simulation which produces code that is fast and reusable. Dynamic omposition is a first-class citizen in ECS, and there is a strict separation between data and behavior. A framework is an Entity Component System if it:

  • Has entities that are unique identifiers
  • Has components that are plain data types
  • Has systems which are behavior matched with entities based on their components

Documentation

See Docsforge for a more readable version of the documentation.

Example

This is a simple flecs example in the C++11 API:

struct Position {
    float x;
    float y;
};

struct Velocity {
    float x;
    float y;
};

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

    ecs.system<Position, const Velocity>()
        .each([](flecs::entity e, Position& p, const Velocity& v) {
            p.x += v.x * e.delta_time();
            p.y += v.y * e.delta_time();
            std::cout << "Entity " << e.name() << " moved!" << std::endl;
        });

    ecs.entity("MyEntity")
        .set<Position>({0, 0})
        .set<Velocity>({1, 1});

    while (ecs.progress()) { }
}

Building

The easiest way to add Flecs to a project is to add flecs.c and flecs.h to your source code. These files can be added to both C and C++ projects (the C++ API is embedded in flecs.h). Alternatively you can also build Flecs as a library by using the cmake, meson, bazel or bake buildfiles.

Custom builds

The Flecs source has a modular design which makes it easy to strip out code you don't need. At its core, Flecs is a minimalistic ECS library with a lot of optional features that you can choose to include or not. This section of the manual describes how to customize which features to include.

Modules

The following modules are available in flecs-hub and are compatible with v2:

Module Description
flecs.meta Reflection for Flecs components
flecs.json JSON serializer for Flecs components
flecs.rest A REST interface for introspecting & editing entities
flecs.player Play, stop and pause simulations
flecs.dash Web-frontend for remote monitoring and debugging of Flecs apps
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.components.http Components describing an HTTP server
flecs.systems.transform Hierarchical transforms for scene graphs
flecs.systems.sdl2 SDL window creation & input management
flecs.systems.sokol Sokol-based renderer
flecs.systems.civetweb A civetweb-based implementation of flecs.components.http

flecs's People

Contributors

sandermertens avatar weremsoft avatar randy408 avatar arncarveris avatar ikrima avatar nxrighthere avatar nmdnm avatar prime31 avatar 0xflotus avatar azdagron avatar sh-dave avatar tmpvar avatar keating950 avatar drywolf avatar piratf avatar raizam avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.