diff --git a/dCommon/ZoneFile.h b/dCommon/ZoneFile.h index 1f3e09a76..d07a74cda 100644 --- a/dCommon/ZoneFile.h +++ b/dCommon/ZoneFile.h @@ -10,6 +10,7 @@ #include "NiPoint3.h" #include "NiQuaternion.h" #include "LDFFormat.h" +#include "eSceneType.h" #include "eWaypointCommandType.h" /** @@ -26,7 +27,7 @@ struct WaypointCommand { struct ZoneScene { std::string filename; uint32_t id{}; - uint32_t sceneType{}; //0 = general, 1 = audio? + eSceneType sceneType{}; std::string name; NiPoint3 unknown1; float unknown2{}; diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index 45c90f5ff..271669e30 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -54,32 +54,6 @@ constexpr float PI = 3.14159f; //============ STRUCTS ============== -struct LWOSCENEID { -public: - constexpr LWOSCENEID() noexcept { m_sceneID = -1; m_layerID = 0; } - constexpr LWOSCENEID(int32_t sceneID) noexcept { m_sceneID = sceneID; m_layerID = 0; } - constexpr LWOSCENEID(int32_t sceneID, uint32_t layerID) noexcept { m_sceneID = sceneID; m_layerID = layerID; } - - constexpr LWOSCENEID& operator=(const LWOSCENEID& rhs) noexcept { m_sceneID = rhs.m_sceneID; m_layerID = rhs.m_layerID; return *this; } - constexpr LWOSCENEID& operator=(const int32_t rhs) noexcept { m_sceneID = rhs; m_layerID = 0; return *this; } - - constexpr bool operator<(const LWOSCENEID& rhs) const noexcept { return (m_sceneID < rhs.m_sceneID || (m_sceneID == rhs.m_sceneID && m_layerID < rhs.m_layerID)); } - constexpr bool operator<(const int32_t rhs) const noexcept { return m_sceneID < rhs; } - - constexpr bool operator==(const LWOSCENEID& rhs) const noexcept { return (m_sceneID == rhs.m_sceneID && m_layerID == rhs.m_layerID); } - constexpr bool operator==(const int32_t rhs) const noexcept { return m_sceneID == rhs; } - - constexpr int32_t GetSceneID() const noexcept { return m_sceneID; } - constexpr uint32_t GetLayerID() const noexcept { return m_layerID; } - - constexpr void SetSceneID(const int32_t sceneID) noexcept { m_sceneID = sceneID; } - constexpr void SetLayerID(const uint32_t layerID) noexcept { m_layerID = layerID; } - -private: - int32_t m_sceneID; - uint32_t m_layerID; -}; - struct LWOZONEID { public: constexpr const LWOMAPID& GetMapID() const noexcept { return m_MapID; } @@ -99,7 +73,6 @@ private: LWOCLONEID m_CloneID = LWOCLONEID_INVALID; //To differentiate between "your property" and "my property". Always 0 for non-prop worlds. }; -constexpr LWOSCENEID LWOSCENEID_INVALID = -1; struct FriendData { public: diff --git a/dCommon/dEnums/eSceneType.h b/dCommon/dEnums/eSceneType.h new file mode 100644 index 000000000..74dbcdd47 --- /dev/null +++ b/dCommon/dEnums/eSceneType.h @@ -0,0 +1,13 @@ +#ifndef ESCENETYPE_H +#define ESCENETYPE_H + +#include + +// A zone scene's layer (the second half of the client's SceneAndLayer); zones split into a scene per layer +enum class eSceneType : uint32_t { + General = 0, // the scene's objects ("Global Scene" and the named scenes) + Audio = 1, // *_audio.lvl scenes, named "Audio" + FX = 2, // *_fxs.lvl scenes, named "FXs" (Nexus Tower) +}; + +#endif //!ESCENETYPE_H diff --git a/dDashboardServer/routes/ReportRoutes.cpp b/dDashboardServer/routes/ReportRoutes.cpp index eac116300..58a6f9ccb 100644 --- a/dDashboardServer/routes/ReportRoutes.cpp +++ b/dDashboardServer/routes/ReportRoutes.cpp @@ -701,7 +701,7 @@ std::optional ZoneTerrainLayersJson(uint32_t zoneId) { const auto luz = ClientAssets::ReadResFile("maps/" + zone->luzPath); std::string error; if (const auto header = luz ? ZonePaths::ReadHeader(*luz, error) : std::nullopt) { - for (const auto& scene : header->scenes) if (scene.sceneType == 0) names.try_emplace(scene.id, scene.name); + for (const auto& scene : header->scenes) if (scene.sceneType == eSceneType::General) names.try_emplace(scene.id, scene.name); } std::map cells; nlohmann::json chunks = nlohmann::json::array(); diff --git a/dDashboardServer/routes/Scenery.cpp b/dDashboardServer/routes/Scenery.cpp index df229c5bb..7f47833d3 100644 --- a/dDashboardServer/routes/Scenery.cpp +++ b/dDashboardServer/routes/Scenery.cpp @@ -373,7 +373,7 @@ namespace { if (!lvl) continue; const auto objectsBefore = assetOf.size(); const auto lighting = WorldScene::ReadLighting(*lvl); - if (lighting && scene.sceneType == 0) lightingOf.try_emplace(scene.id, LightingJson(*lighting)); + if (lighting && scene.sceneType == eSceneType::General) lightingOf.try_emplace(scene.id, LightingJson(*lighting)); if (sky < 0) { const auto skydome = JoinPath("", WorldScene::ReadSkydome(*lvl)); if (skydome.ends_with(".nif") && Files().paths.contains(skydome)) sky = static_cast(scenery.IndexOf(skydome)); diff --git a/dDashboardServer/routes/WorldView.cpp b/dDashboardServer/routes/WorldView.cpp index d3cc2a60e..fbb189e09 100644 --- a/dDashboardServer/routes/WorldView.cpp +++ b/dDashboardServer/routes/WorldView.cpp @@ -138,7 +138,7 @@ namespace { size_t index = 0; for (const auto& scene : zoneFile->scenes) { // Audio scenes share their general scene's id; the general one names it - if (scene.sceneType == 0 || !scenes.contains(std::to_string(scene.id))) scenes[std::to_string(scene.id)] = scene.name; + if (scene.sceneType == eSceneType::General || !scenes.contains(std::to_string(scene.id))) scenes[std::to_string(scene.id)] = scene.name; const auto lvl = ClientAssets::ReadResFile("maps/" + folder + scene.filename); if (!lvl) continue; for (const auto& object : WorldScene::ReadObjects(*lvl)) { diff --git a/dZoneManager/LWOSCENEID.h b/dZoneManager/LWOSCENEID.h new file mode 100644 index 000000000..92ae36d7a --- /dev/null +++ b/dZoneManager/LWOSCENEID.h @@ -0,0 +1,37 @@ +#ifndef LWOSCENEID_H +#define LWOSCENEID_H + +#include + +#include "eSceneType.h" + +// A scene of a zone: its scene ID and layer +struct LWOSCENEID { +public: + constexpr LWOSCENEID() noexcept { m_sceneID = -1; m_layerID = eSceneType::General; } + constexpr LWOSCENEID(int32_t sceneID) noexcept { m_sceneID = sceneID; m_layerID = eSceneType::General; } + constexpr LWOSCENEID(int32_t sceneID, eSceneType layerID) noexcept { m_sceneID = sceneID; m_layerID = layerID; } + + constexpr LWOSCENEID& operator=(const LWOSCENEID& rhs) noexcept { m_sceneID = rhs.m_sceneID; m_layerID = rhs.m_layerID; return *this; } + constexpr LWOSCENEID& operator=(const int32_t rhs) noexcept { m_sceneID = rhs; m_layerID = eSceneType::General; return *this; } + + constexpr bool operator<(const LWOSCENEID& rhs) const noexcept { return (m_sceneID < rhs.m_sceneID || (m_sceneID == rhs.m_sceneID && m_layerID < rhs.m_layerID)); } + constexpr bool operator<(const int32_t rhs) const noexcept { return m_sceneID < rhs; } + + constexpr bool operator==(const LWOSCENEID& rhs) const noexcept { return (m_sceneID == rhs.m_sceneID && m_layerID == rhs.m_layerID); } + constexpr bool operator==(const int32_t rhs) const noexcept { return m_sceneID == rhs; } + + constexpr int32_t GetSceneID() const noexcept { return m_sceneID; } + constexpr eSceneType GetLayerID() const noexcept { return m_layerID; } + + constexpr void SetSceneID(const int32_t sceneID) noexcept { m_sceneID = sceneID; } + constexpr void SetLayerID(const eSceneType layerID) noexcept { m_layerID = layerID; } + +private: + int32_t m_sceneID; + eSceneType m_layerID; +}; + +constexpr LWOSCENEID LWOSCENEID_INVALID = -1; + +#endif //!LWOSCENEID_H diff --git a/dZoneManager/Zone.cpp b/dZoneManager/Zone.cpp index 53e5ed5fa..4d51e128b 100644 --- a/dZoneManager/Zone.cpp +++ b/dZoneManager/Zone.cpp @@ -181,7 +181,7 @@ uint32_t Zone::CalculateChecksum() const { sum2 += sum1 += (sceneID >> 16); sum2 += sum1 += (sceneID & 0xffff); - uint32_t layerID = scene.GetLayerID(); + uint32_t layerID = GeneralUtils::ToUnderlying(scene.GetLayerID()); sum2 += sum1 += (layerID >> 16); sum2 += sum1 += (layerID & 0xffff); diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index 503d4cd3a..5ebd0bae3 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -2,6 +2,7 @@ #include "dZMCommon.h" #include "LDFFormat.h" +#include "LWOSCENEID.h" #include "ZoneFile.h" #include "ZoneScenes.h" #include "tinyxml2.h" diff --git a/tests/dCommonTests/ZoneFileTests.cpp b/tests/dCommonTests/ZoneFileTests.cpp index db02c63bb..82c9c0e5d 100644 --- a/tests/dCommonTests/ZoneFileTests.cpp +++ b/tests/dCommonTests/ZoneFileTests.cpp @@ -65,7 +65,7 @@ TEST(ZoneFileTests, ReadsScenesAndPaths) { ASSERT_EQ(zone.scenes.size(), 1u); EXPECT_EQ(zone.scenes[0].filename, "scene.lvl"); EXPECT_EQ(zone.scenes[0].id, 7u); - EXPECT_EQ(zone.scenes[0].sceneType, 2u); + EXPECT_EQ(zone.scenes[0].sceneType, eSceneType::FX); EXPECT_EQ(zone.zoneRawPath, "zone.raw"); ASSERT_EQ(zone.sceneTransitions.size(), 1u); EXPECT_EQ(zone.sceneTransitions[0].points.size(), 2u);