diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-24 18:10:30 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-24 18:11:46 +0000 |
commit | ae99a2124da32e4d2474e6dc6cf54322b688b743 (patch) | |
tree | 2f447bf5aaae5b13038e04b8d5d154d802775ec3 | |
parent | Add Renderable typed collection to GameState worldObjects (diff) | |
download | ilt-ae99a2124da32e4d2474e6dc6cf54322b688b743.tar.bz2 ilt-ae99a2124da32e4d2474e6dc6cf54322b688b743.tar.xz ilt-ae99a2124da32e4d2474e6dc6cf54322b688b743.zip |
Use is_base_of_v instead of is_convertible_v to choose OtherObjects
-rw-r--r-- | lib/collection.h | 6 | ||||
-rw-r--r-- | test/test-collection.cpp | 4 | ||||
-rw-r--r-- | ui/gameMainWindow.cpp | 6 |
3 files changed, 10 insertions, 6 deletions
diff --git a/lib/collection.h b/lib/collection.h index b786e2f..8e9cf1a 100644 --- a/lib/collection.h +++ b/lib/collection.h @@ -236,12 +236,12 @@ protected: } template<typename T> - requires((std::is_convertible_v<T *, Others *> || ...)) + requires((std::is_base_of_v<Others, T> || ...)) [[nodiscard]] consteval static bool idx() { size_t typeIdx = 0; - return ((typeIdx++ && std::is_convertible_v<Others *, T *>) || ...); + return ((typeIdx++ && std::is_base_of_v<Others, T>) || ...); } template<typename T> @@ -249,7 +249,7 @@ protected: constexpr const auto & containerFor() const { - if constexpr ((std::is_convertible_v<T *, Others *> || ...)) { + if constexpr ((std::is_base_of_v<Others, T> || ...)) { return std::get<idx<T>()>(otherObjects); } else { diff --git a/test/test-collection.cpp b/test/test-collection.cpp index a399845..90a3bd1 100644 --- a/test/test-collection.cpp +++ b/test/test-collection.cpp @@ -113,6 +113,10 @@ BOOST_AUTO_TEST_CASE(a_sub) BOOST_AUTO_TEST_CASE(filter) { + static_assert(TestCollection::idx<Sub>() == 0); + static_assert(TestCollection::idx<const Sub>() == 0); + static_assert(TestCollection::idx<Sub1>() == 0); + static_assert(TestCollection::idx<const Sub1>() == 0); create<Base>(); BOOST_CHECK_EQUAL(1, apply<Base>(&Base::yes)); BOOST_CHECK_EQUAL(0, apply<Sub>(&Base::yes)); diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 07901b3..f8c568b 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -80,7 +80,7 @@ GameMainWindow::content(const SceneShader & shader, const Frustum & frustum) con renderable->render(shader, frustum); } } - gameState->world.apply<Renderable>(&Renderable::render, shader, frustum); + gameState->world.apply<const Renderable>(&Renderable::render, shader, frustum); uiComponents.apply<WorldOverlay>(&WorldOverlay::render, shader, frustum); } @@ -93,7 +93,7 @@ GameMainWindow::environment(const SceneShader &, const SceneRenderer & r) const void GameMainWindow::lights(const SceneShader & shader) const { - gameState->world.apply<Renderable>(&Renderable::lights, shader); + gameState->world.apply<const Renderable>(&Renderable::lights, shader); } void @@ -104,5 +104,5 @@ GameMainWindow::shadows(const ShadowMapper & shadowMapper, const Frustum & frust renderable->shadows(shadowMapper, frustum); } } - gameState->world.apply<Renderable>(&Renderable::shadows, shadowMapper, frustum); + gameState->world.apply<const Renderable>(&Renderable::shadows, shadowMapper, frustum); } |