Skip to content

Commit

Permalink
update regarding widget:UnitDestroyed changes (#4257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwetuin authored Jan 30, 2025
1 parent 31e137c commit 10d0a19
Show file tree
Hide file tree
Showing 22 changed files with 56 additions and 78 deletions.
26 changes: 13 additions & 13 deletions luaui/Widgets/api_unit_tracker_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID, reason, sile
-- So, to prevent zero build progress from further turning into problematic things
-- we will suppress the createunit for any unit that is spawned at full health, and only fire its unitfinished version.
-- So we are relying on UnitFinished to be called right after this one
-- Sensibly enough, this is not a problem for players, as they see the units only after their LOS status is checked, later in the same gameframe.
-- Sensibly enough, this is not a problem for players, as they see the units only after their LOS status is checked, later in the same gameframe.
-- So spectators, and 'own team' suffers this hit only
local health,maxhealth, paralyzeDamage,captureProgress,buildProgress = spGetUnitHealth(unitID)
if health == maxhealth and buildProgress == 0 then
if debuglevel >= 3 then
if health == maxhealth and buildProgress == 0 then
if debuglevel >= 3 then
Spring.Echo("Skipping visibleUnitsAdd for CreateUnit'ed unit", UnitDefs[unitDefID].name, unitID, unitDefID, unitTeam, builderID, reason, silent)
end
return
return
end

-- alliedunits
Expand All @@ -378,10 +378,10 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID, reason, sile
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam, reason)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID, reason)
if debuglevel >= 3 then
unitDefID = unitDefID or spGetUnitDefID(unitID)
Spring.Echo("UnitDestroyed",unitID, unitDefID and UnitDefs[unitDefID].name, unitTeam, reason)
Spring.Echo("UnitDestroyed",unitID, unitDefID and UnitDefs[unitDefID].name, unitTeam, nil, nil, nil, nil, reason)
end
visibleUnitsRemove(unitID, reason or "destroyed")
alliedUnitsRemove(unitID, reason or "destroyed")
Expand All @@ -398,15 +398,15 @@ end
--end

function widget:UnitFinished(unitID, unitDefID, unitTeam) -- todo, this should probably add-remove a unit
widget:UnitDestroyed(unitID, unitDefID, unitTeam, "UnitFinished")
widget:UnitDestroyed(unitID, unitDefID, unitTeam, nil, nil, nil, nil, "UnitFinished")
widget:UnitCreated(unitID, unitDefID, unitTeam, nil, "UnitFinished")
if unitTeam == myTeamID and factoryUnitDefIDs[unitDefID] then
widgetHandler:AddSpadsMessage("UnitFinished:"..tostring(factoryUnitDefIDs[unitDefID]))
end
end

function widget:UnitTaken(unitID, unitDefID, oldTeam, newTeam) --1. this is only called when one if my units gets captured
widget:UnitDestroyed(unitID, unitDefID, oldTeam, "UnitTaken")
widget:UnitDestroyed(unitID, unitDefID, oldTeam, nil, nil, nil, nil, "UnitTaken")
-- not needed, as the unit will call enemyenteredlos, but what if we are spec?
if not fullview then
-- todo, look at this real closely if its even needed!
Expand All @@ -415,7 +415,7 @@ function widget:UnitTaken(unitID, unitDefID, oldTeam, newTeam) --1. this is onl
end

function widget:UnitGiven(unitID, unitDefID, newTeam, oldTeam) --2. this is only called when my team captures a unit
widget:UnitDestroyed(unitID, unitDefID, oldTeam, "UnitGiven") -- to ensure that team changes will trigger from this!
widget:UnitDestroyed(unitID, unitDefID, oldTeam, nil, nil, nil, nil, "UnitGiven") -- to ensure that team changes will trigger from this!
widget:UnitCreated(unitID, unitDefID, newTeam, nil, "UnitGiven")
end

Expand Down Expand Up @@ -451,7 +451,7 @@ end

function widget:UnitLeftLos(unitID, unitTeam, allyTeam, unitDefID)
if not fullview then
widget:UnitDestroyed(unitID, unitDefID, unitTeam, "UnitLeftLos")
widget:UnitDestroyed(unitID, unitDefID, unitTeam, nil, nil, nil, nil, "UnitLeftLos")
end
end

Expand Down Expand Up @@ -792,14 +792,14 @@ function widget:AddConsoleLine(lines, priority)
engineVersion = tostring(Engine.versionFull), -- full complete engine version string
mapName = tostring(Game.mapName), -- full map name
gameID = tostring(Game.gameID and Game.gameID or Spring.GetGameRulesParam("GameID")), -- gameID parameter, not the same as server_match_id, we will match that in teiserver
frame = frameNumber, -- the frame where it happened.
frame = frameNumber, -- the frame where it happened.
gotChecksum = gotChecksum,
correctChecksum = correctChecksum,
}
--Spring.Echo(jsondict)

