From 125ce644f28dccea67ad5bdada0013eba8caafbe Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Tue, 4 Apr 2017 15:39:38 -0400 Subject: cleanup I started cleaning up UI_view2d_scale_get where the y scale was unused, then got carried away... - for loop scope - declare variables closer to where they are used - move early exits closer to function start - unsigned --> unsigned int --- source/blender/editors/space_graph/graph_draw.c | 104 ++++++++++-------------- 1 file changed, 42 insertions(+), 62 deletions(-) (limited to 'source/blender/editors/space_graph/graph_draw.c') diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index e382c2dbd29..d9104007586 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -462,28 +462,21 @@ static void draw_fcurve_samples(SpaceIpo *sipo, ARegion *ar, FCurve *fcu) /* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid, unsigned int pos) { - SpaceIpo *sipo = (SpaceIpo *)ac->sl; - ChannelDriver *driver; - float samplefreq; - float stime, etime; - float unitFac, offset; - float dx, dy; - short mapping_flag = ANIM_get_normalization_flags(ac); - int i, n; - /* when opening a blend file on a different sized screen or while dragging the toolbar this can happen * best just bail out in this case */ + float dx, dy; UI_view2d_grid_size(grid, &dx, &dy); if (dx <= 0.0f) return; - /* disable any drivers temporarily */ - driver = fcu->driver; + ChannelDriver *driver = fcu->driver; fcu->driver = NULL; /* compute unit correction factor */ - unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); + float offset; + const short mapping_flag = ANIM_get_normalization_flags(ac); + const float unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); /* Note about sampling frequency: * Ideally, this is chosen such that we have 1-2 pixels = 1 segment @@ -499,8 +492,9 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d */ /* grid->dx represents the number of 'frames' between gridlines, but we divide by U.v2d_min_gridsize to get pixels-steps */ /* TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted? */ - samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize); + float samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize); + SpaceIpo *sipo = (SpaceIpo *)ac->sl; if (sipo->flag & SIPO_BEAUTYDRAW_OFF) { /* Low Precision = coarse lower-bound clamping * @@ -522,8 +516,8 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d /* the start/end times are simply the horizontal extents of the 'cur' rect */ - stime = v2d->cur.xmin; - etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */ + const float stime = v2d->cur.xmin; + const float etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */ /* at each sampling interval, add a new vertex @@ -531,12 +525,12 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d * the displayed values appear correctly in the viewport */ - n = (etime - stime) / samplefreq + 0.5f; + const int n = (etime - stime) / samplefreq + 0.5f; if (n > 0) { immBegin(PRIM_LINE_STRIP, (n + 1)); - for (i = 0; i <= n; i++) { + for (int i = 0; i <= n; i++) { float ctime = stime + i * samplefreq; immVertex2f(pos, ctime, (evaluate_fcurve(fcu, ctime) + offset) * unitFac); } @@ -554,22 +548,22 @@ static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, Vie FPoint *prevfpt = fcu->fpt; FPoint *fpt = prevfpt + 1; float fac, v[2]; - int b = fcu->totvert; - float unit_scale, offset; - short mapping_flag = ANIM_get_normalization_flags(ac); int count = fcu->totvert; if (prevfpt->vec[0] > v2d->cur.xmin) { count++; } + int b = fcu->totvert; if ((prevfpt + b - 1)->vec[0] < v2d->cur.xmax) { count++; } /* apply unit mapping */ + float offset; + const short mapping_flag = ANIM_get_normalization_flags(ac); + const float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); gpuPushMatrix(); - unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); gpuScale2f(1.0f, unit_scale); gpuTranslate2f(0.0f, offset); @@ -654,22 +648,20 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2 BezTriple *prevbezt = fcu->bezt; BezTriple *bezt = prevbezt + 1; float v1[2], v2[2], v3[2], v4[2]; - float *fp, data[120]; float fac = 0.0f; - int b = fcu->totvert - 1; - int resol; - float unit_scale, offset; - short mapping_flag = ANIM_get_normalization_flags(ac); /* apply unit mapping */ + float offset; + const short mapping_flag = ANIM_get_normalization_flags(ac); + const float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); gpuPushMatrix(); - unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); gpuScale2f(1.0f, unit_scale); gpuTranslate2f(0.0f, offset); /* For now, this assumes the worst case scenario, where all the keyframes have * bezier interpolation, and are drawn at full res. * This is tricky to optimize, but maybe can be improved at some point... */ + int b = fcu->totvert - 1; immBeginAtMost(PRIM_LINE_STRIP, (b * 32 + 3)); /* extrapolate to left? */ @@ -725,10 +717,8 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2 immVertex2fv(pos, v1); } else if (prevbezt->ipo == BEZT_IPO_BEZ) { - /* Bezier-Interpolation: draw curve as series of segments between keyframes - * - resol determines number of points to sample in between keyframes - */ - + /* Bezier-Interpolation: draw curve as series of segments between keyframes */ + int resol; /* determines number of points to sample in between keyframes */ /* resol depends on distance between points (not just horizontal) OR is a fixed high res */ /* TODO: view scale should factor into this someday too... */ if (fcu->driver) { @@ -760,11 +750,13 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2 v4[1] = bezt->vec[1][1]; correct_bezpart(v1, v2, v3, v4); - + + float data[120]; + BKE_curve_forward_diff_bezier(v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float) * 3); BKE_curve_forward_diff_bezier(v1[1], v2[1], v3[1], v4[1], data + 1, resol, sizeof(float) * 3); - for (fp = data; resol; resol--, fp += 3) { + for (const float *fp = data; resol; resol--, fp += 3) { immVertex2fv(pos, fp); } } @@ -824,9 +816,9 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu) { ChannelDriver *driver = fcu->driver; View2D *v2d = &ac->ar->v2d; - short mapping_flag = ANIM_get_normalization_flags(ac); + const short mapping_flag = ANIM_get_normalization_flags(ac); float offset; - float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); + const float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset); /* for now, only show when debugging driver... */ //if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0) @@ -839,8 +831,6 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu) * => We still want to show the 1-1 default... */ if ((fcu->totvert == 0) && BLI_listbase_is_empty(&fcu->modifiers)) { - float t; - /* draw with thin dotted lines in style of what curve would have been */ immUniformColor3fv(fcu->color); @@ -852,7 +842,7 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu) */ immBegin(PRIM_LINES, 2); - t = v2d->cur.xmin; + float t = v2d->cur.xmin; immVertex2f(pos, t, (t + offset) * unitfac); t = v2d->cur.xmax; @@ -933,8 +923,6 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu) */ void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar) { - FCurve *fcu; - /* draw with thick dotted lines */ setlinestyle(10); glLineWidth(3.0f); @@ -947,7 +935,7 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar) immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* the ghost curves are simply sampled F-Curves stored in sipo->ghostCurves */ - for (fcu = sipo->ghostCurves.first; fcu; fcu = fcu->next) { + for (FCurve *fcu = sipo->ghostCurves.first; fcu; fcu = fcu->next) { /* set whatever color the curve has set * - this is set by the function which creates these * - draw with a fixed opacity of 2 @@ -972,20 +960,16 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar) */ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid, short sel) { - ListBase anim_data = {NULL, NULL}; - bAnimListElem *ale; - int filter; - /* build list of curves to draw */ - filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE); - filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL)); + ListBase anim_data = {NULL, NULL}; + const int filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | (sel ? ANIMFILTER_SEL : ANIMFILTER_UNSEL); ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); - + /* for each curve: * draw curve, then handle-lines, and finally vertices in this order so that * the data will be layered correctly */ - for (ale = anim_data.first; ale; ale = ale->next) { + for (bAnimListElem *ale = anim_data.first; ale; ale = ale->next) { FCurve *fcu = (FCurve *)ale->key_data; FModifier *fcm = find_active_fmodifier(&fcu->modifiers); AnimData *adt = ANIM_nla_mapping_get(ac, ale); @@ -1138,18 +1122,12 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid /* left hand part */ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) { - ListBase anim_data = {NULL, NULL}; - bAnimListElem *ale; - int filter; - View2D *v2d = &ar->v2d; - float y = 0.0f, height; - size_t items; - int i = 0; - + /* build list of channels to draw */ - filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS); - items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); + ListBase anim_data = {NULL, NULL}; + const int filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS; + const size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); /* Update max-extent of channels here (taking into account scrollers): * - this is done to allow the channel list to be scrollable, but must be done here @@ -1157,14 +1135,16 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) * - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for * start of list offset, and the second is as a correction for the scrollers. */ - height = (float)((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac) * 2)); + const float height = (float)((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac) * 2)); UI_view2d_totRect_set(v2d, BLI_rcti_size_x(&ar->v2d.mask), height); /* loop through channels, and set up drawing depending on their type */ + bAnimListElem *ale; + int i; { /* first pass: just the standard GL-drawing for backdrop + text */ size_t channel_index = 0; - y = (float)ACHANNEL_FIRST(ac); + float y = (float)ACHANNEL_FIRST(ac); for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) { const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac)); @@ -1187,7 +1167,7 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar) uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS); size_t channel_index = 0; - y = (float)ACHANNEL_FIRST(ac); + float y = (float)ACHANNEL_FIRST(ac); /* set blending again, as may not be set in previous step */ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -- cgit v1.2.3