SecsToFixed, SecsToFixedTens, and 64-bit variants

Converts seconds/tens of seconds to fixed_t values:
- SecsToFixed: 1 second is 1 fracunit
- SecsToFixedTens: 10 seconds is 1 fracunit
This commit is contained in:
yamamama 2025-11-16 00:23:12 -05:00
parent f5c1cd63b4
commit 84e0f9503e

View file

@ -16,6 +16,8 @@
#define __M_FIXED__
#include "doomtype.h"
#include "doomdef.h"
#ifdef __GNUC__
#include <stdlib.h>
#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))