mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
feat(Core/Optimization): Optimize build of units update object by leveraging cache (#18637)
* feat(Core/Optimization): Optimize build of units update object by leveraging cache. * Remove whitespaces. * Add alternative hooks to handle transmog and other similar things. * Fix build on some compilers. * Fix codestyle * Fix build again. * Take into account updateType.
This commit is contained in:
committed by
GitHub
parent
94df67b1c2
commit
1f640c9872
@@ -1321,6 +1321,62 @@ private:
|
||||
Unit* defaultValue;
|
||||
};
|
||||
|
||||
// BuildValuesCachePosPointers is marks of the position of some data inside of BuildValue cache.
|
||||
struct BuildValuesCachePosPointers
|
||||
{
|
||||
BuildValuesCachePosPointers() :
|
||||
UnitNPCFlagsPos(-1), UnitFieldAuraStatePos(-1), UnitFieldFlagsPos(-1), UnitFieldDisplayPos(-1),
|
||||
UnitDynamicFlagsPos(-1), UnitFieldBytes2Pos(-1), UnitFieldFactionTemplatePos(-1) {}
|
||||
|
||||
void ApplyOffset(uint32 offset)
|
||||
{
|
||||
if (UnitNPCFlagsPos >= 0)
|
||||
UnitNPCFlagsPos += offset;
|
||||
|
||||
if (UnitFieldAuraStatePos >= 0)
|
||||
UnitFieldAuraStatePos += offset;
|
||||
|
||||
if (UnitFieldFlagsPos >= 0)
|
||||
UnitFieldFlagsPos += offset;
|
||||
|
||||
if (UnitFieldDisplayPos >= 0)
|
||||
UnitFieldDisplayPos += offset;
|
||||
|
||||
if (UnitDynamicFlagsPos >= 0)
|
||||
UnitDynamicFlagsPos += offset;
|
||||
|
||||
if (UnitFieldBytes2Pos >= 0)
|
||||
UnitFieldBytes2Pos += offset;
|
||||
|
||||
if (UnitFieldFactionTemplatePos >= 0)
|
||||
UnitFieldFactionTemplatePos += offset;
|
||||
|
||||
for (auto it = other.begin(); it != other.end(); ++it)
|
||||
it->second += offset;
|
||||
}
|
||||
|
||||
int32 UnitNPCFlagsPos;
|
||||
int32 UnitFieldAuraStatePos;
|
||||
int32 UnitFieldFlagsPos;
|
||||
int32 UnitFieldDisplayPos;
|
||||
int32 UnitDynamicFlagsPos;
|
||||
int32 UnitFieldBytes2Pos;
|
||||
int32 UnitFieldFactionTemplatePos;
|
||||
|
||||
std::unordered_map<uint16 /*index*/, uint32 /*pos*/> other;
|
||||
};
|
||||
|
||||
// BuildValuesCachedBuffer cache for calculated BuildValue.
|
||||
struct BuildValuesCachedBuffer
|
||||
{
|
||||
BuildValuesCachedBuffer(uint32 bufferSize) :
|
||||
buffer(bufferSize), posPointers() {}
|
||||
|
||||
ByteBuffer buffer;
|
||||
|
||||
BuildValuesCachePosPointers posPointers;
|
||||
};
|
||||
|
||||
class Unit : public WorldObject
|
||||
{
|
||||
public:
|
||||
@@ -2505,7 +2561,7 @@ public:
|
||||
protected:
|
||||
explicit Unit (bool isWorldObject);
|
||||
|
||||
void BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, Player* target) const override;
|
||||
void BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target) override;
|
||||
|
||||
UnitAI* i_AI, *i_disabledAI;
|
||||
|
||||
@@ -2598,6 +2654,9 @@ private:
|
||||
[[nodiscard]] float GetCombatRatingReduction(CombatRating cr) const;
|
||||
[[nodiscard]] uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
|
||||
|
||||
void PatchValuesUpdate(ByteBuffer& valuesUpdateBuf, BuildValuesCachePosPointers& posPointers, Player* target);
|
||||
void InvalidateValuesUpdateCache() { _valuesUpdateCache.clear(); }
|
||||
|
||||
protected:
|
||||
void SetFeared(bool apply, Unit* fearedBy = nullptr, bool isFear = false);
|
||||
void SetConfused(bool apply);
|
||||
@@ -2635,6 +2694,9 @@ private:
|
||||
uint32 _lastExtraAttackSpell;
|
||||
std::unordered_map<ObjectGuid /*guid*/, uint32 /*count*/> extraAttacksTargets;
|
||||
ObjectGuid _lastDamagedTargetGuid;
|
||||
|
||||
typedef std::unordered_map<uint64 /*visibleFlag(uint32) + updateType(uint8)*/, BuildValuesCachedBuffer> ValuesUpdateCache;
|
||||
ValuesUpdateCache _valuesUpdateCache;
|
||||
};
|
||||
|
||||
namespace Acore
|
||||
|
||||
Reference in New Issue
Block a user