Merge pull request #8590 from Spookerton/spkrtn/fix/lingering-overlay-odds

fix overlay odds
This commit is contained in:
Atermonera
2022-04-30 15:30:46 -08:00
committed by GitHub
3 changed files with 381 additions and 385 deletions

View File

@@ -1,242 +1,239 @@
SUBSYSTEM_DEF(overlays) SUBSYSTEM_DEF(overlays)
name = "Overlay" name = "Overlay"
flags = SS_TICKER flags = SS_TICKER
wait = 1 // SS_TICKER - Ticks wait = 1 // SS_TICKER - Ticks
priority = FIRE_PRIORITY_OVERLAYS priority = FIRE_PRIORITY_OVERLAYS
init_order = INIT_ORDER_OVERLAY init_order = INIT_ORDER_OVERLAY
/// The queue of atoms that need overlay updates. /// The queue of atoms that need overlay updates.
var/static/tmp/list/queue = list() var/static/tmp/list/queue = list()
/// An image used to create appearances to be cached. /// A list([icon] = list([state] = [appearance], ...), ...) cache of appearances.
var/static/tmp/image/renderer = new var/static/tmp/list/state_cache = list()
/// A list([icon] = list([state] = [appearance], ...), ...) cache of appearances. /// A list([icon] = [appearance], ...) cache of appearances.
var/static/tmp/list/state_cache = list() var/static/tmp/list/icon_cache = list()
/// A list([icon] = [appearance], ...) cache of appearances. /// The number of appearances currently cached.
var/static/tmp/list/icon_cache = list() var/static/tmp/cache_size = 0
/// The number of appearances currently cached.
var/static/tmp/cache_size = 0 /datum/controller/subsystem/overlays/Recover()
queue.Cut()
state_cache.Cut()
/datum/controller/subsystem/overlays/Recover() icon_cache.Cut()
queue.Cut() cache_size = 0
renderer = new for (var/atom/atom)
state_cache.Cut() atom.flags &= ~OVERLAY_QUEUED
icon_cache.Cut() CHECK_TICK
cache_size = 0
/datum/controller/subsystem/overlays/Initialize(timeofday)
/datum/controller/subsystem/overlays/Initialize(timeofday) fire(FALSE, TRUE)
fire(FALSE, TRUE)
/datum/controller/subsystem/overlays/stat_entry()
/datum/controller/subsystem/overlays/stat_entry() ..("Queued Atoms: [queue.len], Cache Size: [cache_size]")
..("Queued Atoms: [queue.len], Cache Size: [cache_size]")
/datum/controller/subsystem/overlays/fire(resumed, no_mc_tick)
/datum/controller/subsystem/overlays/fire(resumed, no_mc_tick) var/count = 1
var/count = 1 for (var/atom/atom as anything in queue)
for (var/atom/atom as anything in queue) ++count
++count atom?.UpdateOverlays()
atom?.UpdateOverlays() if (no_mc_tick)
if (no_mc_tick) CHECK_TICK
CHECK_TICK else if (MC_TICK_CHECK)
else if (MC_TICK_CHECK) queue.Cut(count)
queue.Cut(count) return
return queue.Cut()
queue.Cut()
/datum/controller/subsystem/overlays/proc/GetStateAppearance(icon, state)
/datum/controller/subsystem/overlays/proc/GetStateAppearance(icon, state) var/list/subcache = state_cache[icon]
var/list/subcache = state_cache[icon] if (!subcache)
if (!subcache) subcache = list()
subcache = list() state_cache[icon] = subcache
state_cache[icon] = subcache if (!subcache[state])
if (!subcache[state]) var/image/image = new (icon, null, state)
renderer.icon = icon subcache[state] = image.appearance
renderer.icon_state = state ++cache_size
subcache[state] = renderer.appearance return subcache[state]
++cache_size
return subcache[state]
/datum/controller/subsystem/overlays/proc/GetIconAppearance(icon)
if (!icon_cache[icon])
/datum/controller/subsystem/overlays/proc/GetIconAppearance(icon) var/image/image = new (icon)
if (!icon_cache[icon]) icon_cache[icon] = image.appearance
renderer.icon = icon ++cache_size
icon_cache[icon] = renderer.appearance return icon_cache[icon]
++cache_size
return icon_cache[icon]
/datum/controller/subsystem/overlays/proc/GetAppearanceList(atom/subject, list/sources)
if (!sources)
/datum/controller/subsystem/overlays/proc/GetAppearanceList(atom/subject, list/sources) return list()
if (!sources) if (!islist(sources))
return list() sources = list(sources)
if (!islist(sources)) var/list/result = list()
sources = list(sources) var/icon/icon = subject.icon
var/image/image for (var/atom/entry as anything in sources)
var/list/result = list() if (!entry)
var/icon/icon = subject.icon continue
for (var/atom/entry as anything in sources) else if (istext(entry))
if (!entry) result += GetStateAppearance(icon, entry)
continue else if (isicon(entry))
else if (istext(entry)) result += GetIconAppearance(entry)
result += GetStateAppearance(icon, entry) else
else if (isicon(entry)) if (isloc(entry))
result += GetIconAppearance(entry) if (entry.flags & OVERLAY_QUEUED)
else entry.ImmediateOverlayUpdate()
if (isloc(entry)) if (!ispath(entry))
if (entry.flags & OVERLAY_QUEUED) result += entry.appearance
entry.ImmediateOverlayUpdate() else
renderer.appearance = entry var/image/image = entry
if (!ispath(entry)) result += image.appearance
image = entry return result
renderer.dir = image.dir
result += renderer.appearance
return result /// Enqueues the atom for an overlay update if not already queued
/atom/proc/QueueOverlayUpdate()
if (flags & OVERLAY_QUEUED)
/// Enqueues the atom for an overlay update if not already queued return
/atom/proc/QueueOverlayUpdate() SSoverlays.queue += src
if (flags & OVERLAY_QUEUED) flags |= OVERLAY_QUEUED
return
SSoverlays.queue += src
flags |= OVERLAY_QUEUED /// Builds the atom's overlay state from caches
/atom/proc/UpdateOverlays()
if (gc_destroyed)
/// Builds the atom's overlay state from caches if (length(overlays))
/atom/proc/UpdateOverlays() overlays.Cut()
if (gc_destroyed) return
if (length(overlays)) flags &= ~OVERLAY_QUEUED
overlays.Cut() if (length(priority_overlays))
return if (length(our_overlays))
flags &= ~OVERLAY_QUEUED overlays = priority_overlays + our_overlays
if (length(priority_overlays)) else
if (length(our_overlays)) overlays = priority_overlays
overlays = priority_overlays + our_overlays else if (length(our_overlays))
else overlays = our_overlays
overlays = priority_overlays else
else if (length(our_overlays)) overlays.Cut()
overlays = our_overlays
else
overlays.Cut() /// Immediately runs an overlay update and dequeues the atom
/atom/proc/ImmediateOverlayUpdate()
SSoverlays.queue -= src
/// Immediately runs an overlay update and dequeues the atom UpdateOverlays()
/atom/proc/ImmediateOverlayUpdate()
SSoverlays.queue -= src
UpdateOverlays() /// Clears the atom's overlay cache(s) and queues an update if needed
/atom/proc/cut_overlays(priority)
if (priority)
/// Clears the atom's overlay cache(s) and queues an update if needed if (!length(priority_overlays))
/atom/proc/cut_overlays(priority) return
if (priority) priority_overlays.Cut()
if (!length(priority_overlays)) QueueOverlayUpdate()
return else if (length(our_overlays))
priority_overlays.Cut() our_overlays.Cut()
QueueOverlayUpdate() QueueOverlayUpdate()
else if (length(our_overlays))
our_overlays.Cut()
QueueOverlayUpdate() /**
* Adds specific overlay(s) to the atom.
* It is designed so any of the types allowed to be added to /atom/overlays can be added here too. More details below.
/** *
* Adds specific overlay(s) to the atom. * @param add The overlay(s) to add. These may be
* It is designed so any of the types allowed to be added to /atom/overlays can be added here too. More details below. * - A string: In which case it is treated as an icon_state of the atom's icon.
* * - An icon: It is treated as an icon.
* @param add The overlay(s) to add. These may be * - An atom: Its own overlays are compiled and then it's appearance is added. (Meaning its current apperance is frozen).
* - A string: In which case it is treated as an icon_state of the atom's icon. * - An image: Image's apperance is added (i.e. subsequently editing the image will not edit the overlay)
* - An icon: It is treated as an icon. * - A type path: Added to overlays as is. Does whatever it is BYOND does when you add paths to overlays.
* - An atom: Its own overlays are compiled and then it's appearance is added. (Meaning its current apperance is frozen). * - Or a list containing any of the above.
* - An image: Image's apperance is added (i.e. subsequently editing the image will not edit the overlay) * @param priority The overlays are added to the "priority" list istead of the normal one.
* - A type path: Added to overlays as is. Does whatever it is BYOND does when you add paths to overlays. */
* - Or a list containing any of the above. /atom/proc/add_overlay(list/add, priority)
* @param priority The overlays are added to the "priority" list istead of the normal one. if (!add)
*/ return
/atom/proc/add_overlay(list/add, priority) add = SSoverlays.GetAppearanceList(src, add)
if (!add) if (!length(add))
return return
add = SSoverlays.GetAppearanceList(src, add) if (priority)
if (!length(add)) if (priority_overlays)
return priority_overlays += add
if (priority) else
if (priority_overlays) priority_overlays = add
priority_overlays += add else if (our_overlays)
else our_overlays += add
priority_overlays = add else
else if (our_overlays) our_overlays = add
our_overlays += add QueueOverlayUpdate()
else
our_overlays = add
QueueOverlayUpdate() /**
* Removes specific overlay(s) from the atom. Usually does not remove them from "priority" overlays.
*
/** * @param overlays The overlays to removed, type can be anything that is allowed for add_overlay().
* Removes specific overlay(s) from the atom. Usually does not remove them from "priority" overlays. * @param priority If true, also will remove them from the "priority" overlays.
* */
* @param overlays The overlays to removed, type can be anything that is allowed for add_overlay(). /atom/proc/cut_overlay(list/cut, priority)
* @param priority If true, also will remove them from the "priority" overlays. if (!cut)
*/ return
/atom/proc/cut_overlay(list/cut, priority) cut = SSoverlays.GetAppearanceList(src, cut)
if (!cut) if (!length(cut))
return return
cut = SSoverlays.GetAppearanceList(src, cut) var/update
if (!length(cut)) if (priority && length(priority_overlays))
return priority_overlays -= cut
var/update update = TRUE
if (priority && length(priority_overlays)) if (length(our_overlays))
priority_overlays -= cut our_overlays -= cut
update = TRUE update = TRUE
if (length(our_overlays)) if (update)
our_overlays -= cut QueueOverlayUpdate()
update = TRUE
if (update)
QueueOverlayUpdate() /**
* Copy the overlays from another atom, either replacing all of ours or appending to our existing overlays.
* Note: This copies only the normal overlays, not the "priority" overlays.
/** *
* Copy the overlays from another atom, either replacing all of ours or appending to our existing overlays. * @param other The atom to copy overlays from.
* Note: This copies only the normal overlays, not the "priority" overlays. * @param cut_old If true, all of our overlays will be *replaced* by the other's. If other is null, that means cutting all ours.
* */
* @param other The atom to copy overlays from. /atom/proc/copy_overlays(atom/other, cut)
* @param cut_old If true, all of our overlays will be *replaced* by the other's. If other is null, that means cutting all ours. if (!other)
*/ if (cut)
/atom/proc/copy_overlays(atom/other, cut) cut_overlays()
if (!other) return
if (cut) if (!length(other.our_overlays))
cut_overlays() if (cut)
return cut_overlays()
if (!length(other.our_overlays)) return
if (cut) if (cut || !length(our_overlays))
cut_overlays() our_overlays = other.our_overlays.Copy()
return else
if (cut || !length(our_overlays)) our_overlays |= other.our_overlays
our_overlays = other.our_overlays.Copy() QueueOverlayUpdate()
else
our_overlays |= other.our_overlays
QueueOverlayUpdate() /**
* Returns a list of overlays that the target atom has
*
/** * @param priority If true, returns priority overlays as well
* Returns a list of overlays that the target atom has * @param special If true, returns special overlays like emissives and em_blockers
* */
* @param priority If true, returns priority overlays as well /proc/get_overlays(atom/other, priority, special)
* @param special If true, returns special overlays like emissives and em_blockers var/list/including = list()
*/ if (!other)
/proc/get_overlays(atom/other, priority, special) return including
var/list/including = list() for (var/image/I as anything in other.our_overlays)
if (!other) if (!special && I.plane > 0)
return including continue
for (var/image/I as anything in other.our_overlays) including += I
if (!special && I.plane > 0) if (!priority)
continue return including
including += I for (var/image/I as anything in other.priority_overlays)
if (!priority) if (!special && I.plane > 0)
return including continue
for (var/image/I as anything in other.priority_overlays) including += I
if (!special && I.plane > 0) return including
continue
including += I
return including

