Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Commit

Permalink
Moves chem reactions onto SSchemistry.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Sep 23, 2018
1 parent f4c4559 commit 67ee73a
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 63 deletions.
1 change: 1 addition & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
#include "code\controllers\subsystems\alarm.dm"
#include "code\controllers\subsystems\antags.dm"
#include "code\controllers\subsystems\atoms.dm"
#include "code\controllers\subsystems\chemistry.dm"
#include "code\controllers\subsystems\evac.dm"
#include "code\controllers\subsystems\event.dm"
#include "code\controllers\subsystems\fluids.dm"
Expand Down
1 change: 1 addition & 0 deletions code/__defines/subsystem-priority.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define SS_PRIORITY_MOB 100 // Mob Life().
#define SS_PRIORITY_MACHINERY 100 // Machinery + powernet ticks.
#define SS_PRIORITY_AIR 80 // ZAS processing.
#define SS_PRIORITY_CHEMISTRY 60 // Multi-tick chemical reactions.
#define SS_PRIORITY_ALARM 20 // Alarm processing.
#define SS_PRIORITY_EVENT 20 // Event processing and queue handling.
#define SS_PRIORITY_SHUTTLE 20 // Shuttle movement.
Expand Down
3 changes: 2 additions & 1 deletion code/__defines/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
// Subsystems shutdown in the reverse of the order they initialize in
// The numbers just define the ordering, they are meaningless otherwise.

#define SS_INIT_GARBAGE 10
#define SS_INIT_GARBAGE 11
#define SS_INIT_CHEMISTRY 10
#define SS_INIT_MATERIALS 9
#define SS_INIT_ANTAGS 8
#define SS_INIT_CULTURE 7
Expand Down
10 changes: 5 additions & 5 deletions code/_helpers/global_access.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
return global.SSantags;
if("SSatoms")
return global.SSatoms;
if("SSchemistry")
return global.SSchemistry;
if("SScircuit")
return global.SScircuit;
if("SScodex")
Expand Down Expand Up @@ -291,8 +293,6 @@
return global.checked_for_inactives;
if("chemical_reaction_logs")
return global.chemical_reaction_logs;
if("chemical_reactions_list")
return global.chemical_reactions_list;
if("chicken_count")
return global.chicken_count;
if("church_name")
Expand Down Expand Up @@ -1028,6 +1028,8 @@
global.SSantags=newval;
if("SSatoms")
global.SSatoms=newval;
if("SSchemistry")
global.SSchemistry=newval;
if("SScircuit")
global.SScircuit=newval;
if("SScodex")
Expand Down Expand Up @@ -1276,8 +1278,6 @@
global.checked_for_inactives=newval;
if("chemical_reaction_logs")
global.chemical_reaction_logs=newval;
if("chemical_reactions_list")
global.chemical_reactions_list=newval;
if("chicken_count")
global.chicken_count=newval;
if("church_name")
Expand Down Expand Up @@ -1991,6 +1991,7 @@
"SSalarm",
"SSantags",
"SSatoms",
"SSchemistry",
"SScircuit",
"SScodex",
"SSculture",
Expand Down Expand Up @@ -2115,7 +2116,6 @@
"chargen_robolimbs",
"checked_for_inactives",
"chemical_reaction_logs",
"chemical_reactions_list",
"chicken_count",
"church_name",
"client_preference_stats_",
Expand Down
15 changes: 0 additions & 15 deletions code/_helpers/global_lists.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//This is for procs to replace all the goddamn 'in world's that are chilling around the code

