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

View File

@@ -14,5 +14,6 @@
#define GC_QUEUED_FOR_HARD_DEL -2 #define GC_QUEUED_FOR_HARD_DEL -2
#define GC_CURRENTLY_BEING_QDELETED -3 #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) #define QDESTROYING(X) (!X || X.gc_destroyed == GC_CURRENTLY_BEING_QDELETED)

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

View File

@@ -544,7 +544,7 @@
plane = SPLASHSCREEN_PLANE plane = SPLASHSCREEN_PLANE
var/client/holder 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 holder = C
if(!visible) if(!visible)

View File

@@ -3,7 +3,9 @@
name = "Initializing..." name = "Initializing..."
var/target 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 name = text
src.target = target src.target = target

View File

@@ -1,6 +1,7 @@
#define INITIALIZATION_INSSATOMS 0 //New should not call Initialize #define BAD_INIT_QDEL_BEFORE 1
#define INITIALIZATION_INNEW_MAPLOAD 1 //New should call Initialize(TRUE) #define BAD_INIT_DIDNT_INIT 2
#define INITIALIZATION_INNEW_REGULAR 2 //New should call Initialize(FALSE) #define BAD_INIT_SLEPT 4
#define BAD_INIT_NO_HINT 8
SUBSYSTEM_DEF(atoms) SUBSYSTEM_DEF(atoms)
name = "Atoms" name = "Atoms"
@@ -19,64 +20,82 @@ SUBSYSTEM_DEF(atoms)
InitializeAtoms() InitializeAtoms()
return ..() return ..()
/datum/controller/subsystem/atoms/proc/InitializeAtoms(list/atoms = null) /datum/controller/subsystem/atoms/proc/InitializeAtoms(list/atoms)
if(initialized == INITIALIZATION_INSSATOMS) if(initialized == INITIALIZATION_INSSATOMS)
return return
initialized = INITIALIZATION_INNEW_MAPLOAD initialized = INITIALIZATION_INNEW_MAPLOAD
var/static/list/NewQdelList = list() LAZYINITLIST(late_loaders)
if(atoms) var/count
for(var/I in atoms) var/list/mapload_arg = list(TRUE)
var/atom/A = I if(atoms)
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 created_atoms = list()
if(QDELETED(A)) count = atoms.len
if(!(NewQdelList[A.type])) for(var/I in atoms)
WARNING("Found new qdeletion in type [A.type]!") var/atom/A = I
NewQdelList[A.type] = TRUE if(!A.initialized)
continue if(InitAtom(I, mapload_arg))
var/start_tick = world.time atoms -= I
if(A.Initialize(TRUE)) CHECK_TICK
LAZYADD(late_loaders, A) else
if(start_tick != world.time) count = 0
WARNING("[A]: [A.type] slept during it's Initialize!") for(var/atom/A in world)
CHECK_TICK if(!A.initialized)
testing("Initialized [atoms.len] atoms") InitAtom(A, mapload_arg)
else ++count
#ifdef TESTING CHECK_TICK
var/count = 0
#endif log_world("Initialized [count] atoms")
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 initialized = INITIALIZATION_INNEW_REGULAR
if(QDELETED(A))
if(!(NewQdelList[A.type])) if(late_loaders.len)
WARNING("Found new qdeletion in type [A.type]!") for(var/I in late_loaders)
NewQdelList[A.type] = TRUE var/atom/A = I
continue A.LateInitialize()
var/start_tick = world.time testing("Late initialized [late_loaders.len] atoms")
if(A.Initialize(TRUE)) late_loaders.Cut()
LAZYADD(late_loaders, A)
#ifdef TESTING if(atoms)
else . = created_atoms + atoms
++count created_atoms = null
#endif TESTING
if(start_tick != world.time) /datum/controller/subsystem/atoms/proc/InitAtom(atom/A, list/arguments)
WARNING("[A]: [A.type] slept during it's Initialize!") var/the_type = A.type
CHECK_TICK if(QDELING(A))
testing("Roundstart initialized [count] atoms") BadInitializeCalls[the_type] |= BAD_INIT_QDEL_BEFORE
return TRUE
initialized = INITIALIZATION_INNEW_REGULAR
var/start_tick = world.time
for(var/I in late_loaders)
var/atom/A = I var/result = A.Initialize(arglist(arguments))
var/start_tick = world.time
A.Initialize(FALSE) if(start_tick != world.time)
if(start_tick != world.time) BadInitializeCalls[the_type] |= BAD_INIT_SLEPT
WARNING("[A]: [A.type] slept during it's Initialize!")
CHECK_TICK var/qdeleted = FALSE
testing("Late-initialized [LAZYLEN(late_loaders)] atoms")
LAZYCLEARLIST(late_loaders) 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() /datum/controller/subsystem/atoms/proc/map_loader_begin()
old_initialized = initialized old_initialized = initialized
@@ -90,6 +109,7 @@ SUBSYSTEM_DEF(atoms)
if(initialized == INITIALIZATION_INNEW_MAPLOAD) if(initialized == INITIALIZATION_INNEW_MAPLOAD)
InitializeAtoms() InitializeAtoms()
old_initialized = SSatoms.old_initialized old_initialized = SSatoms.old_initialized
BadInitializeCalls = SSatoms.BadInitializeCalls
/datum/controller/subsystem/atoms/proc/setupGenetics() /datum/controller/subsystem/atoms/proc/setupGenetics()
var/list/avnums = new /list(DNA_STRUC_ENZYMES_BLOCKS) var/list/avnums = new /list(DNA_STRUC_ENZYMES_BLOCKS)

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

