8#include "EntityStore.h"
10#include "Foundation/ComponentModel/Component.h"
11#include "Foundation/Reflection/TypeDatabase.h"
18 ComponentId componentId,
30 context->
engine->setDirty();
34 template<
typename DataType>
37 using FieldType = std::vector<DataType>;
40 auto field = getComponentField(context, entityId, componentId, fieldId, component);
41 if (!component || !field)
return;
46 auto fieldPointer = field->getPtr<FieldType>(component);
48 fieldPointer->assign(data, data + count);
53 template<
typename DataType>
56 using FieldType = std::vector<DataType>;
59 auto field = getComponentField(context, entityId, componentId, fieldId, component);
60 if (!component || !field)
return;
65 auto fieldPointer = field->getPtr<FieldType>(component);
67 count = std::max(0, std::min(count,
static_cast<int>(fieldPointer->size()) - offset));
69 std::copy_n(data, count, fieldPointer->begin() + offset);
75 template<
typename FieldType>
78 using FieldValueType =
typename std::remove_const_t<typename std::remove_reference_t<FieldType>>;
81 auto field = getComponentField(context, entityId, componentId, fieldId, component);
82 if (!component || !field)
return nullptr;
84 return field->getPtr<FieldValueType>(component);
87 template<
typename FieldType>
90 using FieldValueType =
typename std::remove_const_t<typename std::remove_reference_t<FieldType>>;
93 auto field = getComponentField(context, entityId, componentId, fieldId, component);
94 if (!component || !field)
return;
99 auto fieldPointer = field->getPtr<FieldValueType>(component);
101 *fieldPointer = std::forward<FieldType>(data);
106 template<
typename FieldType>
109 using FieldValueType =
typename std::remove_const_t<typename std::remove_reference_t<FieldType>>;
112 auto field = getComponentField(context, entityId, componentId, fieldId, component);
113 if (!component || !field)
return;
118 auto fieldPointer = field->getPtr< std::vector<FieldValueType>>(component);
119 assert(fieldPointer->size() > index);
120 (*fieldPointer)[index] = std::forward<FieldType>(data);
Base class for Component instances.
void setFieldChanged(const Reflection::FieldId fieldId)
Sets the component to the ComponentFlags::Changed state without carry.
constexpr bool isSet(const uint32_t flag) const
Checks if the given flag is set. Requires exact bit match if test of several bits.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
std::unique_ptr< class Engine > engine
Engine instance.
Field definition describing a single data member of a data structure.
static const Type & getType()
Get the Type of the given template argument.
constexpr size_t getSize() const
Get the size of an instance of the reflected type, in bytes.
uint16_t FieldId
Type used to index fields.
Contains all Cogs related functionality.
void setChanged(Cogs::Core::Context *context, Cogs::ComponentModel::Component *component, Reflection::FieldId fieldId)
Must be Called after changing a Component field. Mark field changed. Request engine update.
void assignField(Cogs::Core::Context *context, EntityId entityId, const ComponentId componentId, const Cogs::Reflection::FieldId fieldId, const DataType *data, int count)
Assign value to a Component field.
@ DisableTracking
No change tracking should be performed on the component.