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:
@@ -11,8 +11,8 @@
|
||||
#include "dConfig.h"
|
||||
|
||||
#include "AssetManager.h"
|
||||
#include "CDClientDatabase.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDSceneTableTable.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
#include "Spawner.h"
|
||||
#include "dZoneManager.h"
|
||||
@@ -31,13 +31,6 @@ Zone::Zone(const LWOZONEID zoneID) :
|
||||
m_CheckSum = 0;
|
||||
m_WorldID = 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() {
|
||||
@@ -332,11 +325,11 @@ void Zone::KeepLoadedScenes() {
|
||||
std::map<LWOSCENEID, SceneRef> resolved;
|
||||
uint32_t index = 0;
|
||||
for (auto& scene : m_Scenes | std::views::values) {
|
||||
const auto sceneName = m_SceneTableLookup(scene.sceneTableID);
|
||||
if (!sceneName) continue;
|
||||
const auto* sceneTableEntry = CDSceneTableTable::Query(scene.sceneTableID);
|
||||
if (!sceneTableEntry) continue;
|
||||
scene.id = index < 256 ? index : UINT32_MAX;
|
||||
scene.filename = *sceneName;
|
||||
scene.name = *sceneName;
|
||||
scene.filename = sceneTableEntry->sceneName;
|
||||
scene.name = sceneTableEntry->sceneName;
|
||||
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);
|
||||
resolved[LWOSCENEID(scene.id, 0)] = std::move(scene);
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include "Raw.h"
|
||||
|
||||
namespace LUTriggers {
|
||||
@@ -235,10 +233,6 @@ public:
|
||||
LUTriggers::Trigger* GetTrigger(uint32_t sceneID, uint32_t triggerID) 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; }
|
||||
[[nodiscard]] std::string GetZoneName() const { return m_ZoneName; }
|
||||
std::string GetZoneRawPath() const { return m_ZoneRawPath; }
|
||||
@@ -284,7 +278,6 @@ private:
|
||||
|
||||
std::map<LWOSCENEID, uint32_t> m_MapRevisions; //rhs is the revision!
|
||||
//private ("helper") functions:
|
||||
SceneTableLookup m_SceneTableLookup;
|
||||
void LoadScene(std::istream& file, uint32_t index);
|
||||
void KeepLoadedScenes();
|
||||
void LoadLUTriggers(std::string triggerFile, SceneRef& scene);
|
||||
|
||||
Reference in New Issue
Block a user