![]() |
Entity Generator 4.2.0
Composable, deterministic entity generation for C++23
|
Requires C++23 (e.g.,
-std=c++23for GCC/Clang,/std:c++latestfor MSVC).
API Reference · Usage Guide · Releases
A small framework for generating entities from your own components, with dependencies, validation and replay.
entity.get<T>(key). Register, remove, and generate with fluent chaining.constant_component<T>, choice_component<T>, range_component<T>, callback_component, and weighted_choice_component<T>. All accept an optional custom formatter.entity_request carries component selection, group, batch count, entity validation and per-call inputs (a country, a reference date, ...) for each call. Generation methods accept (request) or (request, seed); setup stays on the instance.depends_on(): a request pulls in what it needs, orders it, and skips a component whose dependency was skipped. field(key, fn) builds a component in one expression, with a label, formatter, JSON mapper, validator and condition.constant, choice, weighted, int, real, with labels, dependencies and weights) and registered with add_recipe(path), no recompiling.generate(request, e.seed()) reproduces an entity with the same request and setup.should_generate(ctx).validate() with automatic retries, entity-level validator callbacks, and a generation_observer interface with 15 lifecycle hooks. Multiple observers can be attached simultaneously via add_observer / remove_observer.dasmig::ext::stats_observer tracks generation counts, skips, retries, and failures out of the box.spawn() converts generated entities into typed ECS entities.entity.to_string(), operator<<, entity.to_map() for structured key–value export, and entity.to_json() with typed values, arrays, objects, nested documents from dotted keys (identity.age), and a replay signature that covers the inputs and the data behind the components.eg instances enable lock-free concurrent generation.entitygen.hpp is the library released here. Keep core.hpp and the core/ directory (dasmig-core) in the same directory. You need to add
to the files you want to generate entities and set the necessary switches to enable C++23 (e.g., -std=c++23 for GCC and Clang).
Components draw random numbers from ctx.random() with the dasmig-core functions (dasmig::core::uniform_int, pick, bernoulli, ...), which give the same results on every platform. Version 2 changes every seeded result and the component random API; see Migrating from v1.
Define a component by implementing the component interface:
Register components and generate entities:
The positional generation overloads and generator seed / unseed and validator setters have been removed. See Migrating to the request-first API.
For the complete feature guide — component dependencies, custom types, seed signatures, batch generation, groups, weights, validation, event hooks, extensions, and more — see the Usage Guide.
For planned features — Python/Node.js/.NET wrappers and more — see the Roadmap.
Tested with:
-std=c++23)-std=c++23)/std:c++latest)| Dependency | Version | Bundled | Purpose |
|---|---|---|---|
| dasmig-core | 1.0 | Yes (core.hpp, core/) | Platform-independent random engine and distributions, JSON |
| Catch2 | 3.x | Yes (amalgamated) | Unit testing |
| EnTT, Flecs | - | No | Only for the optional adapter headers in dasmig/ext/ |
| Library | Description |
|---|---|
| address-generator | Postal addresses with real streets by place |
| biodata-generator | Procedural human physical characteristics |
| birth-generator | Demographically plausible birthdays |
| city-generator | Weighted city selection by population |
| country-generator | Weighted country selection by population |
| email-generator | Email addresses in each country's style |
| interest-generator | Religion, hobbies and favourite media by country, age and sex |
| name-generator | Culturally appropriate full names |
| nickname-generator | Gamer-style nicknames |
| occupation-generator | Employment status, education and occupation by country, age and sex |
| persona-generator | Complete characters composed from the other generators |
| phone-generator | Phone numbers valid in each country's numbering plan |
| trait-generator | Personality traits with conflicts, synergies and Big Five axes |
This library is released under the MIT License.