Changeset View
Changeset View
Standalone View
Standalone View
source/blender/makesdna/intern/dna_genfile.c
| Show First 20 Lines • Show All 305 Lines • ▼ Show 20 Lines | |||||
| /* ************************* READ DNA ********************** */ | /* ************************* READ DNA ********************** */ | ||||
| BLI_INLINE const char *pad_up_4(const char *ptr) | BLI_INLINE const char *pad_up_4(const char *ptr) | ||||
| { | { | ||||
| return (const char *)((((uintptr_t)ptr) + 3) & ~3); | return (const char *)((((uintptr_t)ptr) + 3) & ~3); | ||||
| } | } | ||||
| /** | /** | ||||
| * Temporary DNA doversion for files that were created with Blender 2.80 | |||||
| * between October 2016, and November 2017 (>=280.0 and < 280.2). | |||||
| * | |||||
| * /note This would be way more efficient if we can get the version from SDNA | |||||
| * So we could return true if version == 280 && subversion < 2. | |||||
| * | |||||
| * Returns true if we need to do the DNA renaming. | |||||
| */ | |||||
| static bool need_doversion_280(SDNA *sdna, int *data, const bool data_alloc) | |||||
| { | |||||
| if (data_alloc == false) { | |||||
| return false; | |||||
| } | |||||
| const char *cp = (char *)data; | |||||
| for (int nr = 0; nr < sdna->nr_names; nr++) { | |||||
| if (strcmp(cp, "*cur_render_layer") == 0) { | |||||
| return true; | |||||
| } | |||||
| while (*cp) cp++; | |||||
| cp++; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * In sdna->data the data, now we convert that to something understandable | * In sdna->data the data, now we convert that to something understandable | ||||
| */ | */ | ||||
| static bool init_structDNA( | static bool init_structDNA( | ||||
| SDNA *sdna, bool do_endian_swap, | SDNA *sdna, bool do_endian_swap, | ||||
| bool data_alloc, | |||||
| const char **r_error_message) | const char **r_error_message) | ||||
| { | { | ||||
| int *data, *verg, gravity_fix = -1; | int *data, *verg, gravity_fix = -1; | ||||
| short *sp; | short *sp; | ||||
| char str[8]; | char str[8]; | ||||
| verg = (int *)str; | verg = (int *)str; | ||||
| data = (int *)sdna->data; | data = (int *)sdna->data; | ||||
| Show All 28 Lines | if (*data == *verg) { | ||||
| data++; | data++; | ||||
| sdna->names = MEM_callocN(sizeof(void *) * sdna->nr_names, "sdnanames"); | sdna->names = MEM_callocN(sizeof(void *) * sdna->nr_names, "sdnanames"); | ||||
| } | } | ||||
| else { | else { | ||||
| *r_error_message = "NAME error in SDNA file"; | *r_error_message = "NAME error in SDNA file"; | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Temporary DNA doversion for files that were created with Blender 2.80 | |||||
| * between 280.0 and 280.2. */ | |||||
| const bool doversion_280 = need_doversion_280(sdna, data, data_alloc); | |||||
| cp = (char *)data; | cp = (char *)data; | ||||
| for (int nr = 0; nr < sdna->nr_names; nr++) { | for (int nr = 0; nr < sdna->nr_names; nr++) { | ||||
| sdna->names[nr] = cp; | sdna->names[nr] = cp; | ||||
| /* "float gravity [3]" was parsed wrong giving both "gravity" and | /* "float gravity [3]" was parsed wrong giving both "gravity" and | ||||
| * "[3]" members. we rename "[3]", and later set the type of | * "[3]" members. we rename "[3]", and later set the type of | ||||
| * "gravity" to "void" so the offsets work out correct */ | * "gravity" to "void" so the offsets work out correct */ | ||||
| if (*cp == '[' && strcmp(cp, "[3]") == 0) { | if (*cp == '[' && strcmp(cp, "[3]") == 0) { | ||||
| if (nr && strcmp(sdna->names[nr - 1], "Cvi") == 0) { | if (nr && strcmp(sdna->names[nr - 1], "Cvi") == 0) { | ||||
| sdna->names[nr] = "gravity[3]"; | sdna->names[nr] = "gravity[3]"; | ||||
| gravity_fix = nr; | gravity_fix = nr; | ||||
| } | } | ||||
| } | } | ||||
| else if (doversion_280) { | |||||
| if (strcmp(cp, "*render_layer") == 0) { | |||||
| /* WorkSpace. */ | |||||
| sdna->names[nr] = "*view_layer"; | |||||
| } | |||||
| else if (strcmp(cp, "*scene_layer") == 0) { | |||||
| /* ParticleEditSettings. */ | |||||
| sdna->names[nr] = "*view_layer"; | |||||
| } | |||||
| else if (strcmp(cp, "render_layers") == 0) { | |||||
| /* Scene. */ | |||||
| sdna->names[nr] = "view_layers"; | |||||
| } | |||||
| else if (strcmp(cp, "active_layer") == 0) { | |||||
| /* Scene. */ | |||||
| sdna->names[nr] = "active_view_layer"; | |||||
| } | |||||
| else if (strcmp(cp, "*cur_render_layer") == 0) { | |||||
| /* FileGlobal. */ | |||||
| sdna->names[nr] = "*cur_view_layer"; | |||||
| } | |||||
| } | |||||
| while (*cp) cp++; | while (*cp) cp++; | ||||
| cp++; | cp++; | ||||
| } | } | ||||
| cp = pad_up_4(cp); | cp = pad_up_4(cp); | ||||
| /* load type names array */ | /* load type names array */ | ||||
| Show All 21 Lines | for (int nr = 0; nr < sdna->nr_types; nr++) { | ||||
| /* this is a patch, to change struct names without a conflict with SDNA */ | /* this is a patch, to change struct names without a conflict with SDNA */ | ||||
| /* be careful to use it, in this case for a system-struct (opengl/X) */ | /* be careful to use it, in this case for a system-struct (opengl/X) */ | ||||
| if (*cp == 'b') { | if (*cp == 'b') { | ||||
| /* struct Screen was already used by X, 'bScreen' replaces the old IrisGL 'Screen' struct */ | /* struct Screen was already used by X, 'bScreen' replaces the old IrisGL 'Screen' struct */ | ||||
| if (strcmp("bScreen", cp) == 0) sdna->types[nr] = cp + 1; | if (strcmp("bScreen", cp) == 0) sdna->types[nr] = cp + 1; | ||||
| } | } | ||||
| else if (doversion_280) { | |||||
| if (strcmp(cp, "SceneLayer") == 0) { | |||||
| sdna->types[nr] = "ViewLayer"; | |||||
| } | |||||
| else if (strcmp(cp, "SceneLayerEngineData") == 0) { | |||||
| sdna->types[nr] = "ViewLayerEngineData"; | |||||
| } | |||||
| } | |||||
| while (*cp) cp++; | while (*cp) cp++; | ||||
| cp++; | cp++; | ||||
| } | } | ||||
| cp = pad_up_4(cp); | cp = pad_up_4(cp); | ||||
| /* load typelen array */ | /* load typelen array */ | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | if (data_alloc) { | ||||
| sdna->data = data_copy; | sdna->data = data_copy; | ||||
| } | } | ||||
| else { | else { | ||||
| sdna->data = data; | sdna->data = data; | ||||
| } | } | ||||
| sdna->data_alloc = data_alloc; | sdna->data_alloc = data_alloc; | ||||
| if (init_structDNA(sdna, do_endian_swap, &error_message)) { | if (init_structDNA(sdna, do_endian_swap, data_alloc, &error_message)) { | ||||
| return sdna; | return sdna; | ||||
| } | } | ||||
| else { | else { | ||||
| if (r_error_message == NULL) { | if (r_error_message == NULL) { | ||||
| fprintf(stderr, "Error decoding blend file SDNA: %s\n", error_message); | fprintf(stderr, "Error decoding blend file SDNA: %s\n", error_message); | ||||
| } | } | ||||
| else { | else { | ||||
| *r_error_message = error_message; | *r_error_message = error_message; | ||||
| ▲ Show 20 Lines • Show All 779 Lines • Show Last 20 Lines | |||||