Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesdna/intern/dna_genfile.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Returns the size of struct fields of the specified type and name. | * Returns the size of struct fields of the specified type and name. | ||||
| * | * | ||||
| * \param type: Index into sdna->types/types_size | * \param type: Index into sdna->types/types_size | ||||
| * \param name: Index into sdna->names, | * \param name: Index into sdna->names, | ||||
| * needed to extract possible pointer/array information. | * needed to extract possible pointer/array information. | ||||
| */ | */ | ||||
| int DNA_elem_size_nr(const SDNA *sdna, short type, short name) | static int elementsize(const SDNA *sdna, short type, short name) | ||||
| { | { | ||||
| int len; | int len; | ||||
| const char *cp = sdna->names[name]; | const char *cp = sdna->names[name]; | ||||
| len = 0; | len = 0; | ||||
| /* is it a pointer or function pointer? */ | /* is it a pointer or function pointer? */ | ||||
| if (ispointer(cp)) { | if (ispointer(cp)) { | ||||
| /* has the name an extra length? (array) */ | /* has the name an extra length? (array) */ | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| /* in old is the old struct */ | /* in old is the old struct */ | ||||
| elemcount = old[1]; | elemcount = old[1]; | ||||
| old += 2; | old += 2; | ||||
| for (a = 0; a < elemcount; a++, old += 2) { | for (a = 0; a < elemcount; a++, old += 2) { | ||||
| otype = sdna->types[old[0]]; | otype = sdna->types[old[0]]; | ||||
| oname = sdna->names[old[1]]; | oname = sdna->names[old[1]]; | ||||
| len = DNA_elem_size_nr(sdna, old[0], old[1]); | len = elementsize(sdna, old[0], old[1]); | ||||
| if (elem_strcmp(name, oname) == 0) { /* name equal */ | if (elem_strcmp(name, oname) == 0) { /* name equal */ | ||||
| if (strcmp(type, otype) == 0) { /* type equal */ | if (strcmp(type, otype) == 0) { /* type equal */ | ||||
| if (sppo) { | if (sppo) { | ||||
| *sppo = old; | *sppo = old; | ||||
| } | } | ||||
| return olddata; | return olddata; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
| /* in old is the old struct */ | /* in old is the old struct */ | ||||
| elemcount = old[1]; | elemcount = old[1]; | ||||
| old += 2; | old += 2; | ||||
| for (a = 0; a < elemcount; a++, old += 2) { | for (a = 0; a < elemcount; a++, old += 2) { | ||||
| const int old_name_nr = old[1]; | const int old_name_nr = old[1]; | ||||
| otype = oldsdna->types[old[0]]; | otype = oldsdna->types[old[0]]; | ||||
| oname = oldsdna->names[old[1]]; | oname = oldsdna->names[old[1]]; | ||||
| len = DNA_elem_size_nr(oldsdna, old[0], old[1]); | len = elementsize(oldsdna, old[0], old[1]); | ||||
| if (strcmp(name, oname) == 0) { /* name equal */ | if (strcmp(name, oname) == 0) { /* name equal */ | ||||
| if (ispointer(name)) { /* pointer of functionpointer afhandelen */ | if (ispointer(name)) { /* pointer of functionpointer afhandelen */ | ||||
| cast_pointer(newsdna->pointer_size, | cast_pointer(newsdna->pointer_size, | ||||
| oldsdna->pointer_size, | oldsdna->pointer_size, | ||||
| newsdna->names_array_len[new_name_nr], | newsdna->names_array_len[new_name_nr], | ||||
| curdata, | curdata, | ||||
| ▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
| elemcount = spc[1]; | elemcount = spc[1]; | ||||
| spc += 2; | spc += 2; | ||||
| cpc = cur; | cpc = cur; | ||||
| for (a = 0; a < elemcount; a++, spc += 2) { /* convert each field */ | for (a = 0; a < elemcount; a++, spc += 2) { /* convert each field */ | ||||
| type = newsdna->types[spc[0]]; | type = newsdna->types[spc[0]]; | ||||
| name = newsdna->names[spc[1]]; | name = newsdna->names[spc[1]]; | ||||
| elen = DNA_elem_size_nr(newsdna, spc[0], spc[1]); | elen = elementsize(newsdna, spc[0], spc[1]); | ||||
| /* Skip pad bytes which must start with '_pad', see makesdna.c 'is_name_legal'. | /* Skip pad bytes which must start with '_pad', see makesdna.c 'is_name_legal'. | ||||
| * for exact rules. Note that if we fail to skip a pad byte it's harmless, | * for exact rules. Note that if we fail to skip a pad byte it's harmless, | ||||
| * this just avoids unnecessary reconstruction. */ | * this just avoids unnecessary reconstruction. */ | ||||
| if (name[0] == '_' || (name[0] == '*' && name[1] == '_')) { | if (name[0] == '_' || (name[0] == '*' && name[1] == '_')) { | ||||
| cpc += elen; | cpc += elen; | ||||
| } | } | ||||
| else if (spc[0] >= firststructtypenr && !ispointer(name)) { | else if (spc[0] >= firststructtypenr && !ispointer(name)) { | ||||
| /* struct field type */ | /* struct field type */ | ||||
| /* where does the old struct data start (and is there an old one?) */ | /* where does the old struct data start (and is there an old one?) */ | ||||
| cpo = (char *)find_elem(oldsdna, type, name, spo, data, &sppo); | cpo = (char *)find_elem(oldsdna, type, name, spo, data, &sppo); | ||||
| if (cpo) { | if (cpo) { | ||||
| oldSDNAnr = DNA_struct_find_nr_ex(oldsdna, type, &oldsdna_index_last); | oldSDNAnr = DNA_struct_find_nr_ex(oldsdna, type, &oldsdna_index_last); | ||||
| curSDNAnr = DNA_struct_find_nr_ex(newsdna, type, &cursdna_index_last); | curSDNAnr = DNA_struct_find_nr_ex(newsdna, type, &cursdna_index_last); | ||||
| /* array! */ | /* array! */ | ||||
| mul = newsdna->names_array_len[spc[1]]; | mul = newsdna->names_array_len[spc[1]]; | ||||
| mulo = oldsdna->names_array_len[sppo[1]]; | mulo = oldsdna->names_array_len[sppo[1]]; | ||||
| eleno = DNA_elem_size_nr(oldsdna, sppo[0], sppo[1]); | eleno = elementsize(oldsdna, sppo[0], sppo[1]); | ||||
| elen /= mul; | elen /= mul; | ||||
| eleno /= mulo; | eleno /= mulo; | ||||
| while (mul--) { | while (mul--) { | ||||
| reconstruct_struct(newsdna, oldsdna, compflags, oldSDNAnr, cpo, curSDNAnr, cpc); | reconstruct_struct(newsdna, oldsdna, compflags, oldSDNAnr, cpo, curSDNAnr, cpc); | ||||
| cpo += eleno; | cpo += eleno; | ||||
| cpc += elen; | cpc += elen; | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
| spc += 2; | spc += 2; | ||||
| cur = data; | cur = data; | ||||
| for (a = 0; a < elemcount; a++, spc += 2) { | for (a = 0; a < elemcount; a++, spc += 2) { | ||||
| type = oldsdna->types[spc[0]]; | type = oldsdna->types[spc[0]]; | ||||
| name = oldsdna->names[spc[1]]; | name = oldsdna->names[spc[1]]; | ||||
| const int old_name_array_len = oldsdna->names_array_len[spc[1]]; | const int old_name_array_len = oldsdna->names_array_len[spc[1]]; | ||||
| /* DNA_elem_size_nr = including arraysize */ | /* elementsize = including arraysize */ | ||||
| elen = DNA_elem_size_nr(oldsdna, spc[0], spc[1]); | elen = elementsize(oldsdna, spc[0], spc[1]); | ||||
| /* test: is type a struct? */ | /* test: is type a struct? */ | ||||
| if (spc[0] >= firststructtypenr && !ispointer(name)) { | if (spc[0] >= firststructtypenr && !ispointer(name)) { | ||||
| /* struct field type */ | /* struct field type */ | ||||
| /* where does the old data start (is there one?) */ | /* where does the old data start (is there one?) */ | ||||
| char *cpo = (char *)find_elem(oldsdna, type, name, spo, data, NULL); | char *cpo = (char *)find_elem(oldsdna, type, name, spo, data, NULL); | ||||
| if (cpo) { | if (cpo) { | ||||
| oldSDNAnr = DNA_struct_find_nr_ex(oldsdna, type, &oldsdna_index_last); | oldSDNAnr = DNA_struct_find_nr_ex(oldsdna, type, &oldsdna_index_last); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||