ECSTASY
All in the name
Loading...
Searching...
No Matches
ecstasy::MarkerStorage< C > Class Template Reference

Storage for empty components. More...

#include <MarkerStorage.hpp>

Inheritance diagram for ecstasy::MarkerStorage< C >:
Collaboration diagram for ecstasy::MarkerStorage< C >:

Public Types

using Component = typename AStorage< C >::Component
 IsStorage constraint.
 
- Public Types inherited from ecstasy::AStorage< C >
using Component = C
 IsStorage constraint.
 
using QueryData = C &
 QueryableObject constraint.
 
using ConstQueryData = const C &
 ConstQueryableObject constraint.
 

Public Member Functions

template<typename... Args>
 MarkerStorage (Args &&...componentArgs)
 Construct a new Marker Storage for a given Component type.
 
 MarkerStorage (const MarkerStorage &other)=delete
 Copy constructor is deleted.
 
Componentemplace (Entity::Index index)
 Set the marker for a given entity.
 
Componentinsert (Entity::Index index, Component &&c) override final
 Insert a new Component instance associated to the given entity.
 
bool erase (Entity::Index index) override final
 Erase the Component instance associated to the given entity.
 
Componentoperator[] (Entity::Index index) noexcept override final
 Retrieve the Component instance associated to the given entity.
 
const Componentoperator[] (Entity::Index index) const noexcept override final
 Retrieve the Component instance associated to the given entity.
 
constexpr const util::BitSetgetMask () const noexcept override final
 Get the Component Mask.
 
constexpr const ComponentGetInternalComponent () const noexcept
 Get the internal Component returned for all entities.
 
constexpr ComponentGetInternalComponent () noexcept
 Get the Internal Component returned for all entities.
 
- Public Member Functions inherited from ecstasy::AStorage< C >
virtual bool erase (Entity::Index index)=0
 Erase the Component instance associated to the given entity.
 
void erase (std::span< Entity > entities) override final
 Erase multiple Component instances associated to the given entities.
 
bool contains (Entity::Index index) const noexcept override final
 Test if the entity index match a Component instance.
 
Componentat (Entity::Index index)
 Retrieve the Component instance associated to the given entity and perform bound checking.
 
const Componentat (Entity::Index index) const
 Retrieve the Component instance associated to the given entity and perform bound checking.
 
virtual Componentoperator[] (Entity::Index index)=0
 Retrieve the Component instance associated to the given entity.
 
QueryData getQueryData (Entity::Index index)
 Retrieve the Component instance associated to the given entity.
 
virtual const Componentoperator[] (Entity::Index index) const =0
 Retrieve the const Component instance associated to the given entity.
 
ConstQueryData getQueryData (Entity::Index index) const
 Retrieve the Component instance associated to the given entity.
 
const std::type_infogetComponentTypeInfos () const noexcept override final
 Get the Component stored type infos.
 
virtual Componentinsert (Entity::Index index, Component &&c)=0
 Insert a new Component instance associated to the given entity.
 
- Public Member Functions inherited from ecstasy::IStorage
virtual ~IStorage ()=default
 
virtual constexpr const util::BitSetgetMask () const noexcept=0
 Get the Component Mask.
 
virtual void erase (std::span< Entity > entities)=0
 Erase the components attached to the given entities.
 
virtual bool contains (size_t index) const noexcept=0
 Test if the entity index match a Component instance.
 
virtual const std::type_infogetComponentTypeInfos () const noexcept=0
 Get the Component stored type infos.
 

Private Attributes

Component _defaultComponent
 Default component returned for all entities.
 
util::BitSet _mask
 Mask of the entities with the marker.
 

Detailed Description

template<typename C>
class ecstasy::MarkerStorage< C >

Storage for empty components.

This storage stores the presence of the component instead of its data. The returned value is always a reference to a default constructed component.

Template Parameters
CComponent type.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-22)

Definition at line 29 of file MarkerStorage.hpp.

Member Typedef Documentation

◆ Component

template<typename C >
using ecstasy::MarkerStorage< C >::Component = typename AStorage<C>::Component

IsStorage constraint.

Definition at line 32 of file MarkerStorage.hpp.

Constructor & Destructor Documentation

◆ MarkerStorage() [1/2]

template<typename C >
template<typename... Args>
ecstasy::MarkerStorage< C >::MarkerStorage ( Args &&...  componentArgs)
inline

Construct a new Marker Storage for a given Component type.

Template Parameters
ArgsType of the arguments to forward to the component constructor.
Parameters
[in]componentArgsArgs to forward to the component constructor.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-22)

Definition at line 45 of file MarkerStorage.hpp.

45 : _defaultComponent(std::forward<Args>(componentArgs)...)
46 {
47 }
Component _defaultComponent
Default component returned for all entities.

◆ MarkerStorage() [2/2]

template<typename C >
ecstasy::MarkerStorage< C >::MarkerStorage ( const MarkerStorage< C > &  other)
delete

Copy constructor is deleted.

Parameters
[in]otherStorage to copy.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-22)

Member Function Documentation

◆ emplace()

