- Major optimisations to handle_reactions().

How is this an improvement? Before we looped through every possible reaction to see if a reaction would occure with our list of reagents. Now we already make a list of reagents which can have a reactions, cutting down on searching every single time. This will decrease the loop expensive iterations from 100s to only a handful.

How does it work? We format our chemical_reactions_list like this:

chemical_reactions_list[reagent_id] = list()

And then we fill that list of possible reactions. Thanks to Exadv1, to cut down on redundancy we only need to have a reaction in a single list at a single time, because our handle_reaction() loop will handle that.

Here is a paste of the structure of the list on runtime. http://privatepaste.com/327bb61628

(has: = an entry in the list that it is nested in)

 - Fixed mecha weapons shooting over people lying down.

git-svn-id: http://tgstation13.googlecode.com/svn/trunk@5569 316c924e-a436-60f5-8080-3fe189b3f50e
This commit is contained in:
giacomand@gmail.com
2013-01-17 20:34:47 +00:00
parent 71ba8dfcd2
commit e6d0ec4859
3 changed files with 100 additions and 65 deletions

View File

@@ -58,3 +58,14 @@ var/global/list/backbaglist = list("Nothing", "Backpack", "Satchel")
facial_hair_styles_male_list += H.name
facial_hair_styles_female_list += H.name
/* // 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"
world << .
*/

View File

@@ -27,7 +27,7 @@
set_ready_state(0)
playsound(chassis, fire_sound, 50, 1)
var/obj/item/projectile/A = new projectile(curloc)
A.original = targloc
A.original = target
A.current = curloc
A.yo = targloc.y - curloc.y
A.xo = targloc.x - curloc.x
@@ -209,7 +209,7 @@
playsound(chassis, fire_sound, 80, 1)
var/obj/item/projectile/A = new projectile(curloc)
src.projectiles--
A.original = targloc
A.original = target
A.current = curloc
A.yo = targloc.y - curloc.y
A.xo = targloc.x - curloc.x
@@ -251,7 +251,7 @@
playsound(chassis, fire_sound, 50, 1)
var/obj/item/projectile/A = new projectile(curloc)
src.projectiles--
A.original = targloc
A.original = target
A.current = curloc
A.yo = targloc.y - curloc.y
A.xo = targloc.x - curloc.x

View File

@@ -24,12 +24,29 @@ datum
var/datum/reagent/D = new path()
chemical_reagents_list[D.id] = D
if(!chemical_reactions_list)
//Chemical Reactions - Initialises all /datum/chemical_reaction into a list (without an index)
//Chemical Reactions - Initialises all /datum/chemical_reaction into a list
// It is filtered into multiple lists within a list.
// For example:
// chemical_reaction_list["plasma"] is a list of all reactions relating to plasma
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()
chemical_reactions_list += D
var/list/reaction_ids = list()
if(D.required_reagents && D.required_reagents.len)
for(var/reaction in D.required_reagents)
reaction_ids += reaction
// Create filters based on each reagent id in the required reagents list
for(var/id in reaction_ids)
if(!chemical_reactions_list[id])
chemical_reactions_list[id] = list()
chemical_reactions_list[id] += D
break // Don't bother adding ourselves to other reagent ids, it is redundant.
proc
@@ -198,7 +215,13 @@ datum
var/reaction_occured = 0
do
reaction_occured = 0
for(var/datum/chemical_reaction/C in chemical_reactions_list)
for(var/datum/reagent/R in reagent_list) // Usually a small list
for(var/reaction in chemical_reactions_list[R.id]) // Was a big list but now it should be smaller since we filtered it with our reagent id
if(!reaction)
continue
var/datum/chemical_reaction/C = reaction
var/total_required_reagents = C.required_reagents.len
var/total_matching_reagents = 0
var/total_required_catalysts = C.required_catalysts.len
@@ -251,7 +274,8 @@ datum
multiplier = max(multiplier, 1) //this shouldnt happen ...
add_reagent(C.result, C.result_amount*multiplier)
for(var/mob/M in viewers(4, get_turf(my_atom)) )
var/list/seen = viewers(4, get_turf(my_atom))
for(var/mob/M in seen)
M << "\blue \icon[my_atom] The solution begins to bubble."
/* if(istype(my_atom, /obj/item/slime_core))
@@ -265,7 +289,7 @@ datum
var/obj/item/slime_extract/ME2 = my_atom
ME2.Uses--
if(ME2.Uses <= 0) // give the notification that the slime core is dead
for(var/mob/M in viewers(4, get_turf(my_atom)) )
for(var/mob/M in seen)
M << "\blue \icon[my_atom] The [my_atom]'s power is consumed in the reaction."
ME2.name = "used slime extract"
ME2.desc = "This extract has been used up."