Implement SMSG_WEATHER and wire real game state (map ID, weather, underwater) to lighting system

This commit is contained in:
Kelsi 2026-02-17 17:59:41 -08:00
parent 60ebb4dc3f
commit 369ad26476
5 changed files with 44 additions and 7 deletions

View file

@ -507,6 +507,13 @@ public:
float getGameTime() const { return gameTime_; }
float getTimeSpeed() const { return timeSpeed_; }
// Weather state (updated by SMSG_WEATHER)
// weatherType: 0=clear, 1=rain, 2=snow, 3=storm/fog
uint32_t getWeatherType() const { return weatherType_; }
float getWeatherIntensity() const { return weatherIntensity_; }
bool isRaining() const { return weatherType_ == 1 && weatherIntensity_ > 0.05f; }
bool isSnowing() const { return weatherType_ == 2 && weatherIntensity_ > 0.05f; }
// Player skills
const std::map<uint32_t, PlayerSkill>& getPlayerSkills() const { return playerSkills_; }
const std::string& getSkillName(uint32_t skillId) const;
@ -1538,6 +1545,10 @@ private:
float timeSpeed_ = 0.0166f; // Time scale (default: 1 game day = 1 real hour)
void handleLoginSetTimeSpeed(network::Packet& packet);
// ---- Weather state (SMSG_WEATHER) ----
uint32_t weatherType_ = 0; // 0=clear, 1=rain, 2=snow, 3=storm
float weatherIntensity_ = 0.0f; // 0.0 to 1.0
// ---- Player skills ----
std::map<uint32_t, PlayerSkill> playerSkills_;
std::unordered_map<uint32_t, std::string> skillLineNames_;

View file

@ -358,6 +358,9 @@ enum class LogicalOpcode : uint16_t {
SMSG_ARENA_ERROR,
MSG_INSPECT_ARENA_TEAMS,
// ---- Weather ----
SMSG_WEATHER,
// ---- Emotes ----
CMSG_EMOTE,
SMSG_EMOTE,

View file

@ -1239,6 +1239,19 @@ void GameHandler::handlePacket(network::Packet& packet) {
}
case Opcode::MSG_RAID_TARGET_UPDATE:
break;
case Opcode::SMSG_WEATHER: {
// Format: uint32 weatherType, float intensity, uint8 isAbrupt
if (packet.getSize() - packet.getReadPos() >= 9) {
uint32_t wType = packet.readUInt32();
float wIntensity = packet.readFloat();
/*uint8_t isAbrupt =*/ packet.readUInt8();
weatherType_ = wType;
weatherIntensity_ = wIntensity;
const char* typeName = (wType == 1) ? "Rain" : (wType == 2) ? "Snow" : (wType == 3) ? "Storm" : "Clear";
LOG_INFO("Weather changed: type=", wType, " (", typeName, "), intensity=", wIntensity);
}
break;
}
case Opcode::SMSG_GAMEOBJECT_QUERY_RESPONSE:
handleGameObjectQueryResponse(packet);
break;

View file

@ -287,6 +287,7 @@ static const OpcodeNameEntry kOpcodeNames[] = {
{"SMSG_ARENA_TEAM_STATS", LogicalOpcode::SMSG_ARENA_TEAM_STATS},
{"SMSG_ARENA_ERROR", LogicalOpcode::SMSG_ARENA_ERROR},
{"MSG_INSPECT_ARENA_TEAMS", LogicalOpcode::MSG_INSPECT_ARENA_TEAMS},
{"SMSG_WEATHER", LogicalOpcode::SMSG_WEATHER},
{"CMSG_EMOTE", LogicalOpcode::CMSG_EMOTE},
{"SMSG_EMOTE", LogicalOpcode::SMSG_EMOTE},
{"CMSG_TEXT_EMOTE", LogicalOpcode::CMSG_TEXT_EMOTE},
@ -627,6 +628,7 @@ void OpcodeTable::loadWotlkDefaults() {
{LogicalOpcode::SMSG_ARENA_TEAM_STATS, 0x035B},
{LogicalOpcode::SMSG_ARENA_ERROR, 0x0376},
{LogicalOpcode::MSG_INSPECT_ARENA_TEAMS, 0x0377},
{LogicalOpcode::SMSG_WEATHER, 0x2F4},
{LogicalOpcode::CMSG_EMOTE, 0x102},
{LogicalOpcode::SMSG_EMOTE, 0x103},
{LogicalOpcode::CMSG_TEXT_EMOTE, 0x104},

View file

@ -1838,15 +1838,23 @@ void Renderer::update(float deltaTime) {
// Update lighting system
auto light1 = std::chrono::high_resolution_clock::now();
if (lightingManager) {
// TODO: Get actual map ID from game state (0 = Eastern Kingdoms for now)
// TODO: Get actual game time from server (use -1 for local time fallback)
// TODO: Get weather/underwater state from game state
uint32_t mapId = 0; // Eastern Kingdoms
float gameTime = -1.0f; // Use local time for now
bool isRaining = false; // TODO: Get from weather system
bool isUnderwater = false; // TODO: Get from player state
const auto* gh = core::Application::getInstance().getGameHandler();
uint32_t mapId = gh ? gh->getCurrentMapId() : 0;
float gameTime = gh ? gh->getGameTime() : -1.0f;
bool isRaining = gh ? gh->isRaining() : false;
bool isUnderwater = cameraController ? cameraController->isSwimming() : false;
lightingManager->update(characterPosition, mapId, gameTime, isRaining, isUnderwater);
// Sync weather visual renderer with game state
if (weather && gh) {
uint32_t wType = gh->getWeatherType();
float wInt = gh->getWeatherIntensity();
if (wType == 1) weather->setWeatherType(Weather::Type::RAIN);
else if (wType == 2) weather->setWeatherType(Weather::Type::SNOW);
else weather->setWeatherType(Weather::Type::NONE);
weather->setIntensity(wInt);
}
}
auto light2 = std::chrono::high_resolution_clock::now();
lightTime += std::chrono::duration<float, std::milli>(light2 - light1).count();