void history_processFlags(history_t* past) // to be called after completely recording this history, before calculating any values. { state_t* flagState = dict_lookup(past->states, "flags"); state_t* nextState; U16 nextFlags, toggledFlags, currentFlags = (U16)flagState->value; while (flagState->next) { nextState = flagState->next; nextFlags = (U16)nextState->value; toggledFlags = currentFlags ^ nextFlags; if (toggledFlags & IF_FIXED_ALIGNMENT) { // the IF_FIXED_ALIGNMENT bit will change in the next state if (nextFlags & IF_FIXED_ALIGNMENT) { // the IF_FIXED_ALIGNMENT bit will be set int onFrame = nextState->frame; state_t* rotations = dict_lookup(past->states, "rotate"); nextState->params.instanceAngle = state_value(rotations, onFrame); state_t* resetRotate = state_new(onFrame, CF_JUMP, 0, 0); state_insert(rotations, resetRotate); if (onFrame == past->firstFrame) onFrame++; state_t *x, *y; float dx, dy; do { x = dict_lookup(past->states, "x"); dx = state_tangent(x, onFrame, T_SYMMETRIC); y = dict_lookup(past->states, "y"); dy = state_tangent(y, onFrame, T_SYMMETRIC); onFrame++; } while (dx == 0 && dy == 0 && onFrame < past->lastFrame); if (onFrame == past->lastFrame) nextState->params.pathAngle = 0; else nextState->params.pathAngle = getAngle(dx, dy) / M_PI * 180; } else // the IF_FIXED_ALIGNMENT bit will be reset { int offFrame = nextState->frame; state_t* rotations = dict_lookup(past->states, "rotate"); state_t* setRotate = state_new(offFrame, CF_JUMP, flagState->params.instanceAngle + state_value(rotations, offFrame), 0); state_insert(rotations, setRotate); } } else // the IF_FIXED_ALIGNMENT bit will not change but some processing may be // required just the same { if (nextFlags & IF_FIXED_ALIGNMENT) { nextState->params.instanceAngle = flagState->params.instanceAngle; nextState->params.pathAngle = flagState->params.pathAngle; } } // and so on for all the other bits. flagState = nextState; currentFlags = nextFlags; } }
void view_insert(view *V) { int i; assert(V); i = (int) (floor(V->t) + 1) % ( V->n + 1); state_insert(V, i, &V->curr); V->t = i; }
void view_load(view *V, const char *name) { FILE *fp; if ((fp = fopen(name, "r"))) { state s; while (state_read(fp, &s)) state_insert(V, V->n, &s); fclose(fp); } }