guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::ecs::Component Class Reference

Base class of every component: a piece of state attached to an entity, plus a "changed" flag. More...

#include <headers/guillaume/ecs/component.hpp>

Inheritance diagram for guillaume::ecs::Component:

Public Member Functions

bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Detailed Description

Base class of every component: a piece of state attached to an entity, plus a "changed" flag.

A component holds data only (a size, a color, a checkbox configuration); the rules that read and write it live in systems. One instance is stored per entity and per component type in a ComponentRegistry, and is reached by entity identifier.

The base class adds one thing: the changed flag. A derived component raises it from its setters when a value really changes; the frame loop lowers every flag at the end of the frame (ComponentRegistry::resetChangedFlags). A component starts unchanged: adding it to an entity does not raise the flag.

class Opacity: public guillaume::ecs::Component
{
public:
float getValue(void) const { return _value; }
Opacity &setValue(float value)
{
if (_value != value) {
_value = value;
}
return *this;
}
private:
float _value { 1.0f }; // 0 to 1
};
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
Note
Components are stored by value and replaced by assignment, so a component type must be movable and constructible from the arguments given to ComponentRegistry::addComponent.
See also
ComponentRegistry
System

Definition at line 71 of file component.hpp.

Member Function Documentation

◆ hasChanged()

bool guillaume::ecs::Component::hasChanged ( void ) const

Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).

Returns
True when the component is marked as changed.
See also
ComponentRegistry::hasChanged

Definition at line 27 of file component.cpp.

Here is the caller graph for this function:

◆ setHasChanged()

void guillaume::ecs::Component::setHasChanged ( bool hasChanged)

Raise or lower the changed flag.

Setters of derived components call setHasChanged(true) after storing a different value. ComponentRegistry::resetChangedFlags calls setHasChanged(false) on every component.

Parameters
hasChangedTrue to mark the component as changed, false to mark it as unchanged.

Definition at line 32 of file component.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files: