Skip to content

Instantly share code, notes, and snippets.

View SanderMertens's full-sized avatar
🐥
Feeding flecs

Sander Mertens SanderMertens

🐥
Feeding flecs
View GitHub Profile
#include <bench_path.h>
#include <stdio.h>
#include <stdlib.h>
#include "entt.hpp"
#define MILLION (1000 * 1000)
#define BILLION (1000 * MILLION)
#define ENTITY_COUNT (255)
#define COMPONENT_COUNT (10)
entity.add<MeleeUnit>();
// Utility for adding features (mixins) to a class without modifying its
// definition.
// -- Mixin code
// Create macro for mixin template type so we don't go cross-eyed
#define MIXIN template<typename Self> typename
// Template that can store a list of mixin templates
// Summary of Flecs data structures
// This is a non-exhaustive overview of flecs datastructures. Things have been ommitted/have different names for clarity.
// --- DATASTRUCTURES
// A sparse set is a map-like structure that guarantees O(1) lookup times (as opposed to O(1) on average for maps) at the cost of
// requiring more RAM (more info on the general idea of sparse sets: https://www.geeksforgeeks.org/sparse-set/)
struct ecs_sparse_t { };

()

An incomplete overview of a language built from entities, values, argument lists and immutable key/value pairs.

Overview

Dynamic typing:

v = {x = 10, y = 20}
v.y = "foo"

v.z = 30 // add member z
// - each expression has a type & an optional value.
//
// - if the expression is an integer literal:
// - the type is Integer
// - the value is the integer value
//
// - if the expression is an floating point literal:
// - the type is Float
// - the value is the integer value
#include <stdio.h>
#include <memory>
struct BuilderCtor { };
template<typename T>
struct Delay {
explicit Delay() : obj_(T()) { printf("Delay::ctor()\n"); }
~Delay() {

Introducing relationships to ECS (draft)

After traits were added to Flecs, use cases have been identified that use the feature for describing & querying entity relationships, and by extension, knowledge graphs. The initial terminology used to describe traits does not really match these new use cases. Additionally, terminology around traits is sometimes ambiguous and unclear (a trait is the combination of a component and a trait?).

This draft proposes to establish a conceptually sound framework for introducing semantic graphs/entity relationships to ECS, in addition to providing unambiguous terminology that better matches what is already established by literature (such as by logic programming, RDF, semantic web, ConceptNet).

Introduction

This section provides a high level overview of semantic data structures and first order logic programming and is not specific to ECS.

Semantic graphs are typically stored as a collection of triples, which take the following form:

ECS Query DSL draft

Proposal for prolog-inspired ECS query DSL that can resolve components as well as entity relationships. Not a formal syntax/grammar definition.

Overview

Primitives

.                             // Self. Indicates iterated over entity or entity for given (arche)type
Entity                        // Entity identifier
X                             // Variable (all caps identifier)