summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test-glContextBhvr.cpp3
-rw-r--r--test/test-network.cpp47
-rw-r--r--test/test-render.cpp51
3 files changed, 85 insertions, 16 deletions
diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp
index 26b45d9..ec5cc21 100644
--- a/test/test-glContextBhvr.cpp
+++ b/test/test-glContextBhvr.cpp
@@ -1,10 +1,9 @@
#define BOOST_TEST_MODULE test_glcontextbehaviour
-
-#include "testHelpers.h"
#include <boost/test/unit_test.hpp>
#include <gfx/gl/sceneRenderer.h>
#include <lib/glArrays.h>
+#include <optional>
#include <ui/applicationBase.h>
#include <ui/window.h>
diff --git a/test/test-network.cpp b/test/test-network.cpp
index 0274b00..174e2a5 100644
--- a/test/test-network.cpp
+++ b/test/test-network.cpp
@@ -23,25 +23,39 @@
BOOST_GLOBAL_FIXTURE(ApplicationBase);
BOOST_GLOBAL_FIXTURE(TestMainWindow);
-struct TestLink : public LinkStraight {
- TestLink(const Node::Ptr & a, const Node::Ptr & b) : TestLink {a, b, (a->pos - b->pos)} { }
+struct TestLinkS;
- TestLink(Node::Ptr a, Node::Ptr b, RelativePosition2D l) :
+struct TestLink : public virtual Link {
+ using StraightLink = TestLinkS;
+ using CurveLink = TestLinkS;
+};
+
+struct TestLinkS : public TestLink, public LinkStraight {
+ TestLinkS(NetworkLinkHolder<TestLinkS> & network, const Node::Ptr & a, const Node::Ptr & b) :
+ TestLinkS {network, a, b, (a->pos - b->pos)}
+ {
+ }
+
+ TestLinkS(NetworkLinkHolder<TestLinkS> &, Node::Ptr a, Node::Ptr b, RelativePosition2D l) :
Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)}
{
}
- TestLink(Node::Ptr a, Node::Ptr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { }
+ struct Vertex { };
- using StraightLink = TestLink;
- using CurveLink = TestLink;
+ TestLinkS(NetworkLinkHolder<TestLinkS> &, Node::Ptr a, Node::Ptr b, float l) :
+ Link {{std::move(a), 0}, {std::move(b), pi}, l}
+ {
+ }
};
constexpr GlobalPosition3D p000 {0, 0, 0}, p100 {10000, 0, 0}, p200 {20000, 0, 0}, p300 {30000, 0, 0};
constexpr GlobalPosition3D p110 {10000, 10000, 0};
-struct TestNetwork : public NetworkOf<TestLink> {
- TestNetwork() : NetworkOf<TestLink> {RESDIR "rails.jpg"}
+template<> NetworkLinkHolder<TestLinkS>::NetworkLinkHolder() = default;
+
+struct TestNetwork : public NetworkOf<TestLink, TestLinkS> {
+ TestNetwork() : NetworkOf<TestLink, TestLinkS> {RESDIR "rails.jpg"}
{
// 0 1 2
// p000 <-> p100 <-> p200 <-> p300
@@ -49,12 +63,17 @@ struct TestNetwork : public NetworkOf<TestLink> {
// \ 5 /
// 3 | 4
// \-> p110 <-/
- addLink<TestLink>(p000, p100, 1.F);
- addLink<TestLink>(p100, p200, 1.F);
- addLink<TestLink>(p200, p300, 1.F);
- addLink<TestLink>(p000, p110, 2.F);
- addLink<TestLink>(p200, p110, 2.F);
- addLink<TestLink>(p100, p110, 1.F);
+ addLink<TestLinkS>(p000, p100, 1.F);
+ addLink<TestLinkS>(p100, p200, 1.F);
+ addLink<TestLinkS>(p200, p300, 1.F);
+ addLink<TestLinkS>(p000, p110, 2.F);
+ addLink<TestLinkS>(p200, p110, 2.F);
+ addLink<TestLinkS>(p100, p110, 1.F);
+ }
+
+ void
+ render(const SceneShader &) const override
+ {
}
};
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 41731dd..6c20a23 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -8,6 +8,7 @@
#include <assetFactory/assetFactory.h>
#include <game/geoData.h>
+#include <game/network/rail.h>
#include <game/terrain.h>
#include <game/vehicles/railVehicle.h>
#include <game/vehicles/railVehicleClass.h>
@@ -24,6 +25,7 @@ class TestScene : public SceneProvider {
const RailVehicleClassPtr brush47rvc = std::dynamic_pointer_cast<RailVehicleClass>(
AssetFactory::loadXML(RESDIR "/brush47.xml")->assets.at("brush-47"));
std::shared_ptr<RailVehicle> train1, train2;
+ RailLinks rail;
Terrain terrain {[]() {
auto gd = std::make_shared<GeoData>(GeoData::createFlat({0, 0}, {1000000, 1000000}, 1));
@@ -41,6 +43,8 @@ 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());
+ rail.addLinksBetween({42000, 50000, 1000}, {65000, 50000, 1000});
+ rail.addLinksBetween({65000, 50000, 1000}, {75000, 45000, 2000});
}
void
@@ -48,6 +52,7 @@ public:
{
terrain.render(shader);
brush47rvc->render(shader);
+ rail.render(shader);
}
void
@@ -158,4 +163,50 @@ BOOST_AUTO_TEST_CASE(terrain)
Texture::save(outImage, "/tmp/terrain.tga");
}
+BOOST_AUTO_TEST_CASE(railnet)
+{
+ SceneRenderer ss {size, output};
+ ss.camera.setView({0, 0, 10000}, glm::normalize(glm::vec3 {1, 1, -0.5F}));
+
+ class TestRail : public SceneProvider {
+ RailLinks net;
+
+ public:
+ TestRail()
+ {
+ net.addLinksBetween({20000, 10000, 0}, {100000, 100000, 0});
+ net.addLinksBetween({20000, 10000, 0}, {10000, 10000, 0});
+ net.addLinksBetween({10000, 20000, 0}, {100000, 120000, 0});
+ net.addLinksBetween({10000, 20000, 0}, {10000, 10000, 0});
+ net.addLinksBetween({100000, 100000, 0}, {100000, 120000, 0});
+ }
+
+ void
+ content(const SceneShader & shader) const override
+ {
+ net.render(shader);
+ }
+
+ void
+ environment(const SceneShader &, const SceneRenderer & sr) const override
+ {
+ sr.setAmbientLight({0.1, 0.1, 0.1});
+ sr.setDirectionalLight({1, 1, 1}, south + down, *this);
+ }
+
+ void
+ lights(const SceneShader &) const override
+ {
+ }
+
+ void
+ shadows(const ShadowMapper &) const override
+ {
+ }
+ };
+
+ ss.render(TestRail {});
+ Texture::save(outImage, "/tmp/railnet.tga");
+}
+
BOOST_AUTO_TEST_SUITE_END();