mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-28 15:37:14 +00:00
* feat: raw terrain parsing for scene data Replace old dNavigation/dTerrain raw parser with new Raw module in dZoneManager. Parse heightmaps, color maps, and scene maps from .raw files to determine which scene a position belongs to. Build scene adjacency graph from terrain data and scene transitions. Adds NiColor type, SceneColor lookup table, eSceneType enum, terrain mesh generation with OBJ export, and debug slash commands for scene visualization. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor: deduplicate terrain grid lookup logic, remove unnecessary cast Add IsValidForSceneLookup(), GetSceneIDAtGrid(), and GridToWorldPos() to Raw::Chunk. Use them in GenerateTerrainMesh, GetSceneIDFromPosition, SpawnScenePoints, and SpawnAllScenePoints instead of duplicated inline math. Remove unnecessary static_cast in LoadSceneTransitionInfo. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: add version < 32 support to raw terrain parser The parser was only correct for v32 files. For v<32: - colorMapResolution is width-1, not width - Color map reads width*width*4 bytes (BGRA per-pixel), not colorMapRes^2*4 - No DDS lightmap - No texture settings byte or blend DDS - Scene map: v31 reads (colorMapRes+1)^2 cells with border skip, v<31 skips 1 byte - No mesh data Verified against all 309 .raw files across multiple client versions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: log and reject legacy raw terrain format, clean up ReadRaw API Log a clear message and throw if the zone uses a legacy raw format (LUZ version < 30) since no known maps use it. Remove ReadLegacyRaw and the mapVersion parameter from ReadRaw. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: revert v33 scene field renames to unknown1/unknown2 These fields are skipped by the client in every known build (ptr += 12 and ptr += 4). No client ever reads them into a struct. Keep the original unknown1/unknown2 names from main. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: load the zone without scene lookups when its raw terrain is missing or unreadable Log at debug when it parses; build the terrain mesh only for the OBJ export; read the zone name and description only for version 31 and later, as the client does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: look up the scene at a position as the client does, in constant time Chunk bounds span (width - 1) * scale; the nearest scene map cell is used and the far edge is kept one cell inside. Chunks are indexed by grid cell when they form a grid. Skipping reads instead of seeking, so a cut-off file can't seek past the end. Terrain mesh indices follow the vertex order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: scene point commands take a step and use brick LOTs from the BrickIDTable Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: rename NiColor::ToXYZ to Luminance Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: raw terrain reading, scene lookup, scene graph and scene commands Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: close the OBJ file before removing it so the test passes on Windows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the zone boundary lines and read the luz scene count as the client does Each boundary line's destination is read as a map ID and an instance ID into a LWOZONEID. The scene count is a byte before version 37 and a u32 from it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: name the fourth flair colour byte padding The client never sets or reads it, so it holds leftover memory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the scene map of version 31 and older raws These files have a (resolution + 1)^2 scene map, kept in sceneMapLegacy. Version 31 uses its first resolution rows and columns; older versions are all scene 0, as in the client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor: simplify the raw heightmap size check The dimensions are capped at kMaxResolution, so the product can't overflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: remove the scene point spawn commands and send /getadjacentscenes as one message The spawn commands were only for testing. /getscene and /getadjacentscenes stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
113 lines
3.7 KiB
C++
113 lines
3.7 KiB
C++
#pragma once
|
|
#include "dZMCommon.h"
|
|
#include "WorldConfig.h"
|
|
#include "Zone.h"
|
|
#include "Spawner.h"
|
|
#include <map>
|
|
|
|
class dZoneManager {
|
|
public:
|
|
enum class dZoneNotifier {
|
|
SpawnedObjectDestroyed,
|
|
SpawnedChildObjectDestroyed, //Used for when an object (like a stromling) needs to notify the spawner to respawn a new enemy.
|
|
ReloadZone, //Forces the server and all connects clients to reload the map
|
|
UserJoined,
|
|
UserMoved,
|
|
InvalidNotifier
|
|
};
|
|
|
|
private:
|
|
/**
|
|
* Reads the WorldConfig from the CDClientDatabase into memory
|
|
*/
|
|
void LoadWorldConfig();
|
|
|
|
public:
|
|
void Initialize(const LWOZONEID& zoneID);
|
|
~dZoneManager();
|
|
|
|
/* Gets a pointer to the currently loaded zone. */
|
|
Zone* GetZoneMut() const;
|
|
const Zone* GetZone() const { return GetZoneMut(); };
|
|
bool HasZone() const { return m_pZone != nullptr; };
|
|
void LoadZone(const LWOZONEID& zoneID); //Discard the current zone (if any) and loads a new zone.
|
|
|
|
/* Adds a spawner to the zone with the specified ID. */
|
|
void AddSpawner(LWOOBJID id, Spawner* spawner);
|
|
const LWOZONEID& GetZoneID() const;
|
|
|
|
/* Creates a new spawner. Returns the finalized ID for the created spawner since some bits may be set to get it to function. */
|
|
LWOOBJID MakeSpawner(SpawnerInfo info);
|
|
Spawner* GetSpawner(LWOOBJID id);
|
|
void RemoveSpawner(LWOOBJID id);
|
|
std::vector<Spawner*> GetSpawnersByName(const std::string& spawnerName);
|
|
std::vector<Spawner*> GetSpawnersInGroup(const std::string& group);
|
|
void Update(float deltaTime);
|
|
Entity* GetZoneControlObject() { return m_ZoneControlObject; }
|
|
bool GetPlayerLoseCoinOnDeath() { return m_PlayerLoseCoinsOnDeath; }
|
|
bool GetDisableSaveLocation() { return m_DisableSaveLocation; }
|
|
bool GetMountsAllowed() { return m_MountsAllowed; }
|
|
bool GetPetsAllowed() { return m_PetsAllowed; }
|
|
|
|
/* Gets the starting ID for missions in the player UI so they are ordered properly and show in the order accepted by the player. */
|
|
uint32_t GetUniqueMissionIdStartingValue();
|
|
bool CheckIfAccessibleZone(LWOMAPID zoneID);
|
|
|
|
/**
|
|
* @brief Get the scene ID at a given position. Scenes do not care about height (Y coordinate).
|
|
*
|
|
* @param position The position to query
|
|
* @return The scene ID at that position, or LWOSCENEID_INVALID if not found
|
|
*/
|
|
LWOSCENEID GetSceneIDFromPosition(const NiPoint3& position) const;
|
|
|
|
/**
|
|
* @brief Get the adjacency list for the scene graph.
|
|
* The adjacency list maps each scene ID to a list of scene IDs it can transition to.
|
|
*
|
|
* @return A reference to the scene adjacency list
|
|
*/
|
|
const std::map<LWOSCENEID, std::vector<LWOSCENEID>>& GetSceneAdjacencyList() const { return m_SceneAdjacencyList; }
|
|
|
|
/**
|
|
* @brief Get all scenes adjacent to (connected to) a given scene.
|
|
*
|
|
* @param sceneID The scene ID to query
|
|
* @return A vector of scene IDs that are directly connected to this scene, or empty vector if scene not found
|
|
*/
|
|
std::vector<LWOSCENEID> GetAdjacentScenes(LWOSCENEID sceneID) const;
|
|
|
|
/**
|
|
* @brief (Re)builds the scene graph adjacency list from the loaded zone's scene transitions.
|
|
*/
|
|
void BuildSceneGraph();
|
|
|
|
// The world config should not be modified by a caller.
|
|
const WorldConfig& GetWorldConfig() {
|
|
if (!m_WorldConfig) LoadWorldConfig();
|
|
return m_WorldConfig.value();
|
|
};
|
|
|
|
private:
|
|
/**
|
|
* The starting unique mission ID.
|
|
*/
|
|
uint32_t m_UniqueMissionIdStart = 0;
|
|
|
|
Zone* m_pZone = nullptr;
|
|
LWOZONEID m_ZoneID;
|
|
bool m_PlayerLoseCoinsOnDeath = false;
|
|
bool m_DisableSaveLocation = false;
|
|
bool m_MountsAllowed = true;
|
|
bool m_PetsAllowed = true;
|
|
std::map<LWOOBJID, Spawner*> m_Spawners;
|
|
std::optional<WorldConfig> m_WorldConfig = std::nullopt;
|
|
|
|
Entity* m_ZoneControlObject = nullptr;
|
|
|
|
/**
|
|
* Scene graph adjacency list: maps each scene ID to a list of scenes it can transition to
|
|
*/
|
|
std::map<LWOSCENEID, std::vector<LWOSCENEID>> m_SceneAdjacencyList;
|
|
};
|