Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesdna/intern/dna_genfile.c
| Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | |||||
| * - int: 4 aligned | * - int: 4 aligned | ||||
| * - float: 4 aligned | * - float: 4 aligned | ||||
| * - double: 8 aligned | * - double: 8 aligned | ||||
| * - long: 8 aligned | * - long: 8 aligned | ||||
| * - struct: 8 aligned | * - struct: 8 aligned | ||||
| * - the sdna functions have several error prints builtin, always check blender running from a console. | * - the sdna functions have several error prints builtin, always check blender running from a console. | ||||
| */ | */ | ||||
| /** If we get here there is no old data, initialize from the default (if it exists). */ | |||||
| #define USE_RECONSTRUCT_DEFAULTS | |||||
| #ifdef USE_RECONSTRUCT_DEFAULTS | |||||
| # include "DNA_defaults.h" | |||||
| #endif | |||||
| #ifdef __BIG_ENDIAN__ | #ifdef __BIG_ENDIAN__ | ||||
| /* Big Endian */ | /* Big Endian */ | ||||
| # define MAKE_ID(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d)) | # define MAKE_ID(a, b, c, d) ((int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d)) | ||||
| #else | #else | ||||
| /* Little Endian */ | /* Little Endian */ | ||||
| # define MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a)) | # define MAKE_ID(a, b, c, d) ((int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a)) | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 813 Lines • ▼ Show 20 Lines | |||||
| * \param newsdna: SDNA of current Blender | * \param newsdna: SDNA of current Blender | ||||
| * \param oldsdna: SDNA of Blender that saved file | * \param oldsdna: SDNA of Blender that saved file | ||||
| * \param type: current field type name | * \param type: current field type name | ||||
| * \param new_name_nr: current field name number. | * \param new_name_nr: current field name number. | ||||
| * \param curdata: put field data converted to newsdna here | * \param curdata: put field data converted to newsdna here | ||||
| * \param old: pointer to struct info in oldsdna | * \param old: pointer to struct info in oldsdna | ||||
| * \param olddata: struct contents laid out according to oldsdna | * \param olddata: struct contents laid out according to oldsdna | ||||
| */ | */ | ||||
| static void reconstruct_elem( | static bool reconstruct_elem( | ||||
| const SDNA *newsdna, | const SDNA *newsdna, | ||||
| const SDNA *oldsdna, | const SDNA *oldsdna, | ||||
| const char *type, | const char *type, | ||||
| const int new_name_nr, | const int new_name_nr, | ||||
| char *curdata, | char *curdata, | ||||
| const short *old, | const short *old, | ||||
| const char *olddata) | const char *olddata) | ||||
| { | { | ||||
| Show All 38 Lines | if (strcmp(name, oname) == 0) { /* name equal */ | ||||
| memcpy(curdata, olddata, len); | memcpy(curdata, olddata, len); | ||||
| } | } | ||||
| else { | else { | ||||
| cast_elem(type, otype, | cast_elem(type, otype, | ||||
| newsdna->names_array_len[new_name_nr], | newsdna->names_array_len[new_name_nr], | ||||
| curdata, olddata); | curdata, olddata); | ||||
| } | } | ||||
| return; | return true; | ||||
| } | } | ||||
| else if (countpos != 0) { /* name is an array */ | else if (countpos != 0) { /* name is an array */ | ||||
| if (oname[countpos] == '[' && strncmp(name, oname, countpos) == 0) { /* basis equal */ | if (oname[countpos] == '[' && strncmp(name, oname, countpos) == 0) { /* basis equal */ | ||||
| const int new_name_array_len = newsdna->names_array_len[new_name_nr]; | const int new_name_array_len = newsdna->names_array_len[new_name_nr]; | ||||
| const int old_name_array_len = oldsdna->names_array_len[old_name_nr]; | const int old_name_array_len = oldsdna->names_array_len[old_name_nr]; | ||||
| const int min_name_array_len = MIN2(new_name_array_len, old_name_array_len); | const int min_name_array_len = MIN2(new_name_array_len, old_name_array_len); | ||||
| Show All 15 Lines | else if (countpos != 0) { /* name is an array */ | ||||
| curdata[mul - 1] = '\0'; | curdata[mul - 1] = '\0'; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| cast_elem(type, otype, | cast_elem(type, otype, | ||||
| min_name_array_len, | min_name_array_len, | ||||
| curdata, olddata); | curdata, olddata); | ||||
| } | } | ||||
| return; | return true; | ||||
| } | } | ||||
| } | } | ||||
| olddata += len; | olddata += len; | ||||
| } | } | ||||
| return false; | |||||
| } | } | ||||
| /** | /** | ||||
| * Converts the contents of an entire struct from oldsdna to newsdna format. | * Converts the contents of an entire struct from oldsdna to newsdna format. | ||||
| * | * | ||||
| * \param newsdna: SDNA of current Blender | * \param newsdna: SDNA of current Blender | ||||
| * \param oldsdna: SDNA of Blender that saved file | * \param oldsdna: SDNA of Blender that saved file | ||||
| * \param compflags: | * \param compflags: | ||||
| Show All 24 Lines | static void reconstruct_struct( | ||||
| const char *cpo; | const char *cpo; | ||||
| char *cpc; | char *cpc; | ||||
| const char *name; | const char *name; | ||||
| unsigned int oldsdna_index_last = UINT_MAX; | unsigned int oldsdna_index_last = UINT_MAX; | ||||
| unsigned int cursdna_index_last = UINT_MAX; | unsigned int cursdna_index_last = UINT_MAX; | ||||
| if (oldSDNAnr == -1) return; | |||||
| if (curSDNAnr == -1) return; | if (curSDNAnr == -1) return; | ||||
| if (oldSDNAnr == -1) { | |||||
| #ifdef USE_RECONSTRUCT_DEFAULTS | |||||
| const char *cur_default = DNA_default_table[curSDNAnr]; | |||||
| if (cur_default != NULL) { | |||||
| memcpy(cpc, cur_default, newsdna->types_size[curSDNAnr]); | |||||
| } | |||||
| #endif | |||||
| return; | |||||
| } | |||||
| if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) { | if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) { | ||||
| /* if recursive: test for equal */ | /* if recursive: test for equal */ | ||||
| spo = oldsdna->structs[oldSDNAnr]; | spo = oldsdna->structs[oldSDNAnr]; | ||||
| elen = oldsdna->types_size[spo[0]]; | elen = oldsdna->types_size[spo[0]]; | ||||
| memcpy(cur, data, elen); | memcpy(cur, data, elen); | ||||
| return; | return; | ||||
| } | } | ||||
| const char *cur_default = DNA_default_table[curSDNAnr]; | |||||
| firststructtypenr = *(newsdna->structs[0]); | firststructtypenr = *(newsdna->structs[0]); | ||||
| spo = oldsdna->structs[oldSDNAnr]; | spo = oldsdna->structs[oldSDNAnr]; | ||||
| spc = newsdna->structs[curSDNAnr]; | spc = newsdna->structs[curSDNAnr]; | ||||
| elemcount = spc[1]; | elemcount = spc[1]; | ||||
| spc += 2; | spc += 2; | ||||
| Show All 40 Lines | else if (spc[0] >= firststructtypenr && !ispointer(name)) { | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| cpc += elen; /* skip field no longer present */ | cpc += elen; /* skip field no longer present */ | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* non-struct field type */ | /* non-struct field type */ | ||||
| reconstruct_elem(newsdna, oldsdna, type, spc[1], cpc, spo, data); | if (!reconstruct_elem(newsdna, oldsdna, type, spc[1], cpc, spo, data)) { | ||||
| #ifdef USE_RECONSTRUCT_DEFAULTS | |||||
| if (cur_default != NULL) { | |||||
| memcpy(cpc, cur_default + (cpc - cur), elen); | |||||
| } | |||||
| #endif | |||||
| } | |||||
| cpc += elen; | cpc += elen; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Does endian swapping on the fields of a struct value. | * Does endian swapping on the fields of a struct value. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 408 Lines • Show Last 20 Lines | |||||