-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1203 from Crystalwarrior/fix-smoke-memory
Fix clear-smoke memory leaks
- Loading branch information
Showing
3 changed files
with
31 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
-- Removes all smoke from the map | ||
--@module = true | ||
|
||
--[====[ | ||
clear-smoke | ||
=========== | ||
Removes all smoke from the map. Note that this can leak memory and should be | ||
used sparingly. | ||
function removeFlow(flow) --have DF remove the flow | ||
if not flow then | ||
return | ||
end | ||
flow.flags.DEAD = true | ||
|
||
]====] | ||
local block = dfhack.maps.getTileBlock(flow.pos) | ||
if block then | ||
block.flow_pool.flags.active = true | ||
else | ||
df.global.world.orphaned_flow_pool.flags.active = true | ||
end | ||
end | ||
|
||
function clearSmoke(flows) | ||
for i = #flows - 1, 0, -1 do | ||
if flows[i].type == df.flow_type.Smoke then | ||
flows:erase(i) | ||
function removeFlows(flow_type) --remove all if flow_type is nil | ||
local count = 0 | ||
for _,flow in ipairs(df.global.flows) do | ||
if not flow.flags.DEAD and (flow_type == nil or flow.type == flow_type) then | ||
removeFlow(flow) | ||
count = count + 1 | ||
end | ||
end | ||
|
||
return count | ||
end | ||
|
||
clearSmoke(df.global.flows) | ||
function clearSmoke() | ||
if dfhack.isWorldLoaded() then | ||
print(('%d smoke flows removed.'):format(removeFlows(df.flow_type.Smoke))) | ||
else | ||
qerror('World not loaded!') | ||
end | ||
end | ||
|
||
for _, block in pairs(df.global.world.map.map_blocks) do | ||
clearSmoke(block.flows) | ||
if not dfhack_flags.module then | ||
clearSmoke() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters