From 73a8abf0762a113a04b05e6f1364aa0b961fa7f6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 15:48:53 +0000 Subject: Remove old hard coded asset factory test, run entirely from XML load and render a RailVehicle instance --- test/test-assetFactory.cpp | 99 ++++------------------------------------------ 1 file changed, 7 insertions(+), 92 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 9930714..ae5a88a 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -6,10 +6,11 @@ #include #include "assetFactory/assetFactory.h" -#include "assetFactory/factoryMesh.h" #include "assetFactory/object.h" +#include "game/vehicles/railVehicle.h" #include "game/vehicles/railVehicleClass.h" #include "gfx/gl/sceneRenderer.h" +#include "gfx/renderable.h" #include "lib/collection.hpp" #include "lib/location.hpp" #include "lib/stream_support.hpp" @@ -34,7 +35,7 @@ public: content(const SceneShader & shader) const override { shader.basic.use(Location {{0, 0, 0}, {0, 0, 0}}); - meshes.apply(&Mesh::Draw); + objects.apply(&Renderable::render, shader); } void lights(const SceneShader & shader) const override @@ -51,7 +52,7 @@ public: shadows(const ShadowMapper & mapper) const override { mapper.dynamicPoint.use(Location {{0, 0, 0}, {0, 0, 0}}); - meshes.apply(&Mesh::Draw); + objects.apply(&Renderable::shadows, mapper); } void render(float dist = 10.f) @@ -59,98 +60,13 @@ public: sceneRenderer.camera.setView({dist, dist, dist}, south + west + down); sceneRenderer.render(*this); } - Collection meshes; + Collection objects; private: SceneRenderer sceneRenderer; }; BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); -BOOST_AUTO_TEST_CASE(brush47) -{ - AssetFactory assetFactory; - { - auto wheel = std::make_shared("wheel"); - { - auto wheelCylinder = wheel->uses.emplace_back(std::make_shared()); - wheelCylinder->type = assetFactory.shapes.at("cylinder"); - wheelCylinder->position = {0, 0, 0.571}; - wheelCylinder->scale = {1.142, 1.142, 0.07}; - wheelCylinder->rotation = {0, 0, half_pi}; - wheelCylinder->colour = assetFactory.parseColour("#2C3539"); - } - assetFactory.shapes.emplace(wheel->id, wheel); - } - { - auto axel = std::make_shared("axel"); - for (float x : {-1.f, 1.f}) { - auto wheel = axel->uses.emplace_back(std::make_shared()); - wheel->type = assetFactory.shapes.at("wheel"); - wheel->position = {x * 0.717f, 0, 0}; - wheel->rotation = {0, x == 1.f ? pi : 0.f, 0}; - } - assetFactory.shapes.emplace(axel->id, axel); - } - { - auto bogie = std::make_shared("bogie"); - for (float y : {-2.f, 0.f, 2.f}) { - auto axel = bogie->uses.emplace_back(std::make_shared()); - axel->type = assetFactory.shapes.at("axel"); - axel->position = {0, y, 0}; - } - assetFactory.shapes.emplace(bogie->id, bogie); - } - FactoryMesh::Collection factoryMeshes; - { - unsigned short b {0}; - for (float y : {-6.f, 6.f}) { - auto bogie = factoryMeshes.emplace_back(std::make_shared()); - bogie->id = "bogie" + std::to_string(b); - auto bogieUse = bogie->uses.emplace_back(std::make_shared()); - bogieUse->type = assetFactory.shapes.at("bogie"); - bogieUse->position = {0, y, 0}; - bogieUse->rotation = {0, b * pi, 0}; - b++; - } - } - { - auto body = factoryMeshes.emplace_back(std::make_shared()); - body->id = "body"; - body->size = {2.69f, 19.38f, 3.9f}; - auto bodyLower = body->uses.emplace_back(std::make_shared()); - bodyLower->type = assetFactory.shapes.at("cuboid"); - bodyLower->position = {0, 0, 1.2}; - bodyLower->scale = {2.69, 19.38, 1.5}; - bodyLower->colour = assetFactory.parseColour("#1111DD"); - auto & bottom = bodyLower->faceControllers["bottom"]; - bottom = std::make_unique(); - bottom->colour = assetFactory.parseColour("#2C3539"); - auto & bodyUpper = bodyLower->faceControllers["top"]; - bodyUpper = std::make_unique(); - bodyUpper->type = "extrude"; - bodyUpper->scale = {1, .95f, 1}; - bodyUpper->position = {0, 0, 1.0}; - auto & roof = bodyUpper->faceControllers["top"]; - roof = std::make_unique(); - roof->type = "extrude"; - roof->scale = {.6f, .9f, 0}; - roof->position = {0, 0, 0.2}; - roof->smooth = true; - { - auto batteryBox = body->uses.emplace_back(std::make_shared()); - batteryBox->type = assetFactory.shapes.at("cuboid"); - batteryBox->position = {0, 0, .2}; - batteryBox->scale = {2.6, 4.5, 1}; - batteryBox->colour = assetFactory.parseColour("#2C3539"); - } - } - std::transform(factoryMeshes.begin(), factoryMeshes.end(), std::back_inserter(meshes.objects), - [](const FactoryMesh::CPtr & factoryMesh) -> Mesh::Ptr { - return factoryMesh->createMesh(); - }); - - render(20); -} BOOST_AUTO_TEST_CASE(brush47xml) { auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml"); @@ -174,9 +90,8 @@ BOOST_AUTO_TEST_CASE(brush47xml) BOOST_REQUIRE(brush47rvc->bogies.front()); BOOST_REQUIRE(brush47rvc->bogies.back()); - meshes.objects.push_back(brush47rvc->bodyMesh); - meshes.objects.push_back(brush47rvc->bogies.front()); - meshes.objects.push_back(brush47rvc->bogies.back()); + auto railVehicle = std::make_shared(brush47rvc); + objects.objects.push_back(railVehicle); render(20); } -- cgit v1.2.3