From 2d252f3b6747f0a06d200489021d7a5a33afea1b Mon Sep 17 00:00:00 2001 From: AffectedArc07 Date: Wed, 27 May 2020 21:29:58 +0100 Subject: [PATCH 1/2] Annihilates the global iterator --- code/datums/helper_datums/global_iterator.dm | 152 ------------------- code/modules/spacepods/spacepod.dm | 41 ++--- paradise.dme | 1 - 3 files changed, 15 insertions(+), 179 deletions(-) delete mode 100644 code/datums/helper_datums/global_iterator.dm diff --git a/code/datums/helper_datums/global_iterator.dm b/code/datums/helper_datums/global_iterator.dm deleted file mode 100644 index 214045941b5..00000000000 --- a/code/datums/helper_datums/global_iterator.dm +++ /dev/null @@ -1,152 +0,0 @@ -/* -README: - -The global_iterator datum is supposed to provide a simple and robust way to -create some constantly "looping" processes with ability to stop and restart them at will. -Generally, the only thing you want to play with (meaning, redefine) is the process() proc. -It must contain all the things you want done. - -Control functions: - new - used to create datum. First argument (optional) - var list(to use in process() proc) as list, - second (optional) - autostart control. - If autostart == TRUE, the loop will be started immediately after datum creation. - - start(list/arguments) - starts the loop. Takes arguments(optional) as a list, which is then used - by process() proc. Returns null if datum already active, 1 if loop started succesfully and 0 if there's - an error in supplied arguments (not list or empty list). - - stop() - stops the loop. Returns null if datum is already inactive and 1 on success. - - set_delay(new_delay) - sets the delay between iterations. Pretty selfexplanatory. - Returns 0 on error(new_delay is not numerical), 1 otherwise. - - set_process_args(list/arguments) - passes the supplied arguments to the process() proc. - - active() - Returns 1 if datum is active, 0 otherwise. - - toggle() - toggles datum state. Returns new datum state (see active()). - -Misc functions: - - get_last_exec_time() - Returns the time of last iteration. - - get_last_exec_time_as_text() - Returns the time of last iteration as text - - -Control vars: - - delay - delay between iterations - - check_for_null - if equals TRUE, on each iteration the supplied arguments will be checked for nulls. - If some varible equals null (and null only), the loop is stopped. - Usefull, if some var unexpectedly becomes null - due to object deletion, for example. - Of course, you can also check the variables inside process() proc to prevent runtime errors. - -Data storage vars: - - result - stores the value returned by process() proc -*/ - -/datum/global_iterator - var/control_switch = 0 - var/delay = 10 - var/list/arg_list = new - var/last_exec = null - var/check_for_null = 1 - var/forbid_garbage = 0 - var/result - var/state = 0 - -/datum/global_iterator/New(list/arguments=null,autostart=1) - delay = delay>0?(delay):1 - if(forbid_garbage) //prevents garbage collection with tag != null - tag = "\ref[src]" - set_process_args(arguments) - if(autostart) - start() - return - -/datum/global_iterator/proc/main() - state = 1 - while(src && control_switch) - last_exec = world.timeofday - if(check_for_null && has_null_args()) - stop() - return 0 - result = process(arglist(arg_list)) - for(var/sleep_time=delay;sleep_time>0;sleep_time--) //uhh, this is ugly. But I see no other way to terminate sleeping proc. Such disgrace. - if(!control_switch) - return 0 - sleep(1) - return 0 - -/datum/global_iterator/proc/start(list/arguments=null) - if(active()) - return - if(arguments) - if(!set_process_args(arguments)) - return 0 - if(!state_check()) //the main loop is sleeping, wait for it to terminate. - return - control_switch = 1 - spawn() - state = main() - return 1 - -/datum/global_iterator/proc/stop() - if(!active()) - return - control_switch = 0 - spawn(-1) //report termination error but don't wait for state_check(). - state_check() - return 1 - -/datum/global_iterator/proc/state_check() - var/lag = 0 - while(state) - sleep(1) - if(++lag>10) - CRASH("The global_iterator loop \ref[src] failed to terminate in designated timeframe. This may be caused by server lagging.") - return 1 - -/datum/global_iterator/process() - return - -/datum/global_iterator/proc/active() - return control_switch - -/datum/global_iterator/proc/has_null_args() - if(null in arg_list) - return 1 - return 0 - - -/datum/global_iterator/proc/set_delay(new_delay) - if(isnum(new_delay)) - delay = max(1, round(new_delay)) - return 1 - else - return 0 - -/datum/global_iterator/proc/get_last_exec_time() - return (last_exec||0) - -/datum/global_iterator/proc/get_last_exec_time_as_text() - return (time2text(last_exec)||"Wasn't executed yet") - -/datum/global_iterator/proc/set_process_args(list/arguments) - if(arguments && istype(arguments, /list) && arguments.len) - arg_list = arguments - return 1 - else -// to_chat(world, "Invalid arguments supplied for [src.type], ref = \ref[src]") - return 0 - -/datum/global_iterator/proc/toggle_null_checks() - check_for_null = !check_for_null - return check_for_null - -/datum/global_iterator/proc/toggle() - if(!stop()) - start() - return active() diff --git a/code/modules/spacepods/spacepod.dm b/code/modules/spacepods/spacepod.dm index de24c351c4a..1da2e1d0e33 100644 --- a/code/modules/spacepods/spacepod.dm +++ b/code/modules/spacepods/spacepod.dm @@ -37,8 +37,6 @@ var/datum/gas_mixture/cabin_air var/obj/machinery/portable_atmospherics/canister/internal_tank var/use_internal_tank = 0 - var/datum/global_iterator/pr_int_temp_processor //normalizes internal air mixture temperature - var/datum/global_iterator/pr_give_air //moves air from tank to cabin var/datum/effect_system/trail_follow/ion/space_trail/ion_trail @@ -117,8 +115,6 @@ src.ion_trail.set_up(src) src.ion_trail.start() src.use_internal_tank = 1 - pr_int_temp_processor = new /datum/global_iterator/pod_preserve_temp(list(src)) - pr_give_air = new /datum/global_iterator/pod_tank_give_air(list(src)) equipment_system = new(src) equipment_system.installed_modules += battery GLOB.spacepods_list += src @@ -127,6 +123,7 @@ cargo_hold.storage_slots = 0 //You need to install cargo modules to use it. cargo_hold.max_w_class = 5 //fit almost anything cargo_hold.max_combined_w_class = 0 //you can optimize your stash with larger items + START_PROCESSING(SSobj, src) /obj/spacepod/Destroy() if(equipment_system.cargo_system) @@ -136,8 +133,6 @@ QDEL_NULL(battery) QDEL_NULL(cabin_air) QDEL_NULL(internal_tank) - QDEL_NULL(pr_int_temp_processor) - QDEL_NULL(pr_give_air) QDEL_NULL(ion_trail) occupant_sanity_check() if(pilot) @@ -148,13 +143,14 @@ M.forceMove(get_turf(src)) passengers -= M GLOB.spacepods_list -= src + STOP_PROCESSING(SSobj, src) return ..() /obj/spacepod/process() + give_air() + regulate_temp() if(src.empcounter > 0) src.empcounter-- - else - STOP_PROCESSING(SSobj, src) /obj/spacepod/proc/update_icons() if(!pod_overlays) @@ -998,22 +994,17 @@ return 1 -/datum/global_iterator/pod_preserve_temp //normalizing cabin air temperature to 20 degrees celsium - delay = 20 - - process(var/obj/spacepod/spacepod) - if(spacepod.cabin_air && spacepod.cabin_air.return_volume() > 0) - var/delta = spacepod.cabin_air.temperature - T20C - spacepod.cabin_air.temperature -= max(-10, min(10, round(delta/4,0.1))) - -/datum/global_iterator/pod_tank_give_air - delay = 15 - -/datum/global_iterator/pod_tank_give_air/process(var/obj/spacepod/spacepod) - if(spacepod && spacepod.internal_tank) - var/datum/gas_mixture/tank_air = spacepod.internal_tank.return_air() - var/datum/gas_mixture/cabin_air = spacepod.cabin_air +// Fun fact, these procs are just copypastes from mech code +// And have been for the past 4 years +// Please send help +/obj/spacepod/proc/regulate_temp() + if(cabin_air && cabin_air.return_volume() > 0) + var/delta = cabin_air.temperature - T20C + cabin_air.temperature -= max(-10, min(10, round(delta/4,0.1))) +/obj/spacepod/proc/give_air() + if(internal_tank) + var/datum/gas_mixture/tank_air = internal_tank.return_air() var/release_pressure = ONE_ATMOSPHERE var/cabin_pressure = cabin_air.return_pressure() var/pressure_delta = min(release_pressure - cabin_pressure, (tank_air.return_pressure() - cabin_pressure)/2) @@ -1024,7 +1015,7 @@ var/datum/gas_mixture/removed = tank_air.remove(transfer_moles) cabin_air.merge(removed) else if(pressure_delta < 0) //cabin pressure higher than release pressure - var/datum/gas_mixture/t_air = spacepod.get_turf_air() + var/datum/gas_mixture/t_air = get_turf_air() pressure_delta = cabin_pressure - release_pressure if(t_air) pressure_delta = min(cabin_pressure - t_air.return_pressure(), pressure_delta) @@ -1035,8 +1026,6 @@ t_air.merge(removed) else //just delete the cabin gas, we're in space or some shit qdel(removed) - else - return stop() /obj/spacepod/relaymove(mob/user, direction) if(user != src.pilot) diff --git a/paradise.dme b/paradise.dme index acc84e8d18f..3e4d100880a 100644 --- a/paradise.dme +++ b/paradise.dme @@ -360,7 +360,6 @@ #include "code\datums\diseases\advance\symptoms\youth.dm" #include "code\datums\helper_datums\construction_datum.dm" #include "code\datums\helper_datums\events.dm" -#include "code\datums\helper_datums\global_iterator.dm" #include "code\datums\helper_datums\icon_snapshot.dm" #include "code\datums\helper_datums\input.dm" #include "code\datums\helper_datums\map_template.dm" From 793f18c5e55ae8d643a490dc8f5805ecaeabdfe3 Mon Sep 17 00:00:00 2001 From: AffectedArc07 Date: Thu, 28 May 2020 15:16:53 +0100 Subject: [PATCH 2/2] Fixes dupe processing --- code/modules/spacepods/spacepod.dm | 1 - 1 file changed, 1 deletion(-) diff --git a/code/modules/spacepods/spacepod.dm b/code/modules/spacepods/spacepod.dm index 1da2e1d0e33..2e3c89017ef 100644 --- a/code/modules/spacepods/spacepod.dm +++ b/code/modules/spacepods/spacepod.dm @@ -284,7 +284,6 @@ deal_damage(80 / severity) if(empcounter < (40 / severity)) empcounter = 40 / severity - START_PROCESSING(SSobj, src) switch(severity) if(1)