View File

@@ -1,51 +1,50 @@
/obj/structure/closet/secure_closet/guncabinet /obj/structure/closet/secure_closet/guncabinet
name = "gun cabinet" name = "gun cabinet"
icon = 'icons/obj/guncabinet.dmi' icon = 'icons/obj/guncabinet.dmi'
icon_state = "base" icon_state = "base"
req_one_access = list(access_armory) req_one_access = list(access_armory)
closet_appearance = null closet_appearance = null
/obj/structure/closet/secure_closet/guncabinet/Initialize() /obj/structure/closet/secure_closet/guncabinet/Initialize()
. = ..() . = ..()
update_icon() update_icon()
/obj/structure/closet/secure_closet/guncabinet/toggle() /obj/structure/closet/secure_closet/guncabinet/toggle()
..() ..()
update_icon() update_icon()
/obj/structure/closet/secure_closet/guncabinet/update_icon() /obj/structure/closet/secure_closet/guncabinet/update_icon()
cut_overlays() cut_overlays()
if(opened) var/list/add = list()
add_overlay("door_open") if (!opened)
else var/energy_count = 0
var/lazors = 0 var/projectile_count = 0
var/shottas = 0 for (var/obj/item/gun/gun in contents)
for (var/obj/item/gun/G in contents) if (istype(gun, /obj/item/gun/energy))
if (istype(G, /obj/item/gun/energy)) ++energy_count
lazors++ else if(istype(gun, /obj/item/gun/projectile))
if (istype(G, /obj/item/gun/projectile)) ++projectile_count
shottas++ for (var/i = 0 to 2)
for (var/i = 0 to 2) if (!energy_count && !projectile_count)
if(lazors || shottas) // only make icons if we have one of the two types. break
var/image/gun = image(icon(src.icon)) var/image/image = new (icon)
if (lazors > shottas) image.pixel_x = i * 4
lazors-- if (energy_count > projectile_count)
gun.icon_state = "laser" image.icon_state = "laser"
else if (shottas) --energy_count
shottas-- else if (projectile_count)
gun.icon_state = "projectile" image.icon_state = "projectile"
gun.pixel_x = i*4 --projectile_count
add_overlay(gun) add += image
add += "door"
add_overlay("door") if (sealed)
add += "sealed"
if(sealed) if (broken)
add_overlay("sealed") add += "broken"
else if (locked)
if(broken) add += "locked"
add_overlay("broken") else
else if (locked) add += "open"
add_overlay("locked") else
else add += "door_open"
add_overlay("open") add_overlay(add)

