diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-10-22 01:01:02 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-10-22 01:01:02 +0100 |
commit | 9edf8711471db08427c5441ed37b6dfe3dd7f3b4 (patch) | |
tree | 4356058e9fd85e44c4404c5db8d5d3322a64aa29 /test/test-render.cpp | |
parent | Bump to CTRE to v3.9.0-1-gacb2f4d to fix compilation with clang 19 (diff) | |
parent | Further template maths functions (diff) | |
download | ilt-9edf8711471db08427c5441ed37b6dfe3dd7f3b4.tar.bz2 ilt-9edf8711471db08427c5441ed37b6dfe3dd7f3b4.tar.xz ilt-9edf8711471db08427c5441ed37b6dfe3dd7f3b4.zip |
Merge branch 'billboard-shadows'
Diffstat (limited to 'test/test-render.cpp')
-rw-r--r-- | test/test-render.cpp | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/test/test-render.cpp b/test/test-render.cpp index ea53708..3966f28 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,8 @@ #include <boost/test/unit_test.hpp> #include <assetFactory/assetFactory.h> +#include <game/environment.h> +#include <game/gamestate.h> #include <game/geoData.h> #include <game/network/rail.h> #include <game/scenary/foliage.h> @@ -26,12 +27,8 @@ #include <ui/window.h> class TestScene : public SceneProvider { - const RailVehicleClassPtr brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>( - AssetFactory::loadXML(RESDIR "/brush47.xml")->assets.at("brush-47")); - const std::shared_ptr<Foliage> tree021f - = std::dynamic_pointer_cast<Foliage>(AssetFactory::loadXML(RESDIR "/foliage.xml")->assets.at("Tree-02-1")); + RailVehicleClassPtr brush47rvc; std::shared_ptr<RailVehicle> train1, train2; - std::shared_ptr<Plant> plant1; RailLinks rail; std::shared_ptr<GeoData> gd = std::make_shared<GeoData>(GeoData::createFlat({0, 0}, {1000000, 1000000}, 1)); std::shared_ptr<Environment> env = std::make_shared<Environment>(); @@ -42,6 +39,13 @@ class TestScene : public SceneProvider { public: TestScene() { + gameState->assets = AssetFactory::loadAll(RESDIR); + brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(gameState->assets.at("brush-47")); + std::random_device randomdev {}; + std::uniform_real_distribution<Angle> rotationDistribution {0, two_pi}; + std::uniform_int_distribution<GlobalDistance> positionOffsetDistribution {-1500, +1500}; + std::uniform_int_distribution<int> treeDistribution {1, 3}; + std::uniform_int_distribution<int> treeVariantDistribution {1, 4}; train1 = std::make_shared<RailVehicle>(brush47rvc); train1->location.setPosition({52000, 50000, 2000}); train1->bogies.front().setPosition(train1->bogies.front().position() + train1->location.position()); @@ -50,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<Plant>(tree021f, Location {{40000, 60000, 1}, {}}); + 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)))), + 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}); } @@ -60,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<const Renderable>(asset.second)) { + renderable->render(shader); + } + }); } void @@ -80,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<const Renderable>(asset.second)) { + renderable->shadows(shadowMapper); + } + }); } }; @@ -164,7 +183,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 @@ -211,7 +230,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 |