Skip to content

Commit

Permalink
Merge pull request #3709 from MistakeNot4892/feature/viscontents
Browse files Browse the repository at this point in the history
Moving vis_contents changes onto a subsystem.
  • Loading branch information
out-of-phaze authored Feb 27, 2024
2 parents 74af7d6 + 7367c38 commit ca4d060
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 66 deletions.
1 change: 1 addition & 0 deletions code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define SS_PRIORITY_SPACEDRIFT 40 // Drifting things.
#define SS_PRIORITY_INPUT 20 // Input things.
#define SS_PRIORITY_ICON_UPDATE 20 // Queued icon updates. Mostly used by APCs and tables.
#define SS_PRIORITY_VIS_CONTENTS 20 // Queued vis_contents updates.
#define SS_PRIORITY_AMBIENCE 20 // Queued ambient lighting updates.
#define SS_PRIORITY_ALARM 20 // Alarm processing.
#define SS_PRIORITY_EVENT 20 // Event processing and queue handling.
Expand Down
21 changes: 11 additions & 10 deletions code/__defines/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@
#define SS_INIT_OVERLAY 1
#define SS_INIT_DEFAULT 0
#define SS_INIT_AIR -1
#define SS_INIT_MISC_LATE -2
#define SS_INIT_MISC_CODEX -3
#define SS_INIT_ALARM -4
#define SS_INIT_SHUTTLE -5
#define SS_INIT_GOALS -5
#define SS_INIT_LIGHTING -6
#define SS_INIT_WEATHER -7
#define SS_INIT_ZCOPY -8
#define SS_INIT_HOLOMAP -9
#define SS_INIT_XENOARCH -10
#define SS_INIT_VIS_CONTENTS -2
#define SS_INIT_MISC_LATE -3
#define SS_INIT_MISC_CODEX -4
#define SS_INIT_ALARM -5
#define SS_INIT_SHUTTLE -6
#define SS_INIT_GOALS -7
#define SS_INIT_LIGHTING -8
#define SS_INIT_WEATHER -9
#define SS_INIT_ZCOPY -10
#define SS_INIT_HOLOMAP -11
#define SS_INIT_XENOARCH -12
#define SS_INIT_TICKER -20
#define SS_INIT_UNIT_TESTS -100

Expand Down
13 changes: 0 additions & 13 deletions code/_helpers/vis_contents.dm

This file was deleted.

2 changes: 1 addition & 1 deletion code/_onclick/hud/radial.dm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ var/global/list/radial_menus = list()
//Blank
menu_holder = image(icon = 'icons/effects/effects.dmi', loc = anchor, icon_state = "nothing", layer = HUD_ABOVE_ITEM_LAYER)
menu_holder.appearance_flags |= KEEP_APART
add_vis_contents(menu_holder, elements + close_button)
menu_holder.add_vis_contents(elements + close_button)
current_user.images += menu_holder

/datum/radial_menu/proc/hide()
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/hud/screen/screen_exosuit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
/obj/screen/exosuit/heat/Initialize(mapload, mob/_owner, ui_style, ui_color, ui_alpha)
. = ..()
gauge_needle = new /obj/screen/exosuit/needle(null, _owner)
add_vis_contents(src, gauge_needle)
add_vis_contents(gauge_needle)

