Skip to content

Commit

Permalink
Some performance optimizations (filtering some units like nameplates).
Browse files Browse the repository at this point in the history
Implementing a workaround to fix ticket #907, dead people sometimes don't show as dead.
  • Loading branch information
michaelnpsp committed Dec 16, 2020
1 parent 3616e1f commit a2a17dc
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion GridCore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function Grid2:ReloadTheme(force)
self:UpdateTheme()
self:RefreshTheme()
self:SendMessage("Grid_ThemeChanged", theme)
self:Debug("ReloadTheme", theme)
self:Debug("Theme Reloaded", theme)
end
return true
end
Expand Down
2 changes: 1 addition & 1 deletion GridLayout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ function Grid2Layout:PlaceHeaders()
frame:SetPoint(anchor, prevFrame, relPoint, xMult2, yMult2 )
end
frame:Show()
prevFrame = frame
self:Debug("Placing group", groupNumber, frame:GetName(), anchor, prevFrame and prevFrame:GetName(), relPoint)
prevFrame = frame
end
end

Expand Down
6 changes: 6 additions & 0 deletions GridRoster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ local raid_units = {}
local pet_of_unit = {}
local owner_of_unit = {}

-- valid units (only friendly party and raid units, excluding nameplates, focus, etc).
local unit_is_valid = {}

-- indexed by index, only nonpet units
local roster_count = 0
local roster_indexed

-- flag to track if roster contains unknown units, workaround to blizard bug (see ticket #628)
local roster_unknowns


-- populate unit tables
do
local function register_unit(tbl, unit, pet, index, indexes)
Expand All @@ -59,6 +63,7 @@ do
owner_of_unit[pet] = unit
indexes[unit] = index
indexes[pet] = index
unit_is_valid[unit] = true
end
register_unit(party_units, "player", "pet", 0, party_indexes)
for i = 1, MAX_PARTY_MEMBERS do
Expand Down Expand Up @@ -423,6 +428,7 @@ do
end

--{{ Publish tables used by some statuses
Grid2.unit_is_valid = unit_is_valid
Grid2.owner_of_unit = owner_of_unit
Grid2.roster_units = roster_units
Grid2.roster_my_units = roster_my_units
Expand Down
2 changes: 1 addition & 1 deletion GridUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ do
function Grid2:MakeColor(color, default)
return color or defaultColors[default or "TRANSPARENT"]
end
Grid2.defaultColors = defaultColors
Grid2.defaultColors = defaultColors
end

-- Repeating Timer Management
Expand Down
5 changes: 5 additions & 0 deletions Options/modules/general/GridExportImport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ do
end
end

-- Publish some useful functions
function Grid2Options:ExportText(title,data)
ShowSerializeFrame(title,'',data)
end

-- {{ Create profile advanced options
Grid2Options.AdvancedProfileOptions = { type = "group", order= 200, name = L["Import&Export"], desc = L["Options for %s."]:format(L["Import&Export"]), args = {
header1 ={
Expand Down
37 changes: 31 additions & 6 deletions modules/StatusHealth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ local UnitIsGhost = UnitIsGhost
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local UnitIsFeignDeath = UnitIsFeignDeath
local UnitHealthMax = UnitHealthMax
local C_Timer_After = C_Timer.After
local unit_is_valid = Grid2.unit_is_valid

-- Caches
local heals_enabled = false
Expand Down Expand Up @@ -52,7 +54,7 @@ local healthdeficit_enabled = false
local statuses = {}

local function UpdateIndicators(unit)
if unit then
if unit_is_valid[unit] then
for status in next, statuses do
status:UpdateIndicators(unit)
end
Expand Down Expand Up @@ -278,10 +280,12 @@ local feign_cache = {}
FeignDeath.GetColor = Grid2.statusLibrary.GetColor

local function FeignDeathUpdateEvent(unit)
local feign = UnitIsFeignDeath(unit)
if feign~=feign_cache[unit] then
feign_cache[unit] = feign
FeignDeath:UpdateIndicators(unit)
if unit_is_valid[unit] then
local feign = UnitIsFeignDeath(unit)
if feign~=feign_cache[unit] then
feign_cache[unit] = feign
FeignDeath:UpdateIndicators(unit)
end
end
end

Expand Down Expand Up @@ -402,12 +406,16 @@ Grid2:DbSetStatusDefaultValue( "health-deficit", {type = "health-deficit", color
local textDeath = L["DEAD"]
local textGhost = L["GHOST"]
local dead_cache = {}
local units_to_fix = {}

Death.GetColor = Grid2.statusLibrary.GetColor

local function DeathUpdateUnit(_, unit, noUpdate)
if unit then
if unit_is_valid[unit] then
local new = UnitIsDeadOrGhost(unit) and (UnitIsGhost(unit) and textGhost or textDeath) or false
if (not new) and UnitHealth(unit)<=0 and not units_to_fix[unit] then
Death:FixDeathBug(unit) -- see ticket #907
end
if new ~= dead_cache[unit] then
dead_cache[unit] = new
if not noUpdate then
Expand All @@ -426,6 +434,23 @@ local function DeathUpdateUnit(_, unit, noUpdate)
end
end

local function DeathTimerEvent()
local updateFunc = HealthCurrent.enabled and HealthCurrent.dbx.deadAsFullHealth and HealthCurrent.UpdateIndicators
for unit in next, units_to_fix do
DeathUpdateUnit(nil, unit)
if updateFunc then updateFunc(HealthCurrent,unit) end
end
wipe(units_to_fix)
end

function Death:FixDeathBug(unit)
if not next(units_to_fix) then
C_Timer_After(0.05, DeathTimerEvent)
end
units_to_fix[unit] = true
Grid2:Debug("Fixing possible death bug (ticket #907) for unit:", unit)
end

function Death:Grid_UnitUpdated(_, unit)
DeathUpdateUnit(_, unit, true)
end
Expand Down
11 changes: 7 additions & 4 deletions modules/StatusShields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Grid2:DbSetStatusDefaultValue( "shields", { type = "shields", thresholdMedium =
local Overflow = Grid2.statusPrototype:new("shields-overflow")

local overflow_cache = {}
local unit_is_valid = Grid2.unit_is_valid

Overflow.GetColor = Grid2.statusLibrary.GetColor

Expand All @@ -112,10 +113,12 @@ function Overflow:OnDisable()
end

function Overflow:UpdateUnit(event, unit)
local v = UnitHealth(unit) + (UnitGetTotalAbsorbs(unit) or 0)
local m = UnitHealthMax(unit)
overflow_cache[unit] = v>m and (v-m)/m or nil
if event~='Grid_UnitUpdated' then self:UpdateIndicators(unit) end
if unit_is_valid[unit] then
local v = UnitHealth(unit) + (UnitGetTotalAbsorbs(unit) or 0)
local m = UnitHealthMax(unit)
overflow_cache[unit] = v>m and (v-m)/m or nil
if event~='Grid_UnitUpdated' then self:UpdateIndicators(unit) end
end
end

function Overflow:GetPercent(unit)
Expand Down

0 comments on commit a2a17dc

Please sign in to comment.