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()