var/global/list/cable_list = list() //Index for all cables, so that powernets don't have to look through the entire world all the time
var/global/list/chemical_reactions_list //list of all /datum/chemical_reaction datums. Used during chemical reactions
var/global/list/landmarks_list = list() //list of all landmarks created
var/global/list/surgery_steps = list() //list of all surgery steps |BS12
var/global/list/side_effects = list() //list of all medical sideeffects types by thier names |BS12
Expand Down Expand Up @@ -176,21 +175,7 @@ var/global/list/string_slot_flags = list(

return 1

/* // Uncomment to debug chemical reaction list.
/client/verb/debug_chemical_list()
for (var/reaction in chemical_reactions_list)
. += "chemical_reactions_list\[\"[reaction]\"\] = \"[chemical_reactions_list[reaction]]\"\n"
if(islist(chemical_reactions_list[reaction]))
var/list/L = chemical_reactions_list[reaction]
for(var/t in L)
. += " has: [t]\n"
log_debug(.)
*/

//*** params cache

var/global/list/paramslist_cache = list()

#define cached_key_number_decode(key_number_data) cached_params_decode(key_number_data, /proc/key_number_decode)
Expand Down
60 changes: 60 additions & 0 deletions code/controllers/subsystems/chemistry.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SUBSYSTEM_DEF(chemistry)
name = "Chemistry"
priority = SS_PRIORITY_CHEMISTRY
init_order = SS_INIT_CHEMISTRY

var/list/active_holders = list()
var/list/chemical_reactions = list()
var/list/chemical_reactions_by_id = list()
var/list/chemical_reactions_by_result = list()
var/list/processing_holders = list()

/datum/controller/subsystem/chemistry/stat_entry()
..("AH:[active_holders.len]")

/datum/controller/subsystem/chemistry/Initialize()

// Init reaction list.
//Chemical Reactions - Initialises all /datum/chemical_reaction into a list
// It is filtered into multiple lists within a list.
// For example:
// chemical_reaction_list["phoron"] is a list of all reactions relating to phoron
// Note that entries in the list are NOT duplicated. So if a reaction pertains to
// more than one chemical it will still only appear in only one of the sublists.

for(var/path in subtypesof(/datum/chemical_reaction))
var/datum/chemical_reaction/D = new path()
chemical_reactions += D
if(!chemical_reactions_by_result[D.result])
chemical_reactions_by_result[D.result] = list()
chemical_reactions_by_result[D.result] += D
if(D.required_reagents && D.required_reagents.len)
var/reagent_id = D.required_reagents[1]
if(!chemical_reactions_by_id[reagent_id])
chemical_reactions_by_id[reagent_id] = list()
chemical_reactions_by_id[reagent_id] += D
. = ..()

/datum/controller/subsystem/chemistry/fire(resumed = FALSE)
if (!resumed)
processing_holders = active_holders.Copy()

while(processing_holders.len)
var/datum/reagents/holder = processing_holders[processing_holders.len]
processing_holders.len--

if (QDELETED(holder))
active_holders -= holder
log_debug("SSchemistry: QDELETED holder found in processing list!")
if(MC_TICK_CHECK)
return
continue

if (!holder.process_reactions())
active_holders -= holder

if (MC_TICK_CHECK)
return

/datum/controller/subsystem/chemistry/proc/mark_for_update(var/datum/reagents/holder)
active_holders[holder] = TRUE
2 changes: 1 addition & 1 deletion code/game/objects/items/weapons/cigs_lighters.dm
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ CIGARETTE PACKETS ARE IN FANCY.DM
qdel(src)
return
atom_flags &= ~ATOM_FLAG_NO_REACT // allowing reagents to react after being lit
reagents.process_reactions()
reagents.handle_reactions()
update_icon()
var/turf/T = get_turf(src)
T.visible_message(flavor_text)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/codex/categories/category_reagents.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
_lore_text = "[initial(reagent.description)] It apparently tastes of [initial(reagent.taste_description)].")

var/list/production_strings = list()
for(var/react in GLOB.chemical_products_list[thing])
for(var/react in SSchemistry.chemical_reactions_by_result[thing])

var/datum/chemical_reaction/reaction = react

Expand Down
19 changes: 11 additions & 8 deletions code/modules/reagents/Chemistry-Holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
total_volume += R.volume
return

/datum/reagents/proc/handle_reactions()
SSchemistry.mark_for_update(src)

/datum/reagents/proc/process_reactions()
if(!my_atom) // No reactions in temporary holders
return 0
Expand All @@ -77,7 +80,7 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
var/list/datum/chemical_reaction/eligible_reactions = list()

for(var/datum/reagent/R in reagent_list)
eligible_reactions |= chemical_reactions_list[R.type]
eligible_reactions |= SSchemistry.chemical_reactions_by_id[R.type]

var/list/datum/chemical_reaction/active_reactions = list()

Expand Down Expand Up @@ -107,7 +110,7 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
update_total()

if(reaction_occured)
process_reactions() // Check again in case the new reagents can react again
handle_reactions() // Check again in case the new reagents can react again

return reaction_occured

