mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-03 08:03:50 +00:00
Load terrain when entering world in online mode
Add world entry callback that triggers terrain loading when receiving SMSG_LOGIN_VERIFY_WORLD. Fix coordinate conversion by applying serverToCanonical() to properly swap X/Y axes from server format.
This commit is contained in:
parent
9c8b202595
commit
a4fcc38c12
5 changed files with 72 additions and 1 deletions
|
|
@ -80,6 +80,7 @@ private:
|
||||||
void spawnNpcs();
|
void spawnNpcs();
|
||||||
std::string getPlayerModelPath() const;
|
std::string getPlayerModelPath() const;
|
||||||
static const char* mapIdToName(uint32_t mapId);
|
static const char* mapIdToName(uint32_t mapId);
|
||||||
|
void loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float z);
|
||||||
|
|
||||||
static Application* instance;
|
static Application* instance;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,6 +271,11 @@ public:
|
||||||
using HearthstoneCallback = std::function<void()>;
|
using HearthstoneCallback = std::function<void()>;
|
||||||
void setHearthstoneCallback(HearthstoneCallback cb) { hearthstoneCallback = std::move(cb); }
|
void setHearthstoneCallback(HearthstoneCallback cb) { hearthstoneCallback = std::move(cb); }
|
||||||
|
|
||||||
|
// World entry callback (online mode - triggered when entering world)
|
||||||
|
// Parameters: mapId, x, y, z (canonical WoW coordinates)
|
||||||
|
using WorldEntryCallback = std::function<void(uint32_t mapId, float x, float y, float z)>;
|
||||||
|
void setWorldEntryCallback(WorldEntryCallback cb) { worldEntryCallback_ = std::move(cb); }
|
||||||
|
|
||||||
// Cooldowns
|
// Cooldowns
|
||||||
float getSpellCooldown(uint32_t spellId) const;
|
float getSpellCooldown(uint32_t spellId) const;
|
||||||
|
|
||||||
|
|
@ -523,6 +528,7 @@ private:
|
||||||
|
|
||||||
// ---- Phase 3: Spells ----
|
// ---- Phase 3: Spells ----
|
||||||
HearthstoneCallback hearthstoneCallback;
|
HearthstoneCallback hearthstoneCallback;
|
||||||
|
WorldEntryCallback worldEntryCallback_;
|
||||||
std::vector<uint32_t> knownSpells;
|
std::vector<uint32_t> knownSpells;
|
||||||
std::unordered_map<uint32_t, float> spellCooldowns; // spellId -> remaining seconds
|
std::unordered_map<uint32_t, float> spellCooldowns; // spellId -> remaining seconds
|
||||||
uint8_t castCount = 0;
|
uint8_t castCount = 0;
|
||||||
|
|
|
||||||
|
|
@ -615,6 +615,12 @@ void Application::setupUICallbacks() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// World entry callback (online mode) - load terrain when entering world
|
||||||
|
gameHandler->setWorldEntryCallback([this](uint32_t mapId, float x, float y, float z) {
|
||||||
|
LOG_INFO("Online world entry: mapId=", mapId, " pos=(", x, ", ", y, ", ", z, ")");
|
||||||
|
loadOnlineWorldTerrain(mapId, x, y, z);
|
||||||
|
});
|
||||||
|
|
||||||
// "Create Character" button on character screen
|
// "Create Character" button on character screen
|
||||||
uiManager->getCharacterScreen().setOnCreateCharacter([this]() {
|
uiManager->getCharacterScreen().setOnCreateCharacter([this]() {
|
||||||
uiManager->getCharacterCreateScreen().reset();
|
uiManager->getCharacterCreateScreen().reset();
|
||||||
|
|
@ -1507,5 +1513,59 @@ void Application::teleportTo(int presetIndex) {
|
||||||
LOG_INFO("Teleport to ", preset.label, " complete");
|
LOG_INFO("Teleport to ", preset.label, " complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float z) {
|
||||||
|
if (!renderer || !assetManager || !assetManager->isInitialized()) {
|
||||||
|
LOG_WARNING("Cannot load online terrain: renderer or assets not ready");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string mapName = mapIdToName(mapId);
|
||||||
|
LOG_INFO("Loading online world terrain for map '", mapName, "' (ID ", mapId, ")");
|
||||||
|
|
||||||
|
// Convert server coordinates to canonical WoW coordinates
|
||||||
|
// Server sends: X=West (canonical.Y), Y=North (canonical.X), Z=Up
|
||||||
|
glm::vec3 spawnCanonical = core::coords::serverToCanonical(glm::vec3(x, y, z));
|
||||||
|
glm::vec3 spawnRender = core::coords::canonicalToRender(spawnCanonical);
|
||||||
|
|
||||||
|
// Set camera position
|
||||||
|
if (renderer->getCameraController()) {
|
||||||
|
renderer->getCameraController()->setDefaultSpawn(spawnRender, 0.0f, 15.0f);
|
||||||
|
renderer->getCameraController()->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set map name for WMO renderer
|
||||||
|
if (renderer->getWMORenderer()) {
|
||||||
|
renderer->getWMORenderer()->setMapName(mapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set map name for terrain manager
|
||||||
|
if (renderer->getTerrainManager()) {
|
||||||
|
renderer->getTerrainManager()->setMapName(mapName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute ADT tile from canonical coordinates
|
||||||
|
auto [tileX, tileY] = core::coords::canonicalToTile(spawnCanonical.x, spawnCanonical.y);
|
||||||
|
std::string adtPath = "World\\Maps\\" + mapName + "\\" + mapName + "_" +
|
||||||
|
std::to_string(tileX) + "_" + std::to_string(tileY) + ".adt";
|
||||||
|
LOG_INFO("Loading ADT tile [", tileX, ",", tileY, "] from canonical (",
|
||||||
|
spawnCanonical.x, ", ", spawnCanonical.y, ", ", spawnCanonical.z, ")");
|
||||||
|
|
||||||
|
// Load the initial terrain tile
|
||||||
|
bool terrainOk = renderer->loadTestTerrain(assetManager.get(), adtPath);
|
||||||
|
if (!terrainOk) {
|
||||||
|
LOG_WARNING("Could not load terrain for online world - atmospheric rendering only");
|
||||||
|
} else {
|
||||||
|
LOG_INFO("Online world terrain loading initiated");
|
||||||
|
|
||||||
|
// Trigger terrain streaming for surrounding tiles
|
||||||
|
if (renderer->getTerrainManager() && renderer->getCamera()) {
|
||||||
|
renderer->getTerrainManager()->update(*renderer->getCamera(), 1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set game state
|
||||||
|
setState(AppState::IN_GAME);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace core
|
} // namespace core
|
||||||
} // namespace wowee
|
} // namespace wowee
|
||||||
|
|
|
||||||
|
|
@ -2102,6 +2102,11 @@ void GameHandler::handleLoginVerifyWorld(network::Packet& packet) {
|
||||||
socket->send(activeMoverPacket);
|
socket->send(activeMoverPacket);
|
||||||
LOG_INFO("Sent CMSG_SET_ACTIVE_MOVER for player 0x", std::hex, playerGuid, std::dec);
|
LOG_INFO("Sent CMSG_SET_ACTIVE_MOVER for player 0x", std::hex, playerGuid, std::dec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify application to load terrain for this map/position (online mode)
|
||||||
|
if (worldEntryCallback_) {
|
||||||
|
worldEntryCallback_(data.mapId, data.x, data.y, data.z);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameHandler::handleAccountDataTimes(network::Packet& packet) {
|
void GameHandler::handleAccountDataTimes(network::Packet& packet) {
|
||||||
|
|
|
||||||
|
|
@ -800,7 +800,6 @@ void TerrainManager::getTileBounds(const TileCoord& coord, float& minX, float& m
|
||||||
|
|
||||||
std::string TerrainManager::getADTPath(const TileCoord& coord) const {
|
std::string TerrainManager::getADTPath(const TileCoord& coord) const {
|
||||||
// Format: World\Maps\{MapName}\{MapName}_{X}_{Y}.adt
|
// Format: World\Maps\{MapName}\{MapName}_{X}_{Y}.adt
|
||||||
// Example: Azeroth_32_49.adt for tile at coord.x=32, coord.y=49
|
|
||||||
return "World\\Maps\\" + mapName + "\\" + mapName + "_" +
|
return "World\\Maps\\" + mapName + "\\" + mapName + "_" +
|
||||||
std::to_string(coord.x) + "_" + std::to_string(coord.y) + ".adt";
|
std::to_string(coord.x) + "_" + std::to_string(coord.y) + ".adt";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue