From 74a241680dcb8e543c7e2ab70eb0cfe00d01f22a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 1 Apr 2026 20:31:29 +0100 Subject: Move spot/point light persistence wrappers to assetFactory --- assetFactory/lights.cpp | 14 ++++++++++++++ assetFactory/lights.h | 18 ++++++++++++++++++ game/scenary/illuminator.cpp | 13 ------------- game/scenary/illuminator.h | 14 +------------- game/scenary/light.cpp | 5 ++--- 5 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 assetFactory/lights.cpp create mode 100644 assetFactory/lights.h diff --git a/assetFactory/lights.cpp b/assetFactory/lights.cpp new file mode 100644 index 0000000..ec8e17e --- /dev/null +++ b/assetFactory/lights.cpp @@ -0,0 +1,14 @@ +#include "lights.h" + +bool +SpotLight::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(direction) && STORE_MEMBER(colour) && STORE_MEMBER(kq) + && STORE_MEMBER(arc); +} + +bool +PointLight::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(colour) && STORE_MEMBER(kq); +} diff --git a/assetFactory/lights.h b/assetFactory/lights.h new file mode 100644 index 0000000..8657d85 --- /dev/null +++ b/assetFactory/lights.h @@ -0,0 +1,18 @@ +#pragma once + +#include "gfx/models/lights.h" +#include "persistence.h" +#include "stdTypeDefs.h" + +struct SpotLight : Persistence::Persistable, SpotLightDef, StdTypeDefs { +private: + friend Persistence::SelectionPtrBase>; + bool persist(Persistence::PersistenceStore & store) override; +}; + +struct PointLight : Persistence::Persistable, PointLightDef, StdTypeDefs { +private: + friend Persistence::SelectionPtrBase>; + bool persist(Persistence::PersistenceStore & store) override; +}; + diff --git a/game/scenary/illuminator.cpp b/game/scenary/illuminator.cpp index 55791a5..7f0c7c2 100644 --- a/game/scenary/illuminator.cpp +++ b/game/scenary/illuminator.cpp @@ -15,19 +15,6 @@ Illuminator::createAt(const Location & position) const instances.acquire(locationData->acquire(position))); } -bool -Illuminator::SpotLight::persist(Persistence::PersistenceStore & store) -{ - return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(direction) && STORE_MEMBER(colour) && STORE_MEMBER(kq) - && STORE_MEMBER(arc); -} - -bool -Illuminator::PointLight::persist(Persistence::PersistenceStore & store) -{ - return STORE_TYPE && STORE_MEMBER(position) && STORE_MEMBER(colour) && STORE_MEMBER(kq); -} - bool Illuminator::persist(Persistence::PersistenceStore & store) { diff --git a/game/scenary/illuminator.h b/game/scenary/illuminator.h index b99a19e..216b536 100644 --- a/game/scenary/illuminator.h +++ b/game/scenary/illuminator.h @@ -1,8 +1,8 @@ #pragma once #include "assetFactory/asset.h" +#include "assetFactory/lights.h" #include "gfx/gl/instanceVertices.h" -#include "gfx/models/lights.h" #include "gfx/models/texture.h" #include "gfx/renderable.h" @@ -18,18 +18,6 @@ class Illuminator : public Asset, public Renderable, public StdTypeDefs { - private: - friend Persistence::SelectionPtrBase>; - bool persist(Persistence::PersistenceStore & store) override; - }; - - struct PointLight : Persistence::Persistable, PointLightDef, StdTypeDefs { - private: - friend Persistence::SelectionPtrBase>; - bool persist(Persistence::PersistenceStore & store) override; - }; - struct InstanceVertex { CommonLocationInstance location; }; diff --git a/game/scenary/light.cpp b/game/scenary/light.cpp index bd83f04..c51efda 100644 --- a/game/scenary/light.cpp +++ b/game/scenary/light.cpp @@ -6,12 +6,11 @@ Light::Light(std::shared_ptr type, const Location & position) instance {this->type->instances.acquire(Renderable::commonLocationData.lock()->acquire(position))} { std::ranges::transform(this->type->spotLight, std::back_inserter(spotLightInstances), - [spotLights = Renderable::commonSpotLights.lock(), this](const Illuminator::SpotLight::CPtr & spotLight) { + [spotLights = Renderable::commonSpotLights.lock(), this](const auto & spotLight) { return spotLights->acquire(*spotLight, instance->location.index); }); std::ranges::transform(this->type->pointLight, std::back_inserter(pointLightInstances), - [pointLights = Renderable::commonPointLights.lock(), this]( - const Illuminator::PointLight::CPtr & pointLight) { + [pointLights = Renderable::commonPointLights.lock(), this](const auto & pointLight) { return pointLights->acquire(*pointLight, instance->location.index); }); } -- cgit v1.3