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 | |||||
| * - double: 8 aligned. | * - double: 8 aligned. | ||||
| * - long: 8 aligned. | * - long: 8 aligned. | ||||
| * - int64: 8 aligned. | * - int64: 8 aligned. | ||||
| * - struct: 8 aligned. | * - struct: 8 aligned. | ||||
| * - the sdna functions have several error prints builtin, | * - the sdna functions have several error prints builtin, | ||||
| * always check blender running from a console. | * 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 947 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(const SDNA *newsdna, | static bool reconstruct_elem(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) | ||||
| { | { | ||||
| /* rules: test for NAME: | /* rules: test for NAME: | ||||
| Show All 40 Lines | if (strcmp(name, oname) == 0) { /* name equal */ | ||||
| } | } | ||||
| else if (strcmp(type, otype) == 0) { /* type equal */ | else if (strcmp(type, otype) == 0) { /* type equal */ | ||||
| memcpy(curdata, olddata, len); | memcpy(curdata, olddata, len); | ||||
| } | } | ||||
| else { | else { | ||||
| cast_elem(type, otype, newsdna->names_array_len[new_name_nr], curdata, olddata); | cast_elem(type, otype, newsdna->names_array_len[new_name_nr], 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 12 Lines | else if (countpos != 0) { /* name is an array */ | ||||
| if (old_name_array_len > new_name_array_len && strcmp(type, "char") == 0) { | if (old_name_array_len > new_name_array_len && strcmp(type, "char") == 0) { | ||||
| /* string had to be truncated, ensure it's still null-terminated */ | /* string had to be truncated, ensure it's still null-terminated */ | ||||
| curdata[mul - 1] = '\0'; | curdata[mul - 1] = '\0'; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| cast_elem(type, otype, min_name_array_len, curdata, olddata); | cast_elem(type, otype, min_name_array_len, 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 22 Lines | static void reconstruct_struct(const SDNA *newsdna, | ||||
| const char *type; | const char *type; | ||||
| 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) { | if (curSDNAnr == -1) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (curSDNAnr == -1) { | if (oldSDNAnr == -1) { | ||||
| #ifdef USE_RECONSTRUCT_DEFAULTS | |||||
| const char *cur_default = DNA_default_table[curSDNAnr]; | |||||
| if (cur_default != NULL) { | |||||
| memcpy(cur, cur_default, newsdna->types_size[curSDNAnr]); | |||||
| } | |||||
| #endif | |||||
| return; | 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 20 Lines • Show All 42 Lines • ▼ Show 20 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 463 Lines • Show Last 20 Lines | |||||