Cogs.Core
|
Base class for Component instances. More...
#include <Component.h>
Public Member Functions | |
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.
Definition at line 142 of file Component.h.
|
inline |
Get a component with the given ComponentType type from the owner of this component. Returns null if no matching instance is found.
Definition at line 159 of file Component.h.
References getComponent(), and getComponentTypeId().
Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::OGC3DTilesSystem::addModelToScene(), Cogs::Core::applyRenderMaterial(), Cogs::Core::VideoCaptureSystem::destroyComponent(), Cogs::Core::Volumetric::OctBounds::getBounds(), Cogs::Core::TerrainBounds::getBounds(), Cogs::Core::InstancedMeshRenderBounds::getBounds(), Cogs::Core::ViewContext::getCameraComponent(), getComponent(), Cogs::Core::SeaCurrentsSystem::getWorldBounds(), Cogs::Core::PotreePicker::pickCamera(), Cogs::Core::Image360::RayPickExtension::pickCamera(), Cogs::Core::OceanPicker::pickCamera(), Cogs::Core::TerrainPicker::pickCamera(), Cogs::Core::VectorField::VectorFieldPick::pickCamera(), Cogs::Core::MarkerPointSetPicker::pickCamera(), Cogs::Core::PotreePicker::pickRay(), Cogs::Core::MarkerPointSetPicker::pickRay(), Cogs::Core::BasicOceanSystem::postUpdate(), Cogs::Core::LightSystem::preRender(), Cogs::Core::EchoSounder::OctProviderSystem::preUpdate(), Cogs::Core::PotreeSystem::preUpdate(), Cogs::Core::VideoCaptureSystem::preUpdate(), Cogs::Core::ClipShapeSystem::preUpdate(), Cogs::Core::OGC3DTilesSystem::pruneTileCache(), Cogs::Core::EntityStore::removeChildren(), Cogs::Core::ViewContext::setCamera(), Cogs::Core::TrajectoryAlignedComponent::update(), Cogs::Core::MarkerPointSetSystem::update(), Cogs::Core::DepthAxisSystem::update(), Cogs::Core::TrajectoryCrossSectionsSystem::update(), Cogs::Core::HeightMapSystem::update(), Cogs::Core::BillboardSystem::update(), Cogs::Core::LodSystem::update(), Cogs::Core::TrajectorySystem::update(), Cogs::Core::VariableExtrusionSystem::update(), Cogs::Core::TrajectoryLayoutSystem::update(), Cogs::Core::RigidBodySystem::update(), Cogs::Core::TriggerSystem::update(), Cogs::Core::CubeMarkerSystem::update(), Cogs::Core::LoftedCrossSectionsSystem::update(), Cogs::Core::EchoSounder::OctProviderSystem::update(), Cogs::Core::EchoSounder::PingIsoSystem::update(), Cogs::Core::EchoSounder::SwathBottomSystem::update(), Cogs::Core::EchoSounder::SwathIsoSystem::update(), Cogs::Core::PotreeSystem::update(), Cogs::Core::OceanSystem::update(), Cogs::Core::Volumetric::DensityFieldSystem::update(), Cogs::Core::Volumetric::OctSystem::update(), Cogs::Core::Volumetric::PointVisualizationSystem::update(), Cogs::Core::BasicOceanSystem::update(), Cogs::Core::AssetSystem::update(), Cogs::Core::CameraArraySystem::update(), Cogs::Core::ClipShapeSystem::update(), Cogs::Core::StaticModelSystem::update(), Cogs::Core::Text3DSystem::update(), Cogs::Core::AdaptivePlanarGridSystem::update(), and Cogs::Core::ShapeSystem::update().
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.
Definition at line 37 of file Component.cpp.
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.
Definition at line 44 of file Component.cpp.
|
inline |
Get a component handle with the given ComponentType type from the owner of this component. Returns null if no matching instance is found.
Definition at line 177 of file Component.h.
References getComponentHandle(), and getComponentTypeId().
Referenced by getComponentHandle(), Cogs::Core::CameraArraySystem::update(), Cogs::Core::CameraSystem::update(), Cogs::Core::InstancedMeshRenderSystem::update(), Cogs::Core::RenderSystem::update(), Cogs::Core::SubMeshRenderSystem::update(), and Cogs::Core::TextSystem::update().
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.
Definition at line 51 of file Component.cpp.
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.
Definition at line 58 of file Component.cpp.
References Cogs::ComponentModel::ComponentHandle::Empty().
|
static |
Get the type id of the component type with the given name.
Definition at line 32 of file Component.cpp.
References Cogs::Reflection::TypeDatabase::getType(), and Cogs::Reflection::Type::getTypeId().
Referenced by getComponent(), and getComponentHandle().
|
inline |
Get the container currently owning this component instance.
Definition at line 151 of file Component.h.
Referenced by Cogs::Core::Engine::invokeComponentNotifyCallback(), Cogs::Core::RayPicking::RayPickFilter::isUnwantedType(), Cogs::Core::EchoSounder::UniformGridSystem::preUpdate(), Cogs::Core::RayPicking::RayPickHit::RayPickHit(), Cogs::Core::EchoSounder::SwathBottomSystem::update(), Cogs::Core::EchoSounder::SwathIsoSystem::update(), Cogs::Core::AssetSystem::update(), Cogs::Core::AdaptivePlanarGridSystem::update(), and Cogs::Core::ShapeSystem::update().
|
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. |
Definition at line 328 of file Component.h.
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.
Definition at line 22 of file Component.cpp.
Referenced by getFieldId().
|
inlineconstexpr |
Gets the component generation.
Definition at line 400 of file Component.h.
|
inlineconstexpr |
Get the components pool index. For internal use only.
Definition at line 392 of file Component.h.
Referenced by Cogs::ComponentModel::ComponentPoolBase::getComponentIndex().
const Cogs::Reflection::Type & Cogs::ComponentModel::Component::getType | ( | ) | const |
Get the full Reflection::Type of the component.
Definition at line 27 of file Component.cpp.
References Cogs::Reflection::TypeDatabase::getType().
Referenced by Cogs::Core::findHierarchyWithMatch().
|
inlineconstexpr |
Get the Reflection::TypeId of the component.
Definition at line 380 of file Component.h.
Referenced by Cogs::Core::Engine::invokeComponentNotifyCallback().
|
inline |
Gets if any fields have been changed.
Definition at line 262 of file Component.h.
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.
Definition at line 259 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::Changed, and isSet().
Referenced by Cogs::Core::LightSystem::preRender(), Cogs::Core::ClipShapeSystem::preUpdate(), Cogs::Core::TransformSystem::update(), Cogs::Core::TrajectoryCrossSectionsSystem::update(), Cogs::Core::TrajectorySystem::update(), Cogs::Core::VariableExtrusionSystem::update(), Cogs::Core::FixedConstraintSystem::update(), Cogs::Core::HingeConstraintSystem::update(), Cogs::Core::SpringConstraintSystem::update(), Cogs::Core::GenericConstraintSystem::update(), Cogs::Core::EchoSounder::PingIsoSystem::update(), Cogs::Core::BasicOceanSystem::update(), Cogs::Core::ClipShapeSystem::update(), Cogs::Core::InstancedMeshRenderSystem::update(), Cogs::Core::RenderSystem::update(), Cogs::Core::SubMeshRenderSystem::update(), Cogs::Core::AdaptivePlanarGridSystem::update(), and Cogs::Core::ShapeSystem::update().
|
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. |
Definition at line 272 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::FieldChange, isSet(), 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. |
Definition at line 290 of file Component.h.
References getFieldId(), and hasFieldChanged().
|
inline |
Calculates a hash of this component's members.
Definition at line 405 of file Component.h.
References Cogs::hash().
|
inline |
Gets if the component is currently set to the ComponentFlags::Active state.
Definition at line 196 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::Active, and isSet().
|
inlineconstexpr |
Checks if the given flag is set. Requires exact bit match if test of several bits.
Definition at line 374 of file Component.h.
Referenced by hasChanged(), hasFieldChanged(), isActive(), resetChanged(), and Cogs::setChanged().
|
inlinestaticconstexprprivate |
Definition at line 417 of file Component.h.
|
static |
Register the Component type in the global type database.
Definition at line 17 of file Component.cpp.
|
inline |
Reset the CarryChanged flag. Called at start of redraw. See ComponentFlags::CarryChanged.
Definition at line 296 of file Component.h.
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.
Definition at line 309 of file Component.h.
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. |
Definition at line 342 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::FieldChange, 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. |
Definition at line 359 of file Component.h.
References getFieldId(), and resetFieldChanged().
|
inline |
Resets the state of all changed field flags.
Definition at line 334 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged, and unsetFlag().
Referenced by resetChanged().
|
inline |
Sets the component to the ComponentFlags::Active state.
Definition at line 193 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::Active, and setFlag().
|
inline |
Sets the component to the ComponentFlags::Changed state with carry.
Also marks all fields changed.
Definition at line 202 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged, Cogs::ComponentModel::ComponentFlags::CarryChanged, Cogs::ComponentModel::ComponentFlags::Changed, and setFlag().
Referenced by Cogs::Core::EntityStore::addChild(), Cogs::Core::OGC3DTilesSystem::addModelToScene(), Cogs::Core::VideoCaptureSystem::destroyComponent(), Cogs::Core::PotreeSystem::preUpdate(), Cogs::Core::VideoCaptureSystem::preUpdate(), Cogs::Core::OGC3DTilesSystem::pruneTileCache(), Cogs::Core::ViewContext::setCamera(), Cogs::Core::ViewContext::setSize(), Cogs::Core::OrbitingCameraController::setTarget(), Cogs::Core::TrajectoryAlignedComponent::update(), Cogs::Core::MarkerPointSetSystem::update(), Cogs::Core::HeightMapSystem::update(), Cogs::Core::TextureGeneratorSystem::update(), Cogs::Core::LoftedCrossSectionsSystem::update(), Cogs::Core::EchoSounder::PingIsoSystem::update(), Cogs::Core::EchoSounder::SwathIsoSystem::update(), Cogs::Core::Volumetric::DensityFieldSystem::update(), Cogs::Core::BasicOceanSystem::update(), Cogs::Core::Text3DSystem::update(), and Cogs::Core::ShapeSystem::update().
|
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.
Definition at line 209 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::AllFieldChanged, Cogs::ComponentModel::ComponentFlags::Changed, and setFlag().
|
inline |
Set the container owning this component instance.
Definition at line 154 of file Component.h.
|
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. |
Definition at line 218 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::CarryChanged, Cogs::ComponentModel::ComponentFlags::Changed, Cogs::ComponentModel::ComponentFlags::FieldChange, Cogs::ComponentModel::ComponentFlags::OverflowFieldChange, and setFlag().
Referenced by Cogs::setChanged(), and 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. |
Definition at line 237 of file Component.h.
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. |
Definition at line 250 of file Component.h.
References Cogs::ComponentModel::ComponentFlags::Changed, Cogs::ComponentModel::ComponentFlags::FieldChange, Cogs::ComponentModel::ComponentFlags::OverflowFieldChange, and setFlag().
|
inlineconstexpr |
Set the given flags. Does not override the currently set flags.
Definition at line 368 of file Component.h.
Referenced by Cogs::Core::LightSystem::preRender(), setActive(), setChanged(), setChangedTransient(), setFieldChanged(), and setFieldChangedTransient().
|
inlineconstexpr |
Override all flags of the Component, setting the given flags.
Definition at line 365 of file Component.h.
|
inlineconstexpr |
Sets the component generation.
Definition at line 395 of file Component.h.
|
inlineconstexpr |
Set the components pool index. For internal use only.
Definition at line 389 of file Component.h.
|
inlineconstexpr |
Set the Reflection::TypeId of the component.
Definition at line 377 of file Component.h.
|
inlineconstexpr |
Unset the given flag. Does not remove the status of other than the given flags.
Definition at line 371 of file Component.h.
Referenced by Cogs::Core::LightSystem::preRender(), resetCarryChanged(), resetChanged(), resetFieldChanged(), and resetFieldsChanged().