Initialize Refactor

This commit is contained in:
CitadelStationBot
2017-04-26 16:03:17 -05:00
parent e7df2bc14a
commit cea81a3357
25 changed files with 277 additions and 105 deletions
+2 -1
View File
@@ -14,5 +14,6 @@
#define GC_QUEUED_FOR_HARD_DEL -2
#define GC_CURRENTLY_BEING_QDELETED -3
#define QDELETED(X) (!X || X.gc_destroyed)
#define QDELING(X) (X.gc_destroyed)
#define QDELETED(X) (!X || QDELING(X))
#define QDESTROYING(X) (!X || X.gc_destroyed == GC_CURRENTLY_BEING_QDELETED)
+18
View File
@@ -0,0 +1,18 @@
diff a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm (rejected hunks)
@@ -26,4 +26,13 @@
#define INITIALIZE_HINT_NORMAL 0 //Nothing happens
#define INITIALIZE_HINT_LATELOAD 1 //Call LateInitialize
-#define INITIALIZE_HINT_QDEL 2 //Call qdel on the atom
\ No newline at end of file
+#define INITIALIZE_HINT_QDEL 2 //Call qdel on the atom
+
+//type and all subtypes should always call Initialize in New()
+#define INITIALIZE_IMMEDIATE(X) ##X/New(loc, ...){\
+ ..();\
+ if(!initialized) {\
+ args[1] = TRUE;\
+ SSatoms.InitAtom(src, args);\
+ }\
+}
\ No newline at end of file
+1 -1
View File
@@ -544,7 +544,7 @@
plane = SPLASHSCREEN_PLANE
var/client/holder
/obj/screen/splash/New(client/C, visible, use_previous_title)
/obj/screen/splash/New(client/C, visible, use_previous_title) //TODO: Make this use INITIALIZE_IMMEDIATE
holder = C
if(!visible)
+3 -1
View File
@@ -3,7 +3,9 @@
name = "Initializing..."
var/target
/obj/effect/statclick/New(loc, text, target) //Don't port this to Initialize it's too critical
INITIALIZE_IMMEDIATE(/obj/effect/statclick)
/obj/effect/statclick/Initialize(mapload, text, target) //Don't port this to Initialize it's too critical
..()
name = text
src.target = target
+78 -58
View File
@@ -1,6 +1,7 @@
#define INITIALIZATION_INSSATOMS 0 //New should not call Initialize
#define INITIALIZATION_INNEW_MAPLOAD 1 //New should call Initialize(TRUE)
#define INITIALIZATION_INNEW_REGULAR 2 //New should call Initialize(FALSE)
#define BAD_INIT_QDEL_BEFORE 1
#define BAD_INIT_DIDNT_INIT 2
#define BAD_INIT_SLEPT 4
#define BAD_INIT_NO_HINT 8
SUBSYSTEM_DEF(atoms)
name = "Atoms"
@@ -19,64 +20,82 @@ SUBSYSTEM_DEF(atoms)
InitializeAtoms()
return ..()
/datum/controller/subsystem/atoms/proc/InitializeAtoms(list/atoms = null)
/datum/controller/subsystem/atoms/proc/InitializeAtoms(list/atoms)
if(initialized == INITIALIZATION_INSSATOMS)
return
initialized = INITIALIZATION_INNEW_MAPLOAD
var/static/list/NewQdelList = list()
if(atoms)
for(var/I in atoms)
var/atom/A = I
if(!A.initialized) //this check is to make sure we don't call it twice on an object that was created in a previous Initialize call
if(QDELETED(A))
if(!(NewQdelList[A.type]))
WARNING("Found new qdeletion in type [A.type]!")
NewQdelList[A.type] = TRUE
continue
var/start_tick = world.time
if(A.Initialize(TRUE))
LAZYADD(late_loaders, A)
if(start_tick != world.time)
WARNING("[A]: [A.type] slept during it's Initialize!")
CHECK_TICK
testing("Initialized [atoms.len] atoms")
else
#ifdef TESTING
var/count = 0
#endif
for(var/atom/A in world)
if(!A.initialized) //this check is to make sure we don't call it twice on an object that was created in a previous Initialize call
if(QDELETED(A))
if(!(NewQdelList[A.type]))
WARNING("Found new qdeletion in type [A.type]!")
NewQdelList[A.type] = TRUE
continue
var/start_tick = world.time
if(A.Initialize(TRUE))
LAZYADD(late_loaders, A)
#ifdef TESTING
else
++count
#endif TESTING
if(start_tick != world.time)
WARNING("[A]: [A.type] slept during it's Initialize!")
CHECK_TICK
testing("Roundstart initialized [count] atoms")
initialized = INITIALIZATION_INNEW_REGULAR
for(var/I in late_loaders)
var/atom/A = I
var/start_tick = world.time
A.Initialize(FALSE)
if(start_tick != world.time)
WARNING("[A]: [A.type] slept during it's Initialize!")
CHECK_TICK
testing("Late-initialized [LAZYLEN(late_loaders)] atoms")
LAZYCLEARLIST(late_loaders)
initialized = INITIALIZATION_INNEW_MAPLOAD
LAZYINITLIST(late_loaders)
var/count
var/list/mapload_arg = list(TRUE)
if(atoms)
created_atoms = list()
count = atoms.len
for(var/I in atoms)
var/atom/A = I
if(!A.initialized)
if(InitAtom(I, mapload_arg))
atoms -= I
CHECK_TICK
else
count = 0
for(var/atom/A in world)
if(!A.initialized)
InitAtom(A, mapload_arg)
++count
CHECK_TICK
log_world("Initialized [count] atoms")
initialized = INITIALIZATION_INNEW_REGULAR
if(late_loaders.len)
for(var/I in late_loaders)
var/atom/A = I
A.LateInitialize()
testing("Late initialized [late_loaders.len] atoms")
late_loaders.Cut()
if(atoms)
. = created_atoms + atoms
created_atoms = null
/datum/controller/subsystem/atoms/proc/InitAtom(atom/A, list/arguments)
var/the_type = A.type
if(QDELING(A))
BadInitializeCalls[the_type] |= BAD_INIT_QDEL_BEFORE
return TRUE
var/start_tick = world.time
var/result = A.Initialize(arglist(arguments))
if(start_tick != world.time)
BadInitializeCalls[the_type] |= BAD_INIT_SLEPT
var/qdeleted = FALSE
if(result != INITIALIZE_HINT_NORMAL)
switch(result)
if(INITIALIZE_HINT_LATELOAD)
if(arguments[1]) //mapload
late_loaders += A
else
A.LateInitialize()
if(INITIALIZE_HINT_QDEL)
qdel(A)
qdeleted = TRUE
else
BadInitializeCalls[the_type] |= BAD_INIT_NO_HINT
if(!A) //possible harddel
qdeleted = TRUE
else if(!A.initialized)
BadInitializeCalls[the_type] |= BAD_INIT_DIDNT_INIT
return qdeleted || QDELETED(A)
/datum/controller/subsystem/atoms/proc/map_loader_begin()
old_initialized = initialized
@@ -90,6 +109,7 @@ SUBSYSTEM_DEF(atoms)
if(initialized == INITIALIZATION_INNEW_MAPLOAD)
InitializeAtoms()
old_initialized = SSatoms.old_initialized
BadInitializeCalls = SSatoms.BadInitializeCalls
/datum/controller/subsystem/atoms/proc/setupGenetics()
var/list/avnums = new /list(DNA_STRUC_ENZYMES_BLOCKS)
+9
View File
@@ -0,0 +1,9 @@
diff a/code/controllers/subsystem/atoms.dm b/code/controllers/subsystem/atoms.dm (rejected hunks)
@@ -12,6 +12,7 @@ SUBSYSTEM_DEF(atoms)
var/old_initialized
var/list/late_loaders
+ var/list/created_atoms
var/list/BadInitializeCalls = list()
+20 -10
View File
@@ -39,20 +39,21 @@
var/do_initialize = SSatoms.initialized
if(do_initialize > INITIALIZATION_INSSATOMS)
if(QDELETED(src))
CRASH("Found new qdeletion in type [type]!")
var/mapload = do_initialize == INITIALIZATION_INNEW_MAPLOAD
args[1] = mapload
if(Initialize(arglist(args)) && mapload)
LAZYADD(SSatoms.late_loaders, src)
args[1] = do_initialize == INITIALIZATION_INNEW_MAPLOAD
if(SSatoms.InitAtom(src, args))
//we were deleted
return
var/list/created = SSatoms.created_atoms
if(created)
created += src
//Called after New if the map is being loaded. mapload = TRUE
//Called from base of New if the map is being loaded. mapload = FALSE
//This base must be called or derivatives must set initialized to TRUE to prevent repeat calls
//Derivatives must not sleep
//Returning TRUE while mapload is TRUE will cause the object to be initialized again with mapload = FALSE when everything else is done
//(Useful for things that requires turfs to have air). This base may only be called once, however
//This base must be called or derivatives must set initialized to TRUE
//must not sleep
//Other parameters are passed from New (excluding loc), this does not happen if mapload is TRUE
//Must return an Initialize hint. Defined in __DEFINES/subsystems.dm
//Note: the following functions don't call the base for optimization and must copypasta:
// /turf/Initialize
@@ -75,7 +76,16 @@
if (opacity && isturf(loc))
var/turf/T = loc
T.has_opaque_atom = TRUE // No need to recalculate it in this case, it's guaranteed to be on afterwards anyways.
return INITIALIZE_HINT_NORMAL
//called if Initialize returns INITIALIZE_HINT_LATELOAD
//This version shouldn't be called
/atom/proc/LateInitialize()
var/static/list/warned_types = list()
if(!warned_types[type])
WARNING("Old style LateInitialize behaviour detected in [type]!")
warned_types[type] = TRUE
Initialize(FALSE)
/atom/Destroy()
if(alternate_appearances)
+1 -1
View File
@@ -45,7 +45,7 @@
return ..()
/atom/movable/Initialize(mapload)
..()
. = ..()
for(var/L in initial_languages)
grant_language(L)
@@ -135,10 +135,10 @@
/obj/machinery/abductor/console/Initialize(mapload)
if(mapload)
return TRUE //wait for machines list
..()
return INITIALIZE_HINT_LATELOAD
/obj/machinery/abductor/console/LateInitialize()
if(!team)
return
@@ -19,12 +19,12 @@
/obj/machinery/doorButtons/proc/findObjsByTag()
return
/obj/machinery/doorButtons/Initialize(mapload)
if(mapload)
..()
return TRUE
else
findObjsByTag()
/obj/machinery/doorButtons/Initialize()
..()
return INITIALIZE_HINT_LATELOAD
/obj/machinery/doorButtons/LateInitialize()
findObjsByTag()
/obj/machinery/doorButtons/emag_act(mob/user)
if(!emagged)
+10
View File
@@ -0,0 +1,10 @@
diff a/code/game/objects/items.dm b/code/game/objects/items.dm (rejected hunks)
@@ -102,7 +102,7 @@ var/global/image/fire_overlay = image("icon" = 'icons/effects/fire.dmi', "icon_s
/obj/item/Initialize()
if (!materials)
materials = list()
- ..()
+ . = ..()
for(var/path in actions_types)
new path(src)
actions_types = null
+1 -1
View File
@@ -37,7 +37,7 @@
..()
/obj/Initialize()
..()
. = ..()
if (!armor)
armor = list(melee = 0, bullet = 0, laser = 0, energy = 0, bomb = 0, bio = 0, rad = 0, fire = 0, acid = 0)
if(on_blueprints && isturf(loc))
+4 -7
View File
@@ -14,18 +14,15 @@
/obj/structure/ladder/Initialize(mapload)
if(!initialized)
GLOB.ladders += src
..()
if(mapload)
return TRUE
update_link()
GLOB.ladders += src
..()
return INITIALIZE_HINT_LATELOAD
/obj/structure/ladder/Destroy()
GLOB.ladders -= src
. = ..()
/obj/structure/ladder/proc/update_link()
/obj/structure/ladder/LateInitialize()
for(var/obj/structure/ladder/L in GLOB.ladders)
if(L.id == id)
if(L.height == (height - 1))
+2
View File
@@ -42,6 +42,8 @@
if (opacity)
has_opaque_atom = TRUE
return INITIALIZE_HINT_NORMAL
/turf/open/space/attack_ghost(mob/dead/observer/user)
if(destination_z)
+1
View File
@@ -56,6 +56,7 @@
if (opacity)
has_opaque_atom = TRUE
return INITIALIZE_HINT_NORMAL
/turf/proc/Initalize_Atmos(times_fired)
CalculateAdjacentTurfs()
+11
View File
@@ -0,0 +1,11 @@
diff a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm (rejected hunks)
@@ -153,7 +153,8 @@ var/list/admin_verbs_debug = list(
/client/proc/clear_dynamic_transit,
/client/proc/toggle_medal_disable,
/client/proc/view_runtimes,
- /client/proc/pump_random_event
+ /client/proc/pump_random_event,
+ /client/proc/cmd_display_init_log
)
var/list/admin_verbs_possess = list(
/proc/possess,
+7
View File
@@ -721,6 +721,13 @@ GLOBAL_PROTECT(AdminProcCall)
usr << browse(dat, "window=dellog")
/client/proc/cmd_display_init_log()
set category = "Debug"
set name = "Display Initialzie() Log"
set desc = "Displays a list of things that didn't handle Initialize() properly"
usr << browse(replacetext(SSatoms.InitLog(), "\n", "<br>"), "window=initlog")
/client/proc/debug_huds(i as num)
set category = "Debug"
set name = "Debug HUDs"
+47
View File
@@ -0,0 +1,47 @@
diff a/code/modules/holodeck/computer.dm b/code/modules/holodeck/computer.dm (rejected hunks)
@@ -64,25 +64,26 @@
..()
/obj/machinery/computer/holodeck/Initialize(mapload)
- . = mapload //late-initialize, area_copy need turfs to have air
- if(!mapload)
- ..()
- program_cache = list()
- emag_programs = list()
- for(var/typekey in subtypesof(program_type))
- var/area/holodeck/A = locate(typekey)
- if(!A || A == offline_program) continue
- if(A.contents.len == 0) continue // not loaded
- if(A.restricted)
- emag_programs += A
- else
- program_cache += A
- if(typekey == init_program)
- load_program(A,force=1)
- if(random_program && program_cache.len && init_program == null)
- load_program(pick(program_cache),force=1)
- else if(!program)
- load_program(offline_program)
+ ..()
+ return INITIALIZE_HINT_LATELOAD
+
+/obj/machinery/computer/holodeck/LateInitialize()
+ program_cache = list()
+ emag_programs = list()
+ for(var/typekey in subtypesof(program_type))
+ var/area/holodeck/A = locate(typekey)
+ if(!A || A == offline_program) continue
+ if(A.contents.len == 0) continue // not loaded
+ if(A.restricted)
+ emag_programs += A
+ else
+ program_cache += A
+ if(typekey == init_program)
+ load_program(A,force=1)
+ if(random_program && program_cache.len && init_program == null)
+ load_program(pick(program_cache),force=1)
+ else if(!program)
+ load_program(offline_program)
/obj/machinery/computer/holodeck/power_change()
..()
+2 -5
View File
@@ -1,9 +1,6 @@
//Dead mobs can exist whenever. This is needful
/mob/dead/New(loc)
..()
if(!initialized)
args[1] = FALSE
Initialize(arglist(args)) //EXIST DAMN YOU!!!
INITIALIZE_IMMEDIATE(/mob/dead)
/mob/dead/dust() //ghosts can't be vaporised.
return
@@ -0,0 +1,9 @@
diff a/code/modules/mob/dead/new_player/new_player.dm b/code/modules/mob/dead/new_player/new_player.dm (rejected hunks)
@@ -30,6 +30,7 @@
loc = pick(newplayer_start)
else
loc = locate(1,1,1)
+ return INITIALIZE_HINT_NORMAL
/mob/dead/new_player/proc/new_player_panel()
+10
View File
@@ -0,0 +1,10 @@
diff a/code/modules/recycling/conveyor2.dm b/code/modules/recycling/conveyor2.dm (rejected hunks)
@@ -220,7 +220,7 @@
id = newid
update()
- return INITIALIZE_HINT_LATELOAD
+ return INITIALIZE_HINT_LATELOAD //for machines list
/obj/machinery/conveyor_switch/LateInitialize()
conveyors = list()
+11 -11
View File
@@ -64,17 +64,17 @@
deconstruct()
/obj/machinery/disposal/Initialize(mapload)
. = mapload //late-initialize, we need turfs to have air
if(initialized) //will only be run on late mapload initialization
//this will get a copy of the air turf and take a SEND PRESSURE amount of air from it
var/atom/L = loc
var/datum/gas_mixture/env = new
env.copy_from(L.return_air())
var/datum/gas_mixture/removed = env.remove(SEND_PRESSURE + 1)
air_contents.merge(removed)
trunk_check()
else
..()
..()
return INITIALIZE_HINT_LATELOAD //we need turfs to have air
/obj/machinery/disposal/LateInitialize()
//this will get a copy of the air turf and take a SEND PRESSURE amount of air from it
var/atom/L = loc
var/datum/gas_mixture/env = new
env.copy_from(L.return_air())
var/datum/gas_mixture/removed = env.remove(SEND_PRESSURE + 1)
air_contents.merge(removed)
trunk_check()
/obj/machinery/disposal/attackby(obj/item/I, mob/user, params)
add_fingerprint(user)
+11
View File
@@ -0,0 +1,11 @@
diff a/code/modules/shuttle/arrivals.dm b/code/modules/shuttle/arrivals.dm (rejected hunks)
@@ -30,6 +30,9 @@
..()
preferred_direction = dir
+ return INITIALIZE_HINT_LATELOAD //for latejoin list
+
+/obj/docking_port/mobile/arrivals/LateInitialize()
areas = list()
var/list/new_latejoin = list()
+1 -1
View File
@@ -54,7 +54,7 @@
return new step_type
/datum/surgery/proc/complete()
feedback_add_details("surgeries_completed", "[type]")
feedback_add_details("surgeries_completed", type)
qdel(src)
+10
View File
@@ -0,0 +1,10 @@
diff a/code/modules/surgery/surgery.dm b/code/modules/surgery/surgery.dm (rejected hunks)
@@ -54,7 +54,7 @@
return new step_type
/datum/surgery/proc/complete()
- feedback_add_details("surgeries_completed", type)
+ feedback_add_details("surgeries_completed", "[type]")
qdel(src)