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:
parent
f5c1cd63b4
commit
84e0f9503e
1 changed files with 49 additions and 0 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue