Cleanup: avoid returning large structs from functions
Return BezTriple as a const pointer from utility functions instead of by a value since it's a large struct.
This commit is contained in:
parent
cc5fefffe6
commit
6a7ecec6e1
|
@ -282,15 +282,15 @@ ListBase find_fcurve_segments(FCurve *fcu)
|
|||
return segments;
|
||||
}
|
||||
|
||||
static BezTriple fcurve_segment_start_get(FCurve *fcu, int index)
|
||||
static const BezTriple *fcurve_segment_start_get(FCurve *fcu, int index)
|
||||
{
|
||||
BezTriple start_bezt = index - 1 >= 0 ? fcu->bezt[index - 1] : fcu->bezt[index];
|
||||
const BezTriple *start_bezt = index - 1 >= 0 ? &fcu->bezt[index - 1] : &fcu->bezt[index];
|
||||
return start_bezt;
|
||||
}
|
||||
|
||||
static BezTriple fcurve_segment_end_get(FCurve *fcu, int index)
|
||||
static const BezTriple *fcurve_segment_end_get(FCurve *fcu, int index)
|
||||
{
|
||||
BezTriple end_bezt = index < fcu->totvert ? fcu->bezt[index] : fcu->bezt[index - 1];
|
||||
const BezTriple *end_bezt = index < fcu->totvert ? &fcu->bezt[index] : &fcu->bezt[index - 1];
|
||||
return end_bezt;
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ static BezTriple fcurve_segment_end_get(FCurve *fcu, int index)
|
|||
void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
|
||||
{
|
||||
const float blend_factor = fabs(factor * 2 - 1);
|
||||
BezTriple target_bezt;
|
||||
const BezTriple *target_bezt;
|
||||
/* Find which key to blend towards. */
|
||||
if (factor < 0.5f) {
|
||||
target_bezt = fcurve_segment_start_get(fcu, segment->start_index);
|
||||
|
@ -309,7 +309,7 @@ void blend_to_neighbor_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const
|
|||
}
|
||||
/* Blend each key individually. */
|
||||
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
|
||||
fcu->bezt[i].vec[1][1] = interpf(target_bezt.vec[1][1], fcu->bezt[i].vec[1][1], blend_factor);
|
||||
fcu->bezt[i].vec[1][1] = interpf(target_bezt->vec[1][1], fcu->bezt[i].vec[1][1], blend_factor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,14 +379,14 @@ void blend_to_default_fcurve(PointerRNA *id_ptr, FCurve *fcu, const float factor
|
|||
|
||||
void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
|
||||
{
|
||||
const BezTriple left_key = fcurve_segment_start_get(fcu, segment->start_index);
|
||||
const float left_x = left_key.vec[1][0];
|
||||
const float left_y = left_key.vec[1][1];
|
||||
const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index);
|
||||
const float left_x = left_key->vec[1][0];
|
||||
const float left_y = left_key->vec[1][1];
|
||||
|
||||
const BezTriple right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
|
||||
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
|
||||
|
||||
const float key_x_range = right_key.vec[1][0] - left_x;
|
||||
const float key_y_range = right_key.vec[1][1] - left_y;
|
||||
const float key_x_range = right_key->vec[1][0] - left_x;
|
||||
const float key_y_range = right_key->vec[1][1] - left_y;
|
||||
|
||||
/* Happens if there is only 1 key on the FCurve. Needs to be skipped because it
|
||||
* would be a divide by 0. */
|
||||
|
@ -419,11 +419,12 @@ void ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor
|
|||
|
||||
void breakdown_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
|
||||
{
|
||||
BezTriple left_bezt = fcurve_segment_start_get(fcu, segment->start_index);
|
||||
BezTriple right_bezt = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
|
||||
const BezTriple *left_bezt = fcurve_segment_start_get(fcu, segment->start_index);
|
||||
const BezTriple *right_bezt = fcurve_segment_end_get(fcu,
|
||||
segment->start_index + segment->length);
|
||||
|
||||
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
|
||||
fcu->bezt[i].vec[1][1] = interpf(right_bezt.vec[1][1], left_bezt.vec[1][1], factor);
|
||||
fcu->bezt[i].vec[1][1] = interpf(right_bezt->vec[1][1], left_bezt->vec[1][1], factor);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue