From f9e6e2bca7d1b72e92279b02527dd00f1affa7fc Mon Sep 17 00:00:00 2001 From: oranges Date: Thu, 10 Mar 2016 11:37:29 +1300 Subject: [PATCH] Add subsystem for safely spawning atoms at roundstart This system is called just before initialize and does not use a world loop, so it is safe to spawn and create new atoms. Any atom can inherit this behaviour by overriding the spawn_atom_to_world proc and spawning atoms there at roundstart Make sure you register the atom in question to the list of spawner atoms by doing SSobj.atom_spawners += src, and then remove when you are done spawning objects --- code/controllers/subsystem/objects.dm | 11 ++++++++++- code/game/atoms.dm | 6 +++++- code/modules/awaymissions/corpse.dm | 6 +++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/code/controllers/subsystem/objects.dm b/code/controllers/subsystem/objects.dm index c902e69aa6f..c430ed5db0a 100644 --- a/code/controllers/subsystem/objects.dm +++ b/code/controllers/subsystem/objects.dm @@ -9,6 +9,7 @@ var/datum/subsystem/objects/SSobj name = "Objects" priority = 12 + var/list/atom_spawners = list() var/list/processing = list() var/list/currentrun = list() var/list/burning = list() @@ -17,6 +18,7 @@ var/datum/subsystem/objects/SSobj NEW_SS_GLOBAL(SSobj) /datum/subsystem/objects/Initialize(timeofday, zlevel) + trigger_atom_spawners() setupGenetics() for(var/V in world) var/atom/A = V @@ -26,6 +28,12 @@ var/datum/subsystem/objects/SSobj CHECK_TICK . = ..() +/datum/subsystem/objects/proc/trigger_atom_spawners(zlevel) + for(var/V in atom_spawners) + var/atom/A = V + if (zlevel && A.z != zlevel) + continue + A.spawn_atom_to_world() /datum/subsystem/objects/stat_entry() ..("P:[processing.len]") @@ -57,4 +65,5 @@ var/datum/subsystem/objects/SSobj /datum/subsystem/objects/proc/setup_template_objects(list/objects) for(var/A in objects) var/atom/B = A - B.initialize() \ No newline at end of file + B.spawn_atom_to_world() + B.initialize() diff --git a/code/game/atoms.dm b/code/game/atoms.dm index ee146dca555..87881a756ff 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -358,6 +358,10 @@ var/list/blood_splatter_icons = list() . = ..() sleep(1) +//This is called just before maps and objects are initialized, use it to spawn other mobs/objects +//effects at world start up without causing runtimes +/atom/proc/spawn_atom_to_world() + //This will be called after the map and objects are loaded /atom/proc/initialize() return @@ -385,4 +389,4 @@ var/list/blood_splatter_icons = list() if(istype(R, /datum/reagent/consumable)) var/datum/reagent/consumable/nutri_check = R if(nutri_check.nutriment_factor >0) - M.reagents.remove_reagent(R.id,R.volume) \ No newline at end of file + M.reagents.remove_reagent(R.id,R.volume) diff --git a/code/modules/awaymissions/corpse.dm b/code/modules/awaymissions/corpse.dm index e5de1715936..2f82fd0fa83 100644 --- a/code/modules/awaymissions/corpse.dm +++ b/code/modules/awaymissions/corpse.dm @@ -27,7 +27,9 @@ log_game("[user.ckey] became [mob_name]") create(ckey = user.ckey) -/obj/effect/mob_spawn/initialize() +/obj/effect/mob_spawn/spawn_atom_to_world() + //We no longer need to spawn mobs, deregister ourself + SSobj.atom_spawners -= src if(roundstart) create() else @@ -35,6 +37,8 @@ /obj/effect/mob_spawn/New() ..() + //Add to the atom spawners register for roundstart atom spawning + SSobj.atom_spawners += src if(instant) create() else