diff options
-rw-r--r-- | assetFactory/asset.cpp | 3 | ||||
-rw-r--r-- | assetFactory/asset.h | 2 | ||||
-rw-r--r-- | game/vehicles/railVehicleClass.cpp | 9 | ||||
-rw-r--r-- | game/vehicles/railVehicleClass.h | 8 | ||||
-rw-r--r-- | res/brush47.xml | 14 | ||||
-rw-r--r-- | test/test-assetFactory.cpp | 18 |
6 files changed, 33 insertions, 21 deletions
diff --git a/assetFactory/asset.cpp b/assetFactory/asset.cpp index 659a950..3ab2f1c 100644 --- a/assetFactory/asset.cpp +++ b/assetFactory/asset.cpp @@ -3,8 +3,7 @@ bool Asset::persist(Persistence::PersistenceStore & store) { - return STORE_MEMBER(id) && STORE_MEMBER(name) - && STORE_NAME_HELPER("mesh", meshes, Persistence::Appender<FactoryMesh::Collection>); + return STORE_MEMBER(id) && STORE_MEMBER(name); } Asset::MeshConstruct::MeshConstruct(Mesh::Ptr & m) : diff --git a/assetFactory/asset.h b/assetFactory/asset.h index 8dd1ecb..e3318e4 100644 --- a/assetFactory/asset.h +++ b/assetFactory/asset.h @@ -9,8 +9,6 @@ public: std::string id; std::string name; - FactoryMesh::Collection meshes; - protected: struct MeshConstruct : public Persistence::SelectionPtrBase<FactoryMesh::Ptr> { using Persistence::SelectionPtrBase<FactoryMesh::Ptr>::setValue; diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index dff1416..7052396 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -39,6 +39,15 @@ RailVehicleClass::RailVehicleClass(std::unique_ptr<ObjParser> o, std::shared_ptr bogies[1] = m.at("Bogie2"); } +RailVehicleClass::RailVehicleClass() { } + +bool +RailVehicleClass::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(maxSpeed) && STORE_NAME_HELPER("bogie", bogies, Asset::MeshArrayConstruct) + && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store); +} + void RailVehicleClass::render( const SceneShader & shader, const Location & location, const std::array<Location, 2> & bl) const diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index bd74ab9..c50dacc 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -1,5 +1,6 @@ #pragma once +#include "assetFactory/asset.h" #include "gfx/models/mesh.h" #include <array> #include <memory> @@ -11,9 +12,10 @@ class Texture; class ObjParser; class Location; -class RailVehicleClass { +class RailVehicleClass : public Asset { public: explicit RailVehicleClass(const std::string & name); + RailVehicleClass(); void render(const SceneShader &, const Location &, const std::array<Location, 2> &) const; void shadows(const ShadowMapper &, const Location &) const; @@ -25,6 +27,10 @@ public: float length; float maxSpeed; +protected: + friend Persistence::SelectionPtrBase<std::shared_ptr<RailVehicleClass>>; + bool persist(Persistence::PersistenceStore & store) override; + private: RailVehicleClass(std::unique_ptr<ObjParser> obj, std::shared_ptr<Texture>); static float bogieOffset(ObjParser & o); diff --git a/res/brush47.xml b/res/brush47.xml index 477610c..796641a 100644 --- a/res/brush47.xml +++ b/res/brush47.xml @@ -12,8 +12,8 @@ <use type="axel" position="0,2,0"/> <use type="axel" position="0,-2,0"/> </object> - <asset id="brush-47" name="Brush 47"> - <mesh id="body" size="2.69,19.38,3.9"> + <asset p.typeid="RailVehicleClass" id="brush-47" name="Brush 47"> + <bodyMesh id="body" size="2.69,19.38,3.9"> <use type="cuboid" position="0,0,1.2" scale="2.69,19.38,1.5" colour="#2c4f5a"> <face id="bottom" colour="#2c3539"/> <face id="front" colour="goldenrod"/> @@ -25,12 +25,12 @@ </face> </use> <use type="cuboid" position="0,0,0.2" scale="2.6,4.5,1" colour="grey30"/> - </mesh> - <mesh id="bogie1"> + </bodyMesh> + <bogie id="bogie1"> <use type="bogie" position="0,6,0" colour="#413b3a"/> - </mesh> - <mesh id="bogie2"> + </bogie> + <bogie id="bogie2"> <use type="bogie" position="0,-6,0" rotation="0,3.14159,0" colour="#413b3a"/> - </mesh> + </bogie> </asset> </ilt> 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<RailVehicleClass>(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); } |