[Bf-blender-cvs] [6e7fbcfbd1a] collada: Refactor Collada: Make BCAnimation class more self contained
Gaia Clary
noreply at git.blender.org
Thu Apr 19 22:24:33 CEST 2018
Commit: 6e7fbcfbd1a7248ac2232ec59ab775efe4806657
Author: Gaia Clary
Date: Thu Apr 19 22:14:02 2018 +0200
Branches: collada
https://developer.blender.org/rB6e7fbcfbd1a7248ac2232ec59ab775efe4806657
Refactor Collada: Make BCAnimation class more self contained
Follwing funtionality was previously located in
BCAnimationSampler, but makes not much sense there:
* Moved the creation of the reference object into the Class constructor
* Moved the destruction of the reference to the Destructor
Furthermore:
* added get_reference() to better shield the rerference object from
unintentional access
* BCAnimationObjectMap now contains Pointers to BCAnimation objects
instead of containing full object instances. This avoids unnecessary
copying of the Animation datastructures when adding BCAnimation objects
to the BCAnimationObjectMap. Note: This forces us to delete the BCAnimation
objects in the BCAnimationSampler destructor.
===================================================================
M source/blender/collada/BCAnimationSampler.cpp
M source/blender/collada/BCAnimationSampler.h
===================================================================
diff --git a/source/blender/collada/BCAnimationSampler.cpp b/source/blender/collada/BCAnimationSampler.cpp
index c082c3b8471..e97ec391c24 100644
--- a/source/blender/collada/BCAnimationSampler.cpp
+++ b/source/blender/collada/BCAnimationSampler.cpp
@@ -64,27 +64,23 @@ BCAnimationSampler::~BCAnimationSampler()
BCAnimationObjectMap::iterator it;
Main *bmain = bc_get_main();
for (it = objects.begin(); it != objects.end(); ++it) {
- BCAnimation &animation = it->second;
- if (animation.reference)
- {
- BKE_libblock_delete(bmain, &animation.reference->id); // is this the correct way to remove a temporary object ?
- }
+ BCAnimation *animation = it->second;
+ delete animation;
}
}
void BCAnimationSampler::add_object(Object *ob)
{
- BCAnimation &animation = objects[ob];
- Main *bmain = bc_get_main();
- animation.reference = BKE_object_copy(bmain, ob); // must be removed in deconstructor (see above)
+ BCAnimation *animation = new BCAnimation(ob);
+ objects[ob] = animation;
- initialize_keyframes(animation.frame_set, ob);
- initialize_curves(animation.curve_map, ob);
+ initialize_keyframes(animation->frame_set, ob);
+ initialize_curves(animation->curve_map, ob);
}
BCAnimationCurveMap *BCAnimationSampler::get_curves(Object *ob)
{
- BCAnimation &animation = objects[ob];
+ BCAnimation &animation = *objects[ob];
if (animation.curve_map.size() == 0)
initialize_curves(animation.curve_map, ob);
return &animation.curve_map;
@@ -137,7 +133,7 @@ void BCAnimationSampler::check_property_is_animated(BCAnimation &animation, floa
BCCurveKey key(BC_ANIMATION_TYPE_OBJECT, data_path, array_index);
BCAnimationCurveMap::iterator it = animation.curve_map.find(key);
if (it == animation.curve_map.end()) {
- animation.curve_map[key] = new BCAnimationCurve(key, animation.reference);
+ animation.curve_map[key] = new BCAnimationCurve(key, animation.get_reference());
}
}
}
@@ -208,8 +204,8 @@ void BCAnimationSampler::sample_scene(
BCAnimationObjectMap::iterator obit;
for (obit = objects.begin(); obit != objects.end(); ++obit) {
Object *ob = obit->first;
- BCAnimation &animation = obit->second;
- BCFrameSet &object_keyframes = animation.frame_set;
+ BCAnimation *animation = obit->second;
+ BCFrameSet &object_keyframes = animation->frame_set;
if (is_scene_sample_frame || object_keyframes.find(frame_index) != object_keyframes.end()) {
if (needs_update) {
@@ -218,7 +214,7 @@ void BCAnimationSampler::sample_scene(
}
BCSample &sample = sample_object(ob, frame_index, for_opensim);
- update_animation_curves(animation, sample, ob, frame_index);
+ update_animation_curves(*animation, sample, ob, frame_index);
}
}
}
diff --git a/source/blender/collada/BCAnimationSampler.h b/source/blender/collada/BCAnimationSampler.h
index fdeee22baa4..aae383aec6a 100644
--- a/source/blender/collada/BCAnimationSampler.h
+++ b/source/blender/collada/BCAnimationSampler.h
@@ -32,16 +32,25 @@
extern "C" {
#include "BKE_action.h"
+#include "BKE_library.h"
#include "BLI_math_rotation.h"
#include "DNA_action_types.h"
}
/* Collection of animation curves */
class BCAnimation {
+private:
+ Object *reference = NULL;
+
public:
BCFrameSet frame_set;
BCAnimationCurveMap curve_map;
- Object *reference = NULL;
+
+ BCAnimation(Object *ob)
+ {
+ Main *bmain = bc_get_main();
+ reference = BKE_object_copy(bmain, ob);
+ }
~BCAnimation()
{
@@ -49,11 +58,22 @@ public:
for (it = curve_map.begin(); it != curve_map.end(); ++it) {
delete it->second;
}
+
+ if (reference)
+ {
+ Main *bmain = bc_get_main();
+ BKE_libblock_delete(bmain, &reference->id);
+ }
curve_map.clear();
}
+
+ Object *get_reference()
+ {
+ return reference;
+ }
};
-typedef std::map<Object *, BCAnimation> BCAnimationObjectMap;
+typedef std::map<Object *, BCAnimation *> BCAnimationObjectMap;
class BCSampleFrame {
More information about the Bf-blender-cvs
mailing list