feat(map): add CMap::LoadWdt

This commit is contained in:
VDm 2025-07-30 02:07:07 +04:00
parent 15608f11e7
commit c4e56fd99d
7 changed files with 162 additions and 3 deletions

View File

@ -51,7 +51,7 @@ int32_t LoginVerifyWorldHandler(void* param, NETMESSAGE msgId, uint32_t time, CD
float facing;
msg->Get(facing);
if (false /* zoneID != ClntObjMgrGetMapID() */) {
if (true /* zoneID != ClntObjMgrGetMapID() */) {
s_newFacing = facing;
s_newPosition = position;
s_newZoneID = zoneID;

View File

@ -8,9 +8,13 @@
#include "world/daynight/DayNight.hpp"
#include "gameui/camera/CGCamera.hpp"
#include "gameui/CGWorldFrame.hpp"
#include "util/SFile.hpp"
uint32_t CWorld::s_enables;
uint32_t CWorld::s_enables2;
float CWorld::s_farClip;
float CWorld::s_nearClip;
float CWorld::prevFarClip;
void CWorld::Initialize() {
CWorld::s_enables |=
@ -50,6 +54,18 @@ void CWorld::Initialize() {
}
void CWorld::LoadMap(const char* mapName, const C3Vector& position, int32_t zoneID) {
// TODO: calculate far clip
CWorld::s_farClip = 1583.3334f;
CWorld::s_nearClip = 0.2f;
CWorld::prevFarClip = CWorld::s_farClip;
if (SFile::IsTrial()) {
// TODO: sub_420AA0(zoneID);
}
// TODO: CWorld::PrepareAreaOfInterest(position);
// TODO
CMap::Load(mapName, zoneID);
}

View File

@ -45,6 +45,9 @@ class CWorld {
// Static variables
static uint32_t s_enables;
static uint32_t s_enables2;
static float s_farClip;
static float s_nearClip;
static float prevFarClip;
// Static functions
static void Initialize(void);

View File

@ -59,6 +59,7 @@ void LoadMap(int32_t zoneID) {
// TODO
g_sky.GenSphere(1.0f);
g_stars.Initialize();
g_dnInfo.showSky = 1;
}
void SetColors() {
@ -78,7 +79,9 @@ void Update() {
}
void RenderSky() {
// TODO
if (!g_dnInfo.showSky) {
return;
}
float minX;
float maxX;
@ -97,6 +100,9 @@ void RenderSky() {
g_stars.Render();
g_sky.Render();
GxRsSet(GxRs_ScissorTest, 0);
GxXformSetViewport(minX, maxX, minY, maxY, minZ, maxZ);
}
DNInfo* GetInfo() {

View File

@ -1,7 +1,91 @@
#include "world/map/CMap.hpp"
#include "world/daynight/DayNight.hpp"
#include "util/SFile.hpp"
#include <storm/Error.hpp>
char CMap::mapPath[STORM_MAX_PATH];
char CMap::mapName[STORM_MAX_PATH];
char CMap::wdtFilename[STORM_MAX_PATH];
uint32_t CMap::version;
SMMapHeader CMap::header;
SMAreaInfo CMap::areaInfo[64 * 64];
uint32_t CMap::uniqueId;
int32_t CMap::bDungeon;
void CMap::Load(const char* mapName, int32_t zoneID) {
// TODO
auto length = SStrCopy(CMap::mapPath, "World\\Maps\\", STORM_MAX_STR);
SStrCopy(&CMap::mapPath[length], mapName, STORM_MAX_STR);
SStrCopy(CMap::mapName, mapName, STORM_MAX_STR);
SStrPrintf(CMap::wdtFilename, 0x100u, "%s\\%s.wdt", CMap::mapPath, CMap::mapName);
// TODO: create sunLight
// TODO
CMap::LoadWdt();
CMap::LoadTextureBlob();
DayNight::LoadMap(zoneID);
// TODO
}
void CMap::LoadWdt() {
SFile* file = nullptr;
if (!SFile::Open(CMap::wdtFilename, &file) || !file) {
SErrDisplayAppFatal("CMap::LoadWdt() failed %s\n", CMap::wdtFilename);
}
SIffChunk iffChunk = {};
SFile::Read(file, &iffChunk, sizeof(iffChunk), nullptr, nullptr, nullptr);
STORM_ASSERT(iffChunk.token == 'MVER' && iffChunk.size == sizeof(CMap::version));
SFile::Read(file, &CMap::version, sizeof(CMap::version), nullptr, nullptr, nullptr);
SFile::Read(file, &iffChunk, sizeof(iffChunk), nullptr, nullptr, nullptr);
STORM_ASSERT(iffChunk.token == 'MPHD' && iffChunk.size == sizeof(CMap::header));
SFile::Read(file, &CMap::header, sizeof(CMap::header), nullptr, nullptr, nullptr);
SFile::Read(file, &iffChunk, sizeof(iffChunk), nullptr, nullptr, nullptr);
STORM_ASSERT(iffChunk.token == 'MAIN' && iffChunk.size == sizeof(CMap::areaInfo));
SFile::Read(file, &CMap::areaInfo, sizeof(CMap::areaInfo), nullptr, nullptr, nullptr);
// wdt_uses_global_map_obj
if (CMap::header.flags & 1) {
char globalWmoName[256];
SFile::Read(file, &iffChunk, sizeof(iffChunk), nullptr, nullptr, nullptr);
STORM_ASSERT(iffChunk.token == 'MWMO' && iffChunk.size <= 256);
SFile::Read(file, globalWmoName, iffChunk.size, nullptr, nullptr, nullptr);
SFile::Read(file, &iffChunk, sizeof(iffChunk), nullptr, nullptr, nullptr);
if (iffChunk.token == 'MODF') {
SMMapObjDef globalMapObjDef = {};
SFile::Read(file, &globalMapObjDef, sizeof(globalMapObjDef), nullptr, nullptr, nullptr);
globalMapObjDef.uniqueId = CMap::uniqueId--;
// TODO
}
CMap::bDungeon = 1;
}
if (CMap::header.flags & 2) {
// TODO: sub_7B7330(2);
} else {
// TODO: sub_7B7330(1);
}
// sub_7BD8A0();
SFile::Close(file);
}
void CMap::LoadTextureBlob() {
char path[STORM_MAX_PATH];
SStrCopy(path, CMap::wdtFilename, STORM_MAX_STR);
char* suffix = SStrChrR(path, '.');
SStrCopy(suffix, ".tex", STORM_MAX_STR);
// TODO: TextureLoadBlob(path);
}

View File

@ -1,11 +1,24 @@
#ifndef WORLD_C_MAP_HPP
#define WORLD_C_MAP_HPP
#include <cstdint>
#include "world/map/Types.hpp"
#include <storm/String.hpp>
class CMap {
public:
static char mapPath[STORM_MAX_PATH];
static char mapName[STORM_MAX_PATH];
static char wdtFilename[STORM_MAX_PATH];
static uint32_t version;
static SMMapHeader header;
static SMAreaInfo areaInfo[64 * 64];
static uint32_t uniqueId;
static int32_t bDungeon;
static void Load(const char* mapName, int32_t zoneID);
static void LoadWdt();
static void LoadTextureBlob();
};
#endif

37
src/world/map/Types.hpp Normal file
View File

@ -0,0 +1,37 @@
#ifndef WORLD_MAP_TYPES_HPP
#define WORLD_MAP_TYPES_HPP
#include <cstdint>
#include <tempest/Vector.hpp>
#include <tempest/Box.hpp>
struct SIffChunk {
uint32_t token;
uint32_t size;
};
struct SMMapHeader {
uint32_t flags;
uint32_t something;
uint32_t unused[6];
};
struct SMAreaInfo {
uint32_t flags;
uint32_t unused;
};
struct SMMapObjDef {
uint32_t nameId;
uint32_t uniqueId;
C3Vector pos;
C3Vector rot;
CAaBox extents;
uint16_t flags;
uint16_t doodadSet;
uint16_t nameSet;
uint16_t pad;
};
#endif