Skip to content

Commit

Permalink
view: setup placeholders on view packs - close #1224
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Feb 21, 2025
1 parent 7a7695e commit 6b95c61
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/entt/entity/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ template<typename Result, typename View, typename Other, std::size_t... GLhs, st
Result elem{};
// friend-initialization, avoid multiple calls to refresh
elem.pools = {view.template storage<GLhs>()..., other.template storage<GRhs>()...};
elem.filter = {view.template storage<sizeof...(GLhs) + ELhs>()..., other.template storage<sizeof...(GRhs) + ERhs>()...};
auto filter_or_placeholder = [placeholder = elem.placeholder](auto *value) { return (value == nullptr) ? placeholder : value; };
elem.filter = {filter_or_placeholder(view.template storage<sizeof...(GLhs) + ELhs>())..., filter_or_placeholder(other.template storage<sizeof...(GRhs) + ERhs>())...};
elem.refresh();
return elem;
}
Expand Down Expand Up @@ -255,7 +256,7 @@ class basic_common_view {
protected:
/*! @cond TURN_OFF_DOXYGEN */
basic_common_view() noexcept {
for(size_type pos{}; pos < Exclude; ++pos) {
for(size_type pos{}, last = filter.size(); pos < last; ++pos) {
filter[pos] = placeholder;
}
}
Expand Down
28 changes: 27 additions & 1 deletion test/entt/entity/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ TEST(MultiStorageView, Storage) {

TEST(MultiStorageView, SwapStorage) {
std::tuple<entt::storage<int>, entt::storage<char>, entt::storage<int>, entt::storage<char>> storage{};
entt::basic_view<entt::get_t<entt::storage<int>>, entt::exclude_t<const entt::storage<char>>> view;
entt::basic_view<entt::get_t<entt::storage<int>>, entt::exclude_t<const entt::storage<char>>> view{};
const entt::entity entity{0};

ASSERT_FALSE(view);
Expand Down Expand Up @@ -1583,3 +1583,29 @@ TEST(View, Pipe) {
ASSERT_NE(pack32.storage<const int>(), nullptr);
ASSERT_NE(pack32.storage<float>(), nullptr);
}

TEST(View, PipeWithPlaceholder) {
entt::storage<void> storage{};
const entt::entity entity{0};

const entt::basic_view view{storage};
entt::basic_view<entt::get_t<entt::storage<void>>, entt::exclude_t<entt::storage<int>>> other{};

other.storage(storage);

ASSERT_FALSE(view.contains(entity));
ASSERT_FALSE(other.contains(entity));

auto pack = view | other;

ASSERT_FALSE(pack.contains(entity));

storage.emplace(entity);

ASSERT_TRUE(view.contains(entity));
ASSERT_TRUE(other.contains(entity));

pack = view | other;

ASSERT_TRUE(pack.contains(entity));
}

0 comments on commit 6b95c61

Please sign in to comment.