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
@SanderMertens
SanderMertens / bevy_bench.rs
Last active May 30, 2023 22:29
Add more benchmarks
use bevy_ecs::prelude::*;
use bevy_hierarchy::*;
use bevy_ecs::system::CommandQueue;
use std::hint::black_box;
use rand;
use std::time::{Instant};
#[derive(Component)]
// Test for importing script from URL
using flecs.components.*
using flecs.game
using assemblies
town :- Town{}
#include <c_app.h>
#include "flecs.h"
#include <stdio.h>
#include <stdlib.h>
#define STARS (1000)
#define PLANETS_MAX (10)
#define P_PLANET_WATER (0.1)
#define P_PLANET_OIL (0.005)
#define P_PLANET_COPPER (0.05)

Clang

8

size_t pretty_type() [T = Position]
size_t pretty_enum() [E = Color, C = Red]
size_t pretty_enum() [E = Color, C = 3]
#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