3 ms·
Function pointers are a good means of allowing "flexible" finite state patterns, by making each function a state, directing all program flow to a "next" functio
by chipsy 17y ago
Function pointers are a good means of allowing "flexible" finite state patterns, by making each function a state, directing all program flow to a "next" function pointer, and using conditionals within each state to begin transitions:
/* an "active" state where a timer decrements unless the user hits a key. */
if (timer<1) {prep_for_idle(); next = idle;}
else if (user_hit_key) {timer+=100; next = active;}
else {timer--; next = active;}
I use this pattern in haXe and Python, not C, but it applies equally well.