lottie: code refactoring++

Unified the property expression and default version.
This also helps to reduce the binarys size (O3=4k, S=360kb)
This commit is contained in:
Hermet Park 2025-01-29 18:05:08 +09:00 committed by Hermet Park
parent 2b97cf7a0d
commit f8da536d1a
2 changed files with 22 additions and 25 deletions

View file

@ -980,7 +980,7 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
{
auto text = static_cast<LottieText*>(layer->children.first());
auto textGrouping = text->alignOption.grouping;
auto& doc = text->doc(frameNo);
auto& doc = text->doc(frameNo, exps);
auto p = doc.text;
if (!p || !text->font) return;

View file

@ -325,8 +325,15 @@ struct LottieGenericProperty : LottieProperty
return (*frames)[frames->count];
}
Value operator()(float frameNo)
Value operator()(float frameNo, LottieExpressions* exps = nullptr)
{
//overriding with expressions
if (exps && exp) {
Value out{};
frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottieGenericProperty<Frame, Value>>(frameNo, out, exp)) return out;
}
if (!frames) return value;
if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value;
if (frameNo >= frames->last().no) return frames->last().value;
@ -336,16 +343,6 @@ struct LottieGenericProperty : LottieProperty
return frame->interpolate(frame + 1, frameNo);
}
Value operator()(float frameNo, LottieExpressions* exps)
{
if (exps && exp) {
Value out{};
frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottieGenericProperty<Frame, Value>>(frameNo, out, exp)) return out;
}
return operator()(frameNo);
}
void copy(const LottieGenericProperty<Frame, Value, Scalar>& rhs, bool shallow = true)
{
if (rhs.frames) {
@ -448,8 +445,14 @@ struct LottiePathSet : LottieProperty
return (*frames)[frames->count];
}
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset)
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, LottieExpressions* exps = nullptr)
{
//overriding with expressions
if (exps && exp) {
frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, offset, exp)) return true;
}
PathSet* path = nullptr;
LottieScalarFrame<PathSet>* frame = nullptr;
float t;
@ -523,16 +526,6 @@ struct LottiePathSet : LottieProperty
return true;
}
bool operator()(float frameNo, Array<PathCommand>& cmds, Array<Point>& pts, Matrix* transform, const LottieRoundnessModifier* roundness, const LottieOffsetModifier* offset, LottieExpressions* exps)
{
if (exps && exp) {
frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottiePathSet>(frameNo, cmds, pts, transform, roundness, offset, exp)) return true;
}
return operator()(frameNo, cmds, pts, transform, roundness, offset);
}
void prepare() {}
};
@ -613,8 +606,9 @@ struct LottieColorStop : LottieProperty
return (*frames)[frames->count];
}
Result operator()(float frameNo, Fill* fill, LottieExpressions* exps)
Result operator()(float frameNo, Fill* fill, LottieExpressions* exps = nullptr)
{
//overriding with expressions
if (exps && exp) {
frameNo = _loop(frames, frameNo, exp);
if (exps->result<LottieColorStop>(frameNo, fill, exp)) return Result::Success;
@ -754,8 +748,11 @@ struct LottieTextDoc : LottieProperty
return (*frames)[frames->count];
}
TextDocument& operator()(float frameNo)
TextDocument& operator()(float frameNo, LottieExpressions* exps = nullptr)
{
//overriding with expressions
if (exps && exp) TVGERR("LOTTIE", "Not support TextDocument expressions?");
if (!frames) return value;
if (frames->count == 1 || frameNo <= frames->first().no) return frames->first().value;
if (frameNo >= frames->last().no) return frames->last().value;