Files
wowdecomp/WoW/Source/WorldClient/MapLowDetail.cpp
T
SatyandClaude Opus 5.5 f6d07ea346 World port: liquids, map load chain, terrain rendering in MapViewer
Liquid system ported from 12340 (LiquidSystem module, chunk/WMO liquid, wave
manager, geometry factories); CMap load chain (Load, LoadWdt, low-detail WDL,
lights, CreateMapObjDef, PurgeMaps); CMapChunk create/batch/vertex/index code;
CMapRenderChunk; frustum stack and scene cull helpers. MapViewer renders
terrain through a viewer-only shortcut (ViewerWorld.cpp). Engine fix: int
render-state setters write the full pointer-sized slot (x64 texture crash).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-09-28 08:07:38 +02:00

174 lines
6.0 KiB
C++

#include "MapLowDetail.h"
#include <cmath>
#include "Engine/Source/BlizzardCore/SFile2-Core.h"
#include "Engine/Source/Storm/H/storm.h"
#include "WoW/Source/WorldClient/FVBBList.h"
#include "WoW/Source/WorldClient/Map.h"
#include "WoW/Source/WorldClient/MapArea.h"
#include "WoW/Source/WorldClient/MapObj.h"
#include "WoW/Source/WorldClient/MapObjDef.h"
// VERIFY: pending
// VERIFY: a9a4e286 manual
// OFFSET: 0x007C06E0
CMapAreaLow::CMapAreaLow() {
this->m_index.x = 0;
this->m_index.y = 0;
this->unk_004C = 0;
this->unk_0050 = 0;
this->m_indexCount = 0;
this->m_block = nullptr;
this->unk_0058 = 0;
this->m_heights = nullptr;
this->m_holes = nullptr;
}
// OFFSET: 0x007CBFE0
void CMapLowDetail::Purge() {
for (uint32_t i = 0; i < 4096; i++) {
CMapAreaLow* areaLow = this->m_areas[i];
if (areaLow) {
if (areaLow->m_block) {
CMap::s_vbbList.Release(areaLow->m_block);
}
this->m_areas[i]->m_block = nullptr;
}
}
}
// VERIFY: pending
// VERIFY: ba76c774 manual
// OFFSET: 0x007CC310
void CMapLowDetail::Load(const char* mapPath, const char* mapName) {
char fileName[256];
SFileImpl* file;
SStrPrintf(fileName, sizeof(fileName), "%s\\%s.wdl", mapPath, mapName);
SFileOpenFile(fileName, &file);
if (!file) {
return;
}
uint32_t size = SFileGetFileSize(file, nullptr);
this->m_data = static_cast<char*>(SMemAlloc(size, __FILE__, __LINE__, 0));
SFileReadFile(file, this->m_data, size, nullptr, nullptr, 0);
SFileCloseFile(file);
uint32_t* chunk = reinterpret_cast<uint32_t*>(this->m_data + reinterpret_cast<uint32_t*>(this->m_data)[1] + 8);
char* data = this->m_data + reinterpret_cast<uint32_t*>(this->m_data)[1] + 16;
if (chunk[0] == 0x4D574D4F) {
this->m_mapObjNames = data;
uint32_t* mwid = reinterpret_cast<uint32_t*>(data + chunk[1]);
this->m_mapObjNameOffsets = mwid + 2;
uint32_t* modf = reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(mwid) + mwid[1] + 8);
this->m_mapObjDefs = reinterpret_cast<SMMapObjDef*>(modf + 2);
this->m_mapObjDefCount = modf[1] >> 6;
data = reinterpret_cast<char*>(modf + 2) + modf[1] + 8;
}
this->m_areaOffsets = reinterpret_cast<uint32_t*>(data);
uint32_t index = 0;
for (uint32_t y = 0; y < 1024; y += 16) {
for (uint32_t x = 0; x < 1024; x += 16) {
if (this->m_areaOffsets[index]) {
char* mare = this->m_data + this->m_areaOffsets[index];
CMapAreaLow* area = CMap::AllocAreaLow();
this->m_areas[index] = area;
area->m_heights = reinterpret_cast<int16_t*>(mare + 8);
uint32_t* next = reinterpret_cast<uint32_t*>(mare + reinterpret_cast<uint32_t*>(mare)[1] + 8);
int32_t minHeight = 100000;
int32_t maxHeight = -100000;
for (uint32_t i = 0; i < 545; i++) {
int32_t height = area->m_heights[i];
if (height > maxHeight) {
maxHeight = height;
}
if (height < minHeight) {
minHeight = height;
}
}
area->m_index.x = x >> 4;
area->m_index.y = y >> 4;
float top = 17066.666f - static_cast<float>(y) * 33.333332f;
area->m_topLeft.x = top;
area->m_bbox.t.x = top;
float left = static_cast<float>(x) * -33.333332f + 17066.666f;
area->m_topLeft.y = left;
area->m_bbox.t.y = left;
area->m_bbox.t.z = static_cast<float>(maxHeight);
area->m_bbox.b.x = top - 533.33331f;
area->m_bbox.b.y = left - 533.33331f;
area->m_bbox.b.z = static_cast<float>(minHeight);
area->m_sphere.c.x = (area->m_bbox.t.x + area->m_bbox.b.x) * 0.5f;
area->m_sphere.c.y = (area->m_bbox.b.y + area->m_bbox.t.y) * 0.5f;
area->m_sphere.c.z = 0.5f * (area->m_bbox.b.z + area->m_bbox.t.z);
float dz = area->m_bbox.t.z - area->m_sphere.c.z;
float dy = area->m_bbox.t.y - area->m_sphere.c.y;
float dx = area->m_bbox.t.x - area->m_sphere.c.x;
area->m_sphere.r = sqrtf(dx * dx + dy * dy + dz * dz);
if (next[0] == 0x4D41484F) {
uint16_t* holes = reinterpret_cast<uint16_t*>(next + 2);
area->m_holes = holes;
area->m_indexCount = 0;
for (uint32_t row = 0; row < 16; row++) {
for (uint32_t bit = 0; bit < 16; bit++) {
if (!((1 << bit) & holes[row])) {
area->m_indexCount += 12;
}
}
}
} else {
area->m_holes = nullptr;
area->m_indexCount = 3072;
}
}
index++;
}
}
C3Vector center(17066.666f, 17066.666f, 0.0f);
this->m_mapObjDefList.SetCount(this->m_mapObjDefCount);
for (uint32_t i = 0; i < this->m_mapObjDefCount; i++) {
SMMapObjDef* def = &this->m_mapObjDefs[i];
CMapObjDef* mapObjDef = CMap::CreateMapObjDef(this->m_mapObjNames + this->m_mapObjNameOffsets[def->m_nameId], def, &center, false);
if (!CMap::s_isStreamingMode) {
CMapObj* mapObj = mapObjDef->m_owner;
if (!mapObj->m_isGroupLoaded) {
mapObj->WaitLoad();
}
uint32_t groupCount = mapObj->m_groupInfoCount;
for (uint32_t group = 0; group < groupCount; group++) {
if (!mapObj->IsGroupLoaded(group)) {
mapObj->ReadGroup(group);
mapObj->WaitLoadGroup(group);
}
}
}
mapObjDef->m_refCount++;
this->m_mapObjDefList.m_data[i] = mapObjDef;
}
}