Skip to content

Commit 85e0d37

Browse files
committed
[tsoding] co_interpolate -> co_tween
1 parent aef6390 commit 85e0d37

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

nob.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Procs procs = {0};
1414

1515
void cflags(void)
1616
{
17-
cmd_append(&cmd, "-Wall", "-Wextra", "-Wno-missing-field-initializers", "-ggdb");
17+
cmd_append(&cmd, "-Wall");
18+
cmd_append(&cmd, "-Wextra");
19+
cmd_append(&cmd, "-Wno-missing-field-initializers");
20+
cmd_append(&cmd, "-Wno-unused-function");
21+
cmd_append(&cmd, "-ggdb");
1822
cmd_append(&cmd, "-I"RAYLIB_DIR"include");
1923
cmd_append(&cmd, "-I"PANIM_DIR);
2024
cmd_append(&cmd, "-I.");
@@ -104,7 +108,7 @@ int main(int argc, char **argv)
104108
bool force = false;
105109
while (argc > 0) {
106110
const char *flag = shift(argv, argc);
107-
if (strcmp(flag, "-f") == 0) {
111+
if (strcmp(flag, "-f") == 0 || strcmp(flag, "-B") == 0) {
108112
force = true;
109113
} else {
110114
nob_log(ERROR, "Unknown flag %s", flag);

plugs/tsoding/plug.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,30 @@ static void unload_assets(void)
4646
UnloadWave(p->kick_wave);
4747
}
4848

49-
void co_interpolate(Stack *stack, float *x, float a, float b, float duration)
49+
#define co_tween(stack, duration, ...) co_tween_impl((stack), (duration), __VA_ARGS__, NULL)
50+
void co_tween_impl(Stack *stack, float duration, ...)
5051
{
5152
float t = 0.0;
5253
while (t < 1.0f) {
5354
t = (t*duration + p->env.delta_time)/duration;
54-
*x = Lerp(a, b, t*t);
55-
coroutine_yield(stack);
56-
}
57-
}
58-
59-
void co_interpolate3(Stack *stack, float *x, float ax, float bx, float *y, float ay, float by, float *z, float az, float bz, float duration)
60-
{
61-
float t = 0.0;
62-
while (t < 1.0f) {
63-
t = (t*duration + p->env.delta_time)/duration;
64-
*x = Lerp(ax, bx, t*t);
65-
*y = Lerp(ay, by, t*t);
66-
*z = Lerp(az, bz, t*t);
55+
va_list args;
56+
va_start(args, duration);
57+
float *x = va_arg(args, float*);
58+
while (x != NULL) {
59+
float a = va_arg(args, double);
60+
float b = va_arg(args, double);
61+
*x = Lerp(a, b, t*t);
62+
x = va_arg(args, float*);
63+
}
64+
va_end(args);
6765
coroutine_yield(stack);
6866
}
6967
}
7068

7169
void co_sleep(Stack *stack, float duration)
7270
{
7371
float x;
74-
co_interpolate(stack, &x, 0, 1, duration);
72+
co_tween(stack, duration, &x, 0, 1);
7573
}
7674

7775
void animation(Stack *stack, void *data)
@@ -86,20 +84,19 @@ void animation(Stack *stack, void *data)
8684
float duration = 0.15f;
8785
float sleep = 0.25f;
8886
p->env.play_sound(p->kick_sound, p->kick_wave);
89-
co_interpolate(stack, &p->radius, 0.f, 1.f, duration);
87+
co_tween(stack, duration, &p->radius, 0.f, 1.f);
9088
co_sleep(stack, sleep);
9189
p->env.play_sound(p->kick_sound, p->kick_wave);
92-
co_interpolate(stack, &p->roundness, 0.f, 1.f, duration);
90+
co_tween(stack, duration, &p->roundness, 0.f, 1.f);
9391
co_sleep(stack, sleep);
9492
p->env.play_sound(p->kick_sound, p->kick_wave);
95-
co_interpolate3(stack,
93+
co_tween(stack, duration,
9694
&p->alpha, 0.f, 1.f,
9795
&p->roundness, 1.f, 0.f,
98-
&p->rotation, 0.f, 1.f,
99-
duration);
96+
&p->rotation, 0.f, 1.f);
10097
co_sleep(stack, sleep);
10198
p->env.play_sound(p->kick_sound, p->kick_wave);
102-
co_interpolate(stack, &p->radius, 1.f, 0.f, duration);
99+
co_tween(stack, duration, &p->radius, 1.f, 0.f);
103100
co_sleep(stack, 2.0);
104101
}
105102

0 commit comments

Comments
 (0)