X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=src%2Fswfc-history.c;h=d97605397bb2c1e673ac60265d018f90ff0d11ce;hp=322c32545e1b84acbd7c7eef1a3f1610a45a011c;hb=f29d8006b1d8253c50808d6eb4941bdeb808c601;hpb=01d3feb7d0121737b3456a3cfbaf6a02b6362d8d diff --git a/src/swfc-history.c b/src/swfc-history.c index 322c325..d976053 100644 --- a/src/swfc-history.c +++ b/src/swfc-history.c @@ -25,9 +25,9 @@ enum { - T_BEFORE = 0, - T_AFTER = 1, - T_SYMMETRIC = 2 + T_BEFORE, + T_AFTER, + T_SYMMETRIC }; state_t* state_new(U16 frame, int function, float value, interpolation_t* inter) @@ -65,29 +65,34 @@ void state_append(state_t* state, state_t* newState) state_t* previous = 0; state_t* start = state; float p0, p1, m0, m1; + int previous_frames = 0, state_frames, new_frames; while (state->next) { + if (previous) + previous_frames = state->frame - previous->frame; previous = state; state = state->next; } state->next = newState; + new_frames = newState->frame - state->frame; if (state->function == CF_SCHANGE) { + state_frames = state->frame - previous->frame; p0 = previous->value; p1 = state->value; if (previous->function == CF_SCHANGE) - m0 = (3 * previous->spline.a + 2 * previous->spline.b + previous->spline.c); + m0 = (3 * previous->spline.a + 2 * previous->spline.b + previous->spline.c) * state_frames / previous_frames ; else if (previous->function == CF_CHANGE || previous->function == CF_SWEEP) - m0 = state_tangent(start, previous->frame, T_BEFORE) * (state->frame - previous->frame); + m0 = state_tangent(start, previous->frame, T_BEFORE) * state_frames; else m0 = (state->value - previous->value); if (newState->function == CF_SCHANGE) - m1 = 0.5 * (newState->value - previous->value)/* * (state->frame - previous->frame) / (newState->frame - state->frame)*/; + m1 = /*0.5 * */(newState->value - previous->value) * state_frames / (new_frames + state_frames); else if (newState->function == CF_CHANGE || newState->function == CF_SWEEP) - m1 = state_tangent(previous, state->frame, T_AFTER) * (state->frame - previous->frame); + m1 = state_tangent(previous, state->frame, T_AFTER) * state_frames; else m1 = (newState->value - state->value); state->spline.a = 2 * p0 + m0 - 2 * p1 + m1; @@ -105,7 +110,7 @@ void state_append(state_t* state, state_t* newState) m0 = m1; else if (state->function == CF_CHANGE || state->function == CF_SWEEP) - m0 = state_tangent(start, state->frame, T_BEFORE) * (state->frame - previous->frame); + m0 = state_tangent(start, state->frame, T_BEFORE) * new_frames; else m0 = (newState->value - state->value); m1 = (newState->value - state->value); @@ -113,6 +118,8 @@ void state_append(state_t* state, state_t* newState) newState->spline.b = -3 * p0 - 2 * m0 + 3 * p1 - m1; newState->spline.c = m0; newState->spline.d = p0; +// printf("p0: %f, p1: %f, m0: %f, m1: %f.\n", p0, p1, m0, m1); +// printf("a: %f, b: %f, c: %f, d: %f.\n", newState->spline.a, newState->spline.b, newState->spline.c, newState->spline.d); } } @@ -315,7 +322,7 @@ void filterState_append(filterState_t* first, filterState_t* newChange) for (i = 0; i < first->value->num; i++) { newList = (char*)malloc(strlen(list1) + strlen(filtername[first->value->filter[i]->type]) + 2); - newList = strcat(strcat(list1, "+"), filtername[first->value->filter[i]->type]); + strcpy(newList, strcat(strcat(list1, "+"), filtername[first->value->filter[i]->type])); free(list1); list1 = newList; } @@ -324,7 +331,7 @@ void filterState_append(filterState_t* first, filterState_t* newChange) for (i = 0; i < newChange->value->num; i++) { newList = (char*)malloc(strlen(list1) + strlen(filtername[newChange->value->filter[i]->type]) + 2); - newList = strcat(strcat(list2, "+"), filtername[newChange->value->filter[i]->type]); + strcpy(newList, strcat(strcat(list2, "+"), filtername[newChange->value->filter[i]->type])); free(list2); list2 = newList; } @@ -811,35 +818,35 @@ history_t* history_new() void history_free(history_t* past) { - state_free(dictionary_lookup(past->states, "x")); - state_free(dictionary_lookup(past->states, "y")); - state_free(dictionary_lookup(past->states, "scalex")); - state_free(dictionary_lookup(past->states, "scaley")); - state_free(dictionary_lookup(past->states, "cxform.r0")); - state_free(dictionary_lookup(past->states, "cxform.g0")); - state_free(dictionary_lookup(past->states, "cxform.b0")); - state_free(dictionary_lookup(past->states, "cxform.a0")); - state_free(dictionary_lookup(past->states, "cxform.r1")); - state_free(dictionary_lookup(past->states, "cxform.g1")); - state_free(dictionary_lookup(past->states, "cxform.b1")); - state_free(dictionary_lookup(past->states, "cxform.a1")); - state_free(dictionary_lookup(past->states, "rotate")); - state_free(dictionary_lookup(past->states, "shear")); - state_free(dictionary_lookup(past->states, "pivot.x")); - state_free(dictionary_lookup(past->states, "pivot.y")); - state_free(dictionary_lookup(past->states, "pin.x")); - state_free(dictionary_lookup(past->states, "pin.y")); - state_free(dictionary_lookup(past->states, "blendmode")); - state_free(dictionary_lookup(past->states, "flags")); - filterState_free(dictionary_lookup(past->states, "filter")); - dictionary_destroy(past->states); - free(past); + state_free(dict_lookup(past->states, "x")); + state_free(dict_lookup(past->states, "y")); + state_free(dict_lookup(past->states, "scalex")); + state_free(dict_lookup(past->states, "scaley")); + state_free(dict_lookup(past->states, "cxform.r0")); + state_free(dict_lookup(past->states, "cxform.g0")); + state_free(dict_lookup(past->states, "cxform.b0")); + state_free(dict_lookup(past->states, "cxform.a0")); + state_free(dict_lookup(past->states, "cxform.r1")); + state_free(dict_lookup(past->states, "cxform.g1")); + state_free(dict_lookup(past->states, "cxform.b1")); + state_free(dict_lookup(past->states, "cxform.a1")); + state_free(dict_lookup(past->states, "rotate")); + state_free(dict_lookup(past->states, "shear")); + state_free(dict_lookup(past->states, "pivot.x")); + state_free(dict_lookup(past->states, "pivot.y")); + state_free(dict_lookup(past->states, "pin.x")); + state_free(dict_lookup(past->states, "pin.y")); + state_free(dict_lookup(past->states, "blendmode")); + state_free(dict_lookup(past->states, "flags")); + filterState_free(dict_lookup(past->states, "filter")); + dict_destroy(past->states); + free(past); } void history_init(history_t* past) { - past->states = (dictionary_t*)malloc(sizeof(dictionary_t)); - dictionary_init(past->states); + past->states = (dict_t*)malloc(sizeof(dict_t)); + dict_init(past->states, 16); } void history_begin(history_t* past, char* parameter, U16 frame, TAG* tag, float value) @@ -847,7 +854,7 @@ void history_begin(history_t* past, char* parameter, U16 frame, TAG* tag, float state_t* first = state_new(frame, CF_PUT, value, 0); past->firstTag = tag; past->firstFrame = frame; - dictionary_put2(past->states, parameter, first); + dict_put2(past->states, parameter, first); } void history_beginFilter(history_t* past, U16 frame, TAG* tag, FILTERLIST* value) @@ -855,13 +862,13 @@ void history_beginFilter(history_t* past, U16 frame, TAG* tag, FILTERLIST* value filterState_t* first = filterState_new(frame, CF_PUT, value, 0); past->firstTag = tag; past->firstFrame = frame; - dictionary_put2(past->states, "filter", first); + dict_put2(past->states, "filter", first); } void history_remember(history_t* past, char* parameter, U16 frame, int function, float value, interpolation_t* inter) { past->lastFrame = frame; - state_t* state = dictionary_lookup(past->states, parameter); + state_t* state = dict_lookup(past->states, parameter); if (state) //should always be true { state_t* next = state_new(frame, function, value, inter); @@ -912,14 +919,14 @@ void history_rememberSweep(history_t* past, U16 frame, float x, float y, float r U16 lastFrame; past->lastFrame = frame; - state_t* change = dictionary_lookup(past->states, "x"); + state_t* change = dict_lookup(past->states, "x"); if (change) //should always be true { while (change->next) change = change->next; lastFrame = change->frame; lastX = change->value; - change = dictionary_lookup(past->states, "y"); + change = dict_lookup(past->states, "y"); if (change) //should always be true { while (change->next) @@ -981,7 +988,7 @@ void history_rememberSweep(history_t* past, U16 frame, float x, float y, float r centerX = c2X; centerY = c2Y; } - change = dictionary_lookup(past->states, "x"); + change = dict_lookup(past->states, "x"); state_t* nextX = state_new(frame, CF_SWEEP, x, inter); nextX->arc.r = r; nextX->arc.angle = angle1; @@ -990,7 +997,7 @@ void history_rememberSweep(history_t* past, U16 frame, float x, float y, float r nextX->arc.cY = centerY; nextX->arc.X = 1; state_append(change, nextX); - change = dictionary_lookup(past->states, "y"); + change = dict_lookup(past->states, "y"); state_t* nextY = state_new(frame, CF_SWEEP, y, inter); nextY->arc.r = r; nextY->arc.angle = angle1; @@ -1010,7 +1017,7 @@ void history_rememberSweep(history_t* past, U16 frame, float x, float y, float r void history_rememberFilter(history_t* past, U16 frame, int function, FILTERLIST* value, interpolation_t* inter) { past->lastFrame = frame; - filterState_t* first = dictionary_lookup(past->states, "filter"); + filterState_t* first = dict_lookup(past->states, "filter"); if (first) //should always be true { filterState_t* next = filterState_new(frame, function, value, inter); @@ -1023,7 +1030,7 @@ void history_rememberFilter(history_t* past, U16 frame, int function, FILTERLIST void history_processFlags(history_t* past) // to be called after completely recording this history, before calculating any values. { - state_t* flagState = dictionary_lookup(past->states, "flags"); + state_t* flagState = dict_lookup(past->states, "flags"); state_t* nextState; U16 nextFlags, toggledFlags, currentFlags = (U16)flagState->value; while (flagState->next) @@ -1036,7 +1043,7 @@ void history_processFlags(history_t* past) if (nextFlags & IF_FIXED_ALIGNMENT) { // the IF_FIXED_ALIGNMENT bit will be set int onFrame = nextState->frame; - state_t* rotations = dictionary_lookup(past->states, "rotate"); + 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); @@ -1046,9 +1053,9 @@ void history_processFlags(history_t* past) float dx, dy; do { - x = dictionary_lookup(past->states, "x"); + x = dict_lookup(past->states, "x"); dx = state_tangent(x, onFrame, T_SYMMETRIC); - y = dictionary_lookup(past->states, "y"); + y = dict_lookup(past->states, "y"); dy = state_tangent(y, onFrame, T_SYMMETRIC); onFrame++; } @@ -1061,7 +1068,7 @@ void history_processFlags(history_t* past) else // the IF_FIXED_ALIGNMENT bit will be reset { int offFrame = nextState->frame; - state_t* rotations = dictionary_lookup(past->states, "rotate"); + 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); } @@ -1083,7 +1090,7 @@ void history_processFlags(history_t* past) int history_change(history_t* past, U16 frame, char* parameter) { - state_t* first = dictionary_lookup(past->states, parameter); + state_t* first = dict_lookup(past->states, parameter); if (first) //should always be true. return state_differs(first, frame); syntaxerror("no history found to predict changes for parameter %s.\n", parameter); @@ -1092,7 +1099,7 @@ int history_change(history_t* past, U16 frame, char* parameter) float history_value(history_t* past, U16 frame, char* parameter) { - state_t* state = dictionary_lookup(past->states, parameter); + state_t* state = dict_lookup(past->states, parameter); if (state) //should always be true. return state_value(state, frame); syntaxerror("no history found to get a value for parameter %s.\n", parameter); @@ -1101,11 +1108,11 @@ float history_value(history_t* past, U16 frame, char* parameter) float history_rotateValue(history_t* past, U16 frame) { - state_t* rotations = dictionary_lookup(past->states, "rotate"); + state_t* rotations = dict_lookup(past->states, "rotate"); if (rotations) //should always be true. { float angle = state_value(rotations, frame); - state_t* flags = dictionary_lookup(past->states, "flags"); + state_t* flags = dict_lookup(past->states, "flags"); U16 currentflags = state_value(flags, frame); if (currentflags & IF_FIXED_ALIGNMENT) { @@ -1116,9 +1123,9 @@ float history_rotateValue(history_t* past, U16 frame) float dx, dy, pathAngle; do { - x = dictionary_lookup(past->states, "x"); + x = dict_lookup(past->states, "x"); dx = state_value(x, frame) - state_value(x, frame - 1); - y = dictionary_lookup(past->states, "y"); + y = dict_lookup(past->states, "y"); dy = state_value(y, frame) - state_value(y, frame - 1); frame--; } @@ -1138,7 +1145,7 @@ float history_rotateValue(history_t* past, U16 frame) int history_changeFilter(history_t* past, U16 frame) { - filterState_t* first = dictionary_lookup(past->states, "filter"); + filterState_t* first = dict_lookup(past->states, "filter"); if (first) //should always be true. return filterState_differs(first, frame); syntaxerror("no history found to predict changes for parameter filter.\n"); @@ -1147,7 +1154,7 @@ int history_changeFilter(history_t* past, U16 frame) FILTERLIST* history_filterValue(history_t* past, U16 frame) { - filterState_t* first = dictionary_lookup(past->states, "filter"); + filterState_t* first = dict_lookup(past->states, "filter"); if (first) //should always be true. return filterState_value(first, frame); syntaxerror("no history found to get a value for parameter filter.\n");