From fb78c88576d9fed90ee69dfa35a9fbd3179ff486 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 30 Mar 2026 13:04:36 +0100 Subject: Use a single buffer for the location/rotation data of all renderable objects Removes the BufferedLocation and BufferedLocationUpdater mess. Note: appears to break bogie rendering in asset factory test only, same symptom as broken network render test? (out of date buffer data) --- lib/location.cpp | 8 ++++++++ lib/location.h | 2 ++ 2 files changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/location.cpp b/lib/location.cpp index 13acfde..2138f0a 100644 --- a/lib/location.cpp +++ b/lib/location.cpp @@ -2,6 +2,14 @@ #include "maths.h" #include +Location +Location::operator+(RelativePosition3D offset) const +{ + Location ret {*this}; + ret.pos += offset; + return ret; +} + glm::mat3 Location::getRotationTransform() const { diff --git a/lib/location.h b/lib/location.h index 016aee7..e642b41 100644 --- a/lib/location.h +++ b/lib/location.h @@ -11,6 +11,8 @@ public: [[nodiscard]] glm::mat3 getRotationTransform() const; + Location operator+(RelativePosition3D) const; + GlobalPosition3D pos; Rotation3D rot; }; -- cgit v1.3 From 56207fbf4e8662b6cf93632193ba68d2576c2d4e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 1 Apr 2026 12:07:58 +0100 Subject: Helper to instantiate transient static values as required --- game/scenary/foliage.cpp | 7 +++---- game/scenary/illuminator.cpp | 4 ++-- gfx/renderable.cpp | 5 ++--- lib/util.h | 12 ++++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/game/scenary/foliage.cpp b/game/scenary/foliage.cpp index 5902e09..f27ac26 100644 --- a/game/scenary/foliage.cpp +++ b/game/scenary/foliage.cpp @@ -4,6 +4,7 @@ #include "gfx/gl/sceneShader.h" #include "gfx/gl/shadowMapper.h" #include "gfx/gl/shadowStenciller.h" +#include "util.h" #include static_assert(std::is_constructible_v); @@ -40,12 +41,10 @@ Foliage::postLoad() { texture = getTexture(); glDebugScope _ {0}; - if (!(instanceVAO = commonInstanceVAO.lock())) { - commonInstanceVAO = instanceVAO = std::make_shared(); + if (createIfRequired(instanceVAO, commonInstanceVAO)) { bodyMesh->configureVAO(*instanceVAO, 0).addAttribs(1); } - if (!(instancePointVAO = commonInstancePointVAO.lock())) { - commonInstancePointVAO = instancePointVAO = std::make_shared(); + if (createIfRequired(instancePointVAO, commonInstancePointVAO)) { instancePointVAO->configure().addAttribs(0); } const auto & size = bodyMesh->getDimensions().size; diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index e991baa..3b73cd3 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -1,6 +1,7 @@ #include "illuminator.h" #include "gfx/gl/sceneShader.h" #include "gfx/models/texture.h" // IWYU pragma: keep +#include "util.h" #include static_assert(std::is_constructible_v); @@ -44,8 +45,7 @@ Illuminator::postLoad() } texture = getTexture(); glDebugScope _ {0}; - if (!(instanceVAO = commonInstanceVAO.lock())) { - commonInstanceVAO = instanceVAO = std::make_shared(); + if (createIfRequired(instanceVAO, commonInstanceVAO)) { bodyMesh->configureVAO(*instanceVAO, 0).addAttribs(1); } if (!spotLight.empty()) { diff --git a/gfx/renderable.cpp b/gfx/renderable.cpp index 4597597..90035c3 100644 --- a/gfx/renderable.cpp +++ b/gfx/renderable.cpp @@ -2,6 +2,7 @@ #include "gl_traits.h" #include "location.h" #include "maths.h" +#include "util.h" std::weak_ptr Renderable::commonLocationData; @@ -21,9 +22,7 @@ Renderable::CommonLocation ::operator=(Location const & location) Renderable::Renderable() { - if (!(locationData = commonLocationData.lock())) { - commonLocationData = locationData = std::make_shared(); - } + createIfRequired(locationData, commonLocationData); } GLuint diff --git a/lib/util.h b/lib/util.h index cd7971b..b60b093 100644 --- a/lib/util.h +++ b/lib/util.h @@ -3,6 +3,7 @@ #include // IWYU pragma: keep #include #include +#include #include template @@ -33,3 +34,14 @@ template inline constexpr auto Nth = GetNth {}; inline constexpr auto GetFirst = Nth<0>; inline constexpr auto GetSecond = Nth<1>; inline constexpr auto GetSwapped = Nth<0, 1>; + +template +bool +createIfRequired(std::shared_ptr & instance, std::weak_ptr & common) +{ + if (!instance && !(instance = common.lock())) { + common = instance = std::make_shared(); + return true; + } + return false; +} -- cgit v1.3 From 6635cee143eb4cf3882bac519b8c12b83b62de62 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 1 Apr 2026 14:21:10 +0100 Subject: Add helper to Decompose a member pointer --- lib/util.cpp | 1 - lib/util.h | 10 ++++++++++ test/Jamfile.jam | 1 + test/test-static-util.cpp | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) delete mode 100644 lib/util.cpp create mode 100644 test/test-static-util.cpp (limited to 'lib') diff --git a/lib/util.cpp b/lib/util.cpp deleted file mode 100644 index 408a76a..0000000 --- a/lib/util.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "util.h" diff --git a/lib/util.h b/lib/util.h index b60b093..093462d 100644 --- a/lib/util.h +++ b/lib/util.h @@ -35,6 +35,16 @@ inline constexpr auto GetFirst = Nth<0>; inline constexpr auto GetSecond = Nth<1>; inline constexpr auto GetSwapped = Nth<0, 1>; +template struct Decompose { + consteval Decompose(M T::*) { } + + using ValueType = M; + using ContainerType = T; +}; + +template using MemberValueType = typename decltype(Decompose {MbrPtr})::ValueType; +template using ContainerType = typename decltype(Decompose {MbrPtr})::ContainerType; + template bool createIfRequired(std::shared_ptr & instance, std::weak_ptr & common) diff --git a/test/Jamfile.jam b/test/Jamfile.jam index da2a61a..baf0db4 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -79,5 +79,6 @@ run test-environment.cpp : : : test ; run test-ui.cpp : : : test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; +compile test-static-util.cpp ; alias perf : perf-assetFactory perf-persistence perf-geoData perf-instancing perf-terrain ; explicit perf ; diff --git a/test/test-static-util.cpp b/test/test-static-util.cpp new file mode 100644 index 0000000..2a8aa81 --- /dev/null +++ b/test/test-static-util.cpp @@ -0,0 +1,29 @@ +#include "util.h" + +namespace { + struct Base1 { + int a; + float b; + }; + + struct Base2 { + int x; + float y; + }; + + struct Sub : Base1, Base2 { + double value; + }; + + static_assert(std::is_same_v, int>); + static_assert(std::is_same_v, float>); + static_assert(std::is_same_v, int>); + static_assert(std::is_same_v, float>); + static_assert(std::is_same_v, double>); + + static_assert(std::is_same_v, Base1>); + static_assert(std::is_same_v, Base2>); + static_assert(std::is_same_v, Base1>); + static_assert(std::is_same_v, Base2>); + static_assert(std::is_same_v, Sub>); +} -- cgit v1.3