diff --git a/src/client/ClientHandlers.cpp b/src/client/ClientHandlers.cpp index 4d53abc..9ed62a8 100644 --- a/src/client/ClientHandlers.cpp +++ b/src/client/ClientHandlers.cpp @@ -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; diff --git a/src/world/CWorld.cpp b/src/world/CWorld.cpp index 55e5f64..4b7fd58 100644 --- a/src/world/CWorld.cpp +++ b/src/world/CWorld.cpp @@ -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); } diff --git a/src/world/CWorld.hpp b/src/world/CWorld.hpp index c2aef48..108833d 100644 --- a/src/world/CWorld.hpp +++ b/src/world/CWorld.hpp @@ -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); diff --git a/src/world/daynight/DayNight.cpp b/src/world/daynight/DayNight.cpp index 3dd018e..213adaf 100644 --- a/src/world/daynight/DayNight.cpp +++ b/src/world/daynight/DayNight.cpp @@ -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() { diff --git a/src/world/map/CMap.cpp b/src/world/map/CMap.cpp index 2dc31c1..a0fe23c 100644 --- a/src/world/map/CMap.cpp +++ b/src/world/map/CMap.cpp @@ -1,7 +1,91 @@ #include "world/map/CMap.hpp" #include "world/daynight/DayNight.hpp" +#include "util/SFile.hpp" +#include + + + +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); } diff --git a/src/world/map/CMap.hpp b/src/world/map/CMap.hpp index c41dd18..c6f458f 100644 --- a/src/world/map/CMap.hpp +++ b/src/world/map/CMap.hpp @@ -1,11 +1,24 @@ #ifndef WORLD_C_MAP_HPP #define WORLD_C_MAP_HPP -#include +#include "world/map/Types.hpp" +#include 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 diff --git a/src/world/map/Types.hpp b/src/world/map/Types.hpp new file mode 100644 index 0000000..709f563 --- /dev/null +++ b/src/world/map/Types.hpp @@ -0,0 +1,37 @@ +#ifndef WORLD_MAP_TYPES_HPP +#define WORLD_MAP_TYPES_HPP + +#include +#include +#include + +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