Alchemy
Loading...
Searching...
No Matches

effect_step.h

Go to the documentation of this file.
1#ifndef ALCHEMY_EFFECT_STEP_H
2#define ALCHEMY_EFFECT_STEP_H
3
4/// @file
5/// EffectStep and EffectPosition, the positions effects move through.
6
7#include "edition.h"
8#include "types.h"
9#include "static_assert.h"
10
11/// A moving point of an effect: its position, its velocity and a value each
12/// effect uses its own way (a size, a timer, -1 for idle).
13struct EffectStep {
14#ifdef UBFIX
15 union {
16 struct {
17 s32 x; ///< 16.16 fixed-point pixels
18 s32 y; ///< 16.16 fixed-point pixels
19 s32 z; ///< 16.16 fixed-point pixels
20 };
21 s32 coordinates[3];
22 };
23#else
24 s32 x; ///< 16.16 fixed-point pixels
25 s32 y; ///< 16.16 fixed-point pixels
26 s32 z; ///< 16.16 fixed-point pixels
27#endif
28 s32 velocityX; ///< 16.16 fixed-point pixels per frame
29 s32 velocityY; ///< 16.16 fixed-point pixels per frame
30 s32 velocityZ; ///< 16.16 fixed-point pixels per frame
31 s32 variant; ///< each effect's own: a size, a countdown, -1 for idle
32};
33
34/// Returns the step's three coordinates as an array.
35// UB: indexing from &x crosses the step's separate scalar members. UBFIX
36// supplies a real coordinate array without including motion state.
37static inline const s32 *EffectStep_Coordinates(const struct EffectStep *step) {
38#ifdef UBFIX
39 return step->coordinates;
40#else
41 return &step->x;
42#endif
43}
44
45/// A point projected onto the screen, with its depth.
47#ifdef UBFIX
48 /// Projection writes three coordinates; effects read their named components.
49 union {
50 struct {
51 s32 x; ///< screen pixels
52 s32 y; ///< screen pixels
53 s32 depth; ///< projected depth, larger further away
54 };
55 s32 coordinates[3];
56 };
57#else
58 s32 x; ///< screen pixels
59 s32 y; ///< screen pixels
60 s32 depth; ///< projected depth, larger further away
61#endif
62};
63
64/// Returns the position's three coordinates as an array.
65// UB: indexing from &x crosses separate scalar members in the legacy record.
66// UBFIX provides a real array while keeping the effects' named coordinates. An
67// always-on union changes native alias analysis in the effect/window code.
68static inline s32 *EffectPosition_Coordinates(struct EffectPosition *position) {
69#ifdef UBFIX
70 return position->coordinates;
71#else
72 return &position->x;
73#endif
74}
75
76STATIC_ASSERT(offsetof(struct EffectStep, x) == 0x00);
77STATIC_ASSERT(offsetof(struct EffectStep, y) == 0x04);
78STATIC_ASSERT(offsetof(struct EffectStep, z) == 0x08);
79STATIC_ASSERT(offsetof(struct EffectStep, velocityX) == 0x0c);
80STATIC_ASSERT(offsetof(struct EffectStep, velocityY) == 0x10);
81STATIC_ASSERT(offsetof(struct EffectStep, velocityZ) == 0x14);
82STATIC_ASSERT(offsetof(struct EffectStep, variant) == 0x18);
83STATIC_ASSERT(sizeof(struct EffectStep) == 0x1c);
84STATIC_ASSERT(sizeof(struct EffectPosition) == 0x0c);
85
86#endif
The edition's language, for C to compare (LANGUAGE == LANGUAGE_GERMAN).
static const s32 * EffectStep_Coordinates(const struct EffectStep *step)
Returns the step's three coordinates as an array.
Definition effect_step.h:37
static s32 * EffectPosition_Coordinates(struct EffectPosition *position)
Returns the position's three coordinates as an array.
Definition effect_step.h:68
STATIC_ASSERT, a compile-time check that emits nothing.
#define STATIC_ASSERT(condition)
C89 permits repeated extern declarations of the same array.
#define offsetof(type, member)
Definition stddef.h:19
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 y
screen pixels
Definition effect_step.h:59
s32 depth
projected depth, larger further away
Definition effect_step.h:60
s32 x
screen pixels
Definition effect_step.h:58
A moving point of an effect: its position, its velocity and a value each effect uses its own way (a s...
Definition effect_step.h:13
s32 velocityX
16.16 fixed-point pixels per frame
Definition effect_step.h:28
s32 z
16.16 fixed-point pixels
Definition effect_step.h:26
s32 variant
each effect's own: a size, a countdown, -1 for idle
Definition effect_step.h:31
s32 x
16.16 fixed-point pixels
Definition effect_step.h:24
s32 y
16.16 fixed-point pixels
Definition effect_step.h:25
s32 velocityY
16.16 fixed-point pixels per frame
Definition effect_step.h:29
s32 velocityZ
16.16 fixed-point pixels per frame
Definition effect_step.h:30
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14