local complex_match_event = string.format("complex-match-event:%s", string.base64Encode(Json.encode(jsondict)))

-- We will be forwarding this as a complex event:
-- sayPrivate complex-match-event <Beherith> <desyncreport> <67> <eyJrZXkiOiJ2YWx1ZSJ9>
-- !sendLobby SAYPRIVATE AutohostMonitor 'complex-match-event <[teh]Beherith> <desyncreport> <67> <eyJrZXkiOiJ2YWx1ZSJ9>'
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/cmd_no_duplicate_orders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function widget:UnitFinished(unitID, unitDefID, unitTeam)
buildList[locString] = nil
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
local locString = toLocString(GetUnitPosition(unitID))
buildList[locString] = nil
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/dbg_ffa_startpoints_picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ local function removeStartPoint(unitID, unitDefID)
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
removeStartPoint(unitID, unitDefID)
end

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/dbg_unit_callins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function widget:UnitFromFactory(unitID, unitDefID, unitTeam, factID, factDefID,

end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if enabledcallins.UnitDestroyed == nil then return end
if printcallins then Spring.Echo("w:UnitDestroyed",unitID, unitDefID and UnitDefs[unitDefID].name, unitTeam) end
if showcallins then addEvent(unitID, "UnitDestroyed") end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gfx_airjets_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam)
AddUnit(unitID, unitDefID, unitTeam)
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
--Spring.Echo("UnitDestroyed(unitID, unitDefID, unitTeam)",unitID, unitDefID, unitTeam)
RemoveUnit(unitID, unitDefID, unitTeam)
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_advplayerslist_music_new.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,6 @@ function widget:UnitFinished()
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)

end
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_build_eta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam)
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
etaTable[unitID] = nil
end

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_buildbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function widget:UnitGiven(unitID, unitDefID, unitTeam, oldTeam)
widget:UnitCreated(unitID, unitDefID, unitTeam)
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if unitTeam ~= myTeamID then
return
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_com_nametags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam)
CheckCom(unitID, unitDefID, unitTeam)
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
comms[unitID] = nil
end

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_emp_decloak_range.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function widget:UnitFinished(unitID, unitDefID, unitTeam)
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if units[unitID] then
units[unitID] = nil
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_geothermalspots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if extractors[unitDefID] then
sceduledCheckedSpotsFrame = Spring.GetGameFrame() + 3 -- delay needed, i don't know why
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_metalspots.lua
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID) -- THIS IS F
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam) -- THIS IS RETARDED TOO
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID) -- THIS IS RETARDED TOO
if extractorDefs[unitDefID] then
sceduledCheckedSpotsFrame = Spring.GetGameFrame() + 3 -- delay needed, i don't know why
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_rank_icons_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam)
end
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
unitRanks[unitID] = nil
RemovePrimitive(unitID, "UnitDestroyed")
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_sensor_ranges_jammer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function removeUnit(unitID)
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
removeUnit(unitID)
end

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_sensor_ranges_radar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function widget:Shutdown()
WG.radarrange = nil
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if unitList[unitID] then
unitList[unitID] = nil
activeUnits[unitID] = nil
Expand Down
68 changes: 23 additions & 45 deletions luaui/Widgets/gui_sensor_ranges_sonar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ void main() {


local function goodbye(reason)
Spring.Echo("Sensor Ranges Sonar widget exiting with reason: "..reason)
widgetHandler:RemoveWidget()
Spring.Echo("Sensor Ranges Sonar widget exiting with reason: "..reason)
widgetHandler:RemoveWidget()
end

local function initgl4()
Expand All @@ -137,15 +137,15 @@ local function initgl4()
fsSrc = fsSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs)
circleShader = LuaShader(
{
vertex = vsSrc:gsub("//__DEFINES__", "#define MYGRAVITY "..tostring(Game.gravity+0.1)),
fragment = fsSrc:gsub("//__DEFINES__", "#define USE_STIPPLE ".. tostring(usestipple) ),
--geometry = gsSrc, no geom shader for now
uniformInt = {
heightmapTex = 0,
},
uniformFloat = {
circleopacity = {1},
},
vertex = vsSrc:gsub("//__DEFINES__", "#define MYGRAVITY "..tostring(Game.gravity+0.1)),
fragment = fsSrc:gsub("//__DEFINES__", "#define USE_STIPPLE ".. tostring(usestipple) ),
--geometry = gsSrc, no geom shader for now
uniformInt = {
heightmapTex = 0,
},
uniformFloat = {
circleopacity = {1},
},
},
"sonarrange shader GL4"
)
Expand Down Expand Up @@ -238,33 +238,26 @@ local function processUnit(unitID, unitDefID, noUpload)
if (not (spec and fullview )) and ( not spIsUnitAllied(unitID)) then return end -- display mode for specs

