mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-20 19:49:39 +01:00
## About The Pull Request Refactors the way we listen for reagent changes. The changes made can be listed as points **1. Removes `COMSIG_REAGENTS_PRE_ADD_REAGENT`** Used to stop new reagents from being added to the holder, its only application is with the BRPED to stop inserting reagents into beakers/cells stored inside it. Rather than using this signal a cleaner solution is to simply remove the component part's reagent holders' flags which allow us to insert reagents into it(i.e. `REFILABLE`, `INJECTIBLE`, `DRAINABLE`) and restore them back when that part is removed thus achieving the same results. Thus `add_reagent()` is now slightly faster because it no longer uses this signal **2. Removes every other signal used by the reagent holder** Removes pretty much every other signal used by `holder.dm` which are `COMSIG_REAGENTS_[NEW_REAGENT, ADD_REAGENT, DEL_REAGENT, REM_REAGENT, CLEAR_REAGENTS]` While yes, it is true that all these signals are unique & serve a specific purpose the problem is no object in code respects their uniqueness & instead clumps them up all together & hooks them onto one proc to listen for "reagent changes". You see this code pattern repeated in so many places https://github.com/tgstation/tgstation/blob/9277364ef6449262e2c693ff6817925e074c47ce/code/modules/power/power_store.dm#L105 Not only does this look ugly but it also has a memory overhead (4 to 5 signal slots all performing the same action which is a lot compared to the solution i implemented below). Bonus is that "none" of the parameters passed to this proc are used so they go to waste as well. So after removing a ton of code we need something that can still make the code function which brings us to point 3 **3. Adds a new signal `COMSIG_REAGENTS_HOLDER_UPDATED` to rule them all** So if all objects in game are listening for "reagent changes"[adding/removing, reagents] then we need to look at the proc that is always called during these changes & that is none other than `update_total()` so we let that send out a signal and cause all objects to hook onto this 1 signal instead of 4 to 5 signals as explained in point 2 ## Why It's Good For The Game This section isn't necessary but i want us to better appreciate both the code & performance benifits of this PR. 1. First of all its waaaay less code and signals to worry about. Just look at the number of lines of code removed compared to added. Nothing more to say 2. Overhead of `RegisterSignal` compared to `RegisterSignals` is less for obvious reasons 3. `remove_all` is significantly faster as it no longer calls `remove_reagent()`[which in turn calls `update_total()` & `handle_reactions()` per call & uses a for loop so its a nested for loop of doom] for every reagent it removes, instead it does the work by itself & calls the above 2 procs just once 4. Usually when a reagent is deleted it calls `COMSIG_REAGENTS_REM_REAGENT` & `COMSIG_REAGENTS_DEL_REAGENT`. So if you have a holder with like 3 reagents upon transferring/deleting them you get a total of 6 signal calls!!. Now it's just 3(when using `trans_to`) and just 1 when using `remove_all/clear_reagents`. Need i say more no ## Changelog 🆑 fix: hydrophonics circuit component actually sets output level when reagents are changed in the tray refactor: refactors how code listens for reagent changes. Report bugs on github /🆑