mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
[NO GBP] Limits plumbing reaction chamber ph balance attempts (#79429)
## About The Pull Request - Fixes #79427 It's not a memory leak but a dedicated while loop that will run as many times as required to accurately balance the ph of the solution. Sometimes it makes way too many attempts causing high tick usage. Now the loop will run for a maximum of 5 times before giving up preventing lag. I decided 5 because that should be sufficient for most cases but it can be adjusted later by anyone interested by changing the value of the `MAX_PH_ADJUSTMENTS` define ## Changelog 🆑 fix: plumbing reaction chamber will attempt to balance the ph of the solution a maximum of 5 times before giving up and thus preventing infinite loops, high tick usage /🆑
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
/// coefficient to convert temperature to joules. same lvl as acclimator
|
||||
#define HEATER_COEFFICIENT 0.05
|
||||
|
||||
/// maximum number of attempts the reaction chamber will make to balance the ph(More means better results but higher tick usage)
|
||||
#define MAX_PH_ADJUSTMENTS 5
|
||||
|
||||
/obj/machinery/plumbing/reaction_chamber
|
||||
name = "mixing chamber"
|
||||
desc = "Keeps chemicals separated until given conditions are met."
|
||||
@@ -170,7 +173,8 @@
|
||||
return ..()
|
||||
|
||||
/obj/machinery/plumbing/reaction_chamber/chem/handle_reagents(seconds_per_tick)
|
||||
while(reagents.ph < acidic_limit || reagents.ph > alkaline_limit)
|
||||
var/ph_balance_attempts = 0
|
||||
while(ph_balance_attempts < MAX_PH_ADJUSTMENTS && (reagents.ph < acidic_limit || reagents.ph > alkaline_limit))
|
||||
//no power
|
||||
if(machine_stat & NOPOWER)
|
||||
return
|
||||
@@ -195,8 +199,9 @@
|
||||
if(!buffer.trans_to(reagents, buffer_amount * seconds_per_tick))
|
||||
return
|
||||
|
||||
//some power for accurate ph balancing
|
||||
//some power for accurate ph balancing & keep track of attempts made
|
||||
use_power(active_power_usage * 0.03 * buffer_amount * seconds_per_tick)
|
||||
ph_balance_attempts += 1
|
||||
|
||||
/obj/machinery/plumbing/reaction_chamber/chem/ui_interact(mob/user, datum/tgui/ui)
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
@@ -215,11 +220,11 @@
|
||||
|
||||
switch(action)
|
||||
if("acidic")
|
||||
acidic_limit = clamp(round(text2num(params["target"])), 0, alkaline_limit)
|
||||
acidic_limit = clamp(round(text2num(params["target"])), CHEMICAL_MIN_PH, alkaline_limit - 1)
|
||||
if("alkaline")
|
||||
alkaline_limit = clamp(round(text2num(params["target"])), acidic_limit + 0.01, 14)
|
||||
alkaline_limit = clamp(round(text2num(params["target"])), acidic_limit + 1, CHEMICAL_MAX_PH)
|
||||
else
|
||||
return FALSE
|
||||
|
||||
|
||||
#undef HEATER_COEFFICIENT
|
||||
#undef MAX_PH_ADJUSTMENTS
|
||||
|
||||
Reference in New Issue
Block a user