Skip to content

Commit

Permalink
Use new unit hooks to optimize BuildValuesUpdate (#146)
Browse files Browse the repository at this point in the history
* Use new unit hooks to optimize BuildValuesUpdate

* Parameter not used

* Address code review feedback

---------

Co-authored-by: Pagani Walter <[email protected]>
  • Loading branch information
walkline and pangolp authored Apr 5, 2024
1 parent 08e9273 commit a21dac3
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/transmog_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,21 +1118,24 @@ class unit_transmog_script : public UnitScript
public:
unit_transmog_script() : UnitScript("unit_transmog_script") { }

bool OnBuildValuesUpdate(Unit const* unit, uint8 /*updateType*/, ByteBuffer& fieldBuffer, Player* target, uint16 index) override
bool ShouldTrackValuesUpdatePosByIndex(Unit const* unit, uint8 /*updateType*/, uint16 index) override
{
if (unit->IsPlayer() && index >= PLAYER_VISIBLE_ITEM_1_ENTRYID && index <= PLAYER_VISIBLE_ITEM_19_ENTRYID && (index & 1))
return unit->IsPlayer() && index >= PLAYER_VISIBLE_ITEM_1_ENTRYID && index <= PLAYER_VISIBLE_ITEM_19_ENTRYID && (index & 1);
}

void OnPatchValuesUpdate(Unit const* unit, ByteBuffer& valuesUpdateBuf, BuildValuesCachePosPointers& posPointers, Player* target) override
{
if (!unit->IsPlayer())
return;

for (auto it = posPointers.other.begin(); it != posPointers.other.end(); ++it)
{
if (Item* item = unit->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, ((index - PLAYER_VISIBLE_ITEM_1_ENTRYID) / 2U)))
{
if (!sTransmogrification->IsEnabled() || target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value)
{
fieldBuffer << item->GetEntry();
return true;
}
}
uint16 index = it->first;
if (index >= PLAYER_VISIBLE_ITEM_1_ENTRYID && index <= PLAYER_VISIBLE_ITEM_19_ENTRYID && (index & 1))
if (Item* item = unit->ToPlayer()->GetItemByPos(INVENTORY_SLOT_BAG_0, ((index - PLAYER_VISIBLE_ITEM_1_ENTRYID) / 2U)))
if (!sTransmogrification->IsEnabled() || target->GetPlayerSetting("mod-transmog", SETTING_HIDE_TRANSMOG).value)
valuesUpdateBuf.put(it->second, item->GetEntry());
}

return false;
}
};

Expand Down

0 comments on commit a21dac3

Please sign in to comment.