View File

@@ -39,20 +39,21 @@
var/do_initialize = SSatoms.initialized var/do_initialize = SSatoms.initialized
if(do_initialize > INITIALIZATION_INSSATOMS) if(do_initialize > INITIALIZATION_INSSATOMS)
if(QDELETED(src)) args[1] = do_initialize == INITIALIZATION_INNEW_MAPLOAD
CRASH("Found new qdeletion in type [type]!") if(SSatoms.InitAtom(src, args))
var/mapload = do_initialize == INITIALIZATION_INNEW_MAPLOAD //we were deleted
args[1] = mapload return
if(Initialize(arglist(args)) && mapload)
LAZYADD(SSatoms.late_loaders, src) var/list/created = SSatoms.created_atoms
if(created)
created += src
//Called after New if the map is being loaded. mapload = TRUE //Called after New if the map is being loaded. mapload = TRUE
//Called from base of New if the map is being loaded. mapload = FALSE //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 //This base must be called or derivatives must set initialized to TRUE
//Derivatives must not sleep //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
//Other parameters are passed from New (excluding loc), this does not happen if mapload is TRUE //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: //Note: the following functions don't call the base for optimization and must copypasta:
// /turf/Initialize // /turf/Initialize
@@ -75,7 +76,16 @@
if (opacity && isturf(loc)) if (opacity && isturf(loc))
var/turf/T = 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. 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() /atom/Destroy()
if(alternate_appearances) if(alternate_appearances)

View File

@@ -45,7 +45,7 @@
return ..() return ..()
/atom/movable/Initialize(mapload) /atom/movable/Initialize(mapload)
..() . = ..()
for(var/L in initial_languages) for(var/L in initial_languages)
grant_language(L) grant_language(L)

View File

@@ -135,10 +135,10 @@
/obj/machinery/abductor/console/Initialize(mapload) /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) if(!team)
return return

View File

@@ -19,12 +19,12 @@
/obj/machinery/doorButtons/proc/findObjsByTag() /obj/machinery/doorButtons/proc/findObjsByTag()
return return
/obj/machinery/doorButtons/Initialize(mapload) /obj/machinery/doorButtons/Initialize()
if(mapload) ..()
..() return INITIALIZE_HINT_LATELOAD
return TRUE
else /obj/machinery/doorButtons/LateInitialize()
findObjsByTag() findObjsByTag()
/obj/machinery/doorButtons/emag_act(mob/user) /obj/machinery/doorButtons/emag_act(mob/user)
if(!emagged) if(!emagged)

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

View File

