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::World is the top-level scene container. It owns all Units and drives the simulation loop. Every scene begins with a World instance — you create and configure Units through it, then hand control over to the game loop by calling play().
Namespace & Header
Constructor
worldName. No Units are created at construction time; use createUnit() to populate the scene.
The display name for this World instance. Stored internally and used for identification purposes.
createUnit
Unit with the given name, wraps it in a std::unique_ptr, and appends it to the internal worldUnits vector. If newUnitName is an empty string, the method prints "New unit name invalid!" to stdout and returns without creating anything.
The name to assign to the new Unit. Must be non-empty — passing an empty string is a no-op and produces a console warning.
Unit names are used as identifiers by
removeUnitByName() and getUnitByName(). Choose unique names to avoid ambiguous lookups.removeUnitByName
worldUnits vector for a Unit whose name matches unitName. If a match is found, that Unit is erased from the vector and its destructor is called (the unique_ptr is released). If no match is found, the method prints "Could not find: <unitName>" to stdout and leaves the vector unchanged.
The name of the Unit to locate and remove. The comparison is an exact string match.
removeUnitByIndex
worldUnits vector. Internally uses vector::at() to access the element, which means an out-of-range index will throw a standard library exception rather than silently invoking undefined behaviour.
Zero-based index into the units vector. Valid range is
[0, getUnitsVector().size() - 1].getUnitByName
worldUnits and returns a mutable reference to the unique_ptr<Unit> whose getName() matches name. This allows you to call Unit methods or pass the smart pointer around without transferring ownership.
The exact name of the Unit to retrieve.
std::unique_ptr<Unit>& — a reference to the smart pointer that owns the matched Unit.
Example
getUnitByIndex
unique_ptr<Unit> at the given zero-based index. Internally delegates to vector::at(), so out-of-range access throws rather than silently corrupting memory.
Zero-based index into the units vector. Valid range is
[0, getUnitsVector().size() - 1].std::unique_ptr<Unit>& — a reference to the smart pointer at the specified position.
Throws: std::out_of_range if index is outside the bounds of the vector.
Example
getUnitsVector
const reference to the internal worldUnits vector. Use this for read-only iteration over all Units in the scene — for example, to inspect names or module counts without modifying the collection.
Returns: const std::vector<std::unique_ptr<Unit>>& — a read-only reference to the units container.
Example
play
worldUnits is non-empty; if it is empty, it prints "No units in the scene" and returns. It then iterates the units vector in order:
- If a Unit has no Modules attached, it prints
"No units in the scene have modules"and moves on to the next Unit. - If a Unit has at least one Module attached, it enters an infinite
while(true)loop for that Unit, callingunit->callModuleStart()each iteration and sleeping the calling thread for 16 milliseconds (approximately 60 frames per second) viastd::this_thread::sleep_for.