Skip to content

Commit 2814fb9

Browse files
committed
Only update cloak linger when required.
Rename variables for clarity.
1 parent 1212188 commit 2814fb9

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

LuaRules/Gadgets/cus_gl4.lua

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,9 @@ local featuresDefsWithAlpha = {} -- featureDefIDs (ie trees) that should be draw
348348
local unitDefsUseSkinning = {} -- unitDefIDs that use the bones and stretchy skin system
349349

350350
local ENEMY_CLOAK_FRAMES = 10 -- How many extra frames to show enemy units for.
351-
local cloakDeferFrame = {}
352-
local keepDrawFlagChecking = false -- a list of units that need draw flag checking
351+
local cloakLingerUnitFrame = {}
352+
local cloakLingerUnitList = false -- a list of units that need draw flag checking
353+
local nextLingerUpdate = false
353354

354355
local spGetUnitIsCloaked = Spring.GetUnitIsCloaked
355356

@@ -1428,18 +1429,19 @@ end
14281429
local function ProcessCusUnit(unitID, drawFlag, gameFrame, reason)
14291430
if debugmode then Spring.Echo("ProcessUnits", unitID, drawFlag, reason) end
14301431

1431-
if cloakDeferFrame[unitID] and ((not drawFlag) or drawFlag == 0) then
1432-
if cloakDeferFrame[unitID] < gameFrame then
1433-
cloakDeferFrame[unitID] = nil
1432+
if cloakLingerUnitFrame[unitID] and ((not drawFlag) or drawFlag == 0) then
1433+
if cloakLingerUnitFrame[unitID] <= gameFrame then
1434+
cloakLingerUnitFrame[unitID] = nil
14341435
end
14351436
if not Spring.ValidUnitID(unitID) then
1436-
cloakDeferFrame[unitID] = nil
1437+
cloakLingerUnitFrame[unitID] = nil
14371438
return
14381439
end
1439-
if cloakDeferFrame[unitID] then
1440+
if cloakLingerUnitFrame[unitID] then
14401441
drawFlag = 1
1441-
keepDrawFlagChecking = keepDrawFlagChecking or {}
1442-
keepDrawFlagChecking[#keepDrawFlagChecking + 1] = unitID
1442+
cloakLingerUnitList = cloakLingerUnitList or {}
1443+
cloakLingerUnitList[#cloakLingerUnitList + 1] = unitID
1444+
nextLingerUpdate = nextLingerUpdate and math.min(nextLingerUpdate, cloakLingerUnitFrame[unitID]) or cloakLingerUnitFrame[unitID]
14431445
else
14441446
Spring.SetUnitAlwaysUpdateMatrix(unitID, false)
14451447
end
@@ -2075,9 +2077,10 @@ function gadget:UnitCloaked(unitID)
20752077
wantTranparent[unitID] = true
20762078
if not allyUnit then
20772079
Spring.SetUnitAlwaysUpdateMatrix(unitID, true)
2078-
keepDrawFlagChecking = keepDrawFlagChecking or {}
2079-
keepDrawFlagChecking[#keepDrawFlagChecking + 1] = unitID
2080-
cloakDeferFrame[unitID] = frame + ENEMY_CLOAK_FRAMES
2080+
cloakLingerUnitList = cloakLingerUnitList or {}
2081+
cloakLingerUnitList[#cloakLingerUnitList + 1] = unitID
2082+
cloakLingerUnitFrame[unitID] = frame + ENEMY_CLOAK_FRAMES
2083+
nextLingerUpdate = nextLingerUpdate and math.min(nextLingerUpdate, cloakLingerUnitFrame[unitID]) or cloakLingerUnitFrame[unitID]
20812084
end
20822085
else
20832086
uniformCache[1] = frame
@@ -2149,8 +2152,8 @@ function gadget:DrawWorldPreUnit()
21492152
-- Spring.Echo(printDrawPassStats())
21502153
--end
21512154
local totalobjects = #units + #features + numdestroyedUnits + numdestroyedFeatures
2152-
if keepDrawFlagChecking then
2153-
totalobjects = totalobjects + #keepDrawFlagChecking
2155+
if cloakLingerUnitList and ((not nextLingerUpdate) or nextLingerUpdate >= gameFrame) then
2156+
totalobjects = totalobjects + #cloakLingerUnitList
21542157
end
21552158

21562159
-- Why do we also do this processing round if #units > 0?
@@ -2198,9 +2201,10 @@ function gadget:DrawWorldPreUnit()
21982201
end
21992202

22002203
ProcessUnits(units, drawFlagsUnits, gameFrame, "changed")
2201-
if keepDrawFlagChecking then
2202-
local checkUnits = keepDrawFlagChecking
2203-
keepDrawFlagChecking = false
2204+
if cloakLingerUnitList and ((not nextLingerUpdate) or nextLingerUpdate >= gameFrame) then
2205+
local checkUnits = cloakLingerUnitList
2206+
cloakLingerUnitList = false
2207+
nextLingerUpdate = false
22042208
ProcessUnits(checkUnits, false, gameFrame, "changed")
22052209
end
22062210
ProcessFeatures(features, drawFlagsFeatures, "changed")

0 commit comments

Comments
 (0)