From f03e11fb38701f278f3c0f465958932044227830 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 26 Aug 2024 13:34:06 +0100 Subject: test-render loads all assets into gameState --- test/test-render.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'test/test-render.cpp') diff --git a/test/test-render.cpp b/test/test-render.cpp index b9a809e..bb5a137 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -25,10 +26,8 @@ #include class TestScene : public SceneProvider { - const RailVehicleClassPtr brush47rvc = std::dynamic_pointer_cast( - AssetFactory::loadXML(RESDIR "/brush47.xml")->assets.at("brush-47")); - const std::shared_ptr tree021f - = std::dynamic_pointer_cast(AssetFactory::loadXML(RESDIR "/foliage.xml")->assets.at("Tree-02-1")); + RailVehicleClassPtr brush47rvc; + std::shared_ptr tree021f; std::shared_ptr train1, train2; std::shared_ptr plant1; RailLinks rail; @@ -40,6 +39,9 @@ class TestScene : public SceneProvider { public: TestScene() { + gameState->assets = AssetFactory::loadAll(RESDIR); + brush47rvc = std::dynamic_pointer_cast(gameState->assets.at("brush-47")); + tree021f = std::dynamic_pointer_cast(gameState->assets.at("Tree-02-1")); train1 = std::make_shared(brush47rvc); train1->location.setPosition({52000, 50000, 2000}); train1->bogies.front().setPosition(train1->bogies.front().position() + train1->location.position()); -- cgit v1.2.3 From 10998a8302b3d7651b4afc046311961eb2dea2c8 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Oct 2024 12:48:40 +0100 Subject: Use LightDirection for calculating/passing all light dir components --- test/test-render.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/test-render.cpp') diff --git a/test/test-render.cpp b/test/test-render.cpp index 0a92689..775eb5c 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -1,4 +1,3 @@ -#include "game/environment.h" #define BOOST_TEST_MODULE test_render #include "testHelpers.h" @@ -8,6 +7,7 @@ #include #include +#include #include #include #include @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(terrain) environment(const SceneShader &, const SceneRenderer & sr) const override { sr.setAmbientLight({0.1, 0.1, 0.1}); - sr.setDirectionalLight({1, 1, 1}, south + down, *this); + sr.setDirectionalLight({1, 1, 1}, {{0, quarter_pi}}, *this); } void @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(railnet) environment(const SceneShader &, const SceneRenderer & sr) const override { sr.setAmbientLight({0.1, 0.1, 0.1}); - sr.setDirectionalLight({1, 1, 1}, south + down, *this); + sr.setDirectionalLight({1, 1, 1}, {{0, quarter_pi}}, *this); } void -- cgit v1.2.3 From f84a4771f3efe642c0946ccd94a52ede27f1d997 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 20 Oct 2024 21:55:00 +0100 Subject: Randomise for many trees, positions, rotations --- test/test-render.cpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'test/test-render.cpp') diff --git a/test/test-render.cpp b/test/test-render.cpp index 775eb5c..3966f28 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -28,9 +28,7 @@ class TestScene : public SceneProvider { RailVehicleClassPtr brush47rvc; - std::shared_ptr tree021f; std::shared_ptr train1, train2; - std::shared_ptr plant1; RailLinks rail; std::shared_ptr gd = std::make_shared(GeoData::createFlat({0, 0}, {1000000, 1000000}, 1)); std::shared_ptr env = std::make_shared(); @@ -43,7 +41,11 @@ public: { gameState->assets = AssetFactory::loadAll(RESDIR); brush47rvc = std::dynamic_pointer_cast(gameState->assets.at("brush-47")); - tree021f = std::dynamic_pointer_cast(gameState->assets.at("Tree-02-1")); + std::random_device randomdev {}; + std::uniform_real_distribution rotationDistribution {0, two_pi}; + std::uniform_int_distribution positionOffsetDistribution {-1500, +1500}; + std::uniform_int_distribution treeDistribution {1, 3}; + std::uniform_int_distribution treeVariantDistribution {1, 4}; train1 = std::make_shared(brush47rvc); train1->location.setPosition({52000, 50000, 2000}); train1->bogies.front().setPosition(train1->bogies.front().position() + train1->location.position()); @@ -52,7 +54,16 @@ public: train2->location.setPosition({52000, 30000, 2000}); train2->bogies.front().setPosition(train2->bogies.front().position() + train2->location.position()); train2->bogies.back().setPosition(train2->bogies.back().position() + train2->location.position()); - plant1 = std::make_shared(tree021f, Location {{40000, 60000, 1}, {}}); + for (auto x = 40000; x < 100000; x += 5000) { + for (auto y = 65000; y < 125000; y += 5000) { + gameState->world.create( + std::dynamic_pointer_cast(gameState->assets.at(std::format( + "Tree-{:#02}-{}", treeDistribution(randomdev), treeVariantDistribution(randomdev)))), + Location {{x + positionOffsetDistribution(randomdev), y + positionOffsetDistribution(randomdev), + 1}, + {0, rotationDistribution(randomdev), 0}}); + } + } rail.addLinksBetween({42000, 50000, 1000}, {65000, 50000, 1000}); rail.addLinksBetween({65000, 50000, 1000}, {75000, 45000, 2000}); } @@ -62,9 +73,12 @@ public: { terrain.render(shader); water.render(shader); - brush47rvc->render(shader); - tree021f->render(shader); rail.render(shader); + std::ranges::for_each(gameState->assets, [&shader](const auto & asset) { + if (const auto renderable = std::dynamic_pointer_cast(asset.second)) { + renderable->render(shader); + } + }); } void @@ -82,8 +96,11 @@ public: shadows(const ShadowMapper & shadowMapper) const override { terrain.shadows(shadowMapper); - brush47rvc->shadows(shadowMapper); - tree021f->shadows(shadowMapper); + std::ranges::for_each(gameState->assets, [&shadowMapper](const auto & asset) { + if (const auto renderable = std::dynamic_pointer_cast(asset.second)) { + renderable->shadows(shadowMapper); + } + }); } }; -- cgit v1.2.3