Files
Wildkins e1770df81e Lag War Day 4: Under Pressure, High Voltage (#21878)
Replace /datum/gas_mixture/proc/return_pressure with XGM_PRESSURE(xgm)
macro. Having such a relatively simple statement contributing proc
overhead to procs called millions of times is ridiculous

Rename /datum/gas_mixture/proc/zburn to react, deleting the old react
which was just an alias for it. Free proc overhead

Turn check_combustibility into a macro CHECK_COMBUSTIBLE(is_cmb, xgm).
also rewrite it slightly so that it only needs to do one pass. Its a bit
nasty so I apologize for that, but speeeeed.

Delete most powernet and obj/machinery/power procs for handling power,
replacing them with macros. The fact that we were unironically calling a
draw_power() on APCs to call draw_power() on their terminals to call
draw_power() on their powernet every single process tick was insane.

Turn `between` into a macro alias for clamp() since the param order is
different

turn `Percent` into a macro AS_PCT

Rewrite significant chunks of update_canmove so its not quite as
horrifying of a proc and hopefully doesn't eat the entire mob subsystem
every movement now
2026-02-27 00:35:41 +00:00

66 lines
2.7 KiB
Plaintext

#define SHORT_REAL_LIMIT 16777216
//"fancy" math for calculating time in ms from tick_usage percentage and the length of ticks
//percent_of_tick_used * (ticklag * 100(to convert to ms)) / 100(percent ratio)
//collapsed to percent_of_tick_used * tick_lag
#define TICK_DELTA_TO_MS(percent_of_tick_used) ((percent_of_tick_used) * world.tick_lag)
#define TICK_USAGE_TO_MS(starting_tickusage) (TICK_DELTA_TO_MS(TICK_USAGE_REAL - starting_tickusage))
#if DM_VERSION < 516
/// Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive
#define SIGN(x) ( ((x) > 0) - ((x) < 0) )
#else
/// Gets the sign of x, returns -1 if negative, 0 if 0, 1 if positive
#define SIGN(x) (sign(x))
#endif
#define CEILING(x, y) ( -round(-(x) / (y)) * (y) )
#define ROUND_UP(x) ( -round(-(x)))
// round() acts like floor(x, 1) by default but can't handle other values
#define FLOOR(x, y) ( round((x) / (y)) * (y) )
// Real modulus that handles decimals
#define MODULUS(x, y) ( (x) - FLOOR(x, y))
/// clamp() but in order of low - mid - high instead of mid - low - high.
#define between(low, mid, high) ( clamp(mid, low, high) )
/// returns current_value as % of max_value, e.g. 60 is 60% of 100
#define AS_PCT(current_value, max_value) ( round((current_value / max_value) * 100, 1) )
// Similar to clamp but the bottom rolls around to the top and vice versa. min is inclusive, max is exclusive
#define WRAP(val, min, max) clamp(( min == max ? min : (val) - (round(((val) - (min))/((max) - (min))) * ((max) - (min))) ),min,max)
#define ATAN2(x, y) ( !(x) && !(y) ? 0 : (y) >= 0 ? arccos((x) / sqrt((x)*(x) + (y)*(y))) : -arccos((x) / sqrt((x)*(x) + (y)*(y))) )
// Will filter out extra rotations and negative rotations
// E.g: 540 becomes 180. -180 becomes 180.
#define SIMPLIFY_DEGREES(degrees) (MODULUS((degrees), 360))
#define GET_ANGLE_OF_INCIDENCE(face, input) (MODULUS((face) - (input), 360))
//Finds the shortest angle that angle A has to change to get to angle B. Aka, whether to move clock or counterclockwise.
/proc/closer_angle_difference(a, b)
if(!isnum(a) || !isnum(b))
return
a = SIMPLIFY_DEGREES(a)
b = SIMPLIFY_DEGREES(b)
var/inc = b - a
if(inc < 0)
inc += 360
var/dec = a - b
if(dec < 0)
dec += 360
. = inc > dec? -dec : inc
/// Converts a probability/second chance to probability/seconds_per_tick chance
/// For example, if you want an event to happen with a 10% per second chance, but your proc only runs every 5 seconds, do `if(prob(100*SPT_PROB_RATE(0.1, 5)))`
#define SPT_PROB_RATE(prob_per_second, seconds_per_tick) (1 - (1 - (prob_per_second)) ** (seconds_per_tick))
/// Like SPT_PROB_RATE but easier to use, simply put `if(SPT_PROB(10, 5))`
#define SPT_PROB(prob_per_second_percent, seconds_per_tick) (prob(100*SPT_PROB_RATE((prob_per_second_percent)/100, (seconds_per_tick))))