From: Mikko Rasa Date: Sat, 8 Jun 2019 06:17:51 +0000 (+0300) Subject: Refactor KeyFrame ownership management in Animation X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=29ee3d841a610d24ccfa3e16e492e278f81f64bd;p=libs%2Fgl.git Refactor KeyFrame ownership management in Animation The public add_keyframe functions no longer provide a convenient single place to set the RefPtr keep flag, so move it into the private function. --- diff --git a/source/animation.cpp b/source/animation.cpp index c58a33d8..900542dd 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -46,9 +46,7 @@ const string &Animation::get_uniform_name(unsigned i) const void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame &kf) { - RefPtr kfr(&kf); - kfr.keep(); - add_keyframe(t, kfr, false); + add_keyframe(t, &kf, false, false); create_curves(); } @@ -67,12 +65,10 @@ void Animation::add_control_keyframe(const KeyFrame &kf) if(keyframes.empty()) throw invalid_operation("Animation::add_control_keyframe"); - RefPtr kfr(&kf); - kfr.keep(); - add_keyframe(keyframes.back().time, kfr, true); + add_keyframe(keyframes.back().time, &kf, true, false); } -void Animation::add_keyframe(const Time::TimeDelta &t, const RefPtr &kf, bool c) +void Animation::add_keyframe(const Time::TimeDelta &t, const KeyFrame *kf, bool c, bool owned) { if(c && keyframes.empty()) throw invalid_argument("Animation::add_keyframe"); @@ -97,6 +93,8 @@ void Animation::add_keyframe(const Time::TimeDelta &t, const RefPtr(n), c); + obj.add_keyframe(current_time, &get_collection().get(n), c, false); } void Animation::Loader::load_kf_inline(bool c) @@ -403,7 +401,8 @@ void Animation::Loader::load_kf_inline(bool c) else load_sub(*kf); - obj.add_keyframe(current_time, kf, c); + obj.add_keyframe(current_time, *kf, c, true); + kf.release(); } void Animation::Loader::control_keyframe(const string &n) diff --git a/source/animation.h b/source/animation.h index 43cfc289..7b86eca9 100644 --- a/source/animation.h +++ b/source/animation.h @@ -168,7 +168,7 @@ public: void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float); void add_control_keyframe(const KeyFrame &); private: - void add_keyframe(const Time::TimeDelta &, const RefPtr &, bool); + void add_keyframe(const Time::TimeDelta &, const KeyFrame *, bool, bool); void prepare_keyframe(TimedKeyFrame &); void create_curves(); template