MiniECS is designed to be extended. TheDocumentation 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.
Module base class provides a minimal, consistent interface — a constructor that accepts a ModuleType, a virtual start() method called each frame, and typed introspection via getType() and getTypeName(). Adding new behaviour to any Unit is a matter of inheriting from Module, registering a new enum value, and wiring the type into the Unit::addModule() switch-case. The walkthrough below uses a PhysicsModule as a concrete example.
Add a new ModuleType enum value
All module identity in MiniECS flows through the
ModuleType enum class defined in Module.h. Open that file and add a new entry for your module. Each value must be a unique integer — the framework uses it to prevent duplicate modules from being added to the same Unit.ModuleType is an enum class, so values are scoped (ModuleType::Physics) and do not implicitly convert to integers. Every entry must have a distinct value; reusing an integer will cause the duplicate-prevention check in addModule() to misidentify unrelated module types as duplicates.Create the header file PhysicsModule.h
Create
src/modules/physics/PhysicsModule.h. Inherit publicly from Module, bring in the base constructor with using Module::Module, declare any data members your module needs, and override start().Implement start() in PhysicsModule.cpp
Create
src/modules/physics/PhysicsModule.cpp. The start() method is called by Unit::callModuleStart() for every module attached to a unit. Put your per-frame logic here.Register the new type in Unit::addModule()
Open Then add a Without this case,
src/unit/Unit.cpp. At the top of the file, add an #include for your new header alongside the existing module includes:case for ModuleType::Physics inside the switch statement in Unit::addModule():addModule(ModuleType::Physics) falls through to the default branch and prints "Invalid Module Type!!" without creating anything.Add PhysicsModule to CMakeLists.txt
MiniECS uses a flat
add_executable list in its CMakeLists.txt. Add both the header and the implementation file so CMake includes them in the build:Use the new module
With the enum value registered and the switch-case wired up, you can attach When
PhysicsModule to any Unit and access it through the templated getModule<T>() method, just like the built-in modules.scene.play() runs, callModuleStart() will invoke PhysicsModule::start() on every tick, printing the updated velocity to stdout.