/obj/screen/exosuit/heat/Destroy()
QDEL_NULL(gauge_needle)
Expand Down
6 changes: 3 additions & 3 deletions code/controllers/subsystems/air.dm
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Total Unsimulated Turfs: [world.maxx*world.maxy*world.maxz - simulated_turf_coun
T.post_update_air_properties()
T.needs_air_update = 0
#ifdef ZASDBG
remove_vis_contents(T, zasdbgovl_mark)
T.remove_vis_contents(zasdbgovl_mark)
#endif

if (no_mc_tick)
Expand All @@ -215,7 +215,7 @@ Total Unsimulated Turfs: [world.maxx*world.maxy*world.maxz - simulated_turf_coun
T.post_update_air_properties()
T.needs_air_update = 0
#ifdef ZASDBG
remove_vis_contents(T, zasdbgovl_mark)
T.remove_vis_contents(zasdbgovl_mark)
#endif

if (no_mc_tick)
Expand Down Expand Up @@ -366,7 +366,7 @@ Total Unsimulated Turfs: [world.maxx*world.maxy*world.maxz - simulated_turf_coun
return
tiles_to_update += T
#ifdef ZASDBG
add_vis_contents(T, zasdbgovl_mark)
T.add_vis_contents(zasdbgovl_mark)
#endif
T.needs_air_update = 1

Expand Down
6 changes: 3 additions & 3 deletions code/controllers/subsystems/typing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Updated 09/10/2022 to include chatbar using Spookerton's SStyping system from Po

/atom/movable/typing_indicator/Destroy()
if(master)
remove_vis_contents(master, src)
master.remove_vis_contents(src)
if(ismob(master))
var/mob/owner = master
if(owner.typing_indicator == src)
Expand All @@ -177,7 +177,7 @@ Updated 09/10/2022 to include chatbar using Spookerton's SStyping system from Po
set_invisibility(INVISIBILITY_MAXIMUM)
if(ismovable(master))
var/atom/movable/owner = master
remove_vis_contents(owner, src)
owner.remove_vis_contents(src)

/atom/movable/typing_indicator/proc/show_typing_indicator()

Expand All @@ -195,7 +195,7 @@ Updated 09/10/2022 to include chatbar using Spookerton's SStyping system from Po

if(ismovable(master))
var/atom/movable/owner = master
add_vis_contents(owner, src)
owner.add_vis_contents(src)

// Animate it popping up from nowhere.
var/matrix/M = matrix()
Expand Down
93 changes: 93 additions & 0 deletions code/controllers/subsystems/vis_contents.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
SUBSYSTEM_DEF(vis_contents_update)
name = "Vis Contents"
flags = SS_BACKGROUND
wait = 1
priority = SS_PRIORITY_VIS_CONTENTS
init_order = SS_INIT_VIS_CONTENTS
runlevels = RUNLEVEL_LOBBY | RUNLEVELS_DEFAULT
var/list/queue_refs = list()

/datum/controller/subsystem/vis_contents_update/stat_entry()
..("Queue: [queue_refs.len]")

/datum/controller/subsystem/vis_contents_update/Initialize()
fire(FALSE, TRUE)

/datum/controller/subsystem/vis_contents_update/StartLoadingMap()
suspend()

/datum/controller/subsystem/vis_contents_update/StopLoadingMap()
wake()

// Largely copied from SSicon_update.
/datum/controller/subsystem/vis_contents_update/fire(resumed = FALSE, no_mc_tick = FALSE)
if(!queue_refs.len)
suspend()
return
var/i = 0
while (i < queue_refs.len)
i++
var/atom/A = queue_refs[i]
if(QDELETED(A))
continue
if(Master.map_loading)
queue_refs.Cut(1, i+1)
return
A.vis_update_queued = FALSE
A.update_vis_contents(force_no_queue = TRUE)
if (no_mc_tick)
CHECK_TICK
else if (MC_TICK_CHECK)
queue_refs.Cut(1, i+1)
return
queue_refs.Cut()

/atom
var/vis_update_queued = FALSE

/atom/proc/queue_vis_contents_update()
if(vis_update_queued)
return
vis_update_queued = TRUE
SSvis_contents_update.queue_refs.Add(src)
SSvis_contents_update.wake()

// Horrible colon syntax below is because vis_contents
// exists in /atom.vars, but will not compile. No idea why.
/atom/proc/add_vis_contents(adding)
src:vis_contents |= adding

/atom/proc/remove_vis_contents(removing)
src:vis_contents -= removing

/atom/proc/clear_vis_contents()
src:vis_contents = null

/atom/proc/set_vis_contents(list/adding)
src:vis_contents = adding

/atom/proc/get_vis_contents_to_add()
return

/atom/proc/update_vis_contents(force_no_queue = FALSE)
if(!force_no_queue && (!SSvis_contents_update.initialized || TICK_CHECK))
queue_vis_contents_update()
return
vis_update_queued = FALSE
var/new_vis_contents = get_vis_contents_to_add()
if(length(new_vis_contents))
set_vis_contents(new_vis_contents)
else if(length(src:vis_contents))
clear_vis_contents()

/image/proc/add_vis_contents(adding)
vis_contents |= adding

/image/proc/remove_vis_contents(removing)
vis_contents -= removing

/image/proc/clear_vis_contents()
vis_contents.Cut()

/image/proc/set_vis_contents(list/adding)
vis_contents = adding
2 changes: 1 addition & 1 deletion code/game/atoms_init.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
QDEL_NULL(bound_overlay)

vis_locs = null //clears this atom out of all vis_contents
clear_vis_contents(src)
clear_vis_contents()

/atom/GetCloneArgs()
return list(loc)
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/weapons/storage/trays.dm
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@

/obj/item/storage/tray/on_update_icon()
. = ..()
clear_vis_contents(src)
clear_vis_contents()
for(var/obj/item/I in contents)
I.vis_flags |= VIS_INHERIT_PLANE | VIS_INHERIT_LAYER
I.appearance_flags |= RESET_COLOR
add_vis_contents(src, I)
add_vis_contents(I)

/obj/item/storage/tray/remove_from_storage(obj/item/W, atom/new_location, var/NoUpdate = 0)
. = ..()
Expand Down
12 changes: 6 additions & 6 deletions code/game/turfs/turf.dm
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

if(flooded)
set_flooded(flooded, TRUE, skip_vis_contents_update = TRUE, mapload = mapload)
refresh_vis_contents()
update_vis_contents()

return INITIALIZE_HINT_NORMAL

Expand Down Expand Up @@ -161,7 +161,7 @@
connections.erase_all()

if(weather)
remove_vis_contents(src, weather.vis_contents_additions)
remove_vis_contents(weather.vis_contents_additions)
weather = null

QDEL_NULL(fluid_overlay)
Expand Down Expand Up @@ -429,14 +429,14 @@
if(istype(new_weather) && is_outside())
if(weather != new_weather)
if(weather)
remove_vis_contents(src, weather.vis_contents_additions)
remove_vis_contents(weather.vis_contents_additions)
weather = new_weather
add_vis_contents(src, weather.vis_contents_additions)
add_vis_contents(weather.vis_contents_additions)
. = TRUE

// We are indoors or there is no local weather system, clear our vis contents.
else if(weather)
remove_vis_contents(src, weather.vis_contents_additions)
remove_vis_contents(weather.vis_contents_additions)
weather = null
. = TRUE

Expand Down Expand Up @@ -537,7 +537,7 @@
var/datum/gas_mixture/environment = return_air()
return environment?.graphic

/turf/proc/get_vis_contents_to_add()
/turf/get_vis_contents_to_add()
var/air_graphic = get_air_graphic()
if(length(air_graphic))
LAZYADD(., air_graphic)
Expand Down
2 changes: 1 addition & 1 deletion code/game/turfs/turf_fluids.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
if(!skip_vis_contents_update)
var/flood_object = get_flood_overlay(flooded)
if(flood_object)
add_vis_contents(src, flood_object)
add_vis_contents(flood_object)
else if(!mapload)
REMOVE_ACTIVE_FLUID_SOURCE(src)
fluid_update() // We are now floodable, so wake up our neighbors.
Expand Down
4 changes: 2 additions & 2 deletions code/modules/ZAS/Debug.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ var/global/list/zasdbgovl_dirzoneblock = list(

/turf/var/tmp/obj/effect/zasdbg/dbg_img
/turf/proc/dbg(obj/effect/zasdbg/img)
remove_vis_contents(src, dbg_img)
add_vis_contents(src, img)
remove_vis_contents(dbg_img)
add_vis_contents(img)
dbg_img = img

/proc/soft_assert(thing,fail)
Expand Down
10 changes: 5 additions & 5 deletions code/modules/ZAS/Zone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Class Procs:
if(T.fire)
fire_tiles.Add(T)
SSair.active_fire_zones |= src
T.refresh_vis_contents()
T.update_vis_contents()

/zone/proc/remove(turf/T)
#ifdef ZASDBG
Expand All @@ -88,7 +88,7 @@ Class Procs:
contents.Remove(T)
fire_tiles.Remove(T)
T.zone = null
T.refresh_vis_contents()
T.update_vis_contents()
if(contents.len)
air.group_multiplier = contents.len
else
Expand All @@ -106,7 +106,7 @@ Class Procs:
if(!T.zone_membership_candidate)
continue
into.add(T)
T.refresh_vis_contents()
T.update_vis_contents()
#ifdef ZASDBG
T.dbg(zasdbgovl_merged)
#endif
Expand All @@ -130,7 +130,7 @@ Class Procs:
if(invalid) return //Short circuit for explosions where rebuild is called many times over.
c_invalidate()
for(var/turf/T as anything in contents)
T.refresh_vis_contents()
T.update_vis_contents()
T.needs_air_update = 0 //Reset the marker so that it will be added to the list.
SSair.mark_for_update(T)
CHECK_TICK
Expand All @@ -154,7 +154,7 @@ Class Procs:
// Update gas overlays.
if(air.check_tile_graphic(graphic_add, graphic_remove))
for(var/turf/T as anything in contents)
T.refresh_vis_contents()
T.update_vis_contents()
CHECK_TICK
graphic_add.len = 0
graphic_remove.len = 0
Expand Down
8 changes: 4 additions & 4 deletions code/modules/mechs/equipment/combat.dm
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@

/obj/aura/mechshield/added_to(var/mob/living/target)
. = ..()
add_vis_contents(target, src)
target.add_vis_contents(src)
set_dir(target.dir)
events_repository.register(/decl/observ/dir_set, user, src, TYPE_PROC_REF(/obj/aura/mechshield, update_dir))

Expand All @@ -177,7 +177,7 @@
/obj/aura/mechshield/Destroy()
if(user)
events_repository.unregister(/decl/observ/dir_set, user, src, TYPE_PROC_REF(/obj/aura/mechshield, update_dir))
remove_vis_contents(user, src)
user.remove_vis_contents(src)
shields = null
. = ..()

Expand Down Expand Up @@ -404,7 +404,7 @@

/obj/aura/mech_ballistic/added_to(mob/living/target)
. = ..()
add_vis_contents(target, src)
target.add_vis_contents(src)
set_dir(target.dir)
global.events_repository.register(/decl/observ/dir_set, user, src, TYPE_PROC_REF(/obj/aura/mech_ballistic, update_dir))

Expand All @@ -414,7 +414,7 @@
/obj/aura/mech_ballistic/Destroy()
if (user)
global.events_repository.unregister(/decl/observ/dir_set, user, src, TYPE_PROC_REF(/obj/aura/mech_ballistic, update_dir))
remove_vis_contents(user, src)
user.remove_vis_contents(src)
shield = null
. = ..()

Expand Down
Loading

0 comments on commit ca4d060

Please sign in to comment.