Repeatedly removing and adding the same overlay with only an alpha change causes oddities with map chunks
https://tgstation13.org/msoshit/2016-04-30-0524-06.flv example.
This was triggered by a change in how the purple confetti like overlay that represents the gas called "plasma" in our atmos system, was done to make it change the alpha of the gas overlay based on how much there was.
old code:
/turf/open/proc/update_visuals()
var/list/new_overlay_types = tile_graphic()
for(var/overlay in atmos_overlay_types-new_overlay_types) //doesn't remove overlays that would only be added
overlays -= overlay
atmos_overlay_types -= overlay
for(var/overlay in new_overlay_types-atmos_overlay_types) //doesn't add overlays that already exist
overlays += overlay
atmos_overlay_types = new_overlay_types
/turf/open/proc/tile_graphic()
. = new /list
var/list/gases = air.gases
for(var/id in gases)
var/gas = gases[id]
if(gas[GAS_META][META_GAS_OVERLAY] && gas[MOLES] > gas[GAS_META][META_GAS_MOLES_VISIBLE])
. += gas[GAS_META][META_GAS_OVERLAY]
new code:
/turf/open/proc/update_visuals()
var/list/new_overlay_types = tile_graphic()
for(var/overlay in atmos_overlay_types-new_overlay_types) //doesn't remove overlays that would only be added
overlays -= overlay
atmos_overlay_types -= overlay
for(var/overlay in new_overlay_types-atmos_overlay_types)
var/atom/A = overlay
if (isnull(atmos_overlay_types[overlay]))
A.alpha = new_overlay_types[overlay]
overlays += overlay //New
else if (new_overlay_types[overlay] == atmos_overlay_types[overlay])
continue //Unchanged
else
//changed
overlays -= overlay
A.alpha = new_overlay_types[overlay]
overlays += overlay
atmos_overlay_types = new_overlay_types
/turf/open/proc/tile_graphic()
. = new /list
var/list/gases = air.gases
for(var/id in gases)
var/gas = gases[id]
if(gas[GAS_META][META_GAS_OVERLAY])
.[gas[GAS_META][META_GAS_OVERLAY]] = tile_graphic_alpha(gas[GAS_META], gas[MOLES])
/turf/open/proc/tile_graphic_alpha(list/meta, moles)
return Clamp(255/meta[META_GAS_MOLES_VISIBLE]*moles,0,255)
There are some obvious bugs with this, (it doesn't round the alpha, so it would almost always be seen as changed.) and i haven't tested rather or not removing then re-adding the overlay is needed (re-adding might just work) but it seems to cause the issue in the video above.
I took a look at the video, and the way turfs are disappearing like that, that looks like potentially some kind of view anomaly. Chunks don't control whether turfs are shown or not, unless they're "extended" turfs with out-of-bounds objects on them, and even then the turf itself should not be made visible inappropriately; what you're seeing looks like turfs that should be visible disappearing.
I strongly suspect this issue is not beta-related, but I even more strongly I think I'm unlikely to make any headway on this without a test case. This is something I'm going to have to puzzle over in the debugger for sure. Is there any way you can strip down a test case?