Cleanup to shapekeys' make_local (and copy) functions.

Mostly pass bmain and do not check for NULL key, keys' make_local is
suspiciously simple in fact, but think until those behave like real
full-featured IDs, it's doing enough!
This commit is contained in:
Bastien Montagne
2016-07-09 14:44:48 +02:00
parent 8bb7a339f7
commit 9044ccec5f
7 changed files with 42 additions and 30 deletions

View File

@@ -39,6 +39,7 @@ struct ListBase;
struct Curve;
struct Object;
struct Lattice;
struct Main;
struct Mesh;
struct WeightsArrayCache;
@@ -52,7 +53,7 @@ void BKE_key_free_nolib(struct Key *key);
struct Key *BKE_key_add(struct ID *id);
struct Key *BKE_key_copy(struct Key *key);
struct Key *BKE_key_copy_nolib(struct Key *key);
void BKE_key_make_local(struct Key *key);
void BKE_key_make_local(struct Main *bmain, struct Key *key);
void BKE_key_sort(struct Key *key);
void key_curve_position_weights(float t, float data[4], int type);

View File

@@ -191,8 +191,10 @@ Curve *BKE_curve_copy(Curve *cu)
cun->tb = MEM_dupallocN(cu->tb);
cun->bb = MEM_dupallocN(cu->bb);
cun->key = BKE_key_copy(cu->key);
if (cun->key) cun->key->from = (ID *)cun;
if (cu->key) {
cun->key = BKE_key_copy(cu->key);
cun->key->from = (ID *)cun;
}
cun->editnurb = NULL;
cun->editfont = NULL;
@@ -242,7 +244,9 @@ void BKE_curve_make_local(Curve *cu)
if (cu->id.us == 1) {
id_clear_lib_data(bmain, &cu->id);
BKE_key_make_local(cu->key);
if (cu->key) {
BKE_key_make_local(bmain, cu->key);
}
extern_local_curve(cu);
return;
}
@@ -256,7 +260,9 @@ void BKE_curve_make_local(Curve *cu)
if (is_local && is_lib == false) {
id_clear_lib_data(bmain, &cu->id);
BKE_key_make_local(cu->key);
if (cu->key) {
BKE_key_make_local(bamin, cu->key);
}
extern_local_curve(cu);
}
else if (is_local && is_lib) {

View File

@@ -58,6 +58,7 @@
#include "BKE_key.h"
#include "BKE_lattice.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_editmesh.h"
#include "BKE_scene.h"
@@ -154,8 +155,6 @@ Key *BKE_key_copy(Key *key)
Key *keyn;
KeyBlock *kbn, *kb;
if (key == NULL) return NULL;
keyn = BKE_libblock_copy(&key->id);
BLI_duplicatelist(&keyn->block, &key->block);
@@ -184,9 +183,6 @@ Key *BKE_key_copy_nolib(Key *key)
Key *keyn;
KeyBlock *kbn, *kb;
if (key == NULL)
return NULL;
keyn = MEM_dupallocN(key);
keyn->adt = NULL;
@@ -207,17 +203,16 @@ Key *BKE_key_copy_nolib(Key *key)
return keyn;
}
void BKE_key_make_local(Key *key)
void BKE_key_make_local(Main *bmain, Key *key)
{
/* Note that here for now we simply just make it local...
* Sounds fishy behavior, but since skeys are not *real* IDs... */
/* - only lib users: do nothing
* - only local users: set flag
* - mixed: make copy
*/
if (key == NULL) return;
key->id.lib = NULL;
new_id(NULL, &key->id, NULL);
if (!ID_IS_LINKED_DATABLOCK(key)) {
return;
}
id_clear_lib_data(bmain, &key->id);
}
/* Sort shape keys and Ipo curves after a change. This assumes that at most

View File

@@ -282,8 +282,10 @@ Lattice *BKE_lattice_copy(Lattice *lt)
ltn = BKE_libblock_copy(&lt->id);
ltn->def = MEM_dupallocN(lt->def);
ltn->key = BKE_key_copy(ltn->key);
if (ltn->key) ltn->key->from = (ID *)ltn;
if (lt->key) {
ltn->key = BKE_key_copy(ltn->key);
ltn->key->from = (ID *)ltn;
}
if (lt->dvert) {
int tot = lt->pntsu * lt->pntsv * lt->pntsw;
@@ -339,7 +341,9 @@ void BKE_lattice_make_local(Lattice *lt)
if (!ID_IS_LINKED_DATABLOCK(lt)) return;
if (lt->id.us == 1) {
id_clear_lib_data(bmain, &lt->id);
BKE_key_make_local(lt->key);
if (lt->key) {
BKE_key_make_local(bmain, lt->key);
}
return;
}
@@ -352,7 +356,9 @@ void BKE_lattice_make_local(Lattice *lt)
if (is_local && is_lib == false) {
id_clear_lib_data(bmain, &lt->id);
BKE_key_make_local(lt->key);
if (lt->key) {
BKE_key_make_local(bmain, lt->key);
}
}
else if (is_local && is_lib) {
Lattice *lt_new = BKE_lattice_copy(lt);

View File

@@ -299,7 +299,7 @@ bool id_make_local(Main *bmain, ID *id, bool test)
case ID_IP:
return false; /* deprecated */
case ID_KE:
if (!test) BKE_key_make_local((Key *)id);
if (!test) BKE_key_make_local(bmain, (Key *)id);
return true;
case ID_WO:
if (!test) BKE_world_make_local((World *)id);

View File

@@ -548,8 +548,10 @@ Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me)
men->mselect = MEM_dupallocN(men->mselect);
men->bb = MEM_dupallocN(men->bb);
men->key = BKE_key_copy(me->key);
if (men->key) men->key->from = (ID *)men;
if (me->key) {
men->key = BKE_key_copy(me->key);
men->key->from = (ID *)men;
}
if (ID_IS_LINKED_DATABLOCK(me)) {
BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);
@@ -642,7 +644,9 @@ void BKE_mesh_make_local(Main *bmain, Mesh *me)
if (is_local) {
if (!is_lib) {
id_clear_lib_data(bmain, &me->id);
BKE_key_make_local(me->key);
if (me->key) {
BKE_key_make_local(bmain, me->key);
}
expand_local_mesh(me);
}
else {

View File

@@ -75,7 +75,7 @@ BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
m_useShapeDrivers(false),
m_lastShapeUpdate(-1)
{
m_key = BKE_key_copy(m_bmesh->key);
m_key = m_bmesh->key ? BKE_key_copy(m_bmesh->key) : NULL;
};
/* this second constructor is needed for making a mesh deformable on the fly. */
@@ -91,7 +91,7 @@ BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
m_useShapeDrivers(false),
m_lastShapeUpdate(-1)
{
m_key = BKE_key_copy(m_bmesh->key);
m_key = m_bmesh->key ? BKE_key_copy(m_bmesh->key) : NULL;
};
BL_ShapeDeformer::~BL_ShapeDeformer()
@@ -117,7 +117,7 @@ void BL_ShapeDeformer::ProcessReplica()
BL_SkinDeformer::ProcessReplica();
m_lastShapeUpdate = -1;
m_key = BKE_key_copy(m_key);
m_key = m_key ? BKE_key_copy(m_key) : NULL;
}
bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject* parent)