diff --git a/src/m_fixed.h b/src/m_fixed.h index 3190d0f1a..74b2f29b6 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -16,6 +16,8 @@ #define __M_FIXED__ #include "doomtype.h" +#include "doomdef.h" + #ifdef __GNUC__ #include #endif @@ -84,6 +86,53 @@ FUNCMATH FUNCINLINE static ATTRINLINE fixed_t DoubleToFixed(double f) return (fixed_t)(f * FRACUNIT); } +/** \brief Converts seconds (in tics) to fixed-point number values; 1 second is 1 fracunit. + + \param t (tic_t) time + + \return (fixed_t) seconds as fracunits +*/ +FUNCMATH FUNCINLINE static ATTRINLINE fixed_t SecsToFixed(tic_t t) +{ + return (fixed_t)(((UINT64)t * FRACUNIT) / (TICRATE)); +} + +/** \brief Converts tens of seconds (in tics) to fixed-point number values; 10 seconds is 1 + fracunit. + + \param t (tic_t) time + + \return (fixed_t) tens of seconds as fracunits +*/ +FUNCMATH FUNCINLINE static ATTRINLINE fixed_t SecsToFixedTens(tic_t t) +{ + return (fixed_t)(((UINT64)t * FRACUNIT) / (10 * TICRATE)); +} + +/** \brief 64-bit version of SecsToFixed. Converts seconds (in tics) to fixed-point number values; 1 + second is 1 fracunit. + + \param t (tic_t) time + + \return (sint64_t) seconds as fracunits +*/ +FUNCMATH FUNCINLINE static ATTRINLINE INT64 SecsToFixed64(tic_t t) +{ + return (INT64)(((UINT64)t * FRACUNIT) / (TICRATE)); +} + +/** \brief 64-bit version of SecsToFixedTens. Converts tens of seconds (in tics) to fixed-point + number values; 10 seconds is 1 fracunit. + + \param t (tic_t) time + + \return (sint64_t) tens of seconds as fracunits +*/ +FUNCMATH FUNCINLINE static ATTRINLINE INT64 SecsToFixedTens64(tic_t t) +{ + return (INT64)(((UINT64)t * FRACUNIT) / (10 * TICRATE)); +} + // for backwards compat #define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT)) #define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT))