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
This commit is contained in:
oranges
2016-03-19 22:41:38 +00:00
parent 3a2a614be9
commit f9e6e2bca7
3 changed files with 20 additions and 3 deletions
+10 -1
View File
@@ -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()
B.spawn_atom_to_world()
B.initialize()
+5 -1
View File
@@ -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)
M.reagents.remove_reagent(R.id,R.volume)
+5 -1
View File
@@ -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