Expand All @@ -127,7 +130,7 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
current.mix_data(data, amount)
update_total()
if(!safety)
process_reactions()
handle_reactions()
if(my_atom)
my_atom.on_reagent_change()
return 1
Expand All @@ -138,7 +141,7 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
R.initialize_data(data)
update_total()
if(!safety)
process_reactions()
handle_reactions()
if(my_atom)
my_atom.on_reagent_change()
return 1
Expand All @@ -154,7 +157,7 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
current.volume -= amount // It can go negative, but it doesn't matter
update_total() // Because this proc will delete it then
if(!safety)
process_reactions()
handle_reactions()
if(my_atom)
my_atom.on_reagent_change()
return 1
Expand Down Expand Up @@ -246,7 +249,7 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
remove_reagent(current.type, amount_to_remove, 1)

update_total()
process_reactions()
handle_reactions()
return amount

/datum/reagents/proc/trans_to_holder(var/datum/reagents/target, var/amount = 1, var/multiplier = 1, var/copy = 0) // Transfers [amount] reagents from [src] to [target], multiplying them by [multiplier]. Returns actual amount removed from [src] (not amount transferred to [target]).
Expand All @@ -267,8 +270,8 @@ GLOBAL_DATUM_INIT(temp_reagents_holder, /obj, new)
remove_reagent(current.type, amount_to_transfer, 1)

if(!copy)
process_reactions()
target.process_reactions()
handle_reactions()
target.handle_reactions()
return amount

/* Holder-to-atom and similar procs */
Expand Down
26 changes: 0 additions & 26 deletions code/modules/reagents/Chemistry-Recipes.dm
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
//Chemical Reactions - Initialises all /datum/chemical_reaction into a list
// It is filtered into multiple lists within a list.
// For example:
// chemical_reaction_list[/datum/reagent/toxin/phoron] is a list of all reactions relating to phoron
// Note that entries in the list are NOT duplicated. So if a reaction pertains to
// more than one chemical it will still only appear in only one of the sublists.

GLOBAL_LIST_INIT(chemical_products_list, new)
/proc/initialize_chemical_reactions()
var/paths = typesof(/datum/chemical_reaction) - /datum/chemical_reaction
chemical_reactions_list = list()

for(var/path in paths)
var/datum/chemical_reaction/D = new path()

if(D.result)
if(!GLOB.chemical_products_list[D.result])
GLOB.chemical_products_list[D.result] = list()
GLOB.chemical_products_list[D.result] += D

if(D.required_reagents && D.required_reagents.len)
var/reagent_id = D.required_reagents[1]
if(!chemical_reactions_list[reagent_id])
chemical_reactions_list[reagent_id] = list()
chemical_reactions_list[reagent_id] += D

/datum/chemical_reaction
var/name = null
var/result = null
Expand Down
2 changes: 1 addition & 1 deletion code/modules/reagents/reagent_containers/food/shaker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/obj/item/weapon/reagent_containers/food/drinks/shaker/proc/mix()
if(reagents && reagents.total_volume)
atom_flags &= ~ATOM_FLAG_NO_REACT
reagents.process_reactions()
reagents.handle_reactions()
addtimer(CALLBACK(src, .proc/stop_react), 0)

/obj/item/weapon/reagent_containers/food/drinks/shaker/proc/stop_react()
Expand Down
2 changes: 1 addition & 1 deletion test/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function run_byond_tests {
source $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}/byond/bin/byondsetup
fi
run_test_ci "check globals build" "python tools/GenerateGlobalVarAccess/gen_globals.py baystation12.dme code/_helpers/global_access.dm"
run_test "check globals unchanged" "md5sum -c - <<< '6d1db6b78d58549b818bc07f65df228d *code/_helpers/global_access.dm'"
run_test "check globals unchanged" "md5sum -c - <<< 'b497c6efd32b1f6be33415a283678c66 *code/_helpers/global_access.dm'"
run_test "build map unit tests" "scripts/dm.sh -DUNIT_TEST -M$MAP_PATH baystation12.dme"
run_test "check no warnings in build" "grep ', 0 warnings' build_log.txt"
run_test "run unit tests" "DreamDaemon baystation12.dmb -invisible -trusted -core 2>&1 | tee log.txt"
Expand Down
4 changes: 0 additions & 4 deletions ~code/global_init.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ var/global/datum/global_init/init = new ()
/datum/global_init/New()
load_configuration()
callHook("global_init")

// kept out of a hook to preserve call order
initialize_chemical_reactions()

qdel(src) //we're done

/datum/global_init/Destroy()
Expand Down

0 comments on commit 67ee73a

Please sign in to comment.