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 --- game/vehicles/railVehicleClass.cpp | 9 +++++++++ game/vehicles/railVehicleClass.h | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'game/vehicles') 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 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 & 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 #include @@ -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 &) const; void shadows(const ShadowMapper &, const Location &) const; @@ -25,6 +27,10 @@ public: float length; float maxSpeed; +protected: + friend Persistence::SelectionPtrBase>; + bool persist(Persistence::PersistenceStore & store) override; + private: RailVehicleClass(std::unique_ptr obj, std::shared_ptr); static float bogieOffset(ObjParser & o); -- cgit v1.2.3 From ca7611dcf999f55ea17d5cd4f53e5a836ec51cd1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 14:59:02 +0000 Subject: RailVehicleClass texture might be null --- game/vehicles/railVehicleClass.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 7052396..c0740cc 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -53,7 +53,9 @@ RailVehicleClass::render( const SceneShader & shader, const Location & location, const std::array & bl) const { shader.basic.use(location); - texture->bind(); + if (texture) { + texture->bind(); + } bodyMesh->Draw(); for (auto b = 0U; b < bogies.size(); ++b) { shader.basic.setModel(bl[b]); -- cgit v1.2.3 From c8ecaaddeee46900540e24e096f86306e77493f7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 15:12:30 +0000 Subject: Load length, wheelBase and maxSpeed RailVehicleClass properties from XML Adjusts bogie position to appear correct according to wheelBase --- game/vehicles/railVehicleClass.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index c0740cc..90a06bd 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -44,7 +44,8 @@ RailVehicleClass::RailVehicleClass() { } bool RailVehicleClass::persist(Persistence::PersistenceStore & store) { - return STORE_TYPE && STORE_MEMBER(maxSpeed) && STORE_NAME_HELPER("bogie", bogies, Asset::MeshArrayConstruct) + return STORE_TYPE && STORE_MEMBER(length) && STORE_MEMBER(wheelBase) && STORE_MEMBER(maxSpeed) + && STORE_NAME_HELPER("bogie", bogies, Asset::MeshArrayConstruct) && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store); } -- 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 --- game/vehicles/railVehicle.cpp | 2 +- game/vehicles/railVehicleClass.cpp | 7 ++++++- game/vehicles/railVehicleClass.h | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index bcde68f..cbe36a6 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -20,7 +20,7 @@ RailVehicle::render(const SceneShader & shader) const void RailVehicle::shadows(const ShadowMapper & shadowMapper) const { - rvClass->shadows(shadowMapper, location); + rvClass->shadows(shadowMapper, location, bogies); } void diff --git a/game/vehicles/railVehicleClass.cpp b/game/vehicles/railVehicleClass.cpp index 90a06bd..41ef5e9 100644 --- a/game/vehicles/railVehicleClass.cpp +++ b/game/vehicles/railVehicleClass.cpp @@ -64,10 +64,15 @@ RailVehicleClass::render( } } void -RailVehicleClass::shadows(const ShadowMapper & shadowMapper, const Location & location) const +RailVehicleClass::shadows( + const ShadowMapper & shadowMapper, const Location & location, const std::array & bl) const { shadowMapper.dynamicPoint.use(location); bodyMesh->Draw(); + for (auto b = 0U; b < bogies.size(); ++b) { + shadowMapper.dynamicPoint.setModel(bl[b]); + bogies[b]->Draw(); + } } float diff --git a/game/vehicles/railVehicleClass.h b/game/vehicles/railVehicleClass.h index c50dacc..a2222fb 100644 --- a/game/vehicles/railVehicleClass.h +++ b/game/vehicles/railVehicleClass.h @@ -18,7 +18,7 @@ public: RailVehicleClass(); void render(const SceneShader &, const Location &, const std::array &) const; - void shadows(const ShadowMapper &, const Location &) const; + void shadows(const ShadowMapper &, const Location &, const std::array &) const; std::array bogies; Mesh::Ptr bodyMesh; -- cgit v1.2.3 From c32674d9bac2cf6283cafc3bf446a45be22b2851 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Mar 2023 15:47:22 +0000 Subject: Default RailVehicle bogie positions according to class wheelBase Useful for render tests so everything looks sane --- game/vehicles/railVehicle.cpp | 6 ++++++ game/vehicles/railVehicle.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'game/vehicles') diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index cbe36a6..77907be 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -11,6 +11,12 @@ #include #include +RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)} +{ + bogies.front().pos.y = rvClass->wheelBase / 2.F; + bogies.back().pos.y = -bogies.front().pos.y; +} + void RailVehicle::render(const SceneShader & shader) const { diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index f172a28..bbf4df9 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -16,7 +16,7 @@ class Ray; class Train; class RailVehicle : public Renderable, Selectable { public: - explicit RailVehicle(RailVehicleClassPtr rvc) : rvClass {std::move(rvc)} { } + explicit RailVehicle(RailVehicleClassPtr rvc); void move(const Train *, float & trailBy); -- cgit v1.2.3