[Bf-blender-cvs] [1e6e44f] alembic: New 'fromtype' variable in Key to allow handling type-dependent pointer size and stride.
Lukas Tönne
noreply at git.blender.org
Mon May 4 13:05:44 CEST 2015
Commit: 1e6e44fd24995279b26d3e670c9d13fd340a5d86
Author: Lukas Tönne
Date: Mon May 4 12:59:34 2015 +0200
Branches: alembic
https://developer.blender.org/rB1e6e44fd24995279b26d3e670c9d13fd340a5d86
New 'fromtype' variable in Key to allow handling type-dependent pointer
size and stride.
This is terribly messy due to the legacy code. At some point should be
cleaned up to get rid of the 'from' backpointer and simplify.
===================================================================
M source/blender/blenkernel/BKE_key.h
M source/blender/blenkernel/intern/cache_library.c
M source/blender/blenkernel/intern/key.c
M source/blender/makesdna/DNA_key_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 724e446..fdda4c1 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -48,15 +48,10 @@ struct WeightsArrayCache;
extern "C" {
#endif
-/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
-#define IPO_FLOAT 4
-#define IPO_BEZTRIPLE 100
-#define IPO_BPOINT 101
-
void BKE_key_free(struct Key *sc);
void BKE_key_free_nolib(struct Key *key);
struct Key *BKE_key_add(struct ID *id);
-struct Key *BKE_key_add_ex(struct ID *from, char elemtype, char numelem, int elemsize);
+struct Key *BKE_key_add_ex(struct ID *from, short fromtype);
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);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index cbb3cbf..8876e3d 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1223,7 +1223,7 @@ static void strandskey_init(StrandsKeyCacheModifier *skmd)
skmd->object = NULL;
skmd->hair_system = -1;
- skmd->key = BKE_key_add_ex(NULL, IPO_FLOAT, 3, 12);
+ skmd->key = BKE_key_add_ex(NULL, KEY_FROMTYPE_STRANDS);
}
static void strandskey_copy(StrandsKeyCacheModifier *skmd, StrandsKeyCacheModifier *tskmd)
@@ -1273,7 +1273,7 @@ KeyBlock *BKE_cache_modifier_strands_key_insert_key(StrandsKeyCacheModifier *skm
bool newkey = 0;
if (key == NULL) {
- key = skmd->key = BKE_key_add_ex(NULL, IPO_FLOAT, 3, 12);
+ key = skmd->key = BKE_key_add_ex(NULL, KEY_FROMTYPE_STRANDS);
key->type = KEY_RELATIVE;
newkey = true;
}
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index c7ebdc2..4a88e9e 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -66,6 +66,11 @@
#include "RNA_access.h"
+/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
+#define IPO_FLOAT 4
+#define IPO_BEZTRIPLE 100
+#define IPO_BPOINT 101
+
#define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */
#define KEY_MODE_BPOINT 1
#define KEY_MODE_BEZTRIPLE 2
@@ -94,57 +99,68 @@ void BKE_key_free_nolib(Key *key)
}
}
-Key *BKE_key_add_ex(ID *from, char elemtype, char numelem, int elemsize) /* common function */
+static void key_set_elemstr(ID *id, short fromtype, char *r_elemstr, int *r_elemsize)
+{
+ /* XXX the code here uses some defines which will soon be deprecated... */
+ char elemtype = IPO_FLOAT;
+ char numelem = 0;
+ int elemsize = 0;
+
+ switch (fromtype) {
+ case KEY_FROMTYPE_ID:
+ if (id) {
+ switch (GS(id->name)) {
+ case ID_ME:
+ numelem = 3;
+ elemtype = IPO_FLOAT;
+ elemsize = 12;
+ break;
+ case ID_LT:
+ numelem = 3;
+ elemtype = IPO_FLOAT;
+ elemsize = 12;
+ break;
+ case ID_CU:
+ numelem = 4;
+ elemtype = IPO_BPOINT;
+ elemsize = 16;
+ break;
+ }
+ }
+ break;
+ case KEY_FROMTYPE_STRANDS:
+ numelem = 3;
+ elemtype = IPO_FLOAT;
+ elemsize = 12;
+ break;
+ }
+
+ r_elemstr[0] = numelem;
+ r_elemstr[1] = elemtype;
+ r_elemstr[2] = 0;
+ *r_elemsize = elemsize;
+}
+
+Key *BKE_key_add_ex(ID *from, short fromtype) /* common function */
{
Key *key;
- char *el;
key = BKE_libblock_alloc(G.main, ID_KE, "Key");
key->type = KEY_NORMAL;
key->from = from;
+ key->fromtype = fromtype;
key->uidgen = 1;
- el = key->elemstr;
-
- el[0] = numelem;
- el[1] = elemtype;
- el[2] = 0;
-
- key->elemsize = elemsize;
+ key_set_elemstr(from, fromtype, key->elemstr, &key->elemsize);
return key;
}
Key *BKE_key_add(ID *id)
{
- /* XXX the code here uses some defines which will soon be deprecated... */
- char elemtype = IPO_FLOAT;
- char numelem = 0;
- int elemsize = 0;
-
- if (id) {
- switch (GS(id->name)) {
- case ID_ME:
- numelem = 3;
- elemtype = IPO_FLOAT;
- elemsize = 12;
- break;
- case ID_LT:
- numelem = 3;
- elemtype = IPO_FLOAT;
- elemsize = 12;
- break;
- case ID_CU:
- numelem = 4;
- elemtype = IPO_BPOINT;
- elemsize = 16;
- break;
- }
- }
-
- return BKE_key_add_ex(id, elemtype, numelem, elemsize);
+ return BKE_key_add_ex(id, KEY_FROMTYPE_ID);
}
Key *BKE_key_copy(Key *key)
@@ -547,35 +563,42 @@ static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **
/* currently only the first value of 'ofs' may be set. */
static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs)
{
- if (key->from == NULL) {
- return false;
- }
-
- switch (GS(key->from->name)) {
- case ID_ME:
- *ofs = sizeof(float) * 3;
- *poinsize = *ofs;
+ switch (key->fromtype) {
+ case KEY_FROMTYPE_ID:
+ if (!key->from)
+ return false;
+
+ switch (GS(key->from->name)) {
+ case ID_ME:
+ *ofs = sizeof(float) * 3;
+ *poinsize = *ofs;
+ break;
+ case ID_LT:
+ *ofs = sizeof(float) * 3;
+ *poinsize = *ofs;
+ break;
+ case ID_CU:
+ if (mode == KEY_MODE_BPOINT) {
+ *ofs = sizeof(float) * 4;
+ *poinsize = *ofs;
+ }
+ else {
+ ofs[0] = sizeof(float) * 12;
+ *poinsize = (*ofs) / 3;
+ }
+
+ break;
+ default:
+ BLI_assert(!"invalid 'key->from' ID type");
+ return false;
+ }
break;
- case ID_LT:
+
+ case KEY_FROMTYPE_STRANDS:
*ofs = sizeof(float) * 3;
*poinsize = *ofs;
break;
- case ID_CU:
- if (mode == KEY_MODE_BPOINT) {
- *ofs = sizeof(float) * 4;
- *poinsize = *ofs;
- }
- else {
- ofs[0] = sizeof(float) * 12;
- *poinsize = (*ofs) / 3;
- }
-
- break;
- default:
- BLI_assert(!"invalid 'key->from' ID type");
- return false;
}
-
return true;
}
diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h
index 60ab01c..f1ed7da 100644
--- a/source/blender/makesdna/DNA_key_types.h
+++ b/source/blender/makesdna/DNA_key_types.h
@@ -84,7 +84,8 @@ typedef struct Key {
* (each one char) used for calculating shape key-blocks */
char elemstr[32];
int elemsize; /* size of each element in #KeyBlock.data, use for allocation and stride */
- int pad;
+ short fromtype;
+ short pad;
ListBase block; /* list of KeyBlock's */
struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */
@@ -104,6 +105,16 @@ typedef struct Key {
int uidgen; /* current free uid for keyblocks */
} Key;
+/* Key->fromtype
+ * XXX terrible mess, legacy code is redundant in several places, lets just add to the confusion ...
+ * Internally the code uses legacy IPO_* defines combined with the Key->from ID and a mode for curves.
+ * This enum allows using Key without a 'from' ID block and without knowing the legacy IPO enum.
+ */
+enum {
+ KEY_FROMTYPE_ID = 0,
+ KEY_FROMTYPE_STRANDS = 1,
+};
+
/* **************** KEY ********************* */
/* Key->type: KeyBlocks are interpreted as... */
More information about the Bf-blender-cvs
mailing list