Try to provide as much info as possible about stuff, as to avoid misunderstandings.
Preferably avoid submitting anything which is in the DMreference, which you simply only just found out about, this is more for obscure inner workings and such, beyond that which the DMreference tells us.
I'll start with how the map is instanced and initialized at round start:
First to explain what I mean by instance, instanced and initialized, since I am self-taught and probably misusing these terms in some way.
instance = any 'thing' which is created. For example, /atom, /datum, /list, /image, /icon are all instances. i.e. and class which has been brought into existence.
instanced = the creation of an instance. e.g. calling new /some/typepath()
initialized = probably completely misusing this term. I'm using it to mean New() has been called for this instance.
Ok, so when the map is created, as far as I can tell, this roughly outlines the order of things. Some of this is no doubt inaccurate in some insignificant technicalities, but it's accurate enough to draw some helpful conclusions (which I will get to later):
1) all turfs are instanced according to the dmm
2) all areas are instanced and any turfs are added to their contents
3) area/New() called for all areas starting from bottom left travelling left-to-right
(//Note: I have yet to test whether -all- areas are instanced and -then- -all- their New are called, or if each area is instanced and initialized sequentially.)
4) turf/New() called for all turfs starting from the top right, travelling right-to-left
5) for each turf, starting at the bottom left, travelling left-to-right, we instance and initialize objects for that turf, then before moving on to the next turf, instance and initialize mobs.
(//Note: this may actually be instancing all atom/movable for the turf and inserting them into the contents list in this order (as they always appear in that order in the contents list), then simply calling New() for each thing in the turf's contents)
If you can improve this please do.
conclusions:
much code contained in spawn() within New() procs can be reworked to not need spawn() by using the information above.
for instance, take:
Code: Select all
/area/station/ai_monitored/New()
..()
spawn(4)
// locate and store the motioncamera
for(var/obj/machinery/camera/M in src)
if(M.isMotion())
motioncamera = M
M.area_motion = src
Code: Select all
/obj/machinery/camera/New()
..()
if(isMotion())
var/area/station/ai_monitored/A = get_area(src)
if(istype(A))
A.motioncamera = src
area_motion = A
another example would be mimic crates collecting all objects in loc.contents and moving them to its contents during mimic/crate/New(). This was originally done with a spawn, but since we know that mobs are initialized after objects, we can just omit the spawn, since we do not need to collect objects from neighbouring turfs (which would not even be instanced yet), just our own turf.
Another case would be the smoothwall code. This is performed in turf/New() obj/structure/falsewall/New() and /obj/structure/falserwall/New(). It searches surrounding turfs for these objects/turfs to update their icon_states.
It can work without spawn because we know that all turfs will be instanced for any of those New() calls.
However, neighbouring objects -not- necessarily be instanced yet. So those will not be smoothwalled.
But if we think carefully about it, we know that objects are initialized from bottom left to top-right. So the smooth-wall code will smooth all of these objects with anything to the west, southwest, southeast or south. Therefore, everything will be smoothed properly since we are travelling in the opposite direction. No need to wait until the map is fully instanced.
Another more difficult case, is when a machine looks to 'link' itself with neighbours during New(). Since only objects to the south,west, southeast and southwest will be instanced by this point. However, by having both partners in the link attempting to find partners, rather than just one of the partners searching, we will always find any partners to the bottom left. Meaning that we no longer need a spawn() in their New().
Sorry if this is really hard to read, I'm not the best at explaining stuff. I hope it helps somebody.