local unitDefID = spGetUnitDefID(unitID)

if not unitRange[unitDefID] then
return
end

local teamID = Spring.GetUnitTeam(unitID)
if teamID == gaiaTeamID then return end -- no gaia units

local x, y, z = spGetUnitPosition(unitID)

local range = unitRange[unitDefID]['range']
local height = unitRange[unitDefID]['height']

unitList[unitID] = unitDefID
activeUnits[unitID] = false
-- shall we jam it straight into the table?
local x, y, z = spGetUnitPosition(unitID)
pushElementInstance(circleInstanceVBO,{x,y,z,0, x,y,z,0,rangeColor[1],rangeColor[2],rangeColor[3],rangeColor[4] },unitID, true, noUpload)

end


function widget:Initialize()
if Spring.GetGroundExtremes() > 50 then
if Spring.GetGroundExtremes() > 50 then
widgetHandler:RemoveWidget()
return
end

if not gl.CreateShader then -- no shader support, so just remove the widget itself, especially for headless
widgetHandler:RemoveWidget()
return
Expand Down Expand Up @@ -292,12 +285,12 @@ function widget:Shutdown()
WG.sonarrange = nil
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
if unitList[unitID] then
unitList[unitID] = nil
activeUnits[unitID] = nil
popElementInstance(circleInstanceVBO,unitID)
end
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if unitList[unitID] then
unitList[unitID] = nil
activeUnits[unitID] = nil
popElementInstance(circleInstanceVBO,unitID)
end
end

function widget:UnitTaken(unitID, unitDefID, unitTeam, newTeam)
Expand All @@ -312,8 +305,6 @@ function widget:UnitFinished( unitID, unitDefID, unitTeam)
processUnit( unitID, unitDefID )
end



function widget:GameFrame(n)
if spec and fullview then return end
if n % 15 == 0 then -- this 15 frames is important, as the vertex shader is interpolating at this rate too!
Expand All @@ -323,32 +314,20 @@ function widget:GameFrame(n)
if not isBuilding[unitDefID] then
local x, y, z = spGetUnitPosition(unitID)


for i=instanceDataOffset + 1, instanceDataOffset+4 do
instanceData[i] = instanceData[i+4]
end
instanceData[instanceDataOffset+5] = x
instanceData[instanceDataOffset+6] = y
instanceData[instanceDataOffset+7] = z

end


local range = unitRange[unitDefID]['range']
local active = spGetUnitIsActive(unitID)
if active then
instanceData[instanceDataOffset+8] = range
else
instanceData[instanceDataOffset+8] = 0
end
if activeUnits[unitID] then
instanceData[instanceDataOffset+4] = range
else
instanceData[instanceDataOffset+4] = 0
end
instanceData[instanceDataOffset+8] = active and range or 0
instanceData[instanceDataOffset+4] = activeUnits[unitID] and range or 0
activeUnits[unitID] = active


--pushElementInstance(circleInstanceVBO,instanceData,unitID, true, true) -- overwrite data and dont upload!, but i am scum and am directly modifying the table
end
uploadAllElements(circleInstanceVBO)
Expand All @@ -362,7 +341,6 @@ function widget:DrawWorld()

if circleInstanceVBO.usedElements == 0 then return end


if opacity < 0.01 then return end
glColorMask(false, false, false, false)
glStencilTest(true)
Expand Down Expand Up @@ -393,7 +371,7 @@ function widget:DrawWorld()
glColor(rangeColor[1], rangeColor[2], rangeColor[3], rangeColor[4])
glLineWidth(rangeLineWidth * lineScale * 1.0)
--Spring.Echo("glLineWidth",rangeLineWidth * lineScale * 1.0)

--gl.DepthMask(false)
glDepthTest(true)
circleInstanceVBO.VAO:DrawArrays(GL_LINE_LOOP, circleInstanceVBO.numVertices, 0, circleInstanceVBO.usedElements, 0)
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_top_bar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam)
comcountChanged = true
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if not isCommander[unitDefID] then
return
end
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/gui_unit_market.lua
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ function widget:TextCommand(command)
end
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
ClearUnitData(unitID)
end

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/map_grass_gl4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam)
end


function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if processChanges and not placementMode and buildingRadius[unitDefID] then
removeUnitGrassQueue[unitID] = nil
unitGrassRemovedHistory[unitID] = nil
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/unit_auto_cloak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function widget:UnitFinished(unitID, unitDefID, unitTeam)
cloakActive(unitID, unitDefID)
end

function widget:UnitDestroyed(unitID, unitDefID, unitTeam)
function widget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam, weaponDefID)
if cloakunits[unitID] then
cloakunits[unitID] = nil
end
Expand Down
Loading

0 comments on commit 10d0a19

Please sign in to comment.