diff options
-rw-r--r-- | source/blender/blenkernel/BKE_idprop.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 15 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 28 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 1 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 3 | ||||
-rw-r--r-- | source/blender/python/api2_2x/IDProp.c | 57 |
6 files changed, 88 insertions, 17 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 2d7d0e9286f..2274c54ad3b 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -46,6 +46,7 @@ struct ID; typedef union { int i; float f; + double d; char *str; struct ID *id; struct { diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 2ef2f3a1b77..b16f52571f6 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -54,7 +54,8 @@ static char idp_size_table[] = { sizeof(float)*16, /*Matrix type, deprecated*/ 0, /*arrays don't have a fixed size*/ sizeof(ListBase), /*Group type*/ - sizeof(void*) + sizeof(void*), + sizeof(double) }; @@ -365,10 +366,14 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name) prop = MEM_callocN(sizeof(IDProperty), "IDProperty float"); *(float*)&prop->data.val = val.f; break; + case IDP_DOUBLE: + prop = MEM_callocN(sizeof(IDProperty), "IDProperty float"); + *(double*)&prop->data.val = val.d; + break; case IDP_ARRAY: { - /*for now, we only support float and int arrays*/ - if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT) { + /*for now, we only support float and int and double arrays*/ + if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT || val.array.type == IDP_DOUBLE) { prop = MEM_callocN(sizeof(IDProperty), "IDProperty array"); prop->len = prop->totallen = val.array.len; prop->subtype = val.array.type; @@ -411,6 +416,10 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name) prop->type = type; strncpy(prop->name, name, MAX_IDPROP_NAME); + + /*security null byte*/ + prop->name[MAX_IDPROP_NAME-1] = 0; + return prop; } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index a93f1d91c77..ad004dd5c82 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1347,8 +1347,14 @@ void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, void *fd) prop->data.pointer = newdataadr(fd, prop->data.pointer); if (switch_endian) { - for (i=0; i<prop->len; i++) { - SWITCH_INT(((int*)prop->data.pointer)[i]); + if (prop->subtype != IDP_DOUBLE) { + for (i=0; i<prop->len; i++) { + SWITCH_INT(((int*)prop->data.pointer)[i]); + } + } else { + for (i=0; i<prop->len; i++) { + SWITCH_LONGINT(((double*)prop->data.pointer)[i]); + } } } } @@ -1385,6 +1391,24 @@ void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, void *fd) case IDP_ARRAY: IDP_DirectLinkArray(prop, switch_endian, fd); break; + case IDP_DOUBLE: + /*erg, stupid doubles. since I'm storing them + in the same field as int val; val2 in the + IDPropertyData struct, they have to deal with + endianness specifically + + in theory, val and val2 would've already been swapped + if switch_endian is true, so we have to first unswap + them then reswap them as a single 64-bit entity. + */ + + if (switch_endian) { + SWITCH_INT(prop->data.val); + SWITCH_INT(prop->data.val2); + SWITCH_LONGINT(prop->data.val); + } + + break; } } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index b59dd851dfe..73abf362d12 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -533,6 +533,7 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) if(part->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_PA, "ParticleSettings", 1, part); + if (part->id.properties) IDP_WriteProperty(part->id.properties, wd); writestruct(wd, DATA, "PartDeflect", 1, part->pd); } part= part->id.next; diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 60050ea010e..3054e038ba2 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -46,7 +46,7 @@ struct ID; typedef struct IDPropertyData { void *pointer; ListBase group; - int val, pad; + int val, val2; /*note, we actually fit a double into these two ints*/ } IDPropertyData; typedef struct IDProperty { @@ -77,6 +77,7 @@ typedef struct IDProperty { /*the ID link property type hasn't been implemented yet, this will require some cleanup of blenkernel, most likely.*/ #define IDP_ID 7 +#define IDP_DOUBLE 8 /*add any future new id property types here.*/ diff --git a/source/blender/python/api2_2x/IDProp.c b/source/blender/python/api2_2x/IDProp.c index f60ebf8dee1..4a51619aec4 100644 --- a/source/blender/python/api2_2x/IDProp.c +++ b/source/blender/python/api2_2x/IDProp.c @@ -60,6 +60,8 @@ PyObject *BPy_IDGroup_WrapData( ID *id, IDProperty *prop ) return PyInt_FromLong( (long)prop->data.val ); case IDP_FLOAT: return PyFloat_FromDouble( (double)(*(float*)(&prop->data.val)) ); + case IDP_DOUBLE: + return PyFloat_FromDouble( (*(double*)(&prop->data.val)) ); case IDP_GROUP: /*blegh*/ { @@ -128,7 +130,19 @@ int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject *value) Py_XDECREF(value); break; } - + case IDP_DOUBLE: + { + double dvalue; + if (!PyNumber_Check(value)) + return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!"); + value = PyNumber_Float(value); + if (!value) + return EXPP_ReturnIntError(PyExc_TypeError, "expected a float!"); + dvalue = (float) PyFloat_AsDouble(value); + *(double*)&self->prop->data.val = dvalue; + Py_XDECREF(value); + break; + } default: return EXPP_ReturnIntError(PyExc_AttributeError, "attempt to set read-only attribute!"); } @@ -204,8 +218,8 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje IDPropertyTemplate val = {0}; if (PyFloat_Check(ob)) { - val.f = (float) PyFloat_AsDouble(ob); - prop = IDP_New(IDP_FLOAT, val, name); + val.d = PyFloat_AsDouble(ob); + prop = IDP_New(IDP_DOUBLE, val, name); } else if (PyInt_Check(ob)) { val.i = (int) PyInt_AsLong(ob); prop = IDP_New(IDP_INT, val, name); @@ -223,7 +237,7 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje val.array.len = PySequence_Length(ob); for (i=0; i<val.array.len; i++) { item = PySequence_GetItem(ob, i); - if (PyFloat_Check(item)) val.array.type = IDP_FLOAT; + if (PyFloat_Check(item)) val.array.type = IDP_DOUBLE; else if (!PyInt_Check(item)) return "only floats and ints are allowed in ID property arrays"; Py_XDECREF(item); } @@ -236,7 +250,7 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje ((int*)prop->data.pointer)[i] = (int)PyInt_AsLong(item); } else { item = PyNumber_Float(item); - ((float*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item); + ((double*)prop->data.pointer)[i] = (float)PyFloat_AsDouble(item); } Py_XDECREF(item); } @@ -334,6 +348,9 @@ PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop) case IDP_FLOAT: return PyFloat_FromDouble(*((float*)&prop->data.val)); break; + case IDP_DOUBLE: + return PyFloat_FromDouble(*((double*)&prop->data.val)); + break; case IDP_INT: return PyInt_FromLong( (long)prop->data.val ); break; @@ -347,12 +364,15 @@ PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop) "PyList_New() failed" ); for (i=0; i<prop->len; i++) { - if (prop->subtype == IDP_FLOAT) + if (prop->subtype == IDP_FLOAT) { PyList_SetItem(seq, i, PyFloat_FromDouble(((float*)prop->data.pointer)[i])); - - else PyList_SetItem(seq, i, - PyInt_FromLong(((int*)prop->data.pointer)[i])); + } else if (prop->subtype == IDP_DOUBLE) { + PyList_SetItem(seq, i, + PyFloat_FromDouble(((double*)prop->data.pointer)[i])); + } else { PyList_SetItem(seq, i, + PyInt_FromLong(((int*)prop->data.pointer)[i])); + } } return seq; } @@ -451,7 +471,7 @@ PyObject *BPy_IDGroup_GetKeys(BPy_IDProperty *self) /*set correct group length*/ self->prop->len = i; - /*free the old list*/ + /*free the list*/ Py_DECREF(seq); /*call self again*/ @@ -688,6 +708,9 @@ PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index) case IDP_FLOAT: return PyFloat_FromDouble( (double)(((float*)self->prop->data.pointer)[index])); break; + case IDP_DOUBLE: + return PyFloat_FromDouble( (((double*)self->prop->data.pointer)[index])); + break; case IDP_INT: return PyInt_FromLong( (long)((int*)self->prop->data.pointer)[index] ); break; @@ -700,7 +723,8 @@ int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val) { int i; float f; - + double d; + if (index < 0 || index >= self->prop->len) return EXPP_ReturnIntError( PyExc_RuntimeError, "index out of range!"); @@ -717,6 +741,17 @@ int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *val) ((float*)self->prop->data.pointer)[index] = f; Py_XDECREF(val); break; + case IDP_DOUBLE: + if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError, + "expected a float"); + val = PyNumber_Float(val); + if (!val) return EXPP_ReturnIntError( PyExc_TypeError, + "expected a float"); + + d = (double) PyFloat_AsDouble(val); + ((double*)self->prop->data.pointer)[index] = d; + Py_XDECREF(val); + break; case IDP_INT: if (!PyNumber_Check(val)) return EXPP_ReturnIntError( PyExc_TypeError, "expected an int"); |