102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
spline.h
Go to the documentation of this file.
1#ifndef PCDOGS_ANIMATION_SPLINE_H
2#define PCDOGS_ANIMATION_SPLINE_H
3
8
14
15static inline uint32_t spline_key_time(uint32_t packed)
16{
17 return (packed >> 14) & ANIMATION_SPLINE_TIME_Q6_MASK;
18}
19
20static inline int32_t spline_mul_q12(int32_t a, int32_t b)
21{
22 return (int32_t)(((int64_t)a * b) >> MATH_Q12_SHIFT);
23}
24
25static inline struct HermiteWeights spline_weights(int32_t t)
26{
27 /* SHRD 12, SHR 8 discards high bits before the Q20 product is reused. */
28 uint32_t square = (uint32_t)spline_mul_q12(t, t) >> 8;
29 uint32_t cube = (uint32_t)spline_mul_q12(t, square) >> 8;
30 int32_t end_value = (int32_t)(3 * square - 2 * cube) >> 8;
31 struct HermiteWeights weights = {
33 (int32_t)(cube - 2 * square + (uint32_t)t) >> 8,
34 (int32_t)(cube - square) >> 8};
35 return weights;
36}
37
38/* Skin weight samplers treat a negative time as preceding every key in the
39 endpoint and linear scans. All three samplers use unsigned binary search. */
40static inline int32_t sample_scalar_keys(uint32_t frame_time, struct Animation_SplineChannelScalar *channel,
41 bool signed_time)
42{
44 int last = channel->keyframe_count - 1;
45 struct Animation_ScalarKeyframe *start = &keys[last];
46 struct Animation_ScalarKeyframe *end = keys;
47 uint32_t time = frame_time + ((uint32_t)(uint16_t)channel->packed_time_bias_and_end_time << 6);
48 bool before_zero = signed_time && (int32_t)time < 0;
49 uint32_t end_time = spline_key_time(start->timing.packed);
50 if (before_zero || time < end_time)
51 {
52 int next = 1;
53 if (last <= 3)
54 {
55 while (!before_zero && time >= spline_key_time(keys[next].timing.packed))
56 ++next;
57 }
58 else
59 {
60 int high = last;
61 while (next <= high)
62 {
63 int mid = (next + high) / 2;
64 if (time < spline_key_time(keys[mid].timing.packed))
65 high = mid - 1;
66 else
67 next = mid + 1;
68 }
69 }
70 start = &keys[next - 1];
71 end = &keys[next];
72 end_time = spline_key_time(end->timing.packed);
73 }
74 else
75 {
76 if (time == end_time)
77 return start->value;
79 if (time >= end_time)
80 {
82 return (channel->channel_flags & wrap) == wrap ? end->value : start->value;
83 }
84 }
85
86 int32_t t = Animation_CalculateSplineParameter(time, end_time, start->timing.packed,
87 (uint8_t)end->timing.packed, (uint8_t *)keys);
88 struct HermiteWeights w = spline_weights(t);
89 return (int32_t)((uint32_t)spline_mul_q12(w.start_value, start->value) +
90 (uint32_t)spline_mul_q12(w.end_value, end->value) +
91 (uint32_t)spline_mul_q12(w.start_tangent, start->tangent_out) +
92 (uint32_t)spline_mul_q12(w.end_tangent, end->tangent_in));
93}
94
95#endif
#define ANIMATION_SPLINE_REPEAT_ENDPOINT
Definition constants.h:31
#define ANIMATION_SPLINE_TIME_Q6_MASK
Definition constants.h:37
#define ANIMATION_SPLINE_WRAP_SAMPLE_TIME
Definition enums.h:55
int32_t Animation_CalculateSplineParameter(uint32_t sample_time, uint32_t next_key_time, uint32_t prev_key_packed, uint8_t next_ease_index, uint8_t *keyframe_data)
#define MATH_Q12_SHIFT
Definition constants.h:8
#define MATH_Q12_ONE
Definition constants.h:9
static int32_t sample_scalar_keys(uint32_t frame_time, struct Animation_SplineChannelScalar *channel, bool signed_time)
Definition spline.h:40
static uint32_t spline_key_time(uint32_t packed)
Definition spline.h:15
static struct HermiteWeights spline_weights(int32_t t)
Definition spline.h:25
static int32_t spline_mul_q12(int32_t a, int32_t b)
Definition spline.h:20
union Animation_KeyframeTiming timing
Definition types.h:1176
struct Animation_ScalarKeyframe * keyframes_or_minus_one_sentinel
Definition types.h:353
int32_t packed_time_bias_and_end_time
Definition types.h:354
Animation_SplineChannelFlags channel_flags
Definition types.h:358
int32_t end_tangent
Definition spline.h:12
int32_t start_tangent
Definition spline.h:12
int32_t end_value
Definition spline.h:11
int32_t start_value
Definition spline.h:11