Skip to content

Commit

Permalink
Increases atmos pump & filter efficiency (#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorDinamit authored Feb 23, 2024
1 parent 63de8b4 commit f91305d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions code/__defines/machinery.dm
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
// These balance how easy or hard it is to create huge pressure gradients with pumps and filters.
// Lower values means it takes longer to create large pressures differences.
// Has no effect on pumping gasses from high pressure to low, only from low to high.
#define ATMOS_PUMP_EFFICIENCY 2.5
#define ATMOS_FILTER_EFFICIENCY 2.5
#define ATMOS_PUMP_EFFICIENCY 6
#define ATMOS_FILTER_EFFICIENCY 6

// Will not bother pumping or filtering if the gas source as fewer than this amount of moles, to help with performance.
#define MINIMUM_MOLES_TO_PUMP 0.01
Expand Down
16 changes: 9 additions & 7 deletions code/modules/atmospherics/atmos_primitives.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
//Moves gas from one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was pumped.
//transfer_moles - Limits the amount of moles to transfer. The actual amount of gas moved may also be limited by available_power, if given.
//available_power - the maximum amount of power that may be used when moving gas. If null then the transfer is not limited by power.
/proc/pump_gas(var/obj/machinery/M, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/transfer_moles = null, var/available_power = null)
/proc/pump_gas(obj/machinery/M, datum/gas_mixture/source, datum/gas_mixture/sink, transfer_moles = null, available_power = null)
if (source.total_moles < MINIMUM_MOLES_TO_PUMP) //if we can't transfer enough gas just stop to avoid further processing
return -1

if (isnull(transfer_moles))
if(isnull(transfer_moles))
transfer_moles = source.total_moles
else
transfer_moles = min(source.total_moles, transfer_moles)

//Calculate the amount of energy required and limit transfer_moles based on available power
var/specific_power = calculate_specific_power(source, sink)/ATMOS_PUMP_EFFICIENCY //this has to be calculated before we modify any gas mixtures
if (!isnull(available_power) && specific_power > 0)
if(!isnull(available_power) && specific_power > 0)
transfer_moles = min(transfer_moles, available_power / specific_power)

if (transfer_moles < MINIMUM_MOLES_TO_PUMP) //if we can't transfer enough gas just stop to avoid further processing
if(transfer_moles < MINIMUM_MOLES_TO_PUMP) //if we can't transfer enough gas just stop to avoid further processing
return -1

//Update flow rate meter
Expand Down Expand Up @@ -426,8 +426,9 @@
//Calculates the APPROXIMATE amount of moles that would need to be transferred to change the pressure of sink by pressure_delta
//If set, sink_volume_mod adjusts the effective output volume used in the calculation. This is useful when the output gas_mixture is
//part of a pipenetwork, and so it's volume isn't representative of the actual volume since the gas will be shared across the pipenetwork when it processes.
/proc/calculate_transfer_moles(datum/gas_mixture/source, datum/gas_mixture/sink, var/pressure_delta, var/sink_volume_mod=0)
if(source.temperature == 0 || source.total_moles == 0) return 0
/proc/calculate_transfer_moles(datum/gas_mixture/source, datum/gas_mixture/sink, pressure_delta, sink_volume_mod = 0)
if(source.temperature == 0 || source.total_moles == 0)
return 0

var/output_volume = (sink.volume * sink.group_multiplier) + sink_volume_mod
var/source_total_moles = source.total_moles * source.group_multiplier
Expand All @@ -445,7 +446,8 @@

//Calculates the APPROXIMATE amount of moles that would need to be transferred to bring source and sink to the same pressure
/proc/calculate_equalize_moles(datum/gas_mixture/source, datum/gas_mixture/sink)
if(source.temperature == 0) return 0
if(source.temperature == 0)
return 0

//Make the approximation that the sink temperature is unchanged after transferring gas
var/source_volume = source.volume * source.group_multiplier
Expand Down
14 changes: 7 additions & 7 deletions code/modules/atmospherics/components/unary/vent_pump.dm
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@
/obj/machinery/atmospherics/unary/vent_pump/Process()
..()

if (hibernate > world.time)
return 1
if(hibernate > world.time)
return TRUE

if (!node)
if(!node)
update_use_power(POWER_USE_OFF)
if(!can_pump())
return 0
return FALSE

var/datum/gas_mixture/environment = loc.return_air()

Expand All @@ -193,7 +193,7 @@
var/transfer_moles = calculate_transfer_moles(air_contents, environment, pressure_delta)
power_draw = pump_gas(src, air_contents, environment, transfer_moles, power_rating)
else //external -> internal
var/transfer_moles = calculate_transfer_moles(environment, air_contents, pressure_delta, (network)? network.volume : 0)
var/transfer_moles = calculate_transfer_moles(environment, air_contents, pressure_delta, network ? network.volume : 0)

//limit flow rate from turfs
transfer_moles = min(transfer_moles, environment.total_moles*air_contents.volume/environment.volume) //group_multiplier gets divided out here
Expand All @@ -206,13 +206,13 @@
hibernate = world.time + (rand(100,200))


if (power_draw >= 0)
if(power_draw >= 0)
last_power_draw = power_draw
use_power_oneoff(power_draw)
if(network)
network.update = 1

return 1
return TRUE

/obj/machinery/atmospherics/unary/vent_pump/proc/get_pressure_delta(datum/gas_mixture/environment)
var/pressure_delta = DEFAULT_PRESSURE_DELTA
Expand Down

0 comments on commit f91305d

Please sign in to comment.