mirror of
https://github.com/pret/pmd-sky.git
synced 2026-08-05 02:37:05 -05:00
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
#ifndef PMDSKY_UTIL_H
|
|
#define PMDSKY_UTIL_H
|
|
|
|
typedef s32 fx32_8; // 32-bit signed fixed-point number with 8 fraction bits
|
|
typedef u32 ufx32_8; // 32-bit unsigned fixed-point number with 8 fraction bits
|
|
typedef u8 bool8;
|
|
typedef u32 bool32;
|
|
|
|
// RGBA8 structure. Sometimes alpha is ignored and only used for padding
|
|
struct rgba {
|
|
u8 r;
|
|
u8 b;
|
|
u8 g;
|
|
u8 a; // Sometimes used only for padding
|
|
};
|
|
|
|
// a 2d short (16bit) vector
|
|
struct vec2_16 {
|
|
s16 x;
|
|
s16 y;
|
|
};
|
|
|
|
// a 2d ushort (16bit) vector
|
|
struct uvec2_16 {
|
|
u16 x;
|
|
u16 y;
|
|
};
|
|
|
|
// a (16b.16b) fixed-point rational
|
|
struct fixed_point {
|
|
s16 integer;
|
|
s16 fractional;
|
|
};
|
|
|
|
// 64-bit signed fixed-point number with 16 fraction bits.
|
|
// Represents the number ((upper << 16) + (lower >> 16) + (lower & 0xFFFF) * 2^-16)
|
|
struct fixed_point_64 {
|
|
s32 upper; // sign bit, plus the 31 most significant integer bits
|
|
u32 lower; // the 32 least significant bits (16 integer + 16 fraction)
|
|
};
|
|
|
|
// Compares two numbers and return the minimum
|
|
#define MIN(A, B) ((A > B) ? B : A)
|
|
|
|
// Same as MIN macro but as a static inline, since the macro doesn't match in some places.
|
|
static inline s32 Min(s32 a, s32 b)
|
|
{
|
|
return a < b ? a : b;
|
|
}
|
|
|
|
#define MAX(A, B) ((A > B) ? A : B)
|
|
|
|
static inline s32 Max(s32 a, s32 b)
|
|
{
|
|
return a > b ? a : b;
|
|
}
|
|
|
|
#define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0]))
|
|
|
|
#define SWAP(a, b, temp) \
|
|
{ \
|
|
temp = a; \
|
|
a = b; \
|
|
b = temp; \
|
|
}
|
|
|
|
// Returns a bool8 given a flag and the target bit
|
|
#define GET_FLAG(FLAG, BIT) ((bool8) (((FLAG) & (BIT)) ? TRUE : FALSE))
|
|
|
|
// Same as GET_FLAG but as a static inline, since the macro doesn't match in some places
|
|
static inline bool8 GetFlag(u8 flag, u8 bit)
|
|
{
|
|
return (flag & bit) != 0;
|
|
}
|
|
|
|
#endif //PMDSKY_UTIL_H
|