mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-20 02:35:28 +00:00
refactor: look up the oldest zone files' scenes in a CDClient SceneTable table
Zone held a std::function that queried the SceneTable, so tests could swap it out. CDSceneTableTable now loads the table with the others, and Zone looks scenes up in it; tests fill its entries like the zone table's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
#include "CDEventGatingTable.h"
|
#include "CDEventGatingTable.h"
|
||||||
#include "CDScriptComponentTable.h"
|
#include "CDScriptComponentTable.h"
|
||||||
#include "CDSkillBehaviorTable.h"
|
#include "CDSkillBehaviorTable.h"
|
||||||
|
#include "CDSceneTableTable.h"
|
||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
#include "CDTamingBuildPuzzleTable.h"
|
#include "CDTamingBuildPuzzleTable.h"
|
||||||
#include "CDVendorComponentTable.h"
|
#include "CDVendorComponentTable.h"
|
||||||
@@ -194,6 +195,7 @@ void CDClientManager::LoadValuesFromDatabase(const std::filesystem::path& fdbPat
|
|||||||
CDRebuildComponentTable::Instance().LoadValuesFromDatabase();
|
CDRebuildComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
CDRewardCodesTable::Instance().LoadValuesFromDatabase();
|
CDRewardCodesTable::Instance().LoadValuesFromDatabase();
|
||||||
CDRewardsTable::Instance().LoadValuesFromDatabase();
|
CDRewardsTable::Instance().LoadValuesFromDatabase();
|
||||||
|
CDSceneTableTable::LoadValuesFromDatabase();
|
||||||
CDScriptComponentTable::Instance().LoadValuesFromDatabase();
|
CDScriptComponentTable::Instance().LoadValuesFromDatabase();
|
||||||
CDSkillBehaviorTable::Instance().LoadValuesFromDatabase();
|
CDSkillBehaviorTable::Instance().LoadValuesFromDatabase();
|
||||||
CDTamingBuildPuzzleTable::Instance().LoadValuesFromDatabase();
|
CDTamingBuildPuzzleTable::Instance().LoadValuesFromDatabase();
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#include "CDSceneTableTable.h"
|
||||||
|
|
||||||
|
namespace CDSceneTableTable {
|
||||||
|
Table entries;
|
||||||
|
|
||||||
|
void LoadValuesFromDatabase() {
|
||||||
|
// Get the data from the database
|
||||||
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM SceneTable");
|
||||||
|
while (!tableData.eof()) {
|
||||||
|
CDSceneTable entry;
|
||||||
|
entry.sceneID = tableData.getIntField("sceneID", -1);
|
||||||
|
entry.sceneName = tableData.getStringField("sceneName", "");
|
||||||
|
|
||||||
|
entries[entry.sceneID] = entry;
|
||||||
|
tableData.nextRow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Queries the table with a sceneID to find.
|
||||||
|
const CDSceneTable* Query(uint32_t sceneID) {
|
||||||
|
const auto& iter = entries.find(sceneID);
|
||||||
|
if (iter != entries.end()) {
|
||||||
|
return &iter->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Custom Classes
|
||||||
|
#include "CDTable.h"
|
||||||
|
|
||||||
|
struct CDSceneTable {
|
||||||
|
uint32_t sceneID; //!< The scene's ID, as zone files before version 30 list their scenes
|
||||||
|
std::string sceneName; //!< The scene's file
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace CDSceneTableTable {
|
||||||
|
using Table = std::map<uint32_t, CDSceneTable>;
|
||||||
|
void LoadValuesFromDatabase();
|
||||||
|
|
||||||
|
// Queries the table with a sceneID to find.
|
||||||
|
const CDSceneTable* Query(uint32_t sceneID);
|
||||||
|
};
|
||||||
@@ -39,6 +39,7 @@ set(DDATABASE_CDCLIENTDATABASE_CDCLIENTTABLES_SOURCES "CDActivitiesTable.cpp"
|
|||||||
"CDRebuildComponentTable.cpp"
|
"CDRebuildComponentTable.cpp"
|
||||||
"CDRewardCodesTable.cpp"
|
"CDRewardCodesTable.cpp"
|
||||||
"CDRewardsTable.cpp"
|
"CDRewardsTable.cpp"
|
||||||
|
"CDSceneTableTable.cpp"
|
||||||
"CDScriptComponentTable.cpp"
|
"CDScriptComponentTable.cpp"
|
||||||
"CDSkillBehaviorTable.cpp"
|
"CDSkillBehaviorTable.cpp"
|
||||||
"CDTamingBuildPuzzleTable.cpp"
|
"CDTamingBuildPuzzleTable.cpp"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
#include "CDClientManager.h"
|
#include "CDClientManager.h"
|
||||||
|
#include "CDSceneTableTable.h"
|
||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
#include "CDClientDatabase.h"
|
#include "CDClientDatabase.h"
|
||||||
#include "Spawner.h"
|
#include "Spawner.h"
|
||||||
@@ -32,13 +33,6 @@ Zone::Zone(const LWOZONEID zoneID) :
|
|||||||
m_CheckSum = 0;
|
m_CheckSum = 0;
|
||||||
m_WorldID = 0;
|
m_WorldID = 0;
|
||||||
m_SceneCount = 0;
|
m_SceneCount = 0;
|
||||||
m_SceneTableLookup = [](uint32_t sceneTableID) -> std::optional<std::string> {
|
|
||||||
auto query = CDClientDatabase::CreatePreppedStmt("SELECT sceneName FROM SceneTable WHERE sceneID = ?;");
|
|
||||||
query.bind(1, static_cast<int32_t>(sceneTableID));
|
|
||||||
auto result = query.execQuery();
|
|
||||||
if (result.eof() || result.fieldIsNull("sceneName")) return std::nullopt;
|
|
||||||
return std::string(result.getStringField("sceneName"));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone::~Zone() {
|
Zone::~Zone() {
|
||||||
@@ -70,7 +64,11 @@ void Zone::LoadZoneIntoMemory() {
|
|||||||
ZoneFile zoneFile;
|
ZoneFile zoneFile;
|
||||||
zoneFile.Read(file);
|
zoneFile.Read(file);
|
||||||
// The oldest files name their scenes by SceneTable ID
|
// The oldest files name their scenes by SceneTable ID
|
||||||
zoneFile.ResolveSceneTable(m_SceneTableLookup);
|
zoneFile.ResolveSceneTable([](uint32_t sceneTableID) -> std::optional<std::string> {
|
||||||
|
const auto* sceneTableEntry = CDSceneTableTable::Query(sceneTableID);
|
||||||
|
if (!sceneTableEntry) return std::nullopt;
|
||||||
|
return sceneTableEntry->sceneName;
|
||||||
|
});
|
||||||
m_FileFormatVersion = zoneFile.fileFormatVersion;
|
m_FileFormatVersion = zoneFile.fileFormatVersion;
|
||||||
m_WorldID = zoneFile.worldID;
|
m_WorldID = zoneFile.worldID;
|
||||||
if (static_cast<LWOMAPID>(m_WorldID) != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID());
|
if (static_cast<LWOMAPID>(m_WorldID) != m_ZoneID.GetMapID()) LOG("WorldID: %i doesn't match MapID %i! Is this intended?", m_WorldID, m_ZoneID.GetMapID());
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
#include "ZoneScenes.h"
|
#include "ZoneScenes.h"
|
||||||
#include "tinyxml2.h"
|
#include "tinyxml2.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
|
||||||
#include <optional>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "Raw.h"
|
#include "Raw.h"
|
||||||
@@ -43,10 +41,6 @@ public:
|
|||||||
const uint32_t GetChecksum() const { return m_CheckSum; }
|
const uint32_t GetChecksum() const { return m_CheckSum; }
|
||||||
LUTriggers::Trigger* GetTrigger(uint32_t sceneID, uint32_t triggerID) const;
|
LUTriggers::Trigger* GetTrigger(uint32_t sceneID, uint32_t triggerID) const;
|
||||||
const Path* GetPath(std::string name) const;
|
const Path* GetPath(std::string name) const;
|
||||||
|
|
||||||
// The CDClient SceneTable's sceneName for a scene of a file from before PrePreAlpha; the database's by default
|
|
||||||
using SceneTableLookup = std::function<std::optional<std::string>(uint32_t sceneTableID)>;
|
|
||||||
void SetSceneTableLookup(SceneTableLookup lookup) { m_SceneTableLookup = std::move(lookup); }
|
|
||||||
const std::vector<Path>& GetPaths() const { return m_Paths; }
|
const std::vector<Path>& GetPaths() const { return m_Paths; }
|
||||||
// A path that isn't in the zone's files (tests); earlier GetPath pointers may move
|
// A path that isn't in the zone's files (tests); earlier GetPath pointers may move
|
||||||
void AddPath(Path path) { m_Paths.push_back(std::move(path)); }
|
void AddPath(Path path) { m_Paths.push_back(std::move(path)); }
|
||||||
@@ -103,7 +97,6 @@ private:
|
|||||||
std::vector<Path> m_Paths;
|
std::vector<Path> m_Paths;
|
||||||
|
|
||||||
std::map<LWOSCENEID, uint32_t> m_MapRevisions; //rhs is the revision!
|
std::map<LWOSCENEID, uint32_t> m_MapRevisions; //rhs is the revision!
|
||||||
SceneTableLookup m_SceneTableLookup;
|
|
||||||
//private ("helper") functions:
|
//private ("helper") functions:
|
||||||
void LoadScene(ZoneScene&& zoneScene);
|
void LoadScene(ZoneScene&& zoneScene);
|
||||||
void LoadLUTriggers(std::string triggerFile, SceneRef& scene);
|
void LoadLUTriggers(std::string triggerFile, SceneRef& scene);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
|
#include "CDSceneTableTable.h"
|
||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
#include "Zone.h"
|
#include "Zone.h"
|
||||||
#include "dZoneManager.h"
|
#include "dZoneManager.h"
|
||||||
@@ -14,6 +15,11 @@ namespace CDZoneTableTable {
|
|||||||
extern Table entries;
|
extern Table entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The scene table's storage (CDSceneTableTable.cpp), to add the scenes of the oldest zone files
|
||||||
|
namespace CDSceneTableTable {
|
||||||
|
extern Table entries;
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Write(std::ostream& stream, const T& value) {
|
void Write(std::ostream& stream, const T& value) {
|
||||||
@@ -93,11 +99,10 @@ protected:
|
|||||||
TearDownDependencies();
|
TearDownDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
Zone* LoadZone(const std::string& data, Zone::SceneTableLookup lookup = nullptr) const {
|
Zone* LoadZone(const std::string& data) const {
|
||||||
std::ofstream(root / "res" / "maps" / "testzone" / "test.luz", std::ios::binary).write(data.data(), data.size());
|
std::ofstream(root / "res" / "maps" / "testzone" / "test.luz", std::ios::binary).write(data.data(), data.size());
|
||||||
Game::zoneManager->LoadZone(LWOZONEID(TEST_MAP, 0, 0));
|
Game::zoneManager->LoadZone(LWOZONEID(TEST_MAP, 0, 0));
|
||||||
Zone* zone = Game::zoneManager->GetZoneMut();
|
Zone* zone = Game::zoneManager->GetZoneMut();
|
||||||
if (lookup) zone->SetSceneTableLookup(std::move(lookup));
|
|
||||||
zone->LoadZoneIntoMemory();
|
zone->LoadZoneIntoMemory();
|
||||||
return zone;
|
return zone;
|
||||||
}
|
}
|
||||||
@@ -144,11 +149,9 @@ TEST_F(ZoneFileVersionTest, OldestScenesComeFromTheSceneTable) {
|
|||||||
Write<uint8_t>(stream, 0); // boundary lines
|
Write<uint8_t>(stream, 0); // boundary lines
|
||||||
WriteString8(stream, "test.raw");
|
WriteString8(stream, "test.raw");
|
||||||
Write<uint16_t>(stream, 0); // trailing bytes: older readers read a name and description here
|
Write<uint16_t>(stream, 0); // trailing bytes: older readers read a name and description here
|
||||||
const Zone* zone = LoadZone(stream.str(), [](uint32_t sceneTableID) -> std::optional<std::string> {
|
CDSceneTableTable::entries = { { 3, { 3, "three.lvl" } }, { 7, { 7, "seven.lvl" } } };
|
||||||
if (sceneTableID == 3) return "three.lvl";
|
const Zone* zone = LoadZone(stream.str());
|
||||||
if (sceneTableID == 7) return "seven.lvl";
|
CDSceneTableTable::entries.clear();
|
||||||
return std::nullopt;
|
|
||||||
});
|
|
||||||
|
|
||||||
const std::vector<std::pair<LWOSCENEID, std::string>> expected = { { LWOSCENEID(0, 0), "three.lvl" }, { LWOSCENEID(1, 0), "seven.lvl" } };
|
const std::vector<std::pair<LWOSCENEID, std::string>> expected = { { LWOSCENEID(0, 0), "three.lvl" }, { LWOSCENEID(1, 0), "seven.lvl" } };
|
||||||
EXPECT_EQ(Scenes(zone), expected) << version;
|
EXPECT_EQ(Scenes(zone), expected) << version;
|
||||||
|
|||||||
Reference in New Issue
Block a user