Skip to content

Commit

Permalink
Fixed: dynamic containers would not release on pop
Browse files Browse the repository at this point in the history
Fixed: Build issues with GAIA_USE_STL_CONTAINERS
Changed: Version bump to 0.7.0
  • Loading branch information
richardbiely committed Sep 17, 2023
1 parent df9b5b3 commit 5d386d1
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 87 deletions.
4 changes: 2 additions & 2 deletions include/gaia/config/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// Breaking changes and big features
#define GAIA_VERSION_MAJOR 0
// Smaller changes and features
#define GAIA_VERSION_MINOR 6
#define GAIA_VERSION_MINOR 7
// Fixes and tweaks
#define GAIA_VERSION_PATCH 2
#define GAIA_VERSION_PATCH 0
5 changes: 3 additions & 2 deletions include/gaia/containers/impl/darray_ext_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,14 @@ namespace gaia {
try_grow();

reference ref = m_pData[m_cnt++];
ref = {std::forward<Args>(args)...};
::new (&ref) T(std::forward<Args>(args)...);
return ref;
}

void pop_back() noexcept {
GAIA_ASSERT(!empty());
--m_cnt;
reference ref = m_pData[--m_cnt];
ref.~T();
}

GAIA_NODISCARD iterator erase(iterator pos) noexcept {
Expand Down
6 changes: 3 additions & 3 deletions include/gaia/containers/impl/darray_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace gaia {
template <typename T>
class darr {
public:
using iterator_category = GAIA_UTIL::random_access_iterator_tag;
using value_type = T;
using reference = T&;
using const_reference = const T&;
Expand Down Expand Up @@ -359,13 +358,14 @@ namespace gaia {
try_grow();

reference ref = m_pData[m_cnt++];
ref = {std::forward<Args>(args)...};
::new (&ref) T(std::forward<Args>(args)...);
return ref;
}

void pop_back() noexcept {
GAIA_ASSERT(!empty());
--m_cnt;
reference ref = m_pData[--m_cnt];
ref.~T();
}

GAIA_NODISCARD iterator erase(iterator pos) noexcept {
Expand Down
5 changes: 3 additions & 2 deletions include/gaia/containers/impl/sarray_ext_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,14 @@ namespace gaia {
constexpr reference emplace_back(Args&&... args) {
GAIA_ASSERT(size() < N);
reference ref = m_data[m_cnt++];
ref = {std::forward<Args>(args)...};
::new (&ref) T(std::forward<Args>(args)...);
return ref;
}

constexpr void pop_back() noexcept {
GAIA_ASSERT(!empty());
--m_cnt;
reference ref = m_data[--m_cnt];
ref.~T();
}

GAIA_NODISCARD constexpr iterator erase(iterator pos) noexcept {
Expand Down
1 change: 0 additions & 1 deletion include/gaia/containers/impl/sarray_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace gaia {
template <typename T, size_t N>
class sarr {
public:
using iterator_category = GAIA_UTIL::random_access_iterator_tag;
using value_type = T;
using reference = T&;
using const_reference = const T&;
Expand Down
10 changes: 5 additions & 5 deletions include/gaia/containers/implicitlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cinttypes>
#include <type_traits>

#include "darray.h"
#include "impl/darray_impl.h"

namespace gaia {
namespace containers {
Expand All @@ -18,11 +18,11 @@ namespace gaia {

template <typename TListItem, typename TItemHandle>
struct ImplicitList {
using internal_storage = darray<TListItem>;
using internal_storage = containers::darr<TListItem>;
using iterator = typename internal_storage::iterator;
using const_iterator = typename internal_storage::const_iterator;

using iterator_category = typename internal_storage::iterator_category;
using iterator_category = typename internal_storage::iterator::iterator_category;
using value_type = TListItem;
using reference = TListItem&;
using const_reference = const TListItem&;
Expand All @@ -33,7 +33,7 @@ namespace gaia {

static_assert(std::is_base_of<ImplicitListItem, TListItem>::value);
//! Implicit list items
darray<TListItem> m_items;
darr<TListItem> m_items;
//! Index of the next item to recycle
size_type m_nextFreeIdx = (size_type)-1;
//! Number of items to recycle
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace gaia {
const auto itemCnt = (size_type)m_items.size();
GAIA_ASSERT(itemCnt < TItemHandle::IdMask && "Trying to allocate too many items!");

m_items.emplace_back(itemCnt, 0U);
m_items.push_back({itemCnt, 0U});
return {itemCnt, 0U};
}

Expand Down
10 changes: 0 additions & 10 deletions include/gaia/containers/sringbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ namespace gaia {
++m_size;
}

template <typename... Args>
reference emplace_back(Args&&... args) {
GAIA_ASSERT(m_size < N);
const auto head = (m_tail + m_size) % N;
reference ref = m_data[head];
ref = {std::forward<Args>(args)...};
++m_size;
return ref;
}

void pop_front(T& out) {
GAIA_ASSERT(!empty());
out = m_data[m_tail];
Expand Down
8 changes: 4 additions & 4 deletions include/gaia/ecs/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,15 @@ namespace gaia {

if (hasFilters) {
auto execWithFiltersON = [&](const auto& chunks) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
if (!pChunk->HasEntities())
return false;
return CheckFilters(*pChunk, queryInfo);
});
};

auto execWithFiltersON_EnabledDisabled = [&](const auto& chunks, bool enabledOnly) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
const auto hasEntities = enabledOnly
? pChunk->GetEntityCount() - pChunk->GetDisabledEntityMask().count() > 0
: pChunk->GetDisabledEntityMask().count() > 0;
Expand All @@ -645,13 +645,13 @@ namespace gaia {
}
} else {
auto execWithFiltersOFF = [&](const auto& chunks) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
return pChunk->HasEntities();
});
};

auto execWithFiltersOFF_EnabledDisabled = [&](const auto& chunks, bool enabledOnly) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
return enabledOnly ? pChunk->GetEntityCount() - pChunk->GetDisabledEntityMask().count() > 0
: pChunk->GetDisabledEntityMask().count() > 0;
});
Expand Down
4 changes: 2 additions & 2 deletions include/gaia/ecs/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,9 @@ namespace gaia {
void DiagEntities() const {
ValidateEntityList();

GAIA_LOG_N("Deleted entities: %u", m_entities.get_free_items());
GAIA_LOG_N("Deleted entities: %u", (uint32_t)m_entities.get_free_items());
if (m_entities.get_free_items() != 0U) {
GAIA_LOG_N(" --> %u", m_entities.get_next_free_item());
GAIA_LOG_N(" --> %u", (uint32_t)m_entities.get_next_free_item());

uint32_t iters = 0;
auto fe = m_entities[m_entities.get_next_free_item()].idx;
Expand Down
51 changes: 21 additions & 30 deletions single_include/gaia.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,9 @@ inline void DoNotOptimize(T const& value) {
// Breaking changes and big features
#define GAIA_VERSION_MAJOR 0
// Smaller changes and features
#define GAIA_VERSION_MINOR 6
#define GAIA_VERSION_MINOR 7
// Fixes and tweaks
#define GAIA_VERSION_PATCH 2
#define GAIA_VERSION_PATCH 0

//------------------------------------------------------------------------------
// General settings.
Expand Down Expand Up @@ -1172,7 +1172,6 @@ namespace gaia {
template <typename T, size_t N>
class sarr {
public:
using iterator_category = GAIA_UTIL::random_access_iterator_tag;
using value_type = T;
using reference = T&;
using const_reference = const T&;
Expand Down Expand Up @@ -4754,7 +4753,6 @@ namespace gaia {
template <typename T>
class darr {
public:
using iterator_category = GAIA_UTIL::random_access_iterator_tag;
using value_type = T;
using reference = T&;
using const_reference = const T&;
Expand Down Expand Up @@ -5097,13 +5095,14 @@ namespace gaia {
try_grow();

reference ref = m_pData[m_cnt++];
ref = {std::forward<Args>(args)...};
::new (&ref) T(std::forward<Args>(args)...);
return ref;
}

void pop_back() noexcept {
GAIA_ASSERT(!empty());
--m_cnt;
reference ref = m_pData[--m_cnt];
ref.~T();
}

GAIA_NODISCARD iterator erase(iterator pos) noexcept {
Expand Down Expand Up @@ -8434,13 +8433,14 @@ namespace gaia {
constexpr reference emplace_back(Args&&... args) {
GAIA_ASSERT(size() < N);
reference ref = m_data[m_cnt++];
ref = {std::forward<Args>(args)...};
::new (&ref) T(std::forward<Args>(args)...);
return ref;
}

constexpr void pop_back() noexcept {
GAIA_ASSERT(!empty());
--m_cnt;
reference ref = m_data[--m_cnt];
ref.~T();
}

GAIA_NODISCARD constexpr iterator erase(iterator pos) noexcept {
Expand Down Expand Up @@ -8689,16 +8689,6 @@ namespace gaia {
++m_size;
}

template <typename... Args>
reference emplace_back(Args&&... args) {
GAIA_ASSERT(m_size < N);
const auto head = (m_tail + m_size) % N;
reference ref = m_data[head];
ref = {std::forward<Args>(args)...};
++m_size;
return ref;
}

void pop_front(T& out) {
GAIA_ASSERT(!empty());
out = m_data[m_tail];
Expand Down Expand Up @@ -8941,11 +8931,11 @@ namespace gaia {

template <typename TListItem, typename TItemHandle>
struct ImplicitList {
using internal_storage = darray<TListItem>;
using internal_storage = containers::darr<TListItem>;
using iterator = typename internal_storage::iterator;
using const_iterator = typename internal_storage::const_iterator;

using iterator_category = typename internal_storage::iterator_category;
using iterator_category = typename internal_storage::iterator::iterator_category;
using value_type = TListItem;
using reference = TListItem&;
using const_reference = const TListItem&;
Expand All @@ -8956,7 +8946,7 @@ namespace gaia {

static_assert(std::is_base_of<ImplicitListItem, TListItem>::value);
//! Implicit list items
darray<TListItem> m_items;
darr<TListItem> m_items;
//! Index of the next item to recycle
size_type m_nextFreeIdx = (size_type)-1;
//! Number of items to recycle
Expand Down Expand Up @@ -9031,7 +9021,7 @@ namespace gaia {
const auto itemCnt = (size_type)m_items.size();
GAIA_ASSERT(itemCnt < TItemHandle::IdMask && "Trying to allocate too many items!");

m_items.emplace_back(itemCnt, 0U);
m_items.push_back({itemCnt, 0U});
return {itemCnt, 0U};
}

Expand Down Expand Up @@ -13353,13 +13343,14 @@ namespace gaia {
try_grow();

reference ref = m_pData[m_cnt++];
ref = {std::forward<Args>(args)...};
::new (&ref) T(std::forward<Args>(args)...);
return ref;
}

void pop_back() noexcept {
GAIA_ASSERT(!empty());
--m_cnt;
reference ref = m_pData[--m_cnt];
ref.~T();
}

GAIA_NODISCARD iterator erase(iterator pos) noexcept {
Expand Down Expand Up @@ -15250,15 +15241,15 @@ namespace gaia {

if (hasFilters) {
auto execWithFiltersON = [&](const auto& chunks) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
if (!pChunk->HasEntities())
return false;
return CheckFilters(*pChunk, queryInfo);
});
};

auto execWithFiltersON_EnabledDisabled = [&](const auto& chunks, bool enabledOnly) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
const auto hasEntities = enabledOnly
? pChunk->GetEntityCount() - pChunk->GetDisabledEntityMask().count() > 0
: pChunk->GetDisabledEntityMask().count() > 0;
Expand All @@ -15283,13 +15274,13 @@ namespace gaia {
}
} else {
auto execWithFiltersOFF = [&](const auto& chunks) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
return pChunk->HasEntities();
});
};

auto execWithFiltersOFF_EnabledDisabled = [&](const auto& chunks, bool enabledOnly) {
return GAIA_UTIL::has_if(chunks, [&](archetype::Chunk* pChunk) {
return utils::has_if(chunks, [&](archetype::Chunk* pChunk) {
return enabledOnly ? pChunk->GetEntityCount() - pChunk->GetDisabledEntityMask().count() > 0
: pChunk->GetDisabledEntityMask().count() > 0;
});
Expand Down Expand Up @@ -16610,9 +16601,9 @@ namespace gaia {
void DiagEntities() const {
ValidateEntityList();

GAIA_LOG_N("Deleted entities: %u", m_entities.get_free_items());
GAIA_LOG_N("Deleted entities: %u", (uint32_t)m_entities.get_free_items());
if (m_entities.get_free_items() != 0U) {
GAIA_LOG_N(" --> %u", m_entities.get_next_free_item());
GAIA_LOG_N(" --> %u", (uint32_t)m_entities.get_next_free_item());

uint32_t iters = 0;
auto fe = m_entities[m_entities.get_next_free_item()].idx;
Expand Down
4 changes: 2 additions & 2 deletions src/examples/example_roguelike/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ class CollisionSystem final: public ecs::System {
for (; pp[ii] != pp_end; pp[ii] += dd[ii], naa += dd[ii]) {
// Stop on wall collisions
if (g_world.map[pp[1]][pp[0]] == TILE_WALL) {
m_colliding.emplace_back(e, ecs::EntityNull, Position{pp[0], pp[1]}, v);
m_colliding.push_back({e, ecs::EntityNull, Position{pp[0], pp[1]}, v});
goto onCollision;
}

Expand Down Expand Up @@ -598,7 +598,7 @@ class CollisionSystem final: public ecs::System {
}
}

m_colliding.emplace_back(e, e2, Position{pp[0], pp[1]}, v);
m_colliding.push_back({e, e2, Position{pp[0], pp[1]}, v});
hadCollision = true;
}
if (hadCollision)
Expand Down
Loading

0 comments on commit 5d386d1

Please sign in to comment.