ECSTASY
All in the name
Loading...
Searching...
No Matches
MarkerStorage.hpp
Go to the documentation of this file.
1
11
12#ifndef ECSTASY_STORAGE_MARKERSTORAGE_HPP_
13#define ECSTASY_STORAGE_MARKERSTORAGE_HPP_
14
15#include "AStorage.hpp"
16
17namespace ecstasy
18{
28 template <typename C>
29 class MarkerStorage : public AStorage<C> {
30 public:
33
44 template <typename... Args>
45 MarkerStorage(Args &&...componentArgs) : _defaultComponent(std::forward<Args>(componentArgs)...)
46 {
47 }
48
57 MarkerStorage(const MarkerStorage &other) = delete;
58
72 {
73 _mask.resize(std::max(_mask.size(), index + 1));
74 _mask[index] = true;
75 return _defaultComponent;
76 }
77
79 Component &insert(Entity::Index index, Component &&c) override final
80 {
81 (void)c;
82 _mask.resize(std::max(_mask.size(), index + 1));
83 _mask[index] = true;
84 return _defaultComponent;
85 }
86
88 bool erase(Entity::Index index) override final
89 {
90 if (_mask.size() <= index) [[unlikely]]
91 return false;
92 bool result = _mask[index];
93
94 _mask[index] = false;
95 return result;
96 }
97
99 [[nodiscard]] Component &operator[](Entity::Index index) noexcept override final
100 {
101 (void)index;
102 return _defaultComponent;
103 }
104
106 [[nodiscard]] const Component &operator[](Entity::Index index) const noexcept override final
107 {
108 (void)index;
109 return _defaultComponent;
110 }
111
113 [[nodiscard]] constexpr const util::BitSet &getMask() const noexcept override final
114 {
115 return _mask;
116 }
117
126 [[nodiscard]] constexpr const Component &GetInternalComponent() const noexcept
127 {
128 return _defaultComponent;
129 }
130
139 [[nodiscard]] constexpr Component &GetInternalComponent() noexcept
140 {
141 return _defaultComponent;
142 }
143
144 private:
149 };
150} // namespace ecstasy
151
152#endif /* !ECSTASY_STORAGE_MARKERSTORAGE_HPP_ */
Abstract class for all components storage.
Definition AStorage.hpp:34
C Component
IsStorage constraint.
Definition AStorage.hpp:37
size_t Index
The entity identifier type.
Definition Entity.hpp:38
Storage for empty components.
constexpr const util::BitSet & getMask() const noexcept override final
Get the Component Mask.
bool erase(Entity::Index index) override final
Erase the Component instance associated to the given entity.
constexpr Component & GetInternalComponent() noexcept
Get the Internal Component returned for all entities.
Component & operator[](Entity::Index index) noexcept override final
Retrieve the Component instance associated to the given entity.
Component & insert(Entity::Index index, Component &&c) override final
Insert a new Component instance associated to the given entity.
Component & emplace(Entity::Index index)
Set the marker for a given entity.
MarkerStorage(const MarkerStorage &other)=delete
Copy constructor is deleted.
typename AStorage< C >::Component Component
IsStorage constraint.
util::BitSet _mask
Mask of the entities with the marker.
const Component & operator[](Entity::Index index) const noexcept override final
Retrieve the Component instance associated to the given entity.
Component _defaultComponent
Default component returned for all entities.
constexpr const Component & GetInternalComponent() const noexcept
Get the internal Component returned for all entities.
MarkerStorage(Args &&...componentArgs)
Construct a new Marker Storage for a given Component type.
Mimics the API of std::bitset but with the dynamic properties of std::vector<bool>
Definition BitSet.hpp:35
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)
Namespace containing all symbols specific to ecstasy.
Definition ecstasy.hpp:30