4#include "../Entity/entity.h"
15template <
typename Component>
29 : componentContainer(componentContainer), entity(entity) {}
42 operator Component*() {
return getVolatile(); }
53 int lastReallocated = -1;
54 Component* cachedComponent =
nullptr;
55 std::shared_ptr<ComponentContainer<Component>> componentContainer;
63 Component* getVolatile() {
64 if (!componentContainer)
return nullptr;
66 if (componentContainer->getLastReallocated() > lastReallocated) {
67 cachedComponent = componentContainer->getComponent(entity);
68 lastReallocated = componentContainer->getLastReallocated();
70 return cachedComponent;
Container for a specific Component type.
Definition: componentContainer.h:39
Reference to a component. Will be valid as long as that component exists on a specific Entity,...
Definition: componentReference.h:16
ComponentReference(std::shared_ptr< ComponentContainer< Component > > componentContainer, Entity entity)
Construct a new Component Reference object.
Definition: componentReference.h:28
ComponentReference()
Construct a new Component Reference object.
Definition: componentReference.h:21
virtual ~ComponentReference()
Destroy the Component Reference object.
Definition: componentReference.h:34
Component * operator->()
Automatic cast of ComponentReference to their volatile Component pointer form.
Definition: componentReference.h:49