From 47cd9d863fb09acb82d2428f881d61242f8ab437 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 17:33:02 +0100 Subject: Load all assets in red dir with asset factory --- application/main.cpp | 9 ++++++++- assetFactory/assetFactory.cpp | 13 +++++++++++++ assetFactory/assetFactory.h | 1 + test/test-assetFactory.cpp | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/application/main.cpp b/application/main.cpp index 1f91dab..aea3d2e 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -11,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -43,6 +46,7 @@ public: world.create(geoData); { + const auto assets = AssetFactory::loadAll("res"); auto rl = world.create(); const glm::vec3 j {-1120, -1100, 3}, k {-1100, -1000, 15}, l {-1000, -800, 20}, m {-900, -600, 30}, n {-600, -500, 32}, o {-500, -800, 30}, p {-600, -900, 25}, q {-1025, -1175, 10}, @@ -66,13 +70,16 @@ public: rl->addLinksBetween(t, u); rl->addLinksBetween(u, m); const std::shared_ptr train = world.create(l3); - auto b47 = std::make_shared("brush47"); + auto b47 = std::dynamic_pointer_cast(assets.at("brush-47")); for (int N = 0; N < 6; N++) { train->create(b47); } train->orders.removeAll(); train->orders.create(&train->orders, l3->ends[1], l3->length, rl->findNodeAt({-1100, -450, 15})); train->currentActivity = train->orders.current()->createActivity(); + + auto foliage = std::dynamic_pointer_cast(assets.at("Tree-01-1")); + world.create(foliage, Location {{-1100, -1100, 0}}); } auto t_start = std::chrono::high_resolution_clock::now(); diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp index 05f0634..af0cd54 100644 --- a/assetFactory/assetFactory.cpp +++ b/assetFactory/assetFactory.cpp @@ -11,6 +11,7 @@ #include "resource.h" #include "saxParse-persistence.h" #include "texturePacker.h" +#include AssetFactory::AssetFactory() : shapes { @@ -29,6 +30,18 @@ AssetFactory::loadXML(const std::filesystem::path & filename) return Persistence::SAXParsePersistence {}.loadState>(file); } +AssetFactory::Assets +AssetFactory::loadAll(const std::filesystem::path & root) +{ + return std::accumulate(std::filesystem::recursive_directory_iterator {root}, + std::filesystem::recursive_directory_iterator {}, Assets {}, [](auto && out, auto && path) { + if (path.path().extension() == ".xml") { + out.merge(loadXML(path)->assets); + } + return std::move(out); + }); +} + AssetFactory::Colours AssetFactory::parseX11RGB(const char * path) { diff --git a/assetFactory/assetFactory.h b/assetFactory/assetFactory.h index 9e5d205..e449ce2 100644 --- a/assetFactory/assetFactory.h +++ b/assetFactory/assetFactory.h @@ -22,6 +22,7 @@ public: AssetFactory(); [[nodiscard]] static std::shared_ptr loadXML(const std::filesystem::path &); + [[nodiscard]] static Assets loadAll(const std::filesystem::path &); [[nodiscard]] ColourAlpha parseColour(std::string_view) const; [[nodiscard]] GLuint getMaterialIndex(std::string_view) const; [[nodiscard]] Asset::TexturePtr getTexture() const; diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index c425e71..3d79213 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -115,6 +115,13 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) } BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_CASE(loadall) +{ + const auto assets = AssetFactory::loadAll(RESDIR); + BOOST_CHECK(assets.at("brush-47")); + BOOST_CHECK(assets.at("Tree-01-1")); +} + template using InOut = std::tuple; BOOST_DATA_TEST_CASE(normalizeColourName, boost::unit_test::data::make>({ -- cgit v1.2.3