diff --git a/code/__DEFINES/MC.dm b/code/__DEFINES/MC.dm index a68d33ecfe7..4e8369bd454 100644 --- a/code/__DEFINES/MC.dm +++ b/code/__DEFINES/MC.dm @@ -28,8 +28,8 @@ #define NEW_SS_GLOBAL(varname) if(varname != src){if(istype(varname)){Recover();qdel(varname);}varname = src;} -// #define START_PROCESSING(Processor, Datum) if (!(Datum.datum_flags & DF_ISPROCESSING)) {Datum.datum_flags |= DF_ISPROCESSING;Processor.processing += Datum} -// #define STOP_PROCESSING(Processor, Datum) Datum.datum_flags &= ~DF_ISPROCESSING;Processor.processing -= Datum;Processor.currentrun -= Datum +#define START_PROCESSING(Processor, Datum) if (!(Datum.datum_flags & DF_ISPROCESSING)) {Datum.datum_flags |= DF_ISPROCESSING;Processor.processing += Datum} +#define STOP_PROCESSING(Processor, Datum) Datum.datum_flags &= ~DF_ISPROCESSING;Processor.processing -= Datum;Processor.currentrun -= Datum /// Returns true if the MC is initialized and running. /// Optional argument init_stage controls what stage the mc must have initializted to count as initialized. Defaults to INITSTAGE_MAX if not specified. diff --git a/code/__DEFINES/_flags.dm b/code/__DEFINES/_flags.dm index cdcaaf21c3d..2dfb225b529 100644 --- a/code/__DEFINES/_flags.dm +++ b/code/__DEFINES/_flags.dm @@ -5,6 +5,7 @@ GLOBAL_LIST_INIT(bitflags, list(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 204 // for /datum/var/datum_flags #define DF_USE_TAG (1<<0) +#define DF_ISPROCESSING (1<<2) ///Whether /atom/Initialize() has already run for the object #define INITIALIZED_1 (1<<5) diff --git a/code/__DEFINES/subsystem-priority.dm b/code/__DEFINES/subsystem-priority.dm index 5a17e0f0082..c8fc867e158 100644 --- a/code/__DEFINES/subsystem-priority.dm +++ b/code/__DEFINES/subsystem-priority.dm @@ -56,7 +56,6 @@ // SS_BACKGROUND -#define SS_PRIORITY_PROCESSING 50 // Generic datum processor. Replaces objects processor. //#define FIRE_PRIORITY_DEFAULT 50 // This is defined somewhere else. #define SS_PRIORITY_PSYCHICS 30 #define SS_PRIORITY_EVAC 30 // Processes the evac controller. diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 8fe6a8fcbdf..4863183796f 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -1,7 +1,3 @@ -// -- SSprocessing stuff -- -#define START_PROCESSING(Processor, Datum) if (!Datum.isprocessing) {Datum.isprocessing = 1;Processor.processing += Datum} -#define STOP_PROCESSING(Processor, Datum) Datum.isprocessing = 0;Processor.processing -= Datum - /// START specific to SSmachinery #define START_PROCESSING_MACHINE(machine, flag)\ if(!istype(machine, /obj/machinery)) CRASH("A non-machine [log_info_line(machine)] was queued to process on the machinery subsystem.");\ @@ -11,7 +7,9 @@ /// STOP specific to SSmachinery #define STOP_PROCESSING_MACHINE(machine, flag)\ machine.processing_flags &= ~flag;\ - if(machine.processing_flags == 0) STOP_PROCESSING(SSmachinery, machine) + if(machine.processing_flags == 0){\ + machine.datum_flags &= ~DF_ISPROCESSING;\ + SSmachinery.processing -= machine} //! ## Timing subsystem /** @@ -113,10 +111,10 @@ #define EFFECT_DESTROY 2 // qdel. // Effect helpers. -#define QUEUE_EFFECT(effect) if (!effect.isprocessing) {effect.isprocessing = TRUE; SSeffects.effect_systems += effect;} -#define QUEUE_VISUAL(visual) if (!visual.isprocessing) {visual.isprocessing = TRUE; SSeffects.visuals += visual;} -#define STOP_EFFECT(effect) effect.isprocessing = FALSE; SSeffects.effect_systems -= effect; -#define STOP_VISUAL(visual) visual.isprocessing = FALSE; SSeffects.visuals -= visual; +#define QUEUE_EFFECT(effect) if (!(effect.datum_flags & DF_ISPROCESSING)) {effect.datum_flags |= DF_ISPROCESSING; SSeffects.effect_systems += effect;} +#define QUEUE_VISUAL(visual) if (!(visual.datum_flags & DF_ISPROCESSING)) {visual.datum_flags |= DF_ISPROCESSING; SSeffects.visuals += visual;} +#define STOP_EFFECT(effect) effect.datum_flags &= ~DF_ISPROCESSING; SSeffects.effect_systems -= effect; +#define STOP_VISUAL(visual) visual.datum_flags &= ~DF_ISPROCESSING; SSeffects.visuals -= visual; // -- SSfalling -- #define ADD_FALLING_ATOM(atom) if (!atom.multiz_falling) { atom.multiz_falling = 1; SSfalling.falling[atom] = 0; } @@ -255,6 +253,7 @@ #define FIRE_PRIORITY_GARBAGE 15 #define FIRE_PRIORITY_ASSETS 20 #define FIRE_PRIORITY_PATHFINDING 23 +#define FIRE_PRIORITY_PROCESS 25 #define FIRE_PRIORITY_DEFAULT 50 #define FIRE_PRIORITY_STATPANEL 390 #define FIRE_PRIORITY_CHAT 400 diff --git a/code/controllers/subsystems/effects.dm b/code/controllers/subsystems/effects.dm index ef369add3ee..afb4ba1fbcb 100644 --- a/code/controllers/subsystems/effects.dm +++ b/code/controllers/subsystems/effects.dm @@ -24,7 +24,7 @@ SUBSYSTEM_DEF(effects) var/datum/effect_system/E = current_effects[current_effects.len] current_effects.len-- - if (QDELETED(E) || !E.isprocessing) + if (QDELETED(E) || !(E.datum_flags & DF_ISPROCESSING)) if (MC_TICK_CHECK) return continue @@ -47,7 +47,7 @@ SUBSYSTEM_DEF(effects) var/obj/effect/visual/V = current_visuals[current_visuals.len] current_visuals.len-- - if (QDELETED(V) || !V.isprocessing) + if (QDELETED(V) || !(V.datum_flags & DF_ISPROCESSING)) visuals -= V if (MC_TICK_CHECK) return diff --git a/code/controllers/subsystems/machinery.dm b/code/controllers/subsystems/machinery.dm index 9ec5eeb53f8..86e07244d66 100644 --- a/code/controllers/subsystems/machinery.dm +++ b/code/controllers/subsystems/machinery.dm @@ -5,22 +5,19 @@ #define START_PROCESSING_IN_LIST(Datum, List) \ -if (Datum.isprocessing) {\ - if(Datum.isprocessing != "SSmachinery.[#List]")\ - {\ - crash_with("Failed to start processing. [log_info_line(Datum)] is already being processed by [Datum.isprocessing] but queue attempt occured on SSmachinery.[#List]."); \ - }\ +if (Datum.datum_flags & DF_ISPROCESSING) {\ + crash_with("Failed to start processing. [log_info_line(Datum)] is already being processed but queue attempt occured on SSmachinery.[#List]."); \ } else {\ - Datum.isprocessing = "SSmachinery.[#List]";\ + Datum.datum_flags |= DF_ISPROCESSING;\ SSmachinery.List += Datum;\ } #define STOP_PROCESSING_IN_LIST(Datum, List) \ -if(Datum.isprocessing) {\ +if(Datum.datum_flags & DF_ISPROCESSING) {\ if(SSmachinery.List.Remove(Datum)) {\ - Datum.isprocessing = null;\ + (Datum.datum_flags &= ~DF_ISPROCESSING);\ } else {\ - crash_with("Failed to stop processing. [log_info_line(Datum)] is being processed by [isprocessing] and not found in SSmachinery.[#List]"); \ + crash_with("Failed to stop processing. [log_info_line(Datum)] is being processed and not found in SSmachinery.[#List]"); \ }\ } @@ -35,9 +32,9 @@ if(Datum.isprocessing) {\ SUBSYSTEM_DEF(machinery) name = "Machinery" - priority = SS_PRIORITY_MACHINERY init_order = INIT_ORDER_MACHINES - flags = SS_POST_FIRE_TIMING + priority = SS_PRIORITY_MACHINERY + flags = SS_KEEP_TIMING wait = 2 SECONDS var/static/tmp/current_step = SSMACHINERY_PIPENETS @@ -164,7 +161,7 @@ SUBSYSTEM_DEF(machinery) network = queue[i] if (QDELETED(network)) if (network) - network.isprocessing = null + network.datum_flags &= ~DF_ISPROCESSING pipenets -= network continue network.process(wait * 0.1) @@ -186,7 +183,7 @@ SUBSYSTEM_DEF(machinery) continue // Hard delete; unlikely but possible. Soft deletes are handled below and expected. if(machine in processing) processing.Remove(machine) - machine.isprocessing = null + machine.datum_flags &= ~DF_ISPROCESSING WARNING("[log_info_line(machine)] was found illegally queued on SSmachines.") continue else if(resumed) @@ -200,7 +197,7 @@ SUBSYSTEM_DEF(machinery) if (QDELETED(machine)) if (machine) - machine.isprocessing = null + machine.datum_flags &= ~DF_ISPROCESSING processing -= machine continue //process_all was moved here because of calls overhead for no benefits @@ -222,7 +219,7 @@ SUBSYSTEM_DEF(machinery) network = queue[i] if (QDELETED(network)) if (network) - network.isprocessing = null + network.datum_flags &= ~DF_ISPROCESSING powernets -= network continue network.reset(wait) @@ -240,11 +237,11 @@ SUBSYSTEM_DEF(machinery) item = queue[i] if (QDELETED(item)) if (item) - item.isprocessing = null + item.datum_flags &= ~DF_ISPROCESSING power_objects -= item continue if (!item.pwr_drain(wait)) - item.isprocessing = null + item.datum_flags &= ~DF_ISPROCESSING power_objects -= item if (no_mc_tick) CHECK_TICK diff --git a/code/controllers/subsystems/processing/processing.dm b/code/controllers/subsystems/processing/processing.dm index e83e45f412b..eccfa750ad2 100644 --- a/code/controllers/subsystems/processing/processing.dm +++ b/code/controllers/subsystems/processing/processing.dm @@ -1,8 +1,10 @@ //Used to process objects. Fires once every two seconds. + SUBSYSTEM_DEF(processing) name = "Processing" - priority = SS_PRIORITY_PROCESSING + priority = FIRE_PRIORITY_PROCESS flags = SS_BACKGROUND|SS_POST_FIRE_TIMING|SS_NO_INIT + wait = 1 SECONDS var/stat_tag = "P" //Used for logging var/list/processing = list() @@ -21,17 +23,31 @@ SUBSYSTEM_DEF(processing) while(current_run.len) var/datum/thing = current_run[current_run.len] current_run.len-- - if(!QDELETED(thing)) - if (thing.process(wait, times_fired) == PROCESS_KILL) - stop_processing(thing) - else + if(QDELETED(thing)) processing -= thing + else if(thing.process(wait * 0.1) == PROCESS_KILL) + // fully stop so that a future START_PROCESSING will work + STOP_PROCESSING(src, thing) if (MC_TICK_CHECK) return -// Helper so PROCESS_KILL works. -/datum/controller/subsystem/processing/proc/stop_processing(datum/D) - STOP_PROCESSING(src, D) + +/** + * This proc is called on a datum on every "cycle" if it is being processed by a subsystem. The time between each cycle is determined by the subsystem's "wait" setting. + * You can start and stop processing a datum using the START_PROCESSING and STOP_PROCESSING defines. + * + * Since the wait setting of a subsystem can be changed at any time, it is important that any rate-of-change that you implement in this proc is multiplied by the seconds_per_tick that is sent as a parameter, + * Additionally, any "prob" you use in this proc should instead use the SPT_PROB define to make sure that the final probability per second stays the same even if the subsystem's wait is altered. + * Examples where this must be considered: + * - Implementing a cooldown timer, use `mytimer -= seconds_per_tick`, not `mytimer -= 1`. This way, `mytimer` will always have the unit of seconds + * - Damaging a mob, do `L.adjustFireLoss(20 * seconds_per_tick)`, not `L.adjustFireLoss(20)`. This way, the damage per second stays constant even if the wait of the subsystem is changed + * - Probability of something happening, do `if(SPT_PROB(25, seconds_per_tick))`, not `if(prob(25))`. This way, if the subsystem wait is e.g. lowered, there won't be a higher chance of this event happening per second + * + * If you override this do not call parent, as it will return PROCESS_KILL. This is done to prevent objects that dont override process() from staying in the processing list + */ +/datum/proc/process(seconds_per_tick) + set waitfor = FALSE + return PROCESS_KILL /datum/controller/subsystem/processing/ExplosionStart() can_fire = FALSE diff --git a/code/datums/datum.dm b/code/datums/datum.dm index f99f8f7c7a3..ad720345a98 100644 --- a/code/datums/datum.dm +++ b/code/datums/datum.dm @@ -12,8 +12,6 @@ /// Active timers with this datum as the target var/list/_active_timers - var/tmp/isprocessing = 0 - /// Status traits attached to this datum. associative list of the form: list(trait name (string) = list(source1, source2, source3,...)) var/list/status_traits /// Components attached to this datum @@ -136,23 +134,6 @@ return QDEL_HINT_QUEUE -/** - * This proc is called on a datum on every "cycle" if it is being processed by a subsystem. The time between each cycle is determined by the subsystem's "wait" setting. - * You can start and stop processing a datum using the START_PROCESSING and STOP_PROCESSING defines. - * - * Since the wait setting of a subsystem can be changed at any time, it is important that any rate-of-change that you implement in this proc is multiplied by the seconds_per_tick that is sent as a parameter, - * Additionally, any "prob" you use in this proc should instead use the SPT_PROB define to make sure that the final probability per second stays the same even if the subsystem's wait is altered. - * Examples where this must be considered: - * - Implementing a cooldown timer, use `mytimer -= seconds_per_tick`, not `mytimer -= 1`. This way, `mytimer` will always have the unit of seconds - * - Damaging a mob, do `L.adjustFireLoss(20 * seconds_per_tick)`, not `L.adjustFireLoss(20)`. This way, the damage per second stays constant even if the wait of the subsystem is changed - * - Probability of something happening, do `if(SPT_PROB(25, seconds_per_tick))`, not `if(prob(25))`. This way, if the subsystem wait is e.g. lowered, there won't be a higher chance of this event happening per second - * - * If you override this do not call parent, as it will return PROCESS_KILL. This is done to prevent objects that dont override process() from staying in the processing list - */ -/datum/proc/process(seconds_per_tick) - set waitfor = FALSE - return PROCESS_KILL - /datum/proc/can_vv_get(var_name) return TRUE diff --git a/code/game/objects/structures/safe.dm b/code/game/objects/structures/safe.dm index 0bdaa093d55..3486bf12e9d 100644 --- a/code/game/objects/structures/safe.dm +++ b/code/game/objects/structures/safe.dm @@ -100,21 +100,21 @@ FLOOR SAFES cut_overlay(drill_overlay) if(istype(drill, /obj/item/thermal_drill)) var/drill_icon = istype(drill, /obj/item/thermal_drill/diamond_drill) ? "d" : "h" - var/state = "[initial(icon_state)]_[drill_icon]-drill-[isprocessing ? "on" : "off"]" + var/state = "[initial(icon_state)]_[drill_icon]-drill-[(datum_flags & DF_ISPROCESSING) ? "on" : "off"]" drill_overlay = image(icon = 'icons/effects/drill.dmi', icon_state = state, pixel_x = drill_x_offset, pixel_y = drill_y_offset) add_overlay(drill_overlay) /obj/structure/safe/attack_hand(mob/user as mob) if(drill) - switch(alert("What would you like to do?", "Thermal Drill", "Turn [isprocessing ? "Off" : "On"]", "Remove Drill", "Cancel")) + switch(alert("What would you like to do?", "Thermal Drill", "Turn [(datum_flags & DF_ISPROCESSING) ? "Off" : "On"]", "Remove Drill", "Cancel")) if("Turn On") - if(!drill || isprocessing) + if(!drill || (datum_flags & DF_ISPROCESSING)) return if(broken) to_chat(user, SPAN_WARNING("\The [src] is already broken open!")) return if(do_after(user, 2 SECONDS)) - if(!drill || isprocessing) + if(!drill || (datum_flags & DF_ISPROCESSING)) return if(broken) return @@ -123,19 +123,19 @@ FLOOR SAFES START_PROCESSING(SSprocessing, src) update_icon() if("Turn Off") - if(!drill || !isprocessing) + if(!drill || !(datum_flags & DF_ISPROCESSING)) return if(do_after(user, 2 SECONDS)) - if(!drill || !isprocessing) + if(!drill || !(datum_flags & DF_ISPROCESSING)) return drill.soundloop.stop() STOP_PROCESSING(SSprocessing, src) update_icon() if("Remove Drill") - if(isprocessing) + if(datum_flags & DF_ISPROCESSING) to_chat(user, SPAN_WARNING("You cannot remove the drill while it's running!")) else if(do_after(user, 2 SECONDS)) - if(isprocessing) + if(datum_flags & DF_ISPROCESSING) return user.put_in_hands(drill) drill = null diff --git a/code/modules/atmospherics/components/unary/cold_sink.dm b/code/modules/atmospherics/components/unary/cold_sink.dm index 330ae509527..a25d00861ae 100644 --- a/code/modules/atmospherics/components/unary/cold_sink.dm +++ b/code/modules/atmospherics/components/unary/cold_sink.dm @@ -118,7 +118,7 @@ add_fingerprint(usr) -/obj/machinery/atmospherics/unary/freezer/process() +/obj/machinery/atmospherics/unary/freezer/process(seconds_per_tick) ..() if(stat & (NOPOWER|BROKEN) || !use_power) @@ -136,11 +136,11 @@ var/cop = FREEZER_PERF_MULT * air_contents.temperature/heatsink_temperature //heatpump coefficient of performance from thermodynamics -> power used = heat_transfer/cop heat_transfer = min(heat_transfer, cop * power_rating) //limit heat transfer by available power - var/removed = -air_contents.add_thermal_energy(-heat_transfer) //remove the heat + var/removed = -air_contents.add_thermal_energy(-heat_transfer*seconds_per_tick) //remove the heat if(debug) visible_message("[src]: Removing [removed] W.") - use_power_oneoff(power_rating) + use_power_oneoff(power_rating*seconds_per_tick) network.update = 1 else diff --git a/code/modules/mining/mine_items.dm b/code/modules/mining/mine_items.dm index a990754d79e..b04ebb401fd 100644 --- a/code/modules/mining/mine_items.dm +++ b/code/modules/mining/mine_items.dm @@ -1118,12 +1118,12 @@ var/list/total_extraction_beacons = list() return /obj/item/oremagnet/proc/toggle_on(mob/user) - if(!isprocessing) + if(!(datum_flags & DF_ISPROCESSING)) START_PROCESSING(SSprocessing, src) else STOP_PROCESSING(SSprocessing, src) if(user) - to_chat(user, "You switch [isprocessing ? "on" : "off"] [src].") + to_chat(user, "You switch [(datum_flags & DF_ISPROCESSING) ? "on" : "off"] [src].") /obj/item/oremagnet/Destroy() STOP_PROCESSING(SSprocessing, src) diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index c573a539793..b8f68a91d2c 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -380,7 +380,7 @@ return process_hitscan() else generate_muzzle_flash() - if(!isprocessing) + if(!(datum_flags & DF_ISPROCESSING)) START_PROCESSING(SSprojectiles, src) pixel_move(1) //move it now! diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm index 1226665f3c8..771c1ac13fb 100644 --- a/code/modules/recycling/disposal.dm +++ b/code/modules/recycling/disposal.dm @@ -842,7 +842,7 @@ if(P) // find other holder in next loc, if inactive merge it with current var/obj/disposalholder/H2 = locate() in P - if(H2 && !H2.isprocessing) + if(H2 && !(H2.datum_flags & DF_ISPROCESSING)) H.merge(H2) H.forceMove(P) @@ -1095,7 +1095,7 @@ if(P) // find other holder in next loc, if inactive merge it with current var/obj/disposalholder/H2 = locate() in P - if(H2 && !H2.isprocessing) + if(H2 && !(H2.datum_flags & DF_ISPROCESSING)) H.merge(H2) H.forceMove(P) @@ -1144,7 +1144,7 @@ if(P) // find other holder in next loc, if inactive merge it with current var/obj/disposalholder/H2 = locate() in P - if(H2 && !H2.isprocessing) + if(H2 && !(H2.datum_flags & DF_ISPROCESSING)) H.merge(H2) H.forceMove(P) @@ -1339,7 +1339,7 @@ if(P) // find other holder in next loc, if inactive merge it with current var/obj/disposalholder/H2 = locate() in P - if(H2 && !H2.isprocessing) + if(H2 && !(H2.datum_flags & DF_ISPROCESSING)) H.merge(H2) H.forceMove(P) diff --git a/code/modules/research/xenoarchaeology/tools/tools_locater.dm b/code/modules/research/xenoarchaeology/tools/tools_locater.dm index 5c4e2dd5ab8..5fdd5e53dbb 100644 --- a/code/modules/research/xenoarchaeology/tools/tools_locater.dm +++ b/code/modules/research/xenoarchaeology/tools/tools_locater.dm @@ -39,7 +39,7 @@ if(prob(scan_ticks * 10)) spawn(0) set background = 1 - if(isprocessing) + if(datum_flags & DF_ISPROCESSING) //scan radios in the world to try and find one var/cur_dist = 999 for(var/obj/item/device/radio/beacon/R in world) diff --git a/html/changelogs/fluffyghost-processingupdate.yml b/html/changelogs/fluffyghost-processingupdate.yml new file mode 100644 index 00000000000..39f80229235 --- /dev/null +++ b/html/changelogs/fluffyghost-processingupdate.yml @@ -0,0 +1,60 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: FluffyGhost + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - code_imp: "Refactored the use of the isprocessing var into the datum flag DF_ISPROCESSING." + - code_imp: "Updated SSprocessing and SSmachinery to have a constant fire rate." + - code_imp: "Updated gas cooler to be time-constant thanks to the above."