diff options
-rw-r--r-- | game/vehicles/railVehicle.cpp | 15 | ||||
-rw-r--r-- | game/vehicles/railVehicle.h | 5 | ||||
-rw-r--r-- | gfx/gl/bufferedLocation.cpp | 7 | ||||
-rw-r--r-- | gfx/gl/bufferedLocation.h | 18 |
4 files changed, 27 insertions, 18 deletions
diff --git a/game/vehicles/railVehicle.cpp b/game/vehicles/railVehicle.cpp index fc43995..1ed904d 100644 --- a/game/vehicles/railVehicle.cpp +++ b/game/vehicles/railVehicle.cpp @@ -12,10 +12,19 @@ #include <ray.h> RailVehicle::RailVehicle(RailVehicleClassPtr rvc) : - RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, location {&LV::body, *this}, + RailVehicleClass::Instance {rvc->instances.acquire()}, rvClass {std::move(rvc)}, + location {[this](const BufferedLocation * l) { + this->get()->body = l->getTransform(); + }}, bogies {{ - {&LV::front, *this, Position3D {0, rvClass->wheelBase / 2.F, 0}}, - {&LV::back, *this, Position3D {0, -rvClass->wheelBase / 2.F, 0}}, + {[this](const BufferedLocation * l) { + this->get()->front = l->getTransform(); + }, + Position3D {0, rvClass->wheelBase / 2.F, 0}}, + {[this](const BufferedLocation * l) { + this->get()->back = l->getTransform(); + }, + Position3D {0, -rvClass->wheelBase / 2.F, 0}}, }} { } diff --git a/game/vehicles/railVehicle.h b/game/vehicles/railVehicle.h index e034852..20d1ea1 100644 --- a/game/vehicles/railVehicle.h +++ b/game/vehicles/railVehicle.h @@ -21,9 +21,8 @@ public: RailVehicleClassPtr rvClass; using LV = RailVehicleClass::LocationVertex; - using BLocation = BufferedLocationT<glm::mat4 LV::*, RailVehicleClass::Instance &>; - BLocation location; - std::array<BLocation, 2> bogies; + BufferedLocationUpdater location; + std::array<BufferedLocationUpdater, 2> bogies; }; using RailVehiclePtr = std::unique_ptr<RailVehicle>; diff --git a/gfx/gl/bufferedLocation.cpp b/gfx/gl/bufferedLocation.cpp index 6ba8812..412e3ab 100644 --- a/gfx/gl/bufferedLocation.cpp +++ b/gfx/gl/bufferedLocation.cpp @@ -1,6 +1,5 @@ #include "bufferedLocation.h" #include "location.h" -#include "maths.h" #include <glm/gtx/transform.hpp> BufferedLocation::BufferedLocation(Position3D p, Rotation3D r) : BufferedLocation {Location {p, r}} { } @@ -69,3 +68,9 @@ BufferedLocation::getRotationTransform() const { return loc.getRotationTransform(); } + +void +BufferedLocationUpdater::updateBuffer() const +{ + onUpdate(this); +} diff --git a/gfx/gl/bufferedLocation.h b/gfx/gl/bufferedLocation.h index 8302b3c..a5cd23e 100644 --- a/gfx/gl/bufferedLocation.h +++ b/gfx/gl/bufferedLocation.h @@ -4,7 +4,7 @@ #include <functional> #include <glm/mat4x4.hpp> #include <glm/vec3.hpp> -#include <tuple> +#include <utility> class BufferedLocation { public: @@ -26,16 +26,16 @@ public: [[nodiscard]] glm::mat4 getRotationTransform() const; private: - virtual void updateBuffer() = 0; + virtual void updateBuffer() const = 0; Location loc; }; -template<typename... Target> class BufferedLocationT : public BufferedLocation { +class BufferedLocationUpdater : public BufferedLocation { public: template<typename... LocationArgs> - BufferedLocationT(Target &&... target, LocationArgs &&... t) : - BufferedLocation {std::forward<LocationArgs>(t)...}, target {std::forward<Target>(target)...} + BufferedLocationUpdater(std::function<void(const BufferedLocation *)> onUpdate, LocationArgs &&... t) : + BufferedLocation {std::forward<LocationArgs>(t)...}, onUpdate {std::move(onUpdate)} { updateBuffer(); } @@ -43,11 +43,7 @@ public: using BufferedLocation::operator=; private: - void - updateBuffer() override - { - std::apply(std::invoke<const Target &...>, target) = getTransform(); - } + void updateBuffer() const override; - std::tuple<Target...> target; + std::function<void(const BufferedLocation *)> onUpdate; }; |