Metabolism Precision Runtime Errors (#5701)

Because of precision issues with floating point values, metabolism would sometimes runtime and cause performance issues. This PR fixes this.

Fixes #5698 as well.
This commit is contained in:
BurgerLUA
2018-12-04 13:50:29 -08:00
committed by Erki
parent 584d7d8dbb
commit cd0400af61
4 changed files with 41 additions and 6 deletions

View File

@@ -98,7 +98,6 @@
//returns 1 if the holder should continue reactiong, 0 otherwise.
/datum/reagents/proc/process_reactions()
if(!my_atom || !my_atom.loc || my_atom.flags & NOREACT)
equalize_temperature()
return 0
var/reaction_occured

View File

@@ -39,6 +39,7 @@
/datum/reagent/proc/initialize_data(var/newdata) // Called when the reagent is created.
if(!isnull(newdata))
data = newdata
metabolism = round(metabolism,0.001)
/datum/reagent/proc/remove_self(var/amount) // Shortcut
if (!holder)

View File

@@ -66,9 +66,8 @@
var/total_thermal_energy = 0
var/total_heat_capacity = 0
var/was_changed = FALSE
for(var/datum/reagent/R in reagent_list)
total_thermal_energy += R.get_thermal_energy()
total_heat_capacity += R.get_heat_capacity()
@@ -76,11 +75,10 @@
for(var/datum/reagent/R in reagent_list)
var/old_thermal_energy = R.get_thermal_energy()
var/new_thermal_energy = total_thermal_energy * (R.get_heat_capacity()/total_heat_capacity)
if(old_thermal_energy != new_thermal_energy)
if(round(old_thermal_energy,1) != round(new_thermal_energy,1))
R.set_thermal_energy( new_thermal_energy )
was_changed = TRUE
return was_changed
/datum/reagents/proc/add_thermal_energy(var/thermal_energy_to_add)