diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 095cd14..a12dd84 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -808,5 +808,12 @@ void ClientInitializeGame(int32_t continentID, const C3Vector& position) { ClientServices::SetMessageHandler(SMSG_NEW_WORLD, &NewWorldHandler, nullptr); ClientServices::SetMessageHandler(SMSG_LOGIN_VERIFY_WORLD, &LoginVerifyWorldHandler, nullptr); + auto record = g_mapDB.GetRecord(continentID); + if (!record) { + return; + } + + CWorld::LoadMap(record->m_directory, position, continentID); + // TODO } diff --git a/src/client/ClientHandlers.cpp b/src/client/ClientHandlers.cpp index c061096..4d53abc 100644 --- a/src/client/ClientHandlers.cpp +++ b/src/client/ClientHandlers.cpp @@ -5,12 +5,8 @@ #include "console/Console.hpp" #include "world/World.hpp" - - -uint32_t s_newZoneID = 0; -C3Vector s_newPosition; -float s_newFacing = 0.0f; -const char* s_newMapname = nullptr; +#include "db/Db.hpp" +#include "event/Timer.hpp" int32_t NewWorldHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg) { @@ -23,7 +19,16 @@ int32_t NewWorldHandler(void* param, NETMESSAGE msgId, uint32_t time, CDataStore msg->Get(s_newFacing); if (msg->IsRead()) { - // TODO + auto record = g_mapDB.GetRecord(s_newZoneID); + if (!record) { + ConsoleWrite("Bad SMSG_NEW_WORLD zoneID\n", DEFAULT_COLOR); + return 0; + } + + s_newMapname = record->m_directory; + // TODO: EventSetTimer(0, LoadNewWorld, 1); + // WORKAROUND: + LoadNewWorld(nullptr); return 1; } else { ConsoleWrite("Bad SMSG_NEW_WORLD\n", DEFAULT_COLOR); @@ -45,17 +50,19 @@ int32_t LoginVerifyWorldHandler(void* param, NETMESSAGE msgId, uint32_t time, CD float facing; msg->Get(facing); - // zoneID != ClntObjMgrGetMapID() - if (false) { + + if (false /* zoneID != ClntObjMgrGetMapID() */) { s_newFacing = facing; s_newPosition = position; s_newZoneID = zoneID; - //if (zoneID < dword_AD4170 || zoneID > dword_AD416C || (v0 = *(_DWORD*)(dword_AD4180 + 4 * (zoneID - dword_AD4170))) == 0) { - // ConsoleWrite("Bad SMSG_NEW_WORLD zoneID\n", 0); - // return 0; - //} - //s_newMapname = *(_DWORD*)(v0 + 4); - LoadNewWorld(); + auto record = g_mapDB.GetRecord(s_newZoneID); + if (!record) { + ConsoleWrite("Bad SMSG_NEW_WORLD zoneID\n", DEFAULT_COLOR); + return 0; + } + + s_newMapname = record->m_directory; + LoadNewWorld(nullptr); } return 1; } diff --git a/src/gameui/CGWorldFrame.cpp b/src/gameui/CGWorldFrame.cpp index 8e3f176..052143e 100644 --- a/src/gameui/CGWorldFrame.cpp +++ b/src/gameui/CGWorldFrame.cpp @@ -3,6 +3,7 @@ #include "gx/Transform.hpp" #include "gx/Draw.hpp" #include "gx/Shader.hpp" +#include "world/CWorld.hpp" #include #include @@ -62,4 +63,5 @@ void CGWorldFrame::OnWorldUpdate() { } void CGWorldFrame::OnWorldRender() { + CWorld::Render(); } diff --git a/src/world/CMakeLists.txt b/src/world/CMakeLists.txt index 78928e9..787984f 100644 --- a/src/world/CMakeLists.txt +++ b/src/world/CMakeLists.txt @@ -1,4 +1,8 @@ -file(GLOB PRIVATE_SOURCES "*.cpp") +file(GLOB PRIVATE_SOURCES + "daynight/*.cpp" + "map/*.cpp" + "*.cpp" +) add_library(world STATIC ${PRIVATE_SOURCES} @@ -13,4 +17,9 @@ target_link_libraries(world PRIVATE gx model + PUBLIC + bc + common + storm + tempest ) diff --git a/src/world/CWorld.cpp b/src/world/CWorld.cpp index 4ee7904..f6c5f2e 100644 --- a/src/world/CWorld.cpp +++ b/src/world/CWorld.cpp @@ -2,6 +2,8 @@ #include "gx/Device.hpp" #include "gx/Shader.hpp" #include "model/Model2.hpp" +#include "world/map/CMap.hpp" +#include "world/daynight/DayNight.hpp" uint32_t CWorld::s_enables; uint32_t CWorld::s_enables2; @@ -42,3 +44,11 @@ void CWorld::Initialize() { // TODO } + +void CWorld::LoadMap(const char* mapName, const C3Vector& position, int32_t zoneID) { + CMap::Load(mapName, zoneID); +} + +void CWorld::Render() { + DayNight::RenderSky(); +} diff --git a/src/world/CWorld.hpp b/src/world/CWorld.hpp index de170eb..c2aef48 100644 --- a/src/world/CWorld.hpp +++ b/src/world/CWorld.hpp @@ -2,6 +2,7 @@ #define WORLD_C_WORLD_HPP #include +#include class CWorld { public: @@ -47,6 +48,8 @@ class CWorld { // Static functions static void Initialize(void); + static void LoadMap(const char* mapName, const C3Vector& position, int32_t zoneID); + static void Render(); }; #endif diff --git a/src/world/World.cpp b/src/world/World.cpp index 6914fc5..48f6a9a 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -1,6 +1,13 @@ #include "world/World.hpp" -int32_t LoadNewWorld() { +uint32_t s_newZoneID = 0; +C3Vector s_newPosition; +float s_newFacing = 0.0f; +const char* s_newMapname = nullptr; + +int32_t LoadNewWorld(const void* eventData) { + // TODO + CWorld::LoadMap(s_newMapname, s_newPosition, s_newZoneID); return 1; } diff --git a/src/world/World.hpp b/src/world/World.hpp index baaeb05..bbdce6a 100644 --- a/src/world/World.hpp +++ b/src/world/World.hpp @@ -3,6 +3,11 @@ #include "world/CWorld.hpp" -int32_t LoadNewWorld(); +extern uint32_t s_newZoneID; +extern C3Vector s_newPosition; +extern float s_newFacing; +extern const char* s_newMapname; + +int32_t LoadNewWorld(const void* eventData); #endif diff --git a/src/world/daynight/DNStars.cpp b/src/world/daynight/DNStars.cpp new file mode 100644 index 0000000..11ad618 --- /dev/null +++ b/src/world/daynight/DNStars.cpp @@ -0,0 +1,46 @@ +#include "world/daynight/DNStars.hpp" +#include "model/Model2.hpp" +#include + +namespace DayNight { + +void DNStars::Initialize() { + this->m_scene = M2CreateScene(); + this->m_model = this->m_scene->CreateModel("Environments\\Stars\\stars.mdl", 0); + this->m_time = OsGetAsyncTimeMs(); +} + +void DNStars::Destroy() { + if (this->m_model) { + this->m_model->Release(); + this->m_model = nullptr; + } + + if (this->m_scene) { + // TODO: this->m_scene->Release(); + this->m_scene = nullptr; + } +} + +void DNStars::Update() { + // TODO +} + +void DNStars::Render() { + if (this->m_color.a < 2) { + //return; + } + + this->m_model->SetAnimating(1); + + // TODO + + uint32_t elapsed = OsGetAsyncTimeMs() - this->m_time; + this->m_time += elapsed; + this->m_scene->AdvanceTime(elapsed); + this->m_scene->Animate(C3Vector()); + this->m_scene->Draw(M2PASS_0); + this->m_scene->Draw(M2PASS_1); +} + +} // namespace DayNight diff --git a/src/world/daynight/DNStars.hpp b/src/world/daynight/DNStars.hpp new file mode 100644 index 0000000..0bd8da1 --- /dev/null +++ b/src/world/daynight/DNStars.hpp @@ -0,0 +1,32 @@ +#ifndef WORLD_DAY_NIGHT_STARS_HPP +#define WORLD_DAY_NIGHT_STARS_HPP + + +#include +#include + + +class CM2Scene; +class CM2Model; + + +namespace DayNight { + +class DNStars { + public: + void Initialize(); + void Destroy(); + void Update(); + void Render(); + + CM2Scene* m_scene = nullptr; + CM2Model* m_model = nullptr; + CImVector m_color { 0 }; + C3Vector m_pos; + uint32_t m_time = 0; +}; + +} // namespace DayNight + + +#endif diff --git a/src/world/daynight/DayNight.cpp b/src/world/daynight/DayNight.cpp new file mode 100644 index 0000000..74df82d --- /dev/null +++ b/src/world/daynight/DayNight.cpp @@ -0,0 +1,20 @@ +#include "world/daynight/DayNight.hpp" +#include "world/daynight/DNStars.hpp" + + +namespace DayNight { + +static DNStars g_stars; + + +void LoadMap(int32_t zoneID) { + // TODO + g_stars.Initialize(); +} + +void RenderSky() { + // TODO + g_stars.Render(); +} + +} // namespace DayNight diff --git a/src/world/daynight/DayNight.hpp b/src/world/daynight/DayNight.hpp new file mode 100644 index 0000000..ffdcbd5 --- /dev/null +++ b/src/world/daynight/DayNight.hpp @@ -0,0 +1,13 @@ +#ifndef WORLD_DAY_NIGHT_HPP +#define WORLD_DAY_NIGHT_HPP + +#include + +namespace DayNight { + +void LoadMap(int32_t zoneID); +void RenderSky(); + +} // namespace DayNight + +#endif diff --git a/src/world/map/CMap.cpp b/src/world/map/CMap.cpp new file mode 100644 index 0000000..2dc31c1 --- /dev/null +++ b/src/world/map/CMap.cpp @@ -0,0 +1,7 @@ +#include "world/map/CMap.hpp" +#include "world/daynight/DayNight.hpp" + + +void CMap::Load(const char* mapName, int32_t zoneID) { + DayNight::LoadMap(zoneID); +} diff --git a/src/world/map/CMap.hpp b/src/world/map/CMap.hpp new file mode 100644 index 0000000..c41dd18 --- /dev/null +++ b/src/world/map/CMap.hpp @@ -0,0 +1,11 @@ +#ifndef WORLD_C_MAP_HPP +#define WORLD_C_MAP_HPP + +#include + +class CMap { + public: + static void Load(const char* mapName, int32_t zoneID); +}; + +#endif