View File

@@ -1,92 +1,92 @@
//Refreshes the icon and sets the luminosity //Refreshes the icon and sets the luminosity
/obj/machinery/portable_atmospherics/hydroponics/update_icon() /obj/machinery/portable_atmospherics/hydroponics/update_icon()
// Update name. // Update name.
if(seed) if(seed)
if(mechanical) if(mechanical)
name = "[base_name] ([seed.seed_name])" name = "[base_name] ([seed.seed_name])"
else else
name = "[seed.seed_name]" name = "[seed.seed_name]"
else else
name = initial(name) name = initial(name)
if(labelled) if(labelled)
name += " ([labelled])" name += " ([labelled])"
overlays.Cut() cut_overlays()
// Updates the plant overlay. // Updates the plant overlay.
if(!isnull(seed)) if(!isnull(seed))
if(mechanical && health <= (seed.get_trait(TRAIT_ENDURANCE) / 2)) if(mechanical && health <= (seed.get_trait(TRAIT_ENDURANCE) / 2))
add_overlay("over_lowhealth3") add_overlay("over_lowhealth3")
if(dead) if(dead)
var/ikey = "[seed.get_trait(TRAIT_PLANT_ICON)]-dead" var/ikey = "[seed.get_trait(TRAIT_PLANT_ICON)]-dead"
var/image/dead_overlay = plant_controller.plant_icon_cache["[ikey]"] var/image/dead_overlay = plant_controller.plant_icon_cache["[ikey]"]
if(!dead_overlay) if(!dead_overlay)
dead_overlay = image('icons/obj/hydroponics_growing.dmi', "[ikey]") dead_overlay = image('icons/obj/hydroponics_growing.dmi', "[ikey]")
dead_overlay.color = DEAD_PLANT_COLOUR dead_overlay.color = DEAD_PLANT_COLOUR
add_overlay(dead_overlay) add_overlay(dead_overlay)
else else
if(!seed.growth_stages) if(!seed.growth_stages)
seed.update_growth_stages() seed.update_growth_stages()
if(!seed.growth_stages) if(!seed.growth_stages)
to_world("<span class='danger'>Seed type [seed.get_trait(TRAIT_PLANT_ICON)] cannot find a growth stage value.</span>") to_world("<span class='danger'>Seed type [seed.get_trait(TRAIT_PLANT_ICON)] cannot find a growth stage value.</span>")
return return
var/overlay_stage = 1 var/overlay_stage = 1
if(age >= seed.get_trait(TRAIT_MATURATION)) if(age >= seed.get_trait(TRAIT_MATURATION))
overlay_stage = seed.growth_stages overlay_stage = seed.growth_stages
else else
var/maturation = seed.get_trait(TRAIT_MATURATION)/seed.growth_stages var/maturation = seed.get_trait(TRAIT_MATURATION)/seed.growth_stages
if(maturation < 1) if(maturation < 1)
maturation = 1 maturation = 1
overlay_stage = maturation ? max(1,round(age/maturation)) : 1 overlay_stage = maturation ? max(1,round(age/maturation)) : 1
var/ikey = "[seed.get_trait(TRAIT_PLANT_ICON)]-[overlay_stage]" var/ikey = "[seed.get_trait(TRAIT_PLANT_ICON)]-[overlay_stage]"
var/image/plant_overlay = plant_controller.plant_icon_cache["[ikey]-[seed.get_trait(TRAIT_PLANT_COLOUR)]"] var/image/plant_overlay = plant_controller.plant_icon_cache["[ikey]-[seed.get_trait(TRAIT_PLANT_COLOUR)]"]
if(frozen == 1) if(frozen == 1)
plant_overlay = image('icons/obj/hydroponics_growing.dmi', "[ikey]") plant_overlay = image('icons/obj/hydroponics_growing.dmi', "[ikey]")
plant_overlay.color = FROZEN_PLANT_COLOUR plant_overlay.color = FROZEN_PLANT_COLOUR
if(!plant_overlay) if(!plant_overlay)
plant_overlay = image('icons/obj/hydroponics_growing.dmi', "[ikey]") plant_overlay = image('icons/obj/hydroponics_growing.dmi', "[ikey]")
plant_overlay.color = seed.get_trait(TRAIT_PLANT_COLOUR) plant_overlay.color = seed.get_trait(TRAIT_PLANT_COLOUR)
plant_controller.plant_icon_cache["[ikey]-[seed.get_trait(TRAIT_PLANT_COLOUR)]"] = plant_overlay plant_controller.plant_icon_cache["[ikey]-[seed.get_trait(TRAIT_PLANT_COLOUR)]"] = plant_overlay
add_overlay(plant_overlay) add_overlay(plant_overlay)
if(harvest && overlay_stage == seed.growth_stages) if(harvest && overlay_stage == seed.growth_stages)
ikey = "[seed.get_trait(TRAIT_PRODUCT_ICON)]" ikey = "[seed.get_trait(TRAIT_PRODUCT_ICON)]"
var/image/harvest_overlay = plant_controller.plant_icon_cache["product-[ikey]-[seed.get_trait(TRAIT_PLANT_COLOUR)]"] var/image/harvest_overlay = plant_controller.plant_icon_cache["product-[ikey]-[seed.get_trait(TRAIT_PLANT_COLOUR)]"]
if(!harvest_overlay) if(!harvest_overlay)
harvest_overlay = image('icons/obj/hydroponics_products.dmi', "[ikey]") harvest_overlay = image('icons/obj/hydroponics_products.dmi', "[ikey]")
harvest_overlay.color = seed.get_trait(TRAIT_PRODUCT_COLOUR) harvest_overlay.color = seed.get_trait(TRAIT_PRODUCT_COLOUR)
plant_controller.plant_icon_cache["product-[ikey]-[seed.get_trait(TRAIT_PRODUCT_COLOUR)]"] = harvest_overlay plant_controller.plant_icon_cache["product-[ikey]-[seed.get_trait(TRAIT_PRODUCT_COLOUR)]"] = harvest_overlay
add_overlay(harvest_overlay) add_overlay(harvest_overlay)
//Draw the cover. //Draw the cover.
if(closed_system) if(closed_system)
add_overlay("hydrocover") add_overlay("hydrocover")
//Updated the various alert icons. //Updated the various alert icons.
if(mechanical) if(mechanical)
var/list/add = list() var/list/add = list()
if(waterlevel <= 10) if(waterlevel <= 10)
add += "over_lowwater3" add += "over_lowwater3"
if(nutrilevel <= 2) if(nutrilevel <= 2)
add += "over_lownutri3" add += "over_lownutri3"
if(weedlevel >= 5 || pestlevel >= 5 || toxins >= 40) if(weedlevel >= 5 || pestlevel >= 5 || toxins >= 40)
add += "over_alert3" add += "over_alert3"
if(harvest) if(harvest)
add += "over_harvest3" add += "over_harvest3"
if(frozen) if(frozen)
add += "over_frozen3" add += "over_frozen3"
add_overlay(add) add_overlay(add)
// Update bioluminescence. // Update bioluminescence.
if(seed) if(seed)
if(seed.get_trait(TRAIT_BIOLUM)) if(seed.get_trait(TRAIT_BIOLUM))
var/clr var/clr
if(seed.get_trait(TRAIT_BIOLUM_COLOUR)) if(seed.get_trait(TRAIT_BIOLUM_COLOUR))
clr = seed.get_trait(TRAIT_BIOLUM_COLOUR) clr = seed.get_trait(TRAIT_BIOLUM_COLOUR)
set_light(round(seed.get_trait(TRAIT_POTENCY)/10), l_color = clr) set_light(round(seed.get_trait(TRAIT_POTENCY)/10), l_color = clr)
return return
set_light(0) set_light(0)
return return