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. //returns 1 if the holder should continue reactiong, 0 otherwise.
/datum/reagents/proc/process_reactions() /datum/reagents/proc/process_reactions()
if(!my_atom || !my_atom.loc || my_atom.flags & NOREACT) if(!my_atom || !my_atom.loc || my_atom.flags & NOREACT)
equalize_temperature()
return 0 return 0
var/reaction_occured var/reaction_occured

View File

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

View File

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

View File

@@ -0,0 +1,37 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
#################################
# Your name.
author: BurgerBB
# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True
# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- bugfix: "Fixed a bug that would cause runtimes with chemicals with low metabolism."