Cogs.Foundation
|
Base class for Component instances. More...
#include <Component.h>
Public Member Functions | |
Component ()=default | |
class Entity * | getContainer () const |
Get the container currently owning this component instance. | |
void | setContainer (class Entity *container) |
Set the container owning this component instance. | |
template<typename ComponentType > | |
ComponentType * | getComponent () const |
COGSFOUNDATION_API Component * | getComponent (const Reflection::Name &name) const |
COGSFOUNDATION_API Component * | getComponent (const Reflection::TypeId &id) const |
template<typename ComponentType > | |
ComponentHandle | getComponentHandle () const |
COGSFOUNDATION_API ComponentHandle | getComponentHandle (const Reflection::Name &name) const |
COGSFOUNDATION_API ComponentHandle | getComponentHandle (const Reflection::TypeId &id) const |
void | setActive () |
Sets the component to the ComponentFlags::Active state. | |
bool | isActive () const |
Gets if the component is currently set to the ComponentFlags::Active state. | |
void | setChanged () |
Sets the component to the ComponentFlags::Changed state with carry. | |
void | setChangedTransient () |
Sets the component to the ComponentFlags::Changed state without carry. | |
void | setFieldChanged (const Reflection::FieldId fieldId) |
Sets the component to the ComponentFlags::Changed state without carry. | |
template<typename ClassType , typename FieldType > | |
void | setFieldChanged (FieldType ClassType::*field) |
Sets a flag indicating that the given field has changed. | |
void | setFieldChangedTransient (const Reflection::FieldId fieldId) |
Sets the component to the ComponentFlags::Changed state without carry. | |
bool | hasChanged () const |
bool | hasAnyfieldChanged () const |
Gets if any fields have been changed. | |
bool | hasFieldChanged (const Reflection::FieldId fieldId) const |
Gets if the field with the given id on this component instance has changed. | |
template<typename ClassType , typename FieldType > | |
bool | hasFieldChanged (FieldType ClassType::*field) const |
Gets if the given field has changed. | |
void | resetCarryChanged () |
Reset the CarryChanged flag. Called at start of redraw. See ComponentFlags::CarryChanged. | |
void | resetChanged () |
Resets the changed state of the component, respecting any carry state set. | |
template<typename ClassType , typename FieldType > | |
Reflection::FieldId | getFieldId (FieldType ClassType::*field) const |
Gets field ID of the given field. | |
void | resetFieldsChanged () |
Resets the state of all changed field flags. | |
void | resetFieldChanged (const Reflection::FieldId fieldId) |
Resets the changed state of the given fieldId. | |
template<typename ClassType , typename FieldType > | |
void | resetFieldChanged (FieldType ClassType::*field) |
Resets the changed state of the given field. | |
constexpr void | setFlags (const uint32_t flags) |
Override all flags of the Component, setting the given flags. | |
constexpr void | setFlag (const uint32_t flag) |
Set the given flags. Does not override the currently set flags. | |
constexpr void | unsetFlag (const uint32_t flag) |
Unset the given flag. Does not remove the status of other than the given flags. | |
constexpr bool | isSet (const uint32_t flag) const |
Checks if the given flag is set. Requires exact bit match if test of several bits. | |
constexpr void | setTypeId (const Reflection::TypeId typeId) |
Set the Reflection::TypeId of the component. | |
constexpr Reflection::TypeId | getTypeId () const |
Get the Reflection::TypeId of the component. | |
COGSFOUNDATION_API const Reflection::Type & | getType () const |
Get the full Reflection::Type of the component. | |
constexpr void | setIndex (const ComponentIndex index) |
Set the components pool index. For internal use only. | |
constexpr ComponentIndex | getIndex () const |
Get the components pool index. For internal use only. | |
constexpr void | setGeneration (uint16_t generation) |
Sets the component generation. | |
constexpr uint16_t | getGeneration () const |
Gets the component generation. | |
size_t | hash (size_t hashValue=Cogs::hash()) const |
Calculates a hash of this component's members. | |
Static Public Member Functions | |
static COGSFOUNDATION_API void | registerType () |
Register the Component type in the global type database. | |
static COGSFOUNDATION_API Reflection::TypeId | getComponentTypeId (const StringView &name) |
Get the type id of the component type with the given name. | |
Private Member Functions | |
COGSFOUNDATION_API Reflection::FieldId | getFieldIdFromOffset (size_t offset) const |
Returns Field ID for the field with the given offset. Returns NoField if not a registered field. | |
Static Private Member Functions | |
static constexpr uint32_t | leftShift (const uint32_t value, const uint32_t fieldId) |
Base class for Component instances.
Contains housekeeping data and a pointer to the owner of the component instance.
|
default |
|
inline |
Get a component with the given ComponentType type from the owner of this component. Returns null if no matching instance is found.
References getComponent(), and getComponentTypeId().
Referenced by getComponent().
Cogs::ComponentModel::Component * Cogs::ComponentModel::Component::getComponent | ( | const Reflection::Name & | name | ) | const |
Get a component with the given type name from the owner of this component. Returns null if no matching instance is found.
Cogs::ComponentModel::Component * Cogs::ComponentModel::Component::getComponent | ( | const Reflection::TypeId & | id | ) | const |
Get a component with the given type id from the owner of this component. Returns null if no matching instance is found.
|
inline |
Get a component handle with the given ComponentType type from the owner of this component. Returns null if no matching instance is found.
References getComponentHandle(), and getComponentTypeId().
Referenced by getComponentHandle().
Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Component::getComponentHandle | ( | const Reflection::Name & | name | ) | const |
Get a component handle with the given type name from the owner of this component. Returns ComponentHandle::Empty if no matching instance is found.
References Cogs::ComponentModel::ComponentHandle::Empty().
Cogs::ComponentModel::ComponentHandle Cogs::ComponentModel::Component::getComponentHandle | ( | const Reflection::TypeId & | id | ) | const |
Get a component handle with the given type id from the owner of this component. Returns ComponentHandle::Empty if no matching instance is found.
References Cogs::ComponentModel::ComponentHandle::Empty().
|
static |
Get the type id of the component type with the given name.
References Cogs::Reflection::TypeDatabase::getType(), and Cogs::Reflection::Type::getTypeId().
Referenced by getComponent(), and getComponentHandle().
|
inline |
Get the container currently owning this component instance.
|
inline |
Gets field ID of the given field.
Allows caching the ID for later hasFieldChanged checking as hasFieldChanged using hasFieldChanged(&Component<T>::fieldMemberName) requires type DB lookups.
ClassType | Type of the component class. |
FieldType | Type of the field. |
field | Pointer to member to the field. |
References getFieldIdFromOffset(), and Cogs::memberOffset().
Referenced by hasFieldChanged(), resetFieldChanged(), and setFieldChanged().
|
private |
Returns Field ID for the field with the given offset. Returns NoField if not a registered field.
Referenced by getFieldId().
|
inlineconstexpr |
Gets the component generation.
|
inlineconstexpr |
Get the components pool index. For internal use only.
Referenced by Cogs::ComponentModel::ComponentPoolBase::getComponentIndex().
const Cogs::Reflection::Type & Cogs::ComponentModel::Component::getType | ( | ) | const |
Get the full Reflection::Type of the component.
References Cogs::Reflection::TypeDatabase::getType().
|
inlineconstexpr |
Get the Reflection::TypeId of the component.
|
inline |
Gets if any fields have been changed.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged.
|
inline |
Gets if the component is currently set to the ComponentFlags::Changed state. Use hasFieldChanged to check for individual fields.
References Cogs::ComponentModel::ComponentFlags::Changed, and isSet().
|
inline |
Gets if the field with the given id on this component instance has changed.
Note that fieldIds in Overflow range share change flag.
fieldId | Field id of the field to check for changes. |
References Cogs::ComponentModel::ComponentFlags::FieldChange, isSet(), leftShift(), and Cogs::ComponentModel::ComponentFlags::OverflowFieldChange.
Referenced by hasFieldChanged().
|
inline |
Gets if the given field has changed.
Expensive - cache fieldID and use this where possible. It is usually not necessary to manually specify template parameters for this method, as they will be deduced from the method parameter.
ClassType | Type of the component class. |
FieldType | Type of the field to check for changed status. |
field | Pointer to member to the field to check for changes. |
References getFieldId(), and hasFieldChanged().
|
inline |
Calculates a hash of this component's members.
References Cogs::hash().
|
inline |
Gets if the component is currently set to the ComponentFlags::Active state.
References Cogs::ComponentModel::ComponentFlags::Active, and isSet().
|
inlineconstexpr |
Checks if the given flag is set. Requires exact bit match if test of several bits.
Referenced by hasChanged(), hasFieldChanged(), isActive(), and resetChanged().
|
inlinestaticconstexprprivate |
Referenced by hasFieldChanged(), resetFieldChanged(), setFieldChanged(), and setFieldChangedTransient().
|
static |
Register the Component type in the global type database.
|
inline |
Reset the CarryChanged flag. Called at start of redraw. See ComponentFlags::CarryChanged.
References Cogs::ComponentModel::ComponentFlags::CarryChanged, and unsetFlag().
|
inline |
Resets the changed state of the component, respecting any carry state set.
If the CarryChanged flag is set, the Changed and FieldChange flags will still be present. The CarryChanged flag is not changed. Called at end of redraw loop.
Call resetCarryChanged() first to ensure a full change state reset.
References Cogs::ComponentModel::ComponentFlags::CarryChanged, Cogs::ComponentModel::ComponentFlags::Changed, isSet(), resetFieldsChanged(), and unsetFlag().
|
inline |
Resets the changed state of the given fieldId.
Note that fieldIds in Overflow range share change flag and cannot be reset.
fieldId | Field id of the field to reset. |
References Cogs::ComponentModel::ComponentFlags::FieldChange, leftShift(), and unsetFlag().
Referenced by resetFieldChanged().
|
inline |
Resets the changed state of the given field.
Expensive - cache fieldID and use this where possible. Note that fieldIds in Overflow range share change flag and cannot be reset.
ClassType | Type of the component class. |
FieldType | Type of the changed field. |
field | Pointer to member to the field to reset. |
References getFieldId(), and resetFieldChanged().
|
inline |
Resets the state of all changed field flags.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged, and unsetFlag().
Referenced by resetChanged().
|
inline |
Sets the component to the ComponentFlags::Active state.
References Cogs::ComponentModel::ComponentFlags::Active, and setFlag().
|
inline |
Sets the component to the ComponentFlags::Changed state with carry.
Also marks all fields changed.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged, Cogs::ComponentModel::ComponentFlags::CarryChanged, Cogs::ComponentModel::ComponentFlags::Changed, and setFlag().
|
inline |
Sets the component to the ComponentFlags::Changed state without carry.
Also marks all fields changed. This call is typically set to trigger an update for another component but will only have effect if the component is not yet updated.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged, Cogs::ComponentModel::ComponentFlags::Changed, and setFlag().
|
inline |
Set the container owning this component instance.
|
inline |
Sets the component to the ComponentFlags::Changed state without carry.
Also sets a flag indicating that the field with the given field id has changed. The first N (24) fields are tracked individually. The remaining tracked by same flag.
fieldId | Field id of the changed field. |
References Cogs::ComponentModel::ComponentFlags::CarryChanged, Cogs::ComponentModel::ComponentFlags::Changed, Cogs::ComponentModel::ComponentFlags::FieldChange, leftShift(), Cogs::ComponentModel::ComponentFlags::OverflowFieldChange, and setFlag().
Referenced by setFieldChanged().
|
inline |
Sets a flag indicating that the given field has changed.
Expensive - cache fieldID and use this where possible. It is usually not necessary to manually specify template parameters for this method, as they will be deduced from the method parameter.
ClassType | Type of the component class. |
FieldType | Type of the changed field. |
field | Pointer to member to the field that changed. |
References getFieldId(), and setFieldChanged().
|
inline |
Sets the component to the ComponentFlags::Changed state without carry.
Also sets a flag indicating that the field with the given field id has changed. The first N (24) fields are tracked individually. The remaining tracked by same flag. This call is typically set to trigger an update for another component but will only have effect if the component is not yet updated.
fieldId | Field id of the changed field. |
References Cogs::ComponentModel::ComponentFlags::Changed, Cogs::ComponentModel::ComponentFlags::FieldChange, leftShift(), Cogs::ComponentModel::ComponentFlags::OverflowFieldChange, and setFlag().
|
inlineconstexpr |
Set the given flags. Does not override the currently set flags.
Referenced by setActive(), setChanged(), setChangedTransient(), setFieldChanged(), and setFieldChangedTransient().
|
inlineconstexpr |
Override all flags of the Component, setting the given flags.
|
inlineconstexpr |
Sets the component generation.
|
inlineconstexpr |
Set the components pool index. For internal use only.
|
inlineconstexpr |
Set the Reflection::TypeId of the component.
|
inlineconstexpr |
Unset the given flag. Does not remove the status of other than the given flags.
Referenced by resetCarryChanged(), resetChanged(), resetFieldChanged(), and resetFieldsChanged().