template<typename C >
Component & ecstasy::MarkerStorage< C >::emplace ( Entity::Index  index)
inline

Set the marker for a given entity.

Note
No check is done to see if the entity already has the marker.
Parameters
[in]indexEntity index.
Returns
Component& Placeholder component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-22)

Definition at line 71 of file MarkerStorage.hpp.

72 {
73 _mask.resize(std::max(_mask.size(), index + 1));
74 _mask[index] = true;
75 return _defaultComponent;
76 }
util::BitSet _mask
Mask of the entities with the marker.
void resize(std::size_t size)
Changes the number of bits stored in this set.
Definition BitSet.hpp:199
constexpr std::size_t size() const noexcept
Definition BitSet.hpp:87
T max(T... args)

◆ erase()

template<typename C >
bool ecstasy::MarkerStorage< C >::erase ( Entity::Index  index)
inlinefinaloverridevirtual

Erase the Component instance associated to the given entity.

Note
Does nothing if the index doesn't match with any component (ie if the entity doesn't have a component Component)
Parameters
[in]indexIndex of the entity.
Returns
bool True if the component was erased, false otherwise.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implements ecstasy::AStorage< C >.

Definition at line 88 of file MarkerStorage.hpp.

89 {
90 if (_mask.size() <= index) [[unlikely]]
91 return false;
92 bool result = _mask[index];
93
94 _mask[index] = false;
95 return result;
96 }

◆ GetInternalComponent() [1/2]

template<typename C >
constexpr const Component & ecstasy::MarkerStorage< C >::GetInternalComponent ( ) const
inlineconstexprnoexcept

Get the internal Component returned for all entities.

Returns
constexpr const Component& Const reference to the internal marker.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-22)

Definition at line 126 of file MarkerStorage.hpp.

127 {
128 return _defaultComponent;
129 }

◆ GetInternalComponent() [2/2]

template<typename C >
constexpr Component & ecstasy::MarkerStorage< C >::GetInternalComponent ( )
inlineconstexprnoexcept

Get the Internal Component returned for all entities.

Returns
constexpr Component& Reference to the internal marker.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-04-22)

Definition at line 139 of file MarkerStorage.hpp.

140 {
141 return _defaultComponent;
142 }

◆ getMask()

template<typename C >
constexpr const util::BitSet & ecstasy::MarkerStorage< C >::getMask ( ) const
inlineconstexprfinaloverridevirtualnoexcept

Get the Component Mask.

Note
Each bit set to true mean the entity at the bit index has a component in the storage.
Warning
The mask might be smaller than the entity count.
Returns
const util::BitSet& Component mask.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-20)

Implements ecstasy::IStorage.

Definition at line 113 of file MarkerStorage.hpp.

114 {
115 return _mask;
116 }

◆ insert()

template<typename C >
Component & ecstasy::MarkerStorage< C >::insert ( Entity::Index  index,
Component &&  c 
)
inlinefinaloverridevirtual

Insert a new Component instance associated to the given entity.

Parameters
[in]indexIndex of the entity.
[in]cComponent instance to insert.
Returns
Component& Reference to the inserted component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2024-06-25)

Implements ecstasy::AStorage< C >.

Definition at line 79 of file MarkerStorage.hpp.

80 {
81 (void)c;
82 _mask.resize(std::max(_mask.size(), index + 1));
83 _mask[index] = true;
84 return _defaultComponent;
85 }

◆ operator[]() [1/2]

template<typename C >
const Component & ecstasy::MarkerStorage< C >::operator[] ( Entity::Index  index) const
inlinefinaloverridevirtualnoexcept

Retrieve the Component instance associated to the given entity.

Warning
This function may not perform bound checking. For VectorStorage or MarkerStorage it is noexcept but not for MapStorage for example.
Parameters
[in]indexIndex of the entity.
Returns
Component& Reference to the associated component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implements ecstasy::AStorage< C >.

Definition at line 106 of file MarkerStorage.hpp.

107 {
108 (void)index;
109 return _defaultComponent;
110 }

◆ operator[]() [2/2]

template<typename C >
Component & ecstasy::MarkerStorage< C >::operator[] ( Entity::Index  index)
inlinefinaloverridevirtualnoexcept

Retrieve the Component instance associated to the given entity.

Warning
This function may not perform bound checking. For VectorStorage or MarkerStorage it is noexcept but not for MapStorage for example.
Parameters
[in]indexIndex of the entity.
Returns
Component& Reference to the associated component.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-10-19)

Implements ecstasy::AStorage< C >.

Definition at line 99 of file MarkerStorage.hpp.

100 {
101 (void)index;
102 return _defaultComponent;
103 }

Member Data Documentation

◆ _defaultComponent

template<typename C >
Component ecstasy::MarkerStorage< C >::_defaultComponent
private

Default component returned for all entities.

Definition at line 146 of file MarkerStorage.hpp.

◆ _mask

template<typename C >
util::BitSet ecstasy::MarkerStorage< C >::_mask
private

Mask of the entities with the marker.

Definition at line 148 of file MarkerStorage.hpp.


The documentation for this class was generated from the following file: