mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-06 11:57:13 +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:
@@ -24,6 +24,7 @@
|
|||||||
#include "CDRebuildComponentTable.h"
|
#include "CDRebuildComponentTable.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"
|
||||||
@@ -144,6 +145,7 @@ void CDClientManager::LoadValuesFromDatabase() {
|
|||||||
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);
|
||||||
|
};
|
||||||
@@ -35,6 +35,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"
|
||||||
|
|||||||
@@ -11,8 +11,8 @@
|
|||||||
#include "dConfig.h"
|
#include "dConfig.h"
|
||||||
|
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
#include "CDClientDatabase.h"
|
|
||||||
#include "CDClientManager.h"
|
#include "CDClientManager.h"
|
||||||
|
#include "CDSceneTableTable.h"
|
||||||
#include "CDZoneTableTable.h"
|
#include "CDZoneTableTable.h"
|
||||||
#include "Spawner.h"
|
#include "Spawner.h"
|
||||||
#include "dZoneManager.h"
|
#include "dZoneManager.h"
|
||||||
@@ -31,13 +31,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() {
|
||||||
@@ -332,11 +325,11 @@ void Zone::KeepLoadedScenes() {
|
|||||||
std::map<LWOSCENEID, SceneRef> resolved;
|
std::map<LWOSCENEID, SceneRef> resolved;
|
||||||
uint32_t index = 0;
|
uint32_t index = 0;
|
||||||
for (auto& scene : m_Scenes | std::views::values) {
|
for (auto& scene : m_Scenes | std::views::values) {
|
||||||
const auto sceneName = m_SceneTableLookup(scene.sceneTableID);
|
const auto* sceneTableEntry = CDSceneTableTable::Query(scene.sceneTableID);
|
||||||
if (!sceneName) continue;
|
if (!sceneTableEntry) continue;
|
||||||
scene.id = index < 256 ? index : UINT32_MAX;
|
scene.id = index < 256 ? index : UINT32_MAX;
|
||||||
scene.filename = *sceneName;
|
scene.filename = sceneTableEntry->sceneName;
|
||||||
scene.name = *sceneName;
|
scene.name = sceneTableEntry->sceneName;
|
||||||
const std::string luTriggersPath = scene.filename.substr(0, scene.filename.size() - 4) + ".lutriggers";
|
const std::string luTriggersPath = scene.filename.substr(0, scene.filename.size() - 4) + ".lutriggers";
|
||||||
if (Game::assetManager->HasFile((m_ZonePath + luTriggersPath).c_str())) LoadLUTriggers(luTriggersPath, scene);
|
if (Game::assetManager->HasFile((m_ZonePath + luTriggersPath).c_str())) LoadLUTriggers(luTriggersPath, scene);
|
||||||
resolved[LWOSCENEID(scene.id, 0)] = std::move(scene);
|
resolved[LWOSCENEID(scene.id, 0)] = std::move(scene);
|
||||||
|
|||||||
@@ -7,8 +7,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <functional>
|
|
||||||
#include <optional>
|
|
||||||
#include "Raw.h"
|
#include "Raw.h"
|
||||||
|
|
||||||
namespace LUTriggers {
|
namespace LUTriggers {
|
||||||
@@ -235,10 +233,6 @@ public:
|
|||||||
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); }
|
|
||||||
|
|
||||||
uint32_t GetWorldID() const { return m_WorldID; }
|
uint32_t GetWorldID() const { return m_WorldID; }
|
||||||
[[nodiscard]] std::string GetZoneName() const { return m_ZoneName; }
|
[[nodiscard]] std::string GetZoneName() const { return m_ZoneName; }
|
||||||
std::string GetZoneRawPath() const { return m_ZoneRawPath; }
|
std::string GetZoneRawPath() const { return m_ZoneRawPath; }
|
||||||
@@ -284,7 +278,6 @@ private:
|
|||||||
|
|
||||||
std::map<LWOSCENEID, uint32_t> m_MapRevisions; //rhs is the revision!
|
std::map<LWOSCENEID, uint32_t> m_MapRevisions; //rhs is the revision!
|
||||||
//private ("helper") functions:
|
//private ("helper") functions:
|
||||||
SceneTableLookup m_SceneTableLookup;
|
|
||||||
void LoadScene(std::istream& file, uint32_t index);
|
void LoadScene(std::istream& file, uint32_t index);
|
||||||
void KeepLoadedScenes();
|
void KeepLoadedScenes();
|
||||||
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