Skip to content

Commit

Permalink
Small Optimizations (#3905)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

Just some miscellaneous optimizations I've slowly been accumulating,
centering around yet another rewrite of
ImmediateCalculateAdjacentTurfs(). Others include jukeboxes, scrubbers,
and lights, and also includes the elimination of a bunch of Destroy()
side effects because those suck

## Why It's Good For The Game

I don't know if this will actually do too much but every bit helps, and
the code quality is hopefully a bit better

## Changelog

:cl:
fix: Jukeboxes should not leak across virtual Zs anymore
fix: Candles can no longer be used like tiki torches
tweak: Ore silos will now only drop materials when dissasembled or
destroyed, instead of any deletion
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->
  • Loading branch information
MarkSuckerberg authored Dec 29, 2024
1 parent a61b0fe commit a61b150
Show file tree
Hide file tree
Showing 60 changed files with 310 additions and 294 deletions.
2 changes: 1 addition & 1 deletion code/__HELPERS/AStar.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Actual Adjacent procs :
if(!start || !end)
stack_trace("Invalid A* start or destination")
return FALSE
if(start.virtual_z() != end.virtual_z() || start == end) //no pathfinding between z levels
if(start.virtual_z != end.virtual_z || start == end) //no pathfinding between z levels
return FALSE
if(maxnodes)
//if start turf is farther than maxnodes from end turf, no need to do anything
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/hud/radial.dm
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,6 @@ GLOBAL_LIST_EMPTY(radial_menus)
/// If provided, will display an info button that will put this text in your chat
var/info

/datum/radial_menu_choice/Destroy(force, ...)
/datum/radial_menu_choice/Destroy(force)
. = ..()
QDEL_NULL(image)
58 changes: 25 additions & 33 deletions code/controllers/subsystem/jukeboxes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ SUBSYSTEM_DEF(jukeboxes)
var/sound/song_to_init = sound(T.song_path)
song_to_init.status = SOUND_MUTE
for(var/mob/M in GLOB.player_list)
if(!M.client)
continue
if(!(M.client.prefs.toggles & SOUND_INSTRUMENTS))
if(!(M?.client.prefs.toggles & SOUND_INSTRUMENTS))
continue

M.playsound_local(M, null, 100, channel = youvegotafreejukebox[2], S = song_to_init)
Expand Down Expand Up @@ -88,9 +86,7 @@ SUBSYSTEM_DEF(jukeboxes)
return ..()

/datum/controller/subsystem/jukeboxes/fire()
if(!activejukeboxes.len)
return
for(var/list/jukeinfo in activejukeboxes)
for(var/list/jukeinfo as anything in activejukeboxes)
if(!jukeinfo.len)
stack_trace("Active jukebox without any associated metadata.")
continue
Expand All @@ -103,42 +99,38 @@ SUBSYSTEM_DEF(jukeboxes)
stack_trace("Nonexistant or invalid object associated with jukebox.")
continue
var/sound/song_played = sound(juketrack.song_path)
var/area/currentarea = get_area(jukebox)
var/turf/currentturf = get_turf(jukebox)
var/list/hearerscache = hearers(7, jukebox)
var/turf/above_turf = currentturf.above()
var/turf/below_turf = currentturf.below()
var/list/hearerscache = get_hearers_in_view(7, jukebox)

var/datum/virtual_level/zone = currentturf.get_virtual_level()
var/turf/above_turf = zone.get_above_turf(currentturf)
var/turf/below_turf = zone.get_below_turf(currentturf)

var/list/virtual_ids = list(zone.id)
var/list/areas = list(get_area(jukebox))
if(above_turf && istransparentturf(above_turf))
virtual_ids += above_turf.virtual_z
areas += get_area(above_turf)
if(below_turf && istransparentturf(below_turf))
virtual_ids += below_turf.virtual_z
areas += get_area(below_turf)

song_played.falloff = jukeinfo[4]

for(var/mob/M in GLOB.player_list)
if(!M.client)
continue
if(!(M.client.prefs.toggles & SOUND_INSTRUMENTS) || !M.can_hear())
for(var/mob/M as anything in GLOB.player_list)
if(!(M.client?.prefs.toggles & SOUND_INSTRUMENTS) || !M.can_hear())
M.stop_sound_channel(jukeinfo[2])
continue

var/inrange = FALSE
if(jukebox.z == M.z) //todo - expand this to work with mining planet z-levels when robust jukebox audio gets merged to master
song_played.status = SOUND_UPDATE
if(get_area(M) == currentarea)
inrange = TRUE
else if(M in hearerscache)
inrange = TRUE
else if(above_turf?.z == M.z)
song_played.status = SOUND_UPDATE
if(istransparentturf(above_turf) && (get_area(M) == get_area(above_turf)))
inrange = TRUE
else if(below_turf?.z == M.z)
if(jukebox.volume <= 0 || !(M.virtual_z() in virtual_ids))
song_played.status = SOUND_MUTE | SOUND_UPDATE
else
song_played.status = SOUND_UPDATE
if(istransparentturf(below_turf) && (get_area(M) == get_area(below_turf)))
if((get_area(M) in areas) || (M in hearerscache))
inrange = TRUE
else
song_played.status = SOUND_MUTE | SOUND_UPDATE //Setting volume = 0 doesn't let the sound properties update at all, which is lame.

if(jukebox.volume <= 0)
song_played.status = SOUND_MUTE

M.playsound_local(currentturf, null, jukebox.volume, channel = jukeinfo[2], S = song_played, envwet = (inrange ? -250 : 0), envdry = (inrange ? 0 : -10000))
CHECK_TICK
return

if(MC_TICK_CHECK)
return
2 changes: 1 addition & 1 deletion code/controllers/subsystem/overmap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SUBSYSTEM_DEF(overmap)
name = "Overmap"
wait = 10
init_order = INIT_ORDER_OVERMAP
flags = SS_KEEP_TIMING|SS_NO_TICK_CHECK
flags = SS_KEEP_TIMING
runlevels = RUNLEVEL_SETUP | RUNLEVEL_GAME

///Defines which generator to use for the overmap
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/statpanel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ SUBSYSTEM_DEF(statpanels)
. = ..()
src.parent = parent

/datum/object_window_info/Destroy(force, ...)
/datum/object_window_info/Destroy(force)
atoms_to_show = null
atoms_to_images = null
atoms_to_imagify = null
Expand Down
2 changes: 1 addition & 1 deletion code/datums/ai_laws.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var/mob/living/silicon/owner
var/id = DEFAULT_AI_LAWID

/datum/ai_laws/Destroy(force, ...)
/datum/ai_laws/Destroy(force)
if(!QDELETED(owner))
CRASH("AI lawset destroyed even though owner AI is not being destroyed.")
owner = null
Expand Down
8 changes: 3 additions & 5 deletions code/datums/components/_component.dm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
var/list/arguments = raw_args.Copy(2)
if(Initialize(arglist(arguments)) == COMPONENT_INCOMPATIBLE)
stack_trace("Incompatible [type] assigned to a [parent.type]! args: [json_encode(arguments)]")
qdel(src, TRUE, TRUE)
qdel(src, TRUE)
return

_JoinParent(parent)
Expand All @@ -69,15 +69,13 @@
*
* Arguments:
* * force - makes it not check for and remove the component from the parent
* * silent - deletes the component without sending a [COMSIG_COMPONENT_REMOVING] signal
*/
/datum/component/Destroy(force=FALSE, silent=FALSE)
/datum/component/Destroy(force=FALSE)
if(!parent)
return ..()
if(!force)
_RemoveFromParent()
if(!silent)
SEND_SIGNAL(parent, COMSIG_COMPONENT_REMOVING, src)
SEND_SIGNAL(parent, COMSIG_COMPONENT_REMOVING, src)
parent = null
return ..()

Expand Down
10 changes: 7 additions & 3 deletions code/datums/components/remote_materials.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ handles linking back and forth.
src.category = category
src.allow_standalone = allow_standalone

RegisterSignal(parent, COMSIG_OBJ_DECONSTRUCT, PROC_REF(OnDeconstruct))
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(OnAttackBy))
RegisterSignal(parent, COMSIG_ATOM_MULTITOOL_ACT, PROC_REF(OnMultitool))

