From e8a4818d2b49470e361f07d6a9c3f01e34659df7 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Sun, 27 Jul 2014 19:54:29 -0400 Subject: [PATCH] Optimizes air alarm power updating --- code/game/machinery/alarm.dm | 42 +++++++++---------- .../embedded_controller_base.dm | 4 +- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index 29aa09e633..2c71964f84 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -47,9 +47,6 @@ #define RCON_AUTO 2 #define RCON_YES 3 -//1000 joules equates to about 1 degree every 2 seconds for a single tile of air. -#define MAX_ENERGY_CHANGE 1000 - #define MAX_TEMPERATURE 90 #define MIN_TEMPERATURE -40 @@ -67,8 +64,8 @@ icon_state = "alarm0" anchored = 1 use_power = 1 - idle_power_usage = 4 - active_power_usage = 8 + idle_power_usage = 80 + active_power_usage = 1000 //For heating/cooling rooms. 1000 joules equates to about 1 degree every 2 seconds for a single tile of air. power_channel = ENVIRON req_one_access = list(access_atmospherics, access_engine_equip) var/breach_detection = 1 // Whether to use automatic breach detection or not @@ -178,16 +175,22 @@ var/datum/gas_mixture/environment = location.return_air() //Handle temperature adjustment here. - if(environment.temperature < target_temperature - 2 || environment.temperature > target_temperature + 2 || regulating_temperature) - //If it goes too far, we should adjust ourselves back before stopping. - if(get_danger_level(target_temperature, TLV["temperature"])) - return - - if(!regulating_temperature) + if (!regulating_temperature) + //check for when we should start adjusting temperature + if(!get_danger_level(target_temperature, TLV["temperature"]) && abs(environment.temperature - target_temperature) > 2.0) + update_use_power(2) regulating_temperature = 1 visible_message("\The [src] clicks as it starts [environment.temperature > target_temperature ? "cooling" : "heating"] the room.",\ "You hear a click and a faint electronic hum.") - + else + //check for when we should stop adjusting temperature + if (get_danger_level(target_temperature, TLV["temperature"]) || abs(environment.temperature - target_temperature) <= 0.5) + update_use_power(1) + regulating_temperature = 0 + visible_message("\The [src] clicks quietly as it stops [environment.temperature > target_temperature ? "cooling" : "heating"] the room.",\ + "You hear a click as a faint electronic humming stops.") + + if (regulating_temperature) if(target_temperature > T0C + MAX_TEMPERATURE) target_temperature = T0C + MAX_TEMPERATURE @@ -199,30 +202,25 @@ if(gas) if (gas.temperature <= target_temperature) //gas heating - var/energy_used = min( gas.get_thermal_energy_change(target_temperature) , MAX_ENERGY_CHANGE) + var/energy_used = min( gas.get_thermal_energy_change(target_temperature) , active_power_usage) gas.add_thermal_energy(energy_used) - use_power(energy_used, ENVIRON) + //use_power(energy_used, ENVIRON) //handle by update_use_power instead else //gas cooling - var/heat_transfer = min(abs(gas.get_thermal_energy_change(target_temperature)), MAX_ENERGY_CHANGE) + var/heat_transfer = min(abs(gas.get_thermal_energy_change(target_temperature)), active_power_usage) //Assume the heat is being pumped into the hull which is fixed at 20 C //none of this is really proper thermodynamics but whatever var/cop = gas.temperature/T20C //coefficient of performance -> power used = heat_transfer/cop - heat_transfer = min(heat_transfer, cop * MAX_ENERGY_CHANGE) //this ensures that we don't use more than MAX_ENERGY_CHANGE amount of power - the machine can only do so much cooling + heat_transfer = min(heat_transfer, cop * active_power_usage) //this ensures that we don't use more than active_power_usage amount of power heat_transfer = -gas.add_thermal_energy(-heat_transfer) //get the actual heat transfer - use_power(heat_transfer / cop, ENVIRON) + //use_power(heat_transfer / cop, ENVIRON) //handle by update_use_power instead environment.merge(gas) - - if(abs(environment.temperature - target_temperature) <= 0.5) - regulating_temperature = 0 - visible_message("\The [src] clicks quietly as it stops [environment.temperature > target_temperature ? "cooling" : "heating"] the room.",\ - "You hear a click as a faint electronic humming stops.") var/old_level = danger_level var/old_pressurelevel = pressure_dangerlevel diff --git a/code/game/machinery/embedded_controller/embedded_controller_base.dm b/code/game/machinery/embedded_controller/embedded_controller_base.dm index 396bec0a01..a71f4017e3 100644 --- a/code/game/machinery/embedded_controller/embedded_controller_base.dm +++ b/code/game/machinery/embedded_controller/embedded_controller_base.dm @@ -46,7 +46,7 @@ density = 0 var/id_tag - var/radio_power_use = 50 //power used to xmit signals + //var/radio_power_use = 50 //power used to xmit signals var/frequency = 1379 var/datum/radio_frequency/radio_connection @@ -67,7 +67,7 @@ /obj/machinery/embedded_controller/radio/post_signal(datum/signal/signal) signal.transmission_method = TRANSMISSION_RADIO if(radio_connection) - use_power(radio_power_use) + //use_power(radio_power_use) //neat idea, but causes way too much lag. return radio_connection.post_signal(src, signal) else del(signal)