summaryrefslogtreecommitdiff
path: root/gfx/gl
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
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')
-rw-r--r--gfx/gl/bufferedLocation.cpp7
-rw-r--r--gfx/gl/bufferedLocation.h18
2 files changed, 13 insertions, 12 deletions
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;
};