Expand All @@ -35,12 +36,15 @@ handles linking back and forth.
silo.updateUsrDialog()
silo = null
mat_container = null
else if (mat_container)
mat_container = null
return ..()

/datum/component/remote_materials/proc/OnDeconstruct(disassembled)
SIGNAL_HANDLER
if(!silo && mat_container)
// specify explicitly in case the other component is deleted first
var/atom/P = parent
mat_container.retrieve_all(P.drop_location())
mat_container = null
return ..()

/datum/component/remote_materials/proc/_MakeLocal()
silo = null
Expand Down
3 changes: 2 additions & 1 deletion code/datums/components/weatherannouncer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
light.set_light_color(LIGHT_COLOR_YELLOW)
if(WEATHER_ALERT_IMMINENT_OR_ACTIVE)
light.set_light_color(LIGHT_COLOR_INTENSE_RED)
light.update_light()
if(light.light_system == STATIC_LIGHT)
light.update_light()

/// Returns a string we should display to communicate what you should be doing
/datum/component/weather_announcer/proc/get_warning_message()
Expand Down
6 changes: 3 additions & 3 deletions code/datums/datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
*
* Returns [QDEL_HINT_QUEUE]
*/
/datum/proc/Destroy(force=FALSE, ...)
/datum/proc/Destroy(force)
SHOULD_CALL_PARENT(TRUE)
tag = null
datum_flags &= ~DF_USE_TAG //In case something tries to REF us
Expand All @@ -111,10 +111,10 @@
var/all_components = dc[/datum/component]
if(length(all_components))
for(var/datum/component/component as anything in all_components)
qdel(component, FALSE, TRUE)
qdel(component, FALSE)
else
var/datum/component/C = all_components
qdel(C, FALSE, TRUE)
qdel(C, FALSE)
dc.Cut()

clear_signal_refs()
Expand Down
19 changes: 19 additions & 0 deletions code/datums/map_zones.dm
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,25 @@
var/abs_y = Turf.y - low_y
return locate(up_linkage.low_x + abs_x, up_linkage.low_y + abs_y, up_linkage.z_value)

