ADocumentation Index
Fetch the complete documentation index at: https://mintlify.com/raoulkdev/MiniECS/llms.txt
Use this file to discover all available pages before exploring further.
MiniECS::Unit is a named entity that lives inside a World. By itself a Unit carries no behaviour — it is purely a container that groups one or more Modules together under a shared identity. Behaviour enters the picture only when Modules are attached: at each game loop tick the World asks every Unit to call start() on all of its Modules. Think of a Unit the same way you would think of a Unity GameObject: an addressable object in the scene whose capabilities are defined entirely by its components.
Creating Units
Units are always created throughWorld::createUnit(). This method constructs the Unit internally and transfers ownership to the World’s std::unique_ptr vector. You never instantiate Unit directly.
Adding Modules
addModule(ModuleType moduleType) is the primary way to attach behaviour to a Unit.
addModule first scans the existing Module list for a duplicate ModuleType. If a match is found the insertion is aborted and a message is printed to stdout — no exception is thrown. This guarantees that a Unit holds at most one Module of each type. If an unrecognised ModuleType is passed, the default case prints "Invalid Module Type!!" to stdout.
switch statement maps each ModuleType enum value to its concrete derived class:
ModuleType | Concrete class |
|---|---|
ModuleType::Renderer | MiniECS::RendererModule |
ModuleType::Transform | MiniECS::TransformModule |
When you register a custom Module type, you add a new
case to this switch and a corresponding entry to the ModuleType enum. The duplicate-check logic requires no changes.Removing Modules
removeModule(ModuleType moduleType) erases the Module whose getType() matches the argument. If no matching Module is found, a message is printed to stdout.
Retrieving Modules
getModule<T>() is a templated accessor that returns a raw pointer to the first Module in the vector that can be dynamic_cast to T. If no such Module exists it writes an error to std::cerr and returns nullptr.
Unit.h:
Always check the return value of
getModule<T>() for nullptr before dereferencing. The method returns nullptr when the requested Module has not been added to the Unit.Other Methods
getName()
Returns the Unit’s name string as set at construction time.
getModulesVector()
Returns a std::vector<std::unique_ptr<Module>>& — a mutable reference to the internal Module list. Primarily used by World::play() to check whether the Unit has any Modules before entering the game loop.
callModuleStart()
Called by World::play() once per frame. Iterates over every Module in the vector and invokes start() on each one. You generally do not call this directly.