2#include "gaia/config/config.h"
6#include "gaia/cnt/darray.h"
7#include "gaia/core/utility.h"
8#include "gaia/ecs/id.h"
21 uint32_t srcToTgtCnt = 0;
29 const auto required = (uint32_t)source.
id() + 1;
30 if (srcToTgt.
size() >= required)
33 const auto oldSize = (uint32_t)srcToTgt.
size();
34 auto newSize = oldSize == 0 ? 16U : oldSize;
35 while (newSize < required)
38 srcToTgt.
resize(newSize, EntityBad);
39 srcToTgtIdx.
resize(newSize, BadIndex);
45 const auto required =
target.
id() + 1;
46 if (tgtToSrc.
size() >= required)
49 const auto oldSize = (uint32_t)tgtToSrc.
size();
50 auto newSize = oldSize == 0 ? 16U : oldSize;
51 while (newSize < required)
61 if (source.
id() >= srcToTgt.
size())
64 return srcToTgt[source.
id()];
88 GAIA_FOR((uint32_t)srcToTgt.
size()) {
89 if (srcToTgt[i] == EntityBad)
105 const auto idx = source.
id() < srcToTgtIdx.
size() ? srcToTgtIdx[source.
id()] : BadIndex;
106 GAIA_ASSERT(idx != BadIndex && idx <
sources.
size());
111 if (idx != lastIdx) {
112 const auto movedSource =
sources[lastIdx];
114 GAIA_ASSERT(movedSource.id() < srcToTgtIdx.
size());
115 srcToTgtIdx[movedSource.id()] = idx;
127 const auto oldTarget = srcToTgt[source.
id()];
128 if (oldTarget != EntityBad) {
151 const auto oldTarget = this->
target(source);
152 if (oldTarget == EntityBad)
158 srcToTgt[source.
id()] = EntityBad;
159 srcToTgtIdx[source.
id()] = BadIndex;
160 GAIA_ASSERT(srcToTgtCnt > 0);
168 return srcToTgtCnt == 0;
Array with variable size of elements of type.
Definition darray_impl.h:27
void reserve(size_type cap)
Ensures storage for at least the requested number of elements.
Definition darray_impl.h:223
GAIA_NODISCARD size_type size() const noexcept
Returns the number of elements.
Definition darray_impl.h:504
void resize(size_type count)
Changes the number of elements.
Definition darray_impl.h:240
GAIA_NODISCARD bool empty() const noexcept
Checks whether the container has no elements.
Definition darray_impl.h:510
void pop_back() noexcept
Removes the last element.
Definition darray_impl.h:342
void push_back(const T &arg)
Appends an element.
Definition darray_impl.h:309
Identifier of an entity or component instance in the world. Packs the entity index,...
Definition id.h:296
GAIA_NODISCARD constexpr auto id() const noexcept
Entity index in the entity array.
Definition id.h:359
Storage for exclusive relation pairs that do not fragment archetypes.
Definition nonfragmenting_relation_store.h:14
void collect_source_ids(cnt::darray< EntityId > &out) const
Appends ids of all bound source entities.
Definition nonfragmenting_relation_store.h:86
GAIA_NODISCARD bool remove(Entity source, Entity target)
Removes source from the store.
Definition nonfragmenting_relation_store.h:150
GAIA_NODISCARD const cnt::darray< Entity > * sources(Entity target) const
Returns sources currently bound to target.
Definition nonfragmenting_relation_store.h:70
GAIA_NODISCARD Entity target(Entity source) const
Returns the target currently bound to source.
Definition nonfragmenting_relation_store.h:60
GAIA_NODISCARD bool set(Entity source, Entity target)
Binds source to target.
Definition nonfragmenting_relation_store.h:125
void ensure_target_capacity(Entity target)
Ensures target-indexed storage can hold target.
Definition nonfragmenting_relation_store.h:44
void remove_target_source(Entity target, Entity source)
Removes source from the source bucket for target.
Definition nonfragmenting_relation_store.h:99
GAIA_NODISCARD uint32_t source_count() const
Returns the number of active source bindings.
Definition nonfragmenting_relation_store.h:80
GAIA_NODISCARD bool empty() const
Checks whether the store has no source bindings.
Definition nonfragmenting_relation_store.h:167
void ensure_source_capacity(Entity source)
Ensures source-indexed storage can hold source.
Definition nonfragmenting_relation_store.h:28