2#include "ComponentPool.h"
5#include "../Reflection/TypeDatabase.h"
7#include "../Logging/Logger.h"
11 size_t generationMismatchCount = 0;
19 Reflection::TypeDatabase::createAbstractType<Component>();
24 return getType().getFieldId(offset);
39 if (!container)
return nullptr;
41 return container->getComponent(name);
46 if (!container)
return nullptr;
48 return container->getComponent(
id);
55 return container->getComponentHandle(name);
62 return container->getComponentHandle(
id);
68 auto * comp = pool->resolve(*
this);
69 if (comp->getGeneration() == generation) {
74 if (++generationMismatchCount <= 10) {
75 LOG_WARNING(logger,
"Component generation mismatch: %u, Expected: %u", comp->getGeneration(), generation);
Base class for Component instances.
static COGSFOUNDATION_API void registerType()
Register the Component type in the global type database.
ComponentType * getComponent() const
static COGSFOUNDATION_API Reflection::TypeId getComponentTypeId(const StringView &name)
Get the type id of the component type with the given name.
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.
ComponentHandle getComponentHandle() const
COGSFOUNDATION_API const Reflection::Type & getType() const
Get the full Reflection::Type of the component.
Log implementation class.
static const Type & getType()
Get the Type of the given template argument.
Represents a discrete type definition, describing a native type class.
constexpr TypeId getTypeId() const
Get the unique Reflection::TypeId of this instance.
Provides a weakly referenced view over the contents of a string.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
uint16_t FieldId
Type used to index fields.
@ Changed
The components data has changed.
Handle to a Component instance.
COGSFOUNDATION_API class Component * resolve() const
Resolve the handle, returning a pointer to the held Component instance.
static ComponentHandle Empty()
Returns an empty, invalid handle. Will evaluate to false if tested against using operator bool().
Represents an unique name.