common_tasks: add RADIAL_LOOP helper macro
Helps with writing radially symmetrical patterns. Replace this: int cnt = 69; cmplx dir = initial_dir; cmplx turn = cdir(M_TAU/cnt); for(int = 0; i < cnt; ++i, dir *= turn) { pew_pew(dir); } with this: RADIAL_LOOP(l, 69, initial_dir) { pew_pew(l.dir); }
This commit is contained in:
parent
bc1267f0e8
commit
323183061b
1 changed files with 21 additions and 0 deletions
|
@ -165,3 +165,24 @@ DECLARE_EXTERN_TASK(
|
|||
);
|
||||
|
||||
DECLARE_EXTERN_TASK(common_play_sfx, { const char *name; });
|
||||
|
||||
// TODO: move this elsewhere?
|
||||
|
||||
typedef struct RadialLoop {
|
||||
cmplx dir, turn;
|
||||
int cnt, i;
|
||||
} RadialLoop;
|
||||
|
||||
INLINE RadialLoop _radial_loop_init(int cnt, cmplx dir) {
|
||||
return (RadialLoop) {
|
||||
.dir = dir,
|
||||
.cnt = abs(cnt),
|
||||
.turn = cdir(M_TAU/cnt),
|
||||
};
|
||||
}
|
||||
|
||||
#define RADIAL_LOOP(_loop_var, _cnt_init, _dir_init) \
|
||||
for( \
|
||||
RadialLoop _loop_var = _radial_loop_init(_cnt_init, _dir_init); \
|
||||
_loop_var.i < _loop_var.cnt; \
|
||||
++_loop_var.i, _loop_var.dir *= _loop_var.turn)
|
||||
|
|
Loading…
Reference in a new issue