diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-22 11:50:31 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-03-22 11:50:31 +0000 |
commit | 9fd25e8b10b1291525a18c8b3e34256ca6151dd6 (patch) | |
tree | c483b55010f310ed60cb7381130feedd2b3980a9 /test | |
parent | Support resizing the main window (diff) | |
download | ilt-9fd25e8b10b1291525a18c8b3e34256ca6151dd6.tar.bz2 ilt-9fd25e8b10b1291525a18c8b3e34256ca6151dd6.tar.xz ilt-9fd25e8b10b1291525a18c8b3e34256ca6151dd6.zip |
Add ManyPtr which tracks specified subclasses
This removes the need to repeated dynamic_cast the pointer.
Provides interface which enforces the fastest option for the required
types.
Diffstat (limited to 'test')
-rw-r--r-- | test/test-assetFactory.cpp | 12 | ||||
-rw-r--r-- | test/test-render.cpp | 13 |
2 files changed, 13 insertions, 12 deletions
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 9bade82..03319da 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -84,7 +84,7 @@ BOOST_AUTO_TEST_CASE(surfaces, *boost::unit_test::timeout(5)) BOOST_CHECK_EQUAL(4, mf->assets.size()); auto gravelAsset = mf->assets.at("terrain.surface.gravel"); BOOST_REQUIRE(gravelAsset); - auto gravel = std::dynamic_pointer_cast<Surface>(gravelAsset); + auto gravel = gravelAsset.dynamicCast<Surface>(); BOOST_REQUIRE(gravel); BOOST_REQUIRE_EQUAL(gravel->name, "Gravel"); BOOST_REQUIRE_EQUAL(gravel->colorBias, RGB {.9F}); @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) BOOST_CHECK_EQUAL(1, mf->assets.size()); auto brush47 = mf->assets.at("brush-47"); BOOST_REQUIRE(brush47); - auto brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(brush47); + auto brush47rvc = brush47.dynamicCast<RailVehicleClass>(); BOOST_REQUIRE(brush47rvc); BOOST_REQUIRE(brush47rvc->bodyMesh); BOOST_REQUIRE(brush47rvc->bogies.front()); @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) gameState.assets = mf->assets; auto tree_01_1 = mf->assets.at("Tree-01-1"); BOOST_REQUIRE(tree_01_1); - auto tree_01_1_f = std::dynamic_pointer_cast<Foliage>(tree_01_1); + auto tree_01_1_f = tree_01_1.dynamicCast<Foliage>(); BOOST_REQUIRE(tree_01_1_f); auto plant1 = std::make_shared<Plant>(tree_01_1_f, Location {{-2000, 2000, 0}, {0, 0, 0}}); @@ -151,9 +151,9 @@ BOOST_AUTO_TEST_CASE(lights, *boost::unit_test::timeout(5)) BOOST_REQUIRE(rlight); auto oldlamp = mf->assets.at("old-lamp"); BOOST_REQUIRE(oldlamp); - auto rlight_f = std::dynamic_pointer_cast<Illuminator>(rlight); + auto rlight_f = rlight.dynamicCast<Illuminator>(); BOOST_REQUIRE(rlight_f); - auto oldlamp_f = std::dynamic_pointer_cast<Illuminator>(oldlamp); + auto oldlamp_f = oldlamp.dynamicCast<Illuminator>(); BOOST_REQUIRE(oldlamp_f); auto light1 = std::make_shared<Light>(oldlamp_f, Location {{0, 0, 0}, {0, 0, 0}}); @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(lights, *boost::unit_test::timeout(5)) objects.objects.push_back(oldlamp_f); // yes I'm hacking some floor to light up as though its a bush - auto floorf = std::dynamic_pointer_cast<Foliage>(mf->assets.at("floor")); + auto floorf = mf->assets.at("floor").dynamicCast<Foliage>(); auto floor = std::make_shared<Plant>(floorf, Location {}); objects.objects.push_back(floorf); diff --git a/test/test-render.cpp b/test/test-render.cpp index 8390d25..a6e28bc 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -41,7 +41,7 @@ public: terrain->point(GeoData::VertexHandle {517}).z = 100'000; terrain->generateMeshes(); gameState->assets = AssetFactory::loadAll(RESDIR); - brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(gameState->assets.at("brush-47")); + brush47rvc = gameState->assets.at("brush-47").dynamicCast<RailVehicleClass>(); std::random_device randomdev {}; std::uniform_real_distribution<Angle> rotationDistribution {0, two_pi}; std::uniform_int_distribution<GlobalDistance> positionOffsetDistribution {-1500, +1500}; @@ -57,9 +57,10 @@ public: train2->bogies.back().setPosition(train2->bogies.back().position() + train2->location.position()); for (auto x = 40000; x < 100000; x += 5000) { for (auto y = 65000; y < 125000; y += 5000) { - gameState->world.create<Plant>( - std::dynamic_pointer_cast<Foliage>(gameState->assets.at(std::format( - "Tree-{:#02}-{}", treeDistribution(randomdev), treeVariantDistribution(randomdev)))), + gameState->world.create<Plant>(gameState->assets + .at(std::format("Tree-{:#02}-{}", treeDistribution(randomdev), + treeVariantDistribution(randomdev))) + .dynamicCast<Foliage>(), Location {{x + positionOffsetDistribution(randomdev), y + positionOffsetDistribution(randomdev), 1}, {0, rotationDistribution(randomdev), 0}}); @@ -76,7 +77,7 @@ public: water.render(shader, frustum); rail.render(shader, frustum); std::ranges::for_each(gameState->assets, [&shader, &frustum](const auto & asset) { - if (const auto renderable = std::dynamic_pointer_cast<const Renderable>(asset.second)) { + if (const auto renderable = asset.second.template getAs<const Renderable>()) { renderable->render(shader, frustum); } }); @@ -98,7 +99,7 @@ public: { terrain->shadows(shadowMapper, frustum); std::ranges::for_each(gameState->assets, [&shadowMapper, &frustum](const auto & asset) { - if (const auto renderable = std::dynamic_pointer_cast<const Renderable>(asset.second)) { + if (const auto renderable = asset.second.template getAs<const Renderable>()) { renderable->shadows(shadowMapper, frustum); } }); |