mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 09:33:51 +00:00
refactor: replace goto with structured control flow
- spell_handler.cpp: replace goto-done with do/while(false) for pet spell packet parsing — bail on truncated data while always firing events afterward - water_renderer.cpp: replace goto-found_neighbor with immediately invoked lambda to break out of nested neighbor search loops
This commit is contained in:
parent
76d29ad669
commit
76f493f7d9
2 changed files with 40 additions and 42 deletions
|
|
@ -1469,21 +1469,22 @@ void SpellHandler::handlePetSpells(network::Packet& packet) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!packet.hasRemaining(4)) goto done;
|
||||
/*uint16_t dur =*/ packet.readUInt16();
|
||||
/*uint16_t timer =*/ packet.readUInt16();
|
||||
// Parse optional pet fields — bail on truncated packets but always log+fire below.
|
||||
do {
|
||||
if (!packet.hasRemaining(4)) break;
|
||||
/*uint16_t dur =*/ packet.readUInt16();
|
||||
/*uint16_t timer =*/ packet.readUInt16();
|
||||
|
||||
if (!packet.hasRemaining(2)) goto done;
|
||||
owner_.petReact_ = packet.readUInt8();
|
||||
owner_.petCommand_ = packet.readUInt8();
|
||||
if (!packet.hasRemaining(2)) break;
|
||||
owner_.petReact_ = packet.readUInt8();
|
||||
owner_.petCommand_ = packet.readUInt8();
|
||||
|
||||
if (!packet.hasRemaining(GameHandler::PET_ACTION_BAR_SLOTS * 4u)) goto done;
|
||||
for (int i = 0; i < GameHandler::PET_ACTION_BAR_SLOTS; ++i) {
|
||||
owner_.petActionSlots_[i] = packet.readUInt32();
|
||||
}
|
||||
if (!packet.hasRemaining(GameHandler::PET_ACTION_BAR_SLOTS * 4u)) break;
|
||||
for (int i = 0; i < GameHandler::PET_ACTION_BAR_SLOTS; ++i) {
|
||||
owner_.petActionSlots_[i] = packet.readUInt32();
|
||||
}
|
||||
|
||||
if (!packet.hasRemaining(1)) goto done;
|
||||
{
|
||||
if (!packet.hasRemaining(1)) break;
|
||||
uint8_t spellCount = packet.readUInt8();
|
||||
owner_.petSpellList_.clear();
|
||||
owner_.petAutocastSpells_.clear();
|
||||
|
|
@ -1496,14 +1497,13 @@ void SpellHandler::handlePetSpells(network::Packet& packet) {
|
|||
owner_.petAutocastSpells_.insert(spellId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (false);
|
||||
|
||||
done:
|
||||
LOG_INFO("SMSG_PET_SPELLS: petGuid=0x", std::hex, owner_.petGuid_, std::dec,
|
||||
" react=", static_cast<int>(owner_.petReact_), " command=", static_cast<int>(owner_.petCommand_),
|
||||
" spells=", owner_.petSpellList_.size());
|
||||
owner_.fireAddonEvent("UNIT_PET", {"player"});
|
||||
owner_.fireAddonEvent("PET_BAR_UPDATE", {});
|
||||
owner_.fireAddonEvent("UNIT_PET", {"player"});
|
||||
owner_.fireAddonEvent("PET_BAR_UPDATE", {});
|
||||
}
|
||||
|
||||
void SpellHandler::sendPetAction(uint32_t action, uint64_t targetGuid) {
|
||||
|
|
|
|||
|
|
@ -1295,38 +1295,36 @@ void WaterRenderer::createWaterMesh(WaterSurface& surface) {
|
|||
renderTile = lsbOrder || msbOrder;
|
||||
}
|
||||
|
||||
// Render masked-out tiles if any adjacent neighbor is visible,
|
||||
// to avoid seam gaps at water surface edges.
|
||||
if (!renderTile) {
|
||||
for (int dy = -1; dy <= 1; dy++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
if (dx == 0 && dy == 0) continue;
|
||||
int nx = x + dx, ny = y + dy;
|
||||
if (nx < 0 || ny < 0 || nx >= gridWidth-1 || ny >= gridHeight-1) continue;
|
||||
int neighborIdx;
|
||||
if (surface.wmoId == 0 && surface.width <= 8 && surface.mask.size() >= 8) {
|
||||
neighborIdx = (static_cast<int>(surface.yOffset) + ny) * 8 +
|
||||
(static_cast<int>(surface.xOffset) + nx);
|
||||
} else {
|
||||
neighborIdx = ny * surface.width + nx;
|
||||
}
|
||||
int nByteIdx = neighborIdx / 8;
|
||||
int nBitIdx = neighborIdx % 8;
|
||||
if (nByteIdx < static_cast<int>(surface.mask.size())) {
|
||||
uint8_t nMask = surface.mask[nByteIdx];
|
||||
if (isMergedTerrain) {
|
||||
if (nMask & (1 << nBitIdx)) {
|
||||
renderTile = true;
|
||||
goto found_neighbor;
|
||||
}
|
||||
renderTile = [&]() {
|
||||
for (int dy = -1; dy <= 1; dy++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
if (dx == 0 && dy == 0) continue;
|
||||
int nx = x + dx, ny = y + dy;
|
||||
if (nx < 0 || ny < 0 || nx >= gridWidth-1 || ny >= gridHeight-1) continue;
|
||||
int neighborIdx;
|
||||
if (surface.wmoId == 0 && surface.width <= 8 && surface.mask.size() >= 8) {
|
||||
neighborIdx = (static_cast<int>(surface.yOffset) + ny) * 8 +
|
||||
(static_cast<int>(surface.xOffset) + nx);
|
||||
} else {
|
||||
if ((nMask & (1 << nBitIdx)) || (nMask & (1 << (7 - nBitIdx)))) {
|
||||
renderTile = true;
|
||||
goto found_neighbor;
|
||||
neighborIdx = ny * surface.width + nx;
|
||||
}
|
||||
int nByteIdx = neighborIdx / 8;
|
||||
int nBitIdx = neighborIdx % 8;
|
||||
if (nByteIdx < static_cast<int>(surface.mask.size())) {
|
||||
uint8_t nMask = surface.mask[nByteIdx];
|
||||
if (isMergedTerrain) {
|
||||
if (nMask & (1 << nBitIdx)) return true;
|
||||
} else {
|
||||
if ((nMask & (1 << nBitIdx)) || (nMask & (1 << (7 - nBitIdx)))) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
found_neighbor:;
|
||||
return false;
|
||||
}();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue