Alchemy
Loading...
Searching...
No Matches

macros.h

Go to the documentation of this file.
1#ifndef ALCHEMY_MACROS_H
2#define ALCHEMY_MACROS_H
3
4/// @file
5/// Small statement macros both games use for positions, velocities and
6/// bounds. The multi-part ones are comma expressions or a plain block, not
7/// do { } while (0): a do-while (0) compiles differently at some of their
8/// sites (see AGENTS.md, S2).
9
10/// Sets the x, y and z of a three-part vector: a position about to be
11/// projected, a per-frame step, a camera point or a scale.
12#define SET_VECTOR(v, x, y, z) ((v)[0] = (x), (v)[1] = (y), (v)[2] = (z))
13
14/// Sets the position or the velocity of a particle, a piece of debris or an
15/// object in one statement.
16#define SET_POSITION(p, px, py, pz) \
17 ((p)->x = (px), (p)->y = (py), (p)->z = (pz))
18#define SET_VELOCITY(p, vx, vy, vz) \
19 ((p)->velocityX = (vx), (p)->velocityY = (vy), (p)->velocityZ = (vz))
20
21/// Keeps `v` within low to high, the low bound tested first. A plain block,
22/// so it cannot stand before an `else`.
23#define CLAMP(v, low, high) \
24 { \
25 if ((v) < (low)) \
26 (v) = (low); \
27 if ((v) > (high)) \
28 (v) = (high); \
29 }
30
31/// The magnitude of v. v is read twice.
32#define ABS(v) ((v) < 0 ? -(v) : (v))
33
34#endif