From ed8fc2c866ffa8a4d8deaf1dcfbba77e3917a5ce Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Sat, 28 Dec 2024 03:20:49 +0530 Subject: [PATCH] Optimization for plumbing reaction chamber & catalysts (#88722) ## About The Pull Request Plumbing components waste extra ticks in requesting reagents if those requested reagents are stored in a reaction chamber & they are catalysts which cannot be sent out. That is because the reaction chamber lies & tells the pipeline it can give them inside it's `/datum/component/plumbing/reaction_chamber/can_give()` proc but won't actually transfer them if it has no excess to spare. This doesn't cause errors because those components will eventually get their requested values from other supplies but it takes extra ticks to do so This ensures the reaction chamber won't volunteer itself as a supplier if it can't give out those catalysts thus enabling the pipeline to request more accurate values by excluding that reaction chamber from its list suppliers ## Changelog :cl: code: plumbing reaction chamber won't waste extra ticks for the pipeline when sending out catalysts /:cl: --------- Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> --- .../components/plumbing/reaction_chamber.dm | 22 ++++++++++++++++--- .../plumbing/plumbers/_plumb_reagents.dm | 7 ++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/code/datums/components/plumbing/reaction_chamber.dm b/code/datums/components/plumbing/reaction_chamber.dm index 4f2acf4710a..f095f07262b 100644 --- a/code/datums/components/plumbing/reaction_chamber.dm +++ b/code/datums/components/plumbing/reaction_chamber.dm @@ -8,13 +8,29 @@ return COMPONENT_INCOMPATIBLE /datum/component/plumbing/reaction_chamber/can_give(amount, reagent, datum/ductnet/net) + . = FALSE + var/obj/machinery/plumbing/reaction_chamber/reaction_chamber = parent //cannot give when we outselves are requesting or reacting the reagents - if(!reaction_chamber.emptying || reagents.is_reacting) - return FALSE + if(amount <= 0 || !reagents.total_volume || !reaction_chamber.emptying || reagents.is_reacting) + return - return ..() + //check to see if we can give catalysts only if they are in excess + var/list/datum/reagent/catalysts = reaction_chamber.catalysts + for(var/datum/reagent/chemical as anything in reagents.reagent_list) + if(reagent && chemical.type != reagent) + continue + + //we have the exact amounts so no excess to spare + if(chemical.volume <= (catalysts[chemical.type] || 0)) + if(reagent) + break + else + continue + + //atleast 1 reagent to give so take whatever + return TRUE /datum/component/plumbing/reaction_chamber/send_request(dir) var/obj/machinery/plumbing/reaction_chamber/chamber = parent diff --git a/code/modules/plumbing/plumbers/_plumb_reagents.dm b/code/modules/plumbing/plumbers/_plumb_reagents.dm index 4cce127c8b8..90954ca4985 100644 --- a/code/modules/plumbing/plumbers/_plumb_reagents.dm +++ b/code/modules/plumbing/plumbers/_plumb_reagents.dm @@ -121,12 +121,19 @@ SHOULD_NOT_OVERRIDE(TRUE) . = 0 + + //no reagents if(!total_volume) return var/obj/machinery/plumbing/reaction_chamber/reactor = my_atom var/list/datum/reagent/catalysts = reactor.catalysts + //no catalysts + if(!catalysts.len) + return total_volume + + //filter out catalysts except when we have excess of them var/working_volume var/catalyst_volume var/list/cached_reagents = reagent_list