From 715d4879fdd096ac82367984fdb22117d48737a4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Feb 2023 02:26:06 +0000 Subject: First cut of the model factory and the hardcoded Brush 47 model Requires temporary change to the fragment shader to hardcode some visible colour to the model --- test/Jamfile.jam | 1 + test/test-modelFactory.cpp | 150 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 test/test-modelFactory.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index cefad7b..d802975 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -52,5 +52,6 @@ run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp : : : test ; run test-glContextBhvr.cpp ; +run test-modelFactory.cpp : : : test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; diff --git a/test/test-modelFactory.cpp b/test/test-modelFactory.cpp new file mode 100644 index 0000000..39362f5 --- /dev/null +++ b/test/test-modelFactory.cpp @@ -0,0 +1,150 @@ +#define BOOST_TEST_MODULE test_model_factory + +#include "testHelpers.h" +#include "testRenderOutput.h" +#include +#include + +#include "assetFactory/factoryMesh.h" +#include "assetFactory/modelFactory.h" +#include "assetFactory/object.h" +#include "gfx/gl/sceneRenderer.h" +#include "lib/collection.hpp" +#include "lib/location.hpp" +#include "testMainWindow.h" +#include "ui/applicationBase.h" + +BOOST_GLOBAL_FIXTURE(ApplicationBase); +BOOST_GLOBAL_FIXTURE(TestMainWindow); + +const std::filesystem::path TMP {"/tmp"}; +class FactoryFixture : public TestRenderOutputSize, public SceneProvider { +public: + FactoryFixture() : sceneRenderer {size, output} { } + ~FactoryFixture() + { + glDisable(GL_DEBUG_OUTPUT); + auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga"); + std::filesystem::create_directories(outpath.parent_path()); + Texture::save(outImage, size, outpath.c_str()); + } + void + content(const SceneShader & shader) const override + { + shader.basic.use(Location {{0, 0, 0}, {0, 0, 0}}); + meshes.apply(&Mesh::Draw); + } + void + lights(const SceneShader & shader) const override + { + shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F); + } + void + environment(const SceneShader &, const SceneRenderer & sceneRenderer) const override + { + sceneRenderer.setAmbientLight({.2, .2, .2}); + sceneRenderer.setDirectionalLight({.3, .3, .3}, east + south + south + down, *this); + } + void + shadows(const ShadowMapper & mapper) const override + { + mapper.dynamicPoint.use(Location {{0, 0, 0}, {0, 0, 0}}); + meshes.apply(&Mesh::Draw); + } + void + render(float dist = 10.f) + { + sceneRenderer.camera.setView({dist, dist, dist}, south + west + down); + sceneRenderer.render(*this); + } + Collection meshes; + +private: + SceneRenderer sceneRenderer; +}; + +BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); +BOOST_AUTO_TEST_CASE(brush47) +{ + ModelFactory modelFactory; + { + auto wheel = std::make_shared("wheel"); + { + auto wheelCylinder = wheel->uses.emplace_back(std::make_shared()); + wheelCylinder->type = modelFactory.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 = "#2C3539"; + } + modelFactory.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 = modelFactory.shapes.at("wheel"); + wheel->position = {x * 0.717f, 0, 0}; + wheel->rotation = {0, x == 1.f ? pi : 0.f, 0}; + } + modelFactory.shapes.emplace(axel->id, axel); + } + { + auto bogey = std::make_shared("bogey"); + for (float y : {-2.f, 0.f, 2.f}) { + auto axel = bogey->uses.emplace_back(std::make_shared()); + axel->type = modelFactory.shapes.at("axel"); + axel->position = {0, y, 0}; + } + modelFactory.shapes.emplace(bogey->id, bogey); + } + FactoryMesh::Collection factoryMeshes; + { + unsigned short b {0}; + for (float y : {-6.f, 6.f}) { + auto bogey = factoryMeshes.emplace_back(std::make_shared()); + bogey->id = "bogey" + std::to_string(b); + auto bogeyUse = bogey->uses.emplace_back(std::make_shared()); + bogeyUse->type = modelFactory.shapes.at("bogey"); + bogeyUse->position = {0, y, 0}; + bogeyUse->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 = modelFactory.shapes.at("cuboid"); + bodyLower->position = {0, 0, 1.2}; + bodyLower->scale = {2.69, 19.38, 1.5}; + bodyLower->colour = "#1111DD"; + bodyLower->faceControllers["bottom"].colour = "#2C3539"; + auto & bodyUpper = bodyLower->faceControllers["top"]; + bodyUpper.type = "extrude"; + bodyUpper.scale = {1, .95f, 1}; + bodyUpper.position = {0, 0, 1.0}; + auto & roof = bodyUpper.faceControllers["top"]; + 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 = modelFactory.shapes.at("cuboid"); + batteryBox->position = {0, 0, .2}; + batteryBox->scale = {2.6, 4.5, 1}; + batteryBox->colour = "#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_SUITE_END(); -- cgit v1.2.3 From 375652641509b75e93a284deea44f6f1be13e7b3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 20 Feb 2023 18:24:54 +0000 Subject: Swap @ prefix for p. prefix for special value names --- test/fixtures/json/abs.json | 2 +- test/fixtures/json/bad/empty_abs.json | 2 +- test/fixtures/json/bad/implicit_abs.json | 2 +- test/fixtures/json/bad/late_type.json | 2 +- test/fixtures/json/bad/wrong_type.json | 2 +- test/fixtures/json/bad_type.json | 2 +- test/fixtures/json/empty.json | 2 +- test/fixtures/json/implicit.json | 2 +- test/fixtures/json/load_object.json | 4 ++-- test/fixtures/json/nested.json | 8 ++++---- test/fixtures/json/shared_ptr_diff.json | 10 +++++----- test/fixtures/json/shared_ptr_diff_default.json | 6 +++--- test/fixtures/json/shared_ptr_null.json | 6 +++--- test/fixtures/json/shared_ptr_same.json | 6 +++--- test/fixtures/json/shared_ptr_wrong_type.json | 6 +++--- test/fixtures/json/vector_ptr.json | 2 +- test/test-persistence.cpp | 8 ++++---- 17 files changed, 36 insertions(+), 36 deletions(-) (limited to 'test') diff --git a/test/fixtures/json/abs.json b/test/fixtures/json/abs.json index 8492df3..1b489ef 100644 --- a/test/fixtures/json/abs.json +++ b/test/fixtures/json/abs.json @@ -1,6 +1,6 @@ { "aptr": { - "@typeid": "SubObject", + "p.typeid": "SubObject", "base": "set base", "sub": "set sub" } diff --git a/test/fixtures/json/bad/empty_abs.json b/test/fixtures/json/bad/empty_abs.json index 7d22001..5cc3598 100644 --- a/test/fixtures/json/bad/empty_abs.json +++ b/test/fixtures/json/bad/empty_abs.json @@ -1,5 +1,5 @@ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 1, "aptr": {}, "str": "after" diff --git a/test/fixtures/json/bad/implicit_abs.json b/test/fixtures/json/bad/implicit_abs.json index 573b323..bf81ee4 100644 --- a/test/fixtures/json/bad/implicit_abs.json +++ b/test/fixtures/json/bad/implicit_abs.json @@ -1,5 +1,5 @@ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 1, "aptr": { "str": "trigger" diff --git a/test/fixtures/json/bad/late_type.json b/test/fixtures/json/bad/late_type.json index 171575a..d1d6f6c 100644 --- a/test/fixtures/json/bad/late_type.json +++ b/test/fixtures/json/bad/late_type.json @@ -1,4 +1,4 @@ { "str": "trigger", - "@typeid": "doesn't matter" + "p.typeid": "doesn't matter" } diff --git a/test/fixtures/json/bad/wrong_type.json b/test/fixtures/json/bad/wrong_type.json index 777d791..4f19033 100644 --- a/test/fixtures/json/bad/wrong_type.json +++ b/test/fixtures/json/bad/wrong_type.json @@ -1,5 +1,5 @@ { "ptr": { - "@typeid": "SubObject" + "p.typeid": "SubObject" } } diff --git a/test/fixtures/json/bad_type.json b/test/fixtures/json/bad_type.json index f316bd1..70b9d1a 100644 --- a/test/fixtures/json/bad_type.json +++ b/test/fixtures/json/bad_type.json @@ -1,3 +1,3 @@ { - "@typeid": "no such type" + "p.typeid": "no such type" } diff --git a/test/fixtures/json/empty.json b/test/fixtures/json/empty.json index a9193a3..9575565 100644 --- a/test/fixtures/json/empty.json +++ b/test/fixtures/json/empty.json @@ -1,5 +1,5 @@ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 1, "ptr": {}, "str": "after" diff --git a/test/fixtures/json/implicit.json b/test/fixtures/json/implicit.json index 478cec6..6efc2ba 100644 --- a/test/fixtures/json/implicit.json +++ b/test/fixtures/json/implicit.json @@ -1,5 +1,5 @@ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 1, "ptr": { "str": "trigger", diff --git a/test/fixtures/json/load_object.json b/test/fixtures/json/load_object.json index bb32298..c622885 100644 --- a/test/fixtures/json/load_object.json +++ b/test/fixtures/json/load_object.json @@ -1,5 +1,5 @@ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 3.14, "str": "Lovely string", "bl": true, @@ -48,7 +48,7 @@ [] ], "ptr": { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 3.14, "str": "Lovely string" } diff --git a/test/fixtures/json/nested.json b/test/fixtures/json/nested.json index 98951fc..1e271e3 100644 --- a/test/fixtures/json/nested.json +++ b/test/fixtures/json/nested.json @@ -1,14 +1,14 @@ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 1, "ptr": { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 2, "ptr": { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 3, "ptr": { - "@typeid": "TestObject", + "p.typeid": "TestObject", "flt": 4, "ptr": null, "str": "four" diff --git a/test/fixtures/json/shared_ptr_diff.json b/test/fixtures/json/shared_ptr_diff.json index bb18e33..043be4a 100644 --- a/test/fixtures/json/shared_ptr_diff.json +++ b/test/fixtures/json/shared_ptr_diff.json @@ -1,11 +1,11 @@ { - "@typeid": "SharedTestObject", + "p.typeid": "SharedTestObject", "sptr": { - "@typeid": "SubObject", - "@id": "someid" + "p.typeid": "SubObject", + "p.id": "someid" }, "ssptr": { - "@typeid": "SubObject", - "@id": "some other id" + "p.typeid": "SubObject", + "p.id": "some other id" } } diff --git a/test/fixtures/json/shared_ptr_diff_default.json b/test/fixtures/json/shared_ptr_diff_default.json index 69f5e85..c78bc12 100644 --- a/test/fixtures/json/shared_ptr_diff_default.json +++ b/test/fixtures/json/shared_ptr_diff_default.json @@ -1,8 +1,8 @@ { - "@typeid": "SharedTestObject", + "p.typeid": "SharedTestObject", "sptr": { - "@typeid": "SubObject", - "@id": "someid" + "p.typeid": "SubObject", + "p.id": "someid" }, "ssptr": {} } diff --git a/test/fixtures/json/shared_ptr_null.json b/test/fixtures/json/shared_ptr_null.json index c2461e8..8669bf2 100644 --- a/test/fixtures/json/shared_ptr_null.json +++ b/test/fixtures/json/shared_ptr_null.json @@ -1,8 +1,8 @@ { - "@typeid": "SharedTestObject", + "p.typeid": "SharedTestObject", "sptr": { - "@typeid": "SubObject", - "@id": "someid" + "p.typeid": "SubObject", + "p.id": "someid" }, "ssptr": null } diff --git a/test/fixtures/json/shared_ptr_same.json b/test/fixtures/json/shared_ptr_same.json index 4115493..2838e82 100644 --- a/test/fixtures/json/shared_ptr_same.json +++ b/test/fixtures/json/shared_ptr_same.json @@ -1,8 +1,8 @@ { - "@typeid": "SharedTestObject", + "p.typeid": "SharedTestObject", "sptr": { - "@typeid": "SubObject", - "@id": "someid" + "p.typeid": "SubObject", + "p.id": "someid" }, "ssptr": "someid" } diff --git a/test/fixtures/json/shared_ptr_wrong_type.json b/test/fixtures/json/shared_ptr_wrong_type.json index 68f7533..5d4e655 100644 --- a/test/fixtures/json/shared_ptr_wrong_type.json +++ b/test/fixtures/json/shared_ptr_wrong_type.json @@ -1,8 +1,8 @@ { - "@typeid": "SharedTestObject", + "p.typeid": "SharedTestObject", "sptr": { - "@typeid": "SubObject2", - "@id": "someid" + "p.typeid": "SubObject2", + "p.id": "someid" }, "ssptr": "someid" } diff --git a/test/fixtures/json/vector_ptr.json b/test/fixtures/json/vector_ptr.json index 8a07a2e..654bd6c 100644 --- a/test/fixtures/json/vector_ptr.json +++ b/test/fixtures/json/vector_ptr.json @@ -1,7 +1,7 @@ { "vptr": [ { - "@typeid": "TestObject", + "p.typeid": "TestObject", "str": "type" }, { diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index e13cb7a..faa0d19 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(write_test_dfl) std::stringstream ss; Persistence::JsonWritePersistence {ss}.saveState(to); BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"vptr":[]})"); + R"({"p.typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"vptr":[]})"); } BOOST_FIXTURE_TEST_CASE(write_test_loaded, JPP) @@ -329,7 +329,7 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded, JPP) std::stringstream ss; Persistence::JsonWritePersistence {ss}.saveState(to); BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":true,"pos":[3.14,6.28,1.57],"flts":[3.14,6.28,1.57,0,-1,-3.14],"poss":[[3.14,6.28,1.57],[0,-1,-3.14]],"nest":[[["a","b"],["c","d","e"]],[["f"]],[]],"ptr":{"@typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"vptr":[]},"vptr":[]})"); + R"({"p.typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":true,"pos":[3.14,6.28,1.57],"flts":[3.14,6.28,1.57,0,-1,-3.14],"poss":[[3.14,6.28,1.57],[0,-1,-3.14]],"nest":[[["a","b"],["c","d","e"]],[["f"]],[]],"ptr":{"p.typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"vptr":[]},"vptr":[]})"); } BOOST_FIXTURE_TEST_CASE(write_test_loaded_abs, JPP) @@ -338,7 +338,7 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded_abs, JPP) std::stringstream ss; Persistence::JsonWritePersistence {ss}.saveState(to); BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"aptr":{"@typeid":"SubObject","base":"set base","sub":"set sub"},"vptr":[]})"); + R"({"p.typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"aptr":{"p.typeid":"SubObject","base":"set base","sub":"set sub"},"vptr":[]})"); } BOOST_FIXTURE_TEST_CASE(write_test_loaded_shared, JPP) @@ -349,7 +349,7 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded_shared, JPP) Persistence::JsonWritePersistence {ss}.saveState(to); BOOST_CHECK_EQUAL(Persistence::seenSharedObjects.size(), 1); BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"SharedTestObject","sptr":{"@typeid":"SubObject","@id":"someid","base":"","sub":""},"ssptr":"someid"})"); + R"({"p.typeid":"SharedTestObject","sptr":{"p.typeid":"SubObject","p.id":"someid","base":"","sub":""},"ssptr":"someid"})"); } BOOST_DATA_TEST_CASE(write_special_strings, TEST_STRINGS, exp, in) -- cgit v1.2.3 From ed7c2a6a73f24f97a0f04c2e6be6862ffe54b585 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 21 Feb 2023 01:25:34 +0000 Subject: Support for loading objects, uses and model factories from an XML resource --- test/Jamfile.jam | 2 +- test/test-modelFactory.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index d802975..027b880 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -52,6 +52,6 @@ run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp : : : test ; run test-glContextBhvr.cpp ; -run test-modelFactory.cpp : : : test ; +run test-modelFactory.cpp : -- : ../res/brush47.xml : test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; diff --git a/test/test-modelFactory.cpp b/test/test-modelFactory.cpp index 39362f5..8f2d56c 100644 --- a/test/test-modelFactory.cpp +++ b/test/test-modelFactory.cpp @@ -147,4 +147,27 @@ BOOST_AUTO_TEST_CASE(brush47) render(20); } +BOOST_AUTO_TEST_CASE(brush47xml) +{ + auto mf = ModelFactory::loadXML(RESDIR "/brush47.xml"); + BOOST_REQUIRE(mf); + BOOST_REQUIRE_EQUAL(6, mf->shapes.size()); + BOOST_CHECK(mf->shapes.at("plane")); + BOOST_CHECK(mf->shapes.at("cylinder")); + BOOST_CHECK(mf->shapes.at("cuboid")); + BOOST_CHECK(mf->shapes.at("wheel")); + BOOST_CHECK(mf->shapes.at("axel")); + auto bogey = mf->shapes.at("bogey"); + BOOST_REQUIRE(bogey); + auto bogeyObj = std::dynamic_pointer_cast(bogey); + BOOST_CHECK_EQUAL(3, bogeyObj->uses.size()); + + FactoryMesh::Collection factoryMeshes; + 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_SUITE_END(); -- cgit v1.2.3 From 5e561d390dc82b08c20532de0952f428e7b14283 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 21 Feb 2023 19:34:16 +0000 Subject: Rename ModelFactory to AssetFactory --- test/Jamfile.jam | 2 +- test/test-assetFactory.cpp | 173 +++++++++++++++++++++++++++++++++++++++++++++ test/test-modelFactory.cpp | 173 --------------------------------------------- 3 files changed, 174 insertions(+), 174 deletions(-) create mode 100644 test/test-assetFactory.cpp delete mode 100644 test/test-modelFactory.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 027b880..06f907a 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -52,6 +52,6 @@ run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp : : : test ; run test-glContextBhvr.cpp ; -run test-modelFactory.cpp : -- : ../res/brush47.xml : test ; +run test-assetFactory.cpp : -- : ../res/brush47.xml : test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp new file mode 100644 index 0000000..64d6a62 --- /dev/null +++ b/test/test-assetFactory.cpp @@ -0,0 +1,173 @@ +#define BOOST_TEST_MODULE test_asset_factory + +#include "testHelpers.h" +#include "testRenderOutput.h" +#include +#include + +#include "assetFactory/assetFactory.h" +#include "assetFactory/factoryMesh.h" +#include "assetFactory/object.h" +#include "gfx/gl/sceneRenderer.h" +#include "lib/collection.hpp" +#include "lib/location.hpp" +#include "testMainWindow.h" +#include "ui/applicationBase.h" + +BOOST_GLOBAL_FIXTURE(ApplicationBase); +BOOST_GLOBAL_FIXTURE(TestMainWindow); + +const std::filesystem::path TMP {"/tmp"}; +class FactoryFixture : public TestRenderOutputSize, public SceneProvider { +public: + FactoryFixture() : sceneRenderer {size, output} { } + ~FactoryFixture() + { + glDisable(GL_DEBUG_OUTPUT); + auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga"); + std::filesystem::create_directories(outpath.parent_path()); + Texture::save(outImage, size, outpath.c_str()); + } + void + content(const SceneShader & shader) const override + { + shader.basic.use(Location {{0, 0, 0}, {0, 0, 0}}); + meshes.apply(&Mesh::Draw); + } + void + lights(const SceneShader & shader) const override + { + shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F); + } + void + environment(const SceneShader &, const SceneRenderer & sceneRenderer) const override + { + sceneRenderer.setAmbientLight({.2, .2, .2}); + sceneRenderer.setDirectionalLight({.3, .3, .3}, east + south + south + down, *this); + } + void + shadows(const ShadowMapper & mapper) const override + { + mapper.dynamicPoint.use(Location {{0, 0, 0}, {0, 0, 0}}); + meshes.apply(&Mesh::Draw); + } + void + render(float dist = 10.f) + { + sceneRenderer.camera.setView({dist, dist, dist}, south + west + down); + sceneRenderer.render(*this); + } + Collection meshes; + +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 = "#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 bogey = std::make_shared("bogey"); + for (float y : {-2.f, 0.f, 2.f}) { + auto axel = bogey->uses.emplace_back(std::make_shared()); + axel->type = assetFactory.shapes.at("axel"); + axel->position = {0, y, 0}; + } + assetFactory.shapes.emplace(bogey->id, bogey); + } + FactoryMesh::Collection factoryMeshes; + { + unsigned short b {0}; + for (float y : {-6.f, 6.f}) { + auto bogey = factoryMeshes.emplace_back(std::make_shared()); + bogey->id = "bogey" + std::to_string(b); + auto bogeyUse = bogey->uses.emplace_back(std::make_shared()); + bogeyUse->type = assetFactory.shapes.at("bogey"); + bogeyUse->position = {0, y, 0}; + bogeyUse->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 = "#1111DD"; + bodyLower->faceControllers["bottom"].colour = "#2C3539"; + auto & bodyUpper = bodyLower->faceControllers["top"]; + bodyUpper.type = "extrude"; + bodyUpper.scale = {1, .95f, 1}; + bodyUpper.position = {0, 0, 1.0}; + auto & roof = bodyUpper.faceControllers["top"]; + 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 = "#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"); + BOOST_REQUIRE(mf); + BOOST_REQUIRE_EQUAL(6, mf->shapes.size()); + BOOST_CHECK(mf->shapes.at("plane")); + BOOST_CHECK(mf->shapes.at("cylinder")); + BOOST_CHECK(mf->shapes.at("cuboid")); + BOOST_CHECK(mf->shapes.at("wheel")); + BOOST_CHECK(mf->shapes.at("axel")); + auto bogey = mf->shapes.at("bogey"); + BOOST_REQUIRE(bogey); + auto bogeyObj = std::dynamic_pointer_cast(bogey); + BOOST_CHECK_EQUAL(3, bogeyObj->uses.size()); + + FactoryMesh::Collection factoryMeshes; + 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_SUITE_END(); diff --git a/test/test-modelFactory.cpp b/test/test-modelFactory.cpp deleted file mode 100644 index 8f2d56c..0000000 --- a/test/test-modelFactory.cpp +++ /dev/null @@ -1,173 +0,0 @@ -#define BOOST_TEST_MODULE test_model_factory - -#include "testHelpers.h" -#include "testRenderOutput.h" -#include -#include - -#include "assetFactory/factoryMesh.h" -#include "assetFactory/modelFactory.h" -#include "assetFactory/object.h" -#include "gfx/gl/sceneRenderer.h" -#include "lib/collection.hpp" -#include "lib/location.hpp" -#include "testMainWindow.h" -#include "ui/applicationBase.h" - -BOOST_GLOBAL_FIXTURE(ApplicationBase); -BOOST_GLOBAL_FIXTURE(TestMainWindow); - -const std::filesystem::path TMP {"/tmp"}; -class FactoryFixture : public TestRenderOutputSize, public SceneProvider { -public: - FactoryFixture() : sceneRenderer {size, output} { } - ~FactoryFixture() - { - glDisable(GL_DEBUG_OUTPUT); - auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga"); - std::filesystem::create_directories(outpath.parent_path()); - Texture::save(outImage, size, outpath.c_str()); - } - void - content(const SceneShader & shader) const override - { - shader.basic.use(Location {{0, 0, 0}, {0, 0, 0}}); - meshes.apply(&Mesh::Draw); - } - void - lights(const SceneShader & shader) const override - { - shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F); - } - void - environment(const SceneShader &, const SceneRenderer & sceneRenderer) const override - { - sceneRenderer.setAmbientLight({.2, .2, .2}); - sceneRenderer.setDirectionalLight({.3, .3, .3}, east + south + south + down, *this); - } - void - shadows(const ShadowMapper & mapper) const override - { - mapper.dynamicPoint.use(Location {{0, 0, 0}, {0, 0, 0}}); - meshes.apply(&Mesh::Draw); - } - void - render(float dist = 10.f) - { - sceneRenderer.camera.setView({dist, dist, dist}, south + west + down); - sceneRenderer.render(*this); - } - Collection meshes; - -private: - SceneRenderer sceneRenderer; -}; - -BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture); -BOOST_AUTO_TEST_CASE(brush47) -{ - ModelFactory modelFactory; - { - auto wheel = std::make_shared("wheel"); - { - auto wheelCylinder = wheel->uses.emplace_back(std::make_shared()); - wheelCylinder->type = modelFactory.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 = "#2C3539"; - } - modelFactory.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 = modelFactory.shapes.at("wheel"); - wheel->position = {x * 0.717f, 0, 0}; - wheel->rotation = {0, x == 1.f ? pi : 0.f, 0}; - } - modelFactory.shapes.emplace(axel->id, axel); - } - { - auto bogey = std::make_shared("bogey"); - for (float y : {-2.f, 0.f, 2.f}) { - auto axel = bogey->uses.emplace_back(std::make_shared()); - axel->type = modelFactory.shapes.at("axel"); - axel->position = {0, y, 0}; - } - modelFactory.shapes.emplace(bogey->id, bogey); - } - FactoryMesh::Collection factoryMeshes; - { - unsigned short b {0}; - for (float y : {-6.f, 6.f}) { - auto bogey = factoryMeshes.emplace_back(std::make_shared()); - bogey->id = "bogey" + std::to_string(b); - auto bogeyUse = bogey->uses.emplace_back(std::make_shared()); - bogeyUse->type = modelFactory.shapes.at("bogey"); - bogeyUse->position = {0, y, 0}; - bogeyUse->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 = modelFactory.shapes.at("cuboid"); - bodyLower->position = {0, 0, 1.2}; - bodyLower->scale = {2.69, 19.38, 1.5}; - bodyLower->colour = "#1111DD"; - bodyLower->faceControllers["bottom"].colour = "#2C3539"; - auto & bodyUpper = bodyLower->faceControllers["top"]; - bodyUpper.type = "extrude"; - bodyUpper.scale = {1, .95f, 1}; - bodyUpper.position = {0, 0, 1.0}; - auto & roof = bodyUpper.faceControllers["top"]; - 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 = modelFactory.shapes.at("cuboid"); - batteryBox->position = {0, 0, .2}; - batteryBox->scale = {2.6, 4.5, 1}; - batteryBox->colour = "#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 = ModelFactory::loadXML(RESDIR "/brush47.xml"); - BOOST_REQUIRE(mf); - BOOST_REQUIRE_EQUAL(6, mf->shapes.size()); - BOOST_CHECK(mf->shapes.at("plane")); - BOOST_CHECK(mf->shapes.at("cylinder")); - BOOST_CHECK(mf->shapes.at("cuboid")); - BOOST_CHECK(mf->shapes.at("wheel")); - BOOST_CHECK(mf->shapes.at("axel")); - auto bogey = mf->shapes.at("bogey"); - BOOST_REQUIRE(bogey); - auto bogeyObj = std::dynamic_pointer_cast(bogey); - BOOST_CHECK_EQUAL(3, bogeyObj->uses.size()); - - FactoryMesh::Collection factoryMeshes; - 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_SUITE_END(); -- cgit v1.2.3 From df2a078c51cee464905c6fb1d1c7c4aa7873f6a1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 22 Feb 2023 23:40:46 +0000 Subject: Implement loading asset, mesh and face definitions --- test/test-assetFactory.cpp | 73 ++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 64d6a62..fd7a41d 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -90,24 +90,24 @@ BOOST_AUTO_TEST_CASE(brush47) assetFactory.shapes.emplace(axel->id, axel); } { - auto bogey = std::make_shared("bogey"); + auto bogie = std::make_shared("bogie"); for (float y : {-2.f, 0.f, 2.f}) { - auto axel = bogey->uses.emplace_back(std::make_shared()); + auto axel = bogie->uses.emplace_back(std::make_shared()); axel->type = assetFactory.shapes.at("axel"); axel->position = {0, y, 0}; } - assetFactory.shapes.emplace(bogey->id, bogey); + assetFactory.shapes.emplace(bogie->id, bogie); } FactoryMesh::Collection factoryMeshes; { unsigned short b {0}; for (float y : {-6.f, 6.f}) { - auto bogey = factoryMeshes.emplace_back(std::make_shared()); - bogey->id = "bogey" + std::to_string(b); - auto bogeyUse = bogey->uses.emplace_back(std::make_shared()); - bogeyUse->type = assetFactory.shapes.at("bogey"); - bogeyUse->position = {0, y, 0}; - bogeyUse->rotation = {0, b * pi, 0}; + 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++; } } @@ -115,23 +115,25 @@ BOOST_AUTO_TEST_CASE(brush47) 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 = "#1111DD"; - bodyLower->faceControllers["bottom"].colour = "#2C3539"; - auto & bodyUpper = bodyLower->faceControllers["top"]; - bodyUpper.type = "extrude"; - bodyUpper.scale = {1, .95f, 1}; - bodyUpper.position = {0, 0, 1.0}; - auto & roof = bodyUpper.faceControllers["top"]; - roof.type = "extrude"; - roof.scale = {.6f, .9f, 0}; - roof.position = {0, 0, 0.2}; - roof.smooth = true; - } + 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 = "#1111DD"; + auto & bottom = bodyLower->faceControllers["bottom"]; + bottom = std::make_unique(); + bottom->colour = "#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"); @@ -157,13 +159,20 @@ BOOST_AUTO_TEST_CASE(brush47xml) BOOST_CHECK(mf->shapes.at("cuboid")); BOOST_CHECK(mf->shapes.at("wheel")); BOOST_CHECK(mf->shapes.at("axel")); - auto bogey = mf->shapes.at("bogey"); - BOOST_REQUIRE(bogey); - auto bogeyObj = std::dynamic_pointer_cast(bogey); - BOOST_CHECK_EQUAL(3, bogeyObj->uses.size()); + auto bogie = mf->shapes.at("bogie"); + BOOST_REQUIRE(bogie); + auto bogieObj = std::dynamic_pointer_cast(bogie); + BOOST_CHECK_EQUAL(3, bogieObj->uses.size()); + BOOST_CHECK_EQUAL(1, mf->assets.size()); + auto brush47 = mf->assets.at("brush-47"); + BOOST_REQUIRE(brush47); + BOOST_CHECK_EQUAL(3, brush47->meshes.size()); + auto body = brush47->meshes.at(0); + BOOST_REQUIRE(body); + BOOST_CHECK_EQUAL("body", body->id); + BOOST_CHECK_EQUAL(2, body->uses.size()); - FactoryMesh::Collection factoryMeshes; - std::transform(factoryMeshes.begin(), factoryMeshes.end(), std::back_inserter(meshes.objects), + std::transform(brush47->meshes.begin(), brush47->meshes.end(), std::back_inserter(meshes.objects), [](const FactoryMesh::CPtr & factoryMesh) -> Mesh::Ptr { return factoryMesh->createMesh(); }); -- cgit v1.2.3 From b59ba638083122456bfeab0ff1fc7e3f3af99423 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 23 Feb 2023 00:39:06 +0000 Subject: Support parsing string values in persistence read --- test/fixtures/json/conv.json | 4 ++++ test/test-persistence.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/fixtures/json/conv.json (limited to 'test') diff --git a/test/fixtures/json/conv.json b/test/fixtures/json/conv.json new file mode 100644 index 0000000..1b690d5 --- /dev/null +++ b/test/fixtures/json/conv.json @@ -0,0 +1,4 @@ +{ + "bl": "true", + "flt": "3.14" +} diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index faa0d19..6bee010 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -208,6 +208,14 @@ BOOST_FIXTURE_TEST_CASE(load_vector_ptr, JPP) BOOST_CHECK(to->vptr.at(3)->str.empty()); } +BOOST_FIXTURE_TEST_CASE(test_conversion, JPP) +{ + auto to = load_json>(FIXTURESDIR "json/conv.json"); + BOOST_REQUIRE(to); + BOOST_CHECK_EQUAL(to->bl, true); + BOOST_CHECK_EQUAL(to->flt, 3.14F); +} + struct SharedTestObject : public Persistence::Persistable { SharedTestObject() = default; -- cgit v1.2.3 From 2e440265e212c18208e683edab833fb9d3b735b4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 27 Feb 2023 00:26:20 +0000 Subject: Add a perf test over the asset factory --- test/Jamfile.jam | 5 ++++- test/perf-assetFactory.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/perf-assetFactory.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 06f907a..907632e 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -2,6 +2,7 @@ import testing ; import sequence ; lib boost_unit_test_framework ; +lib benchmark ; path-constant res : ../res ; path-constant fixtures : fixtures ; @@ -39,7 +40,7 @@ project : requirements tidy:hicpp-vararg tidy:boost ; -lib test : [ glob *.cpp : test-*.cpp ] ; +lib test : [ glob *.cpp : test-*.cpp perf-*.cpp ] ; run test-collection.cpp ; run test-obj.cpp ; @@ -53,5 +54,7 @@ run test-enumDetails.cpp ; run test-render.cpp : : : test ; run test-glContextBhvr.cpp ; run test-assetFactory.cpp : -- : ../res/brush47.xml : test ; +run perf-assetFactory.cpp : : : benchmark test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; +explicit perf-assetFactory ; diff --git a/test/perf-assetFactory.cpp b/test/perf-assetFactory.cpp new file mode 100644 index 0000000..f702fe7 --- /dev/null +++ b/test/perf-assetFactory.cpp @@ -0,0 +1,32 @@ +#include "assetFactory/assetFactory.h" +#include "assetFactory/factoryMesh.h" +#include "testMainWindow.h" +#include "ui/applicationBase.h" +#include + +static void +brush47xml_load(benchmark::State & state) +{ + for (auto _ : state) { + benchmark::DoNotOptimize(AssetFactory::loadXML(RESDIR "/brush47.xml")); + } +} + +static void +brush47xml_mesh(benchmark::State & state) +{ + TestMainWindow window; + + const auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml"); + const auto brush47 = mf->assets.at("brush-47"); + for (auto _ : state) { + std::for_each(brush47->meshes.begin(), brush47->meshes.end(), [](const FactoryMesh::CPtr & factoryMesh) { + factoryMesh->createMesh(); + }); + } +} + +BENCHMARK(brush47xml_load); +BENCHMARK(brush47xml_mesh); + +BENCHMARK_MAIN(); -- cgit v1.2.3 From b7b9eb7bb9deb6704f276fb3b8fd67ba370caf3e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 27 Feb 2023 19:38:14 +0000 Subject: Load the X11 RGB colour definitions into a map --- test/fixtures/rgb.txt | 20 ++++++++++++++++++++ test/test-assetFactory.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/fixtures/rgb.txt (limited to 'test') diff --git a/test/fixtures/rgb.txt b/test/fixtures/rgb.txt new file mode 100644 index 0000000..2fab7af --- /dev/null +++ b/test/fixtures/rgb.txt @@ -0,0 +1,20 @@ +127 255 0 chartreuse1 +190 190 190 x11 gray +169 169 169 DarkGrey + 0 255 255 cyan +173 173 173 gray68 +202 225 255 LightSteelBlue1 + 72 209 204 medium turquoise +224 238 224 honeydew2 +238 197 145 burlywood2 +205 133 63 peru + 28 28 28 gray11 + 83 134 139 CadetBlue4 +139 76 57 salmon4 +238 232 170 pale goldenrod +112 128 144 slate grey +255 255 0 yellow1 +159 121 238 MediumPurple2 +190 190 190 gray + 66 66 66 grey26 +0 0 139 DarkBlue diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index fd7a41d..89f6bf0 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -11,6 +11,7 @@ #include "gfx/gl/sceneRenderer.h" #include "lib/collection.hpp" #include "lib/location.hpp" +#include "lib/stream_support.hpp" #include "testMainWindow.h" #include "ui/applicationBase.h" @@ -180,3 +181,32 @@ BOOST_AUTO_TEST_CASE(brush47xml) render(20); } BOOST_AUTO_TEST_SUITE_END(); + +template using InOut = std::tuple; +BOOST_DATA_TEST_CASE(normalizeColourName, + boost::unit_test::data::make>({ + {"", ""}, + {"black", "black"}, + {" black ", "black"}, + {" b l a c k ", "black"}, + {" B L A c k ", "black"}, + {"BLAck ", "black"}, + {"BLACK ", "black"}, + {"BlAck ", "black"}, + {"Bl Ack ", "black"}, + }), + in_, exp) +{ + auto in {in_}; + BOOST_CHECK_NO_THROW(AssetFactory::normalizeColourName(in)); + BOOST_CHECK_EQUAL(in, exp); +} + +BOOST_AUTO_TEST_CASE(parseX11RGB) +{ + const auto parsedColours = AssetFactory::parseX11RGB(FIXTURESDIR "rgb.txt"); + BOOST_REQUIRE_EQUAL(parsedColours.size(), 20); + BOOST_CHECK_EQUAL(parsedColours.at("cyan"), AssetFactory::Colour(0, 255, 255)); + BOOST_CHECK_EQUAL(parsedColours.at("slategrey"), AssetFactory::Colour(112, 128, 144)); + BOOST_CHECK_EQUAL(parsedColours.at("lightsteelblue1"), AssetFactory::Colour(202, 225, 255)); +} -- cgit v1.2.3 From 98df33e0a52e086b68df2a62ce2f41cc6b67db63 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Mar 2023 18:18:38 +0000 Subject: Parse colour values as they're read --- test/test-assetFactory.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 89f6bf0..8feb831 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(brush47) wheelCylinder->position = {0, 0, 0.571}; wheelCylinder->scale = {1.142, 1.142, 0.07}; wheelCylinder->rotation = {0, 0, half_pi}; - wheelCylinder->colour = "#2C3539"; + wheelCylinder->colour = assetFactory.parseColour("#2C3539"); } assetFactory.shapes.emplace(wheel->id, wheel); } @@ -120,10 +120,10 @@ BOOST_AUTO_TEST_CASE(brush47) bodyLower->type = assetFactory.shapes.at("cuboid"); bodyLower->position = {0, 0, 1.2}; bodyLower->scale = {2.69, 19.38, 1.5}; - bodyLower->colour = "#1111DD"; + bodyLower->colour = assetFactory.parseColour("#1111DD"); auto & bottom = bodyLower->faceControllers["bottom"]; bottom = std::make_unique(); - bottom->colour = "#2C3539"; + bottom->colour = assetFactory.parseColour("#2C3539"); auto & bodyUpper = bodyLower->faceControllers["top"]; bodyUpper = std::make_unique(); bodyUpper->type = "extrude"; @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(brush47) batteryBox->type = assetFactory.shapes.at("cuboid"); batteryBox->position = {0, 0, .2}; batteryBox->scale = {2.6, 4.5, 1}; - batteryBox->colour = "#2C3539"; + batteryBox->colour = assetFactory.parseColour("#2C3539"); } } std::transform(factoryMeshes.begin(), factoryMeshes.end(), std::back_inserter(meshes.objects), @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(parseX11RGB) { const auto parsedColours = AssetFactory::parseX11RGB(FIXTURESDIR "rgb.txt"); BOOST_REQUIRE_EQUAL(parsedColours.size(), 20); - BOOST_CHECK_EQUAL(parsedColours.at("cyan"), AssetFactory::Colour(0, 255, 255)); - BOOST_CHECK_EQUAL(parsedColours.at("slategrey"), AssetFactory::Colour(112, 128, 144)); - BOOST_CHECK_EQUAL(parsedColours.at("lightsteelblue1"), AssetFactory::Colour(202, 225, 255)); + BOOST_CHECK_CLOSE_VEC(parsedColours.at("cyan"), AssetFactory::Colour(0, 1, 1)); + BOOST_CHECK_CLOSE_VEC(parsedColours.at("slategrey"), AssetFactory::Colour(0.44F, 0.5, 0.56F)); + BOOST_CHECK_CLOSE_VEC(parsedColours.at("lightsteelblue1"), AssetFactory::Colour(0.79, 0.88, 1)); } -- cgit v1.2.3 From 17ac090dd1dd245cf1e24b62b7333ba9be571bde Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 2 Mar 2023 18:36:34 +0000 Subject: Add ParseBase Acts as a base class for persistence parser, encompasses the parse stack and manages shared objects --- test/test-persistence.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index 6bee010..7bca91a 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -83,16 +83,14 @@ struct TestObject : public Persistence::Persistable { } }; -struct JPP : public Persistence::JsonParsePersistence { +struct JPP { template T load_json(const std::filesystem::path & path) { BOOST_TEST_CONTEXT(path) { std::ifstream ss {path}; - auto to = loadState(ss); - Persistence::sharedObjects.clear(); - BOOST_CHECK(stk.empty()); + auto to = Persistence::JsonParsePersistence {}.loadState(ss); BOOST_REQUIRE(to); return to; } @@ -289,10 +287,10 @@ auto const TEST_STRINGS_DECODE_ONLY = boost::unit_test::data::make({ {R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"}, {R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"}, }); -BOOST_DATA_TEST_CASE_F(JPP, load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, exp) +BOOST_DATA_TEST_CASE(load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, exp) { std::stringstream str {in}; - BOOST_CHECK_EQUAL(loadState(str), exp); + BOOST_CHECK_EQUAL(Persistence::JsonParsePersistence {}.loadState(str), exp); } using cpstr = std::tuple; -- cgit v1.2.3 From 54ddcd3da0916b6a46f5fcf3f33ff0fbffe375ce Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 14:27:23 +0000 Subject: Support and load factory asset directly into a RailVehicleClass instance --- test/test-assetFactory.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 8feb831..9930714 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -8,6 +8,7 @@ #include "assetFactory/assetFactory.h" #include "assetFactory/factoryMesh.h" #include "assetFactory/object.h" +#include "game/vehicles/railVehicleClass.h" #include "gfx/gl/sceneRenderer.h" #include "lib/collection.hpp" #include "lib/location.hpp" @@ -167,16 +168,15 @@ BOOST_AUTO_TEST_CASE(brush47xml) BOOST_CHECK_EQUAL(1, mf->assets.size()); auto brush47 = mf->assets.at("brush-47"); BOOST_REQUIRE(brush47); - BOOST_CHECK_EQUAL(3, brush47->meshes.size()); - auto body = brush47->meshes.at(0); - BOOST_REQUIRE(body); - BOOST_CHECK_EQUAL("body", body->id); - BOOST_CHECK_EQUAL(2, body->uses.size()); + auto brush47rvc = std::dynamic_pointer_cast(brush47); + BOOST_REQUIRE(brush47rvc); + BOOST_REQUIRE(brush47rvc->bodyMesh); + BOOST_REQUIRE(brush47rvc->bogies.front()); + BOOST_REQUIRE(brush47rvc->bogies.back()); - std::transform(brush47->meshes.begin(), brush47->meshes.end(), std::back_inserter(meshes.objects), - [](const FactoryMesh::CPtr & factoryMesh) -> Mesh::Ptr { - return factoryMesh->createMesh(); - }); + meshes.objects.push_back(brush47rvc->bodyMesh); + meshes.objects.push_back(brush47rvc->bogies.front()); + meshes.objects.push_back(brush47rvc->bogies.back()); render(20); } -- cgit v1.2.3 From 74b86470aec99b87a1f3545b7d3799dbf0c1e90c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 15:26:35 +0000 Subject: RailVehicleClass now renders bogie shadows as well as body --- test/test-render.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test-render.cpp b/test/test-render.cpp index 7db847d..7771760 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -29,8 +29,8 @@ class TestScene : public SceneProvider { content(const SceneShader & shader) const override { terrain.render(shader); - train.render(shader, Location {{52, 50, 2}}, {Location {}, Location {}}); - train.render(shader, Location {{52, 30, 2}}, {Location {}, Location {}}); + train.render(shader, Location {{52, 50, 2}}, {Location {{52, 56, 2}}, Location {{52, 44, 2}}}); + train.render(shader, Location {{52, 30, 2}}, {Location {{52, 36, 2}}, Location {{52, 24, 2}}}); } void lights(const SceneShader &) const override @@ -40,8 +40,8 @@ class TestScene : public SceneProvider { shadows(const ShadowMapper & shadowMapper) const override { terrain.shadows(shadowMapper); - train.shadows(shadowMapper, Location {{52, 50, 2}}); - train.shadows(shadowMapper, Location {{52, 30, 2}}); + train.shadows(shadowMapper, Location {{52, 50, 2}}, {Location {{52, 56, 2}}, Location {{52, 44, 2}}}); + train.shadows(shadowMapper, Location {{52, 30, 2}}, {Location {{52, 36, 2}}, Location {{52, 24, 2}}}); } }; -- cgit v1.2.3 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