Skip to content

Commit

Permalink
ports various missing parts of TG PRs (#563)
Browse files Browse the repository at this point in the history
At least some of tgstation/tgstation#70729
  • Loading branch information
francinum authored Sep 13, 2023
1 parent d2467c2 commit 3f6dbbe
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 57 deletions.
3 changes: 0 additions & 3 deletions code/_globalvars/lists/maintenance_loot.dm
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,3 @@ GLOBAL_LIST_INIT(ratking_coins, list(//Coins: Used by the regal rat mob when spa
/obj/item/coin/silver,
/obj/item/coin/titanium,
))

// List of all maintenance loot spawners, for easy finding at roundstart.
GLOBAL_LIST_EMPTY(maintenance_loot_spawners)
8 changes: 4 additions & 4 deletions code/controllers/subsystem/garbage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ SUBSYSTEM_DEF(garbage)
var/type = D.type
var/datum/qdel_item/I = items[type]

log_world("## TESTING: GC: -- \ref[D] | [type] was unable to be GC'd --")
log_world("## TESTING: GC: -- [text_ref(D)] | [type] was unable to be GC'd --")
#ifdef TESTING
for(var/c in GLOB.admins) //Using testing() here would fill the logs with ADMIN_VV garbage
var/client/admin = c
Expand Down Expand Up @@ -249,7 +249,7 @@ SUBSYSTEM_DEF(garbage)
HardDelete(D)
return
var/gctime = world.time
var/refid = "\ref[D]"
var/refid = text_ref(D)

D.gc_destroyed = gctime
var/list/queue = queues[level]
Expand All @@ -261,7 +261,7 @@ SUBSYSTEM_DEF(garbage)
++delslasttick
++totaldels
var/type = D.type
var/refID = "\ref[D]"
var/refID = text_ref(D)

var/tick_usage = TICK_USAGE
del(D)
Expand Down Expand Up @@ -376,7 +376,7 @@ SUBSYSTEM_DEF(garbage)
D.find_references() //This breaks ci. Consider it insurance against somehow pring reftracking on accident
if (QDEL_HINT_IFFAIL_FINDREFERENCE) //qdel will, if REFERENCE_TRACKING is enabled and the object fails to collect, display all references to this object.
SSgarbage.Queue(D)
SSgarbage.reference_find_on_fail["\ref[D]"] = TRUE
SSgarbage.reference_find_on_fail[text_ref(D)] = TRUE
#endif
else
#ifdef TESTING
Expand Down
56 changes: 37 additions & 19 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SUBSYSTEM_DEF(mapping)
name = "Mapping"
init_order = INIT_ORDER_MAPPING
flags = SS_NO_FIRE
runlevels = ALL

var/list/nuke_tiles = list()
var/list/nuke_threats = list()
Expand Down Expand Up @@ -30,6 +30,8 @@ SUBSYSTEM_DEF(mapping)
var/list/turf/unused_turfs = list() //Not actually unused turfs they're unused but reserved for use for whatever requests them. "[zlevel_of_turf]" = list(turfs)
var/list/datum/turf_reservations //list of turf reservations
var/list/used_turfs = list() //list of turf = datum/turf_reservation
/// List of lists of turfs to reserve
var/list/lists_to_reserve = list()

var/list/reservation_ready = list()
var/clearing_reserved_turfs = FALSE
Expand Down Expand Up @@ -111,11 +113,37 @@ SUBSYSTEM_DEF(mapping)
setup_map_transitions()
generate_station_area_list()
initialize_reserved_level(transit.z_value)
SSticker.OnRoundstart(CALLBACK(src, PROC_REF(spawn_maintenance_loot)))
calculate_default_z_level_gravities()

return ..()

/datum/controller/subsystem/mapping/fire(resumed)
// Cache for sonic speed
var/list/unused_turfs = src.unused_turfs
var/list/world_contents = GLOB.areas_by_type[world.area].contents
var/list/lists_to_reserve = src.lists_to_reserve
var/index = 0
while(length(lists_to_reserve))
var/list/packet = lists_to_reserve[index + 1]
var/packetlen = length(packet)
while(packetlen)
if(MC_TICK_CHECK)
lists_to_reserve.Cut(1, index)
return
var/turf/T = packet[packetlen]
T.empty(RESERVED_TURF_TYPE, RESERVED_TURF_TYPE, null, TRUE)
LAZYINITLIST(unused_turfs["[T.z]"])
unused_turfs["[T.z]"] |= T
T.flags_1 |= UNUSED_RESERVATION_TURF
world_contents += T
packet.len--
packetlen = length(packet)

index++
// If we're here, we're done with that lad
lists_to_reserve.len--
lists_to_reserve.Cut(1, index)

/datum/controller/subsystem/mapping/proc/calculate_default_z_level_gravities()
for(var/z_level in 1 to length(z_list))
calculate_z_level_gravity(z_level)
Expand Down Expand Up @@ -617,15 +645,12 @@ GLOBAL_LIST_EMPTY(the_station_areas)
reservation_ready["[z]"] = TRUE
clearing_reserved_turfs = FALSE

/datum/controller/subsystem/mapping/proc/reserve_turfs(list/turfs)
for(var/i in turfs)
var/turf/T = i
T.empty(RESERVED_TURF_TYPE, RESERVED_TURF_TYPE, null, TRUE)
LAZYINITLIST(unused_turfs["[T.z]"])
unused_turfs["[T.z]"] |= T
T.flags_1 |= UNUSED_RESERVATION_TURF
GLOB.areas_by_type[world.area].contents += T
CHECK_TICK
/// Schedules a group of turfs to be handed back to the reservation system's control
/// If await is true, will sleep until the turfs are finished work
/datum/controller/subsystem/mapping/proc/reserve_turfs(list/turfs, await = FALSE)
lists_to_reserve += list(turfs)
if(await)
UNTIL(!length(turfs))

//DO NOT CALL THIS PROC DIRECTLY, CALL wipe_reservations().
/datum/controller/subsystem/mapping/proc/do_wipe_turf_reservations()
Expand All @@ -643,7 +668,7 @@ GLOBAL_LIST_EMPTY(the_station_areas)
clearing |= used_turfs //used turfs is an associative list, BUT, reserve_turfs() can still handle it. If the code above works properly, this won't even be needed as the turfs would be freed already.
unused_turfs.Cut()
used_turfs.Cut()
reserve_turfs(clearing)
reserve_turfs(clearing, await = TRUE)

///Initialize all biomes, assoc as type || instance
/datum/controller/subsystem/mapping/proc/initialize_biomes()
Expand All @@ -661,10 +686,3 @@ GLOBAL_LIST_EMPTY(the_station_areas)
isolated_ruins_z = add_new_zlevel("Isolated Ruins/Reserved", list(ZTRAIT_RESERVED = TRUE, ZTRAIT_ISOLATED_RUINS = TRUE))
initialize_reserved_level(isolated_ruins_z.z_value)
return isolated_ruins_z.z_value

/datum/controller/subsystem/mapping/proc/spawn_maintenance_loot()
for(var/obj/effect/spawner/random/maintenance/spawner as anything in GLOB.maintenance_loot_spawners)
CHECK_TICK

spawner.spawn_loot()
qdel(spawner)
6 changes: 5 additions & 1 deletion code/game/objects/effects/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
/obj/effect/spawner
name = "object spawner"

// Brief explanation:
// Rather then setting up and then deleting spawners, we block all atomlike setup
// and do the absolute bare minimum
// This is with the intent of optimizing mapload
/obj/effect/spawner/Initialize(mapload)
SHOULD_CALL_PARENT(FALSE)
if(initialized)
Expand All @@ -31,7 +35,7 @@

/obj/effect/spawner/Destroy(force)
SHOULD_CALL_PARENT(FALSE)
loc = null
moveToNullspace()
return QDEL_HINT_QUEUE

/obj/effect/list_container
Expand Down
4 changes: 1 addition & 3 deletions code/game/objects/effects/spawners/costume.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
var/list/items

/obj/effect/spawner/costume/Initialize(mapload)
..()
. = ..()
if(items?.len)
for(var/path in items)
new path(loc)
return INITIALIZE_HINT_QDEL

/obj/effect/spawner/costume/chicken
name = "chicken costume spawner"
items = list(
Expand Down
3 changes: 1 addition & 2 deletions code/game/objects/effects/spawners/random/entertainment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,4 @@

/obj/effect/spawner/random/entertainment/toy/Initialize(mapload)
loot += GLOB.arcade_prize_pool
. = ..()
return INITIALIZE_HINT_QDEL
return ..()
17 changes: 0 additions & 17 deletions code/game/objects/effects/spawners/random/maintenance.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@

/obj/effect/spawner/random/maintenance/Initialize(mapload)
loot = GLOB.maintenance_loot

. = ..()

GLOB.maintenance_loot_spawners += src

/obj/effect/spawner/random/maintenance/should_spawn_on_init()
. = ..()

if(.)
return

// Late loaded templates like shuttles can have maintenance loot.
// Once the game state progresses to roundstart, new maint loot spawners should just instantly pop.
return (SSticker.current_state >= GAME_STATE_SETTING_UP)

/obj/effect/spawner/random/maintenance/Destroy()
GLOB.maintenance_loot_spawners -= src
return ..()

/obj/effect/spawner/random/maintenance/proc/hide()
Expand Down
9 changes: 1 addition & 8 deletions code/game/objects/effects/spawners/random/random.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@

/obj/effect/spawner/random/Initialize(mapload)
. = ..()

if(should_spawn_on_init())
spawn_loot()
return INITIALIZE_HINT_QDEL

/// Helper proc that returns TRUE if the spawner should spawn loot in Initialise() and FALSE otherwise. Override this to change spawning behaviour.
/obj/effect/spawner/random/proc/should_spawn_on_init()
return spawn_on_init
spawn_loot()

///If the spawner has any loot defined, randomly picks some and spawns it. Does not cleanup the spawner.
/obj/effect/spawner/random/proc/spawn_loot(lootcount_override)
Expand Down

0 comments on commit 3f6dbbe

Please sign in to comment.