/datum/virtual_level/proc/get_zone_step(turf/source, direction)
// multiz dir is just the up/down dir flags
var/multiz_dir = direction & (UP|DOWN)
// while the passed dir is normalized to just the cardinals
direction &= ~(UP|DOWN)
var/turf/my_turf = get_step(source, direction)
if(isnull(my_turf))
return
switch(multiz_dir)
// the old version of this code prioritized UP over DOWN when
// both were passed. i don't want to fuck with that, so here it is preserved
if(UP|DOWN)
return get_above_turf(my_turf)
if(UP)
return get_above_turf(my_turf)
if(DOWN)
return get_below_turf(my_turf)
return my_turf

/datum/virtual_level/proc/get_client_mobs()
return get_alive_client_mobs() + get_dead_client_mobs()

Expand Down
5 changes: 1 addition & 4 deletions code/game/machinery/cloning.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@
begin_processing()

/obj/machinery/clonepod/Destroy()
var/mob/living/mob_occupant = occupant
go_out()
if(mob_occupant)
log_cloning("[key_name(mob_occupant)] ejected from [src] at [AREACOORD(src)] due to Destroy().")
QDEL_NULL(radio)
QDEL_NULL(countdown)
QDEL_NULL(occupant)
if(connected)
connected.DetachCloner(src)
QDEL_LIST(unattached_flesh)
Expand Down
4 changes: 2 additions & 2 deletions code/game/machinery/doors/firedoor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
/obj/machinery/door/firedoor/Destroy()
remove_from_areas()
density = FALSE
air_update_turf(1)
air_update_turf(TRUE)
affecting_areas.Cut()
return ..()

Expand Down Expand Up @@ -430,7 +430,7 @@
if(operating || welded)
return
density = TRUE
air_update_turf(1)
air_update_turf(TRUE)
do_animate("closing")
update_freelook_sight()
if(!(flags_1 & ON_BORDER_1))
Expand Down
5 changes: 4 additions & 1 deletion code/game/machinery/gulag_item_reclaimer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
var/list/stored_items = list()
var/obj/machinery/gulag_teleporter/linked_teleporter = null

/obj/machinery/gulag_item_reclaimer/Destroy()
/obj/machinery/gulag_item_reclaimer/deconstruct(disassembled)
for(var/i in contents)
var/obj/item/I = i
I.forceMove(get_turf(src))
return ..()

/obj/machinery/gulag_item_reclaimer/Destroy()
if(linked_teleporter)
linked_teleporter.linked_reclaimer = null
return ..()
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/slotmachine.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
var/obj/item/coin/C = cointype
coinvalues["[cointype]"] = initial(C.value)

/obj/machinery/computer/slot_machine/Destroy()
/obj/machinery/computer/slot_machine/deconstruct(disassembled, mob/user)
if(balance)
give_payout(balance)
return ..()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/effect_system/effects_smoke.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
if(!t_loc)
return
var/list/newsmokes = list()
for(var/turf/T in t_loc.GetAtmosAdjacentTurfs())
for(var/turf/T in t_loc.get_atmos_adjacent_turfs())
var/obj/effect/particle_effect/smoke/foundsmoke = locate() in T //Don't spread smoke where there's already smoke!
if(foundsmoke)
continue
Expand Down
33 changes: 17 additions & 16 deletions code/game/objects/effects/turf_fire.dm
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@
color = fire_color
base_icon_state = "greyscale"

switch(base_icon_state) //switches light color depdning on the flame color
if("greyscale")
light_color = hex_color
if("red")
light_color = LIGHT_COLOR_FIRE
if("blue")
light_color = LIGHT_COLOR_CYAN
if("green")
light_color = LIGHT_COLOR_GREEN
else
light_color = COLOR_VERY_LIGHT_GRAY

open_turf.turf_fire = src
START_PROCESSING(SSturf_fire, src)
if(power)
Expand Down Expand Up @@ -187,29 +199,18 @@
return
current_fire_state = new_state

switch(base_icon_state) //switches light color depdning on the flame color
if("greyscale")
light_color = hex_color
if("red")
light_color = LIGHT_COLOR_FIRE
if("blue")
light_color = LIGHT_COLOR_CYAN
if("green")
light_color = LIGHT_COLOR_GREEN
else
light_color = COLOR_VERY_LIGHT_GRAY
update_light()

switch(current_fire_state)
if(TURF_FIRE_STATE_SMALL)
icon_state = "[base_icon_state]_small"
set_light_range(1.5)
light_range = 1.5
if(TURF_FIRE_STATE_MEDIUM)
icon_state = "[base_icon_state]_medium"
set_light_range(2.5)
light_range = 2
if(TURF_FIRE_STATE_LARGE)
icon_state = "[base_icon_state]_big"
set_light_range(3)
light_range = 3

update_light()

#undef TURF_FIRE_REQUIRED_TEMP
#undef TURF_FIRE_TEMP_BASE
Expand Down
Loading

0 comments on commit a61b150

Please sign in to comment.