From ec564b14df538dd84c926aa2f7518847ada68bf3 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sat, 23 Nov 2024 23:08:13 +0300 Subject: [PATCH] Support ESM4::Light with no spotlight data --- components/esm4/loadligh.cpp | 34 ++++++++++++++++++++-------------- components/esm4/loadligh.hpp | 28 ++++++++++++++-------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/components/esm4/loadligh.cpp b/components/esm4/loadligh.cpp index a0d467bafc..32432c97e1 100644 --- a/components/esm4/loadligh.cpp +++ b/components/esm4/loadligh.cpp @@ -48,7 +48,11 @@ void ESM4::Light::load(ESM4::Reader& reader) break; case ESM::fourCC("DATA"): { - if (subHdr.dataSize != 32 && subHdr.dataSize != 48 && subHdr.dataSize != 64) + // 24: older TES4 records (found in GOG release) + // 32: newer TES4 records, FO3/FNV + // 48: TES5 + // 64: FO4/FO76 + if (subHdr.dataSize != 24 && subHdr.dataSize != 32 && subHdr.dataSize != 48 && subHdr.dataSize != 64) { reader.skipSubRecordData(); break; @@ -57,21 +61,23 @@ void ESM4::Light::load(ESM4::Reader& reader) reader.get(mData.radius); reader.get(mData.colour); reader.get(mData.flags); - reader.get(mData.falloff); - reader.get(mData.FOV); - // TES5, FO4 - if (subHdr.dataSize >= 48) + if (subHdr.dataSize >= 32) { - reader.get(mData.nearClip); - reader.get(mData.frequency); - reader.get(mData.intensityAmplitude); - reader.get(mData.movementAmplitude); - if (subHdr.dataSize == 64) + reader.get(mData.falloff); + reader.get(mData.FOV); + if (subHdr.dataSize >= 48) { - reader.get(mData.constant); - reader.get(mData.scalar); - reader.get(mData.exponent); - reader.get(mData.godRaysNearClip); + reader.get(mData.nearClip); + reader.get(mData.frequency); + reader.get(mData.intensityAmplitude); + reader.get(mData.movementAmplitude); + if (subHdr.dataSize == 64) + { + reader.get(mData.constant); + reader.get(mData.scalar); + reader.get(mData.exponent); + reader.get(mData.godRaysNearClip); + } } } reader.get(mData.value); diff --git a/components/esm4/loadligh.hpp b/components/esm4/loadligh.hpp index 5845f3769a..8fc59b7687 100644 --- a/components/esm4/loadligh.hpp +++ b/components/esm4/loadligh.hpp @@ -56,9 +56,9 @@ namespace ESM4 struct Data { - std::int32_t time; - std::uint32_t radius; - std::uint32_t colour; // RGBA + std::int32_t time = 0; + std::uint32_t radius = 0; + std::uint32_t colour = 0; // RGBA // flags: // 0x00000001 = Dynamic // 0x00000002 = Can be Carried @@ -70,19 +70,19 @@ namespace ESM4 // 0x00000100 = Pulse Slow // 0x00000200 = Spot Light // 0x00000400 = Spot Shadow - std::int32_t flags; + std::int32_t flags = 0; float falloff = 1.f; float FOV = 90; // FIXME: FOV in degrees or radians? - float nearClip; // TES5+ - float frequency; // TES5+ - float intensityAmplitude; // TES5+ - float movementAmplitude; // TES5+ - float constant; // FO4 - float scalar; // FO4 - float exponent; // FO4 - float godRaysNearClip; // FO4 - std::uint32_t value; // gold - float weight; + float nearClip = 0.f; // TES5+ + float frequency = 0.f; // TES5+ + float intensityAmplitude = 0.f; // TES5+ + float movementAmplitude = 0.f; // TES5+ + float constant = 0.f; // FO4 + float scalar = 0.f; // FO4 + float exponent = 0.f; // FO4 + float godRaysNearClip = 0.f; // FO4 + std::uint32_t value = 0; // gold + float weight = 0.f; }; ESM::FormId mId; // from the header