summaryrefslogtreecommitdiff
path: root/gfx/gl/bufferedLocation.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-11 17:37:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-11 17:37:57 +0000
commit5e25d79beef19c39537b0f15982a175fec45bb3e (patch)
tree011cdd78c661757bab03cfd8ede11e6a58047968 /gfx/gl/bufferedLocation.h
parentAdd BufferedLocation method for getting the rotation only transform (diff)
downloadilt-5e25d79beef19c39537b0f15982a175fec45bb3e.tar.bz2
ilt-5e25d79beef19c39537b0f15982a175fec45bb3e.tar.xz
ilt-5e25d79beef19c39537b0f15982a175fec45bb3e.zip
Refactor BufferedLocationT to use a callback
Simplifies customisation in the face of multiple fields
Diffstat (limited to 'gfx/gl/bufferedLocation.h')
-rw-r--r--gfx/gl/bufferedLocation.h18
1 files changed, 7 insertions, 11 deletions
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;
};