summaryrefslogtreecommitdiff
path: root/game/mixins/lights.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/mixins/lights.cpp')
-rw-r--r--game/mixins/lights.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/game/mixins/lights.cpp b/game/mixins/lights.cpp
new file mode 100644
index 0000000..6829bbb
--- /dev/null
+++ b/game/mixins/lights.cpp
@@ -0,0 +1,30 @@
+#include "lights.h"
+#include "gfx/renderable.h"
+
+bool
+AssetLights::persist(Persistence::PersistenceStore & store)
+{
+ return STORE_HELPER(pointLight, Persistence::Appender<decltype(pointLight)>)
+ && STORE_HELPER(spotLight, Persistence::Appender<decltype(spotLight)>);
+}
+
+void
+InstanceLights::lightsEnable(AnyPtr<const AssetLights> asset, uint32_t owner)
+{
+ auto createLights = [owner](const auto & assetLights, auto & lightInstances, auto commonLights) {
+ std::ranges::transform(assetLights | std::views::enumerate, std::inserter(lightInstances, lightInstances.end()),
+ [&commonLights, owner](const auto & idxAndLight) {
+ const auto & [idx, light] = idxAndLight;
+ return std::make_pair(idx, commonLights->acquire(*light, owner));
+ });
+ };
+ createLights(asset->spotLight, spotLightInstances, Renderable::commonSpotLights.lock());
+ createLights(asset->pointLight, pointLightInstances, Renderable::commonPointLights.lock());
+}
+
+void
+InstanceLights::lightsDisable()
+{
+ spotLightInstances.clear();
+ pointLightInstances.clear();
+}