Skip to main content

Documentation 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::Module is the abstract base class for all components in the MiniECS framework. Every piece of per-Unit behaviour — rendering, transformation, physics, custom logic — is implemented by subclassing Module and overriding the start() method. Modules are owned by Units via std::unique_ptr and are created through Unit::addModule().

Namespace & Header

namespace MiniECS { class Module; }
#include "modules/module_base/Module.h"

Constructor

Module(const ModuleType setType);
Stores the provided ModuleType enum value in the private type field and derives a human-readable string name from it via an internal switch statement. The resolved names are:
ModuleTypeResolved moduleTypeName
ModuleType::ModuleBase"ModuleBase"
ModuleType::Transform"Transform"
ModuleType::Renderer"Renderer"
(unrecognised)"Unknown"
After resolving the name, the constructor prints "Added <typeName>" to stdout.
setType
ModuleType
required
The type identifier for this Module instance. Determines the value returned by getType() and getTypeName() for the lifetime of the object. See ModuleType for all valid values.
Example
// Typically constructed internally by Unit::addModule():
MiniECS::Module mod(MiniECS::ModuleType::Transform);
// stdout: "Added Transform"

Destructor

virtual ~Module();
Prints "Removed <typeName>" to stdout when the Module is destroyed. The destructor is virtual to ensure correct cleanup when a Module* or unique_ptr<Module> pointing to a derived class instance is destroyed. Example
{
    MiniECS::Module mod(MiniECS::ModuleType::Renderer);
    // stdout: "Added Renderer"
} // scope ends
// stdout: "Removed Renderer"

start

virtual void start();
Called every frame by Unit::callModuleStart() as part of the World::play() game loop. The base implementation prints "Start / Start module" to stdout. Override this method in your derived classes to implement custom per-frame behaviour. Example — base class behaviour
MiniECS::Module mod(MiniECS::ModuleType::ModuleBase);
mod.start();
// stdout: "Start / Start module"
Example — overriding in a subclass
class MyBehaviour : public MiniECS::Module
{
public:
    using Module::Module;

    void start() override
    {
        // Custom per-frame logic here
        std::cout << "MyBehaviour tick\n";
    }
};
The start() method is called every frame inside an infinite loop. Keep its implementation lightweight and avoid blocking calls to maintain the target 60 fps cadence.

getType

ModuleType getType();
Returns the ModuleType enum value that was passed to the constructor. Used internally by Unit::addModule() and Unit::removeModule() for duplicate detection and targeted removal. Returns: ModuleType — the type identifier of this Module instance. Example
auto* mod = unit->getModule<MiniECS::TransformModule>();
if (mod && mod->getType() == MiniECS::ModuleType::Transform)
{
    // confirmed it's a Transform module
}

getTypeName

std::string getTypeName();
Returns the string name that was resolved from the ModuleType at construction time. Useful for logging and debugging. Returns: std::string — the human-readable type name, e.g. "Transform", "Renderer", or "ModuleBase". Example
auto* mod = unit->getModule<MiniECS::RendererModule>();
if (mod)
{
    std::cout << mod->getTypeName(); // "Renderer"
}

Private Members

The following private fields are set at construction and accessed only via the public methods above:
FieldTypeDescription
typeModuleTypeThe enum value identifying this Module’s type.
moduleTypeNamestd::stringHuman-readable name resolved from type at construction.

Built-in Derived Classes

MiniECS ships with two concrete Module subclasses. Both inherit the Module constructor via using Module::Module and override start().

TransformModule

TransformModule stores 2D spatial data for a Unit and prints that data to stdout on every start() call. It exposes three public glm::vec2 fields.
glm::vec2 position; // World-space position (x, y)
glm::vec2 rotation; // Rotation in two axes (x, y)
glm::vec2 scale;    // Scale factors (x, y)
When start() is called, it prints:
Update / Transform -> Position: <x>, <y>, Rotation: <rx>, <ry>, Scale: <sx>, <sy>
Requires GLM. See the full reference at TransformModule.

RendererModule

RendererModule is a minimal rendering lifecycle hook. Its start() override prints "Start / Started rendering..." to stdout each frame. See the full reference at RendererModule.
Both TransformModule and RendererModule are added to a Unit via Unit::addModule() using their corresponding ModuleType values — you do not construct them directly. Use Unit::getModule<T>() to retrieve a typed pointer after adding them.

Build docs developers (and LLMs) love