diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-01-16 07:00:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-01-16 07:00:22 +0300 |
commit | 92b222a158877eeb90cc391ff8f64c133153bdf9 (patch) | |
tree | ff4ee493ccf2056523c7923ee68509973761deb4 /source/blender | |
parent | 63de1e7e7a783525bbd4c2770c8454b4b0e79cc8 (diff) |
Cleanup: use enum constant for DNA comparison
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 5 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.h | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_genfile.h | 8 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 24 |
4 files changed, 27 insertions, 12 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 505c236e01f..bd759e2c580 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1847,11 +1847,12 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname) if (bh->SDNAnr && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) switch_endian_structs(fd->filesdna, bh); - if (fd->compflags[bh->SDNAnr]) { /* flag==0: doesn't exist anymore */ - if (fd->compflags[bh->SDNAnr] == 2) { + if (fd->compflags[bh->SDNAnr] != SDNA_CMP_REMOVED) { + if (fd->compflags[bh->SDNAnr] == SDNA_CMP_NOT_EQUAL) { temp = DNA_struct_reconstruct(fd->memsdna, fd->filesdna, fd->compflags, bh->SDNAnr, bh->nr, (bh+1)); } else { + /* SDNA_CMP_EQUAL */ temp = MEM_mallocN(bh->len, blockname); memcpy(temp, (bh+1), bh->len); } diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index f6c3b69c414..00e19b0597a 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -75,7 +75,7 @@ typedef struct FileData { // general reading variables struct SDNA *filesdna; struct SDNA *memsdna; - char *compflags; + char *compflags; /* array of eSDNA_StructCompare */ int fileversion; int id_name_offs; /* used to retrieve ID names from (bhead+1) */ diff --git a/source/blender/makesdna/DNA_genfile.h b/source/blender/makesdna/DNA_genfile.h index 2858de74776..d62369803d6 100644 --- a/source/blender/makesdna/DNA_genfile.h +++ b/source/blender/makesdna/DNA_genfile.h @@ -65,6 +65,14 @@ typedef enum eSDNA_Type { SDNA_TYPE_UINT64 = 11 } eSDNA_Type; +/** + * For use with #DNA_struct_reconstruct & #DNA_struct_get_compareflags + */ +enum eSDNA_StructCompare { + SDNA_CMP_REMOVED = 0, + SDNA_CMP_EQUAL = 1, + SDNA_CMP_NOT_EQUAL = 2, +}; struct SDNA *DNA_sdna_from_data(const void *data, const int datalen, bool do_endian_swap); void DNA_sdna_free(struct SDNA *sdna); diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index f3c99154ac2..4f19e819625 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -582,7 +582,7 @@ static void recurs_test_compflags(const SDNA *sdna, char *compflags, int structn typenr = sp[0]; for (a = 0; a < sdna->nr_structs; a++) { - if (a != structnr && compflags[a] == 1) { + if ((a != structnr) && (compflags[a] == SDNA_CMP_EQUAL)) { sp = sdna->structs[a]; elems = sp[1]; sp += 2; @@ -590,7 +590,7 @@ static void recurs_test_compflags(const SDNA *sdna, char *compflags, int structn if (sp[0] == typenr) { cp = sdna->names[sp[1]]; if (!ispointer(cp)) { - compflags[a] = 2; + compflags[a] = SDNA_CMP_NOT_EQUAL; recurs_test_compflags(sdna, compflags, a); } } @@ -635,7 +635,8 @@ char *DNA_struct_get_compareflags(SDNA *oldsdna, SDNA *newsdna) sp_new = findstruct_name(newsdna, oldsdna->types[sp_old[0]]); if (sp_new) { - compflags[a] = 2; /* initial assumption */ + /* initial assumption */ + compflags[a] = SDNA_CMP_NOT_EQUAL; /* compare length and amount of elems */ if (sp_new[1] == sp_old[1]) { @@ -663,7 +664,10 @@ char *DNA_struct_get_compareflags(SDNA *oldsdna, SDNA *newsdna) sp_old += 2; sp_new += 2; } - if (b == 0) compflags[a] = 1; /* no differences found */ + if (b == 0) { + /* no differences found */ + compflags[a] = SDNA_CMP_EQUAL; + } } } @@ -674,18 +678,20 @@ char *DNA_struct_get_compareflags(SDNA *oldsdna, SDNA *newsdna) /* first struct in util.h is struct Link, this is skipped in compflags (als # 0). * was a bug, and this way dirty patched! Solve this later.... */ - compflags[0] = 1; + compflags[0] = SDNA_CMP_EQUAL; /* Because structs can be inside structs, we recursively * set flags when a struct is altered */ for (a = 0; a < oldsdna->nr_structs; a++) { - if (compflags[a] == 2) recurs_test_compflags(oldsdna, compflags, a); + if (compflags[a] == SDNA_CMP_NOT_EQUAL) { + recurs_test_compflags(oldsdna, compflags, a); + } } #if 0 for (a = 0; a < oldsdna->nr_structs; a++) { - if (compflags[a] == 2) { + if (compflags[a] == SDNA_CMP_NOT_EQUAL) { spold = oldsdna->structs[a]; printf("changed: %s\n", oldsdna->types[spold[0]]); } @@ -1040,8 +1046,8 @@ static void reconstruct_struct( if (oldSDNAnr == -1) return; if (curSDNAnr == -1) return; - if (compflags[oldSDNAnr] == 1) { /* if recursive: test for equal */ - + if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) { + /* if recursive: test for equal */ spo = oldsdna->structs[oldSDNAnr]; elen = oldsdna->typelens[spo[0]]; memcpy(cur, data, elen); |