@@ -37,7 +37,7 @@
..() ..()
/obj/Initialize() /obj/Initialize()
..() . = ..()
if (!armor) if (!armor)
armor = list(melee = 0, bullet = 0, laser = 0, energy = 0, bomb = 0, bio = 0, rad = 0, fire = 0, acid = 0) 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)) if(on_blueprints && isturf(loc))

View File

@@ -14,18 +14,15 @@
/obj/structure/ladder/Initialize(mapload) /obj/structure/ladder/Initialize(mapload)
if(!initialized) GLOB.ladders += src
GLOB.ladders += src ..()
..() return INITIALIZE_HINT_LATELOAD
if(mapload)
return TRUE
update_link()
/obj/structure/ladder/Destroy() /obj/structure/ladder/Destroy()
GLOB.ladders -= src GLOB.ladders -= src
. = ..() . = ..()
/obj/structure/ladder/proc/update_link() /obj/structure/ladder/LateInitialize()
for(var/obj/structure/ladder/L in GLOB.ladders) for(var/obj/structure/ladder/L in GLOB.ladders)
if(L.id == id) if(L.id == id)
if(L.height == (height - 1)) if(L.height == (height - 1))

View File

@@ -42,6 +42,8 @@
if (opacity) if (opacity)
has_opaque_atom = TRUE has_opaque_atom = TRUE
return INITIALIZE_HINT_NORMAL
/turf/open/space/attack_ghost(mob/dead/observer/user) /turf/open/space/attack_ghost(mob/dead/observer/user)
if(destination_z) if(destination_z)

View File

@@ -56,6 +56,7 @@
if (opacity) if (opacity)
has_opaque_atom = TRUE has_opaque_atom = TRUE
return INITIALIZE_HINT_NORMAL
/turf/proc/Initalize_Atmos(times_fired) /turf/proc/Initalize_Atmos(times_fired)
CalculateAdjacentTurfs() CalculateAdjacentTurfs()

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,

View File

@@ -721,6 +721,13 @@ GLOBAL_PROTECT(AdminProcCall)
usr << browse(dat, "window=dellog") 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) /client/proc/debug_huds(i as num)
set category = "Debug" set category = "Debug"
set name = "Debug HUDs" set name = "Debug HUDs"

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

View File

@@ -1,9 +1,6 @@
//Dead mobs can exist whenever. This is needful //Dead mobs can exist whenever. This is needful
/mob/dead/New(loc)
..() INITIALIZE_IMMEDIATE(/mob/dead)
if(!initialized)
args[1] = FALSE
Initialize(arglist(args)) //EXIST DAMN YOU!!!
/mob/dead/dust() //ghosts can't be vaporised. /mob/dead/dust() //ghosts can't be vaporised.
return return

View File

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

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

View File

@@ -64,17 +64,17 @@
deconstruct() deconstruct()
/obj/machinery/disposal/Initialize(mapload) /obj/machinery/disposal/Initialize(mapload)
. = mapload //late-initialize, we need turfs to have air ..()
if(initialized) //will only be run on late mapload initialization return INITIALIZE_HINT_LATELOAD //we need turfs to have air
//this will get a copy of the air turf and take a SEND PRESSURE amount of air from it
var/atom/L = loc /obj/machinery/disposal/LateInitialize()
var/datum/gas_mixture/env = new //this will get a copy of the air turf and take a SEND PRESSURE amount of air from it
env.copy_from(L.return_air()) var/atom/L = loc
var/datum/gas_mixture/removed = env.remove(SEND_PRESSURE + 1) var/datum/gas_mixture/env = new
air_contents.merge(removed) env.copy_from(L.return_air())
trunk_check() var/datum/gas_mixture/removed = env.remove(SEND_PRESSURE + 1)
else air_contents.merge(removed)
..() trunk_check()
/obj/machinery/disposal/attackby(obj/item/I, mob/user, params) /obj/machinery/disposal/attackby(obj/item/I, mob/user, params)
add_fingerprint(user) add_fingerprint(user)

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

View File

@@ -54,7 +54,7 @@
return new step_type return new step_type
/datum/surgery/proc/complete() /datum/surgery/proc/complete()
feedback_add_details("surgeries_completed", "[type]") feedback_add_details("surgeries_completed", type)
qdel(src) qdel(src)

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)