diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Jamfile.jam | 1 | ||||
-rw-r--r-- | test/test-assetFactory.cpp | 5 | ||||
-rw-r--r-- | test/test-environment.cpp | 63 | ||||
-rw-r--r-- | test/test-geoData.cpp | 4 | ||||
-rw-r--r-- | test/test-maths.cpp | 10 | ||||
-rw-r--r-- | test/test-render.cpp | 51 | ||||
-rw-r--r-- | test/testRenderOutput.h | 2 |
7 files changed, 116 insertions, 20 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 0b830a8..3ab4c4c 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -63,6 +63,7 @@ run test-instancing.cpp : -- : test-glContainer : <library>test ; run perf-instancing.cpp : \< : test-instancing : <library>benchmark <library>test ; run test-glContainer.cpp : : : <library>test ; run test-pack.cpp : : : <library>test ; +run test-environment.cpp : : : <library>test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; explicit perf-assetFactory ; diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 1c2c417..6036721 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -54,7 +54,7 @@ public: environment(const SceneShader &, const SceneRenderer & sceneRenderer) const override { sceneRenderer.setAmbientLight({.4, .4, .4}); - sceneRenderer.setDirectionalLight({.6, .6, .6}, east + south + south + down, *this); + sceneRenderer.setDirectionalLight({.6, .6, .6}, {{0.9, 0.5}}, *this); } void @@ -97,6 +97,7 @@ BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml"); BOOST_REQUIRE(mf); + gameState.assets = mf->assets; BOOST_REQUIRE_GE(mf->shapes.size(), 6); BOOST_CHECK(mf->shapes.at("plane")); BOOST_CHECK(mf->shapes.at("cylinder")); @@ -126,6 +127,7 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/foliage.xml"); BOOST_REQUIRE(mf); + 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); @@ -144,6 +146,7 @@ BOOST_AUTO_TEST_CASE(lights, *boost::unit_test::timeout(5)) { auto mf = AssetFactory::loadXML(RESDIR "/lights.xml"); BOOST_REQUIRE(mf); + gameState.assets = mf->assets; auto rlight = mf->assets.at("r-light"); BOOST_REQUIRE(rlight); auto oldlamp = mf->assets.at("old-lamp"); diff --git a/test/test-environment.cpp b/test/test-environment.cpp new file mode 100644 index 0000000..8bd64be --- /dev/null +++ b/test/test-environment.cpp @@ -0,0 +1,63 @@ +#define BOOST_TEST_MODULE environment +#include "testHelpers.h" +#include <boost/test/data/test_case.hpp> +#include <boost/test/unit_test.hpp> +#include <cmath> +#include <stream_support.h> + +#include <chronology.h> +#include <config/types.h> +#include <game/environment.h> +#include <gfx/lightDirection.h> +#include <maths.h> + +using sunPosTestData = std::tuple<Direction2D, time_t, Direction2D>; +using sunDirTestData = std::tuple<Direction2D, Direction3D, float, float>; +constexpr Direction2D Doncaster = {-1.1, 53.5}; +constexpr Direction2D NewYork = {74.0, 40.7}; +constexpr Direction2D Syndey = {-151.2, -33.9}; +constexpr Direction2D EqGM = {}; + +BOOST_DATA_TEST_CASE(sun_position, + boost::unit_test::data::make<sunPosTestData>({ + {EqGM, "2024-01-02T00:00:00"_time_t, {181.52F, -66.86F}}, + {EqGM, "2024-01-02T06:00:00"_time_t, {113.12F, -0.85F}}, + {EqGM, "2024-01-02T06:30:00"_time_t, {113.12F, 6.05F}}, + {EqGM, "2024-01-02T12:00:00"_time_t, {177.82F, 66.97F}}, + {EqGM, "2024-01-02T18:00:00"_time_t, {246.99F, 0.90F}}, + {EqGM, "2024-01-03T00:00:00"_time_t, {181.52F, -67.04F}}, + {EqGM, "2024-06-29T12:00:00"_time_t, {2.1F, 66.80F}}, + {Doncaster, "2024-06-29T12:00:00"_time_t, {176.34F, 59.64F}}, + {NewYork, "2024-06-29T12:00:00"_time_t, {278.04F, 27.34F}}, + {Syndey, "2024-06-29T12:00:00"_time_t, {106.13F, -63.29F}}, + }), + position, timeOfYear, expSunPos) +{ + const auto sunPos = Environment::getSunPos(position * degreesToRads, timeOfYear) / degreesToRads; + BOOST_CHECK_CLOSE(sunPos.x, expSunPos.x, 1.F); + BOOST_CHECK_CLOSE(sunPos.y, expSunPos.y, 1.F); +} + +BOOST_DATA_TEST_CASE(sun_direction, + boost::unit_test::data::make<sunDirTestData>({ + {{0.F, 0.F}, south, 0.314F, 0.0087F}, + {{90.F, 0.F}, west, 0.314F, 0.0087F}, + {{-90.F, 0.F}, east, 0.314F, 0.0087F}, + // From above + // EqGM midnight, sun below horizon, shining upwards + {{181.52F, -66.86F}, {-0.01F, 0.39F, 0.919F}, 0, 0.F}, + // EqGM just before sunrise, mostly west, north a bit, up a bit + {{113.12F, -0.85F}, {-0.92F, 0.39F, 0.015F}, 0.299F, 0.F}, + // EqGM just after sunrise, mostly west, north a bit, down a bit + {{113.12F, 6.05F}, {-0.92F, 0.39F, -0.015F}, 0.42F, 0.114F}, + // Doncaster noon, roughly from south to north, high in the sky, downward + {{176.34F, 59.64F}, {-0.03F, 0.5F, -0.86F}, 1, 1}, + }), + position, direction, amb, dir) +{ + const LightDirection ld {position * degreesToRads}; + BOOST_CHECK_CLOSE_VEC(ld.vector(), direction); + BOOST_CHECK_CLOSE(glm::length(ld.vector()), 1.F, 1); + BOOST_CHECK_CLOSE(ld.ambient(), amb, 5); + BOOST_CHECK_CLOSE(ld.directional(), dir, 5); +} diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 11d634d..35d6bae 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -168,7 +168,7 @@ BOOST_DATA_TEST_CASE(walkTerrainSetsFromFace, from, to, visits) { GeoData::PointFace pf {from}; - BOOST_CHECK_NO_THROW(fixedTerrtain.walk(pf, to, [](auto) {})); + BOOST_CHECK_NO_THROW(fixedTerrtain.walk(pf, to, [](auto) { })); BOOST_CHECK_EQUAL(pf.face(&fixedTerrtain).idx(), visits.front()); } @@ -253,7 +253,7 @@ BOOST_DATA_TEST_CASE(deform, loadFixtureJson<DeformTerrainData>("geoData/deform/ 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}, {{quarter_pi, -3 * half_pi}}, *this); } void diff --git a/test/test-maths.cpp b/test/test-maths.cpp index ccfb113..f7f34b3 100644 --- a/test/test-maths.cpp +++ b/test/test-maths.cpp @@ -107,9 +107,9 @@ const auto angs = boost::unit_test::data::make({pi, half_pi, two_pi, quarter_pi, * boost::unit_test::data::make(0); const auto random_angs = boost::unit_test::data::random(-two_pi, two_pi) ^ boost::unit_test::data::xrange(1000); const auto rots = boost::unit_test::data::make<std::tuple<glm::vec3, glm::mat4 (*)(float), std::string_view>>({ - {down, rotate_yaw, "yaw"}, - {east, rotate_pitch, "pitch"}, - {north, rotate_roll, "roll"}, + {down, rotate_yaw<4>, "yaw"}, + {east, rotate_pitch<4>, "pitch"}, + {north, rotate_roll<4>, "roll"}, }); BOOST_DATA_TEST_CASE(test_rotations, (angs + random_angs) * rots, angle, ai, axis, ilt_func, name) @@ -247,13 +247,13 @@ BOOST_DATA_TEST_CASE(curve1, BOOST_CHECK_EQUAL(l.radius, 1.F); { const auto p = l.positionAt(0, 0); - const auto angForReversed = normalize(vector_yaw(-e1) * 2 - angFor); + const auto angForReversed = normalize(vector_yaw(difference({}, e1)) * 2 - angFor); BOOST_CHECK_CLOSE_VECI(p.pos, e1); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angForReversed, 0)); } { const auto p = l.positionAt(0, 1); - const auto angBackReversed = normalize(vector_yaw(e1) * 2 - angBack); + const auto angBackReversed = normalize(vector_yaw(difference(e1, {})) * 2 - angBack); BOOST_CHECK_CLOSE_VECI(p.pos, GlobalPosition3D {}); BOOST_CHECK_CLOSE_VEC(p.rot, glm::vec3(0, angBackReversed, 0)); } diff --git a/test/test-render.cpp b/test/test-render.cpp index b9a809e..3966f28 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -7,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> @@ -25,14 +27,11 @@ #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>(); Terrain terrain {gd}; Water water {gd}; @@ -40,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()); @@ -48,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}); } @@ -58,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 @@ -69,11 +87,20 @@ public: } void + environment(const SceneShader &, const SceneRenderer & r) const override + { + env->render(r, *this); + } + + void 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); + } + }); } }; @@ -156,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 @@ -203,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 diff --git a/test/testRenderOutput.h b/test/testRenderOutput.h index 056d029..79908b1 100644 --- a/test/testRenderOutput.h +++ b/test/testRenderOutput.h @@ -1,6 +1,7 @@ #pragma once #include "config/types.h" +#include "game/gamestate.h" #include "glArrays.h" #include <glm/vec2.hpp> #include <special_members.h> @@ -17,6 +18,7 @@ public: glFrameBuffer output; glRenderBuffer depth; glTexture outImage; + GameState gameState; }; template<TextureAbsCoord Size> class TestRenderOutputSize : public TestRenderOutput { |