fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchMerge pull request #307 from NickCondron/wd4578fd4

master
2.2 KiB114 linesraw
1#ifndef MEX_H_INLINE
2#define MEX_H_INLINE
3
4#include "structs.h"
5#include "fighter.h"
6#include "obj.h"
7#include "mex.h"
8#include "datatypes.h"
9#include "gx.h"
10#include "hsd.h"
11#include "math.h"
12#include "useful.h"
13#include "scene.h"
14#include "preload.h"
15
16/*** Macros ***/
17#define countof(A) (sizeof(A)/sizeof(*(A)))
18
19/*** Functions ***/
20
21static inline int min(int a, int b) {
22    return a < b ? a : b;
23}
24
25static inline int max(int a, int b) {
26    return a > b ? a : b;
27}
28
29static inline float lerp(float start, float end, float t)
30{
31    // clamp
32    if (t < 0)
33        t = 0;
34    else if (t > 1)
35        t = 1;
36
37    return start + t * (end - start);
38}
39
40static inline int abs(int x)
41{
42    if (x < 0)
43        return -x;
44    else
45        return x;
46}
47
48static float ceil(float x)
49{
50    if (x != x) return x;  // NaN
51    if (x >= 2147483647.0f || x <= -2147483648.0f) return x;  // Too large for int
52    
53    int trunc = (int)x;
54    
55    if (x == (float)trunc)
56        return x;
57    if (x > 0)
58        return (float)(trunc + 1);
59    return (float)trunc;
60}
61
62static void PRIM_DRAW(float x, float y, float z, u32 color)
63{
64    gx_pipe->d.F32 = x;
65    gx_pipe->d.F32 = y;
66    gx_pipe->d.F32 = z;
67    gx_pipe->d.U32 = color;
68}
69
70static HSD_Pad *PadGetMaster(int player_index)
71{
72    return &stc_master_pads->pad[player_index];
73}
74static HSD_Pad *PadGetEngine(int player_index)
75{
76    return &stc_engine_pads->pad[player_index];
77}
78static PADStatus *PadGetRaw(int player_index)
79{
80    PadLibData *p = stc_padlibdata;
81    u8 index = (p->qread + p->qnum - 1) % p->qnum;
82    return &p->queue[index].stat[player_index];
83}
84
85static float Math_Vec2Distance(Vec2 *a, Vec2 *b)
86{
87    return sqrtf(squaref(a->X - b->X) + squaref(a->Y - b->Y));
88}
89
90static float Math_Vec3Distance(Vec3 *a, Vec3 *b)
91{
92    return sqrtf(squaref(a->X - b->X) + squaref(a->Y - b->Y) + squaref(a->Z - b->Z));
93}
94
95static inline float fmin(float a, float b)
96{
97    return (((a) < (b)) ? (a) : (b));
98}
99
100static inline float fmax(float a, float b)
101{
102    return (((a) > (b)) ? (a) : (b));
103}
104
105static inline float fclamp(float n, float min, float max) {
106    return fmin(max, fmax(min, n));
107}
108
109static inline float smooth_lerp(float time, float start, float end) {
110    float delta = time * time * (3.0f - 2.0f * time);
111    return delta * (end - start) + start;
112}
113
114#endif