From 49aeee5a3dfa9fc0ae29e99f7c5c0cc0124e560e Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Wed, 18 May 2016 03:19:06 +1200 Subject: Bendy Bones: Advanced B-Bones for Easier + Simple Rigging This commit/patch/branch brings a bunch of powerful new options for B-Bones and for working with B-Bones, making it easier for animators to create their own rigs, using fewer bones (which also means hopefully lighter + faster rigs ;) This functionality was first demoed by Daniel at BConf15 Some highlights from this patch include: * You can now directly control the shape of B-Bones using a series of properties instead of being restricted to trying to indirectly control them through the neighbouring bones. See the "Bendy Bones" panel... * B-Bones can be shaped in EditMode to define a "curved rest pose" for the bone. This is useful for things like eyebrows and mouths/eyelids * You can now make B-Bones use custom bones as their reference bone handles, instead of only using the parent/child bones. To do so, enable the "Use Custom Reference Handles" toggle. If none are specified, then the BBone will only use the Bendy Bone properties. * Constraints Head/Tail option can now slide along the B-Bone shape, instead of just linearly interpolating between the endpoints of the bone. For more details, see: * http://aligorith.blogspot.co.nz/2016/05/bendy-bones-dev-update.html * http://aligorith.blogspot.co.nz/2016/05/an-in-depth-look-at-how-b-bones-work.html -- Credits -- Original Idea: Daniel M Lara (pepeland) Original Patch/Research: Jose Molina Additional Development + Polish: Joshua Leung (aligorith) Testing/Feedback: Daniel M Lara (pepeland), Juan Pablo Bouza (jpbouza) --- source/blender/blenloader/intern/readfile.c | 3 ++ source/blender/blenloader/intern/versioning_270.c | 39 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 678fd84de94..d6e2f237be9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4926,6 +4926,9 @@ static void direct_link_pose(FileData *fd, bPose *pose) pchan->child = newdataadr(fd, pchan->child); pchan->custom_tx = newdataadr(fd, pchan->custom_tx); + pchan->bbone_prev = newdataadr(fd, pchan->bbone_prev); + pchan->bbone_next = newdataadr(fd, pchan->bbone_next); + direct_link_constraints(fd, &pchan->constraints); pchan->prop = newdataadr(fd, pchan->prop); diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index efd167d49d5..58542d05879 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -34,6 +34,7 @@ /* allow readfile to use deprecated functionality */ #define DNA_DEPRECATED_ALLOW +#include "DNA_armature_types.h" #include "DNA_brush_types.h" #include "DNA_camera_types.h" #include "DNA_cloth_types.h" @@ -161,6 +162,16 @@ static void do_version_action_editor_properties_region(ListBase *regionbase) } } +static void do_version_bones_super_bbone(ListBase *lb) +{ + for (Bone *bone = lb->first; bone; bone = bone->next) { + bone->scaleIn = 1.0f; + bone->scaleOut = 1.0f; + + do_version_bones_super_bbone(&bone->childbase); + } +} + void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) { if (!MAIN_VERSION_ATLEAST(main, 270, 0)) { @@ -1151,4 +1162,32 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + if (!MAIN_VERSION_ATLEAST(main, 277, 2)) { + if (!DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scaleIn")) { + for (bArmature *arm = main->armature.first; arm; arm = arm->id.next) { + do_version_bones_super_bbone(&arm->bonebase); + } + } + if (!DNA_struct_elem_find(fd->filesdna, "bPoseChannel", "float", "scaleIn")) { + for (Object *ob = main->object.first; ob; ob = ob->id.next) { + if (ob->pose) { + for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { + /* see do_version_bones_super_bbone()... */ + pchan->scaleIn = 1.0f; + pchan->scaleOut = 1.0f; + + /* also make sure some legacy (unused for over a decade) flags are unset, + * so that we can reuse them for stuff that matters now... + * (i.e. POSE_IK_MAT, (unknown/unused x 4), POSE_HAS_IK) + * + * These seem to have been runtime flags used by the IK solver, but that stuff + * should be able to be recalculated automatically anyway, so it should be fine. + */ + pchan->flag &= ~((1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8)); + } + } + } + } + } } -- cgit v1.2.3 From cbe7f9dd03634a29082f51d05a2b1b71c6fc6aef Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 17 May 2016 14:12:29 +0200 Subject: Cycles: Pole merging for spherical stereo The idea of pole merge is to fade interocular distance after a certain altitude to zero when altitude goes closer to a pole. This should prevent annoyances looking up in the sky or down to the bottom. Works for both panorama and perspective cameras when Spherical Stereo is enabled. Reviewers: dfelinto, brecht Reviewed By: brecht Subscribers: sebastian_k Differential Revision: https://developer.blender.org/D1998 --- source/blender/blenloader/intern/versioning_270.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 58542d05879..0ea4078a5cb 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1190,4 +1190,15 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + { + for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) { + if (camera->stereo.pole_merge_angle_from == 0.0f && + camera->stereo.pole_merge_angle_to == 0.0f) + { + camera->stereo.pole_merge_angle_from = DEG2RAD(60.0f); + camera->stereo.pole_merge_angle_to = DEG2RAD(75.0f); + } + } + } } -- cgit v1.2.3 From 0cc514ec845e3170a63ad837360842219e951e85 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Sun, 22 May 2016 15:44:18 +0200 Subject: Make Shift-Z in viewprot a toggle between current shading mode and rendered one This way it is now possible to toggle between material and rendered shading while previously rendered viewport will always go back to solid shading. --- source/blender/blenloader/intern/readfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d6e2f237be9..464fc0a2d49 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6935,6 +6935,7 @@ static bool direct_link_screen(FileData *fd, bScreen *sc) /* render can be quite heavy, set to solid on load */ if (v3d->drawtype == OB_RENDER) v3d->drawtype = OB_SOLID; + v3d->prev_drawtype = OB_SOLID; if (v3d->fx_settings.dof) v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof); -- cgit v1.2.3 From a97bcc2985feb8e868d5e61cf0acc122107be683 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Jun 2016 17:55:22 +1000 Subject: Cleanup: rename flag -> tag ID's have a flag member too, best avoid confusion here. --- source/blender/blenloader/intern/readfile.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 464fc0a2d49..6a2f80d3ab4 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7880,7 +7880,7 @@ static BHead *read_data_into_oldnewmap(FileData *fd, BHead *bhead, const char *a return bhead; } -static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID **r_id) +static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short tag, ID **r_id) { /* this routine reads a libblock and its direct data. Use link functions to connect it all */ @@ -7966,7 +7966,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID if (!id) return blo_nextbhead(fd, bhead); - id->tag = flag | LIB_TAG_NEED_LINK; + id->tag = tag | LIB_TAG_NEED_LINK; id->lib = main->curlib; id->us = ID_FAKE_USERS(id); id->icon_id = 0; @@ -9644,7 +9644,7 @@ static void give_base_to_groups( } } -static ID *create_placeholder(Main *mainvar, const char *idname, const short flag) +static ID *create_placeholder(Main *mainvar, const char *idname, const short tag) { const short idcode = GS(idname); ListBase *lb = which_libbase(mainvar, idcode); @@ -9653,7 +9653,7 @@ static ID *create_placeholder(Main *mainvar, const char *idname, const short fla memcpy(ph_id->name, idname, sizeof(ph_id->name)); BKE_libblock_init_empty(ph_id); ph_id->lib = mainvar->curlib; - ph_id->tag = flag | LIB_TAG_MISSING; + ph_id->tag = tag | LIB_TAG_MISSING; ph_id->us = ID_FAKE_USERS(ph_id); ph_id->icon_id = 0; -- cgit v1.2.3 From 894d24fb16eb1dcfc0ef8c5febde4d7fb072f79b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Jun 2016 18:03:45 +1000 Subject: Cleanup: use const for old member in OldNew struct --- source/blender/blenloader/intern/readfile.c | 48 ++++++++++++++--------------- source/blender/blenloader/intern/readfile.h | 6 ++-- 2 files changed, 26 insertions(+), 28 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6a2f80d3ab4..a6fc2a88d3b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -214,7 +214,8 @@ /***/ typedef struct OldNew { - void *old, *newp; + const void *old; + void *newp; int nr; } OldNew; @@ -292,7 +293,7 @@ static void oldnewmap_sort(FileData *fd) } /* nr is zero for data, and ID code for libdata */ -static void oldnewmap_insert(OldNewMap *onm, void *oldaddr, void *newaddr, int nr) +static void oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr, int nr) { OldNew *entry; @@ -309,7 +310,7 @@ static void oldnewmap_insert(OldNewMap *onm, void *oldaddr, void *newaddr, int n entry->nr = nr; } -void blo_do_versions_oldnewmap_insert(OldNewMap *onm, void *oldaddr, void *newaddr, int nr) +void blo_do_versions_oldnewmap_insert(OldNewMap *onm, const void *oldaddr, void *newaddr, int nr) { oldnewmap_insert(onm, oldaddr, newaddr, nr); } @@ -364,7 +365,7 @@ static int oldnewmap_lookup_entry_full(const OldNewMap *onm, const void *addr, i return -1; } -static void *oldnewmap_lookup_and_inc(OldNewMap *onm, void *addr, bool increase_users) +static void *oldnewmap_lookup_and_inc(OldNewMap *onm, const void *addr, bool increase_users) { int i; @@ -394,7 +395,7 @@ static void *oldnewmap_lookup_and_inc(OldNewMap *onm, void *addr, bool increase_ } /* for libdata, nr has ID code, no increment */ -static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib) +static void *oldnewmap_liblookup(OldNewMap *onm, const void *addr, const void *lib) { if (addr == NULL) { return NULL; @@ -402,11 +403,8 @@ static void *oldnewmap_liblookup(OldNewMap *onm, void *addr, void *lib) /* lasthit works fine for non-libdata, linking there is done in same sequence as writing */ if (onm->sorted) { - OldNew entry_s, *entry; - - entry_s.old = addr; - - entry = bsearch(&entry_s, onm->entries, onm->nentries, sizeof(OldNew), verg_oldnewmap); + const OldNew entry_s = {.old = addr}; + OldNew *entry = bsearch(&entry_s, onm->entries, onm->nentries, sizeof(OldNew), verg_oldnewmap); if (entry) { ID *id = entry->newp; @@ -1413,7 +1411,7 @@ BlendThumbnail *BLO_thumbnail_from_file(const char *filepath) /* ************** OLD POINTERS ******************* */ -static void *newdataadr(FileData *fd, void *adr) /* only direct databocks */ +static void *newdataadr(FileData *fd, const void *adr) /* only direct databocks */ { return oldnewmap_lookup_and_inc(fd->datamap, adr, true); } @@ -1430,7 +1428,7 @@ static void *newdataadr(FileData *fd, void *adr) /* only direct databocks */ * fcurve group pointer and keeps lasthit optimal for linking all further * fcurves. */ -static void *newdataadr_ex(FileData *fd, void *adr, bool increase_lasthit) /* only direct databocks */ +static void *newdataadr_ex(FileData *fd, const void *adr, bool increase_lasthit) /* only direct databocks */ { if (increase_lasthit) { return newdataadr(fd, adr); @@ -1443,38 +1441,38 @@ static void *newdataadr_ex(FileData *fd, void *adr, bool increase_lasthit) /* o } } -static void *newdataadr_no_us(FileData *fd, void *adr) /* only direct databocks */ +static void *newdataadr_no_us(FileData *fd, const void *adr) /* only direct databocks */ { return oldnewmap_lookup_and_inc(fd->datamap, adr, false); } -static void *newglobadr(FileData *fd, void *adr) /* direct datablocks with global linking */ +static void *newglobadr(FileData *fd, const void *adr) /* direct datablocks with global linking */ { return oldnewmap_lookup_and_inc(fd->globmap, adr, true); } -static void *newimaadr(FileData *fd, void *adr) /* used to restore image data after undo */ +static void *newimaadr(FileData *fd, const void *adr) /* used to restore image data after undo */ { if (fd->imamap && adr) return oldnewmap_lookup_and_inc(fd->imamap, adr, true); return NULL; } -static void *newmclipadr(FileData *fd, void *adr) /* used to restore movie clip data after undo */ +static void *newmclipadr(FileData *fd, const void *adr) /* used to restore movie clip data after undo */ { if (fd->movieclipmap && adr) return oldnewmap_lookup_and_inc(fd->movieclipmap, adr, true); return NULL; } -static void *newsoundadr(FileData *fd, void *adr) /* used to restore sound data after undo */ +static void *newsoundadr(FileData *fd, const void *adr) /* used to restore sound data after undo */ { if (fd->soundmap && adr) return oldnewmap_lookup_and_inc(fd->soundmap, adr, true); return NULL; } -static void *newpackedadr(FileData *fd, void *adr) /* used to restore packed data after undo */ +static void *newpackedadr(FileData *fd, const void *adr) /* used to restore packed data after undo */ { if (fd->packedmap && adr) return oldnewmap_lookup_and_inc(fd->packedmap, adr, true); @@ -1483,17 +1481,17 @@ static void *newpackedadr(FileData *fd, void *adr) /* used to restore packe } -static void *newlibadr(FileData *fd, void *lib, void *adr) /* only lib data */ +static void *newlibadr(FileData *fd, const void *lib, const void *adr) /* only lib data */ { return oldnewmap_liblookup(fd->libmap, adr, lib); } -void *blo_do_versions_newlibadr(FileData *fd, void *lib, void *adr) /* only lib data */ +void *blo_do_versions_newlibadr(FileData *fd, const void *lib, const void *adr) /* only lib data */ { return newlibadr(fd, lib, adr); } -static void *newlibadr_us(FileData *fd, void *lib, void *adr) /* increases user number */ +static void *newlibadr_us(FileData *fd, const void *lib, const void *adr) /* increases user number */ { ID *id = newlibadr(fd, lib, adr); @@ -1502,12 +1500,12 @@ static void *newlibadr_us(FileData *fd, void *lib, void *adr) /* increases user return id; } -void *blo_do_versions_newlibadr_us(FileData *fd, void *lib, void *adr) /* increases user number */ +void *blo_do_versions_newlibadr_us(FileData *fd, const void *lib, const void *adr) /* increases user number */ { return newlibadr_us(fd, lib, adr); } -static void change_idid_adr_fd(FileData *fd, void *old, void *new) +static void change_idid_adr_fd(FileData *fd, const void *old, void *new) { int i; @@ -7892,8 +7890,8 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short /* In undo case, most libs and linked data should be kept as is from previous state (see BLO_read_from_memfile). * However, some needed by the snapshot being read may have been removed in previous one, and would go missing. * This leads e.g. to desappearing objects in some undo/redo case, see T34446. - * That means we have to carefully check whether current lib or libdata already exits in old main, if it does - * we merely copy it over into new main area, otherwise we have to do a full read of that bhead... */ + * That means we have to carefully check whether current lib or libdata already exits in old main, if it does + * we merely copy it over into new main area, otherwise we have to do a full read of that bhead... */ if (fd->memfile && ELEM(bhead->code, ID_LI, ID_ID)) { const char *idname = bhead_id_name(fd, bhead); diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index f5c19f5ee22..42728fd406f 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -156,9 +156,9 @@ const char *bhead_id_name(const FileData *fd, const BHead *bhead); void blo_reportf_wrap(struct ReportList *reports, ReportType type, const char *format, ...) ATTR_PRINTF_FORMAT(3, 4); -void blo_do_versions_oldnewmap_insert(struct OldNewMap *onm, void *oldaddr, void *newaddr, int nr); -void *blo_do_versions_newlibadr(struct FileData *fd, void *lib, void *adr); -void *blo_do_versions_newlibadr_us(struct FileData *fd, void *lib, void *adr); +void blo_do_versions_oldnewmap_insert(struct OldNewMap *onm, const void *oldaddr, void *newaddr, int nr); +void *blo_do_versions_newlibadr(struct FileData *fd, const void *lib, const void *adr); +void *blo_do_versions_newlibadr_us(struct FileData *fd, const void *lib, const void *adr); struct PartEff *blo_do_version_give_parteff_245(struct Object *ob); void blo_do_version_old_trackto_to_constraints(struct Object *ob); -- cgit v1.2.3 From 5d45ffc755e3c7961cadd007e7440ec1fe8b6dbe Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Jun 2016 19:03:09 +1000 Subject: readfile: minor optimization, no need to count flags in this case we only need to check if any id's need to be read. --- source/blender/blenloader/intern/readfile.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index a6fc2a88d3b..df36def5ba1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -9990,21 +9990,22 @@ void *BLO_library_read_struct(FileData *fd, BHead *bh, const char *blockname) /* ************* READ LIBRARY ************** */ -static int mainvar_count_libread_blocks(Main *mainvar) +static int mainvar_id_tag_any_check(Main *mainvar, const short tag) { ListBase *lbarray[MAX_LIBARRAY]; - int a, tot = 0; + int a; a = set_listbasepointers(mainvar, lbarray); while (a--) { ID *id; for (id = lbarray[a]->first; id; id = id->next) { - if (id->tag & LIB_TAG_READ) - tot++; + if (id->tag & tag) { + return true; + } } } - return tot; + return false; } static void read_libraries(FileData *basefd, ListBase *mainlist) @@ -10024,10 +10025,9 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) /* test 1: read libdata */ mainptr= mainl->next; while (mainptr) { - int tot = mainvar_count_libread_blocks(mainptr); - - // printf("found LIB_TAG_READ %s\n", mainptr->curlib->name); - if (tot) { + if (mainvar_id_tag_any_check(mainptr, LIB_TAG_READ)) { + // printf("found LIB_TAG_READ %s\n", mainptr->curlib->name); + FileData *fd = mainptr->curlib->filedata; if (fd == NULL) { -- cgit v1.2.3 From 24049c8196ccb88eadc5930e780151c1c0da6a27 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 6 Jun 2016 19:09:46 +1000 Subject: readfile: add assert to check libmap isn't sorted --- source/blender/blenloader/intern/readfile.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index df36def5ba1..96a9c4442d9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -222,7 +222,7 @@ typedef struct OldNew { typedef struct OldNewMap { OldNew *entries; int nentries, entriessize; - int sorted; + bool sorted; int lasthit; } OldNewMap; @@ -288,6 +288,7 @@ static int verg_oldnewmap(const void *v1, const void *v2) static void oldnewmap_sort(FileData *fd) { + BLI_assert(fd->libmap->sorted == false); qsort(fd->libmap->entries, fd->libmap->nentries, sizeof(OldNew), verg_oldnewmap); fd->libmap->sorted = 1; } @@ -1509,6 +1510,9 @@ static void change_idid_adr_fd(FileData *fd, const void *old, void *new) { int i; + /* use a binary search if we have a sorted libmap, for now it's not needed. */ + BLI_assert(fd->libmap->sorted == false); + for (i = 0; i < fd->libmap->nentries; i++) { OldNew *entry = &fd->libmap->entries[i]; -- cgit v1.2.3 From ac7feaed3d4d80c60557b3c4af5eee65bef2e4ec Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 6 Jun 2016 21:41:17 +0200 Subject: EditNormal modifier: add some 'maximum angle' limit. Allows to avoid generating flipped faces when using extreme normal modifications. Related to T48576. --- source/blender/blenloader/intern/versioning_270.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 0ea4078a5cb..b7b6ace3c1a 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1189,9 +1189,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } - } - { for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) { if (camera->stereo.pole_merge_angle_from == 0.0f && camera->stereo.pole_merge_angle_to == 0.0f) @@ -1200,5 +1198,19 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) camera->stereo.pole_merge_angle_to = DEG2RAD(75.0f); } } + + if (!DNA_struct_elem_find(fd->filesdna, "NormalEditModifierData", "float", "mix_limit")) { + Object *ob; + + for (ob = main->object.first; ob; ob = ob->id.next) { + ModifierData *md; + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_NormalEdit) { + NormalEditModifierData *nemd = (NormalEditModifierData *)md; + nemd->mix_limit = DEG2RADF(180.0f); + } + } + } + } } } -- cgit v1.2.3 From 2d9d17c031cc651fde2c78e37452e99c9ee6fb77 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Jun 2016 01:54:59 +1000 Subject: readfile: avoid library lookups for every id on undo Instead index libraries, makes minor speedup when using many libraries. --- source/blender/blenloader/intern/readfile.c | 54 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 96a9c4442d9..fd105f6aafa 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -485,53 +485,57 @@ void blo_join_main(ListBase *mainlist) } } -static void split_libdata(ListBase *lb, Main *first) +static void split_libdata(ListBase *lb_src, Main **lib_main_array, const unsigned int lib_main_array_len) { - ListBase *lbn; - ID *id, *idnext; - Main *mainvar; - - id = lb->first; - while (id) { + for (ID *id = lb_src->first, *idnext; id; id = idnext) { idnext = id->next; + if (id->lib) { - mainvar = first; - while (mainvar) { - if (mainvar->curlib == id->lib) { - lbn= which_libbase(mainvar, GS(id->name)); - BLI_remlink(lb, id); - BLI_addtail(lbn, id); - break; - } - mainvar = mainvar->next; + if (((unsigned int)id->lib->temp_index < lib_main_array_len) && + /* this check should never fail, just incase 'id->lib' is a dangling pointer. */ + (lib_main_array[id->lib->temp_index]->curlib == id->lib)) + { + Main *mainvar = lib_main_array[id->lib->temp_index]; + ListBase *lb_dst = which_libbase(mainvar, GS(id->name)); + BLI_remlink(lb_src, id); + BLI_addtail(lb_dst, id); + } + else { + printf("%s: invalid library for '%s'\n", __func__, id->name); + BLI_assert(0); } - if (mainvar == NULL) printf("error split_libdata\n"); } - id = idnext; } } void blo_split_main(ListBase *mainlist, Main *main) { - ListBase *lbarray[MAX_LIBARRAY]; - Library *lib; - int i; - mainlist->first = mainlist->last = main; main->next = NULL; if (BLI_listbase_is_empty(&main->library)) return; - for (lib = main->library.first; lib; lib = lib->id.next) { + /* (Library.temp_index -> Main), lookup table */ + const unsigned int lib_main_array_len = BLI_listbase_count(&main->library); + Main **lib_main_array = MEM_mallocN(lib_main_array_len * sizeof(*lib_main_array), __func__); + + int i = 0; + for (Library *lib = main->library.first; lib; lib = lib->id.next, i++) { Main *libmain = BKE_main_new(); libmain->curlib = lib; BLI_addtail(mainlist, libmain); + lib->temp_index = i; + lib_main_array[i] = libmain; } + ListBase *lbarray[MAX_LIBARRAY]; i = set_listbasepointers(main, lbarray); - while (i--) - split_libdata(lbarray[i], main->next); + while (i--) { + split_libdata(lbarray[i], lib_main_array, lib_main_array_len); + } + + MEM_freeN(lib_main_array); } static void read_file_version(FileData *fd, Main *main) -- cgit v1.2.3 From 441a440cbbb700511d6d1ec01e2f149355adcc02 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Jun 2016 16:07:13 +1000 Subject: readfile: optimization for undo Was using O(n^2) lookup on ID's with undo. This caused undo to hang with 1000's of data-blocks (especially with heavy scenes & outliner-space, which doesn't even need to be visible to cause a slow-down). Internally this uses a ghash per id-type, which is lazy-initialized. Each key uses the name and library since there may be name collisions between libraries. Developer Notes: - Adds small `BKE_main_idmap_*` API. - Needed to change linking order for this to build. --- source/blender/blenloader/intern/readfile.c | 156 +++++++++++++++++----------- 1 file changed, 96 insertions(+), 60 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index fd105f6aafa..621088c5a3c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -124,6 +124,7 @@ #include "BKE_global.h" // for G #include "BKE_group.h" #include "BKE_library.h" // for which_libbase +#include "BKE_library_idmap.h" #include "BKE_library_query.h" #include "BKE_idcode.h" #include "BKE_material.h" @@ -211,6 +212,9 @@ /* use GHash for BHead name-based lookups (speeds up linking) */ #define USE_GHASH_BHEAD +/* Use GHash for restoring pointers by name */ +#define USE_GHASH_RESTORE_POINTER + /***/ typedef struct OldNew { @@ -6389,68 +6393,96 @@ typedef enum ePointerUserMode { USER_REAL = 1, /* ensure at least one real user (fake user ignored) */ } ePointerUserMode; -static bool restore_pointer(ID *id, ID *newid, ePointerUserMode user) +static void restore_pointer_user(ID *id, ID *newid, ePointerUserMode user) { - if (STREQ(newid->name + 2, id->name + 2)) { - if (newid->lib == id->lib) { - if (user == USER_REAL) { - id_us_ensure_real(newid); + BLI_assert(STREQ(newid->name + 2, id->name + 2)); + BLI_assert(newid->lib == id->lib); + UNUSED_VARS_NDEBUG(id); + + if (user == USER_REAL) { + id_us_ensure_real(newid); + } +} + +#ifndef USE_GHASH_RESTORE_POINTER +/** + * A version of #restore_pointer_by_name that performs a full search (slow!). + * Use only for limited lookups, when the overhead of + * creating a #IDNameLib_Map for a single lookup isn't worthwhile. + */ +static void *restore_pointer_by_name_main(Main *mainp, ID *id, ePointerUserMode user) +{ + if (id) { + ListBase *lb = which_libbase(mainp, GS(id->name)); + if (lb) { /* there's still risk of checking corrupt mem (freed Ids in oops) */ + ID *idn = lb->first; + for (; idn; idn = idn->next) { + if (STREQ(idn->name + 2, id->name + 2)) { + if (idn->lib == id->lib) { + restore_pointer_user(id, idn, user); + break; + } + } } - return true; + return idn; } } - return false; + return NULL; } +#endif /** * Only for undo files, or to restore a screen after reading without UI... * - * user + * \param user: * - USER_IGNORE: no usercount change * - USER_REAL: ensure a real user (even if a fake one is set) + * \param id_map: lookup table, use when performing many lookups. + * this could be made an optional agument (falling back to a full lookup), + * however at the moment it's always available. */ -static void *restore_pointer_by_name(Main *mainp, ID *id, ePointerUserMode user) +static void *restore_pointer_by_name(struct IDNameLib_Map *id_map, ID *id, ePointerUserMode user) { +#ifdef USE_GHASH_RESTORE_POINTER if (id) { - ListBase *lb = which_libbase(mainp, GS(id->name)); - if (lb) { // there's still risk of checking corrupt mem (freed Ids in oops) - ID *idn = lb->first; - - for (; idn; idn = idn->next) { - if (restore_pointer(id, idn, user)) - break; - } - - return idn; + /* use fast lookup when available */ + ID *idn = BKE_main_idmap_lookup_id(id_map, id); + if (idn) { + restore_pointer_user(id, idn, user); } + return idn; } return NULL; +#else + Main *mainp = BKE_main_idmap_main_get(id_map); + return restore_pointer_by_name_main(mainp, id, user); +#endif } -static void lib_link_seq_clipboard_pt_restore(ID *id, Main *newmain) +static void lib_link_seq_clipboard_pt_restore(ID *id, struct IDNameLib_Map *id_map) { if (id) { /* clipboard must ensure this */ BLI_assert(id->newid != NULL); - id->newid = restore_pointer_by_name(newmain, (ID *)id->newid, USER_REAL); + id->newid = restore_pointer_by_name(id_map, id->newid, USER_REAL); } } static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) { - Main *newmain = (Main *)arg_pt; + struct IDNameLib_Map *id_map = arg_pt; - lib_link_seq_clipboard_pt_restore((ID *)seq->scene, newmain); - lib_link_seq_clipboard_pt_restore((ID *)seq->scene_camera, newmain); - lib_link_seq_clipboard_pt_restore((ID *)seq->clip, newmain); - lib_link_seq_clipboard_pt_restore((ID *)seq->mask, newmain); - lib_link_seq_clipboard_pt_restore((ID *)seq->sound, newmain); + lib_link_seq_clipboard_pt_restore((ID *)seq->scene, id_map); + lib_link_seq_clipboard_pt_restore((ID *)seq->scene_camera, id_map); + lib_link_seq_clipboard_pt_restore((ID *)seq->clip, id_map); + lib_link_seq_clipboard_pt_restore((ID *)seq->mask, id_map); + lib_link_seq_clipboard_pt_restore((ID *)seq->sound, id_map); return 1; } -static void lib_link_clipboard_restore(Main *newmain) +static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map) { /* update IDs stored in sequencer clipboard */ - BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain); + BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map); } /* called from kernel/blender.c */ @@ -6462,11 +6494,13 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc wmWindowManager *wm; bScreen *sc; ScrArea *sa; - + + struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain); + /* first windowmanager */ for (wm = newmain->wm.first; wm; wm = wm->id.next) { for (win= wm->windows.first; win; win= win->next) { - win->screen = restore_pointer_by_name(newmain, (ID *)win->screen, USER_REAL); + win->screen = restore_pointer_by_name(id_map, (ID *)win->screen, USER_REAL); if (win->screen == NULL) win->screen = curscreen; @@ -6479,7 +6513,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc for (sc = newmain->screen.first; sc; sc = sc->id.next) { Scene *oldscene = sc->scene; - sc->scene= restore_pointer_by_name(newmain, (ID *)sc->scene, USER_REAL); + sc->scene= restore_pointer_by_name(id_map, (ID *)sc->scene, USER_REAL); if (sc->scene == NULL) sc->scene = curscene; @@ -6498,16 +6532,16 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc if (v3d->scenelock) v3d->camera = NULL; /* always get from scene */ else - v3d->camera = restore_pointer_by_name(newmain, (ID *)v3d->camera, USER_REAL); + v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL); if (v3d->camera == NULL) v3d->camera = sc->scene->camera; - v3d->ob_centre = restore_pointer_by_name(newmain, (ID *)v3d->ob_centre, USER_REAL); + v3d->ob_centre = restore_pointer_by_name(id_map, (ID *)v3d->ob_centre, USER_REAL); for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) { - if ((bgpic->ima = restore_pointer_by_name(newmain, (ID *)bgpic->ima, USER_IGNORE))) { + if ((bgpic->ima = restore_pointer_by_name(id_map, (ID *)bgpic->ima, USER_IGNORE))) { id_us_plus((ID *)bgpic->ima); } - if ((bgpic->clip = restore_pointer_by_name(newmain, (ID *)bgpic->clip, USER_IGNORE))) { + if ((bgpic->clip = restore_pointer_by_name(id_map, (ID *)bgpic->clip, USER_IGNORE))) { id_us_plus((ID *)bgpic->clip); } } @@ -6551,10 +6585,10 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc bDopeSheet *ads = sipo->ads; if (ads) { - ads->source = restore_pointer_by_name(newmain, (ID *)ads->source, USER_REAL); + ads->source = restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL); if (ads->filter_grp) - ads->filter_grp = restore_pointer_by_name(newmain, (ID *)ads->filter_grp, USER_IGNORE); + ads->filter_grp = restore_pointer_by_name(id_map, (ID *)ads->filter_grp, USER_IGNORE); } /* force recalc of list of channels (i.e. includes calculating F-Curve colors) @@ -6564,7 +6598,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc } else if (sl->spacetype == SPACE_BUTS) { SpaceButs *sbuts = (SpaceButs *)sl; - sbuts->pinid = restore_pointer_by_name(newmain, sbuts->pinid, USER_IGNORE); + sbuts->pinid = restore_pointer_by_name(id_map, sbuts->pinid, USER_IGNORE); if (sbuts->pinid == NULL) { sbuts->flag &= ~SB_PIN_CONTEXT; } @@ -6581,11 +6615,11 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc else if (sl->spacetype == SPACE_ACTION) { SpaceAction *saction = (SpaceAction *)sl; - saction->action = restore_pointer_by_name(newmain, (ID *)saction->action, USER_REAL); - saction->ads.source = restore_pointer_by_name(newmain, (ID *)saction->ads.source, USER_REAL); + saction->action = restore_pointer_by_name(id_map, (ID *)saction->action, USER_REAL); + saction->ads.source = restore_pointer_by_name(id_map, (ID *)saction->ads.source, USER_REAL); if (saction->ads.filter_grp) - saction->ads.filter_grp = restore_pointer_by_name(newmain, (ID *)saction->ads.filter_grp, USER_IGNORE); + saction->ads.filter_grp = restore_pointer_by_name(id_map, (ID *)saction->ads.filter_grp, USER_IGNORE); /* force recalc of list of channels, potentially updating the active action @@ -6596,7 +6630,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc else if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; - sima->image = restore_pointer_by_name(newmain, (ID *)sima->image, USER_REAL); + sima->image = restore_pointer_by_name(id_map, (ID *)sima->image, USER_REAL); /* this will be freed, not worth attempting to find same scene, * since it gets initialized later */ @@ -6611,8 +6645,8 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data * so assume that here we're doing for undo only... */ - sima->gpd = restore_pointer_by_name(newmain, (ID *)sima->gpd, USER_REAL); - sima->mask_info.mask = restore_pointer_by_name(newmain, (ID *)sima->mask_info.mask, USER_REAL); + sima->gpd = restore_pointer_by_name(id_map, (ID *)sima->gpd, USER_REAL); + sima->mask_info.mask = restore_pointer_by_name(id_map, (ID *)sima->mask_info.mask, USER_REAL); } else if (sl->spacetype == SPACE_SEQ) { SpaceSeq *sseq = (SpaceSeq *)sl; @@ -6620,29 +6654,29 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data * so assume that here we're doing for undo only... */ - sseq->gpd = restore_pointer_by_name(newmain, (ID *)sseq->gpd, USER_REAL); + sseq->gpd = restore_pointer_by_name(id_map, (ID *)sseq->gpd, USER_REAL); } else if (sl->spacetype == SPACE_NLA) { SpaceNla *snla = (SpaceNla *)sl; bDopeSheet *ads = snla->ads; if (ads) { - ads->source = restore_pointer_by_name(newmain, (ID *)ads->source, USER_REAL); + ads->source = restore_pointer_by_name(id_map, (ID *)ads->source, USER_REAL); if (ads->filter_grp) - ads->filter_grp = restore_pointer_by_name(newmain, (ID *)ads->filter_grp, USER_IGNORE); + ads->filter_grp = restore_pointer_by_name(id_map, (ID *)ads->filter_grp, USER_IGNORE); } } else if (sl->spacetype == SPACE_TEXT) { SpaceText *st = (SpaceText *)sl; - st->text = restore_pointer_by_name(newmain, (ID *)st->text, USER_REAL); + st->text = restore_pointer_by_name(id_map, (ID *)st->text, USER_REAL); if (st->text == NULL) st->text = newmain->text.first; } else if (sl->spacetype == SPACE_SCRIPT) { SpaceScript *scpt = (SpaceScript *)sl; - scpt->script = restore_pointer_by_name(newmain, (ID *)scpt->script, USER_REAL); + scpt->script = restore_pointer_by_name(id_map, (ID *)scpt->script, USER_REAL); /*sc->script = NULL; - 2.45 set to null, better re-run the script */ if (scpt->script) { @@ -6652,7 +6686,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc else if (sl->spacetype == SPACE_OUTLINER) { SpaceOops *so= (SpaceOops *)sl; - so->search_tse.id = restore_pointer_by_name(newmain, so->search_tse.id, USER_IGNORE); + so->search_tse.id = restore_pointer_by_name(id_map, so->search_tse.id, USER_IGNORE); if (so->treestore) { TreeStoreElem *tselem; @@ -6662,7 +6696,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc while ((tselem = BLI_mempool_iterstep(&iter))) { /* Do not try to restore pointers to drivers/sequence/etc., can crash in undo case! */ if (TSE_IS_REAL_ID(tselem)) { - tselem->id = restore_pointer_by_name(newmain, tselem->id, USER_IGNORE); + tselem->id = restore_pointer_by_name(id_map, tselem->id, USER_IGNORE); } else { tselem->id = NULL; @@ -6680,14 +6714,14 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc bNodeTree *ntree; /* node tree can be stored locally in id too, link this first */ - snode->id = restore_pointer_by_name(newmain, snode->id, USER_REAL); - snode->from = restore_pointer_by_name(newmain, snode->from, USER_IGNORE); + snode->id = restore_pointer_by_name(id_map, snode->id, USER_REAL); + snode->from = restore_pointer_by_name(id_map, snode->from, USER_IGNORE); ntree = nodetree_from_id(snode->id); if (ntree) snode->nodetree = ntree; else - snode->nodetree = restore_pointer_by_name(newmain, (ID*)snode->nodetree, USER_REAL); + snode->nodetree = restore_pointer_by_name(id_map, (ID*)snode->nodetree, USER_REAL); for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { @@ -6695,7 +6729,7 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc path->nodetree = snode->nodetree; } else - path->nodetree= restore_pointer_by_name(newmain, (ID*)path->nodetree, USER_REAL); + path->nodetree= restore_pointer_by_name(id_map, (ID*)path->nodetree, USER_REAL); if (!path->nodetree) break; @@ -6721,22 +6755,24 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc else if (sl->spacetype == SPACE_CLIP) { SpaceClip *sclip = (SpaceClip *)sl; - sclip->clip = restore_pointer_by_name(newmain, (ID *)sclip->clip, USER_REAL); - sclip->mask_info.mask = restore_pointer_by_name(newmain, (ID *)sclip->mask_info.mask, USER_REAL); + sclip->clip = restore_pointer_by_name(id_map, (ID *)sclip->clip, USER_REAL); + sclip->mask_info.mask = restore_pointer_by_name(id_map, (ID *)sclip->mask_info.mask, USER_REAL); sclip->scopes.ok = 0; } else if (sl->spacetype == SPACE_LOGIC) { SpaceLogic *slogic = (SpaceLogic *)sl; - slogic->gpd = restore_pointer_by_name(newmain, (ID *)slogic->gpd, USER_REAL); + slogic->gpd = restore_pointer_by_name(id_map, (ID *)slogic->gpd, USER_REAL); } } } } /* update IDs stored in all possible clipboards */ - lib_link_clipboard_restore(newmain); + lib_link_clipboard_restore(id_map); + + BKE_main_idmap_destroy(id_map); } static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) -- cgit v1.2.3 From c7e7c1b24168078dcec6c7affdd749bf2750afd9 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 14 Jun 2016 14:53:39 +0200 Subject: Write .blend file: refactor & fixes re ID block itself. Factorized writing of ID block's data (so far, only IDProps) into own helper func. This also fixes missing IDProp (aka custom data) saving from GreasePencil and Library datablocks (and add comment about why we do not save WM IDProps). Finaly, it ensures all ID-related data are written immediately after the ID itself (was not the case for all data types previously, some were writting their own data before IDProps). This is not a fix (.blend file format does not enforce any order on sub-data of datablocks, they only have to be after datablock struct itself in file), but makes things more consistent. --- source/blender/blenloader/intern/writefile.c | 235 ++++++++++++++------------- 1 file changed, 120 insertions(+), 115 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 124b1efddac..327b7b5aed4 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -588,6 +588,14 @@ void IDP_WriteProperty(IDProperty *prop, void *wd) IDP_WriteProperty_OnlyData(prop, wd); } +static void write_iddata(void *wd, ID *id) +{ + /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */ + if (id->properties && !ELEM(GS(id->name), ID_WM)) { + IDP_WriteProperty(id->properties, wd); + } +} + static void write_previews(WriteData *wd, PreviewImage *prv) { /* Never write previews when doing memsave (i.e. undo/redo)! */ @@ -716,8 +724,8 @@ static void write_actions(WriteData *wd, ListBase *idbase) for (act=idbase->first; act; act= act->id.next) { if (act->id.us>0 || wd->current) { writestruct(wd, ID_AC, "bAction", 1, act); - if (act->id.properties) IDP_WriteProperty(act->id.properties, wd); - + write_iddata(wd, &act->id); + write_fcurves(wd, &act->curves); for (grp=act->groups.first; grp; grp=grp->next) { @@ -1155,7 +1163,8 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) if (part->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_PA, "ParticleSettings", 1, part); - if (part->id.properties) IDP_WriteProperty(part->id.properties, wd); + write_iddata(wd, &part->id); + if (part->adt) write_animdata(wd, part->adt); writestruct(wd, DATA, "PartDeflect", 1, part->pd); writestruct(wd, DATA, "PartDeflect", 1, part->pd2); @@ -1668,11 +1677,8 @@ static void write_objects(WriteData *wd, ListBase *idbase) if (ob->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_OB, "Object", 1, ob); - - /* Write ID Properties -- and copy this comment EXACTLY for easy finding - * of library blocks that implement this.*/ - if (ob->id.properties) IDP_WriteProperty(ob->id.properties, wd); - + write_iddata(wd, &ob->id); + if (ob->adt) write_animdata(wd, ob->adt); /* direct data */ @@ -1743,7 +1749,7 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) if (vf->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_VF, "VFont", 1, vf); - if (vf->id.properties) IDP_WriteProperty(vf->id.properties, wd); + write_iddata(wd, &vf->id); /* direct data */ @@ -1769,8 +1775,8 @@ static void write_keys(WriteData *wd, ListBase *idbase) if (key->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_KE, "Key", 1, key); - if (key->id.properties) IDP_WriteProperty(key->id.properties, wd); - + write_iddata(wd, &key->id); + if (key->adt) write_animdata(wd, key->adt); /* direct data */ @@ -1797,8 +1803,8 @@ static void write_cameras(WriteData *wd, ListBase *idbase) if (cam->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_CA, "Camera", 1, cam); - if (cam->id.properties) IDP_WriteProperty(cam->id.properties, wd); - + write_iddata(wd, &cam->id); + if (cam->adt) write_animdata(wd, cam->adt); } @@ -1816,7 +1822,7 @@ static void write_mballs(WriteData *wd, ListBase *idbase) if (mb->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_MB, "MetaBall", 1, mb); - if (mb->id.properties) IDP_WriteProperty(mb->id.properties, wd); + write_iddata(wd, &mb->id); /* direct data */ writedata(wd, DATA, sizeof(void *)*mb->totcol, mb->mat); @@ -1842,10 +1848,10 @@ static void write_curves(WriteData *wd, ListBase *idbase) if (cu->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_CU, "Curve", 1, cu); - + write_iddata(wd, &cu->id); + /* direct data */ writedata(wd, DATA, sizeof(void *)*cu->totcol, cu->mat); - if (cu->id.properties) IDP_WriteProperty(cu->id.properties, wd); if (cu->adt) write_animdata(wd, cu->adt); if (cu->vfont) { @@ -2037,9 +2043,9 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + write_iddata(wd, &mesh->id); /* direct data */ - if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd); if (mesh->adt) write_animdata(wd, mesh->adt); writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); @@ -2095,9 +2101,9 @@ static void write_meshes(WriteData *wd, ListBase *idbase) #endif writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + write_iddata(wd, &mesh->id); /* direct data */ - if (mesh->id.properties) IDP_WriteProperty(mesh->id.properties, wd); if (mesh->adt) write_animdata(wd, mesh->adt); writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); @@ -2150,8 +2156,8 @@ static void write_lattices(WriteData *wd, ListBase *idbase) if (lt->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_LT, "Lattice", 1, lt); - if (lt->id.properties) IDP_WriteProperty(lt->id.properties, wd); - + write_iddata(wd, <->id); + /* write animdata */ if (lt->adt) write_animdata(wd, lt->adt); @@ -2184,7 +2190,7 @@ static void write_images(WriteData *wd, ListBase *idbase) /* write LibData */ writestruct(wd, ID_IM, "Image", 1, ima); - if (ima->id.properties) IDP_WriteProperty(ima->id.properties, wd); + write_iddata(wd, &ima->id); for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { writestruct(wd, DATA, "ImagePackedFile", 1, imapf); @@ -2218,7 +2224,7 @@ static void write_textures(WriteData *wd, ListBase *idbase) if (tex->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_TE, "Tex", 1, tex); - if (tex->id.properties) IDP_WriteProperty(tex->id.properties, wd); + write_iddata(wd, &tex->id); if (tex->adt) write_animdata(wd, tex->adt); @@ -2258,13 +2264,8 @@ static void write_materials(WriteData *wd, ListBase *idbase) if (ma->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_MA, "Material", 1, ma); - - /* Write ID Properties -- and copy this comment EXACTLY for easy finding - * of library blocks that implement this.*/ - /* manually set head group property to IDP_GROUP, just in case it hadn't been - * set yet :) */ - if (ma->id.properties) IDP_WriteProperty(ma->id.properties, wd); - + write_iddata(wd, &ma->id); + if (ma->adt) write_animdata(wd, ma->adt); for (a=0; aid.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_WO, "World", 1, wrld); - if (wrld->id.properties) IDP_WriteProperty(wrld->id.properties, wd); - + write_iddata(wd, &wrld->id); + if (wrld->adt) write_animdata(wd, wrld->adt); for (a=0; aid.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_LA, "Lamp", 1, la); - if (la->id.properties) IDP_WriteProperty(la->id.properties, wd); - + write_iddata(wd, &la->id); + if (la->adt) write_animdata(wd, la->adt); /* direct data */ @@ -2411,8 +2412,8 @@ static void write_scenes(WriteData *wd, ListBase *scebase) while (sce) { /* write LibData */ writestruct(wd, ID_SCE, "Scene", 1, sce); - if (sce->id.properties) IDP_WriteProperty(sce->id.properties, wd); - + write_iddata(wd, &sce->id); + if (sce->adt) write_animdata(wd, sce->adt); write_keyingsets(wd, &sce->keyingsets); @@ -2593,7 +2594,8 @@ static void write_gpencils(WriteData *wd, ListBase *lb) if (gpd->id.us>0 || wd->current) { /* write gpd data block to file */ writestruct(wd, ID_GD, "bGPdata", 1, gpd); - + write_iddata(wd, &gpd->id); + if (gpd->adt) write_animdata(wd, gpd->adt); /* write grease-pencil layers to file */ @@ -2622,7 +2624,8 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) for (wm= lb->first; wm; wm= wm->id.next) { writestruct(wd, ID_WM, "wmWindowManager", 1, wm); - + write_iddata(wd, &wm->id); + for (win= wm->windows.first; win; win= win->next) { writestruct(wd, DATA, "wmWindow", 1, win); writestruct(wd, DATA, "Stereo3dFormat", 1, win->stereo3d_format); @@ -2722,9 +2725,8 @@ static void write_screens(WriteData *wd, ListBase *scrbase) /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ writestruct(wd, ID_SCRN, "Screen", 1, sc); - if (sc->id.properties) - IDP_WriteProperty(sc->id.properties, wd); - + write_iddata(wd, &sc->id); + /* direct data */ for (sv= sc->vertbase.first; sv; sv= sv->next) writestruct(wd, DATA, "ScrVert", 1, sv); @@ -2879,63 +2881,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase) mywrite(wd, MYWRITE_FLUSH, 0); } -static void write_libraries(WriteData *wd, Main *main) -{ - ListBase *lbarray[MAX_LIBARRAY]; - ID *id; - int a, tot; - bool found_one; - - for (; main; main= main->next) { - - a=tot= set_listbasepointers(main, lbarray); - - /* test: is lib being used */ - if (main->curlib && main->curlib->packedfile) - found_one = true; - else { - found_one = false; - while (tot--) { - for (id= lbarray[tot]->first; id; id= id->next) { - if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { - found_one = true; - break; - } - } - if (found_one) break; - } - } - - /* to be able to restore quit.blend and temp saves, the packed blend has to be in undo buffers... */ - /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the] - * quit.blend and temp saves */ - if (found_one) { - writestruct(wd, ID_LI, "Library", 1, main->curlib); - - if (main->curlib->packedfile) { - PackedFile *pf = main->curlib->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); - writedata(wd, DATA, pf->size, pf->data); - if (wd->current == NULL) - printf("write packed .blend: %s\n", main->curlib->name); - } - - while (a--) { - for (id= lbarray[a]->first; id; id= id->next) { - if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { - if (!BKE_idcode_is_linkable(GS(id->name))) { - printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable " - "but is flagged as directly linked", id->name, main->curlib->filepath); - BLI_assert(0); - } - writestruct(wd, ID_ID, "ID", 1, id); - } - } - } - } - } -} - static void write_bone(WriteData *wd, Bone *bone) { Bone* cbone; @@ -2968,7 +2913,7 @@ static void write_armatures(WriteData *wd, ListBase *idbase) while (arm) { if (arm->id.us>0 || wd->current) { writestruct(wd, ID_AR, "bArmature", 1, arm); - if (arm->id.properties) IDP_WriteProperty(arm->id.properties, wd); + write_iddata(wd, &arm->id); if (arm->adt) write_animdata(wd, arm->adt); @@ -2997,8 +2942,9 @@ static void write_texts(WriteData *wd, ListBase *idbase) /* write LibData */ writestruct(wd, ID_TXT, "Text", 1, text); + write_iddata(wd, &text->id); + if (text->name) writedata(wd, DATA, strlen(text->name)+1, text->name); - if (text->id.properties) IDP_WriteProperty(text->id.properties, wd); if (!(text->flags & TXT_ISEXT)) { /* now write the text data, in two steps for optimization in the readfunction */ @@ -3032,7 +2978,7 @@ static void write_speakers(WriteData *wd, ListBase *idbase) if (spk->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_SPK, "Speaker", 1, spk); - if (spk->id.properties) IDP_WriteProperty(spk->id.properties, wd); + write_iddata(wd, &spk->id); if (spk->adt) write_animdata(wd, spk->adt); } @@ -3051,7 +2997,7 @@ static void write_sounds(WriteData *wd, ListBase *idbase) if (sound->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_SO, "bSound", 1, sound); - if (sound->id.properties) IDP_WriteProperty(sound->id.properties, wd); + write_iddata(wd, &sound->id); if (sound->packedfile) { pf = sound->packedfile; @@ -3075,7 +3021,7 @@ static void write_groups(WriteData *wd, ListBase *idbase) if (group->id.us>0 || wd->current) { /* write LibData */ writestruct(wd, ID_GR, "Group", 1, group); - if (group->id.properties) IDP_WriteProperty(group->id.properties, wd); + write_iddata(wd, &group->id); write_previews(wd, group->preview); @@ -3095,11 +3041,11 @@ static void write_nodetrees(WriteData *wd, ListBase *idbase) for (ntree=idbase->first; ntree; ntree= ntree->id.next) { if (ntree->id.us>0 || wd->current) { writestruct(wd, ID_NT, "bNodeTree", 1, ntree); + /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot + * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ + write_iddata(wd, &ntree->id); + write_nodetree(wd, ntree); - - if (ntree->id.properties) IDP_WriteProperty(ntree->id.properties, wd); - - if (ntree->adt) write_animdata(wd, ntree->adt); } } } @@ -3178,8 +3124,8 @@ static void write_brushes(WriteData *wd, ListBase *idbase) for (brush=idbase->first; brush; brush= brush->id.next) { if (brush->id.us>0 || wd->current) { writestruct(wd, ID_BR, "Brush", 1, brush); - if (brush->id.properties) IDP_WriteProperty(brush->id.properties, wd); - + write_iddata(wd, &brush->id); + if (brush->curve) write_curvemapping(wd, brush->curve); if (brush->gradient) @@ -3196,7 +3142,7 @@ static void write_palettes(WriteData *wd, ListBase *idbase) if (palette->id.us > 0 || wd->current) { PaletteColor *color; writestruct(wd, ID_PAL, "Palette", 1, palette); - if (palette->id.properties) IDP_WriteProperty(palette->id.properties, wd); + write_iddata(wd, &palette->id); for (color = palette->colors.first; color; color= color->next) writestruct(wd, DATA, "PaletteColor", 1, color); @@ -3211,9 +3157,9 @@ static void write_paintcurves(WriteData *wd, ListBase *idbase) for (pc = idbase->first; pc; pc = pc->id.next) { if (pc->id.us > 0 || wd->current) { writestruct(wd, ID_PC, "PaintCurve", 1, pc); + write_iddata(wd, &pc->id); writestruct(wd, DATA, "PaintCurvePoint", pc->tot_points, pc->points); - if (pc->id.properties) IDP_WriteProperty(pc->id.properties, wd); } } } @@ -3263,10 +3209,9 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) if (clip->id.us>0 || wd->current) { MovieTracking *tracking= &clip->tracking; MovieTrackingObject *object; - writestruct(wd, ID_MC, "MovieClip", 1, clip); - if (clip->id.properties) - IDP_WriteProperty(clip->id.properties, wd); + writestruct(wd, ID_MC, "MovieClip", 1, clip); + write_iddata(wd, &clip->id); if (clip->adt) write_animdata(wd, clip->adt); @@ -3304,6 +3249,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) MaskLayer *masklay; writestruct(wd, ID_MSK, "Mask", 1, mask); + write_iddata(wd, &mask->id); if (mask->adt) write_animdata(wd, mask->adt); @@ -3609,8 +3555,8 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) for (linestyle = idbase->first; linestyle; linestyle = linestyle->id.next) { if (linestyle->id.us>0 || wd->current) { writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle); - if (linestyle->id.properties) - IDP_WriteProperty(linestyle->id.properties, wd); + write_iddata(wd, &linestyle->id); + if (linestyle->adt) write_animdata(wd, linestyle->adt); write_linestyle_color_modifiers(wd, &linestyle->color_modifiers); @@ -3628,6 +3574,65 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) } } +/* Keep it last of write_foodata functions. */ +static void write_libraries(WriteData *wd, Main *main) +{ + ListBase *lbarray[MAX_LIBARRAY]; + ID *id; + int a, tot; + bool found_one; + + for (; main; main= main->next) { + + a=tot= set_listbasepointers(main, lbarray); + + /* test: is lib being used */ + if (main->curlib && main->curlib->packedfile) + found_one = true; + else { + found_one = false; + while (tot--) { + for (id= lbarray[tot]->first; id; id= id->next) { + if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { + found_one = true; + break; + } + } + if (found_one) break; + } + } + + /* to be able to restore quit.blend and temp saves, the packed blend has to be in undo buffers... */ + /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the] + * quit.blend and temp saves */ + if (found_one) { + writestruct(wd, ID_LI, "Library", 1, main->curlib); + write_iddata(wd, &main->curlib->id); + + if (main->curlib->packedfile) { + PackedFile *pf = main->curlib->packedfile; + writestruct(wd, DATA, "PackedFile", 1, pf); + writedata(wd, DATA, pf->size, pf->data); + if (wd->current == NULL) + printf("write packed .blend: %s\n", main->curlib->name); + } + + while (a--) { + for (id= lbarray[a]->first; id; id= id->next) { + if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { + if (!BKE_idcode_is_linkable(GS(id->name))) { + printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable " + "but is flagged as directly linked", id->name, main->curlib->filepath); + BLI_assert(0); + } + writestruct(wd, ID_ID, "ID", 1, id); + } + } + } + } + } +} + /* context is usually defined by WM, two cases where no WM is available: * - for forward compatibility, curscreen has to be saved * - for undofile, curscene needs to be saved */ -- cgit v1.2.3 From d05014f844d721581b2fc09afc4d76dc28afac5c Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 16 Jun 2016 19:23:09 +0200 Subject: Readfile cleanup: add new newlibadr_real_us helper. --- source/blender/blenloader/intern/readfile.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 621088c5a3c..15a540d68e5 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1514,6 +1514,15 @@ void *blo_do_versions_newlibadr_us(FileData *fd, const void *lib, const void *ad return newlibadr_us(fd, lib, adr); } +static void *newlibadr_real_us(FileData *fd, const void *lib, const void *adr) /* ensures real user */ +{ + ID *id = newlibadr(fd, lib, adr); + + id_us_ensure_real(id); + + return id; +} + static void change_idid_adr_fd(FileData *fd, const void *old, void *new) { int i; @@ -4294,8 +4303,7 @@ static void lib_link_mtface(FileData *fd, Mesh *me, MTFace *mtface, int totface) * little bogus; it would be better if each mesh consistently added one ref * to each image it used. - z0r */ for (i = 0; i < totface; i++, tf++) { - tf->tpage= newlibadr(fd, me->id.lib, tf->tpage); - id_us_ensure_real(&tf->tpage->id); + tf->tpage = newlibadr_real_us(fd, me->id.lib, tf->tpage); } } @@ -4323,8 +4331,7 @@ static void lib_link_customdata_mtpoly(FileData *fd, Mesh *me, CustomData *pdata int j; for (j = 0; j < totface; j++, tf++) { - tf->tpage = newlibadr(fd, me->id.lib, tf->tpage); - id_us_ensure_real((ID *)tf->tpage); + tf->tpage = newlibadr_real_us(fd, me->id.lib, tf->tpage); } } } @@ -7345,12 +7352,11 @@ static void lib_link_group(FileData *fd, Main *main) add_us = false; for (go = group->gobject.first; go; go = go->next) { - go->ob= newlibadr(fd, group->id.lib, go->ob); + go->ob = newlibadr_real_us(fd, group->id.lib, go->ob); if (go->ob) { go->ob->flag |= OB_FROMGROUP; /* if group has an object, it increments user... */ add_us = true; - id_us_ensure_real(&go->ob->id); } } if (add_us) { -- cgit v1.2.3 From 503315111e43188fb8bfc003b4979797c433eaa4 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 16 Jun 2016 20:31:11 +0200 Subject: readfile.c: fix some wrong usages of newlibadr_us. There are most likely some more still, but think this should now be inline with libquery looper... --- source/blender/blenloader/intern/readfile.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 15a540d68e5..888e3aabfda 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2184,9 +2184,10 @@ static void lib_link_brush(FileData *fd, Main *main) if (brush->id.tag & LIB_TAG_NEED_LINK) { brush->id.tag &= ~LIB_TAG_NEED_LINK; + /* brush->(mask_)mtex.obj is ignored on purpose? */ brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex); brush->mask_mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mask_mtex.tex); - brush->clone.image = newlibadr_us(fd, brush->id.lib, brush->clone.image); + brush->clone.image = newlibadr(fd, brush->id.lib, brush->clone.image); brush->toggle_brush = newlibadr(fd, brush->id.lib, brush->toggle_brush); brush->paint_curve = newlibadr_us(fd, brush->id.lib, brush->paint_curve); } @@ -3816,7 +3817,7 @@ static void lib_link_texture(FileData *fd, Main *main) lib_link_animdata(fd, &tex->id, tex->adt); tex->ima = newlibadr_us(fd, tex->id.lib, tex->ima); - tex->ipo = newlibadr_us(fd, tex->id.lib, tex->ipo); + tex->ipo = newlibadr_us(fd, tex->id.lib, tex->ipo); // XXX deprecated - old animation system if (tex->env) tex->env->object = newlibadr(fd, tex->id.lib, tex->env->object); if (tex->pd) @@ -3900,7 +3901,7 @@ static void lib_link_material(FileData *fd, Main *main) * of library blocks that implement this.*/ IDP_LibLinkProperty(ma->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo); + ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo); // XXX deprecated - old animation system ma->group = newlibadr_us(fd, ma->id.lib, ma->group); for (a = 0; a < MAX_MTEX; a++) { @@ -4881,7 +4882,7 @@ static void lib_link_object(FileData *fd, Main *main) FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim); if (fluidmd && fluidmd->fss) - fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, fluidmd->fss->ipo); + fluidmd->fss->ipo = newlibadr_us(fd, ob->id.lib, fluidmd->fss->ipo); // XXX deprecated - old animation system } { @@ -5632,7 +5633,7 @@ static void lib_link_scene(FileData *fd, Main *main) SEQ_BEGIN (sce->ed, seq) { - if (seq->ipo) seq->ipo = newlibadr_us(fd, sce->id.lib, seq->ipo); + if (seq->ipo) seq->ipo = newlibadr_us(fd, sce->id.lib, seq->ipo); // XXX deprecated - old animation system seq->scene_sound = NULL; if (seq->scene) { seq->scene = newlibadr(fd, sce->id.lib, seq->scene); @@ -6272,8 +6273,8 @@ static void lib_link_screen(FileData *fd, Main *main) else if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; - sima->image = newlibadr_us(fd, sc->id.lib, sima->image); - sima->mask_info.mask = newlibadr_us(fd, sc->id.lib, sima->mask_info.mask); + sima->image = newlibadr_real_us(fd, sc->id.lib, sima->image); + sima->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sima->mask_info.mask); /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data * so fingers crossed this works fine! @@ -6379,8 +6380,8 @@ static void lib_link_screen(FileData *fd, Main *main) else if (sl->spacetype == SPACE_CLIP) { SpaceClip *sclip = (SpaceClip *)sl; - sclip->clip = newlibadr_us(fd, sc->id.lib, sclip->clip); - sclip->mask_info.mask = newlibadr_us(fd, sc->id.lib, sclip->mask_info.mask); + sclip->clip = newlibadr_real_us(fd, sc->id.lib, sclip->clip); + sclip->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sclip->mask_info.mask); } else if (sl->spacetype == SPACE_LOGIC) { SpaceLogic *slogic = (SpaceLogic *)sl; -- cgit v1.2.3 From d747bfbe298327a01f03a0c7d1183c98f4c85f4e Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 16 Jun 2016 21:09:01 +0200 Subject: Fix/cleanup BKE libquery's ID looper. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some area were still not in sync with readfile.c, now should be better. Note that readfile.c has been used as référence here re us refcounting, not sure how accurate it is, time will say :| --- source/blender/blenloader/intern/readfile.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 888e3aabfda..b11f3093850 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5619,7 +5619,6 @@ static void lib_link_scene(FileData *fd, Main *main) for (base = sce->base.first; base; base = next) { next = base->next; - /* base->object= newlibadr_us(fd, sce->id.lib, base->object); */ base->object = newlibadr_us(fd, sce->id.lib, base->object); if (base->object == NULL) { -- cgit v1.2.3 From 1c199401983bd53577cb180efe83ee5314f04296 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 21 Jun 2016 09:41:25 +1000 Subject: Fix T48688: Crash loading particle effector weights --- source/blender/blenloader/intern/readfile.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index b11f3093850..838179ec0a9 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4054,9 +4054,13 @@ static void lib_link_particlesettings(FileData *fd, Main *main) lib_link_partdeflect(fd, &part->id, part->pd); lib_link_partdeflect(fd, &part->id, part->pd2); - if (part->effector_weights) + if (part->effector_weights) { part->effector_weights->group = newlibadr(fd, part->id.lib, part->effector_weights->group); - + } + else { + part->effector_weights = BKE_add_effector_weights(part->eff_group); + } + if (part->dupliweights.first && part->dup_group) { int index_ok = 0; /* check for old files without indices (all indexes 0) */ -- cgit v1.2.3 From e34ade4eb3b28a44d7bb1685a0fba32937c8982f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 21 Jun 2016 16:12:33 +0200 Subject: Fix T48412: Blender 2.77a crashes on Undo in some specific multi-level linked libraries cases. Good old dead-brain stupid error when iterating over a linked list from which you remove some items... --- source/blender/blenloader/intern/readblenentry.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index 3cae95d418e..b5ba9879057 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -411,11 +411,12 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil /* Even though directly used libs have been already moved to new main, indirect ones have not. * This is a bit annoying, but we have no choice but to keep them all for now - means some now unused * data may remain in memory, but think we'll have to live with it. */ - Main *libmain; + Main *libmain, *libmain_next; Main *newmain = bfd->main; ListBase new_mainlist = {newmain, newmain}; - for (libmain = oldmain->next; libmain; libmain = libmain->next) { + for (libmain = oldmain->next; libmain; libmain = libmain_next) { + libmain_next = libmain->next; /* Note that LIB_INDIRECT does not work with libraries themselves, so we use non-NULL parent * to detect indirect-linked ones... */ if (libmain->curlib && (libmain->curlib->parent != NULL)) { -- cgit v1.2.3 From db4a46bc3c97bf9762a472bb8dcd4213b69acf83 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 21 Jun 2016 16:19:08 +0200 Subject: Cleanup: hide debug print behind proper debug defines instead of using comments... --- source/blender/blenloader/intern/readblenentry.c | 4 ++-- source/blender/blenloader/intern/readfile.c | 28 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index b5ba9879057..be893177b3b 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -423,11 +423,11 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain, const char *filename, MemFil BLI_remlink(&old_mainlist, libmain); BLI_addtail(&new_mainlist, libmain); } -#if 0 else { +#ifdef PRINT_DEBUG printf("Dropped Main for lib: %s\n", libmain->curlib->id.name); - } #endif + } } /* In any case, we need to move all lib datablocks themselves - those are 'first level data', * getting rid of them would imply updating spaces & co to prevent invalid pointers access. */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 838179ec0a9..6aa2fc4ac8c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7949,16 +7949,22 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short if (fd->memfile && ELEM(bhead->code, ID_LI, ID_ID)) { const char *idname = bhead_id_name(fd, bhead); - /* printf("Checking %s...\n", idname); */ +#ifdef PRINT_DEBUG + printf("Checking %s...\n", idname); +#endif if (bhead->code == ID_LI) { Main *libmain = fd->old_mainlist->first; /* Skip oldmain itself... */ for (libmain = libmain->next; libmain; libmain = libmain->next) { - /* printf("... against %s: ", libmain->curlib ? libmain->curlib->id.name : ""); */ +#ifdef PRINT_DEBUG + printf("... against %s: ", libmain->curlib ? libmain->curlib->id.name : ""); +#endif if (libmain->curlib && STREQ(idname, libmain->curlib->id.name)) { Main *oldmain = fd->old_mainlist->first; - /* printf("FOUND!\n"); */ +#ifdef PRINT_DEBUG + printf("FOUND!\n"); +#endif /* In case of a library, we need to re-add its main to fd->mainlist, because if we have later * a missing ID_ID, we need to get the correct lib it is linked to! * Order is crucial, we cannot bulk-add it in BLO_read_from_memfile() like it used to be... */ @@ -7972,13 +7978,19 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short } return blo_nextbhead(fd, bhead); } - /* printf("nothing...\n"); */ +#ifdef PRINT_DEBUG + printf("nothing...\n"); +#endif } } else { - /* printf("... in %s (%s): ", main->curlib ? main->curlib->id.name : "", main->curlib ? main->curlib->name : ""); */ +#ifdef PRINT_DEBUG + printf("... in %s (%s): ", main->curlib ? main->curlib->id.name : "", main->curlib ? main->curlib->name : ""); +#endif if ((id = BKE_libblock_find_name_ex(main, GS(idname), idname + 2))) { - /* printf("FOUND!\n"); */ +#ifdef PRINT_DEBUG + printf("FOUND!\n"); +#endif /* Even though we found our linked ID, there is no guarantee its address is still the same... */ if (id != bhead->old) { oldnewmap_insert(fd->libmap, bhead->old, id, GS(id->name)); @@ -7990,7 +8002,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short } return blo_nextbhead(fd, bhead); } - /* printf("nothing...\n"); */ +#ifdef PRINT_DEBUG + printf("nothing...\n"); +#endif } } -- cgit v1.2.3 From a5b474e35209a67e6d48e934b4205831a252fbf3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 22 Jun 2016 07:22:00 +1000 Subject: Docs: use doxy formatting for readfile --- source/blender/blenloader/intern/readfile.c | 83 +++++++++++++++-------------- 1 file changed, 42 insertions(+), 41 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6aa2fc4ac8c..5c7b664e547 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -160,53 +160,54 @@ #include -/* - * Remark: still a weak point is the newaddress() function, that doesnt solve reading from - * multiple files at the same time - * - * (added remark: oh, i thought that was solved? will look at that... (ton) - * +/** * READ - * - Existing Library (Main) push or free - * - allocate new Main + * ==== + * + * - Existing Library (#Main) push or free + * - allocate new #Main * - load file - * - read SDNA + * - read #SDNA * - for each LibBlock - * - read LibBlock - * - if a Library - * - make a new Main - * - attach ID's to it - * - else - * - read associated 'direct data' - * - link direct data (internal and to LibBlock) - * - read FileGlobal - * - read USER data, only when indicated (file is ~/X.XX/startup.blend) + * - read LibBlock + * - if a Library + * - make a new #Main + * - attach ID's to it + * - else + * - read associated 'direct data' + * - link direct data (internal and to LibBlock) + * - read #FileGlobal + * - read #USER data, only when indicated (file is ``~/X.XX/startup.blend``) * - free file - * - per Library (per Main) - * - read file - * - read SDNA - * - find LibBlocks and attach IDs to Main - * - if external LibBlock - * - search all Main's - * - or it's already read, - * - or not read yet - * - or make new Main - * - per LibBlock - * - read recursive - * - read associated direct data - * - link direct data (internal and to LibBlock) - * - free file + * - per Library (per #Main) + * - read file + * - read #SDNA + * - find LibBlocks and attach #ID's to #Main + * - if external LibBlock + * - search all #Main's + * - or it's already read, + * - or not read yet + * - or make new #Main + * - per LibBlock + * - read recursive + * - read associated direct data + * - link direct data (internal and to LibBlock) + * - free file * - per Library with unread LibBlocks - * - read file - * - read SDNA - * - per LibBlock - * - read recursive - * - read associated direct data - * - link direct data (internal and to LibBlock) - * - free file - * - join all Mains + * - read file + * - read #SDNA + * - per LibBlock + * - read recursive + * - read associated direct data + * - link direct data (internal and to LibBlock) + * - free file + * - join all #Main's * - link all LibBlocks and indirect pointers to libblocks - * - initialize FileGlobal and copy pointers to Global + * - initialize #FileGlobal and copy pointers to #Global + * + * \note Still a weak point is the new-address function, that doesnt solve reading from + * multiple files at the same time. + * (added remark: oh, i thought that was solved? will look at that... (ton). */ /* use GHash for BHead name-based lookups (speeds up linking) */ -- cgit v1.2.3 From 63006c88a1527c9199b9db0f6f22309781eaa4c3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 22 Jun 2016 08:44:26 +1000 Subject: writefile: use const for old address Also remove temp preview overwriting. --- source/blender/blenloader/intern/readfile.c | 2 +- source/blender/blenloader/intern/writefile.c | 65 ++++++++++++++-------------- 2 files changed, 33 insertions(+), 34 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 5c7b664e547..689a975e19f 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8519,7 +8519,7 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) struct BHeadSort { BHead *bhead; - void *old; + const void *old; }; static int verg_bheadsort(const void *v1, const void *v2) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 327b7b5aed4..b5a2115fa5f 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -449,7 +449,9 @@ static int endwrite(WriteData *wd) /* ********** WRITE FILE ****************** */ -static void writestruct_at_address(WriteData *wd, int filecode, const char *structname, int nr, void *adr, void *data) +static void writestruct_at_address( + WriteData *wd, int filecode, const char *structname, int nr, + const void *adr, const void *data) { BHead bh; const short *sp; @@ -476,7 +478,9 @@ static void writestruct_at_address(WriteData *wd, int filecode, const char *stru mywrite(wd, data, bh.len); } -static void writestruct(WriteData *wd, int filecode, const char *structname, int nr, void *adr) +static void writestruct( + WriteData *wd, int filecode, const char *structname, int nr, + const void *adr) { writestruct_at_address(wd, filecode, structname, nr, adr, adr); } @@ -493,7 +497,7 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* /* init BHead */ bh.code = filecode; - bh.old = (void *)adr; /* this is safe to cast from const */ + bh.old = adr; bh.nr = 1; bh.SDNAnr = 0; bh.len = len; @@ -503,9 +507,9 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* } /* use this to force writing of lists in same order as reading (using link_list) */ -static void writelist(WriteData *wd, int filecode, const char *structname, ListBase *lb) +static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb) { - Link *link = lb->first; + const Link *link = lb->first; while (link) { writestruct(wd, filecode, structname, 1, link); @@ -515,10 +519,10 @@ static void writelist(WriteData *wd, int filecode, const char *structname, ListB /* *************** writing some direct data structs used in more code parts **************** */ /*These functions are used by blender's .blend system for file saving/loading.*/ -void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd); -void IDP_WriteProperty(IDProperty *prop, void *wd); +void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd); +void IDP_WriteProperty(const IDProperty *prop, void *wd); -static void IDP_WriteArray(IDProperty *prop, void *wd) +static void IDP_WriteArray(const IDProperty *prop, void *wd) { /*REMEMBER to set totalen to len in the linking code!!*/ if (prop->data.pointer) { @@ -534,11 +538,11 @@ static void IDP_WriteArray(IDProperty *prop, void *wd) } } -static void IDP_WriteIDPArray(IDProperty *prop, void *wd) +static void IDP_WriteIDPArray(const IDProperty *prop, void *wd) { /*REMEMBER to set totalen to len in the linking code!!*/ if (prop->data.pointer) { - IDProperty *array = prop->data.pointer; + const IDProperty *array = prop->data.pointer; int a; writestruct(wd, DATA, "IDProperty", prop->len, array); @@ -548,13 +552,13 @@ static void IDP_WriteIDPArray(IDProperty *prop, void *wd) } } -static void IDP_WriteString(IDProperty *prop, void *wd) +static void IDP_WriteString(const IDProperty *prop, void *wd) { /*REMEMBER to set totalen to len in the linking code!!*/ writedata(wd, DATA, prop->len, prop->data.pointer); } -static void IDP_WriteGroup(IDProperty *prop, void *wd) +static void IDP_WriteGroup(const IDProperty *prop, void *wd) { IDProperty *loop; @@ -564,7 +568,7 @@ static void IDP_WriteGroup(IDProperty *prop, void *wd) } /* Functions to read/write ID Properties */ -void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd) +void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd) { switch (prop->type) { case IDP_GROUP: @@ -582,13 +586,13 @@ void IDP_WriteProperty_OnlyData(IDProperty *prop, void *wd) } } -void IDP_WriteProperty(IDProperty *prop, void *wd) +void IDP_WriteProperty(const IDProperty *prop, void *wd) { writestruct(wd, DATA, "IDProperty", 1, prop); IDP_WriteProperty_OnlyData(prop, wd); } -static void write_iddata(void *wd, ID *id) +static void write_iddata(void *wd, const ID *id) { /* ID_WM's id->properties are considered runtime only, and never written in .blend file. */ if (id->properties && !ELEM(GS(id->name), ID_WM)) { @@ -596,29 +600,24 @@ static void write_iddata(void *wd, ID *id) } } -static void write_previews(WriteData *wd, PreviewImage *prv) +static void write_previews(WriteData *wd, const PreviewImage *prv_orig) { /* Never write previews when doing memsave (i.e. undo/redo)! */ - if (prv && !wd->current) { - short w = prv->w[1]; - short h = prv->h[1]; - unsigned int *rect = prv->rect[1]; + if (prv_orig && !wd->current) { + PreviewImage prv = *prv_orig; /* don't write out large previews if not requested */ if (!(U.flag & USER_SAVE_PREVIEWS)) { - prv->w[1] = 0; - prv->h[1] = 0; - prv->rect[1] = NULL; - } - writestruct(wd, DATA, "PreviewImage", 1, prv); - if (prv->rect[0]) writedata(wd, DATA, prv->w[0] * prv->h[0] * sizeof(unsigned int), prv->rect[0]); - if (prv->rect[1]) writedata(wd, DATA, prv->w[1] * prv->h[1] * sizeof(unsigned int), prv->rect[1]); - - /* restore preview, we still want to keep it in memory even if not saved to file */ - if (!(U.flag & USER_SAVE_PREVIEWS) ) { - prv->w[1] = w; - prv->h[1] = h; - prv->rect[1] = rect; + prv.w[1] = 0; + prv.h[1] = 0; + prv.rect[1] = NULL; + } + writestruct_at_address(wd, DATA, "PreviewImage", 1, prv_orig, &prv); + if (prv.rect[0]) { + writedata(wd, DATA, prv.w[0] * prv.h[0] * sizeof(unsigned int), prv.rect[0]); + } + if (prv.rect[1]) { + writedata(wd, DATA, prv.w[1] * prv.h[1] * sizeof(unsigned int), prv.rect[1]); } } } -- cgit v1.2.3 From 435fa9a015c8e1396ff2b7f72e2b83f1b8867790 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 22 Jun 2016 09:50:53 +1000 Subject: Cleanup: remove unused Image space curves Caused leaks reading old files, was read/written but not freed, remove since its unused. --- source/blender/blenloader/intern/readfile.c | 6 +----- source/blender/blenloader/intern/writefile.c | 4 ---- 2 files changed, 1 insertion(+), 9 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 689a975e19f..fd611dada47 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7038,11 +7038,7 @@ static bool direct_link_screen(FileData *fd, bScreen *sc) } else if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; - - sima->cumap = newdataadr(fd, sima->cumap); - if (sima->cumap) - direct_link_curvemapping(fd, sima->cumap); - + sima->iuser.scene = NULL; sima->iuser.ok = 1; sima->scopes.waveform_1 = NULL; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index b5a2115fa5f..a7cb1043c64 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2808,11 +2808,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase) write_soops(wd, so, &tmp_mem_list); } else if (sl->spacetype==SPACE_IMAGE) { - SpaceImage *sima= (SpaceImage *)sl; - writestruct(wd, DATA, "SpaceImage", 1, sl); - if (sima->cumap) - write_curvemapping(wd, sima->cumap); } else if (sl->spacetype==SPACE_TEXT) { writestruct(wd, DATA, "SpaceText", 1, sl); -- cgit v1.2.3 From 493c6b622fe3fb80243dfeac29f9399ac6fc4a8c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 22 Jun 2016 14:02:51 +1000 Subject: Cleanup: style --- source/blender/blenloader/intern/readfile.c | 4 ++-- source/blender/blenloader/intern/writefile.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index fd611dada47..d8768f13538 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1259,7 +1259,7 @@ void blo_freefiledata(FileData *fd) } if (fd->strm.next_in) { - if (inflateEnd (&fd->strm) != Z_OK) { + if (inflateEnd(&fd->strm) != Z_OK) { printf("close gzip stream error\n"); } } @@ -3971,7 +3971,7 @@ static void direct_link_pointcache_cb(FileData *fd, void *data) /* the cache saves non-struct data without DNA */ if (pm->data[i] && ptcache_data_struct[i][0]=='\0' && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { - int tot = (BKE_ptcache_data_size (i) * pm->totpoint) / sizeof(int); /* data_size returns bytes */ + int tot = (BKE_ptcache_data_size(i) * pm->totpoint) / sizeof(int); /* data_size returns bytes */ int *poin = pm->data[i]; BLI_endian_switch_int32_array(poin, tot); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index a7cb1043c64..4fd3e410e63 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2427,19 +2427,19 @@ static void write_scenes(WriteData *wd, ListBase *scebase) writestruct(wd, DATA, "ToolSettings", 1, tos); if (tos->vpaint) { writestruct(wd, DATA, "VPaint", 1, tos->vpaint); - write_paint (wd, &tos->vpaint->paint); + write_paint(wd, &tos->vpaint->paint); } if (tos->wpaint) { writestruct(wd, DATA, "VPaint", 1, tos->wpaint); - write_paint (wd, &tos->wpaint->paint); + write_paint(wd, &tos->wpaint->paint); } if (tos->sculpt) { writestruct(wd, DATA, "Sculpt", 1, tos->sculpt); - write_paint (wd, &tos->sculpt->paint); + write_paint(wd, &tos->sculpt->paint); } if (tos->uvsculpt) { writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt); - write_paint (wd, &tos->uvsculpt->paint); + write_paint(wd, &tos->uvsculpt->paint); } write_paint(wd, &tos->imapaint.paint); -- cgit v1.2.3 From 7547c6a250cd6f36c9894605b822380a1261febf Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 22 Jun 2016 18:05:55 +0200 Subject: ID-Remap, step two: add some user-level tools. This commit adds operators and Outliner menu entries to reload or relocate a library, and to delete or replace a datablock. RNA ID API is also extended to allow ID deletion and remapping from python. Review task: D2027 (https://developer.blender.org/D2027). Reviewed by campbellbarton, thanks a bunch. --- source/blender/blenloader/BLO_readfile.h | 3 ++- source/blender/blenloader/intern/readfile.c | 39 +++++++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index bf47682297d..c85cf128643 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -100,7 +100,8 @@ struct ID *BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, con struct ID *BLO_library_link_named_part_ex( struct Main *mainl, BlendHandle **bh, const short idcode, const char *name, const short flag, - struct Scene *scene, struct View3D *v3d); + struct Scene *scene, struct View3D *v3d, + const bool use_placeholders, const bool force_indirect); void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct View3D *v3d); void BLO_library_link_copypaste(struct Main *mainl, BlendHandle *bh); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d8768f13538..8e69408bfd8 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -113,6 +113,7 @@ #include "BKE_action.h" #include "BKE_armature.h" +#include "BKE_blender_version.h" #include "BKE_brush.h" #include "BKE_cloth.h" #include "BKE_constraint.h" @@ -8287,6 +8288,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main) blo_do_versions_260(fd, lib, main); blo_do_versions_270(fd, lib, main); + main->versionfile = BLENDER_VERSION; + main->subversionfile = BLENDER_SUBVERSION; + /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */ @@ -9707,13 +9711,13 @@ static void give_base_to_groups( } } -static ID *create_placeholder(Main *mainvar, const char *idname, const short tag) +static ID *create_placeholder(Main *mainvar, const short idcode, const char *idname, const short tag) { - const short idcode = GS(idname); ListBase *lb = which_libbase(mainvar, idcode); ID *ph_id = BKE_libblock_alloc_notest(idcode); - memcpy(ph_id->name, idname, sizeof(ph_id->name)); + *((short *)ph_id->name) = idcode; + BLI_strncpy(ph_id->name + 2, idname, sizeof(ph_id->name) - 2); BKE_libblock_init_empty(ph_id); ph_id->lib = mainvar->curlib; ph_id->tag = tag | LIB_TAG_MISSING; @@ -9728,7 +9732,9 @@ static ID *create_placeholder(Main *mainvar, const char *idname, const short tag /* returns true if the item was found * but it may already have already been appended/linked */ -static ID *link_named_part(Main *mainl, FileData *fd, const short idcode, const char *name) +static ID *link_named_part( + Main *mainl, FileData *fd, const short idcode, const char *name, + const bool use_placeholders, const bool force_indirect) { BHead *bhead = find_bhead_from_code_name(fd, idcode, name); ID *id; @@ -9739,7 +9745,7 @@ static ID *link_named_part(Main *mainl, FileData *fd, const short idcode, const id = is_yet_read(fd, mainl, bhead); if (id == NULL) { /* not read yet */ - read_libblock(fd, mainl, bhead, LIB_TAG_TESTEXT, &id); + read_libblock(fd, mainl, bhead, force_indirect ? LIB_TAG_TESTIND : LIB_TAG_TESTEXT, &id); if (id) { /* sort by name in list */ @@ -9752,18 +9758,22 @@ static ID *link_named_part(Main *mainl, FileData *fd, const short idcode, const if (G.debug) printf("append: already linked\n"); oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code); - if (id->tag & LIB_TAG_INDIRECT) { + if (!force_indirect && (id->tag & LIB_TAG_INDIRECT)) { id->tag &= ~LIB_TAG_INDIRECT; id->tag |= LIB_TAG_EXTERN; } } } + else if (use_placeholders) { + /* XXX flag part is weak! */ + id = create_placeholder(mainl, idcode, name, force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN); + } else { id = NULL; } /* if we found the id but the id is NULL, this is really bad */ - BLI_assert((bhead != NULL) == (id != NULL)); + BLI_assert(!((bhead != NULL) && (id == NULL))); return id; } @@ -9835,9 +9845,9 @@ void BLO_library_link_copypaste(Main *mainl, BlendHandle *bh) static ID *link_named_part_ex( Main *mainl, FileData *fd, const short idcode, const char *name, const short flag, - Scene *scene, View3D *v3d) + Scene *scene, View3D *v3d, const bool use_placeholders, const bool force_indirect) { - ID *id = link_named_part(mainl, fd, idcode, name); + ID *id = link_named_part(mainl, fd, idcode, name, use_placeholders, force_indirect); if (id && (GS(id->name) == ID_OB)) { /* loose object: give a base */ link_object_postprocess(id, scene, v3d, flag); @@ -9863,7 +9873,7 @@ static ID *link_named_part_ex( ID *BLO_library_link_named_part(Main *mainl, BlendHandle **bh, const short idcode, const char *name) { FileData *fd = (FileData*)(*bh); - return link_named_part(mainl, fd, idcode, name); + return link_named_part(mainl, fd, idcode, name, false, false); } /** @@ -9877,15 +9887,18 @@ ID *BLO_library_link_named_part(Main *mainl, BlendHandle **bh, const short idcod * \param flag Options for linking, used for instantiating. * \param scene The scene in which to instantiate objects/groups (if NULL, no instantiation is done). * \param v3d The active View3D (only to define active layers for instantiated objects & groups, can be NULL). + * \param use_placeholders If true, generate a placeholder (empty ID) if not found in current lib file. + * \param force_indirect If true, force loaded ID to be tagged as LIB_TAG_INDIRECT (used in reload context only). * \return the linked ID when found. */ ID *BLO_library_link_named_part_ex( Main *mainl, BlendHandle **bh, const short idcode, const char *name, const short flag, - Scene *scene, View3D *v3d) + Scene *scene, View3D *v3d, + const bool use_placeholders, const bool force_indirect) { FileData *fd = (FileData*)(*bh); - return link_named_part_ex(mainl, fd, idcode, name, flag, scene, v3d); + return link_named_part_ex(mainl, fd, idcode, name, flag, scene, v3d, use_placeholders, force_indirect); } static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *id, ID **r_id) @@ -9925,7 +9938,7 @@ static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *i /* Generate a placeholder for this ID (simplified version of read_libblock actually...). */ if (r_id) { - *r_id = is_valid ? create_placeholder(mainvar, id->name, id->tag) : NULL; + *r_id = is_valid ? create_placeholder(mainvar, GS(id->name), id->name + 2, id->tag) : NULL; } } } -- cgit v1.2.3 From 6e193c42cbedbb13a71596b6c8cbb860b7d47cae Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 27 Jun 2016 11:21:03 +1000 Subject: Docs: minor edits to writefile comments --- source/blender/blenloader/intern/writefile.c | 34 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 4fd3e410e63..ef4295ee955 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -29,15 +29,22 @@ */ -/* - * FILEFORMAT: IFF-style structure (but not IFF compatible!) +/** + * + * FILE FORMAT + * =========== + * + * IFF-style structure (but not IFF compatible!) * * start file: + *
  *     BLENDER_V100    12 bytes  (versie 1.00)
  *                     V = big endian, v = little endian
  *                     _ = 4 byte pointer, - = 8 byte pointer
+ * 
* - * datablocks: also see struct BHead + * datablocks: (also see struct #BHead). + *
  *                4 chars
  *                 int,  len data after BHead
  *                 void,  old pointer
@@ -46,29 +53,32 @@
  *     data
  *     ...
  *     ...
+ * 
* * Almost all data in Blender are structures. Each struct saved * gets a BHead header. With BHead the struct can be linked again * and compared with StructDNA . * + * * WRITE + * ===== * * Preferred writing order: (not really a must, but why would you do it random?) * Any case: direct data is ALWAYS after the lib block * * (Local file data) * - for each LibBlock - * - write LibBlock - * - write associated direct data + * - write LibBlock + * - write associated direct data * (External file data) * - per library - * - write library block - * - per LibBlock - * - write the ID of LibBlock - * - write TEST (128x128, blend file preview, optional) - * - write FileGlobal (some global vars) - * - write SDNA - * - write USER if filename is ~/X.XX/config/startup.blend + * - write library block + * - per LibBlock + * - write the ID of LibBlock + * - write #TEST (#RenderInfo struct. 128x128 blend file preview is optional). + * - write #GLOB (#FileGlobal struct) (some global vars). + * - write #DNA1 (#SDNA struct) + * - write #USER (#UserDef struct) if filename is ``~/X.XX/config/startup.blend``. */ -- cgit v1.2.3 From 538a70c9b640789a67a7f2f19fa53e234443f64c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 27 Jun 2016 12:54:56 +1000 Subject: Cleanup: unnecessary NULL check --- source/blender/blenloader/intern/writefile.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ef4295ee955..7a84eb690cd 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -321,12 +321,6 @@ static WriteData *writedata_new(WriteWrap *ww) { WriteData *wd= MEM_callocN(sizeof(*wd), "writedata"); - /* XXX, see note about this in readfile.c, remove - * once we have an xp lock - zr - */ - - if (wd == NULL) return NULL; - wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false); wd->ww = ww; -- cgit v1.2.3 From ab921321e1ca6303ee0fa2f2de511b490d9d6427 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 27 Jun 2016 12:38:12 +0200 Subject: Fix (unreported) potential buffer overflow with BLO_library_path_explode() usage. Also added warning to func doc, let's try to avoid this in future (for until we pass string length systematically...). --- source/blender/blenloader/intern/readfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 8e69408bfd8..323f0a93e05 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1326,6 +1326,7 @@ bool BLO_has_bfile_extension(const char *str) * * \param path the full path to explode. * \param r_dir the string that'll contain path up to blend file itself ('library' path). + * WARNING! Must be FILE_MAX_LIBEXTRA long (it also stores group and name strings)! * \param r_group the string that'll contain 'group' part of the path, if any. May be NULL. * \param r_name the string that'll contain data's name part of the path, if any. May be NULL. * \return true if path contains a blend file. -- cgit v1.2.3 From f181839c572fdffe9554cf7d9e41c7ceffeec02e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Jun 2016 17:35:35 +1000 Subject: Cleanup: code-style Other changes here planned which touch many lines, so run cleanup first. --- source/blender/blenloader/intern/writefile.c | 2205 ++++++++++++++------------ 1 file changed, 1222 insertions(+), 983 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 7a84eb690cd..5a7b2a7880c 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -173,7 +173,7 @@ #include "BKE_mesh.h" #ifdef USE_NODE_COMPAT_CUSTOMNODES -#include "NOD_socket.h" /* for sock->default_value data */ +#include "NOD_socket.h" /* for sock->default_value data */ #endif @@ -304,7 +304,7 @@ typedef struct { unsigned char *buf; MemFile *compare, *current; - + int tot, count, error; /* Wrap writing, so we can use zlib or @@ -319,21 +319,26 @@ typedef struct { static WriteData *writedata_new(WriteWrap *ww) { - WriteData *wd= MEM_callocN(sizeof(*wd), "writedata"); + WriteData *wd = MEM_callocN(sizeof(*wd), "writedata"); wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false); wd->ww = ww; - wd->buf= MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf"); + wd->buf = MEM_mallocN(MYWRITE_BUFFER_SIZE, "wd->buf"); return wd; } static void writedata_do_write(WriteData *wd, const void *mem, int memlen) { - if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) return; - if (wd->error) return; + if ((wd == NULL) || wd->error || (mem == NULL) || memlen < 1) { + return; + } + + if (UNLIKELY(wd->error)) { + return; + } /* memory based save */ if (wd->current) { @@ -367,29 +372,31 @@ static void writedata_free(WriteData *wd) static void mywrite(WriteData *wd, const void *adr, int len) { - if (wd->error) return; + if (UNLIKELY(wd->error)) { + return; + } /* flush helps compression for undo-save */ - if (adr==MYWRITE_FLUSH) { + if (adr == MYWRITE_FLUSH) { if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } return; } - wd->tot+= len; - + wd->tot += len; + /* if we have a single big chunk, write existing data in * buffer and write out big chunk in smaller pieces */ - if (len>MYWRITE_MAX_CHUNK) { + if (len > MYWRITE_MAX_CHUNK) { if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } do { - int writelen= MIN2(len, MYWRITE_MAX_CHUNK); + int writelen = MIN2(len, MYWRITE_MAX_CHUNK); writedata_do_write(wd, adr, writelen); adr = (const char *)adr + writelen; len -= writelen; @@ -399,14 +406,14 @@ static void mywrite(WriteData *wd, const void *adr, int len) } /* if data would overflow buffer, write out the buffer */ - if (len+wd->count>MYWRITE_BUFFER_SIZE-1) { + if (len + wd->count > MYWRITE_BUFFER_SIZE - 1) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } /* append data at end of buffer */ memcpy(&wd->buf[wd->count], adr, len); - wd->count+= len; + wd->count += len; } /** @@ -418,15 +425,17 @@ static void mywrite(WriteData *wd, const void *adr, int len) */ static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current) { - WriteData *wd= writedata_new(ww); + WriteData *wd = writedata_new(ww); - if (wd == NULL) return NULL; + if (wd == NULL) { + return NULL; + } - wd->compare= compare; - wd->current= current; + wd->compare = compare; + wd->current = current; /* this inits comparing */ memfile_chunk_add(compare, NULL, NULL, 0); - + return wd; } @@ -442,10 +451,10 @@ static int endwrite(WriteData *wd) if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); - wd->count= 0; + wd->count = 0; } - - err= wd->error; + + err = wd->error; writedata_free(wd); return err; @@ -460,23 +469,27 @@ static void writestruct_at_address( BHead bh; const short *sp; - if (adr==NULL || data==NULL || nr==0) return; + if (adr == NULL || data == NULL || nr == 0) { + return; + } /* init BHead */ - bh.code= filecode; - bh.old= adr; - bh.nr= nr; + bh.code = filecode; + bh.old = adr; + bh.nr = nr; - bh.SDNAnr= DNA_struct_find_nr(wd->sdna, structname); - if (bh.SDNAnr== -1) { + bh.SDNAnr = DNA_struct_find_nr(wd->sdna, structname); + if (bh.SDNAnr == -1) { printf("error: can't find SDNA code <%s>\n", structname); return; } - sp= wd->sdna->structs[bh.SDNAnr]; + sp = wd->sdna->structs[bh.SDNAnr]; - bh.len= nr*wd->sdna->typelens[sp[0]]; + bh.len = nr * wd->sdna->typelens[sp[0]]; - if (bh.len==0) return; + if (bh.len == 0) { + return; + } mywrite(wd, &bh, sizeof(BHead)); mywrite(wd, data, bh.len); @@ -493,8 +506,9 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* { BHead bh; - if (adr==NULL) return; - if (len==0) return; + if (adr == NULL || len == 0) { + return; + } /* align to 4 (writes uninitialized bytes in some cases) */ len = (len + 3) & ~3; @@ -514,7 +528,7 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb) { const Link *link = lb->first; - + while (link) { writestruct(wd, filecode, structname, 1, link); link = link->next; @@ -533,11 +547,12 @@ static void IDP_WriteArray(const IDProperty *prop, void *wd) writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), prop->data.pointer); if (prop->subtype == IDP_GROUP) { - IDProperty **array= prop->data.pointer; + IDProperty **array = prop->data.pointer; int a; - for (a=0; alen; a++) + for (a = 0; a < prop->len; a++) { IDP_WriteProperty(array[a], wd); + } } } } @@ -551,8 +566,9 @@ static void IDP_WriteIDPArray(const IDProperty *prop, void *wd) writestruct(wd, DATA, "IDProperty", prop->len, array); - for (a=0; alen; a++) + for (a = 0; a < prop->len; a++) { IDP_WriteProperty_OnlyData(&array[a], wd); + } } } @@ -566,7 +582,7 @@ static void IDP_WriteGroup(const IDProperty *prop, void *wd) { IDProperty *loop; - for (loop=prop->data.group.first; loop; loop=loop->next) { + for (loop = prop->data.group.first; loop; loop = loop->next) { IDP_WriteProperty(loop, wd); } } @@ -629,45 +645,47 @@ static void write_previews(WriteData *wd, const PreviewImage *prv_orig) static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) { FModifier *fcm; - + /* Write all modifiers first (for faster reloading) */ writelist(wd, DATA, "FModifier", fmodifiers); - + /* Modifiers */ - for (fcm= fmodifiers->first; fcm; fcm= fcm->next) { - const FModifierTypeInfo *fmi= fmodifier_get_typeinfo(fcm); - + for (fcm = fmodifiers->first; fcm; fcm = fcm->next) { + const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); + /* Write the specific data */ if (fmi && fcm->data) { /* firstly, just write the plain fmi->data struct */ writestruct(wd, DATA, fmi->structName, 1, fcm->data); - + /* do any modifier specific stuff */ switch (fcm->type) { case FMODIFIER_TYPE_GENERATOR: { - FMod_Generator *data= (FMod_Generator *)fcm->data; - + FMod_Generator *data = fcm->data; + /* write coefficients array */ - if (data->coefficients) - writedata(wd, DATA, sizeof(float)*(data->arraysize), data->coefficients); + if (data->coefficients) { + writedata(wd, DATA, sizeof(float) * (data->arraysize), data->coefficients); + } break; } case FMODIFIER_TYPE_ENVELOPE: { - FMod_Envelope *data= (FMod_Envelope *)fcm->data; - + FMod_Envelope *data = fcm->data; + /* write envelope data */ - if (data->data) + if (data->data) { writestruct(wd, DATA, "FCM_EnvelopeData", data->totvert, data->data); + } break; } case FMODIFIER_TYPE_PYTHON: { - FMod_Python *data = (FMod_Python *)fcm->data; - + FMod_Python *data = fcm->data; + /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ IDP_WriteProperty(data->prop, wd); @@ -682,37 +700,41 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) static void write_fcurves(WriteData *wd, ListBase *fcurves) { FCurve *fcu; - + writelist(wd, DATA, "FCurve", fcurves); - for (fcu=fcurves->first; fcu; fcu=fcu->next) { + for (fcu = fcurves->first; fcu; fcu = fcu->next) { /* curve data */ - if (fcu->bezt) + if (fcu->bezt) { writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt); - if (fcu->fpt) + } + if (fcu->fpt) { writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt); - - if (fcu->rna_path) - writedata(wd, DATA, strlen(fcu->rna_path)+1, fcu->rna_path); - + } + + if (fcu->rna_path) { + writedata(wd, DATA, strlen(fcu->rna_path) + 1, fcu->rna_path); + } + /* driver data */ if (fcu->driver) { - ChannelDriver *driver= fcu->driver; + ChannelDriver *driver = fcu->driver; DriverVar *dvar; - + writestruct(wd, DATA, "ChannelDriver", 1, driver); - + /* variables */ writelist(wd, DATA, "DriverVar", &driver->variables); - for (dvar= driver->variables.first; dvar; dvar= dvar->next) { + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { DRIVER_TARGETS_USED_LOOPER(dvar) { - if (dtar->rna_path) - writedata(wd, DATA, strlen(dtar->rna_path)+1, dtar->rna_path); + if (dtar->rna_path) { + writedata(wd, DATA, strlen(dtar->rna_path) + 1, dtar->rna_path); + } } DRIVER_TARGETS_LOOPER_END } } - + /* write F-Modifiers */ write_fmodifiers(wd, &fcu->modifiers); } @@ -720,27 +742,27 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) static void write_actions(WriteData *wd, ListBase *idbase) { - bAction *act; + bAction *act; bActionGroup *grp; TimeMarker *marker; - - for (act=idbase->first; act; act= act->id.next) { - if (act->id.us>0 || wd->current) { + + for (act = idbase->first; act; act = act->id.next) { + if (act->id.us > 0 || wd->current) { writestruct(wd, ID_AC, "bAction", 1, act); write_iddata(wd, &act->id); write_fcurves(wd, &act->curves); - - for (grp=act->groups.first; grp; grp=grp->next) { + + for (grp = act->groups.first; grp; grp = grp->next) { writestruct(wd, DATA, "bActionGroup", 1, grp); } - - for (marker=act->markers.first; marker; marker=marker->next) { + + for (marker = act->markers.first; marker; marker = marker->next) { writestruct(wd, DATA, "TimeMarker", 1, marker); } } } - + /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); } @@ -749,18 +771,19 @@ static void write_keyingsets(WriteData *wd, ListBase *list) { KeyingSet *ks; KS_Path *ksp; - - for (ks= list->first; ks; ks= ks->next) { + + for (ks = list->first; ks; ks = ks->next) { /* KeyingSet */ writestruct(wd, DATA, "KeyingSet", 1, ks); - + /* Paths */ - for (ksp= ks->paths.first; ksp; ksp= ksp->next) { + for (ksp = ks->paths.first; ksp; ksp = ksp->next) { /* Path */ writestruct(wd, DATA, "KS_Path", 1, ksp); - - if (ksp->rna_path) - writedata(wd, DATA, strlen(ksp->rna_path)+1, ksp->rna_path); + + if (ksp->rna_path) { + writedata(wd, DATA, strlen(ksp->rna_path) + 1, ksp->rna_path); + } } } } @@ -768,13 +791,13 @@ static void write_keyingsets(WriteData *wd, ListBase *list) static void write_nlastrips(WriteData *wd, ListBase *strips) { NlaStrip *strip; - + writelist(wd, DATA, "NlaStrip", strips); - for (strip= strips->first; strip; strip= strip->next) { + for (strip = strips->first; strip; strip = strip->next) { /* write the strip's F-Curves and modifiers */ write_fcurves(wd, &strip->fcurves); write_fmodifiers(wd, &strip->modifiers); - + /* write the strip's children */ write_nlastrips(wd, &strip->strips); } @@ -783,12 +806,12 @@ static void write_nlastrips(WriteData *wd, ListBase *strips) static void write_nladata(WriteData *wd, ListBase *nlabase) { NlaTrack *nlt; - + /* write all the tracks */ - for (nlt= nlabase->first; nlt; nlt= nlt->next) { + for (nlt = nlabase->first; nlt; nlt = nlt->next) { /* write the track first */ writestruct(wd, DATA, "NlaTrack", 1, nlt); - + /* write the track's strips */ write_nlastrips(wd, &nlt->strips); } @@ -797,33 +820,32 @@ static void write_nladata(WriteData *wd, ListBase *nlabase) static void write_animdata(WriteData *wd, AnimData *adt) { AnimOverride *aor; - + /* firstly, just write the AnimData block */ writestruct(wd, DATA, "AnimData", 1, adt); - + /* write drivers */ write_fcurves(wd, &adt->drivers); - + /* write overrides */ // FIXME: are these needed? - for (aor= adt->overrides.first; aor; aor= aor->next) { + for (aor = adt->overrides.first; aor; aor = aor->next) { /* overrides consist of base data + rna_path */ writestruct(wd, DATA, "AnimOverride", 1, aor); - writedata(wd, DATA, strlen(aor->rna_path)+1, aor->rna_path); + writedata(wd, DATA, strlen(aor->rna_path) + 1, aor->rna_path); } - + // TODO write the remaps (if they are needed) - + /* write NLA data */ write_nladata(wd, &adt->nla_tracks); } static void write_curvemapping_curves(WriteData *wd, CurveMapping *cumap) { - int a; - - for (a = 0; a < CM_TOT; a++) + for (int a = 0; a < CM_TOT; a++) { writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve); + } } static void write_curvemapping(WriteData *wd, CurveMapping *cumap) @@ -838,14 +860,14 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no #ifdef USE_NODE_COMPAT_CUSTOMNODES /* forward compatibility code, so older blenders still open */ sock->stack_type = 1; - + if (node->type == NODE_GROUP) { bNodeTree *ngroup = (bNodeTree *)node->id; if (ngroup) { /* for node groups: look up the deprecated groupsock pointer */ sock->groupsock = ntreeFindSocketInterface(ngroup, sock->in_out, sock->identifier); BLI_assert(sock->groupsock != NULL); - + /* node group sockets now use the generic identifier string to verify group nodes, * old blender uses the own_index. */ @@ -857,18 +879,20 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no /* actual socket writing */ writestruct(wd, DATA, "bNodeSocket", 1, sock); - if (sock->prop) + if (sock->prop) { IDP_WriteProperty(sock->prop, wd); - - if (sock->default_value) + } + + if (sock->default_value) { writedata(wd, DATA, MEM_allocN_len(sock->default_value), sock->default_value); + } } static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree), bNodeSocket *sock) { #ifdef USE_NODE_COMPAT_CUSTOMNODES /* forward compatibility code, so older blenders still open */ sock->stack_type = 1; - + /* Reconstruct the deprecated default_value structs in socket interface DNA. */ if (sock->default_value == NULL && sock->typeinfo) { node_socket_init_default_value(sock); @@ -878,11 +902,13 @@ static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree), /* actual socket writing */ writestruct(wd, DATA, "bNodeSocket", 1, sock); - if (sock->prop) + if (sock->prop) { IDP_WriteProperty(sock->prop, wd); - - if (sock->default_value) + } + + if (sock->default_value) { writedata(wd, DATA, MEM_allocN_len(sock->default_value), sock->default_value); + } } /* this is only direct data, tree itself should have been written */ static void write_nodetree(WriteData *wd, bNodeTree *ntree) @@ -890,64 +916,91 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) bNode *node; bNodeSocket *sock; bNodeLink *link; - + /* for link_list() speed, we write per list */ - - if (ntree->adt) write_animdata(wd, ntree->adt); - + + if (ntree->adt) { + write_animdata(wd, ntree->adt); + } + for (node = ntree->nodes.first; node; node = node->next) { writestruct(wd, DATA, "bNode", 1, node); - if (node->prop) + if (node->prop) { IDP_WriteProperty(node->prop, wd); + } - for (sock= node->inputs.first; sock; sock= sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) { write_node_socket(wd, ntree, node, sock); - for (sock= node->outputs.first; sock; sock= sock->next) + } + for (sock = node->outputs.first; sock; sock = sock->next) { write_node_socket(wd, ntree, node, sock); - - for (link = node->internal_links.first; link; link = link->next) + } + + for (link = node->internal_links.first; link; link = link->next) { writestruct(wd, DATA, "bNodeLink", 1, link); + } + if (node->storage) { /* could be handlerized at some point, now only 1 exception still */ - if (ntree->type==NTREE_SHADER && (node->type==SH_NODE_CURVE_VEC || node->type==SH_NODE_CURVE_RGB)) + if ((ntree->type == NTREE_SHADER) && + ELEM(node->type, SH_NODE_CURVE_VEC, SH_NODE_CURVE_RGB)) + { write_curvemapping(wd, node->storage); - else if (ntree->type==NTREE_SHADER && node->type==SH_NODE_SCRIPT) { + } + else if (ntree->type == NTREE_SHADER && + (node->type == SH_NODE_SCRIPT)) + { NodeShaderScript *nss = (NodeShaderScript *)node->storage; - if (nss->bytecode) - writedata(wd, DATA, strlen(nss->bytecode)+1, nss->bytecode); + if (nss->bytecode) { + writedata(wd, DATA, strlen(nss->bytecode) + 1, nss->bytecode); + } writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); } - else if (ntree->type==NTREE_COMPOSIT && ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) + else if ((ntree->type == NTREE_COMPOSIT) && + ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) + { write_curvemapping(wd, node->storage); - else if (ntree->type==NTREE_TEXTURE && (node->type==TEX_NODE_CURVE_RGB || node->type==TEX_NODE_CURVE_TIME) ) + } + else if ((ntree->type == NTREE_TEXTURE) && + (node->type == TEX_NODE_CURVE_RGB || node->type == TEX_NODE_CURVE_TIME)) + { write_curvemapping(wd, node->storage); - else if (ntree->type==NTREE_COMPOSIT && node->type==CMP_NODE_MOVIEDISTORTION) { + } + else if ((ntree->type == NTREE_COMPOSIT) && + (node->type == CMP_NODE_MOVIEDISTORTION)) + { /* pass */ } - else + else { writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + } } - - if (node->type==CMP_NODE_OUTPUT_FILE) { + + if (node->type == CMP_NODE_OUTPUT_FILE) { /* inputs have own storage data */ - for (sock = node->inputs.first; sock; sock = sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) { writestruct(wd, DATA, "NodeImageMultiFileSocket", 1, sock->storage); + } } - if (node->type==CMP_NODE_IMAGE) { + if (node->type == CMP_NODE_IMAGE) { /* write extra socket info */ - for (sock = node->outputs.first; sock; sock = sock->next) + for (sock = node->outputs.first; sock; sock = sock->next) { writestruct(wd, DATA, "NodeImageLayer", 1, sock->storage); + } } } - - for (link= ntree->links.first; link; link= link->next) + + for (link = ntree->links.first; link; link = link->next) { writestruct(wd, DATA, "bNodeLink", 1, link); - - for (sock = ntree->inputs.first; sock; sock = sock->next) + } + + for (sock = ntree->inputs.first; sock; sock = sock->next) { write_node_socket_interface(wd, ntree, sock); - for (sock = ntree->outputs.first; sock; sock = sock->next) + } + for (sock = ntree->outputs.first; sock; sock = sock->next) { write_node_socket_interface(wd, ntree, sock); + } } /** @@ -1002,9 +1055,11 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) /* XXX in future, handle multiple windows with multiple screens? */ current_screen_compat(mainvar, &curscreen, false); - if (curscreen) curscene = curscreen->scene; - - for (sce= mainvar->scene.first; sce; sce= sce->id.next) { + if (curscreen) { + curscene = curscreen->scene; + } + + for (sce = mainvar->scene.first; sce; sce = sce->id.next) { if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) { data.sfra = sce->r.sfra; data.efra = sce->r.efra; @@ -1020,8 +1075,9 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) static void write_keymapitem(WriteData *wd, wmKeyMapItem *kmi) { writestruct(wd, DATA, "wmKeyMapItem", 1, kmi); - if (kmi->properties) + if (kmi->properties) { IDP_WriteProperty(kmi->properties, wd); + } } static void write_userdef(WriteData *wd) @@ -1033,28 +1089,32 @@ static void write_userdef(WriteData *wd) bAddon *bext; bPathCompare *path_cmp; uiStyle *style; - + writestruct(wd, USER, "UserDef", 1, &U); - for (btheme= U.themes.first; btheme; btheme=btheme->next) + for (btheme = U.themes.first; btheme; btheme = btheme->next) { writestruct(wd, DATA, "bTheme", 1, btheme); + } - for (keymap= U.user_keymaps.first; keymap; keymap=keymap->next) { + for (keymap = U.user_keymaps.first; keymap; keymap = keymap->next) { writestruct(wd, DATA, "wmKeyMap", 1, keymap); - for (kmdi=keymap->diff_items.first; kmdi; kmdi=kmdi->next) { + for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { writestruct(wd, DATA, "wmKeyMapDiffItem", 1, kmdi); - if (kmdi->remove_item) + if (kmdi->remove_item) { write_keymapitem(wd, kmdi->remove_item); - if (kmdi->add_item) + } + if (kmdi->add_item) { write_keymapitem(wd, kmdi->add_item); + } } - for (kmi=keymap->items.first; kmi; kmi=kmi->next) + for (kmi = keymap->items.first; kmi; kmi = kmi->next) { write_keymapitem(wd, kmi); + } } - for (bext= U.addons.first; bext; bext=bext->next) { + for (bext = U.addons.first; bext; bext = bext->next) { writestruct(wd, DATA, "bAddon", 1, bext); if (bext->prop) { IDP_WriteProperty(bext->prop, wd); @@ -1064,8 +1124,8 @@ static void write_userdef(WriteData *wd) for (path_cmp = U.autoexec_paths.first; path_cmp; path_cmp = path_cmp->next) { writestruct(wd, DATA, "bPathCompare", 1, path_cmp); } - - for (style= U.uistyles.first; style; style= style->next) { + + for (style = U.uistyles.first; style; style = style->next) { writestruct(wd, DATA, "uiStyle", 1, style); } } @@ -1073,11 +1133,10 @@ static void write_userdef(WriteData *wd) static void write_boid_state(WriteData *wd, BoidState *state) { BoidRule *rule = state->rules.first; - //BoidCondition *cond = state->conditions.first; writestruct(wd, DATA, "BoidState", 1, state); - for (; rule; rule=rule->next) { + for (; rule; rule = rule->next) { switch (rule->type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: @@ -1100,8 +1159,12 @@ static void write_boid_state(WriteData *wd, BoidState *state) break; } } - //for (; cond; cond=cond->next) - // writestruct(wd, DATA, "BoidCondition", 1, cond); +#if 0 + BoidCondition *cond = state->conditions.first; + for (; cond; cond = cond->next) { + writestruct(wd, DATA, "BoidCondition", 1, cond); + } +#endif } /* update this also to readfile.c */ @@ -1124,29 +1187,32 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) PointCache *cache = ptcaches->first; int i; - for (; cache; cache=cache->next) { + for (; cache; cache = cache->next) { writestruct(wd, DATA, "PointCache", 1, cache); - if ((cache->flag & PTCACHE_DISK_CACHE)==0) { + if ((cache->flag & PTCACHE_DISK_CACHE) == 0) { PTCacheMem *pm = cache->mem_cache.first; - for (; pm; pm=pm->next) { + for (; pm; pm = pm->next) { PTCacheExtra *extra = pm->extradata.first; writestruct(wd, DATA, "PTCacheMem", 1, pm); - - for (i=0; idata[i] && pm->data_types & (1<data[i] && pm->data_types & (1 << i)) { + if (ptcache_data_struct[i][0] == '\0') { writedata(wd, DATA, MEM_allocN_len(pm->data[i]), pm->data[i]); - else + } + else { writestruct(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); + } } } - for (; extra; extra=extra->next) { - if (ptcache_extra_struct[extra->type][0] == '\0') + for (; extra; extra = extra->next) { + if (ptcache_extra_struct[extra->type][0] == '\0') { continue; + } writestruct(wd, DATA, "PTCacheExtra", 1, extra); writestruct(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); } @@ -1161,31 +1227,35 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) GroupObject *go; int a; - part= idbase->first; + part = idbase->first; while (part) { - if (part->id.us>0 || wd->current) { + if (part->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_PA, "ParticleSettings", 1, part); write_iddata(wd, &part->id); - if (part->adt) write_animdata(wd, part->adt); + if (part->adt) { + write_animdata(wd, part->adt); + } writestruct(wd, DATA, "PartDeflect", 1, part->pd); writestruct(wd, DATA, "PartDeflect", 1, part->pd2); writestruct(wd, DATA, "EffectorWeights", 1, part->effector_weights); - if (part->clumpcurve) + if (part->clumpcurve) { write_curvemapping(wd, part->clumpcurve); - if (part->roughcurve) + } + if (part->roughcurve) { write_curvemapping(wd, part->roughcurve); - + } + dw = part->dupliweights.first; - for (; dw; dw=dw->next) { + for (; dw; dw = dw->next) { /* update indices */ dw->index = 0; if (part->dup_group) { /* can be NULL if lining fails or set to None */ go = part->dup_group->gobject.first; while (go && go->ob != dw->ob) { - go=go->next; + go = go->next; dw->index++; } } @@ -1197,27 +1267,30 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) writestruct(wd, DATA, "BoidSettings", 1, part->boids); - for (; state; state=state->next) + for (; state; state = state->next) { write_boid_state(wd, state); + } } if (part->fluid && part->phystype == PART_PHYS_FLUID) { - writestruct(wd, DATA, "SPHFluidSettings", 1, part->fluid); + writestruct(wd, DATA, "SPHFluidSettings", 1, part->fluid); } - for (a=0; amtex[a]) writestruct(wd, DATA, "MTex", 1, part->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (part->mtex[a]) { + writestruct(wd, DATA, "MTex", 1, part->mtex[a]); + } } } - part= part->id.next; + part = part->id.next; } } static void write_particlesystems(WriteData *wd, ListBase *particles) { - ParticleSystem *psys= particles->first; + ParticleSystem *psys = particles->first; ParticleTarget *pt; int a; - for (; psys; psys=psys->next) { + for (; psys; psys = psys->next) { writestruct(wd, DATA, "ParticleSystem", 1, psys); if (psys->particles) { @@ -1226,21 +1299,32 @@ static void write_particlesystems(WriteData *wd, ListBase *particles) if (psys->particles->hair) { ParticleData *pa = psys->particles; - for (a=0; atotpart; a++, pa++) + for (a = 0; a < psys->totpart; a++, pa++) { writestruct(wd, DATA, "HairKey", pa->totkey, pa->hair); + } } - if (psys->particles->boid && psys->part->phystype == PART_PHYS_BOIDS) + if (psys->particles->boid && + (psys->part->phystype == PART_PHYS_BOIDS)) + { writestruct(wd, DATA, "BoidParticle", psys->totpart, psys->particles->boid); + } - if (psys->part->fluid && psys->part->phystype == PART_PHYS_FLUID && (psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) + if (psys->part->fluid && + (psys->part->phystype == PART_PHYS_FLUID) && + (psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) + { writestruct(wd, DATA, "ParticleSpring", psys->tot_fluidsprings, psys->fluid_springs); + } } pt = psys->targets.first; - for (; pt; pt=pt->next) + for (; pt; pt = pt->next) { writestruct(wd, DATA, "ParticleTarget", 1, pt); + } - if (psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchild, psys->child); + if (psys->child) { + writestruct(wd, DATA, "ChildParticle", psys->totchild, psys->child); + } if (psys->clmd) { writestruct(wd, DATA, "ClothModifierData", 1, psys->clmd); @@ -1256,14 +1340,15 @@ static void write_properties(WriteData *wd, ListBase *lb) { bProperty *prop; - prop= lb->first; + prop = lb->first; while (prop) { writestruct(wd, DATA, "bProperty", 1, prop); - if (prop->poin && prop->poin != &prop->data) + if (prop->poin && prop->poin != &prop->data) { writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin); + } - prop= prop->next; + prop = prop->next; } } @@ -1271,57 +1356,57 @@ static void write_sensors(WriteData *wd, ListBase *lb) { bSensor *sens; - sens= lb->first; + sens = lb->first; while (sens) { writestruct(wd, DATA, "bSensor", 1, sens); - writedata(wd, DATA, sizeof(void *)*sens->totlinks, sens->links); + writedata(wd, DATA, sizeof(void *) * sens->totlinks, sens->links); switch (sens->type) { - case SENS_NEAR: - writestruct(wd, DATA, "bNearSensor", 1, sens->data); - break; - case SENS_MOUSE: - writestruct(wd, DATA, "bMouseSensor", 1, sens->data); - break; - case SENS_KEYBOARD: - writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data); - break; - case SENS_PROPERTY: - writestruct(wd, DATA, "bPropertySensor", 1, sens->data); - break; - case SENS_ARMATURE: - writestruct(wd, DATA, "bArmatureSensor", 1, sens->data); - break; - case SENS_ACTUATOR: - writestruct(wd, DATA, "bActuatorSensor", 1, sens->data); - break; - case SENS_DELAY: - writestruct(wd, DATA, "bDelaySensor", 1, sens->data); - break; - case SENS_COLLISION: - writestruct(wd, DATA, "bCollisionSensor", 1, sens->data); - break; - case SENS_RADAR: - writestruct(wd, DATA, "bRadarSensor", 1, sens->data); - break; - case SENS_RANDOM: - writestruct(wd, DATA, "bRandomSensor", 1, sens->data); - break; - case SENS_RAY: - writestruct(wd, DATA, "bRaySensor", 1, sens->data); - break; - case SENS_MESSAGE: - writestruct(wd, DATA, "bMessageSensor", 1, sens->data); - break; - case SENS_JOYSTICK: - writestruct(wd, DATA, "bJoystickSensor", 1, sens->data); - break; - default: - ; /* error: don't know how to write this file */ + case SENS_NEAR: + writestruct(wd, DATA, "bNearSensor", 1, sens->data); + break; + case SENS_MOUSE: + writestruct(wd, DATA, "bMouseSensor", 1, sens->data); + break; + case SENS_KEYBOARD: + writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data); + break; + case SENS_PROPERTY: + writestruct(wd, DATA, "bPropertySensor", 1, sens->data); + break; + case SENS_ARMATURE: + writestruct(wd, DATA, "bArmatureSensor", 1, sens->data); + break; + case SENS_ACTUATOR: + writestruct(wd, DATA, "bActuatorSensor", 1, sens->data); + break; + case SENS_DELAY: + writestruct(wd, DATA, "bDelaySensor", 1, sens->data); + break; + case SENS_COLLISION: + writestruct(wd, DATA, "bCollisionSensor", 1, sens->data); + break; + case SENS_RADAR: + writestruct(wd, DATA, "bRadarSensor", 1, sens->data); + break; + case SENS_RANDOM: + writestruct(wd, DATA, "bRandomSensor", 1, sens->data); + break; + case SENS_RAY: + writestruct(wd, DATA, "bRaySensor", 1, sens->data); + break; + case SENS_MESSAGE: + writestruct(wd, DATA, "bMessageSensor", 1, sens->data); + break; + case SENS_JOYSTICK: + writestruct(wd, DATA, "bJoystickSensor", 1, sens->data); + break; + default: + ; /* error: don't know how to write this file */ } - sens= sens->next; + sens = sens->next; } } @@ -1329,24 +1414,24 @@ static void write_controllers(WriteData *wd, ListBase *lb) { bController *cont; - cont= lb->first; + cont = lb->first; while (cont) { writestruct(wd, DATA, "bController", 1, cont); - writedata(wd, DATA, sizeof(void *)*cont->totlinks, cont->links); + writedata(wd, DATA, sizeof(void *) * cont->totlinks, cont->links); switch (cont->type) { - case CONT_EXPRESSION: - writestruct(wd, DATA, "bExpressionCont", 1, cont->data); - break; - case CONT_PYTHON: - writestruct(wd, DATA, "bPythonCont", 1, cont->data); - break; - default: - ; /* error: don't know how to write this file */ + case CONT_EXPRESSION: + writestruct(wd, DATA, "bExpressionCont", 1, cont->data); + break; + case CONT_PYTHON: + writestruct(wd, DATA, "bPythonCont", 1, cont->data); + break; + default: + ; /* error: don't know how to write this file */ } - cont= cont->next; + cont = cont->next; } } @@ -1354,86 +1439,87 @@ static void write_actuators(WriteData *wd, ListBase *lb) { bActuator *act; - act= lb->first; + act = lb->first; while (act) { writestruct(wd, DATA, "bActuator", 1, act); switch (act->type) { - case ACT_ACTION: - case ACT_SHAPEACTION: - writestruct(wd, DATA, "bActionActuator", 1, act->data); - break; - case ACT_SOUND: - writestruct(wd, DATA, "bSoundActuator", 1, act->data); - break; - case ACT_OBJECT: - writestruct(wd, DATA, "bObjectActuator", 1, act->data); - break; - case ACT_PROPERTY: - writestruct(wd, DATA, "bPropertyActuator", 1, act->data); - break; - case ACT_CAMERA: - writestruct(wd, DATA, "bCameraActuator", 1, act->data); - break; - case ACT_CONSTRAINT: - writestruct(wd, DATA, "bConstraintActuator", 1, act->data); - break; - case ACT_EDIT_OBJECT: - writestruct(wd, DATA, "bEditObjectActuator", 1, act->data); - break; - case ACT_SCENE: - writestruct(wd, DATA, "bSceneActuator", 1, act->data); - break; - case ACT_GROUP: - writestruct(wd, DATA, "bGroupActuator", 1, act->data); - break; - case ACT_RANDOM: - writestruct(wd, DATA, "bRandomActuator", 1, act->data); - break; - case ACT_MESSAGE: - writestruct(wd, DATA, "bMessageActuator", 1, act->data); - break; - case ACT_GAME: - writestruct(wd, DATA, "bGameActuator", 1, act->data); - break; - case ACT_VISIBILITY: - writestruct(wd, DATA, "bVisibilityActuator", 1, act->data); - break; - case ACT_2DFILTER: - writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data); - break; - case ACT_PARENT: - writestruct(wd, DATA, "bParentActuator", 1, act->data); - break; - case ACT_STATE: - writestruct(wd, DATA, "bStateActuator", 1, act->data); - break; - case ACT_ARMATURE: - writestruct(wd, DATA, "bArmatureActuator", 1, act->data); - break; - case ACT_STEERING: - writestruct(wd, DATA, "bSteeringActuator", 1, act->data); - break; - case ACT_MOUSE: - writestruct(wd, DATA, "bMouseActuator", 1, act->data); - break; - default: - ; /* error: don't know how to write this file */ + case ACT_ACTION: + case ACT_SHAPEACTION: + writestruct(wd, DATA, "bActionActuator", 1, act->data); + break; + case ACT_SOUND: + writestruct(wd, DATA, "bSoundActuator", 1, act->data); + break; + case ACT_OBJECT: + writestruct(wd, DATA, "bObjectActuator", 1, act->data); + break; + case ACT_PROPERTY: + writestruct(wd, DATA, "bPropertyActuator", 1, act->data); + break; + case ACT_CAMERA: + writestruct(wd, DATA, "bCameraActuator", 1, act->data); + break; + case ACT_CONSTRAINT: + writestruct(wd, DATA, "bConstraintActuator", 1, act->data); + break; + case ACT_EDIT_OBJECT: + writestruct(wd, DATA, "bEditObjectActuator", 1, act->data); + break; + case ACT_SCENE: + writestruct(wd, DATA, "bSceneActuator", 1, act->data); + break; + case ACT_GROUP: + writestruct(wd, DATA, "bGroupActuator", 1, act->data); + break; + case ACT_RANDOM: + writestruct(wd, DATA, "bRandomActuator", 1, act->data); + break; + case ACT_MESSAGE: + writestruct(wd, DATA, "bMessageActuator", 1, act->data); + break; + case ACT_GAME: + writestruct(wd, DATA, "bGameActuator", 1, act->data); + break; + case ACT_VISIBILITY: + writestruct(wd, DATA, "bVisibilityActuator", 1, act->data); + break; + case ACT_2DFILTER: + writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data); + break; + case ACT_PARENT: + writestruct(wd, DATA, "bParentActuator", 1, act->data); + break; + case ACT_STATE: + writestruct(wd, DATA, "bStateActuator", 1, act->data); + break; + case ACT_ARMATURE: + writestruct(wd, DATA, "bArmatureActuator", 1, act->data); + break; + case ACT_STEERING: + writestruct(wd, DATA, "bSteeringActuator", 1, act->data); + break; + case ACT_MOUSE: + writestruct(wd, DATA, "bMouseActuator", 1, act->data); + break; + default: + ; /* error: don't know how to write this file */ } - act= act->next; + act = act->next; } } static void write_motionpath(WriteData *wd, bMotionPath *mpath) { /* sanity checks */ - if (mpath == NULL) + if (mpath == NULL) { return; - + } + /* firstly, just write the motionpath struct */ writestruct(wd, DATA, "bMotionPath", 1, mpath); - + /* now write the array of data */ writestruct(wd, DATA, "bMotionPathVert", mpath->length, mpath->points); } @@ -1442,43 +1528,44 @@ static void write_constraints(WriteData *wd, ListBase *conlist) { bConstraint *con; - for (con=conlist->first; con; con=con->next) { - const bConstraintTypeInfo *cti= BKE_constraint_typeinfo_get(con); - + for (con = conlist->first; con; con = con->next) { + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); + /* Write the specific data */ if (cti && con->data) { /* firstly, just write the plain con->data struct */ writestruct(wd, DATA, cti->structName, 1, con->data); - + /* do any constraint specific stuff */ switch (con->type) { case CONSTRAINT_TYPE_PYTHON: { - bPythonConstraint *data = (bPythonConstraint *)con->data; + bPythonConstraint *data = con->data; bConstraintTarget *ct; - + /* write targets */ - for (ct= data->targets.first; ct; ct= ct->next) + for (ct = data->targets.first; ct; ct = ct->next) { writestruct(wd, DATA, "bConstraintTarget", 1, ct); - + } + /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ IDP_WriteProperty(data->prop, wd); break; } - case CONSTRAINT_TYPE_SPLINEIK: + case CONSTRAINT_TYPE_SPLINEIK: { - bSplineIKConstraint *data = (bSplineIKConstraint *)con->data; - + bSplineIKConstraint *data = con->data; + /* write points array */ - writedata(wd, DATA, sizeof(float)*(data->numpoints), data->points); + writedata(wd, DATA, sizeof(float) * (data->numpoints), data->points); break; } } } - + /* Write the constraint */ writestruct(wd, DATA, "bConstraint", 1, con); } @@ -1490,36 +1577,43 @@ static void write_pose(WriteData *wd, bPose *pose) bActionGroup *grp; /* Write each channel */ - if (!pose) + if (pose == NULL) { return; + } /* Write channels */ - for (chan=pose->chanbase.first; chan; chan=chan->next) { + for (chan = pose->chanbase.first; chan; chan = chan->next) { /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - if (chan->prop) + if (chan->prop) { IDP_WriteProperty(chan->prop, wd); - + } + write_constraints(wd, &chan->constraints); - + write_motionpath(wd, chan->mpath); - - /* prevent crashes with autosave, when a bone duplicated in editmode has not yet been assigned to its posechannel */ - if (chan->bone) - chan->selectflag= chan->bone->flag & BONE_SELECTED; /* gets restored on read, for library armatures */ - + + /* prevent crashes with autosave, + * when a bone duplicated in editmode has not yet been assigned to its posechannel */ + if (chan->bone) { + /* gets restored on read, for library armatures */ + chan->selectflag = chan->bone->flag & BONE_SELECTED; + } + writestruct(wd, DATA, "bPoseChannel", 1, chan); } - + /* Write groups */ - for (grp=pose->agroups.first; grp; grp=grp->next) + for (grp = pose->agroups.first; grp; grp = grp->next) { writestruct(wd, DATA, "bActionGroup", 1, grp); + } /* write IK param */ if (pose->ikparam) { const char *structname = BKE_pose_ikparam_get_name(pose); - if (structname) + if (structname) { writestruct(wd, DATA, structname, 1, pose->ikparam); + } } /* Write this pose */ @@ -1529,87 +1623,94 @@ static void write_pose(WriteData *wd, bPose *pose) static void write_defgroups(WriteData *wd, ListBase *defbase) { - bDeformGroup *defgroup; - - for (defgroup=defbase->first; defgroup; defgroup=defgroup->next) + for (bDeformGroup *defgroup = defbase->first; defgroup; defgroup = defgroup->next) { writestruct(wd, DATA, "bDeformGroup", 1, defgroup); + } } static void write_modifiers(WriteData *wd, ListBase *modbase) { ModifierData *md; - if (modbase == NULL) return; - for (md=modbase->first; md; md= md->next) { + if (modbase == NULL) { + return; + } + + for (md = modbase->first; md; md = md->next) { const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - if (mti == NULL) return; - + if (mti == NULL) { + return; + } + writestruct(wd, DATA, mti->structName, 1, md); - - if (md->type==eModifierType_Hook) { - HookModifierData *hmd = (HookModifierData*) md; - + + if (md->type == eModifierType_Hook) { + HookModifierData *hmd = (HookModifierData *)md; + if (hmd->curfalloff) { write_curvemapping(wd, hmd->curfalloff); } - writedata(wd, DATA, sizeof(int)*hmd->totindex, hmd->indexar); + writedata(wd, DATA, sizeof(int) * hmd->totindex, hmd->indexar); } - else if (md->type==eModifierType_Cloth) { - ClothModifierData *clmd = (ClothModifierData*) md; - + else if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *)md; + writestruct(wd, DATA, "ClothSimSettings", 1, clmd->sim_parms); writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms); writestruct(wd, DATA, "EffectorWeights", 1, clmd->sim_parms->effector_weights); write_pointcaches(wd, &clmd->ptcaches); } - else if (md->type==eModifierType_Smoke) { - SmokeModifierData *smd = (SmokeModifierData*) md; - + else if (md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { if (smd->domain) { write_pointcaches(wd, &(smd->domain->ptcaches[0])); /* create fake pointcache so that old blender versions can read it */ smd->domain->point_cache[1] = BKE_ptcache_add(&smd->domain->ptcaches[1]); - smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE|PTCACHE_FAKE_SMOKE; + smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE | PTCACHE_FAKE_SMOKE; smd->domain->point_cache[1]->step = 1; write_pointcaches(wd, &(smd->domain->ptcaches[1])); } - + writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain); if (smd->domain) { /* cleanup the fake pointcache */ BKE_ptcache_free_list(&smd->domain->ptcaches[1]); smd->domain->point_cache[1] = NULL; - + writestruct(wd, DATA, "EffectorWeights", 1, smd->domain->effector_weights); } } - else if (smd->type & MOD_SMOKE_TYPE_FLOW) + else if (smd->type & MOD_SMOKE_TYPE_FLOW) { writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow); - else if (smd->type & MOD_SMOKE_TYPE_COLL) + } + else if (smd->type & MOD_SMOKE_TYPE_COLL) { writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll); + } } - else if (md->type==eModifierType_Fluidsim) { - FluidsimModifierData *fluidmd = (FluidsimModifierData*) md; - + else if (md->type == eModifierType_Fluidsim) { + FluidsimModifierData *fluidmd = (FluidsimModifierData *)md; + writestruct(wd, DATA, "FluidsimSettings", 1, fluidmd->fss); } - else if (md->type==eModifierType_DynamicPaint) { - DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; - + else if (md->type == eModifierType_DynamicPaint) { + DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; + if (pmd->canvas) { DynamicPaintSurface *surface; writestruct(wd, DATA, "DynamicPaintCanvasSettings", 1, pmd->canvas); - + /* write surfaces */ - for (surface=pmd->canvas->surfaces.first; surface; surface=surface->next) + for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { writestruct(wd, DATA, "DynamicPaintSurface", 1, surface); + } /* write caches and effector weights */ - for (surface=pmd->canvas->surfaces.first; surface; surface=surface->next) { + for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { write_pointcaches(wd, &(surface->ptcaches)); writestruct(wd, DATA, "EffectorWeights", 1, surface->effector_weights); @@ -1621,45 +1722,46 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) writestruct(wd, DATA, "ColorBand", 1, pmd->brush->vel_ramp); } } - else if (md->type==eModifierType_Collision) { - + else if (md->type == eModifierType_Collision) { + #if 0 - CollisionModifierData *collmd = (CollisionModifierData*) md; - // TODO: CollisionModifier should use pointcache + CollisionModifierData *collmd = (CollisionModifierData *)md; + // TODO: CollisionModifier should use pointcache // + have proper reset events before enabling this writestruct(wd, DATA, "MVert", collmd->numverts, collmd->x); writestruct(wd, DATA, "MVert", collmd->numverts, collmd->xnew); writestruct(wd, DATA, "MFace", collmd->numfaces, collmd->mfaces); #endif } - else if (md->type==eModifierType_MeshDeform) { - MeshDeformModifierData *mmd = (MeshDeformModifierData*) md; + else if (md->type == eModifierType_MeshDeform) { + MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; int size = mmd->dyngridsize; writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->bindinfluences); writedata(wd, DATA, sizeof(int) * (mmd->totvert + 1), mmd->bindoffsets); writedata(wd, DATA, sizeof(float) * 3 * mmd->totcagevert, - mmd->bindcagecos); - writestruct(wd, DATA, "MDefCell", size*size*size, mmd->dyngrid); + mmd->bindcagecos); + writestruct(wd, DATA, "MDefCell", size * size * size, mmd->dyngrid); writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->dyninfluences); - writedata(wd, DATA, sizeof(int)*mmd->totvert, mmd->dynverts); + writedata(wd, DATA, sizeof(int) * mmd->totvert, mmd->dynverts); } - else if (md->type==eModifierType_Warp) { - WarpModifierData *tmd = (WarpModifierData*) md; + else if (md->type == eModifierType_Warp) { + WarpModifierData *tmd = (WarpModifierData *)md; if (tmd->curfalloff) { write_curvemapping(wd, tmd->curfalloff); } } - else if (md->type==eModifierType_WeightVGEdit) { - WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md; + else if (md->type == eModifierType_WeightVGEdit) { + WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md; - if (wmd->cmap_curve) + if (wmd->cmap_curve) { write_curvemapping(wd, wmd->cmap_curve); + } } - else if (md->type==eModifierType_LaplacianDeform) { - LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData*) md; + else if (md->type == eModifierType_LaplacianDeform) { + LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md; - writedata(wd, DATA, sizeof(float)*lmd->total_verts * 3, lmd->vertexco); + writedata(wd, DATA, sizeof(float) * lmd->total_verts * 3, lmd->vertexco); } else if (md->type == eModifierType_CorrectiveSmooth) { CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)md; @@ -1674,19 +1776,21 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) static void write_objects(WriteData *wd, ListBase *idbase) { Object *ob; - - ob= idbase->first; + + ob = idbase->first; while (ob) { - if (ob->id.us>0 || wd->current) { + if (ob->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_OB, "Object", 1, ob); write_iddata(wd, &ob->id); - if (ob->adt) write_animdata(wd, ob->adt); - + if (ob->adt) { + write_animdata(wd, ob->adt); + } + /* direct data */ - writedata(wd, DATA, sizeof(void *)*ob->totcol, ob->mat); - writedata(wd, DATA, sizeof(char)*ob->totcol, ob->matbits); + writedata(wd, DATA, sizeof(void *) * ob->totcol, ob->mat); + writedata(wd, DATA, sizeof(char) * ob->totcol, ob->matbits); /* write_effects(wd, &ob->effect); */ /* not used anymore */ write_properties(wd, &ob->prop); write_sensors(wd, &ob->sensors); @@ -1704,7 +1808,7 @@ static void write_objects(WriteData *wd, ListBase *idbase) write_defgroups(wd, &ob->defbase); write_constraints(wd, &ob->constraints); write_motionpath(wd, ob->mpath); - + writestruct(wd, DATA, "PartDeflect", 1, ob->pd); writestruct(wd, DATA, "SoftBody", 1, ob->soft); if (ob->soft) { @@ -1712,9 +1816,9 @@ static void write_objects(WriteData *wd, ListBase *idbase) writestruct(wd, DATA, "EffectorWeights", 1, ob->soft->effector_weights); } writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft); - + if (ob->rigidbody_object) { - // TODO: if any extra data is added to handle duplis, will need separate function then + /* TODO: if any extra data is added to handle duplis, will need separate function then */ writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object); } if (ob->rigidbody_constraint) { @@ -1734,7 +1838,7 @@ static void write_objects(WriteData *wd, ListBase *idbase) write_previews(wd, ob->preview); - ob= ob->id.next; + ob = ob->id.next; } /* flush helps the compression for undo-save */ @@ -1745,11 +1849,11 @@ static void write_objects(WriteData *wd, ListBase *idbase) static void write_vfonts(WriteData *wd, ListBase *idbase) { VFont *vf; - PackedFile * pf; + PackedFile *pf; - vf= idbase->first; + vf = idbase->first; while (vf) { - if (vf->id.us>0 || wd->current) { + if (vf->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_VF, "VFont", 1, vf); write_iddata(wd, &vf->id); @@ -1763,7 +1867,7 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) } } - vf= vf->id.next; + vf = vf->id.next; } } @@ -1773,25 +1877,29 @@ static void write_keys(WriteData *wd, ListBase *idbase) Key *key; KeyBlock *kb; - key= idbase->first; + key = idbase->first; while (key) { - if (key->id.us>0 || wd->current) { + if (key->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_KE, "Key", 1, key); write_iddata(wd, &key->id); - if (key->adt) write_animdata(wd, key->adt); - + if (key->adt) { + write_animdata(wd, key->adt); + } + /* direct data */ - kb= key->block.first; + kb = key->block.first; while (kb) { writestruct(wd, DATA, "KeyBlock", 1, kb); - if (kb->data) writedata(wd, DATA, kb->totelem*key->elemsize, kb->data); - kb= kb->next; + if (kb->data) { + writedata(wd, DATA, kb->totelem * key->elemsize, kb->data); + } + kb = kb->next; } } - key= key->id.next; + key = key->id.next; } /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); @@ -1801,17 +1909,19 @@ static void write_cameras(WriteData *wd, ListBase *idbase) { Camera *cam; - cam= idbase->first; + cam = idbase->first; while (cam) { - if (cam->id.us>0 || wd->current) { + if (cam->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_CA, "Camera", 1, cam); write_iddata(wd, &cam->id); - if (cam->adt) write_animdata(wd, cam->adt); + if (cam->adt) { + write_animdata(wd, cam->adt); + } } - cam= cam->id.next; + cam = cam->id.next; } } @@ -1820,24 +1930,26 @@ static void write_mballs(WriteData *wd, ListBase *idbase) MetaBall *mb; MetaElem *ml; - mb= idbase->first; + mb = idbase->first; while (mb) { - if (mb->id.us>0 || wd->current) { + if (mb->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_MB, "MetaBall", 1, mb); write_iddata(wd, &mb->id); /* direct data */ - writedata(wd, DATA, sizeof(void *)*mb->totcol, mb->mat); - if (mb->adt) write_animdata(wd, mb->adt); + writedata(wd, DATA, sizeof(void *) * mb->totcol, mb->mat); + if (mb->adt) { + write_animdata(wd, mb->adt); + } - ml= mb->elems.first; + ml = mb->elems.first; while (ml) { writestruct(wd, DATA, "MetaElem", 1, ml); - ml= ml->next; + ml = ml->next; } } - mb= mb->id.next; + mb = mb->id.next; } } @@ -1846,17 +1958,19 @@ static void write_curves(WriteData *wd, ListBase *idbase) Curve *cu; Nurb *nu; - cu= idbase->first; + cu = idbase->first; while (cu) { - if (cu->id.us>0 || wd->current) { + if (cu->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_CU, "Curve", 1, cu); write_iddata(wd, &cu->id); /* direct data */ - writedata(wd, DATA, sizeof(void *)*cu->totcol, cu->mat); - if (cu->adt) write_animdata(wd, cu->adt); - + writedata(wd, DATA, sizeof(void *) * cu->totcol, cu->mat); + if (cu->adt) { + write_animdata(wd, cu->adt); + } + if (cu->vfont) { writedata(wd, DATA, cu->len + 1, cu->str); writestruct(wd, DATA, "CharInfo", cu->len_wchar + 1, cu->strinfo); @@ -1864,25 +1978,30 @@ static void write_curves(WriteData *wd, ListBase *idbase) } else { /* is also the order of reading */ - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { writestruct(wd, DATA, "Nurb", 1, nu); - nu= nu->next; + nu = nu->next; } - nu= cu->nurb.first; + nu = cu->nurb.first; while (nu) { - if (nu->type == CU_BEZIER) + if (nu->type == CU_BEZIER) { writestruct(wd, DATA, "BezTriple", nu->pntsu, nu->bezt); - else { - writestruct(wd, DATA, "BPoint", nu->pntsu*nu->pntsv, nu->bp); - if (nu->knotsu) writedata(wd, DATA, KNOTSU(nu)*sizeof(float), nu->knotsu); - if (nu->knotsv) writedata(wd, DATA, KNOTSV(nu)*sizeof(float), nu->knotsv); } - nu= nu->next; + else { + writestruct(wd, DATA, "BPoint", nu->pntsu * nu->pntsv, nu->bp); + if (nu->knotsu) { + writedata(wd, DATA, KNOTSU(nu) * sizeof(float), nu->knotsu); + } + if (nu->knotsv) { + writedata(wd, DATA, KNOTSV(nu) * sizeof(float), nu->knotsv); + } + } + nu = nu->next; } } } - cu= cu->id.next; + cu = cu->id.next; } /* flush helps the compression for undo-save */ @@ -1892,15 +2011,15 @@ static void write_curves(WriteData *wd, ListBase *idbase) static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist) { if (dvlist) { - int i; - + /* Write the dvert list */ writestruct(wd, DATA, "MDeformVert", count, dvlist); - + /* Write deformation data for each dvert */ - for (i=0; idisps) { - if (!external) + if (!external) { writedata(wd, DATA, sizeof(float) * 3 * md->totdisp, md->disps); + } } - - if (md->hidden) + + if (md->hidden) { writedata(wd, DATA, BLI_BITMAP_SIZE(md->totdisp), md->hidden); + } } } } @@ -1928,7 +2049,7 @@ static void write_grid_paint_mask(WriteData *wd, int count, GridPaintMask *grid_ { if (grid_paint_mask) { int i; - + writestruct(wd, DATA, "GridPaintMask", count, grid_paint_mask); for (i = 0; i < count; ++i) { GridPaintMask *gpm = &grid_paint_mask[i]; @@ -1949,11 +2070,12 @@ static void write_customdata( int i; /* write external customdata (not for undo) */ - if (data->external && !wd->current) + if (data->external && !wd->current) { CustomData_external_write(data, id, CD_MASK_MESH, count, 0); + } writestruct_at_address(wd, DATA, "CustomDataLayer", data->totlayer, data->layers, layers); - + for (i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &layers[i]; const char *structname; @@ -1979,8 +2101,12 @@ static void write_customdata( /* when using partial visibility, the MEdge and MFace layers * are smaller than the original, so their type and count is * passed to make this work */ - if (layer->type != partial_type) datasize= structnum*count; - else datasize= structnum*partial_count; + if (layer->type != partial_type) { + datasize = structnum * count; + } + else { + datasize = structnum * partial_count; + } writestruct(wd, DATA, structname, datasize, layer->data); } @@ -1991,20 +2117,21 @@ static void write_customdata( } } - if (data->external) + if (data->external) { writestruct(wd, DATA, "CustomDataExternal", 1, data->external); + } } static void write_meshes(WriteData *wd, ListBase *idbase) { Mesh *mesh; - int save_for_old_blender= 0; + int save_for_old_blender = 0; #ifdef USE_BMESH_SAVE_AS_COMPAT save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */ #endif - mesh= idbase->first; + mesh = idbase->first; while (mesh) { CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE]; @@ -2012,7 +2139,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE]; CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE]; - if (mesh->id.us>0 || wd->current) { + if (mesh->id.us > 0 || wd->current) { /* write LibData */ if (!save_for_old_blender) { /* write a copy of the mesh, don't modify in place because it is @@ -2049,9 +2176,11 @@ static void write_meshes(WriteData *wd, ListBase *idbase) write_iddata(wd, &mesh->id); /* direct data */ - if (mesh->adt) write_animdata(wd, mesh->adt); + if (mesh->adt) { + write_animdata(wd, mesh->adt); + } - writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); + writedata(wd, DATA, sizeof(void *) * mesh->totcol, mesh->mat); writedata(wd, DATA, sizeof(MSelect) * mesh->totselect, mesh->mselect); write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, -1, 0); @@ -2107,9 +2236,11 @@ static void write_meshes(WriteData *wd, ListBase *idbase) write_iddata(wd, &mesh->id); /* direct data */ - if (mesh->adt) write_animdata(wd, mesh->adt); + if (mesh->adt) { + write_animdata(wd, mesh->adt); + } - writedata(wd, DATA, sizeof(void *)*mesh->totcol, mesh->mat); + writedata(wd, DATA, sizeof(void *) * mesh->totcol, mesh->mat); /* writedata(wd, DATA, sizeof(MSelect) * mesh->totselect, mesh->mselect); */ /* pre-bmesh NULL's */ write_customdata(wd, &mesh->id, mesh->totvert, &mesh->vdata, vlayers, -1, 0); @@ -2146,44 +2277,46 @@ static void write_meshes(WriteData *wd, ListBase *idbase) MEM_freeN(players); } - mesh= mesh->id.next; + mesh = mesh->id.next; } } static void write_lattices(WriteData *wd, ListBase *idbase) { Lattice *lt; - - lt= idbase->first; + + lt = idbase->first; while (lt) { - if (lt->id.us>0 || wd->current) { + if (lt->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_LT, "Lattice", 1, lt); write_iddata(wd, <->id); /* write animdata */ - if (lt->adt) write_animdata(wd, lt->adt); - + if (lt->adt) { + write_animdata(wd, lt->adt); + } + /* direct data */ - writestruct(wd, DATA, "BPoint", lt->pntsu*lt->pntsv*lt->pntsw, lt->def); - - write_dverts(wd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert); - + writestruct(wd, DATA, "BPoint", lt->pntsu * lt->pntsv * lt->pntsw, lt->def); + + write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); + } - lt= lt->id.next; + lt = lt->id.next; } } static void write_images(WriteData *wd, ListBase *idbase) { Image *ima; - PackedFile * pf; + PackedFile *pf; ImageView *iv; ImagePackedFile *imapf; - ima= idbase->first; + ima = idbase->first; while (ima) { - if (ima->id.us>0 || wd->current) { + if (ima->id.us > 0 || wd->current) { /* Some trickery to keep forward compatibility of packed images. */ BLI_assert(ima->packedfile == NULL); if (ima->packedfiles.first != NULL) { @@ -2206,13 +2339,14 @@ static void write_images(WriteData *wd, ListBase *idbase) write_previews(wd, ima->preview); - for (iv = ima->views.first; iv; iv = iv->next) + for (iv = ima->views.first; iv; iv = iv->next) { writestruct(wd, DATA, "ImageView", 1, iv); + } writestruct(wd, DATA, "Stereo3dFormat", 1, ima->stereo3d_format); ima->packedfile = NULL; } - ima= ima->id.next; + ima = ima->id.next; } /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); @@ -2222,35 +2356,49 @@ static void write_textures(WriteData *wd, ListBase *idbase) { Tex *tex; - tex= idbase->first; + tex = idbase->first; while (tex) { - if (tex->id.us>0 || wd->current) { + if (tex->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_TE, "Tex", 1, tex); write_iddata(wd, &tex->id); - if (tex->adt) write_animdata(wd, tex->adt); + if (tex->adt) { + write_animdata(wd, tex->adt); + } /* direct data */ - if (tex->coba) writestruct(wd, DATA, "ColorBand", 1, tex->coba); - if (tex->type == TEX_ENVMAP && tex->env) writestruct(wd, DATA, "EnvMap", 1, tex->env); + if (tex->coba) { + writestruct(wd, DATA, "ColorBand", 1, tex->coba); + } + if (tex->type == TEX_ENVMAP && tex->env) { + writestruct(wd, DATA, "EnvMap", 1, tex->env); + } if (tex->type == TEX_POINTDENSITY && tex->pd) { writestruct(wd, DATA, "PointDensity", 1, tex->pd); - if (tex->pd->coba) writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba); - if (tex->pd->falloff_curve) write_curvemapping(wd, tex->pd->falloff_curve); + if (tex->pd->coba) { + writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba); + } + if (tex->pd->falloff_curve) { + write_curvemapping(wd, tex->pd->falloff_curve); + } + } + if (tex->type == TEX_VOXELDATA) { + writestruct(wd, DATA, "VoxelData", 1, tex->vd); + } + if (tex->type == TEX_OCEAN && tex->ot) { + writestruct(wd, DATA, "OceanTex", 1, tex->ot); } - if (tex->type == TEX_VOXELDATA) writestruct(wd, DATA, "VoxelData", 1, tex->vd); - if (tex->type == TEX_OCEAN && tex->ot) writestruct(wd, DATA, "OceanTex", 1, tex->ot); - + /* nodetree is integral part of texture, no libdata */ if (tex->nodetree) { writestruct(wd, DATA, "bNodeTree", 1, tex->nodetree); write_nodetree(wd, tex->nodetree); } - + write_previews(wd, tex->preview); } - tex= tex->id.next; + tex = tex->id.next; } /* flush helps the compression for undo-save */ @@ -2262,22 +2410,30 @@ static void write_materials(WriteData *wd, ListBase *idbase) Material *ma; int a; - ma= idbase->first; + ma = idbase->first; while (ma) { - if (ma->id.us>0 || wd->current) { + if (ma->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_MA, "Material", 1, ma); write_iddata(wd, &ma->id); - if (ma->adt) write_animdata(wd, ma->adt); + if (ma->adt) { + write_animdata(wd, ma->adt); + } - for (a=0; amtex[a]) writestruct(wd, DATA, "MTex", 1, ma->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (ma->mtex[a]) { + writestruct(wd, DATA, "MTex", 1, ma->mtex[a]); + } } - - if (ma->ramp_col) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col); - if (ma->ramp_spec) writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec); - + + if (ma->ramp_col) { + writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col); + } + if (ma->ramp_spec) { + writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec); + } + /* nodetree is integral part of material, no libdata */ if (ma->nodetree) { writestruct(wd, DATA, "bNodeTree", 1, ma->nodetree); @@ -2286,7 +2442,7 @@ static void write_materials(WriteData *wd, ListBase *idbase) write_previews(wd, ma->preview); } - ma= ma->id.next; + ma = ma->id.next; } } @@ -2295,17 +2451,21 @@ static void write_worlds(WriteData *wd, ListBase *idbase) World *wrld; int a; - wrld= idbase->first; + wrld = idbase->first; while (wrld) { - if (wrld->id.us>0 || wd->current) { + if (wrld->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_WO, "World", 1, wrld); write_iddata(wd, &wrld->id); - if (wrld->adt) write_animdata(wd, wrld->adt); - - for (a=0; amtex[a]) writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]); + if (wrld->adt) { + write_animdata(wd, wrld->adt); + } + + for (a = 0; a < MAX_MTEX; a++) { + if (wrld->mtex[a]) { + writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]); + } } /* nodetree is integral part of world, no libdata */ @@ -2313,10 +2473,10 @@ static void write_worlds(WriteData *wd, ListBase *idbase) writestruct(wd, DATA, "bNodeTree", 1, wrld->nodetree); write_nodetree(wd, wrld->nodetree); } - + write_previews(wd, wrld->preview); } - wrld= wrld->id.next; + wrld = wrld->id.next; } } @@ -2325,23 +2485,28 @@ static void write_lamps(WriteData *wd, ListBase *idbase) Lamp *la; int a; - la= idbase->first; + la = idbase->first; while (la) { - if (la->id.us>0 || wd->current) { + if (la->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_LA, "Lamp", 1, la); write_iddata(wd, &la->id); - if (la->adt) write_animdata(wd, la->adt); - + if (la->adt) { + write_animdata(wd, la->adt); + } + /* direct data */ - for (a=0; amtex[a]) writestruct(wd, DATA, "MTex", 1, la->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (la->mtex[a]) { + writestruct(wd, DATA, "MTex", 1, la->mtex[a]); + } } - - if (la->curfalloff) + + if (la->curfalloff) { write_curvemapping(wd, la->curfalloff); - + } + /* nodetree is integral part of lamps, no libdata */ if (la->nodetree) { writestruct(wd, DATA, "bNodeTree", 1, la->nodetree); @@ -2349,9 +2514,9 @@ static void write_lamps(WriteData *wd, ListBase *idbase) } write_previews(wd, la->preview); - + } - la= la->id.next; + la = la->id.next; } } @@ -2366,12 +2531,12 @@ static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) writestruct(wd, DATA, smti->struct_name, 1, smd); if (smd->type == seqModifierType_Curves) { - CurvesModifierData *cmd = (CurvesModifierData *) smd; + CurvesModifierData *cmd = (CurvesModifierData *)smd; write_curvemapping(wd, &cmd->curve_mapping); } else if (smd->type == seqModifierType_HueCorrect) { - HueCorrectModifierData *hcmd = (HueCorrectModifierData *) smd; + HueCorrectModifierData *hcmd = (HueCorrectModifierData *)smd; write_curvemapping(wd, &hcmd->curve_mapping); } @@ -2391,8 +2556,9 @@ static void write_view_settings(WriteData *wd, ColorManagedViewSettings *view_se static void write_paint(WriteData *wd, Paint *p) { - if (p->cavity_curve) + if (p->cavity_curve) { write_curvemapping(wd, p->cavity_curve); + } } static void write_scenes(WriteData *wd, ListBase *scebase) @@ -2410,23 +2576,25 @@ static void write_scenes(WriteData *wd, ListBase *scebase) ToolSettings *tos; FreestyleModuleConfig *fmc; FreestyleLineSet *fls; - - sce= scebase->first; + + sce = scebase->first; while (sce) { /* write LibData */ writestruct(wd, ID_SCE, "Scene", 1, sce); write_iddata(wd, &sce->id); - if (sce->adt) write_animdata(wd, sce->adt); + if (sce->adt) { + write_animdata(wd, sce->adt); + } write_keyingsets(wd, &sce->keyingsets); - + /* direct data */ - base= sce->base.first; + base = sce->base.first; while (base) { writestruct(wd, DATA, "Base", 1, base); - base= base->next; + base = base->next; } - + tos = sce->toolsettings; writestruct(wd, DATA, "ToolSettings", 1, tos); if (tos->vpaint) { @@ -2448,53 +2616,55 @@ static void write_scenes(WriteData *wd, ListBase *scebase) write_paint(wd, &tos->imapaint.paint); - ed= sce->ed; + ed = sce->ed; if (ed) { writestruct(wd, DATA, "Editing", 1, ed); - + /* reset write flags too */ - - SEQ_BEGIN (ed, seq) + + SEQ_BEGIN(ed, seq) { - if (seq->strip) seq->strip->done = false; + if (seq->strip) { + seq->strip->done = false; + } writestruct(wd, DATA, "Sequence", 1, seq); } SEQ_END - - SEQ_BEGIN (ed, seq) + + SEQ_BEGIN(ed, seq) { - if (seq->strip && seq->strip->done==0) { + if (seq->strip && seq->strip->done == 0) { /* write strip with 'done' at 0 because readfile */ - + if (seq->effectdata) { switch (seq->type) { - case SEQ_TYPE_COLOR: - writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata); - break; - case SEQ_TYPE_SPEED: - writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata); - break; - case SEQ_TYPE_WIPE: - writestruct(wd, DATA, "WipeVars", 1, seq->effectdata); - break; - case SEQ_TYPE_GLOW: - writestruct(wd, DATA, "GlowVars", 1, seq->effectdata); - break; - case SEQ_TYPE_TRANSFORM: - writestruct(wd, DATA, "TransformVars", 1, seq->effectdata); - break; - case SEQ_TYPE_GAUSSIAN_BLUR: - writestruct(wd, DATA, "GaussianBlurVars", 1, seq->effectdata); - break; - case SEQ_TYPE_TEXT: - writestruct(wd, DATA, "TextVars", 1, seq->effectdata); - break; + case SEQ_TYPE_COLOR: + writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata); + break; + case SEQ_TYPE_SPEED: + writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata); + break; + case SEQ_TYPE_WIPE: + writestruct(wd, DATA, "WipeVars", 1, seq->effectdata); + break; + case SEQ_TYPE_GLOW: + writestruct(wd, DATA, "GlowVars", 1, seq->effectdata); + break; + case SEQ_TYPE_TRANSFORM: + writestruct(wd, DATA, "TransformVars", 1, seq->effectdata); + break; + case SEQ_TYPE_GAUSSIAN_BLUR: + writestruct(wd, DATA, "GaussianBlurVars", 1, seq->effectdata); + break; + case SEQ_TYPE_TEXT: + writestruct(wd, DATA, "TextVars", 1, seq->effectdata); + break; } } writestruct(wd, DATA, "Stereo3dFormat", 1, seq->stereo3d_format); - strip= seq->strip; + strip = seq->strip; writestruct(wd, DATA, "Strip", 1, strip); if (seq->flag & SEQ_USE_CROP && strip->crop) { writestruct(wd, DATA, "StripCrop", 1, strip->crop); @@ -2505,11 +2675,15 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->flag & SEQ_USE_PROXY && strip->proxy) { writestruct(wd, DATA, "StripProxy", 1, strip->proxy); } - if (seq->type==SEQ_TYPE_IMAGE) - writestruct(wd, DATA, "StripElem", MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata); - else if (seq->type==SEQ_TYPE_MOVIE || seq->type==SEQ_TYPE_SOUND_RAM || seq->type == SEQ_TYPE_SOUND_HD) + if (seq->type == SEQ_TYPE_IMAGE) { + writestruct(wd, DATA, "StripElem", + MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), + strip->stripdata); + } + else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { writestruct(wd, DATA, "StripElem", 1, strip->stripdata); - + } + strip->done = true; } @@ -2520,35 +2694,43 @@ static void write_scenes(WriteData *wd, ListBase *scebase) write_sequence_modifiers(wd, &seq->modifiers); } SEQ_END - + /* new; meta stack too, even when its nasty restore code */ - for (ms= ed->metastack.first; ms; ms= ms->next) { + for (ms = ed->metastack.first; ms; ms = ms->next) { writestruct(wd, DATA, "MetaStack", 1, ms); } } - + if (sce->r.avicodecdata) { writestruct(wd, DATA, "AviCodecData", 1, sce->r.avicodecdata); - if (sce->r.avicodecdata->lpFormat) writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat); - if (sce->r.avicodecdata->lpParms) writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms); + if (sce->r.avicodecdata->lpFormat) { + writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat); + } + if (sce->r.avicodecdata->lpParms) { + writedata(wd, DATA, sce->r.avicodecdata->cbParms, sce->r.avicodecdata->lpParms); + } } if (sce->r.qtcodecdata) { writestruct(wd, DATA, "QuicktimeCodecData", 1, sce->r.qtcodecdata); - if (sce->r.qtcodecdata->cdParms) writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms); + if (sce->r.qtcodecdata->cdParms) { + writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms); + } } if (sce->r.ffcodecdata.properties) { IDP_WriteProperty(sce->r.ffcodecdata.properties, wd); } /* writing dynamic list of TimeMarkers to the blend file */ - for (marker= sce->markers.first; marker; marker= marker->next) + for (marker = sce->markers.first; marker; marker = marker->next) { writestruct(wd, DATA, "TimeMarker", 1, marker); - + } + /* writing dynamic list of TransformOrientations to the blend file */ - for (ts = sce->transform_spaces.first; ts; ts = ts->next) + for (ts = sce->transform_spaces.first; ts; ts = ts->next) { writestruct(wd, DATA, "TransformOrientation", 1, ts); - + } + for (srl = sce->r.layers.first; srl; srl = srl->next) { writestruct(wd, DATA, "SceneRenderLayer", 1, srl); for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) { @@ -2560,27 +2742,28 @@ static void write_scenes(WriteData *wd, ListBase *scebase) } /* writing MultiView to the blend file */ - for (srv = sce->r.views.first; srv; srv = srv->next) + for (srv = sce->r.views.first; srv; srv = srv->next) { writestruct(wd, DATA, "SceneRenderView", 1, srv); - + } + if (sce->nodetree) { writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree); write_nodetree(wd, sce->nodetree); } write_view_settings(wd, &sce->view_settings); - + /* writing RigidBodyWorld data to the blend file */ if (sce->rigidbody_world) { writestruct(wd, DATA, "RigidBodyWorld", 1, sce->rigidbody_world); writestruct(wd, DATA, "EffectorWeights", 1, sce->rigidbody_world->effector_weights); write_pointcaches(wd, &(sce->rigidbody_world->ptcaches)); } - + write_previews(wd, sce->preview); write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve); - sce= sce->id.next; + sce = sce->id.next; } /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); @@ -2592,26 +2775,28 @@ static void write_gpencils(WriteData *wd, ListBase *lb) bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps; - - for (gpd= lb->first; gpd; gpd= gpd->id.next) { - if (gpd->id.us>0 || wd->current) { + + for (gpd = lb->first; gpd; gpd = gpd->id.next) { + if (gpd->id.us > 0 || wd->current) { /* write gpd data block to file */ writestruct(wd, ID_GD, "bGPdata", 1, gpd); write_iddata(wd, &gpd->id); - if (gpd->adt) write_animdata(wd, gpd->adt); - + if (gpd->adt) { + write_animdata(wd, gpd->adt); + } + /* write grease-pencil layers to file */ writelist(wd, DATA, "bGPDlayer", &gpd->layers); - for (gpl= gpd->layers.first; gpl; gpl= gpl->next) { - + for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* write this layer's frames to file */ writelist(wd, DATA, "bGPDframe", &gpl->frames); - for (gpf= gpl->frames.first; gpf; gpf= gpf->next) { - + for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { + /* write strokes */ writelist(wd, DATA, "bGPDstroke", &gpf->strokes); - for (gps= gpf->strokes.first; gps; gps= gps->next) { + for (gps = gpf->strokes.first; gps; gps = gps->next) { writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points); } } @@ -2624,12 +2809,12 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) { wmWindowManager *wm; wmWindow *win; - - for (wm= lb->first; wm; wm= wm->id.next) { + + for (wm = lb->first; wm; wm = wm->id.next) { writestruct(wd, ID_WM, "wmWindowManager", 1, wm); write_iddata(wd, &wm->id); - for (win= wm->windows.first; win; win= win->next) { + for (win = wm->windows.first; win; win = win->next) { writestruct(wd, DATA, "wmWindow", 1, win); writestruct(wd, DATA, "Stereo3dFormat", 1, win->stereo3d_format); } @@ -2637,20 +2822,22 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) } static void write_region(WriteData *wd, ARegion *ar, int spacetype) -{ +{ writestruct(wd, DATA, "ARegion", 1, ar); - + if (ar->regiondata) { switch (spacetype) { case SPACE_VIEW3D: - if (ar->regiontype==RGN_TYPE_WINDOW) { - RegionView3D *rv3d= ar->regiondata; + if (ar->regiontype == RGN_TYPE_WINDOW) { + RegionView3D *rv3d = ar->regiondata; writestruct(wd, DATA, "RegionView3D", 1, rv3d); - - if (rv3d->localvd) + + if (rv3d->localvd) { writestruct(wd, DATA, "RegionView3D", 1, rv3d->localvd); - if (rv3d->clipbb) + } + if (rv3d->clipbb) { writestruct(wd, DATA, "BoundBox", 1, rv3d->clipbb); + } } else @@ -2674,7 +2861,7 @@ static void write_uilist(WriteData *wd, uiList *ui_list) static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) { BLI_mempool *ts = so->treestore; - + if (ts) { int elems = BLI_mempool_count(ts); /* linearize mempool to array */ @@ -2686,7 +2873,7 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) ts_flat->usedelem = elems; ts_flat->totelem = elems; ts_flat->data = data; - + /* temporarily replace mempool-treestore by flat-treestore */ so->treestore = (BLI_mempool *)ts_flat; writestruct(wd, DATA, "SpaceOops", 1, so); @@ -2722,208 +2909,225 @@ static void write_screens(WriteData *wd, ListBase *scrbase) ScrEdge *se; LinkNode *tmp_mem_list = NULL; - sc= scrbase->first; + sc = scrbase->first; while (sc) { - + /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ writestruct(wd, ID_SCRN, "Screen", 1, sc); write_iddata(wd, &sc->id); /* direct data */ - for (sv= sc->vertbase.first; sv; sv= sv->next) + for (sv = sc->vertbase.first; sv; sv = sv->next) { writestruct(wd, DATA, "ScrVert", 1, sv); - - for (se= sc->edgebase.first; se; se= se->next) + } + + for (se = sc->edgebase.first; se; se = se->next) { writestruct(wd, DATA, "ScrEdge", 1, se); - - for (sa= sc->areabase.first; sa; sa= sa->next) { + } + + for (sa = sc->areabase.first; sa; sa = sa->next) { SpaceLink *sl; Panel *pa; uiList *ui_list; uiPreview *ui_preview; PanelCategoryStack *pc_act; ARegion *ar; - + writestruct(wd, DATA, "ScrArea", 1, sa); - - for (ar= sa->regionbase.first; ar; ar= ar->next) { + + for (ar = sa->regionbase.first; ar; ar = ar->next) { write_region(wd, ar, sa->spacetype); - - for (pa= ar->panels.first; pa; pa= pa->next) + + for (pa = ar->panels.first; pa; pa = pa->next) { writestruct(wd, DATA, "Panel", 1, pa); - - for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) + } + + for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) { writestruct(wd, DATA, "PanelCategoryStack", 1, pc_act); + } - for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) + for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { write_uilist(wd, ui_list); + } - for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) + for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { writestruct(wd, DATA, "uiPreview", 1, ui_preview); + } } - - sl= sa->spacedata.first; + + sl = sa->spacedata.first; while (sl) { - for (ar= sl->regionbase.first; ar; ar= ar->next) + for (ar = sl->regionbase.first; ar; ar = ar->next) { write_region(wd, ar, sl->spacetype); - - if (sl->spacetype==SPACE_VIEW3D) { - View3D *v3d= (View3D *) sl; + } + + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; BGpic *bgpic; writestruct(wd, DATA, "View3D", 1, v3d); - for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) + for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { writestruct(wd, DATA, "BGpic", 1, bgpic); - if (v3d->localvd) writestruct(wd, DATA, "View3D", 1, v3d->localvd); + } + if (v3d->localvd) { + writestruct(wd, DATA, "View3D", 1, v3d->localvd); + } - if (v3d->fx_settings.ssao) + if (v3d->fx_settings.ssao) { writestruct(wd, DATA, "GPUSSAOSettings", 1, v3d->fx_settings.ssao); - if (v3d->fx_settings.dof) + } + if (v3d->fx_settings.dof) { writestruct(wd, DATA, "GPUDOFSettings", 1, v3d->fx_settings.dof); + } } - else if (sl->spacetype==SPACE_IPO) { - SpaceIpo *sipo= (SpaceIpo *)sl; + else if (sl->spacetype == SPACE_IPO) { + SpaceIpo *sipo = (SpaceIpo *)sl; ListBase tmpGhosts = sipo->ghostCurves; - + /* temporarily disable ghost curves when saving */ - sipo->ghostCurves.first= sipo->ghostCurves.last= NULL; - + sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; + writestruct(wd, DATA, "SpaceIpo", 1, sl); - if (sipo->ads) writestruct(wd, DATA, "bDopeSheet", 1, sipo->ads); - + if (sipo->ads) { + writestruct(wd, DATA, "bDopeSheet", 1, sipo->ads); + } + /* reenable ghost curves */ - sipo->ghostCurves= tmpGhosts; + sipo->ghostCurves = tmpGhosts; } - else if (sl->spacetype==SPACE_BUTS) { + else if (sl->spacetype == SPACE_BUTS) { writestruct(wd, DATA, "SpaceButs", 1, sl); } - else if (sl->spacetype==SPACE_FILE) { - SpaceFile *sfile= (SpaceFile *)sl; + else if (sl->spacetype == SPACE_FILE) { + SpaceFile *sfile = (SpaceFile *)sl; writestruct(wd, DATA, "SpaceFile", 1, sl); - if (sfile->params) + if (sfile->params) { writestruct(wd, DATA, "FileSelectParams", 1, sfile->params); + } } - else if (sl->spacetype==SPACE_SEQ) { + else if (sl->spacetype == SPACE_SEQ) { writestruct(wd, DATA, "SpaceSeq", 1, sl); } - else if (sl->spacetype==SPACE_OUTLINER) { - SpaceOops *so= (SpaceOops *)sl; + else if (sl->spacetype == SPACE_OUTLINER) { + SpaceOops *so = (SpaceOops *)sl; write_soops(wd, so, &tmp_mem_list); } - else if (sl->spacetype==SPACE_IMAGE) { + else if (sl->spacetype == SPACE_IMAGE) { writestruct(wd, DATA, "SpaceImage", 1, sl); } - else if (sl->spacetype==SPACE_TEXT) { + else if (sl->spacetype == SPACE_TEXT) { writestruct(wd, DATA, "SpaceText", 1, sl); } - else if (sl->spacetype==SPACE_SCRIPT) { - SpaceScript *scr = (SpaceScript*)sl; + else if (sl->spacetype == SPACE_SCRIPT) { + SpaceScript *scr = (SpaceScript *)sl; scr->but_refs = NULL; writestruct(wd, DATA, "SpaceScript", 1, sl); } - else if (sl->spacetype==SPACE_ACTION) { + else if (sl->spacetype == SPACE_ACTION) { writestruct(wd, DATA, "SpaceAction", 1, sl); } - else if (sl->spacetype==SPACE_NLA) { - SpaceNla *snla= (SpaceNla *)sl; - + else if (sl->spacetype == SPACE_NLA) { + SpaceNla *snla = (SpaceNla *)sl; + writestruct(wd, DATA, "SpaceNla", 1, snla); - if (snla->ads) writestruct(wd, DATA, "bDopeSheet", 1, snla->ads); + if (snla->ads) { + writestruct(wd, DATA, "bDopeSheet", 1, snla->ads); + } } - else if (sl->spacetype==SPACE_TIME) { + else if (sl->spacetype == SPACE_TIME) { writestruct(wd, DATA, "SpaceTime", 1, sl); } - else if (sl->spacetype==SPACE_NODE) { + else if (sl->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)sl; bNodeTreePath *path; writestruct(wd, DATA, "SpaceNode", 1, snode); - - for (path=snode->treepath.first; path; path=path->next) + + for (path = snode->treepath.first; path; path = path->next) { writestruct(wd, DATA, "bNodeTreePath", 1, path); + } } - else if (sl->spacetype==SPACE_LOGIC) { + else if (sl->spacetype == SPACE_LOGIC) { writestruct(wd, DATA, "SpaceLogic", 1, sl); } - else if (sl->spacetype==SPACE_CONSOLE) { - SpaceConsole *con = (SpaceConsole*)sl; + else if (sl->spacetype == SPACE_CONSOLE) { + SpaceConsole *con = (SpaceConsole *)sl; ConsoleLine *cl; - for (cl=con->history.first; cl; cl=cl->next) { + for (cl = con->history.first; cl; cl = cl->next) { /* 'len_alloc' is invalid on write, set from 'len' on read */ writestruct(wd, DATA, "ConsoleLine", 1, cl); - writedata(wd, DATA, cl->len+1, cl->line); + writedata(wd, DATA, cl->len + 1, cl->line); } writestruct(wd, DATA, "SpaceConsole", 1, sl); } - else if (sl->spacetype==SPACE_USERPREF) { + else if (sl->spacetype == SPACE_USERPREF) { writestruct(wd, DATA, "SpaceUserPref", 1, sl); } - else if (sl->spacetype==SPACE_CLIP) { + else if (sl->spacetype == SPACE_CLIP) { writestruct(wd, DATA, "SpaceClip", 1, sl); } else if (sl->spacetype == SPACE_INFO) { writestruct(wd, DATA, "SpaceInfo", 1, sl); } - sl= sl->next; + sl = sl->next; } } - sc= sc->id.next; + sc = sc->id.next; } BLI_linklist_freeN(tmp_mem_list); - + /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); } static void write_bone(WriteData *wd, Bone *bone) { - Bone* cbone; - - // PATCH for upward compatibility after 2.37+ armature recode + /* PATCH for upward compatibility after 2.37+ armature recode */ bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; - - // Write this bone + + /* Write this bone */ writestruct(wd, DATA, "Bone", 1, bone); /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ - if (bone->prop) + if (bone->prop) { IDP_WriteProperty(bone->prop, wd); - - // Write Children - cbone= bone->childbase.first; - while (cbone) { + } + + /* Write Children */ + for (Bone *cbone = bone->childbase.first; cbone; cbone = cbone->next) { write_bone(wd, cbone); - cbone= cbone->next; } } static void write_armatures(WriteData *wd, ListBase *idbase) { - bArmature *arm; - Bone *bone; + bArmature *arm; + Bone *bone; - arm=idbase->first; + arm = idbase->first; while (arm) { - if (arm->id.us>0 || wd->current) { + if (arm->id.us > 0 || wd->current) { writestruct(wd, ID_AR, "bArmature", 1, arm); write_iddata(wd, &arm->id); - if (arm->adt) write_animdata(wd, arm->adt); + if (arm->adt) { + write_animdata(wd, arm->adt); + } /* Direct data */ - bone= arm->bonebase.first; + bone = arm->bonebase.first; while (bone) { write_bone(wd, bone); - bone=bone->next; + bone = bone->next; } } - arm=arm->id.next; + arm = arm->id.next; } /* flush helps the compression for undo-save */ @@ -2935,33 +3139,37 @@ static void write_texts(WriteData *wd, ListBase *idbase) Text *text; TextLine *tmp; - text= idbase->first; + text = idbase->first; while (text) { - if ( (text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) text->flags &= ~TXT_ISEXT; + if ( (text->flags & TXT_ISMEM) && (text->flags & TXT_ISEXT)) { + text->flags &= ~TXT_ISEXT; + } /* write LibData */ writestruct(wd, ID_TXT, "Text", 1, text); write_iddata(wd, &text->id); - if (text->name) writedata(wd, DATA, strlen(text->name)+1, text->name); + if (text->name) { + writedata(wd, DATA, strlen(text->name) + 1, text->name); + } if (!(text->flags & TXT_ISEXT)) { /* now write the text data, in two steps for optimization in the readfunction */ - tmp= text->lines.first; + tmp = text->lines.first; while (tmp) { writestruct(wd, DATA, "TextLine", 1, tmp); - tmp= tmp->next; + tmp = tmp->next; } - tmp= text->lines.first; + tmp = text->lines.first; while (tmp) { - writedata(wd, DATA, tmp->len+1, tmp->line); - tmp= tmp->next; + writedata(wd, DATA, tmp->len + 1, tmp->line); + tmp = tmp->next; } } - text= text->id.next; + text = text->id.next; } /* flush helps the compression for undo-save */ @@ -2972,16 +3180,18 @@ static void write_speakers(WriteData *wd, ListBase *idbase) { Speaker *spk; - spk= idbase->first; + spk = idbase->first; while (spk) { - if (spk->id.us>0 || wd->current) { + if (spk->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_SPK, "Speaker", 1, spk); write_iddata(wd, &spk->id); - if (spk->adt) write_animdata(wd, spk->adt); + if (spk->adt) { + write_animdata(wd, spk->adt); + } } - spk= spk->id.next; + spk = spk->id.next; } } @@ -2989,11 +3199,11 @@ static void write_sounds(WriteData *wd, ListBase *idbase) { bSound *sound; - PackedFile * pf; + PackedFile *pf; - sound= idbase->first; + sound = idbase->first; while (sound) { - if (sound->id.us>0 || wd->current) { + if (sound->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_SO, "bSound", 1, sound); write_iddata(wd, &sound->id); @@ -3004,7 +3214,7 @@ static void write_sounds(WriteData *wd, ListBase *idbase) writedata(wd, DATA, pf->size, pf->data); } } - sound= sound->id.next; + sound = sound->id.next; } /* flush helps the compression for undo-save */ @@ -3016,18 +3226,18 @@ static void write_groups(WriteData *wd, ListBase *idbase) Group *group; GroupObject *go; - for (group= idbase->first; group; group= group->id.next) { - if (group->id.us>0 || wd->current) { + for (group = idbase->first; group; group = group->id.next) { + if (group->id.us > 0 || wd->current) { /* write LibData */ writestruct(wd, ID_GR, "Group", 1, group); write_iddata(wd, &group->id); write_previews(wd, group->preview); - go= group->gobject.first; + go = group->gobject.first; while (go) { writestruct(wd, DATA, "GroupObject", 1, go); - go= go->next; + go = go->next; } } } @@ -3036,9 +3246,9 @@ static void write_groups(WriteData *wd, ListBase *idbase) static void write_nodetrees(WriteData *wd, ListBase *idbase) { bNodeTree *ntree; - - for (ntree=idbase->first; ntree; ntree= ntree->id.next) { - if (ntree->id.us>0 || wd->current) { + + for (ntree = idbase->first; ntree; ntree = ntree->id.next) { + if (ntree->id.us > 0 || wd->current) { writestruct(wd, ID_NT, "bNodeTree", 1, ntree); /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ @@ -3054,11 +3264,12 @@ static void customnodes_add_deprecated_data(Main *mainvar) { FOREACH_NODETREE(mainvar, ntree, id) { bNodeLink *link, *last_link = ntree->links.last; - + /* only do this for node groups */ - if (id != &ntree->id) + if (id != &ntree->id) { continue; - + } + /* Forward compatibility for group nodes: add links to node tree interface sockets. * These links are invalid by new rules (missing node pointer)! * They will be removed again in customnodes_free_deprecated_data, @@ -3069,7 +3280,7 @@ static void customnodes_add_deprecated_data(Main *mainvar) for (link = ntree->links.first; link; link = link->next) { bNode *fromnode = link->fromnode, *tonode = link->tonode; bNodeSocket *fromsock = link->fromsock, *tosock = link->tosock; - + /* check both sides of the link, to handle direct input-to-output links */ if (fromnode->type == NODE_GROUP_INPUT) { fromnode = NULL; @@ -3080,22 +3291,23 @@ static void customnodes_add_deprecated_data(Main *mainvar) tonode = NULL; tosock = ntreeFindSocketInterface(ntree, SOCK_OUT, tosock->identifier); } - + if (!fromnode || !tonode) { /* Note: not using nodeAddLink here, it asserts existing node pointers */ bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "group node link"); tlink->fromnode = fromnode; tlink->fromsock = fromsock; tlink->tonode = tonode; - tlink->tosock= tosock; + tlink->tosock = tosock; tosock->link = tlink; tlink->flag |= NODE_LINK_VALID; BLI_addtail(&ntree->links, tlink); } - + /* don't check newly created compatibility links */ - if (link == last_link) + if (link == last_link) { break; + } } } FOREACH_NODETREE_END @@ -3105,11 +3317,12 @@ static void customnodes_free_deprecated_data(Main *mainvar) { FOREACH_NODETREE(mainvar, ntree, id) { bNodeLink *link, *next_link; - + for (link = ntree->links.first; link; link = next_link) { next_link = link->next; - if (link->fromnode == NULL || link->tonode == NULL) + if (link->fromnode == NULL || link->tonode == NULL) { nodeRemLink(ntree, link); + } } } FOREACH_NODETREE_END @@ -3119,16 +3332,18 @@ static void customnodes_free_deprecated_data(Main *mainvar) static void write_brushes(WriteData *wd, ListBase *idbase) { Brush *brush; - - for (brush=idbase->first; brush; brush= brush->id.next) { - if (brush->id.us>0 || wd->current) { + + for (brush = idbase->first; brush; brush = brush->id.next) { + if (brush->id.us > 0 || wd->current) { writestruct(wd, ID_BR, "Brush", 1, brush); write_iddata(wd, &brush->id); - if (brush->curve) + if (brush->curve) { write_curvemapping(wd, brush->curve); - if (brush->gradient) + } + if (brush->gradient) { writestruct(wd, DATA, "ColorBand", 1, brush->gradient); + } } } } @@ -3143,8 +3358,9 @@ static void write_palettes(WriteData *wd, ListBase *idbase) writestruct(wd, ID_PAL, "Palette", 1, palette); write_iddata(wd, &palette->id); - for (color = palette->colors.first; color; color= color->next) + for (color = palette->colors.first; color; color = color->next) { writestruct(wd, DATA, "PaletteColor", 1, color); + } } } } @@ -3167,14 +3383,15 @@ static void write_movieTracks(WriteData *wd, ListBase *tracks) { MovieTrackingTrack *track; - track= tracks->first; + track = tracks->first; while (track) { writestruct(wd, DATA, "MovieTrackingTrack", 1, track); - if (track->markers) + if (track->markers) { writestruct(wd, DATA, "MovieTrackingMarker", track->markersnr, track->markers); + } - track= track->next; + track = track->next; } } @@ -3195,31 +3412,33 @@ static void write_moviePlaneTracks(WriteData *wd, ListBase *plane_tracks_base) static void write_movieReconstruction(WriteData *wd, MovieTrackingReconstruction *reconstruction) { - if (reconstruction->camnr) + if (reconstruction->camnr) { writestruct(wd, DATA, "MovieReconstructedCamera", reconstruction->camnr, reconstruction->cameras); + } } static void write_movieclips(WriteData *wd, ListBase *idbase) { MovieClip *clip; - clip= idbase->first; + clip = idbase->first; while (clip) { - if (clip->id.us>0 || wd->current) { - MovieTracking *tracking= &clip->tracking; + if (clip->id.us > 0 || wd->current) { + MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object; writestruct(wd, ID_MC, "MovieClip", 1, clip); write_iddata(wd, &clip->id); - if (clip->adt) + if (clip->adt) { write_animdata(wd, clip->adt); + } write_movieTracks(wd, &tracking->tracks); write_moviePlaneTracks(wd, &tracking->plane_tracks); write_movieReconstruction(wd, &tracking->reconstruction); - object= tracking->objects.first; + object = tracking->objects.first; while (object) { writestruct(wd, DATA, "MovieTrackingObject", 1, object); @@ -3227,11 +3446,11 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) write_moviePlaneTracks(wd, &object->plane_tracks); write_movieReconstruction(wd, &object->reconstruction); - object= object->next; + object = object->next; } } - clip= clip->id.next; + clip = clip->id.next; } /* flush helps the compression for undo-save */ @@ -3250,8 +3469,9 @@ static void write_masks(WriteData *wd, ListBase *idbase) writestruct(wd, ID_MSK, "Mask", 1, mask); write_iddata(wd, &mask->id); - if (mask->adt) + if (mask->adt) { write_animdata(wd, mask->adt); + } for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { MaskSpline *spline; @@ -3273,14 +3493,20 @@ static void write_masks(WriteData *wd, ListBase *idbase) for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; - if (point->tot_uw) + if (point->tot_uw) { writestruct(wd, DATA, "MaskSplinePointUW", point->tot_uw, point->uw); + } } } - for (masklay_shape = masklay->splines_shapes.first; masklay_shape; masklay_shape = masklay_shape->next) { + for (masklay_shape = masklay->splines_shapes.first; + masklay_shape; + masklay_shape = masklay_shape->next) + { writestruct(wd, DATA, "MaskLayerShape", 1, masklay_shape); - writedata(wd, DATA, masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data); + writedata(wd, DATA, + masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, + masklay_shape->data); } } } @@ -3299,61 +3525,61 @@ static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleColorModifier_AlongStroke"; - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleColorModifier_DistanceFromCamera"; - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleColorModifier_DistanceFromObject"; - break; - case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleColorModifier_Material"; - break; - case LS_MODIFIER_TANGENT: - struct_name = "LineStyleColorModifier_Tangent"; - break; - case LS_MODIFIER_NOISE: - struct_name = "LineStyleColorModifier_Noise"; - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleColorModifier_CreaseAngle"; - break; - case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleColorModifier_Curvature_3D"; - break; - default: - struct_name = "LineStyleColorModifier"; /* this should not happen */ + case LS_MODIFIER_ALONG_STROKE: + struct_name = "LineStyleColorModifier_AlongStroke"; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_name = "LineStyleColorModifier_DistanceFromCamera"; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_name = "LineStyleColorModifier_DistanceFromObject"; + break; + case LS_MODIFIER_MATERIAL: + struct_name = "LineStyleColorModifier_Material"; + break; + case LS_MODIFIER_TANGENT: + struct_name = "LineStyleColorModifier_Tangent"; + break; + case LS_MODIFIER_NOISE: + struct_name = "LineStyleColorModifier_Noise"; + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_name = "LineStyleColorModifier_CreaseAngle"; + break; + case LS_MODIFIER_CURVATURE_3D: + struct_name = "LineStyleColorModifier_Curvature_3D"; + break; + default: + struct_name = "LineStyleColorModifier"; /* this should not happen */ } writestruct(wd, DATA, struct_name, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); - break; - case LS_MODIFIER_MATERIAL: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp); - break; - case LS_MODIFIER_TANGENT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); - break; - case LS_MODIFIER_NOISE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); - break; - case LS_MODIFIER_CREASE_ANGLE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); - break; - case LS_MODIFIER_CURVATURE_3D: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); - break; + case LS_MODIFIER_ALONG_STROKE: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + break; + case LS_MODIFIER_MATERIAL: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp); + break; + case LS_MODIFIER_TANGENT: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); + break; + case LS_MODIFIER_NOISE: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); + break; + case LS_MODIFIER_CREASE_ANGLE: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); + break; + case LS_MODIFIER_CURVATURE_3D: + writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); + break; } } } @@ -3365,61 +3591,61 @@ static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleAlphaModifier_AlongStroke"; - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleAlphaModifier_DistanceFromCamera"; - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleAlphaModifier_DistanceFromObject"; - break; - case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleAlphaModifier_Material"; - break; - case LS_MODIFIER_TANGENT: - struct_name = "LineStyleAlphaModifier_Tangent"; - break; - case LS_MODIFIER_NOISE: - struct_name = "LineStyleAlphaModifier_Noise"; - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleAlphaModifier_CreaseAngle"; - break; - case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleAlphaModifier_Curvature_3D"; - break; - default: - struct_name = "LineStyleAlphaModifier"; /* this should not happen */ + case LS_MODIFIER_ALONG_STROKE: + struct_name = "LineStyleAlphaModifier_AlongStroke"; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_name = "LineStyleAlphaModifier_DistanceFromCamera"; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_name = "LineStyleAlphaModifier_DistanceFromObject"; + break; + case LS_MODIFIER_MATERIAL: + struct_name = "LineStyleAlphaModifier_Material"; + break; + case LS_MODIFIER_TANGENT: + struct_name = "LineStyleAlphaModifier_Tangent"; + break; + case LS_MODIFIER_NOISE: + struct_name = "LineStyleAlphaModifier_Noise"; + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_name = "LineStyleAlphaModifier_CreaseAngle"; + break; + case LS_MODIFIER_CURVATURE_3D: + struct_name = "LineStyleAlphaModifier_Curvature_3D"; + break; + default: + struct_name = "LineStyleAlphaModifier"; /* this should not happen */ } writestruct(wd, DATA, struct_name, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - write_curvemapping(wd, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - write_curvemapping(wd, ((LineStyleAlphaModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - write_curvemapping(wd, ((LineStyleAlphaModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_NOISE: - write_curvemapping(wd, ((LineStyleAlphaModifier_Noise *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - write_curvemapping(wd, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - write_curvemapping(wd, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); - break; + case LS_MODIFIER_ALONG_STROKE: + write_curvemapping(wd, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + write_curvemapping(wd, ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + write_curvemapping(wd, ((LineStyleAlphaModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + write_curvemapping(wd, ((LineStyleAlphaModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_NOISE: + write_curvemapping(wd, ((LineStyleAlphaModifier_Noise *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + write_curvemapping(wd, ((LineStyleAlphaModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + write_curvemapping(wd, ((LineStyleAlphaModifier_Curvature_3D *)m)->curve); + break; } } } @@ -3431,61 +3657,61 @@ static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifie for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleThicknessModifier_AlongStroke"; - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleThicknessModifier_DistanceFromCamera"; - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleThicknessModifier_DistanceFromObject"; - break; - case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleThicknessModifier_Material"; - break; - case LS_MODIFIER_CALLIGRAPHY: - struct_name = "LineStyleThicknessModifier_Calligraphy"; - break; - case LS_MODIFIER_TANGENT: - struct_name = "LineStyleThicknessModifier_Tangent"; - break; - case LS_MODIFIER_NOISE: - struct_name = "LineStyleThicknessModifier_Noise"; - break; - case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleThicknessModifier_CreaseAngle"; - break; - case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleThicknessModifier_Curvature_3D"; - break; - default: - struct_name = "LineStyleThicknessModifier"; /* this should not happen */ + case LS_MODIFIER_ALONG_STROKE: + struct_name = "LineStyleThicknessModifier_AlongStroke"; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + struct_name = "LineStyleThicknessModifier_DistanceFromCamera"; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + struct_name = "LineStyleThicknessModifier_DistanceFromObject"; + break; + case LS_MODIFIER_MATERIAL: + struct_name = "LineStyleThicknessModifier_Material"; + break; + case LS_MODIFIER_CALLIGRAPHY: + struct_name = "LineStyleThicknessModifier_Calligraphy"; + break; + case LS_MODIFIER_TANGENT: + struct_name = "LineStyleThicknessModifier_Tangent"; + break; + case LS_MODIFIER_NOISE: + struct_name = "LineStyleThicknessModifier_Noise"; + break; + case LS_MODIFIER_CREASE_ANGLE: + struct_name = "LineStyleThicknessModifier_CreaseAngle"; + break; + case LS_MODIFIER_CURVATURE_3D: + struct_name = "LineStyleThicknessModifier_Curvature_3D"; + break; + default: + struct_name = "LineStyleThicknessModifier"; /* this should not happen */ } writestruct(wd, DATA, struct_name, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_ALONG_STROKE: - write_curvemapping(wd, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_CAMERA: - write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); - break; - case LS_MODIFIER_DISTANCE_FROM_OBJECT: - write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); - break; - case LS_MODIFIER_MATERIAL: - write_curvemapping(wd, ((LineStyleThicknessModifier_Material *)m)->curve); - break; - case LS_MODIFIER_TANGENT: - write_curvemapping(wd, ((LineStyleThicknessModifier_Tangent *)m)->curve); - break; - case LS_MODIFIER_CREASE_ANGLE: - write_curvemapping(wd, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); - break; - case LS_MODIFIER_CURVATURE_3D: - write_curvemapping(wd, ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); - break; + case LS_MODIFIER_ALONG_STROKE: + write_curvemapping(wd, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + write_curvemapping(wd, ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + write_curvemapping(wd, ((LineStyleThicknessModifier_Material *)m)->curve); + break; + case LS_MODIFIER_TANGENT: + write_curvemapping(wd, ((LineStyleThicknessModifier_Tangent *)m)->curve); + break; + case LS_MODIFIER_CREASE_ANGLE: + write_curvemapping(wd, ((LineStyleThicknessModifier_CreaseAngle *)m)->curve); + break; + case LS_MODIFIER_CURVATURE_3D: + write_curvemapping(wd, ((LineStyleThicknessModifier_Curvature_3D *)m)->curve); + break; } } } @@ -3497,50 +3723,50 @@ static void write_linestyle_geometry_modifiers(WriteData *wd, ListBase *modifier for (m = modifiers->first; m; m = m->next) { switch (m->type) { - case LS_MODIFIER_SAMPLING: - struct_name = "LineStyleGeometryModifier_Sampling"; - break; - case LS_MODIFIER_BEZIER_CURVE: - struct_name = "LineStyleGeometryModifier_BezierCurve"; - break; - case LS_MODIFIER_SINUS_DISPLACEMENT: - struct_name = "LineStyleGeometryModifier_SinusDisplacement"; - break; - case LS_MODIFIER_SPATIAL_NOISE: - struct_name = "LineStyleGeometryModifier_SpatialNoise"; - break; - case LS_MODIFIER_PERLIN_NOISE_1D: - struct_name = "LineStyleGeometryModifier_PerlinNoise1D"; - break; - case LS_MODIFIER_PERLIN_NOISE_2D: - struct_name = "LineStyleGeometryModifier_PerlinNoise2D"; - break; - case LS_MODIFIER_BACKBONE_STRETCHER: - struct_name = "LineStyleGeometryModifier_BackboneStretcher"; - break; - case LS_MODIFIER_TIP_REMOVER: - struct_name = "LineStyleGeometryModifier_TipRemover"; - break; - case LS_MODIFIER_POLYGONIZATION: - struct_name = "LineStyleGeometryModifier_Polygonalization"; - break; - case LS_MODIFIER_GUIDING_LINES: - struct_name = "LineStyleGeometryModifier_GuidingLines"; - break; - case LS_MODIFIER_BLUEPRINT: - struct_name = "LineStyleGeometryModifier_Blueprint"; - break; - case LS_MODIFIER_2D_OFFSET: - struct_name = "LineStyleGeometryModifier_2DOffset"; - break; - case LS_MODIFIER_2D_TRANSFORM: - struct_name = "LineStyleGeometryModifier_2DTransform"; - break; - case LS_MODIFIER_SIMPLIFICATION: - struct_name = "LineStyleGeometryModifier_Simplification"; - break; - default: - struct_name = "LineStyleGeometryModifier"; /* this should not happen */ + case LS_MODIFIER_SAMPLING: + struct_name = "LineStyleGeometryModifier_Sampling"; + break; + case LS_MODIFIER_BEZIER_CURVE: + struct_name = "LineStyleGeometryModifier_BezierCurve"; + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + struct_name = "LineStyleGeometryModifier_SinusDisplacement"; + break; + case LS_MODIFIER_SPATIAL_NOISE: + struct_name = "LineStyleGeometryModifier_SpatialNoise"; + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + struct_name = "LineStyleGeometryModifier_PerlinNoise1D"; + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + struct_name = "LineStyleGeometryModifier_PerlinNoise2D"; + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + struct_name = "LineStyleGeometryModifier_BackboneStretcher"; + break; + case LS_MODIFIER_TIP_REMOVER: + struct_name = "LineStyleGeometryModifier_TipRemover"; + break; + case LS_MODIFIER_POLYGONIZATION: + struct_name = "LineStyleGeometryModifier_Polygonalization"; + break; + case LS_MODIFIER_GUIDING_LINES: + struct_name = "LineStyleGeometryModifier_GuidingLines"; + break; + case LS_MODIFIER_BLUEPRINT: + struct_name = "LineStyleGeometryModifier_Blueprint"; + break; + case LS_MODIFIER_2D_OFFSET: + struct_name = "LineStyleGeometryModifier_2DOffset"; + break; + case LS_MODIFIER_2D_TRANSFORM: + struct_name = "LineStyleGeometryModifier_2DTransform"; + break; + case LS_MODIFIER_SIMPLIFICATION: + struct_name = "LineStyleGeometryModifier_Simplification"; + break; + default: + struct_name = "LineStyleGeometryModifier"; /* this should not happen */ } writestruct(wd, DATA, struct_name, 1, m); } @@ -3552,18 +3778,22 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) int a; for (linestyle = idbase->first; linestyle; linestyle = linestyle->id.next) { - if (linestyle->id.us>0 || wd->current) { + if (linestyle->id.us > 0 || wd->current) { writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle); write_iddata(wd, &linestyle->id); - if (linestyle->adt) + if (linestyle->adt) { write_animdata(wd, linestyle->adt); + } + write_linestyle_color_modifiers(wd, &linestyle->color_modifiers); write_linestyle_alpha_modifiers(wd, &linestyle->alpha_modifiers); write_linestyle_thickness_modifiers(wd, &linestyle->thickness_modifiers); write_linestyle_geometry_modifiers(wd, &linestyle->geometry_modifiers); - for (a=0; amtex[a]) writestruct(wd, DATA, "MTex", 1, linestyle->mtex[a]); + for (a = 0; a < MAX_MTEX; a++) { + if (linestyle->mtex[a]) { + writestruct(wd, DATA, "MTex", 1, linestyle->mtex[a]); + } } if (linestyle->nodetree) { writestruct(wd, DATA, "bNodeTree", 1, linestyle->nodetree); @@ -3581,23 +3811,26 @@ static void write_libraries(WriteData *wd, Main *main) int a, tot; bool found_one; - for (; main; main= main->next) { + for (; main; main = main->next) { - a=tot= set_listbasepointers(main, lbarray); + a = tot = set_listbasepointers(main, lbarray); /* test: is lib being used */ - if (main->curlib && main->curlib->packedfile) + if (main->curlib && main->curlib->packedfile) { found_one = true; + } else { found_one = false; while (tot--) { - for (id= lbarray[tot]->first; id; id= id->next) { + for (id = lbarray[tot]->first; id; id = id->next) { if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { found_one = true; break; } } - if (found_one) break; + if (found_one) { + break; + } } } @@ -3612,12 +3845,13 @@ static void write_libraries(WriteData *wd, Main *main) PackedFile *pf = main->curlib->packedfile; writestruct(wd, DATA, "PackedFile", 1, pf); writedata(wd, DATA, pf->size, pf->data); - if (wd->current == NULL) + if (wd->current == NULL) { printf("write packed .blend: %s\n", main->curlib->name); + } } while (a--) { - for (id= lbarray[a]->first; id; id= id->next) { + for (id = lbarray[a]->first; id; id = id->next) { if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { if (!BKE_idcode_is_linkable(GS(id->name))) { printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable " @@ -3641,7 +3875,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) FileGlobal fg; bScreen *screen; char subvstr[8]; - + /* prevent mem checkers from complaining */ memset(fg.pad, 0, sizeof(fg.pad)); memset(fg.filename, 0, sizeof(fg.filename)); @@ -3650,20 +3884,20 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) current_screen_compat(mainvar, &screen, is_undo); /* XXX still remap G */ - fg.curscreen= screen; - fg.curscene= screen ? screen->scene : NULL; + fg.curscreen = screen; + fg.curscene = screen ? screen->scene : NULL; /* prevent to save this, is not good convention, and feature with concerns... */ - fg.fileflags= (fileflags & ~G_FILE_FLAGS_RUNTIME); + fg.fileflags = (fileflags & ~G_FILE_FLAGS_RUNTIME); - fg.globalf= G.f; + fg.globalf = G.f; BLI_strncpy(fg.filename, mainvar->name, sizeof(fg.filename)); sprintf(subvstr, "%4d", BLENDER_SUBVERSION); memcpy(fg.subvstr, subvstr, 4); - - fg.subversion= BLENDER_SUBVERSION; - fg.minversion= BLENDER_MINVERSION; - fg.minsubversion= BLENDER_MINSUBVERSION; + + fg.subversion = BLENDER_SUBVERSION; + fg.minversion = BLENDER_MINVERSION; + fg.minsubversion = BLENDER_MINSUBVERSION; #ifdef WITH_BUILDINFO { extern unsigned long build_commit_timestamp; @@ -3730,42 +3964,42 @@ static int write_file_handle( write_global(wd, write_flags, mainvar); write_windowmanagers(wd, &mainvar->wm); - write_screens (wd, &mainvar->screen); - write_movieclips (wd, &mainvar->movieclip); - write_masks (wd, &mainvar->mask); - write_scenes (wd, &mainvar->scene); - write_curves (wd, &mainvar->curve); - write_mballs (wd, &mainvar->mball); - write_images (wd, &mainvar->image); - write_cameras (wd, &mainvar->camera); - write_lamps (wd, &mainvar->lamp); - write_lattices (wd, &mainvar->latt); - write_vfonts (wd, &mainvar->vfont); - write_keys (wd, &mainvar->key); - write_worlds (wd, &mainvar->world); - write_texts (wd, &mainvar->text); - write_speakers (wd, &mainvar->speaker); - write_sounds (wd, &mainvar->sound); - write_groups (wd, &mainvar->group); + write_screens(wd, &mainvar->screen); + write_movieclips(wd, &mainvar->movieclip); + write_masks(wd, &mainvar->mask); + write_scenes(wd, &mainvar->scene); + write_curves(wd, &mainvar->curve); + write_mballs(wd, &mainvar->mball); + write_images(wd, &mainvar->image); + write_cameras(wd, &mainvar->camera); + write_lamps(wd, &mainvar->lamp); + write_lattices(wd, &mainvar->latt); + write_vfonts(wd, &mainvar->vfont); + write_keys(wd, &mainvar->key); + write_worlds(wd, &mainvar->world); + write_texts(wd, &mainvar->text); + write_speakers(wd, &mainvar->speaker); + write_sounds(wd, &mainvar->sound); + write_groups(wd, &mainvar->group); write_armatures(wd, &mainvar->armature); - write_actions (wd, &mainvar->action); - write_objects (wd, &mainvar->object); + write_actions(wd, &mainvar->action); + write_objects(wd, &mainvar->object); write_materials(wd, &mainvar->mat); - write_textures (wd, &mainvar->tex); - write_meshes (wd, &mainvar->mesh); + write_textures(wd, &mainvar->tex); + write_meshes(wd, &mainvar->mesh); write_particlesettings(wd, &mainvar->particle); write_nodetrees(wd, &mainvar->nodetree); - write_brushes (wd, &mainvar->brush); - write_palettes (wd, &mainvar->palettes); - write_paintcurves (wd, &mainvar->paintcurves); - write_gpencils (wd, &mainvar->gpencil); + write_brushes(wd, &mainvar->brush); + write_palettes(wd, &mainvar->palettes); + write_paintcurves(wd, &mainvar->paintcurves); + write_gpencils(wd, &mainvar->gpencil); write_linestyles(wd, &mainvar->linestyle); write_libraries(wd, mainvar->next); if (write_user_block) { write_userdef(wd); } - + /* dna as last, because (to be implemented) test for which structs are written */ writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data); @@ -3782,7 +4016,7 @@ static int write_file_handle( /* end of file */ memset(&bhead, 0, sizeof(BHead)); - bhead.code= ENDB; + bhead.code = ENDB; mywrite(wd, &bhead, sizeof(BHead)); blo_join_main(&mainlist); @@ -3795,16 +4029,19 @@ static int write_file_handle( static bool do_history(const char *name, ReportList *reports) { char tempname1[FILE_MAX], tempname2[FILE_MAX]; - int hisnr= U.versions; - - if (U.versions==0) return 0; - if (strlen(name)<2) { + int hisnr = U.versions; + + if (U.versions == 0) { + return 0; + } + + if (strlen(name) < 2) { BKE_report(reports, RPT_ERROR, "Unable to make version backup: filename too short"); return 1; } while (hisnr > 1) { - BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr-1); + BLI_snprintf(tempname1, sizeof(tempname1), "%s%d", name, hisnr - 1); if (BLI_exists(tempname1)) { BLI_snprintf(tempname2, sizeof(tempname2), "%s%d", name, hisnr); @@ -3836,7 +4073,7 @@ bool BLO_write_file( Main *mainvar, const char *filepath, int write_flags, ReportList *reports, const BlendThumbnail *thumb) { - char tempname[FILE_MAX+1]; + char tempname[FILE_MAX + 1]; int err, write_user_block; eWriteWrapType ww_type; WriteWrap ww; @@ -3892,10 +4129,12 @@ bool BLO_write_file( } } - write_user_block= write_flags & G_FILE_USERPREFS; + write_user_block = write_flags & G_FILE_USERPREFS; - if (write_flags & G_FILE_RELATIVE_REMAP) - BKE_bpath_relative_convert(mainvar, filepath, NULL); /* note, making relative to something OTHER then G.main->name */ + if (write_flags & G_FILE_RELATIVE_REMAP) { + /* note, making relative to something OTHER then G.main->name */ + BKE_bpath_relative_convert(mainvar, filepath, NULL); + } /* actual file writing */ err = write_file_handle(mainvar, &ww, NULL, NULL, write_user_block, write_flags, thumb); -- cgit v1.2.3 From 55546b4e135283f2ec4b5715536e59722c55f11c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Jun 2016 20:05:42 +1000 Subject: writefile: replace most struct lookups /w constants Removes many hash lookups per file-save and undo-step. --- source/blender/blenloader/CMakeLists.txt | 7 + source/blender/blenloader/intern/writefile.c | 838 ++++++++++++++------------- 2 files changed, 453 insertions(+), 392 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 8364df38208..479d3a15e6c 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -35,6 +35,10 @@ set(INC ../nodes ../render/extern/include ../../../intern/guardedalloc + + # for writefile.c: dna_type_offsets.h + ${CMAKE_BINARY_DIR}/source/blender/makesdna/intern + ) set(INC_SYS @@ -74,3 +78,6 @@ if(WITH_CODEC_FFMPEG) endif() blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}") + +# needed so writefile.c can use dna_type_offsets.h +add_dependencies(bf_blenloader bf_dna) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 5a7b2a7880c..9cf32e1fb73 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -184,6 +184,9 @@ #include "readfile.h" +/* for SDNA_TYPE_FROM_STRUCT() macro */ +#include "dna_type_offsets.h" + #include /* ********* my write, buffered writing with minimum size chunks ************ */ @@ -367,7 +370,7 @@ static void writedata_free(WriteData *wd) * \param len Length of new chunk of data * \warning Talks to other functions with global parameters */ - + #define MYWRITE_FLUSH NULL static void mywrite(WriteData *wd, const void *adr, int len) @@ -462,13 +465,15 @@ static int endwrite(WriteData *wd) /* ********** WRITE FILE ****************** */ -static void writestruct_at_address( - WriteData *wd, int filecode, const char *structname, int nr, +static void writestruct_at_address_nr( + WriteData *wd, int filecode, const int struct_nr, int nr, const void *adr, const void *data) { BHead bh; const short *sp; + BLI_assert(struct_nr > 0 && struct_nr < SDNA_TYPE_MAX); + if (adr == NULL || data == NULL || nr == 0) { return; } @@ -478,11 +483,7 @@ static void writestruct_at_address( bh.old = adr; bh.nr = nr; - bh.SDNAnr = DNA_struct_find_nr(wd->sdna, structname); - if (bh.SDNAnr == -1) { - printf("error: can't find SDNA code <%s>\n", structname); - return; - } + bh.SDNAnr = struct_nr; sp = wd->sdna->structs[bh.SDNAnr]; bh.len = nr * wd->sdna->typelens[sp[0]]; @@ -495,11 +496,35 @@ static void writestruct_at_address( mywrite(wd, data, bh.len); } -static void writestruct( +static void writestruct_at_address_id( + WriteData *wd, int filecode, const char *structname, int nr, + const void *adr, const void *data) +{ + if (adr == NULL || data == NULL || nr == 0) { + return; + } + + const int SDNAnr = DNA_struct_find_nr(wd->sdna, structname); + if (UNLIKELY(SDNAnr == -1)) { + printf("error: can't find SDNA code <%s>\n", structname); + return; + } + + writestruct_at_address_nr(wd, filecode, SDNAnr, nr, adr, data); +} + +static void writestruct_nr( + WriteData *wd, int filecode, const int struct_nr, int nr, + const void *adr) +{ + writestruct_at_address_nr(wd, filecode, struct_nr, nr, adr, adr); +} + +static void writestruct_id( WriteData *wd, int filecode, const char *structname, int nr, const void *adr) { - writestruct_at_address(wd, filecode, structname, nr, adr, adr); + writestruct_at_address_id(wd, filecode, structname, nr, adr, adr); } static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* do not use for structs */ @@ -525,16 +550,45 @@ static void writedata(WriteData *wd, int filecode, int len, const void *adr) /* } /* use this to force writing of lists in same order as reading (using link_list) */ -static void writelist(WriteData *wd, int filecode, const char *structname, const ListBase *lb) +static void writelist_nr(WriteData *wd, int filecode, const int struct_nr, const ListBase *lb) { const Link *link = lb->first; while (link) { - writestruct(wd, filecode, structname, 1, link); + writestruct_nr(wd, filecode, struct_nr, 1, link); link = link->next; } } +#if 0 +static void writelist_id(WriteData *wd, int filecode, const char *structname, const ListBase *lb) +{ + const Link *link = lb->first; + if (link) { + + const int struct_nr = DNA_struct_find_nr(wd->sdna, structname); + if (struct_nr == -1) { + printf("error: can't find SDNA code <%s>\n", structname); + return; + } + + while (link) { + writestruct_nr(wd, filecode, struct_nr, 1, link); + link = link->next; + } + } +} +#endif + +#define writestruct_at_address(wd, filecode, struct_id, nr, adr, data) \ + writestruct_at_address_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr, data) + +#define writestruct(wd, filecode, struct_id, nr, adr) \ + writestruct_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), nr, adr) + +#define writelist(wd, filecode, struct_id, lb) \ + writelist_nr(wd, filecode, SDNA_TYPE_FROM_STRUCT(struct_id), lb) + /* *************** writing some direct data structs used in more code parts **************** */ /*These functions are used by blender's .blend system for file saving/loading.*/ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd); @@ -564,7 +618,7 @@ static void IDP_WriteIDPArray(const IDProperty *prop, void *wd) const IDProperty *array = prop->data.pointer; int a; - writestruct(wd, DATA, "IDProperty", prop->len, array); + writestruct(wd, DATA, IDProperty, prop->len, array); for (a = 0; a < prop->len; a++) { IDP_WriteProperty_OnlyData(&array[a], wd); @@ -608,7 +662,7 @@ void IDP_WriteProperty_OnlyData(const IDProperty *prop, void *wd) void IDP_WriteProperty(const IDProperty *prop, void *wd) { - writestruct(wd, DATA, "IDProperty", 1, prop); + writestruct(wd, DATA, IDProperty, 1, prop); IDP_WriteProperty_OnlyData(prop, wd); } @@ -632,7 +686,7 @@ static void write_previews(WriteData *wd, const PreviewImage *prv_orig) prv.h[1] = 0; prv.rect[1] = NULL; } - writestruct_at_address(wd, DATA, "PreviewImage", 1, prv_orig, &prv); + writestruct_at_address(wd, DATA, PreviewImage, 1, prv_orig, &prv); if (prv.rect[0]) { writedata(wd, DATA, prv.w[0] * prv.h[0] * sizeof(unsigned int), prv.rect[0]); } @@ -647,7 +701,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) FModifier *fcm; /* Write all modifiers first (for faster reloading) */ - writelist(wd, DATA, "FModifier", fmodifiers); + writelist(wd, DATA, FModifier, fmodifiers); /* Modifiers */ for (fcm = fmodifiers->first; fcm; fcm = fcm->next) { @@ -656,7 +710,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) /* Write the specific data */ if (fmi && fcm->data) { /* firstly, just write the plain fmi->data struct */ - writestruct(wd, DATA, fmi->structName, 1, fcm->data); + writestruct_id(wd, DATA, fmi->structName, 1, fcm->data); /* do any modifier specific stuff */ switch (fcm->type) { @@ -677,7 +731,7 @@ static void write_fmodifiers(WriteData *wd, ListBase *fmodifiers) /* write envelope data */ if (data->data) { - writestruct(wd, DATA, "FCM_EnvelopeData", data->totvert, data->data); + writestruct(wd, DATA, FCM_EnvelopeData, data->totvert, data->data); } break; @@ -701,14 +755,14 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) { FCurve *fcu; - writelist(wd, DATA, "FCurve", fcurves); + writelist(wd, DATA, FCurve, fcurves); for (fcu = fcurves->first; fcu; fcu = fcu->next) { /* curve data */ if (fcu->bezt) { - writestruct(wd, DATA, "BezTriple", fcu->totvert, fcu->bezt); + writestruct(wd, DATA, BezTriple, fcu->totvert, fcu->bezt); } if (fcu->fpt) { - writestruct(wd, DATA, "FPoint", fcu->totvert, fcu->fpt); + writestruct(wd, DATA, FPoint, fcu->totvert, fcu->fpt); } if (fcu->rna_path) { @@ -720,10 +774,10 @@ static void write_fcurves(WriteData *wd, ListBase *fcurves) ChannelDriver *driver = fcu->driver; DriverVar *dvar; - writestruct(wd, DATA, "ChannelDriver", 1, driver); + writestruct(wd, DATA, ChannelDriver, 1, driver); /* variables */ - writelist(wd, DATA, "DriverVar", &driver->variables); + writelist(wd, DATA, DriverVar, &driver->variables); for (dvar = driver->variables.first; dvar; dvar = dvar->next) { DRIVER_TARGETS_USED_LOOPER(dvar) { @@ -748,17 +802,17 @@ static void write_actions(WriteData *wd, ListBase *idbase) for (act = idbase->first; act; act = act->id.next) { if (act->id.us > 0 || wd->current) { - writestruct(wd, ID_AC, "bAction", 1, act); + writestruct(wd, ID_AC, bAction, 1, act); write_iddata(wd, &act->id); write_fcurves(wd, &act->curves); for (grp = act->groups.first; grp; grp = grp->next) { - writestruct(wd, DATA, "bActionGroup", 1, grp); + writestruct(wd, DATA, bActionGroup, 1, grp); } for (marker = act->markers.first; marker; marker = marker->next) { - writestruct(wd, DATA, "TimeMarker", 1, marker); + writestruct(wd, DATA, TimeMarker, 1, marker); } } } @@ -774,12 +828,12 @@ static void write_keyingsets(WriteData *wd, ListBase *list) for (ks = list->first; ks; ks = ks->next) { /* KeyingSet */ - writestruct(wd, DATA, "KeyingSet", 1, ks); + writestruct(wd, DATA, KeyingSet, 1, ks); /* Paths */ for (ksp = ks->paths.first; ksp; ksp = ksp->next) { /* Path */ - writestruct(wd, DATA, "KS_Path", 1, ksp); + writestruct(wd, DATA, KS_Path, 1, ksp); if (ksp->rna_path) { writedata(wd, DATA, strlen(ksp->rna_path) + 1, ksp->rna_path); @@ -792,7 +846,7 @@ static void write_nlastrips(WriteData *wd, ListBase *strips) { NlaStrip *strip; - writelist(wd, DATA, "NlaStrip", strips); + writelist(wd, DATA, NlaStrip, strips); for (strip = strips->first; strip; strip = strip->next) { /* write the strip's F-Curves and modifiers */ write_fcurves(wd, &strip->fcurves); @@ -810,7 +864,7 @@ static void write_nladata(WriteData *wd, ListBase *nlabase) /* write all the tracks */ for (nlt = nlabase->first; nlt; nlt = nlt->next) { /* write the track first */ - writestruct(wd, DATA, "NlaTrack", 1, nlt); + writestruct(wd, DATA, NlaTrack, 1, nlt); /* write the track's strips */ write_nlastrips(wd, &nlt->strips); @@ -822,7 +876,7 @@ static void write_animdata(WriteData *wd, AnimData *adt) AnimOverride *aor; /* firstly, just write the AnimData block */ - writestruct(wd, DATA, "AnimData", 1, adt); + writestruct(wd, DATA, AnimData, 1, adt); /* write drivers */ write_fcurves(wd, &adt->drivers); @@ -831,7 +885,7 @@ static void write_animdata(WriteData *wd, AnimData *adt) // FIXME: are these needed? for (aor = adt->overrides.first; aor; aor = aor->next) { /* overrides consist of base data + rna_path */ - writestruct(wd, DATA, "AnimOverride", 1, aor); + writestruct(wd, DATA, AnimOverride, 1, aor); writedata(wd, DATA, strlen(aor->rna_path) + 1, aor->rna_path); } @@ -844,13 +898,13 @@ static void write_animdata(WriteData *wd, AnimData *adt) static void write_curvemapping_curves(WriteData *wd, CurveMapping *cumap) { for (int a = 0; a < CM_TOT; a++) { - writestruct(wd, DATA, "CurveMapPoint", cumap->cm[a].totpoint, cumap->cm[a].curve); + writestruct(wd, DATA, CurveMapPoint, cumap->cm[a].totpoint, cumap->cm[a].curve); } } static void write_curvemapping(WriteData *wd, CurveMapping *cumap) { - writestruct(wd, DATA, "CurveMapping", 1, cumap); + writestruct(wd, DATA, CurveMapping, 1, cumap); write_curvemapping_curves(wd, cumap); } @@ -877,7 +931,7 @@ static void write_node_socket(WriteData *wd, bNodeTree *UNUSED(ntree), bNode *no #endif /* actual socket writing */ - writestruct(wd, DATA, "bNodeSocket", 1, sock); + writestruct(wd, DATA, bNodeSocket, 1, sock); if (sock->prop) { IDP_WriteProperty(sock->prop, wd); @@ -900,7 +954,7 @@ static void write_node_socket_interface(WriteData *wd, bNodeTree *UNUSED(ntree), #endif /* actual socket writing */ - writestruct(wd, DATA, "bNodeSocket", 1, sock); + writestruct(wd, DATA, bNodeSocket, 1, sock); if (sock->prop) { IDP_WriteProperty(sock->prop, wd); @@ -924,7 +978,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) } for (node = ntree->nodes.first; node; node = node->next) { - writestruct(wd, DATA, "bNode", 1, node); + writestruct(wd, DATA, bNode, 1, node); if (node->prop) { IDP_WriteProperty(node->prop, wd); @@ -938,7 +992,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) } for (link = node->internal_links.first; link; link = link->next) { - writestruct(wd, DATA, "bNodeLink", 1, link); + writestruct(wd, DATA, bNodeLink, 1, link); } if (node->storage) { @@ -955,7 +1009,7 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) if (nss->bytecode) { writedata(wd, DATA, strlen(nss->bytecode) + 1, nss->bytecode); } - writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage); } else if ((ntree->type == NTREE_COMPOSIT) && ELEM(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB, CMP_NODE_HUECORRECT)) @@ -973,26 +1027,26 @@ static void write_nodetree(WriteData *wd, bNodeTree *ntree) /* pass */ } else { - writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage); + writestruct_id(wd, DATA, node->typeinfo->storagename, 1, node->storage); } } if (node->type == CMP_NODE_OUTPUT_FILE) { /* inputs have own storage data */ for (sock = node->inputs.first; sock; sock = sock->next) { - writestruct(wd, DATA, "NodeImageMultiFileSocket", 1, sock->storage); + writestruct(wd, DATA, NodeImageMultiFileSocket, 1, sock->storage); } } if (node->type == CMP_NODE_IMAGE) { /* write extra socket info */ for (sock = node->outputs.first; sock; sock = sock->next) { - writestruct(wd, DATA, "NodeImageLayer", 1, sock->storage); + writestruct(wd, DATA, NodeImageLayer, 1, sock->storage); } } } for (link = ntree->links.first; link; link = link->next) { - writestruct(wd, DATA, "bNodeLink", 1, link); + writestruct(wd, DATA, bNodeLink, 1, link); } for (sock = ntree->inputs.first; sock; sock = sock->next) { @@ -1074,7 +1128,7 @@ static void write_renderinfo(WriteData *wd, Main *mainvar) static void write_keymapitem(WriteData *wd, wmKeyMapItem *kmi) { - writestruct(wd, DATA, "wmKeyMapItem", 1, kmi); + writestruct(wd, DATA, wmKeyMapItem, 1, kmi); if (kmi->properties) { IDP_WriteProperty(kmi->properties, wd); } @@ -1090,17 +1144,17 @@ static void write_userdef(WriteData *wd) bPathCompare *path_cmp; uiStyle *style; - writestruct(wd, USER, "UserDef", 1, &U); + writestruct(wd, USER, UserDef, 1, &U); for (btheme = U.themes.first; btheme; btheme = btheme->next) { - writestruct(wd, DATA, "bTheme", 1, btheme); + writestruct(wd, DATA, bTheme, 1, btheme); } for (keymap = U.user_keymaps.first; keymap; keymap = keymap->next) { - writestruct(wd, DATA, "wmKeyMap", 1, keymap); + writestruct(wd, DATA, wmKeyMap, 1, keymap); for (kmdi = keymap->diff_items.first; kmdi; kmdi = kmdi->next) { - writestruct(wd, DATA, "wmKeyMapDiffItem", 1, kmdi); + writestruct(wd, DATA, wmKeyMapDiffItem, 1, kmdi); if (kmdi->remove_item) { write_keymapitem(wd, kmdi->remove_item); } @@ -1115,18 +1169,18 @@ static void write_userdef(WriteData *wd) } for (bext = U.addons.first; bext; bext = bext->next) { - writestruct(wd, DATA, "bAddon", 1, bext); + writestruct(wd, DATA, bAddon, 1, bext); if (bext->prop) { IDP_WriteProperty(bext->prop, wd); } } for (path_cmp = U.autoexec_paths.first; path_cmp; path_cmp = path_cmp->next) { - writestruct(wd, DATA, "bPathCompare", 1, path_cmp); + writestruct(wd, DATA, bPathCompare, 1, path_cmp); } for (style = U.uistyles.first; style; style = style->next) { - writestruct(wd, DATA, "uiStyle", 1, style); + writestruct(wd, DATA, uiStyle, 1, style); } } @@ -1134,35 +1188,35 @@ static void write_boid_state(WriteData *wd, BoidState *state) { BoidRule *rule = state->rules.first; - writestruct(wd, DATA, "BoidState", 1, state); + writestruct(wd, DATA, BoidState, 1, state); for (; rule; rule = rule->next) { switch (rule->type) { case eBoidRuleType_Goal: case eBoidRuleType_Avoid: - writestruct(wd, DATA, "BoidRuleGoalAvoid", 1, rule); + writestruct(wd, DATA, BoidRuleGoalAvoid, 1, rule); break; case eBoidRuleType_AvoidCollision: - writestruct(wd, DATA, "BoidRuleAvoidCollision", 1, rule); + writestruct(wd, DATA, BoidRuleAvoidCollision, 1, rule); break; case eBoidRuleType_FollowLeader: - writestruct(wd, DATA, "BoidRuleFollowLeader", 1, rule); + writestruct(wd, DATA, BoidRuleFollowLeader, 1, rule); break; case eBoidRuleType_AverageSpeed: - writestruct(wd, DATA, "BoidRuleAverageSpeed", 1, rule); + writestruct(wd, DATA, BoidRuleAverageSpeed, 1, rule); break; case eBoidRuleType_Fight: - writestruct(wd, DATA, "BoidRuleFight", 1, rule); + writestruct(wd, DATA, BoidRuleFight, 1, rule); break; default: - writestruct(wd, DATA, "BoidRule", 1, rule); + writestruct(wd, DATA, BoidRule, 1, rule); break; } } #if 0 BoidCondition *cond = state->conditions.first; for (; cond; cond = cond->next) { - writestruct(wd, DATA, "BoidCondition", 1, cond); + writestruct(wd, DATA, BoidCondition, 1, cond); } #endif } @@ -1188,7 +1242,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) int i; for (; cache; cache = cache->next) { - writestruct(wd, DATA, "PointCache", 1, cache); + writestruct(wd, DATA, PointCache, 1, cache); if ((cache->flag & PTCACHE_DISK_CACHE) == 0) { PTCacheMem *pm = cache->mem_cache.first; @@ -1196,7 +1250,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) for (; pm; pm = pm->next) { PTCacheExtra *extra = pm->extradata.first; - writestruct(wd, DATA, "PTCacheMem", 1, pm); + writestruct(wd, DATA, PTCacheMem, 1, pm); for (i = 0; i < BPHYS_TOT_DATA; i++) { if (pm->data[i] && pm->data_types & (1 << i)) { @@ -1204,7 +1258,7 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) writedata(wd, DATA, MEM_allocN_len(pm->data[i]), pm->data[i]); } else { - writestruct(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); + writestruct_id(wd, DATA, ptcache_data_struct[i], pm->totpoint, pm->data[i]); } } } @@ -1213,8 +1267,8 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) if (ptcache_extra_struct[extra->type][0] == '\0') { continue; } - writestruct(wd, DATA, "PTCacheExtra", 1, extra); - writestruct(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); + writestruct(wd, DATA, PTCacheExtra, 1, extra); + writestruct_id(wd, DATA, ptcache_extra_struct[extra->type], extra->totdata, extra->data); } } } @@ -1231,15 +1285,15 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) while (part) { if (part->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_PA, "ParticleSettings", 1, part); + writestruct(wd, ID_PA, ParticleSettings, 1, part); write_iddata(wd, &part->id); if (part->adt) { write_animdata(wd, part->adt); } - writestruct(wd, DATA, "PartDeflect", 1, part->pd); - writestruct(wd, DATA, "PartDeflect", 1, part->pd2); - writestruct(wd, DATA, "EffectorWeights", 1, part->effector_weights); + writestruct(wd, DATA, PartDeflect, 1, part->pd); + writestruct(wd, DATA, PartDeflect, 1, part->pd2); + writestruct(wd, DATA, EffectorWeights, 1, part->effector_weights); if (part->clumpcurve) { write_curvemapping(wd, part->clumpcurve); @@ -1259,25 +1313,25 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) dw->index++; } } - writestruct(wd, DATA, "ParticleDupliWeight", 1, dw); + writestruct(wd, DATA, ParticleDupliWeight, 1, dw); } if (part->boids && part->phystype == PART_PHYS_BOIDS) { BoidState *state = part->boids->states.first; - writestruct(wd, DATA, "BoidSettings", 1, part->boids); + writestruct(wd, DATA, BoidSettings, 1, part->boids); for (; state; state = state->next) { write_boid_state(wd, state); } } if (part->fluid && part->phystype == PART_PHYS_FLUID) { - writestruct(wd, DATA, "SPHFluidSettings", 1, part->fluid); + writestruct(wd, DATA, SPHFluidSettings, 1, part->fluid); } for (a = 0; a < MAX_MTEX; a++) { if (part->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, part->mtex[a]); + writestruct(wd, DATA, MTex, 1, part->mtex[a]); } } } @@ -1291,45 +1345,45 @@ static void write_particlesystems(WriteData *wd, ListBase *particles) int a; for (; psys; psys = psys->next) { - writestruct(wd, DATA, "ParticleSystem", 1, psys); + writestruct(wd, DATA, ParticleSystem, 1, psys); if (psys->particles) { - writestruct(wd, DATA, "ParticleData", psys->totpart, psys->particles); + writestruct(wd, DATA, ParticleData, psys->totpart, psys->particles); if (psys->particles->hair) { ParticleData *pa = psys->particles; for (a = 0; a < psys->totpart; a++, pa++) { - writestruct(wd, DATA, "HairKey", pa->totkey, pa->hair); + writestruct(wd, DATA, HairKey, pa->totkey, pa->hair); } } if (psys->particles->boid && (psys->part->phystype == PART_PHYS_BOIDS)) { - writestruct(wd, DATA, "BoidParticle", psys->totpart, psys->particles->boid); + writestruct(wd, DATA, BoidParticle, psys->totpart, psys->particles->boid); } if (psys->part->fluid && (psys->part->phystype == PART_PHYS_FLUID) && (psys->part->fluid->flag & SPH_VISCOELASTIC_SPRINGS)) { - writestruct(wd, DATA, "ParticleSpring", psys->tot_fluidsprings, psys->fluid_springs); + writestruct(wd, DATA, ParticleSpring, psys->tot_fluidsprings, psys->fluid_springs); } } pt = psys->targets.first; for (; pt; pt = pt->next) { - writestruct(wd, DATA, "ParticleTarget", 1, pt); + writestruct(wd, DATA, ParticleTarget, 1, pt); } if (psys->child) { - writestruct(wd, DATA, "ChildParticle", psys->totchild, psys->child); + writestruct(wd, DATA, ChildParticle, psys->totchild, psys->child); } if (psys->clmd) { - writestruct(wd, DATA, "ClothModifierData", 1, psys->clmd); - writestruct(wd, DATA, "ClothSimSettings", 1, psys->clmd->sim_parms); - writestruct(wd, DATA, "ClothCollSettings", 1, psys->clmd->coll_parms); + writestruct(wd, DATA, ClothModifierData, 1, psys->clmd); + writestruct(wd, DATA, ClothSimSettings, 1, psys->clmd->sim_parms); + writestruct(wd, DATA, ClothCollSettings, 1, psys->clmd->coll_parms); } write_pointcaches(wd, &psys->ptcaches); @@ -1342,7 +1396,7 @@ static void write_properties(WriteData *wd, ListBase *lb) prop = lb->first; while (prop) { - writestruct(wd, DATA, "bProperty", 1, prop); + writestruct(wd, DATA, bProperty, 1, prop); if (prop->poin && prop->poin != &prop->data) { writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin); @@ -1358,49 +1412,49 @@ static void write_sensors(WriteData *wd, ListBase *lb) sens = lb->first; while (sens) { - writestruct(wd, DATA, "bSensor", 1, sens); + writestruct(wd, DATA, bSensor, 1, sens); writedata(wd, DATA, sizeof(void *) * sens->totlinks, sens->links); switch (sens->type) { case SENS_NEAR: - writestruct(wd, DATA, "bNearSensor", 1, sens->data); + writestruct(wd, DATA, bNearSensor, 1, sens->data); break; case SENS_MOUSE: - writestruct(wd, DATA, "bMouseSensor", 1, sens->data); + writestruct(wd, DATA, bMouseSensor, 1, sens->data); break; case SENS_KEYBOARD: - writestruct(wd, DATA, "bKeyboardSensor", 1, sens->data); + writestruct(wd, DATA, bKeyboardSensor, 1, sens->data); break; case SENS_PROPERTY: - writestruct(wd, DATA, "bPropertySensor", 1, sens->data); + writestruct(wd, DATA, bPropertySensor, 1, sens->data); break; case SENS_ARMATURE: - writestruct(wd, DATA, "bArmatureSensor", 1, sens->data); + writestruct(wd, DATA, bArmatureSensor, 1, sens->data); break; case SENS_ACTUATOR: - writestruct(wd, DATA, "bActuatorSensor", 1, sens->data); + writestruct(wd, DATA, bActuatorSensor, 1, sens->data); break; case SENS_DELAY: - writestruct(wd, DATA, "bDelaySensor", 1, sens->data); + writestruct(wd, DATA, bDelaySensor, 1, sens->data); break; case SENS_COLLISION: - writestruct(wd, DATA, "bCollisionSensor", 1, sens->data); + writestruct(wd, DATA, bCollisionSensor, 1, sens->data); break; case SENS_RADAR: - writestruct(wd, DATA, "bRadarSensor", 1, sens->data); + writestruct(wd, DATA, bRadarSensor, 1, sens->data); break; case SENS_RANDOM: - writestruct(wd, DATA, "bRandomSensor", 1, sens->data); + writestruct(wd, DATA, bRandomSensor, 1, sens->data); break; case SENS_RAY: - writestruct(wd, DATA, "bRaySensor", 1, sens->data); + writestruct(wd, DATA, bRaySensor, 1, sens->data); break; case SENS_MESSAGE: - writestruct(wd, DATA, "bMessageSensor", 1, sens->data); + writestruct(wd, DATA, bMessageSensor, 1, sens->data); break; case SENS_JOYSTICK: - writestruct(wd, DATA, "bJoystickSensor", 1, sens->data); + writestruct(wd, DATA, bJoystickSensor, 1, sens->data); break; default: ; /* error: don't know how to write this file */ @@ -1416,16 +1470,16 @@ static void write_controllers(WriteData *wd, ListBase *lb) cont = lb->first; while (cont) { - writestruct(wd, DATA, "bController", 1, cont); + writestruct(wd, DATA, bController, 1, cont); writedata(wd, DATA, sizeof(void *) * cont->totlinks, cont->links); switch (cont->type) { case CONT_EXPRESSION: - writestruct(wd, DATA, "bExpressionCont", 1, cont->data); + writestruct(wd, DATA, bExpressionCont, 1, cont->data); break; case CONT_PYTHON: - writestruct(wd, DATA, "bPythonCont", 1, cont->data); + writestruct(wd, DATA, bPythonCont, 1, cont->data); break; default: ; /* error: don't know how to write this file */ @@ -1441,66 +1495,66 @@ static void write_actuators(WriteData *wd, ListBase *lb) act = lb->first; while (act) { - writestruct(wd, DATA, "bActuator", 1, act); + writestruct(wd, DATA, bActuator, 1, act); switch (act->type) { case ACT_ACTION: case ACT_SHAPEACTION: - writestruct(wd, DATA, "bActionActuator", 1, act->data); + writestruct(wd, DATA, bActionActuator, 1, act->data); break; case ACT_SOUND: - writestruct(wd, DATA, "bSoundActuator", 1, act->data); + writestruct(wd, DATA, bSoundActuator, 1, act->data); break; case ACT_OBJECT: - writestruct(wd, DATA, "bObjectActuator", 1, act->data); + writestruct(wd, DATA, bObjectActuator, 1, act->data); break; case ACT_PROPERTY: - writestruct(wd, DATA, "bPropertyActuator", 1, act->data); + writestruct(wd, DATA, bPropertyActuator, 1, act->data); break; case ACT_CAMERA: - writestruct(wd, DATA, "bCameraActuator", 1, act->data); + writestruct(wd, DATA, bCameraActuator, 1, act->data); break; case ACT_CONSTRAINT: - writestruct(wd, DATA, "bConstraintActuator", 1, act->data); + writestruct(wd, DATA, bConstraintActuator, 1, act->data); break; case ACT_EDIT_OBJECT: - writestruct(wd, DATA, "bEditObjectActuator", 1, act->data); + writestruct(wd, DATA, bEditObjectActuator, 1, act->data); break; case ACT_SCENE: - writestruct(wd, DATA, "bSceneActuator", 1, act->data); + writestruct(wd, DATA, bSceneActuator, 1, act->data); break; case ACT_GROUP: - writestruct(wd, DATA, "bGroupActuator", 1, act->data); + writestruct(wd, DATA, bGroupActuator, 1, act->data); break; case ACT_RANDOM: - writestruct(wd, DATA, "bRandomActuator", 1, act->data); + writestruct(wd, DATA, bRandomActuator, 1, act->data); break; case ACT_MESSAGE: - writestruct(wd, DATA, "bMessageActuator", 1, act->data); + writestruct(wd, DATA, bMessageActuator, 1, act->data); break; case ACT_GAME: - writestruct(wd, DATA, "bGameActuator", 1, act->data); + writestruct(wd, DATA, bGameActuator, 1, act->data); break; case ACT_VISIBILITY: - writestruct(wd, DATA, "bVisibilityActuator", 1, act->data); + writestruct(wd, DATA, bVisibilityActuator, 1, act->data); break; case ACT_2DFILTER: - writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data); + writestruct(wd, DATA, bTwoDFilterActuator, 1, act->data); break; case ACT_PARENT: - writestruct(wd, DATA, "bParentActuator", 1, act->data); + writestruct(wd, DATA, bParentActuator, 1, act->data); break; case ACT_STATE: - writestruct(wd, DATA, "bStateActuator", 1, act->data); + writestruct(wd, DATA, bStateActuator, 1, act->data); break; case ACT_ARMATURE: - writestruct(wd, DATA, "bArmatureActuator", 1, act->data); + writestruct(wd, DATA, bArmatureActuator, 1, act->data); break; case ACT_STEERING: - writestruct(wd, DATA, "bSteeringActuator", 1, act->data); + writestruct(wd, DATA, bSteeringActuator, 1, act->data); break; case ACT_MOUSE: - writestruct(wd, DATA, "bMouseActuator", 1, act->data); + writestruct(wd, DATA, bMouseActuator, 1, act->data); break; default: ; /* error: don't know how to write this file */ @@ -1518,10 +1572,10 @@ static void write_motionpath(WriteData *wd, bMotionPath *mpath) } /* firstly, just write the motionpath struct */ - writestruct(wd, DATA, "bMotionPath", 1, mpath); + writestruct(wd, DATA, bMotionPath, 1, mpath); /* now write the array of data */ - writestruct(wd, DATA, "bMotionPathVert", mpath->length, mpath->points); + writestruct(wd, DATA, bMotionPathVert, mpath->length, mpath->points); } static void write_constraints(WriteData *wd, ListBase *conlist) @@ -1534,7 +1588,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist) /* Write the specific data */ if (cti && con->data) { /* firstly, just write the plain con->data struct */ - writestruct(wd, DATA, cti->structName, 1, con->data); + writestruct_id(wd, DATA, cti->structName, 1, con->data); /* do any constraint specific stuff */ switch (con->type) { @@ -1545,7 +1599,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist) /* write targets */ for (ct = data->targets.first; ct; ct = ct->next) { - writestruct(wd, DATA, "bConstraintTarget", 1, ct); + writestruct(wd, DATA, bConstraintTarget, 1, ct); } /* Write ID Properties -- and copy this comment EXACTLY for easy finding @@ -1567,7 +1621,7 @@ static void write_constraints(WriteData *wd, ListBase *conlist) } /* Write the constraint */ - writestruct(wd, DATA, "bConstraint", 1, con); + writestruct(wd, DATA, bConstraint, 1, con); } } @@ -1600,31 +1654,31 @@ static void write_pose(WriteData *wd, bPose *pose) chan->selectflag = chan->bone->flag & BONE_SELECTED; } - writestruct(wd, DATA, "bPoseChannel", 1, chan); + writestruct(wd, DATA, bPoseChannel, 1, chan); } /* Write groups */ for (grp = pose->agroups.first; grp; grp = grp->next) { - writestruct(wd, DATA, "bActionGroup", 1, grp); + writestruct(wd, DATA, bActionGroup, 1, grp); } /* write IK param */ if (pose->ikparam) { const char *structname = BKE_pose_ikparam_get_name(pose); if (structname) { - writestruct(wd, DATA, structname, 1, pose->ikparam); + writestruct_id(wd, DATA, structname, 1, pose->ikparam); } } /* Write this pose */ - writestruct(wd, DATA, "bPose", 1, pose); + writestruct(wd, DATA, bPose, 1, pose); } static void write_defgroups(WriteData *wd, ListBase *defbase) { for (bDeformGroup *defgroup = defbase->first; defgroup; defgroup = defgroup->next) { - writestruct(wd, DATA, "bDeformGroup", 1, defgroup); + writestruct(wd, DATA, bDeformGroup, 1, defgroup); } } @@ -1642,7 +1696,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) return; } - writestruct(wd, DATA, mti->structName, 1, md); + writestruct_id(wd, DATA, mti->structName, 1, md); if (md->type == eModifierType_Hook) { HookModifierData *hmd = (HookModifierData *)md; @@ -1656,9 +1710,9 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) else if (md->type == eModifierType_Cloth) { ClothModifierData *clmd = (ClothModifierData *)md; - writestruct(wd, DATA, "ClothSimSettings", 1, clmd->sim_parms); - writestruct(wd, DATA, "ClothCollSettings", 1, clmd->coll_parms); - writestruct(wd, DATA, "EffectorWeights", 1, clmd->sim_parms->effector_weights); + writestruct(wd, DATA, ClothSimSettings, 1, clmd->sim_parms); + writestruct(wd, DATA, ClothCollSettings, 1, clmd->coll_parms); + writestruct(wd, DATA, EffectorWeights, 1, clmd->sim_parms->effector_weights); write_pointcaches(wd, &clmd->ptcaches); } else if (md->type == eModifierType_Smoke) { @@ -1676,50 +1730,50 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) write_pointcaches(wd, &(smd->domain->ptcaches[1])); } - writestruct(wd, DATA, "SmokeDomainSettings", 1, smd->domain); + writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain); if (smd->domain) { /* cleanup the fake pointcache */ BKE_ptcache_free_list(&smd->domain->ptcaches[1]); smd->domain->point_cache[1] = NULL; - writestruct(wd, DATA, "EffectorWeights", 1, smd->domain->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, smd->domain->effector_weights); } } else if (smd->type & MOD_SMOKE_TYPE_FLOW) { - writestruct(wd, DATA, "SmokeFlowSettings", 1, smd->flow); + writestruct(wd, DATA, SmokeFlowSettings, 1, smd->flow); } else if (smd->type & MOD_SMOKE_TYPE_COLL) { - writestruct(wd, DATA, "SmokeCollSettings", 1, smd->coll); + writestruct(wd, DATA, SmokeCollSettings, 1, smd->coll); } } else if (md->type == eModifierType_Fluidsim) { FluidsimModifierData *fluidmd = (FluidsimModifierData *)md; - writestruct(wd, DATA, "FluidsimSettings", 1, fluidmd->fss); + writestruct(wd, DATA, FluidsimSettings, 1, fluidmd->fss); } else if (md->type == eModifierType_DynamicPaint) { DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; if (pmd->canvas) { DynamicPaintSurface *surface; - writestruct(wd, DATA, "DynamicPaintCanvasSettings", 1, pmd->canvas); + writestruct(wd, DATA, DynamicPaintCanvasSettings, 1, pmd->canvas); /* write surfaces */ for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { - writestruct(wd, DATA, "DynamicPaintSurface", 1, surface); + writestruct(wd, DATA, DynamicPaintSurface, 1, surface); } /* write caches and effector weights */ for (surface = pmd->canvas->surfaces.first; surface; surface = surface->next) { write_pointcaches(wd, &(surface->ptcaches)); - writestruct(wd, DATA, "EffectorWeights", 1, surface->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, surface->effector_weights); } } if (pmd->brush) { - writestruct(wd, DATA, "DynamicPaintBrushSettings", 1, pmd->brush); - writestruct(wd, DATA, "ColorBand", 1, pmd->brush->paint_ramp); - writestruct(wd, DATA, "ColorBand", 1, pmd->brush->vel_ramp); + writestruct(wd, DATA, DynamicPaintBrushSettings, 1, pmd->brush); + writestruct(wd, DATA, ColorBand, 1, pmd->brush->paint_ramp); + writestruct(wd, DATA, ColorBand, 1, pmd->brush->vel_ramp); } } else if (md->type == eModifierType_Collision) { @@ -1728,21 +1782,21 @@ static void write_modifiers(WriteData *wd, ListBase *modbase) CollisionModifierData *collmd = (CollisionModifierData *)md; // TODO: CollisionModifier should use pointcache // + have proper reset events before enabling this - writestruct(wd, DATA, "MVert", collmd->numverts, collmd->x); - writestruct(wd, DATA, "MVert", collmd->numverts, collmd->xnew); - writestruct(wd, DATA, "MFace", collmd->numfaces, collmd->mfaces); + writestruct(wd, DATA, MVert, collmd->numverts, collmd->x); + writestruct(wd, DATA, MVert, collmd->numverts, collmd->xnew); + writestruct(wd, DATA, MFace, collmd->numfaces, collmd->mfaces); #endif } else if (md->type == eModifierType_MeshDeform) { MeshDeformModifierData *mmd = (MeshDeformModifierData *)md; int size = mmd->dyngridsize; - writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->bindinfluences); + writestruct(wd, DATA, MDefInfluence, mmd->totinfluence, mmd->bindinfluences); writedata(wd, DATA, sizeof(int) * (mmd->totvert + 1), mmd->bindoffsets); writedata(wd, DATA, sizeof(float) * 3 * mmd->totcagevert, mmd->bindcagecos); - writestruct(wd, DATA, "MDefCell", size * size * size, mmd->dyngrid); - writestruct(wd, DATA, "MDefInfluence", mmd->totinfluence, mmd->dyninfluences); + writestruct(wd, DATA, MDefCell, size * size * size, mmd->dyngrid); + writestruct(wd, DATA, MDefInfluence, mmd->totinfluence, mmd->dyninfluences); writedata(wd, DATA, sizeof(int) * mmd->totvert, mmd->dynverts); } else if (md->type == eModifierType_Warp) { @@ -1781,7 +1835,7 @@ static void write_objects(WriteData *wd, ListBase *idbase) while (ob) { if (ob->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_OB, "Object", 1, ob); + writestruct(wd, ID_OB, Object, 1, ob); write_iddata(wd, &ob->id); if (ob->adt) { @@ -1809,31 +1863,31 @@ static void write_objects(WriteData *wd, ListBase *idbase) write_constraints(wd, &ob->constraints); write_motionpath(wd, ob->mpath); - writestruct(wd, DATA, "PartDeflect", 1, ob->pd); - writestruct(wd, DATA, "SoftBody", 1, ob->soft); + writestruct(wd, DATA, PartDeflect, 1, ob->pd); + writestruct(wd, DATA, SoftBody, 1, ob->soft); if (ob->soft) { write_pointcaches(wd, &ob->soft->ptcaches); - writestruct(wd, DATA, "EffectorWeights", 1, ob->soft->effector_weights); + writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights); } - writestruct(wd, DATA, "BulletSoftBody", 1, ob->bsoft); + writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft); if (ob->rigidbody_object) { /* TODO: if any extra data is added to handle duplis, will need separate function then */ - writestruct(wd, DATA, "RigidBodyOb", 1, ob->rigidbody_object); + writestruct(wd, DATA, RigidBodyOb, 1, ob->rigidbody_object); } if (ob->rigidbody_constraint) { - writestruct(wd, DATA, "RigidBodyCon", 1, ob->rigidbody_constraint); + writestruct(wd, DATA, RigidBodyCon, 1, ob->rigidbody_constraint); } if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) { - writestruct(wd, DATA, "ImageUser", 1, ob->iuser); + writestruct(wd, DATA, ImageUser, 1, ob->iuser); } write_particlesystems(wd, &ob->particlesystem); write_modifiers(wd, &ob->modifiers); - writelist(wd, DATA, "LinkData", &ob->pc_ids); - writelist(wd, DATA, "LodLevel", &ob->lodlevels); + writelist(wd, DATA, LinkData, &ob->pc_ids); + writelist(wd, DATA, LodLevel, &ob->lodlevels); } write_previews(wd, ob->preview); @@ -1855,14 +1909,14 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) while (vf) { if (vf->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_VF, "VFont", 1, vf); + writestruct(wd, ID_VF, VFont, 1, vf); write_iddata(wd, &vf->id); /* direct data */ if (vf->packedfile) { pf = vf->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } @@ -1881,7 +1935,7 @@ static void write_keys(WriteData *wd, ListBase *idbase) while (key) { if (key->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_KE, "Key", 1, key); + writestruct(wd, ID_KE, Key, 1, key); write_iddata(wd, &key->id); if (key->adt) { @@ -1891,7 +1945,7 @@ static void write_keys(WriteData *wd, ListBase *idbase) /* direct data */ kb = key->block.first; while (kb) { - writestruct(wd, DATA, "KeyBlock", 1, kb); + writestruct(wd, DATA, KeyBlock, 1, kb); if (kb->data) { writedata(wd, DATA, kb->totelem * key->elemsize, kb->data); } @@ -1913,7 +1967,7 @@ static void write_cameras(WriteData *wd, ListBase *idbase) while (cam) { if (cam->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_CA, "Camera", 1, cam); + writestruct(wd, ID_CA, Camera, 1, cam); write_iddata(wd, &cam->id); if (cam->adt) { @@ -1934,7 +1988,7 @@ static void write_mballs(WriteData *wd, ListBase *idbase) while (mb) { if (mb->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_MB, "MetaBall", 1, mb); + writestruct(wd, ID_MB, MetaBall, 1, mb); write_iddata(wd, &mb->id); /* direct data */ @@ -1945,7 +1999,7 @@ static void write_mballs(WriteData *wd, ListBase *idbase) ml = mb->elems.first; while (ml) { - writestruct(wd, DATA, "MetaElem", 1, ml); + writestruct(wd, DATA, MetaElem, 1, ml); ml = ml->next; } } @@ -1962,7 +2016,7 @@ static void write_curves(WriteData *wd, ListBase *idbase) while (cu) { if (cu->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_CU, "Curve", 1, cu); + writestruct(wd, ID_CU, Curve, 1, cu); write_iddata(wd, &cu->id); /* direct data */ @@ -1973,23 +2027,23 @@ static void write_curves(WriteData *wd, ListBase *idbase) if (cu->vfont) { writedata(wd, DATA, cu->len + 1, cu->str); - writestruct(wd, DATA, "CharInfo", cu->len_wchar + 1, cu->strinfo); - writestruct(wd, DATA, "TextBox", cu->totbox, cu->tb); + writestruct(wd, DATA, CharInfo, cu->len_wchar + 1, cu->strinfo); + writestruct(wd, DATA, TextBox, cu->totbox, cu->tb); } else { /* is also the order of reading */ nu = cu->nurb.first; while (nu) { - writestruct(wd, DATA, "Nurb", 1, nu); + writestruct(wd, DATA, Nurb, 1, nu); nu = nu->next; } nu = cu->nurb.first; while (nu) { if (nu->type == CU_BEZIER) { - writestruct(wd, DATA, "BezTriple", nu->pntsu, nu->bezt); + writestruct(wd, DATA, BezTriple, nu->pntsu, nu->bezt); } else { - writestruct(wd, DATA, "BPoint", nu->pntsu * nu->pntsv, nu->bp); + writestruct(wd, DATA, BPoint, nu->pntsu * nu->pntsv, nu->bp); if (nu->knotsu) { writedata(wd, DATA, KNOTSU(nu) * sizeof(float), nu->knotsu); } @@ -2013,12 +2067,12 @@ static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist) if (dvlist) { /* Write the dvert list */ - writestruct(wd, DATA, "MDeformVert", count, dvlist); + writestruct(wd, DATA, MDeformVert, count, dvlist); /* Write deformation data for each dvert */ for (int i = 0; i < count; i++) { if (dvlist[i].dw) { - writestruct(wd, DATA, "MDeformWeight", dvlist[i].totweight, dvlist[i].dw); + writestruct(wd, DATA, MDeformWeight, dvlist[i].totweight, dvlist[i].dw); } } } @@ -2029,7 +2083,7 @@ static void write_mdisps(WriteData *wd, int count, MDisps *mdlist, int external) if (mdlist) { int i; - writestruct(wd, DATA, "MDisps", count, mdlist); + writestruct(wd, DATA, MDisps, count, mdlist); for (i = 0; i < count; ++i) { MDisps *md = &mdlist[i]; if (md->disps) { @@ -2050,7 +2104,7 @@ static void write_grid_paint_mask(WriteData *wd, int count, GridPaintMask *grid_ if (grid_paint_mask) { int i; - writestruct(wd, DATA, "GridPaintMask", count, grid_paint_mask); + writestruct(wd, DATA, GridPaintMask, count, grid_paint_mask); for (i = 0; i < count; ++i) { GridPaintMask *gpm = &grid_paint_mask[i]; if (gpm->data) { @@ -2074,7 +2128,7 @@ static void write_customdata( CustomData_external_write(data, id, CD_MASK_MESH, count, 0); } - writestruct_at_address(wd, DATA, "CustomDataLayer", data->totlayer, data->layers, layers); + writestruct_at_address(wd, DATA, CustomDataLayer, data->totlayer, data->layers, layers); for (i = 0; i < data->totlayer; i++) { CustomDataLayer *layer = &layers[i]; @@ -2108,7 +2162,7 @@ static void write_customdata( datasize = structnum * partial_count; } - writestruct(wd, DATA, structname, datasize, layer->data); + writestruct_id(wd, DATA, structname, datasize, layer->data); } else { printf("%s error: layer '%s':%d - can't be written to file\n", @@ -2118,7 +2172,7 @@ static void write_customdata( } if (data->external) { - writestruct(wd, DATA, "CustomDataExternal", 1, data->external); + writestruct(wd, DATA, CustomDataExternal, 1, data->external); } } @@ -2172,7 +2226,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff)); CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); - writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh); write_iddata(wd, &mesh->id); /* direct data */ @@ -2232,7 +2286,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) CustomData_file_write_prepare(&mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff)); #endif - writestruct_at_address(wd, ID_ME, "Mesh", 1, old_mesh, mesh); + writestruct_at_address(wd, ID_ME, Mesh, 1, old_mesh, mesh); write_iddata(wd, &mesh->id); /* direct data */ @@ -2289,7 +2343,7 @@ static void write_lattices(WriteData *wd, ListBase *idbase) while (lt) { if (lt->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_LT, "Lattice", 1, lt); + writestruct(wd, ID_LT, Lattice, 1, lt); write_iddata(wd, <->id); /* write animdata */ @@ -2298,7 +2352,7 @@ static void write_lattices(WriteData *wd, ListBase *idbase) } /* direct data */ - writestruct(wd, DATA, "BPoint", lt->pntsu * lt->pntsv * lt->pntsw, lt->def); + writestruct(wd, DATA, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def); write_dverts(wd, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert); @@ -2325,14 +2379,14 @@ static void write_images(WriteData *wd, ListBase *idbase) } /* write LibData */ - writestruct(wd, ID_IM, "Image", 1, ima); + writestruct(wd, ID_IM, Image, 1, ima); write_iddata(wd, &ima->id); for (imapf = ima->packedfiles.first; imapf; imapf = imapf->next) { - writestruct(wd, DATA, "ImagePackedFile", 1, imapf); + writestruct(wd, DATA, ImagePackedFile, 1, imapf); if (imapf->packedfile) { pf = imapf->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } @@ -2340,9 +2394,9 @@ static void write_images(WriteData *wd, ListBase *idbase) write_previews(wd, ima->preview); for (iv = ima->views.first; iv; iv = iv->next) { - writestruct(wd, DATA, "ImageView", 1, iv); + writestruct(wd, DATA, ImageView, 1, iv); } - writestruct(wd, DATA, "Stereo3dFormat", 1, ima->stereo3d_format); + writestruct(wd, DATA, Stereo3dFormat, 1, ima->stereo3d_format); ima->packedfile = NULL; } @@ -2360,7 +2414,7 @@ static void write_textures(WriteData *wd, ListBase *idbase) while (tex) { if (tex->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_TE, "Tex", 1, tex); + writestruct(wd, ID_TE, Tex, 1, tex); write_iddata(wd, &tex->id); if (tex->adt) { @@ -2369,30 +2423,30 @@ static void write_textures(WriteData *wd, ListBase *idbase) /* direct data */ if (tex->coba) { - writestruct(wd, DATA, "ColorBand", 1, tex->coba); + writestruct(wd, DATA, ColorBand, 1, tex->coba); } if (tex->type == TEX_ENVMAP && tex->env) { - writestruct(wd, DATA, "EnvMap", 1, tex->env); + writestruct(wd, DATA, EnvMap, 1, tex->env); } if (tex->type == TEX_POINTDENSITY && tex->pd) { - writestruct(wd, DATA, "PointDensity", 1, tex->pd); + writestruct(wd, DATA, PointDensity, 1, tex->pd); if (tex->pd->coba) { - writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba); + writestruct(wd, DATA, ColorBand, 1, tex->pd->coba); } if (tex->pd->falloff_curve) { write_curvemapping(wd, tex->pd->falloff_curve); } } if (tex->type == TEX_VOXELDATA) { - writestruct(wd, DATA, "VoxelData", 1, tex->vd); + writestruct(wd, DATA, VoxelData, 1, tex->vd); } if (tex->type == TEX_OCEAN && tex->ot) { - writestruct(wd, DATA, "OceanTex", 1, tex->ot); + writestruct(wd, DATA, OceanTex, 1, tex->ot); } /* nodetree is integral part of texture, no libdata */ if (tex->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, tex->nodetree); + writestruct(wd, DATA, bNodeTree, 1, tex->nodetree); write_nodetree(wd, tex->nodetree); } @@ -2414,7 +2468,7 @@ static void write_materials(WriteData *wd, ListBase *idbase) while (ma) { if (ma->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_MA, "Material", 1, ma); + writestruct(wd, ID_MA, Material, 1, ma); write_iddata(wd, &ma->id); if (ma->adt) { @@ -2423,20 +2477,20 @@ static void write_materials(WriteData *wd, ListBase *idbase) for (a = 0; a < MAX_MTEX; a++) { if (ma->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, ma->mtex[a]); + writestruct(wd, DATA, MTex, 1, ma->mtex[a]); } } if (ma->ramp_col) { - writestruct(wd, DATA, "ColorBand", 1, ma->ramp_col); + writestruct(wd, DATA, ColorBand, 1, ma->ramp_col); } if (ma->ramp_spec) { - writestruct(wd, DATA, "ColorBand", 1, ma->ramp_spec); + writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec); } /* nodetree is integral part of material, no libdata */ if (ma->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, ma->nodetree); + writestruct(wd, DATA, bNodeTree, 1, ma->nodetree); write_nodetree(wd, ma->nodetree); } @@ -2455,7 +2509,7 @@ static void write_worlds(WriteData *wd, ListBase *idbase) while (wrld) { if (wrld->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_WO, "World", 1, wrld); + writestruct(wd, ID_WO, World, 1, wrld); write_iddata(wd, &wrld->id); if (wrld->adt) { @@ -2464,13 +2518,13 @@ static void write_worlds(WriteData *wd, ListBase *idbase) for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, wrld->mtex[a]); + writestruct(wd, DATA, MTex, 1, wrld->mtex[a]); } } /* nodetree is integral part of world, no libdata */ if (wrld->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, wrld->nodetree); + writestruct(wd, DATA, bNodeTree, 1, wrld->nodetree); write_nodetree(wd, wrld->nodetree); } @@ -2489,7 +2543,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) while (la) { if (la->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_LA, "Lamp", 1, la); + writestruct(wd, ID_LA, Lamp, 1, la); write_iddata(wd, &la->id); if (la->adt) { @@ -2499,7 +2553,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) /* direct data */ for (a = 0; a < MAX_MTEX; a++) { if (la->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, la->mtex[a]); + writestruct(wd, DATA, MTex, 1, la->mtex[a]); } } @@ -2509,7 +2563,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) /* nodetree is integral part of lamps, no libdata */ if (la->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, la->nodetree); + writestruct(wd, DATA, bNodeTree, 1, la->nodetree); write_nodetree(wd, la->nodetree); } @@ -2528,7 +2582,7 @@ static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) const SequenceModifierTypeInfo *smti = BKE_sequence_modifier_type_info_get(smd->type); if (smti) { - writestruct(wd, DATA, smti->struct_name, 1, smd); + writestruct_id(wd, DATA, smti->struct_name, 1, smd); if (smd->type == seqModifierType_Curves) { CurvesModifierData *cmd = (CurvesModifierData *)smd; @@ -2542,7 +2596,7 @@ static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) } } else { - writestruct(wd, DATA, "SequenceModifierData", 1, smd); + writestruct(wd, DATA, SequenceModifierData, 1, smd); } } } @@ -2580,7 +2634,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) sce = scebase->first; while (sce) { /* write LibData */ - writestruct(wd, ID_SCE, "Scene", 1, sce); + writestruct(wd, ID_SCE, Scene, 1, sce); write_iddata(wd, &sce->id); if (sce->adt) { @@ -2591,26 +2645,26 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* direct data */ base = sce->base.first; while (base) { - writestruct(wd, DATA, "Base", 1, base); + writestruct(wd, DATA, Base, 1, base); base = base->next; } tos = sce->toolsettings; - writestruct(wd, DATA, "ToolSettings", 1, tos); + writestruct(wd, DATA, ToolSettings, 1, tos); if (tos->vpaint) { - writestruct(wd, DATA, "VPaint", 1, tos->vpaint); + writestruct(wd, DATA, VPaint, 1, tos->vpaint); write_paint(wd, &tos->vpaint->paint); } if (tos->wpaint) { - writestruct(wd, DATA, "VPaint", 1, tos->wpaint); + writestruct(wd, DATA, VPaint, 1, tos->wpaint); write_paint(wd, &tos->wpaint->paint); } if (tos->sculpt) { - writestruct(wd, DATA, "Sculpt", 1, tos->sculpt); + writestruct(wd, DATA, Sculpt, 1, tos->sculpt); write_paint(wd, &tos->sculpt->paint); } if (tos->uvsculpt) { - writestruct(wd, DATA, "UvSculpt", 1, tos->uvsculpt); + writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt); write_paint(wd, &tos->uvsculpt->paint); } @@ -2618,7 +2672,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) ed = sce->ed; if (ed) { - writestruct(wd, DATA, "Editing", 1, ed); + writestruct(wd, DATA, Editing, 1, ed); /* reset write flags too */ @@ -2627,7 +2681,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->strip) { seq->strip->done = false; } - writestruct(wd, DATA, "Sequence", 1, seq); + writestruct(wd, DATA, Sequence, 1, seq); } SEQ_END @@ -2639,49 +2693,49 @@ static void write_scenes(WriteData *wd, ListBase *scebase) if (seq->effectdata) { switch (seq->type) { case SEQ_TYPE_COLOR: - writestruct(wd, DATA, "SolidColorVars", 1, seq->effectdata); + writestruct(wd, DATA, SolidColorVars, 1, seq->effectdata); break; case SEQ_TYPE_SPEED: - writestruct(wd, DATA, "SpeedControlVars", 1, seq->effectdata); + writestruct(wd, DATA, SpeedControlVars, 1, seq->effectdata); break; case SEQ_TYPE_WIPE: - writestruct(wd, DATA, "WipeVars", 1, seq->effectdata); + writestruct(wd, DATA, WipeVars, 1, seq->effectdata); break; case SEQ_TYPE_GLOW: - writestruct(wd, DATA, "GlowVars", 1, seq->effectdata); + writestruct(wd, DATA, GlowVars, 1, seq->effectdata); break; case SEQ_TYPE_TRANSFORM: - writestruct(wd, DATA, "TransformVars", 1, seq->effectdata); + writestruct(wd, DATA, TransformVars, 1, seq->effectdata); break; case SEQ_TYPE_GAUSSIAN_BLUR: - writestruct(wd, DATA, "GaussianBlurVars", 1, seq->effectdata); + writestruct(wd, DATA, GaussianBlurVars, 1, seq->effectdata); break; case SEQ_TYPE_TEXT: - writestruct(wd, DATA, "TextVars", 1, seq->effectdata); + writestruct(wd, DATA, TextVars, 1, seq->effectdata); break; } } - writestruct(wd, DATA, "Stereo3dFormat", 1, seq->stereo3d_format); + writestruct(wd, DATA, Stereo3dFormat, 1, seq->stereo3d_format); strip = seq->strip; - writestruct(wd, DATA, "Strip", 1, strip); + writestruct(wd, DATA, Strip, 1, strip); if (seq->flag & SEQ_USE_CROP && strip->crop) { - writestruct(wd, DATA, "StripCrop", 1, strip->crop); + writestruct(wd, DATA, StripCrop, 1, strip->crop); } if (seq->flag & SEQ_USE_TRANSFORM && strip->transform) { - writestruct(wd, DATA, "StripTransform", 1, strip->transform); + writestruct(wd, DATA, StripTransform, 1, strip->transform); } if (seq->flag & SEQ_USE_PROXY && strip->proxy) { - writestruct(wd, DATA, "StripProxy", 1, strip->proxy); + writestruct(wd, DATA, StripProxy, 1, strip->proxy); } if (seq->type == SEQ_TYPE_IMAGE) { - writestruct(wd, DATA, "StripElem", + writestruct(wd, DATA, StripElem, MEM_allocN_len(strip->stripdata) / sizeof(struct StripElem), strip->stripdata); } else if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD)) { - writestruct(wd, DATA, "StripElem", 1, strip->stripdata); + writestruct(wd, DATA, StripElem, 1, strip->stripdata); } strip->done = true; @@ -2697,12 +2751,12 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* new; meta stack too, even when its nasty restore code */ for (ms = ed->metastack.first; ms; ms = ms->next) { - writestruct(wd, DATA, "MetaStack", 1, ms); + writestruct(wd, DATA, MetaStack, 1, ms); } } if (sce->r.avicodecdata) { - writestruct(wd, DATA, "AviCodecData", 1, sce->r.avicodecdata); + writestruct(wd, DATA, AviCodecData, 1, sce->r.avicodecdata); if (sce->r.avicodecdata->lpFormat) { writedata(wd, DATA, sce->r.avicodecdata->cbFormat, sce->r.avicodecdata->lpFormat); } @@ -2712,7 +2766,7 @@ static void write_scenes(WriteData *wd, ListBase *scebase) } if (sce->r.qtcodecdata) { - writestruct(wd, DATA, "QuicktimeCodecData", 1, sce->r.qtcodecdata); + writestruct(wd, DATA, QuicktimeCodecData, 1, sce->r.qtcodecdata); if (sce->r.qtcodecdata->cdParms) { writedata(wd, DATA, sce->r.qtcodecdata->cdSize, sce->r.qtcodecdata->cdParms); } @@ -2723,31 +2777,31 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* writing dynamic list of TimeMarkers to the blend file */ for (marker = sce->markers.first; marker; marker = marker->next) { - writestruct(wd, DATA, "TimeMarker", 1, marker); + writestruct(wd, DATA, TimeMarker, 1, marker); } /* writing dynamic list of TransformOrientations to the blend file */ for (ts = sce->transform_spaces.first; ts; ts = ts->next) { - writestruct(wd, DATA, "TransformOrientation", 1, ts); + writestruct(wd, DATA, TransformOrientation, 1, ts); } for (srl = sce->r.layers.first; srl; srl = srl->next) { - writestruct(wd, DATA, "SceneRenderLayer", 1, srl); + writestruct(wd, DATA, SceneRenderLayer, 1, srl); for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) { - writestruct(wd, DATA, "FreestyleModuleConfig", 1, fmc); + writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc); } for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) { - writestruct(wd, DATA, "FreestyleLineSet", 1, fls); + writestruct(wd, DATA, FreestyleLineSet, 1, fls); } } /* writing MultiView to the blend file */ for (srv = sce->r.views.first; srv; srv = srv->next) { - writestruct(wd, DATA, "SceneRenderView", 1, srv); + writestruct(wd, DATA, SceneRenderView, 1, srv); } if (sce->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, sce->nodetree); + writestruct(wd, DATA, bNodeTree, 1, sce->nodetree); write_nodetree(wd, sce->nodetree); } @@ -2755,8 +2809,8 @@ static void write_scenes(WriteData *wd, ListBase *scebase) /* writing RigidBodyWorld data to the blend file */ if (sce->rigidbody_world) { - writestruct(wd, DATA, "RigidBodyWorld", 1, sce->rigidbody_world); - writestruct(wd, DATA, "EffectorWeights", 1, sce->rigidbody_world->effector_weights); + writestruct(wd, DATA, RigidBodyWorld, 1, sce->rigidbody_world); + writestruct(wd, DATA, EffectorWeights, 1, sce->rigidbody_world->effector_weights); write_pointcaches(wd, &(sce->rigidbody_world->ptcaches)); } @@ -2779,7 +2833,7 @@ static void write_gpencils(WriteData *wd, ListBase *lb) for (gpd = lb->first; gpd; gpd = gpd->id.next) { if (gpd->id.us > 0 || wd->current) { /* write gpd data block to file */ - writestruct(wd, ID_GD, "bGPdata", 1, gpd); + writestruct(wd, ID_GD, bGPdata, 1, gpd); write_iddata(wd, &gpd->id); if (gpd->adt) { @@ -2787,17 +2841,17 @@ static void write_gpencils(WriteData *wd, ListBase *lb) } /* write grease-pencil layers to file */ - writelist(wd, DATA, "bGPDlayer", &gpd->layers); + writelist(wd, DATA, bGPDlayer, &gpd->layers); for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* write this layer's frames to file */ - writelist(wd, DATA, "bGPDframe", &gpl->frames); + writelist(wd, DATA, bGPDframe, &gpl->frames); for (gpf = gpl->frames.first; gpf; gpf = gpf->next) { /* write strokes */ - writelist(wd, DATA, "bGPDstroke", &gpf->strokes); + writelist(wd, DATA, bGPDstroke, &gpf->strokes); for (gps = gpf->strokes.first; gps; gps = gps->next) { - writestruct(wd, DATA, "bGPDspoint", gps->totpoints, gps->points); + writestruct(wd, DATA, bGPDspoint, gps->totpoints, gps->points); } } } @@ -2811,32 +2865,32 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) wmWindow *win; for (wm = lb->first; wm; wm = wm->id.next) { - writestruct(wd, ID_WM, "wmWindowManager", 1, wm); + writestruct(wd, ID_WM, wmWindowManager, 1, wm); write_iddata(wd, &wm->id); for (win = wm->windows.first; win; win = win->next) { - writestruct(wd, DATA, "wmWindow", 1, win); - writestruct(wd, DATA, "Stereo3dFormat", 1, win->stereo3d_format); + writestruct(wd, DATA, wmWindow, 1, win); + writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); } } } static void write_region(WriteData *wd, ARegion *ar, int spacetype) { - writestruct(wd, DATA, "ARegion", 1, ar); + writestruct(wd, DATA, ARegion, 1, ar); if (ar->regiondata) { switch (spacetype) { case SPACE_VIEW3D: if (ar->regiontype == RGN_TYPE_WINDOW) { RegionView3D *rv3d = ar->regiondata; - writestruct(wd, DATA, "RegionView3D", 1, rv3d); + writestruct(wd, DATA, RegionView3D, 1, rv3d); if (rv3d->localvd) { - writestruct(wd, DATA, "RegionView3D", 1, rv3d->localvd); + writestruct(wd, DATA, RegionView3D, 1, rv3d->localvd); } if (rv3d->clipbb) { - writestruct(wd, DATA, "BoundBox", 1, rv3d->clipbb); + writestruct(wd, DATA, BoundBox, 1, rv3d->clipbb); } } @@ -2851,7 +2905,7 @@ static void write_region(WriteData *wd, ARegion *ar, int spacetype) static void write_uilist(WriteData *wd, uiList *ui_list) { - writestruct(wd, DATA, "uiList", 1, ui_list); + writestruct(wd, DATA, uiList, 1, ui_list); if (ui_list->properties) { IDP_WriteProperty(ui_list->properties, wd); @@ -2876,10 +2930,10 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) /* temporarily replace mempool-treestore by flat-treestore */ so->treestore = (BLI_mempool *)ts_flat; - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); - writestruct(wd, DATA, "TreeStore", 1, ts_flat); - writestruct(wd, DATA, "TreeStoreElem", elems, data); + writestruct(wd, DATA, TreeStore, 1, ts_flat); + writestruct(wd, DATA, TreeStoreElem, elems, data); /* we do not free the pointers immediately, because if we have multiple * outliners in a screen we might get the same address on the next @@ -2890,14 +2944,14 @@ static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) } else { so->treestore = NULL; - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); } /* restore old treestore */ so->treestore = ts; } else { - writestruct(wd, DATA, "SpaceOops", 1, so); + writestruct(wd, DATA, SpaceOops, 1, so); } } @@ -2914,16 +2968,16 @@ static void write_screens(WriteData *wd, ListBase *scrbase) /* write LibData */ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */ - writestruct(wd, ID_SCRN, "Screen", 1, sc); + writestruct(wd, ID_SCRN, bScreen, 1, sc); write_iddata(wd, &sc->id); /* direct data */ for (sv = sc->vertbase.first; sv; sv = sv->next) { - writestruct(wd, DATA, "ScrVert", 1, sv); + writestruct(wd, DATA, ScrVert, 1, sv); } for (se = sc->edgebase.first; se; se = se->next) { - writestruct(wd, DATA, "ScrEdge", 1, se); + writestruct(wd, DATA, ScrEdge, 1, se); } for (sa = sc->areabase.first; sa; sa = sa->next) { @@ -2934,17 +2988,17 @@ static void write_screens(WriteData *wd, ListBase *scrbase) PanelCategoryStack *pc_act; ARegion *ar; - writestruct(wd, DATA, "ScrArea", 1, sa); + writestruct(wd, DATA, ScrArea, 1, sa); for (ar = sa->regionbase.first; ar; ar = ar->next) { write_region(wd, ar, sa->spacetype); for (pa = ar->panels.first; pa; pa = pa->next) { - writestruct(wd, DATA, "Panel", 1, pa); + writestruct(wd, DATA, Panel, 1, pa); } for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) { - writestruct(wd, DATA, "PanelCategoryStack", 1, pc_act); + writestruct(wd, DATA, PanelCategoryStack, 1, pc_act); } for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) { @@ -2952,7 +3006,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase) } for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) { - writestruct(wd, DATA, "uiPreview", 1, ui_preview); + writestruct(wd, DATA, uiPreview, 1, ui_preview); } } @@ -2965,19 +3019,19 @@ static void write_screens(WriteData *wd, ListBase *scrbase) if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; BGpic *bgpic; - writestruct(wd, DATA, "View3D", 1, v3d); + writestruct(wd, DATA, View3D, 1, v3d); for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { - writestruct(wd, DATA, "BGpic", 1, bgpic); + writestruct(wd, DATA, BGpic, 1, bgpic); } if (v3d->localvd) { - writestruct(wd, DATA, "View3D", 1, v3d->localvd); + writestruct(wd, DATA, View3D, 1, v3d->localvd); } if (v3d->fx_settings.ssao) { - writestruct(wd, DATA, "GPUSSAOSettings", 1, v3d->fx_settings.ssao); + writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao); } if (v3d->fx_settings.dof) { - writestruct(wd, DATA, "GPUDOFSettings", 1, v3d->fx_settings.dof); + writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof); } } else if (sl->spacetype == SPACE_IPO) { @@ -2987,68 +3041,68 @@ static void write_screens(WriteData *wd, ListBase *scrbase) /* temporarily disable ghost curves when saving */ sipo->ghostCurves.first = sipo->ghostCurves.last = NULL; - writestruct(wd, DATA, "SpaceIpo", 1, sl); + writestruct(wd, DATA, SpaceIpo, 1, sl); if (sipo->ads) { - writestruct(wd, DATA, "bDopeSheet", 1, sipo->ads); + writestruct(wd, DATA, bDopeSheet, 1, sipo->ads); } /* reenable ghost curves */ sipo->ghostCurves = tmpGhosts; } else if (sl->spacetype == SPACE_BUTS) { - writestruct(wd, DATA, "SpaceButs", 1, sl); + writestruct(wd, DATA, SpaceButs, 1, sl); } else if (sl->spacetype == SPACE_FILE) { SpaceFile *sfile = (SpaceFile *)sl; - writestruct(wd, DATA, "SpaceFile", 1, sl); + writestruct(wd, DATA, SpaceFile, 1, sl); if (sfile->params) { - writestruct(wd, DATA, "FileSelectParams", 1, sfile->params); + writestruct(wd, DATA, FileSelectParams, 1, sfile->params); } } else if (sl->spacetype == SPACE_SEQ) { - writestruct(wd, DATA, "SpaceSeq", 1, sl); + writestruct(wd, DATA, SpaceSeq, 1, sl); } else if (sl->spacetype == SPACE_OUTLINER) { SpaceOops *so = (SpaceOops *)sl; write_soops(wd, so, &tmp_mem_list); } else if (sl->spacetype == SPACE_IMAGE) { - writestruct(wd, DATA, "SpaceImage", 1, sl); + writestruct(wd, DATA, SpaceImage, 1, sl); } else if (sl->spacetype == SPACE_TEXT) { - writestruct(wd, DATA, "SpaceText", 1, sl); + writestruct(wd, DATA, SpaceText, 1, sl); } else if (sl->spacetype == SPACE_SCRIPT) { SpaceScript *scr = (SpaceScript *)sl; scr->but_refs = NULL; - writestruct(wd, DATA, "SpaceScript", 1, sl); + writestruct(wd, DATA, SpaceScript, 1, sl); } else if (sl->spacetype == SPACE_ACTION) { - writestruct(wd, DATA, "SpaceAction", 1, sl); + writestruct(wd, DATA, SpaceAction, 1, sl); } else if (sl->spacetype == SPACE_NLA) { SpaceNla *snla = (SpaceNla *)sl; - writestruct(wd, DATA, "SpaceNla", 1, snla); + writestruct(wd, DATA, SpaceNla, 1, snla); if (snla->ads) { - writestruct(wd, DATA, "bDopeSheet", 1, snla->ads); + writestruct(wd, DATA, bDopeSheet, 1, snla->ads); } } else if (sl->spacetype == SPACE_TIME) { - writestruct(wd, DATA, "SpaceTime", 1, sl); + writestruct(wd, DATA, SpaceTime, 1, sl); } else if (sl->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)sl; bNodeTreePath *path; - writestruct(wd, DATA, "SpaceNode", 1, snode); + writestruct(wd, DATA, SpaceNode, 1, snode); for (path = snode->treepath.first; path; path = path->next) { - writestruct(wd, DATA, "bNodeTreePath", 1, path); + writestruct(wd, DATA, bNodeTreePath, 1, path); } } else if (sl->spacetype == SPACE_LOGIC) { - writestruct(wd, DATA, "SpaceLogic", 1, sl); + writestruct(wd, DATA, SpaceLogic, 1, sl); } else if (sl->spacetype == SPACE_CONSOLE) { SpaceConsole *con = (SpaceConsole *)sl; @@ -3056,20 +3110,20 @@ static void write_screens(WriteData *wd, ListBase *scrbase) for (cl = con->history.first; cl; cl = cl->next) { /* 'len_alloc' is invalid on write, set from 'len' on read */ - writestruct(wd, DATA, "ConsoleLine", 1, cl); + writestruct(wd, DATA, ConsoleLine, 1, cl); writedata(wd, DATA, cl->len + 1, cl->line); } - writestruct(wd, DATA, "SpaceConsole", 1, sl); + writestruct(wd, DATA, SpaceConsole, 1, sl); } else if (sl->spacetype == SPACE_USERPREF) { - writestruct(wd, DATA, "SpaceUserPref", 1, sl); + writestruct(wd, DATA, SpaceUserPref, 1, sl); } else if (sl->spacetype == SPACE_CLIP) { - writestruct(wd, DATA, "SpaceClip", 1, sl); + writestruct(wd, DATA, SpaceClip, 1, sl); } else if (sl->spacetype == SPACE_INFO) { - writestruct(wd, DATA, "SpaceInfo", 1, sl); + writestruct(wd, DATA, SpaceInfo, 1, sl); } sl = sl->next; @@ -3091,7 +3145,7 @@ static void write_bone(WriteData *wd, Bone *bone) bone->size[0] = bone->size[1] = bone->size[2] = 1.0f; /* Write this bone */ - writestruct(wd, DATA, "Bone", 1, bone); + writestruct(wd, DATA, Bone, 1, bone); /* Write ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ @@ -3113,7 +3167,7 @@ static void write_armatures(WriteData *wd, ListBase *idbase) arm = idbase->first; while (arm) { if (arm->id.us > 0 || wd->current) { - writestruct(wd, ID_AR, "bArmature", 1, arm); + writestruct(wd, ID_AR, bArmature, 1, arm); write_iddata(wd, &arm->id); if (arm->adt) { @@ -3146,7 +3200,7 @@ static void write_texts(WriteData *wd, ListBase *idbase) } /* write LibData */ - writestruct(wd, ID_TXT, "Text", 1, text); + writestruct(wd, ID_TXT, Text, 1, text); write_iddata(wd, &text->id); if (text->name) { @@ -3157,7 +3211,7 @@ static void write_texts(WriteData *wd, ListBase *idbase) /* now write the text data, in two steps for optimization in the readfunction */ tmp = text->lines.first; while (tmp) { - writestruct(wd, DATA, "TextLine", 1, tmp); + writestruct(wd, DATA, TextLine, 1, tmp); tmp = tmp->next; } @@ -3184,7 +3238,7 @@ static void write_speakers(WriteData *wd, ListBase *idbase) while (spk) { if (spk->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_SPK, "Speaker", 1, spk); + writestruct(wd, ID_SPK, Speaker, 1, spk); write_iddata(wd, &spk->id); if (spk->adt) { @@ -3205,12 +3259,12 @@ static void write_sounds(WriteData *wd, ListBase *idbase) while (sound) { if (sound->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_SO, "bSound", 1, sound); + writestruct(wd, ID_SO, bSound, 1, sound); write_iddata(wd, &sound->id); if (sound->packedfile) { pf = sound->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); } } @@ -3229,14 +3283,14 @@ static void write_groups(WriteData *wd, ListBase *idbase) for (group = idbase->first; group; group = group->id.next) { if (group->id.us > 0 || wd->current) { /* write LibData */ - writestruct(wd, ID_GR, "Group", 1, group); + writestruct(wd, ID_GR, Group, 1, group); write_iddata(wd, &group->id); write_previews(wd, group->preview); go = group->gobject.first; while (go) { - writestruct(wd, DATA, "GroupObject", 1, go); + writestruct(wd, DATA, GroupObject, 1, go); go = go->next; } } @@ -3249,7 +3303,7 @@ static void write_nodetrees(WriteData *wd, ListBase *idbase) for (ntree = idbase->first; ntree; ntree = ntree->id.next) { if (ntree->id.us > 0 || wd->current) { - writestruct(wd, ID_NT, "bNodeTree", 1, ntree); + writestruct(wd, ID_NT, bNodeTree, 1, ntree); /* Note that trees directly used by other IDs (materials etc.) are not 'real' ID, they cannot * be linked, etc., so we write actual id data here only, for 'real' ID trees. */ write_iddata(wd, &ntree->id); @@ -3335,14 +3389,14 @@ static void write_brushes(WriteData *wd, ListBase *idbase) for (brush = idbase->first; brush; brush = brush->id.next) { if (brush->id.us > 0 || wd->current) { - writestruct(wd, ID_BR, "Brush", 1, brush); + writestruct(wd, ID_BR, Brush, 1, brush); write_iddata(wd, &brush->id); if (brush->curve) { write_curvemapping(wd, brush->curve); } if (brush->gradient) { - writestruct(wd, DATA, "ColorBand", 1, brush->gradient); + writestruct(wd, DATA, ColorBand, 1, brush->gradient); } } } @@ -3355,11 +3409,11 @@ static void write_palettes(WriteData *wd, ListBase *idbase) for (palette = idbase->first; palette; palette = palette->id.next) { if (palette->id.us > 0 || wd->current) { PaletteColor *color; - writestruct(wd, ID_PAL, "Palette", 1, palette); + writestruct(wd, ID_PAL, Palette, 1, palette); write_iddata(wd, &palette->id); for (color = palette->colors.first; color; color = color->next) { - writestruct(wd, DATA, "PaletteColor", 1, color); + writestruct(wd, DATA, PaletteColor, 1, color); } } } @@ -3371,10 +3425,10 @@ static void write_paintcurves(WriteData *wd, ListBase *idbase) for (pc = idbase->first; pc; pc = pc->id.next) { if (pc->id.us > 0 || wd->current) { - writestruct(wd, ID_PC, "PaintCurve", 1, pc); + writestruct(wd, ID_PC, PaintCurve, 1, pc); write_iddata(wd, &pc->id); - writestruct(wd, DATA, "PaintCurvePoint", pc->tot_points, pc->points); + writestruct(wd, DATA, PaintCurvePoint, pc->tot_points, pc->points); } } } @@ -3385,10 +3439,10 @@ static void write_movieTracks(WriteData *wd, ListBase *tracks) track = tracks->first; while (track) { - writestruct(wd, DATA, "MovieTrackingTrack", 1, track); + writestruct(wd, DATA, MovieTrackingTrack, 1, track); if (track->markers) { - writestruct(wd, DATA, "MovieTrackingMarker", track->markersnr, track->markers); + writestruct(wd, DATA, MovieTrackingMarker, track->markersnr, track->markers); } track = track->next; @@ -3403,17 +3457,17 @@ static void write_moviePlaneTracks(WriteData *wd, ListBase *plane_tracks_base) plane_track; plane_track = plane_track->next) { - writestruct(wd, DATA, "MovieTrackingPlaneTrack", 1, plane_track); + writestruct(wd, DATA, MovieTrackingPlaneTrack, 1, plane_track); writedata(wd, DATA, sizeof(MovieTrackingTrack *) * plane_track->point_tracksnr, plane_track->point_tracks); - writestruct(wd, DATA, "MovieTrackingPlaneMarker", plane_track->markersnr, plane_track->markers); + writestruct(wd, DATA, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers); } } static void write_movieReconstruction(WriteData *wd, MovieTrackingReconstruction *reconstruction) { if (reconstruction->camnr) { - writestruct(wd, DATA, "MovieReconstructedCamera", reconstruction->camnr, reconstruction->cameras); + writestruct(wd, DATA, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras); } } @@ -3427,7 +3481,7 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object; - writestruct(wd, ID_MC, "MovieClip", 1, clip); + writestruct(wd, ID_MC, MovieClip, 1, clip); write_iddata(wd, &clip->id); if (clip->adt) { @@ -3440,7 +3494,7 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) object = tracking->objects.first; while (object) { - writestruct(wd, DATA, "MovieTrackingObject", 1, object); + writestruct(wd, DATA, MovieTrackingObject, 1, object); write_movieTracks(wd, &object->tracks); write_moviePlaneTracks(wd, &object->plane_tracks); @@ -3466,7 +3520,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) if (mask->id.us > 0 || wd->current) { MaskLayer *masklay; - writestruct(wd, ID_MSK, "Mask", 1, mask); + writestruct(wd, ID_MSK, Mask, 1, mask); write_iddata(wd, &mask->id); if (mask->adt) { @@ -3477,7 +3531,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) MaskSpline *spline; MaskLayerShape *masklay_shape; - writestruct(wd, DATA, "MaskLayer", 1, masklay); + writestruct(wd, DATA, MaskLayer, 1, masklay); for (spline = masklay->splines.first; spline; spline = spline->next) { int i; @@ -3485,8 +3539,8 @@ static void write_masks(WriteData *wd, ListBase *idbase) void *points_deform = spline->points_deform; spline->points_deform = NULL; - writestruct(wd, DATA, "MaskSpline", 1, spline); - writestruct(wd, DATA, "MaskSplinePoint", spline->tot_point, spline->points); + writestruct(wd, DATA, MaskSpline, 1, spline); + writestruct(wd, DATA, MaskSplinePoint, spline->tot_point, spline->points); spline->points_deform = points_deform; @@ -3494,7 +3548,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) MaskSplinePoint *point = &spline->points[i]; if (point->tot_uw) { - writestruct(wd, DATA, "MaskSplinePointUW", point->tot_uw, point->uw); + writestruct(wd, DATA, MaskSplinePointUW, point->tot_uw, point->uw); } } } @@ -3503,7 +3557,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) masklay_shape; masklay_shape = masklay_shape->next) { - writestruct(wd, DATA, "MaskLayerShape", 1, masklay_shape); + writestruct(wd, DATA, MaskLayerShape, 1, masklay_shape); writedata(wd, DATA, masklay_shape->tot_vert * sizeof(float) * MASK_OBJECT_SHAPE_ELEM_SIZE, masklay_shape->data); @@ -3521,64 +3575,64 @@ static void write_masks(WriteData *wd, ListBase *idbase) static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleColorModifier_AlongStroke"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleColorModifier_DistanceFromCamera"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleColorModifier_DistanceFromObject"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromObject); break; case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleColorModifier_Material"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Material); break; case LS_MODIFIER_TANGENT: - struct_name = "LineStyleColorModifier_Tangent"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Tangent); break; case LS_MODIFIER_NOISE: - struct_name = "LineStyleColorModifier_Noise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Noise); break; case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleColorModifier_CreaseAngle"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_CreaseAngle); break; case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleColorModifier_Curvature_3D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); break; default: - struct_name = "LineStyleColorModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); break; case LS_MODIFIER_MATERIAL: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Material *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Material *)m)->color_ramp); break; case LS_MODIFIER_TANGENT: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Tangent *)m)->color_ramp); break; case LS_MODIFIER_NOISE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Noise *)m)->color_ramp); break; case LS_MODIFIER_CREASE_ANGLE: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_CreaseAngle *)m)->color_ramp); break; case LS_MODIFIER_CURVATURE_3D: - writestruct(wd, DATA, "ColorBand", 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); + writestruct(wd, DATA, ColorBand, 1, ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp); break; } } @@ -3587,38 +3641,38 @@ static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleAlphaModifier_AlongStroke"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleAlphaModifier_DistanceFromCamera"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleAlphaModifier_DistanceFromObject"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromObject); break; case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleAlphaModifier_Material"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Material); break; case LS_MODIFIER_TANGENT: - struct_name = "LineStyleAlphaModifier_Tangent"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Tangent); break; case LS_MODIFIER_NOISE: - struct_name = "LineStyleAlphaModifier_Noise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Noise); break; case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleAlphaModifier_CreaseAngle"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_CreaseAngle); break; case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleAlphaModifier_Curvature_3D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); break; default: - struct_name = "LineStyleAlphaModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { @@ -3653,41 +3707,41 @@ static void write_linestyle_alpha_modifiers(WriteData *wd, ListBase *modifiers) static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_ALONG_STROKE: - struct_name = "LineStyleThicknessModifier_AlongStroke"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); break; case LS_MODIFIER_DISTANCE_FROM_CAMERA: - struct_name = "LineStyleThicknessModifier_DistanceFromCamera"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); break; case LS_MODIFIER_DISTANCE_FROM_OBJECT: - struct_name = "LineStyleThicknessModifier_DistanceFromObject"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromObject); break; case LS_MODIFIER_MATERIAL: - struct_name = "LineStyleThicknessModifier_Material"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Material); break; case LS_MODIFIER_CALLIGRAPHY: - struct_name = "LineStyleThicknessModifier_Calligraphy"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Calligraphy); break; case LS_MODIFIER_TANGENT: - struct_name = "LineStyleThicknessModifier_Tangent"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Tangent); break; case LS_MODIFIER_NOISE: - struct_name = "LineStyleThicknessModifier_Noise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Noise); break; case LS_MODIFIER_CREASE_ANGLE: - struct_name = "LineStyleThicknessModifier_CreaseAngle"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_CreaseAngle); break; case LS_MODIFIER_CURVATURE_3D: - struct_name = "LineStyleThicknessModifier_Curvature_3D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); break; default: - struct_name = "LineStyleThicknessModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } for (m = modifiers->first; m; m = m->next) { switch (m->type) { @@ -3719,56 +3773,56 @@ static void write_linestyle_thickness_modifiers(WriteData *wd, ListBase *modifie static void write_linestyle_geometry_modifiers(WriteData *wd, ListBase *modifiers) { LineStyleModifier *m; - const char *struct_name; for (m = modifiers->first; m; m = m->next) { + int struct_nr; switch (m->type) { case LS_MODIFIER_SAMPLING: - struct_name = "LineStyleGeometryModifier_Sampling"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); break; case LS_MODIFIER_BEZIER_CURVE: - struct_name = "LineStyleGeometryModifier_BezierCurve"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); break; case LS_MODIFIER_SINUS_DISPLACEMENT: - struct_name = "LineStyleGeometryModifier_SinusDisplacement"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SinusDisplacement); break; case LS_MODIFIER_SPATIAL_NOISE: - struct_name = "LineStyleGeometryModifier_SpatialNoise"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_SpatialNoise); break; case LS_MODIFIER_PERLIN_NOISE_1D: - struct_name = "LineStyleGeometryModifier_PerlinNoise1D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise1D); break; case LS_MODIFIER_PERLIN_NOISE_2D: - struct_name = "LineStyleGeometryModifier_PerlinNoise2D"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_PerlinNoise2D); break; case LS_MODIFIER_BACKBONE_STRETCHER: - struct_name = "LineStyleGeometryModifier_BackboneStretcher"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BackboneStretcher); break; case LS_MODIFIER_TIP_REMOVER: - struct_name = "LineStyleGeometryModifier_TipRemover"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_TipRemover); break; case LS_MODIFIER_POLYGONIZATION: - struct_name = "LineStyleGeometryModifier_Polygonalization"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Polygonalization); break; case LS_MODIFIER_GUIDING_LINES: - struct_name = "LineStyleGeometryModifier_GuidingLines"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_GuidingLines); break; case LS_MODIFIER_BLUEPRINT: - struct_name = "LineStyleGeometryModifier_Blueprint"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Blueprint); break; case LS_MODIFIER_2D_OFFSET: - struct_name = "LineStyleGeometryModifier_2DOffset"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DOffset); break; case LS_MODIFIER_2D_TRANSFORM: - struct_name = "LineStyleGeometryModifier_2DTransform"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_2DTransform); break; case LS_MODIFIER_SIMPLIFICATION: - struct_name = "LineStyleGeometryModifier_Simplification"; + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Simplification); break; default: - struct_name = "LineStyleGeometryModifier"; /* this should not happen */ + struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ } - writestruct(wd, DATA, struct_name, 1, m); + writestruct_nr(wd, DATA, struct_nr, 1, m); } } @@ -3779,7 +3833,7 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) for (linestyle = idbase->first; linestyle; linestyle = linestyle->id.next) { if (linestyle->id.us > 0 || wd->current) { - writestruct(wd, ID_LS, "FreestyleLineStyle", 1, linestyle); + writestruct(wd, ID_LS, FreestyleLineStyle, 1, linestyle); write_iddata(wd, &linestyle->id); if (linestyle->adt) { @@ -3792,11 +3846,11 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) write_linestyle_geometry_modifiers(wd, &linestyle->geometry_modifiers); for (a = 0; a < MAX_MTEX; a++) { if (linestyle->mtex[a]) { - writestruct(wd, DATA, "MTex", 1, linestyle->mtex[a]); + writestruct(wd, DATA, MTex, 1, linestyle->mtex[a]); } } if (linestyle->nodetree) { - writestruct(wd, DATA, "bNodeTree", 1, linestyle->nodetree); + writestruct(wd, DATA, bNodeTree, 1, linestyle->nodetree); write_nodetree(wd, linestyle->nodetree); } } @@ -3838,12 +3892,12 @@ static void write_libraries(WriteData *wd, Main *main) /* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the] * quit.blend and temp saves */ if (found_one) { - writestruct(wd, ID_LI, "Library", 1, main->curlib); + writestruct(wd, ID_LI, Library, 1, main->curlib); write_iddata(wd, &main->curlib->id); if (main->curlib->packedfile) { PackedFile *pf = main->curlib->packedfile; - writestruct(wd, DATA, "PackedFile", 1, pf); + writestruct(wd, DATA, PackedFile, 1, pf); writedata(wd, DATA, pf->size, pf->data); if (wd->current == NULL) { printf("write packed .blend: %s\n", main->curlib->name); @@ -3858,7 +3912,7 @@ static void write_libraries(WriteData *wd, Main *main) "but is flagged as directly linked", id->name, main->curlib->filepath); BLI_assert(0); } - writestruct(wd, ID_ID, "ID", 1, id); + writestruct(wd, ID_ID, ID, 1, id); } } } @@ -3910,7 +3964,7 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar) fg.build_commit_timestamp = 0; BLI_strncpy(fg.build_hash, "unknown", sizeof(fg.build_hash)); #endif - writestruct(wd, GLOB, "FileGlobal", 1, &fg); + writestruct(wd, GLOB, FileGlobal, 1, &fg); } /* preview image, first 2 values are width and height -- cgit v1.2.3 From 0d7817d1a46adebdad4cb68ea54169720e86068d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Jun 2016 21:00:00 +1000 Subject: Cleanup: use bool for writefile --- source/blender/blenloader/intern/writefile.c | 30 ++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 9cf32e1fb73..2c8bb92ac4b 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -308,7 +308,8 @@ typedef struct { unsigned char *buf; MemFile *compare, *current; - int tot, count, error; + int tot, count; + bool error; /* Wrap writing, so we can use zlib or * other compression types later, see: G_FILE_COMPRESS @@ -316,7 +317,7 @@ typedef struct { WriteWrap *ww; #ifdef USE_BMESH_SAVE_AS_COMPAT - char use_mesh_compat; /* option to save with older mesh format */ + bool use_mesh_compat; /* option to save with older mesh format */ #endif } WriteData; @@ -349,7 +350,7 @@ static void writedata_do_write(WriteData *wd, const void *mem, int memlen) } else { if (wd->ww->write(wd->ww, mem, memlen) != memlen) { - wd->error = 1; + wd->error = true; } } } @@ -448,16 +449,14 @@ static WriteData *bgnwrite(WriteWrap *ww, MemFile *compare, MemFile *current) * \return unknown global variable otherwise * \warning Talks to other functions with global parameters */ -static int endwrite(WriteData *wd) +static bool endwrite(WriteData *wd) { - int err; - if (wd->count) { writedata_do_write(wd, wd->buf, wd->count); wd->count = 0; } - err = wd->error; + const bool err = wd->error; writedata_free(wd); return err; @@ -2179,7 +2178,7 @@ static void write_customdata( static void write_meshes(WriteData *wd, ListBase *idbase) { Mesh *mesh; - int save_for_old_blender = 0; + bool save_for_old_blender = false; #ifdef USE_BMESH_SAVE_AS_COMPAT save_for_old_blender = wd->use_mesh_compat; /* option to save with older mesh format */ @@ -3979,11 +3978,11 @@ static void write_thumb(WriteData *wd, const BlendThumbnail *thumb) } /* if MemFile * there's filesave to memory */ -static int write_file_handle( +static bool write_file_handle( Main *mainvar, WriteWrap *ww, MemFile *compare, MemFile *current, - int write_user_block, int write_flags, const BlendThumbnail *thumb) + int write_flags, const BlendThumbnail *thumb) { BHead bhead; ListBase mainlist; @@ -4050,7 +4049,7 @@ static int write_file_handle( write_linestyles(wd, &mainvar->linestyle); write_libraries(wd, mainvar->next); - if (write_user_block) { + if (write_flags & G_FILE_USERPREFS) { write_userdef(wd); } @@ -4128,7 +4127,6 @@ bool BLO_write_file( ReportList *reports, const BlendThumbnail *thumb) { char tempname[FILE_MAX + 1]; - int err, write_user_block; eWriteWrapType ww_type; WriteWrap ww; @@ -4183,15 +4181,13 @@ bool BLO_write_file( } } - write_user_block = write_flags & G_FILE_USERPREFS; - if (write_flags & G_FILE_RELATIVE_REMAP) { /* note, making relative to something OTHER then G.main->name */ BKE_bpath_relative_convert(mainvar, filepath, NULL); } /* actual file writing */ - err = write_file_handle(mainvar, &ww, NULL, NULL, write_user_block, write_flags, thumb); + const bool err = write_file_handle(mainvar, &ww, NULL, NULL, write_flags, thumb); ww.close(&ww); @@ -4230,9 +4226,9 @@ bool BLO_write_file( */ bool BLO_write_file_mem(Main *mainvar, MemFile *compare, MemFile *current, int write_flags) { - int err; + write_flags &= ~G_FILE_USERPREFS; - err = write_file_handle(mainvar, NULL, compare, current, 0, write_flags, NULL); + const bool err = write_file_handle(mainvar, NULL, compare, current, write_flags, NULL); return (err == 0); } -- cgit v1.2.3 From 9e173afca30b0c7b2762d13eeeea595400877506 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 29 Jun 2016 18:12:59 +1000 Subject: Cleanup: endian tests --- source/blender/blenloader/intern/readfile.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 323f0a93e05..325f846669b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -880,8 +880,6 @@ static void decode_blender_header(FileData *fd) if (readsize == sizeof(header)) { if (STREQLEN(header, "BLENDER", 7)) { - int remove_this_endian_test = 1; - fd->flags |= FD_FLAGS_FILE_OK; /* what size are pointers in the file ? */ @@ -900,7 +898,7 @@ static void decode_blender_header(FileData *fd) /* is the file saved in a different endian * than we need ? */ - if (((((char *)&remove_this_endian_test)[0] == 1) ? L_ENDIAN : B_ENDIAN) != ((header[8] == 'v') ? L_ENDIAN : B_ENDIAN)) { + if (((header[8] == 'v') ? L_ENDIAN : B_ENDIAN) != ENDIAN_ORDER) { fd->flags |= FD_FLAGS_SWITCH_ENDIAN; } -- cgit v1.2.3 From 0971749f4cdc6c5263b91f652c1d78c97e30b973 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 29 Jun 2016 20:37:54 +1000 Subject: Cleanup: spelling, indentation --- source/blender/blenloader/intern/readfile.c | 2 +- source/blender/blenloader/intern/writefile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 325f846669b..b09ea45469c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6450,7 +6450,7 @@ static void *restore_pointer_by_name_main(Main *mainp, ID *id, ePointerUserMode * - USER_IGNORE: no usercount change * - USER_REAL: ensure a real user (even if a fake one is set) * \param id_map: lookup table, use when performing many lookups. - * this could be made an optional agument (falling back to a full lookup), + * this could be made an optional argument (falling back to a full lookup), * however at the moment it's always available. */ static void *restore_pointer_by_name(struct IDNameLib_Map *id_map, ID *id, ePointerUserMode user) diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 2c8bb92ac4b..19fb80ffb66 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -514,7 +514,7 @@ static void writestruct_at_address_id( static void writestruct_nr( WriteData *wd, int filecode, const int struct_nr, int nr, - const void *adr) + const void *adr) { writestruct_at_address_nr(wd, filecode, struct_nr, nr, adr, adr); } -- cgit v1.2.3 From fe44eacf78736f99bdfd3bc3ac86abd17e8ad514 Mon Sep 17 00:00:00 2001 From: Alexander Romanov Date: Mon, 4 Jul 2016 11:01:32 +0300 Subject: Environment lighting for the GLSL mode Environment lighting (aka ambient) is a key component of any renderer. It's implemented like the Environment lighting of BI render for Approximate Gather mode. It support "Sky Color" and "White" Environment lighting modes. It would be great if the user could see actual lighting conditions right in the Blender viewport instead of waiting for the renderer to complete the final image, exporting for external renderer or for a game engine. Before: {F113921} After: {F113922} Example file: {F319013} Original author: valentin_b4w Alexander (Blend4Web Team) Reviewers: valentin_b4w, campbellbarton, merwin, brecht Reviewed By: brecht Subscribers: panzergame, youle, duarteframos, AlexKowel, yurikovelenov, dingto, Evgeny_Rodygin Projects: #rendering, #opengl_gfx Differential Revision: https://developer.blender.org/D810 --- source/blender/blenloader/intern/versioning_250.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 43ebab7856c..1956a17d57b 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -1108,6 +1108,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main) sce->gm.flag |= GAME_GLSL_NO_NODES; if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX) sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX; + if (fd->fileflags & G_FILE_GLSL_NO_ENV_LIGHTING) + sce->gm.flag |= GAME_GLSL_NO_ENV_LIGHTING; if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS) sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS; -- cgit v1.2.3 From b98b331d04fe3a335cc0656809b4b09196507500 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 6 Jul 2016 21:58:47 +1000 Subject: writefile: simplify outliner treestore workaround Instead of keeping a list of allocations, write to unique addresses based on the BLI_mempool address since we know this is unique. --- source/blender/blenloader/intern/writefile.c | 45 +++++++++++++--------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 19fb80ffb66..7933f5450f3 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2911,43 +2911,41 @@ static void write_uilist(WriteData *wd, uiList *ui_list) } } -static void write_soops(WriteData *wd, SpaceOops *so, LinkNode **tmp_mem_list) +static void write_soops(WriteData *wd, SpaceOops *so) { BLI_mempool *ts = so->treestore; if (ts) { + SpaceOops so_flat = *so; + int elems = BLI_mempool_count(ts); /* linearize mempool to array */ TreeStoreElem *data = elems ? BLI_mempool_as_arrayN(ts, "TreeStoreElem") : NULL; if (data) { - TreeStore *ts_flat = MEM_callocN(sizeof(TreeStore), "TreeStore"); + /* In this block we use the memory location of the treestore + * but _not_ its data, the addresses in this case are UUID's, + * since we can't rely on malloc giving us different values each time. + */ + TreeStore ts_flat = {0}; - ts_flat->usedelem = elems; - ts_flat->totelem = elems; - ts_flat->data = data; + /* we know the treestore is at least as big as a pointer, + * so offsetting works to give us a UUID. */ + void *data_addr = (void *)POINTER_OFFSET(ts, sizeof(void *)); - /* temporarily replace mempool-treestore by flat-treestore */ - so->treestore = (BLI_mempool *)ts_flat; - writestruct(wd, DATA, SpaceOops, 1, so); + ts_flat.usedelem = elems; + ts_flat.totelem = elems; + ts_flat.data = data_addr; - writestruct(wd, DATA, TreeStore, 1, ts_flat); - writestruct(wd, DATA, TreeStoreElem, elems, data); + writestruct(wd, DATA, SpaceOops, 1, so); - /* we do not free the pointers immediately, because if we have multiple - * outliners in a screen we might get the same address on the next - * malloc, which makes the address no longer unique and so invalid for - * lookups on file read, causing crashes or double frees */ - BLI_linklist_prepend(tmp_mem_list, ts_flat); - BLI_linklist_prepend(tmp_mem_list, data); + writestruct_at_address(wd, DATA, TreeStore, 1, ts, &ts_flat); + writestruct_at_address(wd, DATA, TreeStoreElem, elems, data_addr, data); } else { - so->treestore = NULL; - writestruct(wd, DATA, SpaceOops, 1, so); + so_flat.treestore = NULL; + writestruct_at_address(wd, DATA, SpaceOops, 1, so, &so_flat); } - - /* restore old treestore */ - so->treestore = ts; } else { writestruct(wd, DATA, SpaceOops, 1, so); @@ -2960,7 +2958,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase) ScrArea *sa; ScrVert *sv; ScrEdge *se; - LinkNode *tmp_mem_list = NULL; sc = scrbase->first; while (sc) { @@ -3064,7 +3061,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase) } else if (sl->spacetype == SPACE_OUTLINER) { SpaceOops *so = (SpaceOops *)sl; - write_soops(wd, so, &tmp_mem_list); + write_soops(wd, so); } else if (sl->spacetype == SPACE_IMAGE) { writestruct(wd, DATA, SpaceImage, 1, sl); @@ -3132,8 +3129,6 @@ static void write_screens(WriteData *wd, ListBase *scrbase) sc = sc->id.next; } - BLI_linklist_freeN(tmp_mem_list); - /* flush helps the compression for undo-save */ mywrite(wd, MYWRITE_FLUSH, 0); } -- cgit v1.2.3 From 94e84f5be41de0f5b222f091e97f9fd0ad959460 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 6 Jul 2016 14:45:06 +0200 Subject: Fix memleak with recent Outliner writefile changes. --- source/blender/blenloader/intern/writefile.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 7933f5450f3..bbbe04dd24e 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2941,6 +2941,8 @@ static void write_soops(WriteData *wd, SpaceOops *so) writestruct_at_address(wd, DATA, TreeStore, 1, ts, &ts_flat); writestruct_at_address(wd, DATA, TreeStoreElem, elems, data_addr, data); + + MEM_freeN(data); } else { so_flat.treestore = NULL; -- cgit v1.2.3 From a0793765ef229b0d93bb9216b57faeb5940c5986 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 6 Jul 2016 22:23:50 +1000 Subject: writefile: avoid adding SDNA to every undo step Since SDNA was allocated for each undo step, the new address meant it was considered different and included again. Add an option not to duplicate the DNA string when calling DNA_sdna_from_data, as well as avoiding a redundant copy, it writes the same address each time. --- source/blender/blenloader/intern/readfile.c | 4 ++-- source/blender/blenloader/intern/writefile.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index b09ea45469c..0dd099df79b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -918,7 +918,7 @@ static int read_file_dna(FileData *fd) if (bhead->code == DNA1) { const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0; - fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap); + fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true); if (fd->filesdna) { fd->compflags = DNA_struct_get_compareflags(fd->filesdna, fd->memsdna); /* used to retrieve ID names from (bhead+1) */ @@ -1078,7 +1078,7 @@ static FileData *filedata_new(void) * but it keeps us re-entrant, remove once we have * a lib that provides a nice lock. - zr */ - fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false); + fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false); fd->datamap = oldnewmap_new(); fd->globmap = oldnewmap_new(); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index bbbe04dd24e..77df7ae0431 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -325,7 +325,7 @@ static WriteData *writedata_new(WriteWrap *ww) { WriteData *wd = MEM_callocN(sizeof(*wd), "writedata"); - wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false); + wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false); wd->ww = ww; @@ -4013,6 +4013,10 @@ static bool write_file_handle( write_thumb(wd, thumb); write_global(wd, write_flags, mainvar); + /* The windowmanager and screen often change, + * avoid thumbnail detecting changes because of this. */ + mywrite(wd, MYWRITE_FLUSH, 0); + write_windowmanagers(wd, &mainvar->wm); write_screens(wd, &mainvar->screen); write_movieclips(wd, &mainvar->movieclip); @@ -4046,11 +4050,17 @@ static bool write_file_handle( write_linestyles(wd, &mainvar->linestyle); write_libraries(wd, mainvar->next); + /* So changes above don't cause a 'DNA1' to be detected as changed on undo. */ + mywrite(wd, MYWRITE_FLUSH, 0); + if (write_flags & G_FILE_USERPREFS) { write_userdef(wd); } - /* dna as last, because (to be implemented) test for which structs are written */ + /* Write DNA last, because (to be implemented) test for which structs are written. + * + * Note that we *borrow* the pointer to 'DNAstr', + * so writing each time uses the same address and doesn't cause unnecessary undo overhead. */ writedata(wd, DNA1, wd->sdna->datalen, wd->sdna->data); #ifdef USE_NODE_COMPAT_CUSTOMNODES -- cgit v1.2.3 From 2fcb9ef919b93626182c1d711bab7316140215a5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 6 Jul 2016 23:27:22 +1000 Subject: writefile: add flushes Flush on grease pencil and data with image preview or packed data. --- source/blender/blenloader/intern/writefile.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 77df7ae0431..217162a67dc 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1922,6 +1922,9 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) vf = vf->id.next; } + + /* flush helps the compression for undo-save */ + mywrite(wd, MYWRITE_FLUSH, 0); } @@ -2358,6 +2361,9 @@ static void write_lattices(WriteData *wd, ListBase *idbase) } lt = lt->id.next; } + + /* flush helps the compression for undo-save */ + mywrite(wd, MYWRITE_FLUSH, 0); } static void write_images(WriteData *wd, ListBase *idbase) @@ -2571,6 +2577,9 @@ static void write_lamps(WriteData *wd, ListBase *idbase) } la = la->id.next; } + + /* flush helps the compression for undo-save */ + mywrite(wd, MYWRITE_FLUSH, 0); } static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) @@ -2856,6 +2865,9 @@ static void write_gpencils(WriteData *wd, ListBase *lb) } } } + + /* flush helps the compression for undo-save */ + mywrite(wd, MYWRITE_FLUSH, 0); } static void write_windowmanagers(WriteData *wd, ListBase *lb) @@ -3291,6 +3303,9 @@ static void write_groups(WriteData *wd, ListBase *idbase) } } } + + /* flush helps the compression for undo-save */ + mywrite(wd, MYWRITE_FLUSH, 0); } static void write_nodetrees(WriteData *wd, ListBase *idbase) @@ -3914,6 +3929,9 @@ static void write_libraries(WriteData *wd, Main *main) } } } + + /* flush helps the compression for undo-save */ + mywrite(wd, MYWRITE_FLUSH, 0); } /* context is usually defined by WM, two cases where no WM is available: -- cgit v1.2.3 From d501d0f91ecc9cc1fa832d8145683cd2a30b8640 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 6 Jul 2016 17:12:35 +0200 Subject: Revert rB961ebfa8c40b9909 - do not set Main's versions directly in do_versions(). This breaks any post-versionning (like IPO conversion, python handler, etc.). rB961ebfa8c40b9909 mentions some Main being do_versionned several times (which is not desired for sure), will try to reproduce again and find another fix. --- source/blender/blenloader/intern/readfile.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 0dd099df79b..68cc060b010 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -113,7 +113,6 @@ #include "BKE_action.h" #include "BKE_armature.h" -#include "BKE_blender_version.h" #include "BKE_brush.h" #include "BKE_cloth.h" #include "BKE_constraint.h" @@ -8287,9 +8286,6 @@ static void do_versions(FileData *fd, Library *lib, Main *main) blo_do_versions_260(fd, lib, main); blo_do_versions_270(fd, lib, main); - main->versionfile = BLENDER_VERSION; - main->subversionfile = BLENDER_SUBVERSION; - /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ /* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */ -- cgit v1.2.3 From 2b5c93d8fe0e46ae21027355d6efa4a7d910c42d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 7 Jul 2016 16:02:45 +1000 Subject: Cleanup: move write flush into its own function No point passing dummy args to existing function, split out logic instead. Also add flush after writing mesh data too. --- source/blender/blenloader/intern/writefile.c | 89 +++++++++++++--------------- 1 file changed, 40 insertions(+), 49 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 217162a67dc..e8bbc5ef36b 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -365,27 +365,32 @@ static void writedata_free(WriteData *wd) /***/ +/** + * Flush helps the de-duplicating memory for undo-save by logically segmenting data, + * so differences in one part of memory won't cause unrelated data to be duplicated. + */ +static void mywrite_flush(WriteData *wd) +{ + if (wd->count) { + writedata_do_write(wd, wd->buf, wd->count); + wd->count = 0; + } +} + /** * Low level WRITE(2) wrapper that buffers data * \param adr Pointer to new chunk of data * \param len Length of new chunk of data * \warning Talks to other functions with global parameters */ - -#define MYWRITE_FLUSH NULL - static void mywrite(WriteData *wd, const void *adr, int len) { if (UNLIKELY(wd->error)) { return; } - /* flush helps compression for undo-save */ - if (adr == MYWRITE_FLUSH) { - if (wd->count) { - writedata_do_write(wd, wd->buf, wd->count); - wd->count = 0; - } + if (adr == NULL) { + BLI_assert(0); return; } @@ -816,8 +821,7 @@ static void write_actions(WriteData *wd, ListBase *idbase) } } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_keyingsets(WriteData *wd, ListBase *list) @@ -1894,8 +1898,7 @@ static void write_objects(WriteData *wd, ListBase *idbase) ob = ob->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } @@ -1923,8 +1926,7 @@ static void write_vfonts(WriteData *wd, ListBase *idbase) vf = vf->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } @@ -1957,8 +1959,8 @@ static void write_keys(WriteData *wd, ListBase *idbase) key = key->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + + mywrite_flush(wd); } static void write_cameras(WriteData *wd, ListBase *idbase) @@ -2060,8 +2062,7 @@ static void write_curves(WriteData *wd, ListBase *idbase) cu = cu->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_dverts(WriteData *wd, int count, MDeformVert *dvlist) @@ -2335,6 +2336,8 @@ static void write_meshes(WriteData *wd, ListBase *idbase) mesh = mesh->id.next; } + + mywrite_flush(wd); } static void write_lattices(WriteData *wd, ListBase *idbase) @@ -2362,8 +2365,7 @@ static void write_lattices(WriteData *wd, ListBase *idbase) lt = lt->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_images(WriteData *wd, ListBase *idbase) @@ -2407,8 +2409,8 @@ static void write_images(WriteData *wd, ListBase *idbase) } ima = ima->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + + mywrite_flush(wd); } static void write_textures(WriteData *wd, ListBase *idbase) @@ -2460,8 +2462,7 @@ static void write_textures(WriteData *wd, ListBase *idbase) tex = tex->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_materials(WriteData *wd, ListBase *idbase) @@ -2578,8 +2579,7 @@ static void write_lamps(WriteData *wd, ListBase *idbase) la = la->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_sequence_modifiers(WriteData *wd, ListBase *modbase) @@ -2827,8 +2827,8 @@ static void write_scenes(WriteData *wd, ListBase *scebase) sce = sce->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + + mywrite_flush(wd); } static void write_gpencils(WriteData *wd, ListBase *lb) @@ -2866,8 +2866,7 @@ static void write_gpencils(WriteData *wd, ListBase *lb) } } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_windowmanagers(WriteData *wd, ListBase *lb) @@ -3143,8 +3142,7 @@ static void write_screens(WriteData *wd, ListBase *scrbase) sc = sc->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_bone(WriteData *wd, Bone *bone) @@ -3192,8 +3190,7 @@ static void write_armatures(WriteData *wd, ListBase *idbase) arm = arm->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_texts(WriteData *wd, ListBase *idbase) @@ -3234,8 +3231,7 @@ static void write_texts(WriteData *wd, ListBase *idbase) text = text->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_speakers(WriteData *wd, ListBase *idbase) @@ -3279,8 +3275,7 @@ static void write_sounds(WriteData *wd, ListBase *idbase) sound = sound->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_groups(WriteData *wd, ListBase *idbase) @@ -3304,8 +3299,7 @@ static void write_groups(WriteData *wd, ListBase *idbase) } } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_nodetrees(WriteData *wd, ListBase *idbase) @@ -3518,8 +3512,7 @@ static void write_movieclips(WriteData *wd, ListBase *idbase) clip = clip->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_masks(WriteData *wd, ListBase *idbase) @@ -3579,8 +3572,7 @@ static void write_masks(WriteData *wd, ListBase *idbase) mask = mask->id.next; } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } static void write_linestyle_color_modifiers(WriteData *wd, ListBase *modifiers) @@ -3930,8 +3922,7 @@ static void write_libraries(WriteData *wd, Main *main) } } - /* flush helps the compression for undo-save */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); } /* context is usually defined by WM, two cases where no WM is available: @@ -4033,7 +4024,7 @@ static bool write_file_handle( /* The windowmanager and screen often change, * avoid thumbnail detecting changes because of this. */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); write_windowmanagers(wd, &mainvar->wm); write_screens(wd, &mainvar->screen); @@ -4069,7 +4060,7 @@ static bool write_file_handle( write_libraries(wd, mainvar->next); /* So changes above don't cause a 'DNA1' to be detected as changed on undo. */ - mywrite(wd, MYWRITE_FLUSH, 0); + mywrite_flush(wd); if (write_flags & G_FILE_USERPREFS) { write_userdef(wd); -- cgit v1.2.3 From dac125b8ecd51b89ce8dc65080ad3d2111c0ed7b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 7 Jul 2016 16:27:33 +1000 Subject: writefile: call undo flush after writing the windowmanager Data here is constantly changing, avoids outliner data being included in those changes for undo. --- source/blender/blenloader/intern/writefile.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index e8bbc5ef36b..a761a56a42d 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2883,6 +2883,10 @@ static void write_windowmanagers(WriteData *wd, ListBase *lb) writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format); } } + + /* typically flushing wouldn't be needed however this data _always_ changes, + * so flush here for more efficient undo. */ + mywrite_flush(wd); } static void write_region(WriteData *wd, ARegion *ar, int spacetype) -- cgit v1.2.3 From a02915c0f3b9b24f615fc7e4b8f491106a52dee0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 8 Jul 2016 14:32:29 +1000 Subject: writefile: optimize undo memory use Slop-space on Linux wasted ~20% of memory for undo storage. --- source/blender/blenloader/intern/writefile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index a761a56a42d..bd19f2aeb74 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -191,9 +191,9 @@ /* ********* my write, buffered writing with minimum size chunks ************ */ -#define MYWRITE_BUFFER_SIZE 100000 -#define MYWRITE_MAX_CHUNK 32768 - +/* Use optimal allocation since blocks of this size are kept in memory for undo. */ +#define MYWRITE_BUFFER_SIZE (MEM_SIZE_OPTIMAL(1 << 17)) /* 128kb */ +#define MYWRITE_MAX_CHUNK (MEM_SIZE_OPTIMAL(1 << 15)) /* ~32kb */ /** \name Small API to handle compression. -- cgit v1.2.3 From 83fe139b2b9c37db50c14833cb38877b999db6de Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 8 Jul 2016 15:42:50 +1000 Subject: Undo: use system memcmp `my_memcmp` didn't work properly comparing memory sizes not aligned to 4 bytes, this worked while we used guarded-alloc (which always wrote a guard at the end of each allocation). Since moving to lockfree allocator it could read uninitialized memory. It also consistently performed ~10-30% worse then glibc's. This is typically well optimized, no need to do ourselves. --- source/blender/blenloader/intern/undofile.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c index d0dc9a88cc0..c191e48a143 100644 --- a/source/blender/blenloader/intern/undofile.c +++ b/source/blender/blenloader/intern/undofile.c @@ -80,20 +80,6 @@ void BLO_memfile_merge(MemFile *first, MemFile *second) BLO_memfile_free(first); } -static int my_memcmp(const int *mem1, const int *mem2, const int len) -{ - register int a = len; - register const int *mema = mem1; - register const int *memb = mem2; - - while (a--) { - if (*mema != *memb) return 1; - mema++; - memb++; - } - return 0; -} - void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsigned int size) { static MemFileChunk *compchunk = NULL; @@ -118,7 +104,7 @@ void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsi /* we compare compchunk with buf */ if (compchunk) { if (compchunk->size == curchunk->size) { - if (my_memcmp((int *)compchunk->buf, (const int *)buf, size / 4) == 0) { + if (memcmp(compchunk->buf, buf, size) == 0) { curchunk->buf = compchunk->buf; curchunk->ident = 1; } -- cgit v1.2.3 From 0b3183d13cdbdcb06317fd1dd9b04ccd93a767c1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Jul 2016 11:48:04 +1000 Subject: writefile: remove SDNA last-hit, optimize DNA reconstruct - Move last-hit index out of SDNA struct (allows for access by multiple threads). - Replace O(n^2) search with hash lookup in DNA reconstruction. --- source/blender/blenloader/intern/readfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 68cc060b010..27a119a4532 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1844,7 +1844,7 @@ void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd) /* ********** END OLD POINTERS ****************** */ /* ********** READ FILE ****************** */ -static void switch_endian_structs(struct SDNA *filesdna, BHead *bhead) +static void switch_endian_structs(const struct SDNA *filesdna, BHead *bhead) { int blocksize, nblocks; char *data; -- cgit v1.2.3 From 4db1db327a0613abee950ffe12b013afdec2c111 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Jul 2016 12:23:48 +1000 Subject: readfile: report SDNA decoding errors on file read This was printed to the stdout, however the error case wasn't checked or well supported. Also, errors decoding SDNA would sometimes call exit(1). --- source/blender/blenloader/intern/readfile.c | 25 ++++++++++++++++++------- source/blender/blenloader/intern/writefile.c | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 27a119a4532..eeb8a5d8dbd 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -909,7 +909,10 @@ static void decode_blender_header(FileData *fd) } } -static int read_file_dna(FileData *fd) +/** + * \return Success if the file is read correctly, else set \a r_error_message. + */ +static bool read_file_dna(FileData *fd, const char **r_error_message) { BHead *bhead; @@ -917,20 +920,25 @@ static int read_file_dna(FileData *fd) if (bhead->code == DNA1) { const bool do_endian_swap = (fd->flags & FD_FLAGS_SWITCH_ENDIAN) != 0; - fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true); + fd->filesdna = DNA_sdna_from_data(&bhead[1], bhead->len, do_endian_swap, true, r_error_message); if (fd->filesdna) { fd->compflags = DNA_struct_get_compareflags(fd->filesdna, fd->memsdna); /* used to retrieve ID names from (bhead+1) */ fd->id_name_offs = DNA_elem_offset(fd->filesdna, "ID", "char", "name[]"); + + return true; + } + else { + return false; } - return 1; } else if (bhead->code == ENDB) break; } - return 0; + *r_error_message = "Missing DNA block"; + return false; } static int *read_file_thumbnail(FileData *fd) @@ -1077,7 +1085,7 @@ static FileData *filedata_new(void) * but it keeps us re-entrant, remove once we have * a lib that provides a nice lock. - zr */ - fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false); + fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL); fd->datamap = oldnewmap_new(); fd->globmap = oldnewmap_new(); @@ -1091,8 +1099,11 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports) decode_blender_header(fd); if (fd->flags & FD_FLAGS_FILE_OK) { - if (!read_file_dna(fd)) { - BKE_reportf(reports, RPT_ERROR, "Failed to read blend file '%s', incomplete", fd->relabase); + const char *error_message = NULL; + if (read_file_dna(fd, &error_message) == false) { + BKE_reportf(reports, RPT_ERROR, + "Failed to read blend file '%s': %s", + fd->relabase, error_message); blo_freefiledata(fd); fd = NULL; } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index bd19f2aeb74..f898eea566d 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -325,7 +325,7 @@ static WriteData *writedata_new(WriteWrap *ww) { WriteData *wd = MEM_callocN(sizeof(*wd), "writedata"); - wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false); + wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL); wd->ww = ww; -- cgit v1.2.3 From 0708b9aba8f7da87c4cf97b96c0bc9229fa9689c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 12 Jul 2016 12:53:49 +1000 Subject: writefile: reuse SDNA between writes Avoids decoding the SDNA string every undo step. --- source/blender/blenloader/intern/readfile.c | 14 ++++---------- source/blender/blenloader/intern/readfile.h | 2 +- source/blender/blenloader/intern/writefile.c | 6 ++---- 3 files changed, 7 insertions(+), 15 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index eeb8a5d8dbd..059dce2459e 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1080,13 +1080,9 @@ static FileData *filedata_new(void) fd->filedes = -1; fd->gzfiledes = NULL; - - /* XXX, this doesn't need to be done all the time, - * but it keeps us re-entrant, remove once we have - * a lib that provides a nice lock. - zr - */ - fd->memsdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL); - + + fd->memsdna = DNA_sdna_current_get(); + fd->datamap = oldnewmap_new(); fd->globmap = oldnewmap_new(); fd->libmap = oldnewmap_new(); @@ -1280,9 +1276,7 @@ void blo_freefiledata(FileData *fd) // Free all BHeadN data blocks BLI_freelistN(&fd->listbase); - - if (fd->memsdna) - DNA_sdna_free(fd->memsdna); + if (fd->filesdna) DNA_sdna_free(fd->filesdna); if (fd->compflags) diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index 42728fd406f..b054cd0031d 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -74,7 +74,7 @@ typedef struct FileData { // general reading variables struct SDNA *filesdna; - struct SDNA *memsdna; + const struct SDNA *memsdna; char *compflags; /* array of eSDNA_StructCompare */ int fileversion; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index f898eea566d..88f1c4d5e4a 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -303,7 +303,7 @@ static void ww_handle_init(eWriteWrapType ww_type, WriteWrap *r_ww) typedef struct { - struct SDNA *sdna; + const struct SDNA *sdna; unsigned char *buf; MemFile *compare, *current; @@ -325,7 +325,7 @@ static WriteData *writedata_new(WriteWrap *ww) { WriteData *wd = MEM_callocN(sizeof(*wd), "writedata"); - wd->sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, NULL); + wd->sdna = DNA_sdna_current_get(); wd->ww = ww; @@ -357,8 +357,6 @@ static void writedata_do_write(WriteData *wd, const void *mem, int memlen) static void writedata_free(WriteData *wd) { - DNA_sdna_free(wd->sdna); - MEM_freeN(wd->buf); MEM_freeN(wd); } -- cgit v1.2.3 From 51812fb502c0a3034055df2c7b80e77dba5e91c3 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 12 Jul 2016 17:49:30 +0200 Subject: Fix 48831, Step I: Mismatch issues bewteen ID icon and preview system. - icon_id from ID and PreviewImage were not guaranteed to be in sync. - PreviewImage one was not reset on file read. - Through RNA e.g., it was possible to ensure an ID icon via its preview image, which was running code designed for custom previews/icons system, instead of generating correct 'auto ID icon'. --- source/blender/blenloader/intern/readfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 059dce2459e..4ef30fe0f3b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2144,6 +2144,7 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p } prv->gputexture[i] = NULL; } + prv->icon_id = 0; } return prv; -- cgit v1.2.3 From 2aa056986152c7e17a4c85b4dafb7c16bd692ed1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 13 Jul 2016 17:45:55 +1000 Subject: Boolean Modifier: Add back BMesh option There are still issues with overlapping geometry, however some of the issues reported are are causing problems, or fail entirely with Carve too. --- source/blender/blenloader/intern/versioning_270.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index b7b6ace3c1a..ac2811aeb06 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1212,5 +1212,18 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + if (!DNA_struct_elem_find(fd->filesdna, "BooleanModifierData", "float", "double_threshold")) { + Object *ob; + for (ob = main->object.first; ob; ob = ob->id.next) { + ModifierData *md; + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Boolean) { + BooleanModifierData *bmd = (BooleanModifierData *)md; + bmd->double_threshold = 1e-6f; + } + } + } + } } } -- cgit v1.2.3 From 018d336cbd51a9e4b75f8270e90397d35192496f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 14 Jul 2016 15:32:25 +0200 Subject: Cleanup: use BKE's ntreeFromID in readfile instead of local same function. Also, no need to set ntree->id.lib to NULL after BKE_libblock_copy_nolib(), generic datablock copy function always make copy local. --- source/blender/blenloader/intern/readfile.c | 34 +++++++---------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 4ef30fe0f3b..79cd8a7fe6e 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2756,22 +2756,6 @@ static void lib_link_nodetree(FileData *fd, Main *main) } } -/* get node tree stored locally in other IDs */ -static bNodeTree *nodetree_from_id(ID *id) -{ - if (!id) - return NULL; - switch (GS(id->name)) { - case ID_SCE: return ((Scene *)id)->nodetree; - case ID_MA: return ((Material *)id)->nodetree; - case ID_WO: return ((World *)id)->nodetree; - case ID_LA: return ((Lamp *)id)->nodetree; - case ID_TE: return ((Tex *)id)->nodetree; - case ID_LS: return ((FreestyleLineStyle *)id)->nodetree; - } - return NULL; -} - /* updates group node socket identifier so that * external links to/from the group node are preserved. */ @@ -6350,11 +6334,9 @@ static void lib_link_screen(FileData *fd, Main *main) snode->id = newlibadr(fd, sc->id.lib, snode->id); snode->from = newlibadr(fd, sc->id.lib, snode->from); - ntree = nodetree_from_id(snode->id); - if (ntree) - snode->nodetree = ntree; - else { - snode->nodetree = newlibadr_us(fd, sc->id.lib, snode->nodetree); + if (snode->id) { + ntree = ntreeFromID(snode->id); + snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); } for (path = snode->treepath.first; path; path = path->next) { @@ -6734,11 +6716,11 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc snode->id = restore_pointer_by_name(id_map, snode->id, USER_REAL); snode->from = restore_pointer_by_name(id_map, snode->from, USER_IGNORE); - ntree = nodetree_from_id(snode->id); - if (ntree) - snode->nodetree = ntree; - else - snode->nodetree = restore_pointer_by_name(id_map, (ID*)snode->nodetree, USER_REAL); + if (snode->id) { + ntree = ntreeFromID(snode->id); + snode->nodetree = ntree ? ntree : + restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL); + } for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { -- cgit v1.2.3 From bcfd8d9ab82501047f11da8c3f039142dfd9e8f8 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 14 Jul 2016 18:16:05 +0200 Subject: Correct recent own fix to id_clear_lib_data_ex(). Datablocks' nodetree are *never* in main, while shapekeys are... --- source/blender/blenloader/intern/readfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 79cd8a7fe6e..a25b56b9cf1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2713,7 +2713,7 @@ static void lib_link_node_socket(FileData *fd, ID *UNUSED(id), bNodeSocket *sock IDP_LibLinkProperty(sock->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); } -/* singe node tree (also used for material/scene trees), ntree is not NULL */ +/* Single node tree (also used for material/scene trees), ntree is not NULL */ static void lib_link_ntree(FileData *fd, ID *id, bNodeTree *ntree) { bNode *node; -- cgit v1.2.3 From c885cea7bbfbbb8f1815cf5bc1f3ecc532c309ad Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 16 Jul 2016 17:48:57 +1000 Subject: Cleanup: spelling --- source/blender/blenloader/intern/writefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 88f1c4d5e4a..ba783e08b39 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2268,7 +2268,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) mesh->edit_btmesh = NULL; /* now fill in polys to mfaces */ - /* XXX This breaks writing desing, by using temp allocated memory, which will likely generate + /* XXX This breaks writing design, by using temp allocated memory, which will likely generate * duplicates in stored 'old' addresses. * This is very bad, but do not see easy way to avoid this, aside from generating those data * outside of save process itself. -- cgit v1.2.3 From bd59206b5c28674a757746a64aaf31abc107cedb Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Jul 2016 08:39:38 +1000 Subject: Cleanup: style, spelling --- source/blender/blenloader/intern/writefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ba783e08b39..88f1c4d5e4a 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2268,7 +2268,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) mesh->edit_btmesh = NULL; /* now fill in polys to mfaces */ - /* XXX This breaks writing design, by using temp allocated memory, which will likely generate + /* XXX This breaks writing desing, by using temp allocated memory, which will likely generate * duplicates in stored 'old' addresses. * This is very bad, but do not see easy way to avoid this, aside from generating those data * outside of save process itself. -- cgit v1.2.3 From 3948f65686ae78de2b0cd668390826f49598f99b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Jul 2016 10:23:26 +1000 Subject: Cleanup: style, spelling --- source/blender/blenloader/intern/writefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 88f1c4d5e4a..ba783e08b39 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2268,7 +2268,7 @@ static void write_meshes(WriteData *wd, ListBase *idbase) mesh->edit_btmesh = NULL; /* now fill in polys to mfaces */ - /* XXX This breaks writing desing, by using temp allocated memory, which will likely generate + /* XXX This breaks writing design, by using temp allocated memory, which will likely generate * duplicates in stored 'old' addresses. * This is very bad, but do not see easy way to avoid this, aside from generating those data * outside of save process itself. -- cgit v1.2.3 From 690063edb928b2755462863d971600deb608f848 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 20 Jul 2016 13:54:55 +1000 Subject: Fix T48897: Flatten brush fails on first stroke The flatten brush depended on accumulate being disabled, Adding dynotopo support for accumulate caused problems for this tool (see T44390). Enable for existing files. --- source/blender/blenloader/intern/versioning_270.c | 6 ++++++ source/blender/blenloader/intern/versioning_defaults.c | 5 +++++ 2 files changed, 11 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index ac2811aeb06..8d96d7c3807 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1225,5 +1225,11 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + for (Brush *br = main->brush.first; br; br = br->id.next) { + if (br->sculpt_tool == SCULPT_TOOL_FLATTEN) { + br->flag |= BRUSH_ACCUMULATE; + } + } } } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index ad7a3c5b9c4..0ed7a397e0b 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -256,6 +256,11 @@ void BLO_update_defaults_startup_blend(Main *bmain) if (br) { br->alpha = 1.0f; } + + br = (Brush *)BKE_libblock_find_name_ex(bmain, ID_BR, "Flatten/Contrast"); + if (br) { + br->flag |= BRUSH_ACCUMULATE; + } } } -- cgit v1.2.3 From ecd33bacf0992d67bbad8e2c70996639837503b1 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 21 Jul 2016 11:49:30 +1000 Subject: Cleanup: use const, move comments to enum --- source/blender/blenloader/intern/readfile.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index b054cd0031d..7719aaa2b0d 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; const struct SDNA *memsdna; - char *compflags; /* array of eSDNA_StructCompare */ + const char *compflags; /* array of eSDNA_StructCompare */ int fileversion; int id_name_offs; /* used to retrieve ID names from (bhead+1) */ -- cgit v1.2.3 From 1cc0ce58fd082a819431a766fa3e2f897dd46a4e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 22 Jul 2016 04:05:38 +1000 Subject: Cleanup: warnings --- source/blender/blenloader/intern/readfile.c | 2 +- source/blender/blenloader/intern/versioning_270.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index a25b56b9cf1..2fbdc1a3f19 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -1280,7 +1280,7 @@ void blo_freefiledata(FileData *fd) if (fd->filesdna) DNA_sdna_free(fd->filesdna); if (fd->compflags) - MEM_freeN(fd->compflags); + MEM_freeN((void *)fd->compflags); if (fd->datamap) oldnewmap_free(fd->datamap); diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 8d96d7c3807..a254a854c66 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1194,8 +1194,8 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) if (camera->stereo.pole_merge_angle_from == 0.0f && camera->stereo.pole_merge_angle_to == 0.0f) { - camera->stereo.pole_merge_angle_from = DEG2RAD(60.0f); - camera->stereo.pole_merge_angle_to = DEG2RAD(75.0f); + camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f); + camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f); } } -- cgit v1.2.3 From 3d8c2e25a3af1ea1645f5a6df1b566ae6313e657 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 27 Jul 2016 10:18:54 +0200 Subject: Fix T48950: Movie Clip mode segfaults Missing linking code in blenloader. --- source/blender/blenloader/intern/readfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 2fbdc1a3f19..d007eed0673 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7471,6 +7471,7 @@ static void lib_link_movieclip(FileData *fd, Main *main) for (object = tracking->objects.first; object; object = object->next) { lib_link_movieTracks(fd, clip, &object->tracks); + lib_link_moviePlaneTracks(fd, clip, &object->plane_tracks); } clip->id.tag &= ~LIB_TAG_NEED_LINK; -- cgit v1.2.3 From 8e004062612e50789f081c795e7f39bf51ca3ae7 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 29 Jul 2016 17:35:31 +0200 Subject: Fix a bunch of missing expand calls in object/particle physics area, was breaking linking of those. Initial report/patch by Alexander Gavrilov (@angavrilov), found more on the road. Nice demo of why we should use libquery ID looper in read code too - but that's for another day (also because read code needs to take care of some deprecated pointers sometimes)... --- source/blender/blenloader/intern/readfile.c | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d007eed0673..22e1507cd99 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8850,6 +8850,37 @@ static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSetting expand_doit(fd, mainvar, part->mtex[a]->object); } } + + if (part->effector_weights) { + expand_doit(fd, mainvar, part->effector_weights->group); + } + + if (part->pd) { + expand_doit(fd, mainvar, part->pd->tex); + expand_doit(fd, mainvar, part->pd->f_source); + } + if (part->pd2) { + expand_doit(fd, mainvar, part->pd2->tex); + expand_doit(fd, mainvar, part->pd2->f_source); + } + + if (part->boids) { + BoidState *state; + BoidRule *rule; + + for (state = part->boids->states.first; state; state = state->next) { + for (rule = state->rules.first; rule; rule = rule->next) { + if (rule->type == eBoidRuleType_Avoid) { + BoidRuleGoalAvoid *gabr = (BoidRuleGoalAvoid *)rule; + expand_doit(fd, mainvar, gabr->ob); + } + else if (rule->type == eBoidRuleType_FollowLeader) { + BoidRuleFollowLeader *flbr = (BoidRuleFollowLeader *)rule; + expand_doit(fd, mainvar, flbr->ob); + } + } + } + } } static void expand_group(FileData *fd, Main *mainvar, Group *group) @@ -9213,7 +9244,7 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) for (psys = ob->particlesystem.first; psys; psys = psys->next) expand_doit(fd, mainvar, psys->part); - + for (sens = ob->sensors.first; sens; sens = sens->next) { if (sens->type == SENS_MESSAGE) { bMessageSensor *ms = sens->data; @@ -9292,8 +9323,16 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) } } - if (ob->pd && ob->pd->tex) + if (ob->pd) { expand_doit(fd, mainvar, ob->pd->tex); + expand_doit(fd, mainvar, ob->pd->f_source); + } + + if (ob->soft) { + if (ob->soft->effector_weights) { + expand_doit(fd, mainvar, ob->soft->effector_weights->group); + } + } if (ob->rigidbody_constraint) { expand_doit(fd, mainvar, ob->rigidbody_constraint->ob1); -- cgit v1.2.3 From e4255a9535f8c4bd440ede159ec271e7fcd394cf Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 29 Jul 2016 18:49:50 +0200 Subject: Cleanup space/tabs, Grrr. --- source/blender/blenloader/intern/readfile.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 22e1507cd99..50e5eb195db 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -9329,9 +9329,9 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) } if (ob->soft) { - if (ob->soft->effector_weights) { - expand_doit(fd, mainvar, ob->soft->effector_weights->group); - } + if (ob->soft->effector_weights) { + expand_doit(fd, mainvar, ob->soft->effector_weights->group); + } } if (ob->rigidbody_constraint) { -- cgit v1.2.3 From 362b3bbe58ae378d5e154dd1a27d55d913594a1a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 30 Jul 2016 14:46:19 +1000 Subject: Cloth Simulation: add time scale property This setting can also be animated, to create a "time warp" effect. D2122 by @LucaRood --- source/blender/blenloader/intern/versioning_270.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index a254a854c66..3e6b0d34ba6 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1231,5 +1231,24 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) br->flag |= BRUSH_ACCUMULATE; } } + + if (!DNA_struct_elem_find(fd->filesdna, "ClothSimSettings", "float", "time_scale")) { + Object *ob; + ModifierData *md; + for (ob = main->object.first; ob; ob = ob->id.next) { + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *)md; + clmd->sim_parms->time_scale = 1.0f; + } + else if (md->type == eModifierType_ParticleSystem) { + ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md; + if (pmd->psys->clmd) { + pmd->psys->clmd->sim_parms->time_scale = 1.0f; + } + } + } + } + } } } -- cgit v1.2.3 From 64d4d6b134d5b36c43aa55e09ad92d8593a18269 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 31 Jul 2016 18:56:44 +1000 Subject: Support limiting collisions by group for softbody and particles This feature is extremely useful for layering multiple cloth objects, and there is no reason there shouldn't be the same kind of feature for softbody. --- source/blender/blenloader/intern/readfile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 50e5eb195db..f6d371ee2d3 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4040,6 +4040,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main) part->dup_group = newlibadr(fd, part->id.lib, part->dup_group); part->eff_group = newlibadr(fd, part->id.lib, part->eff_group); part->bb_ob = newlibadr(fd, part->id.lib, part->bb_ob); + part->collision_group = newlibadr(fd, part->id.lib, part->collision_group); lib_link_partdeflect(fd, &part->id, part->pd); lib_link_partdeflect(fd, &part->id, part->pd2); @@ -4891,8 +4892,11 @@ static void lib_link_object(FileData *fd, Main *main) if (ob->pd) lib_link_partdeflect(fd, &ob->id, ob->pd); - if (ob->soft) + if (ob->soft) { + ob->soft->collision_group = newlibadr(fd, ob->id.lib, ob->soft->collision_group); + ob->soft->effector_weights->group = newlibadr(fd, ob->id.lib, ob->soft->effector_weights->group); + } lib_link_particlesystems(fd, ob, &ob->id, &ob->particlesystem); lib_link_modifiers(fd, ob); @@ -8840,6 +8844,7 @@ static void expand_particlesettings(FileData *fd, Main *mainvar, ParticleSetting expand_doit(fd, mainvar, part->dup_group); expand_doit(fd, mainvar, part->eff_group); expand_doit(fd, mainvar, part->bb_ob); + expand_doit(fd, mainvar, part->collision_group); if (part->adt) expand_animdata(fd, mainvar, part->adt); @@ -9329,6 +9334,8 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob) } if (ob->soft) { + expand_doit(fd, mainvar, ob->soft->collision_group); + if (ob->soft->effector_weights) { expand_doit(fd, mainvar, ob->soft->effector_weights->group); } -- cgit v1.2.3 From 36a790653c01809546ae2db9f9a56123f2dfdec7 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 31 Jul 2016 20:07:33 +0200 Subject: Fix T48980: crash when loading a file that contains a custom node tree. Syupid logical mistake in own recent rB018d336cbd51... --- source/blender/blenloader/intern/readfile.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f6d371ee2d3..7eabcd18fb8 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6338,10 +6338,8 @@ static void lib_link_screen(FileData *fd, Main *main) snode->id = newlibadr(fd, sc->id.lib, snode->id); snode->from = newlibadr(fd, sc->id.lib, snode->from); - if (snode->id) { - ntree = ntreeFromID(snode->id); - snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); - } + ntree = snode->id ? ntreeFromID(snode->id) : NULL; + snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree); for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { @@ -6720,11 +6718,8 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc snode->id = restore_pointer_by_name(id_map, snode->id, USER_REAL); snode->from = restore_pointer_by_name(id_map, snode->from, USER_IGNORE); - if (snode->id) { - ntree = ntreeFromID(snode->id); - snode->nodetree = ntree ? ntree : - restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL); - } + ntree = snode->id ? ntreeFromID(snode->id) : NULL; + snode->nodetree = ntree ? ntree : restore_pointer_by_name(id_map, (ID *)snode->nodetree, USER_REAL); for (path = snode->treepath.first; path; path = path->next) { if (path == snode->treepath.first) { -- cgit v1.2.3 From eaea4ea51f665945e44ff2ffa534a594e9fb1938 Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Wed, 3 Aug 2016 23:31:48 +0200 Subject: Grease Pencil v2 Branch Improve current Grease Pencil in order to get a better 2D animation tool. More info in WIKI pages: https://wiki.blender.org/index.php/User:Antoniov Reviewed By: Severin, aligorith, campbellbarton Patch by @antoniov, with edits by @Severin. Differential Revision: https://developer.blender.org/D2115 --- source/blender/blenloader/intern/readfile.c | 36 ++++++++- source/blender/blenloader/intern/versioning_270.c | 90 +++++++++++++++++++--- .../blenloader/intern/versioning_defaults.c | 5 ++ source/blender/blenloader/intern/writefile.c | 20 +++++ 4 files changed, 137 insertions(+), 14 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 7eabcd18fb8..52ca8520b46 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -144,7 +144,7 @@ #include "BKE_sequencer.h" #include "BKE_outliner_treehash.h" #include "BKE_sound.h" - +#include "BKE_colortools.h" #include "NOD_common.h" #include "NOD_socket.h" @@ -5872,6 +5872,22 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->toolsettings->wpaint->wpaint_prev = NULL; sce->toolsettings->wpaint->tot = 0; } + /* relink grease pencil drawing brushes */ + link_list(fd, &sce->toolsettings->gp_brushes); + for (bGPDbrush *brush = sce->toolsettings->gp_brushes.first; brush; brush = brush->next) { + brush->cur_sensitivity = newdataadr(fd, brush->cur_sensitivity); + if (brush->cur_sensitivity) { + direct_link_curvemapping(fd, brush->cur_sensitivity); + } + brush->cur_strength = newdataadr(fd, brush->cur_strength); + if (brush->cur_strength) { + direct_link_curvemapping(fd, brush->cur_strength); + } + brush->cur_jitter = newdataadr(fd, brush->cur_jitter); + if (brush->cur_jitter) { + direct_link_curvemapping(fd, brush->cur_jitter); + } + } } if (sce->ed) { @@ -6154,7 +6170,8 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps; - + bGPDpalette *palette; + /* we must firstly have some grease-pencil data to link! */ if (gpd == NULL) return; @@ -6162,11 +6179,19 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) /* relink animdata */ gpd->adt = newdataadr(fd, gpd->adt); direct_link_animdata(fd, gpd->adt); - + + /* relink palettes */ + link_list(fd, &gpd->palettes); + for (palette = gpd->palettes.first; palette; palette = palette->next) { + link_list(fd, &palette->colors); + } + /* relink layers */ link_list(fd, &gpd->layers); for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* parent */ + gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent); /* relink frames */ link_list(fd, &gpl->frames); gpl->actframe = newdataadr(fd, gpl->actframe); @@ -6179,9 +6204,12 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) gps->points = newdataadr(fd, gps->points); /* the triangulation is not saved, so need to be recalculated */ - gps->flag |= GP_STROKE_RECALC_CACHES; gps->triangles = NULL; gps->tot_triangles = 0; + gps->flag |= GP_STROKE_RECALC_CACHES; + /* the color pointer is not saved, so need to be recalculated using the color name */ + gps->palcolor = NULL; + gps->flag |= GP_STROKE_RECALC_COLOR; } } } diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 3e6b0d34ba6..c4fec3ed824 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -63,6 +63,7 @@ #include "BKE_scene.h" #include "BKE_sequencer.h" #include "BKE_screen.h" +#include "BKE_gpencil.h" #include "BLI_math.h" #include "BLI_listbase.h" @@ -1075,15 +1076,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } - /* init grease pencil smooth level iterations */ - for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { - for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { - if (gpl->draw_smoothlvl == 0) { - gpl->draw_smoothlvl = 1; - } - } - } - for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) { for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { @@ -1192,7 +1184,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) for (Camera *camera = main->camera.first; camera != NULL; camera = camera->id.next) { if (camera->stereo.pole_merge_angle_from == 0.0f && - camera->stereo.pole_merge_angle_to == 0.0f) + camera->stereo.pole_merge_angle_to == 0.0f) { camera->stereo.pole_merge_angle_from = DEG2RADF(60.0f); camera->stereo.pole_merge_angle_to = DEG2RADF(75.0f); @@ -1251,4 +1243,82 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + if (!MAIN_VERSION_ATLEAST(main, 277, 3)) { + /* ------- init of grease pencil initialization --------------- */ + if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "palcolor")) { + for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { + ToolSettings *ts = scene->toolsettings; + /* initialize use position for sculpt brushes */ + ts->gp_sculpt.flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION; + /* initialize selected vertices alpha factor */ + ts->gp_sculpt.alpha = 1.0f; + + /* new strength sculpt brush */ + if (ts->gp_sculpt.brush[0].size >= 11) { + GP_BrushEdit_Settings *gset = &ts->gp_sculpt; + GP_EditBrush_Data *brush; + + brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH]; + brush->size = 25; + brush->strength = 0.5f; + brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; + } + } + /* create a default grease pencil drawing brushes set */ + if (!BLI_listbase_is_empty(&main->gpencil)) { + for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { + ToolSettings *ts = scene->toolsettings; + if (BLI_listbase_is_empty(&ts->gp_brushes)) { + gpencil_brush_init_presets(ts); + } + } + } + /* Convert Grease Pencil to new palettes/brushes + * Loop all strokes and create the palette and all colors + */ + for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { + if (BLI_listbase_is_empty(&gpd->palettes)) { + /* create palette */ + bGPDpalette *palette = gpencil_palette_addnew(gpd, "GP_Palette", true); + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + /* create color using layer name */ + bGPDpalettecolor *palcolor = gpencil_palettecolor_addnew(palette, gpl->info, true); + if (palcolor != NULL) { + /* set color attributes */ + copy_v4_v4(palcolor->color, gpl->color); + copy_v4_v4(palcolor->fill, gpl->fill); + palcolor->flag = gpl->flag; + /* set layer opacity to 1 */ + gpl->opacity = 1.0f; + /* set tint color */ + ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f); + + for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { + for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { + /* set stroke to palette and force recalculation */ + strcpy(gps->colorname, gpl->info); + gps->palcolor = NULL; + gps->flag |= GP_STROKE_RECALC_COLOR; + gps->thickness = gpl->thickness; + /* set alpha strength to 1 */ + for (int i = 0; i < gps->totpoints; i++) { + gps->points[i].strength = 1.0f; + } + + } + } + } + /* set thickness to 0 (now it is a factor to override stroke thickness) */ + gpl->thickness = 0.0f; + } + /* set first color as active */ + if (palette->colors.first) + gpencil_palettecolor_setactive(palette, palette->colors.first); + } + } + } + /* ------- end of grease pencil initialization --------------- */ + } + } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 0ed7a397e0b..ec817b9b261 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -108,6 +108,11 @@ void BLO_update_defaults_startup_blend(Main *bmain) brush->strength = 0.5f; brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; + brush = &gset->brush[GP_EDITBRUSH_TYPE_STRENGTH]; + brush->size = 25; + brush->strength = 0.5f; + brush->flag = GP_EDITBRUSH_FLAG_USE_FALLOFF; + brush = &gset->brush[GP_EDITBRUSH_TYPE_GRAB]; brush->size = 50; brush->strength = 0.3f; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ba783e08b39..fb31cd227ba 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2673,6 +2673,20 @@ static void write_scenes(WriteData *wd, ListBase *scebase) writestruct(wd, DATA, UvSculpt, 1, tos->uvsculpt); write_paint(wd, &tos->uvsculpt->paint); } + /* write grease-pencil drawing brushes to file */ + writelist(wd, DATA, bGPDbrush, &tos->gp_brushes); + for (bGPDbrush *brush = tos->gp_brushes.first; brush; brush = brush->next) { + if (brush->cur_sensitivity) { + write_curvemapping(wd, brush->cur_sensitivity); + } + if (brush->cur_strength) { + write_curvemapping(wd, brush->cur_strength); + } + if (brush->cur_jitter) { + write_curvemapping(wd, brush->cur_jitter); + } + } + write_paint(wd, &tos->imapaint.paint); @@ -2835,6 +2849,7 @@ static void write_gpencils(WriteData *wd, ListBase *lb) bGPDlayer *gpl; bGPDframe *gpf; bGPDstroke *gps; + bGPDpalette *palette; for (gpd = lb->first; gpd; gpd = gpd->id.next) { if (gpd->id.us > 0 || wd->current) { @@ -2861,6 +2876,11 @@ static void write_gpencils(WriteData *wd, ListBase *lb) } } } + /* write grease-pencil palettes */ + writelist(wd, DATA, bGPDpalette, &gpd->palettes); + for (palette = gpd->palettes.first; palette; palette = palette->next) { + writelist(wd, DATA, bGPDpalettecolor, &palette->colors); + } } } -- cgit v1.2.3 From 357480f8c3710cdd6331c86a8ee0f28bfaf4f507 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Thu, 4 Aug 2016 15:03:18 +0200 Subject: Cleanup: Use BKE_gpencil prefix This is a good point to change this as grease-pencil-v2 branch was just merged, so I hope merge conflicts with other branches are minimal. --- source/blender/blenloader/intern/versioning_270.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index c4fec3ed824..af95649a559 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1270,7 +1270,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; if (BLI_listbase_is_empty(&ts->gp_brushes)) { - gpencil_brush_init_presets(ts); + BKE_gpencil_brush_init_presets(ts); } } } @@ -1280,10 +1280,10 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) { if (BLI_listbase_is_empty(&gpd->palettes)) { /* create palette */ - bGPDpalette *palette = gpencil_palette_addnew(gpd, "GP_Palette", true); + bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette", true); for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* create color using layer name */ - bGPDpalettecolor *palcolor = gpencil_palettecolor_addnew(palette, gpl->info, true); + bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info, true); if (palcolor != NULL) { /* set color attributes */ copy_v4_v4(palcolor->color, gpl->color); @@ -1314,7 +1314,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } /* set first color as active */ if (palette->colors.first) - gpencil_palettecolor_setactive(palette, palette->colors.first); + BKE_gpencil_palettecolor_setactive(palette, palette->colors.first); } } } -- cgit v1.2.3 From 61050f75b13ef706d3a80b86137436d3fb0bfa93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Sat, 6 Aug 2016 06:20:37 +0200 Subject: Basic Alembic support All in all, this patch adds an Alembic importer, an Alembic exporter, and a new CacheFile data block which, for now, wraps around an Alembic archive. This data block is made available through a new modifier ("Mesh Sequence Cache") as well as a new constraint ("Transform Cache") to somewhat properly support respectively geometric and transformation data streaming from alembic caches. A more in-depth documentation is to be found on the wiki, as well as a guide to compile alembic: https://wiki.blender.org/index.php/ User:Kevindietrich/AlembicBasicIo. Many thanks to everyone involved in this little project, and huge shout out to "cgstrive" for the thorough testings with Maya, 3ds Max, Houdini and Realflow as well as @fjuhec, @jensverwiebe and @jasperge for the custom builds and compile fixes. Reviewers: sergey, campbellbarton, mont29 Reviewed By: sergey, campbellbarton, mont29 Differential Revision: https://developer.blender.org/D2060 --- source/blender/blenloader/CMakeLists.txt | 7 +++++ source/blender/blenloader/intern/readfile.c | 47 ++++++++++++++++++++++++++++ source/blender/blenloader/intern/writefile.c | 17 ++++++++++ 3 files changed, 71 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 479d3a15e6c..8cb9ef837b2 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -77,6 +77,13 @@ if(WITH_CODEC_FFMPEG) add_definitions(-DWITH_FFMPEG) endif() +if(WITH_ALEMBIC) + list(APPEND INC + ../alembic + ) + add_definitions(-DWITH_ALEMBIC) +endif() + blender_add_lib(bf_blenloader "${SRC}" "${INC}" "${INC_SYS}") # needed so writefile.c can use dna_type_offsets.h diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 52ca8520b46..eb94c91389c 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -59,6 +59,7 @@ #include "DNA_actuator_types.h" #include "DNA_brush_types.h" #include "DNA_camera_types.h" +#include "DNA_cachefile_types.h" #include "DNA_cloth_types.h" #include "DNA_controller_types.h" #include "DNA_constraint_types.h" @@ -114,6 +115,7 @@ #include "BKE_action.h" #include "BKE_armature.h" #include "BKE_brush.h" +#include "BKE_cachefile.h" #include "BKE_cloth.h" #include "BKE_constraint.h" #include "BKE_context.h" @@ -2691,6 +2693,36 @@ static void direct_link_animdata(FileData *fd, AnimData *adt) adt->actstrip = newdataadr(fd, adt->actstrip); } +/* ************ READ CACHEFILES *************** */ + +static void lib_link_cachefiles(FileData *fd, Main *bmain) +{ + CacheFile *cache_file; + + /* only link ID pointers */ + for (cache_file = bmain->cachefiles.first; cache_file; cache_file = cache_file->id.next) { + if (cache_file->id.tag & LIB_TAG_NEED_LINK) { + cache_file->id.tag &= ~LIB_TAG_NEED_LINK; + } + + BLI_listbase_clear(&cache_file->object_paths); + cache_file->handle = NULL; + + if (cache_file->adt) { + lib_link_animdata(fd, &cache_file->id, cache_file->adt); + } + } +} + +static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) +{ + cache_file->handle = NULL; + + /* relink animdata */ + cache_file->adt = newdataadr(fd, cache_file->adt); + direct_link_animdata(fd, cache_file->adt); +} + /* ************ READ MOTION PATHS *************** */ /* direct data for cache */ @@ -7912,6 +7944,7 @@ static const char *dataname(short id_code) case ID_MC: return "Data from MC"; case ID_MSK: return "Data from MSK"; case ID_LS: return "Data from LS"; + case ID_CF: return "Data from CF"; } return "Data from Lib Block"; @@ -8163,6 +8196,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short case ID_PC: direct_link_paint_curve(fd, (PaintCurve *)id); break; + case ID_CF: + direct_link_cachefile(fd, (CacheFile *)id); + break; } oldnewmap_free_unused(fd->datamap); @@ -8356,6 +8392,7 @@ static void lib_link_all(FileData *fd, Main *main) lib_link_mask(fd, main); lib_link_linestyle(fd, main); lib_link_gpencil(fd, main); + lib_link_cachefiles(fd, main); lib_link_mesh(fd, main); /* as last: tpage images with users at zero */ @@ -9462,6 +9499,13 @@ static void expand_camera(FileData *fd, Main *mainvar, Camera *ca) expand_animdata(fd, mainvar, ca->adt); } +static void expand_cachefile(FileData *fd, Main *mainvar, CacheFile *cache_file) +{ + if (cache_file->adt) { + expand_animdata(fd, mainvar, cache_file->adt); + } +} + static void expand_speaker(FileData *fd, Main *mainvar, Speaker *spk) { expand_doit(fd, mainvar, spk->sound); @@ -9657,6 +9701,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar) case ID_GD: expand_gpencil(fd, mainvar, (bGPdata *)id); break; + case ID_CF: + expand_cachefile(fd, mainvar, (CacheFile *)id); + break; } do_it = true; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index fb31cd227ba..b6a54715763 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -107,6 +107,7 @@ #include "DNA_armature_types.h" #include "DNA_actuator_types.h" #include "DNA_brush_types.h" +#include "DNA_cachefile_types.h" #include "DNA_camera_types.h" #include "DNA_cloth_types.h" #include "DNA_constraint_types.h" @@ -3882,6 +3883,21 @@ static void write_linestyles(WriteData *wd, ListBase *idbase) } } +static void write_cachefiles(WriteData *wd, ListBase *idbase) +{ + CacheFile *cache_file; + + for (cache_file = idbase->first; cache_file; cache_file = cache_file->id.next) { + if (cache_file->id.us > 0 || wd->current) { + writestruct(wd, ID_CF, CacheFile, 1, cache_file); + + if (cache_file->adt) { + write_animdata(wd, cache_file->adt); + } + } + } +} + /* Keep it last of write_foodata functions. */ static void write_libraries(WriteData *wd, Main *main) { @@ -4079,6 +4095,7 @@ static bool write_file_handle( write_paintcurves(wd, &mainvar->paintcurves); write_gpencils(wd, &mainvar->gpencil); write_linestyles(wd, &mainvar->linestyle); + write_cachefiles(wd, &mainvar->cachefiles); write_libraries(wd, mainvar->next); /* So changes above don't cause a 'DNA1' to be detected as changed on undo. */ -- cgit v1.2.3 From 04c7d9d56674f97d14c393488439c93a343823b4 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 12 Aug 2016 14:59:11 +0200 Subject: Depsgraph: tag relations for update when aterial slots changes New dependency graph puts materials to the graph in order to deal with animation assigned to them and things like that. This leads us to a requirement to update relations when slots changes. This fixes: T49075 Assignment of a keyframed material using the frame_change_pre handler doesn't update the keyframe using the new dependency graph --- source/blender/blenloader/intern/readfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index eb94c91389c..161ab3a2b82 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4774,7 +4774,7 @@ static void lib_link_object(FileData *fd, Main *main) /* Only expand so as not to loose any object materials that might be set. */ if (totcol_data && (*totcol_data > ob->totcol)) { /* printf("'%s' %d -> %d\n", ob->id.name, ob->totcol, *totcol_data); */ - BKE_material_resize_object(ob, *totcol_data, false); + BKE_material_resize_object(main, ob, *totcol_data, false); } } -- cgit v1.2.3 From 25872cae291235ec49298419a2fa141a1c98cbb9 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Sat, 13 Aug 2016 01:29:17 +0200 Subject: Fix error in GPencil V2 version patching GPencil conversion would just always run for file version 2.77.3. This wasn't an issue in master, but possibly for other branches that used the 2.77.3 block. Wasn't aware that you have to add the asterisk for pointers either, this is kinda weird. Anyway, it's running correctly now. --- source/blender/blenloader/intern/versioning_270.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index af95649a559..f41aba1b5b0 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1246,7 +1246,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) if (!MAIN_VERSION_ATLEAST(main, 277, 3)) { /* ------- init of grease pencil initialization --------------- */ - if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "palcolor")) { + if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "bGPDpalettecolor", "*palcolor")) { for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; /* initialize use position for sculpt brushes */ -- cgit v1.2.3 From b1677201f9af7a3e5f5254817179f12384fbdc44 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 16 Aug 2016 10:32:55 +0200 Subject: Rework 2D stabilizator See this page for motivation and description of concepts: https://github.com/Ichthyostega/blender/wiki See this video for UI explanation and demonstration of usage http://vimeo.com/blenderHack/stabilizerdemo This proposal attempts to improve usability of Blender's image stabilization feature for real-world footage esp. with moving and panning camera. It builds upon the feature tracking to get a measurement of 2D image movement. - Use a weighted average of movement contributions (instead of a median). - Allow for rotation compensation and zoom (image scale) compensation. - Allow to pick a different set of tracks for translation and for rotation/zoom. - Treat translation / rotation / zoom contributions systematically in a similar way. - Improve handling of partial tracking data with gaps and varying start / end points. - Have a user definable anchor frame and interpolate / extrapolate data to avoid jumping back to "neutral" position when no tracking data is available. - Support for travelling and panning shots by including an //intended// position/rotation/zoom ("target position"). The idea is for these parameters to be //animated// by the user, in order to supply an smooth, intended camera movement. This way, we can keep the image content roughly in frame even when moving completely away from the initial view. A known shortcoming is that the pivot point for rotation compensation is set to the translation compensated image center. This can produce spurious rotation on travelling shots, which needs to be compensated manually (by animating the target rotation parameter). There are several possible ways to address that problem, yet all of them are considered beyond the scope of this improvement proposal for now. Own modifications: - Restrict line length, it's really handy for split-view editing - In motion tracking we prefer fully human-readable comments, meaning we don't use doxygen with it's weird markup and comments are supposed to start with capital and end with a full stop, - Add explicit comparison of pointer to NULL. Reviewers: sergey Subscribers: kusi, kdawg, forest-house, mardy, Samoth, plasmasolutions, willolis, sebastian_k, hype, enetheru, sunboy, jta, leon_cheung Maniphest Tasks: T49036 Differential Revision: https://developer.blender.org/D583 --- source/blender/blenloader/intern/readfile.c | 2 +- source/blender/blenloader/intern/versioning_270.c | 58 +++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 161ab3a2b82..ded60af4af2 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7478,7 +7478,7 @@ static void direct_link_movieclip(FileData *fd, MovieClip *clip) clip->tracking_context = NULL; clip->tracking.stats = NULL; - clip->tracking.stabilization.ok = 0; + /* Needed for proper versioning, will be NULL for all newer files anyway. */ clip->tracking.stabilization.rot_track = newdataadr(fd, clip->tracking.stabilization.rot_track); clip->tracking.dopesheet.ok = 0; diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index f41aba1b5b0..394547757e9 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -63,6 +63,7 @@ #include "BKE_scene.h" #include "BKE_sequencer.h" #include "BKE_screen.h" +#include "BKE_tracking.h" #include "BKE_gpencil.h" #include "BLI_math.h" @@ -75,6 +76,26 @@ #include "MEM_guardedalloc.h" +/** + * Setup rotation stabilization from ancient single track spec. + * Former Version of 2D stabilization used a single tracking marker to determine the rotation + * to be compensated. Now several tracks can contribute to rotation detection and this feature + * is enabled by the MovieTrackingTrack#flag on a per track base. + */ +static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabilization *stab) +{ + if (stab->rot_track) { + if (!(stab->rot_track->flag & TRACK_USE_2D_STAB_ROT)) { + stab->tot_rot_track++; + stab->rot_track->flag |= TRACK_USE_2D_STAB_ROT; + } + } + stab->rot_track = NULL; /* this field is now ignored */ + + /* by default show the track lists expanded, to improve "discoverability" */ + stab->flag |= TRACKING_SHOW_STAB_TRACKS; +} + static void do_version_constraints_radians_degrees_270_1(ListBase *lb) { bConstraint *con; @@ -1321,4 +1342,41 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) /* ------- end of grease pencil initialization --------------- */ } + if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) { + MovieClip *clip; + for (clip = main->movieclip.first; clip; clip = clip->id.next) { + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *tracking_object; + for (tracking_object = tracking->objects.first; + tracking_object != NULL; + tracking_object = tracking_object->next) + { + ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object); + MovieTrackingTrack *track; + for (track = tracksbase->first; + track != NULL; + track = track->next) + { + track->weight_stab = track->weight; + } + } + } + } + + if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) { + + MovieClip *clip; + for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) { + if (clip->tracking.stabilization.rot_track) { + migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization); + + if (!clip->tracking.stabilization.scale) { + /* ensure init. + * Was previously used for autoscale only, + * now used always (as "target scale") */ + clip->tracking.stabilization.scale = 1.0f; + } + } + } + } } -- cgit v1.2.3 From 5e8c09921e58e1f86d61e825bc8f446bb134ed0d Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 16 Aug 2016 13:30:47 +0200 Subject: 2D stabilization: Modify interface so dependency goes strictly from top to bottom --- source/blender/blenloader/intern/versioning_270.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 394547757e9..45c73edf908 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -91,9 +91,6 @@ static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabili } } stab->rot_track = NULL; /* this field is now ignored */ - - /* by default show the track lists expanded, to improve "discoverability" */ - stab->flag |= TRACKING_SHOW_STAB_TRACKS; } static void do_version_constraints_radians_degrees_270_1(ListBase *lb) -- cgit v1.2.3 From e3576c7bf45a6b5666df093b8194a3c5e4b67a2e Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 16 Aug 2016 13:53:29 +0200 Subject: Correct previous commit, need to indent verisoning code --- source/blender/blenloader/intern/versioning_270.c | 56 +++++++++++------------ 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 45c73edf908..18b60883977 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1339,39 +1339,39 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) /* ------- end of grease pencil initialization --------------- */ } - if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) { - MovieClip *clip; - for (clip = main->movieclip.first; clip; clip = clip->id.next) { - MovieTracking *tracking = &clip->tracking; - MovieTrackingObject *tracking_object; - for (tracking_object = tracking->objects.first; - tracking_object != NULL; - tracking_object = tracking_object->next) - { - ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object); - MovieTrackingTrack *track; - for (track = tracksbase->first; - track != NULL; - track = track->next) + { + if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) { + MovieClip *clip; + for (clip = main->movieclip.first; clip; clip = clip->id.next) { + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *tracking_object; + for (tracking_object = tracking->objects.first; + tracking_object != NULL; + tracking_object = tracking_object->next) { - track->weight_stab = track->weight; + ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object); + MovieTrackingTrack *track; + for (track = tracksbase->first; + track != NULL; + track = track->next) + { + track->weight_stab = track->weight; + } } } } - } - if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) { - - MovieClip *clip; - for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) { - if (clip->tracking.stabilization.rot_track) { - migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization); - - if (!clip->tracking.stabilization.scale) { - /* ensure init. - * Was previously used for autoscale only, - * now used always (as "target scale") */ - clip->tracking.stabilization.scale = 1.0f; + if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingStabilization", "int", "tot_rot_track")) { + MovieClip *clip; + for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) { + if (clip->tracking.stabilization.rot_track) { + migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization); + if (!clip->tracking.stabilization.scale) { + /* ensure init. + * Was previously used for autoscale only, + * now used always (as "target scale") */ + clip->tracking.stabilization.scale = 1.0f; + } } } } -- cgit v1.2.3 From b7d656c3b24cee4400d8bd4d5e5184e7657227ef Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 16 Aug 2016 14:25:55 +0200 Subject: 2D stabilizer: Revert majority of UI change For now simply reshuffle option so they keep proper dependency flow. Benefits: - Has an ability to hide tracks lists to work with other sliders around. Could be really handy to quickly get rid of lenghty lists. - From a feedback seems to be fitting workflow better. Things to doublecheck on: - Feels a bit misordered: first you define whether one want to have rotation stabilized, then have tracks, then scale options. While this follows dependency flow (which is really good and which we should not violate) it has weird feeling on whether things are really where they have to be. - Autoscale controls visibility of max-scale, can we just make it active/inactive instead? - Autoscale replaces slider with label. Can it be disabled slider instead to reduce visual jumping (disabled slider prevents user input) Hopefully we'll still want to have collapsable box after re-iterating over this points, so we don't waste bits in DNA. --- source/blender/blenloader/intern/versioning_270.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 18b60883977..d735f099dc0 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -91,6 +91,9 @@ static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabili } } stab->rot_track = NULL; /* this field is now ignored */ + + /* by default show the track lists expanded, to improve "discoverability" */ + stab->flag |= TRACKING_SHOW_STAB_TRACKS; } static void do_version_constraints_radians_degrees_270_1(ListBase *lb) -- cgit v1.2.3 From 2e6d4270cdd4dab1964af4427f833846e4aef4a7 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 18 Aug 2016 15:45:20 +0200 Subject: Cleanup/security fix: do not use strcpy (at least in new code). This function is only really secure in a very limited amount of cases, and can especially bite you later if you change some buffer sizes... So not worth bothering with it, just always use BLI_strncpy instead. --- source/blender/blenloader/intern/versioning_270.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index d735f099dc0..f6ac42c1941 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1318,7 +1318,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* set stroke to palette and force recalculation */ - strcpy(gps->colorname, gpl->info); + BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname)); gps->palcolor = NULL; gps->flag |= GP_STROKE_RECALC_COLOR; gps->thickness = gpl->thickness; -- cgit v1.2.3 From 3dbe1744402c2790d7854f09cf977bb275436479 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 22 Aug 2016 17:22:06 +0200 Subject: 2D stabilization: flip orientation of the scale parameter values > 1 will zoom in and values < 1 zoom out Rationale: the changed orientation is more natural from a user POV and doing it this way is also more consistent with the calculation of the other target_* parameters. Compatibility: This will break *.blend files saved with the previous version of this patch from the last days (test period). It will *not* break any old/migrated files: Previously, the DNA field "scale" was only used to cache autoscale. Only with the Stabilisator rework, "scale" becomes a first class persistent DNA field. There is migration code to init this field to 1.0 --- source/blender/blenloader/intern/versioning_270.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index f6ac42c1941..1ef32d6f006 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -91,9 +91,6 @@ static void migrate_single_rot_stabilization_track_settings(MovieTrackingStabili } } stab->rot_track = NULL; /* this field is now ignored */ - - /* by default show the track lists expanded, to improve "discoverability" */ - stab->flag |= TRACKING_SHOW_STAB_TRACKS; } static void do_version_constraints_radians_degrees_270_1(ListBase *lb) @@ -1369,13 +1366,17 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) for (clip = main->movieclip.first; clip != NULL; clip = clip->id.next) { if (clip->tracking.stabilization.rot_track) { migrate_single_rot_stabilization_track_settings(&clip->tracking.stabilization); - if (!clip->tracking.stabilization.scale) { - /* ensure init. - * Was previously used for autoscale only, - * now used always (as "target scale") */ - clip->tracking.stabilization.scale = 1.0f; - } } + if (clip->tracking.stabilization.scale == 0.0f) { + /* ensure init. + * Was previously used for autoscale only, + * now used always (as "target scale") */ + clip->tracking.stabilization.scale = 1.0f; + } + /* by default show the track lists expanded, to improve "discoverability" */ + clip->tracking.stabilization.flag |= TRACKING_SHOW_STAB_TRACKS; + /* deprecated, not used anymore */ + clip->tracking.stabilization.ok = false; } } } -- cgit v1.2.3 From 498ba756abeec746322b883d98ba6a192f37e7ea Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 22 Aug 2016 17:29:19 +0200 Subject: 2D stabilization: by default init anchor_frame to frame 1 It is common in blender to use 1-based counting for frame sequences (while 0-based is allowed). Thus initializing to use frame 1 as reference for stabilization is likely to produce smooth start values in most cases --- source/blender/blenloader/intern/versioning_270.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 1ef32d6f006..49ef8baa184 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1373,6 +1373,9 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) * now used always (as "target scale") */ clip->tracking.stabilization.scale = 1.0f; } + /* blender prefers 1-based frame counting; + * thus using frame 1 as reference typically works best */ + clip->tracking.stabilization.anchor_frame = 1; /* by default show the track lists expanded, to improve "discoverability" */ clip->tracking.stabilization.flag |= TRACKING_SHOW_STAB_TRACKS; /* deprecated, not used anymore */ -- cgit v1.2.3 From 2d1f522a74a8637c9cc64509ed26be6d014e5871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 25 Aug 2016 16:22:26 +0200 Subject: Fixed little error in comment "amount" is for uncountable things, "number" is for countable things. --- source/blender/blenloader/intern/writefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index b6a54715763..dbc67d30b35 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -49,7 +49,7 @@ * int, len data after BHead * void, old pointer * int - * int, in case of array: amount of structs + * int, in case of array: number of structs * data * ... * ... -- cgit v1.2.3 From a80977cd213d1a158f4292b9809c85a5b2a7a699 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 26 Aug 2016 12:54:49 +0200 Subject: Fix T49139: Memory leak in UV image editor related to Undo (and possibly Waveform and Vectorscope). Assigning NULL to scopes' data pointer in 'non-UI readfile' context was terribly wrong for sure, if we'd really want to reset them here we should freed them first. But we can rather just ignore them here, those are purely runtime data managed by image editor, no need to touch them here. --- source/blender/blenloader/intern/readfile.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index ded60af4af2..7d65dbc2e17 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -6697,10 +6697,13 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc * since it gets initialized later */ sima->iuser.scene = NULL; - sima->scopes.waveform_1 = NULL; - sima->scopes.waveform_2 = NULL; - sima->scopes.waveform_3 = NULL; - sima->scopes.vecscope = NULL; +#if 0 + /* Those are allocated and freed by space code, no need to handle them here. */ + MEM_SAFE_FREE(sima->scopes.waveform_1); + MEM_SAFE_FREE(sima->scopes.waveform_2); + MEM_SAFE_FREE(sima->scopes.waveform_3); + MEM_SAFE_FREE(sima->scopes.vecscope); +#endif sima->scopes.ok = 0; /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data -- cgit v1.2.3 From 62b1cdd66e39db58e422e15b20a80d5e05f3dd4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Fri, 26 Aug 2016 14:25:03 +0200 Subject: Fix over creation of cache files handles (leading to memory leaks). Multiple threads could create multiple handles for the same cache file, so protect handle creation with a mutex, to make sure only one is created. --- source/blender/blenloader/intern/readfile.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 7d65dbc2e17..f5bfe1f4de6 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2707,6 +2707,7 @@ static void lib_link_cachefiles(FileData *fd, Main *bmain) BLI_listbase_clear(&cache_file->object_paths); cache_file->handle = NULL; + cache_file->handle_mutex = NULL; if (cache_file->adt) { lib_link_animdata(fd, &cache_file->id, cache_file->adt); @@ -2717,6 +2718,7 @@ static void lib_link_cachefiles(FileData *fd, Main *bmain) static void direct_link_cachefile(FileData *fd, CacheFile *cache_file) { cache_file->handle = NULL; + cache_file->handle_mutex = NULL; /* relink animdata */ cache_file->adt = newdataadr(fd, cache_file->adt); -- cgit v1.2.3 From 195c7797e68ec99d8a4a6c396a74264d7d836189 Mon Sep 17 00:00:00 2001 From: Joshua Leung Date: Mon, 29 Aug 2016 17:00:18 +1200 Subject: Fix: Some settings (e.g. "volumetric strokes") from old files were not getting correctly ported to GPv2 --- source/blender/blenloader/intern/versioning_270.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 49ef8baa184..0a36e7846fe 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1306,12 +1306,20 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) /* set color attributes */ copy_v4_v4(palcolor->color, gpl->color); copy_v4_v4(palcolor->fill, gpl->fill); - palcolor->flag = gpl->flag; + + if (gpl->flag & GP_LAYER_HIDE) palcolor->flag |= PC_COLOR_HIDE; + if (gpl->flag & GP_LAYER_LOCKED) palcolor->flag |= PC_COLOR_LOCKED; + if (gpl->flag & GP_LAYER_ONIONSKIN) palcolor->flag |= PC_COLOR_ONIONSKIN; + if (gpl->flag & GP_LAYER_VOLUMETRIC) palcolor->flag |= PC_COLOR_VOLUMETRIC; + if (gpl->flag & GP_LAYER_HQ_FILL) palcolor->flag |= PC_COLOR_HQ_FILL; + /* set layer opacity to 1 */ gpl->opacity = 1.0f; + /* set tint color */ ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f); - + + /* flush relevant layer-settings to strokes */ for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { /* set stroke to palette and force recalculation */ @@ -1319,14 +1327,15 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) gps->palcolor = NULL; gps->flag |= GP_STROKE_RECALC_COLOR; gps->thickness = gpl->thickness; + /* set alpha strength to 1 */ for (int i = 0; i < gps->totpoints; i++) { gps->points[i].strength = 1.0f; } - } } } + /* set thickness to 0 (now it is a factor to override stroke thickness) */ gpl->thickness = 0.0f; } -- cgit v1.2.3 From 159ac3f638df5b1a569aaab8800de9671f0667c9 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 1 Sep 2016 21:16:54 +0200 Subject: Fix T49224: Crash due to dangling value in 'Object.proxy_from' pointer. Why/how this may happen remains a mystery, so for now simply clearing this runtime-only pointer on Object reading... --- source/blender/blenloader/intern/readfile.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f5bfe1f4de6..57d499fbe91 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5303,6 +5303,9 @@ static void direct_link_object(FileData *fd, Object *ob) */ ob->recalc = 0; + /* XXX This should not be needed - but seems like it can happen in some cases, so for now play safe... */ + ob->proxy_from = NULL; + /* loading saved files with editmode enabled works, but for undo we like * to stay in object mode during undo presses so keep editmode disabled. * -- cgit v1.2.3 From 98d28a8a6c503a217a1fe9377e6219f8d512fe11 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 2 Sep 2016 11:37:25 +0200 Subject: Blender 2.78 commit! Includes: - Version bump to 2.78 - Doxy file update - New splash screen - Wrapped some do_versions with version check - Updated template to use proper font After poking around a lot it seems Droid Sans was used during 2.7x series. (or at least difference between using this font and comparing to previous splash screens gives none visible difference). --- source/blender/blenloader/intern/versioning_270.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 0a36e7846fe..dfaa59c4e3f 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1348,7 +1348,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) /* ------- end of grease pencil initialization --------------- */ } - { + if (!MAIN_VERSION_ATLEAST(main, 278, 0)) { if (!DNA_struct_elem_find(fd->filesdna, "MovieTrackingTrack", "float", "weight_stab")) { MovieClip *clip; for (clip = main->movieclip.first; clip; clip = clip->id.next) { -- cgit v1.2.3 From bcc863993adfe019454d2da014528ac922fffd41 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 7 Sep 2016 12:45:58 +0200 Subject: Fix T49273: Crash during access to dupli weights at launch time. See commit's comments for details, but this boils down to: do not try to use purely runtime cache data as a 'real' ID pointer in readcode, it's likely doomed to fail in some cases, and is bad practice in any case! Thix fix implies dupliweight's object will be invalid until first scene update (i.e. first particles evaluation). --- source/blender/blenloader/intern/readfile.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 57d499fbe91..60f276b1744 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4105,8 +4105,14 @@ static void lib_link_particlesettings(FileData *fd, Main *main) if (index_ok) { /* if we have indexes, let's use them */ for (dw = part->dupliweights.first; dw; dw = dw->next) { - GroupObject *go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index); - dw->ob = go ? go->ob : NULL; + /* Do not try to restore pointer here, we have to search for group objects in another + * separated step. + * Reason is, the used group may be linked from another library, which has not yet + * been 'lib_linked'. + * Since dw->ob is not considered as an object user (it does not make objet directly linked), + * we may have no valid way to retrieve it yet. + * See T49273. */ + dw->ob = NULL; } } else { -- cgit v1.2.3 From 16ed49b26ec3b181fd72b37bcbce0f96551bc939 Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Mon, 19 Sep 2016 16:46:20 +0200 Subject: UI Messages: Consistent spelling of term "data-block" Was using a bunch of different spellings, mostly "data-block" though, so went with that one (would have been my #1 choice anyway ;) ) --- source/blender/blenloader/intern/writefile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index dbc67d30b35..49e5255eccc 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -3949,7 +3949,7 @@ static void write_libraries(WriteData *wd, Main *main) for (id = lbarray[a]->first; id; id = id->next) { if (id->us > 0 && (id->tag & LIB_TAG_EXTERN)) { if (!BKE_idcode_is_linkable(GS(id->name))) { - printf("ERROR: write file: datablock '%s' from lib '%s' is not linkable " + printf("ERROR: write file: data-block '%s' from lib '%s' is not linkable " "but is flagged as directly linked", id->name, main->curlib->filepath); BLI_assert(0); } -- cgit v1.2.3 From a7e74791221e2ef9b44ee1b3eb9ece37785aa62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 21 Sep 2016 15:01:51 +0200 Subject: FFmpeg interface improvements This patch changes a couple of things in the video output encoding. {F362527} - Clearer separation between container and codec. No more "format", as this is too ambiguous. As a result, codecs were removed from the container list. - Added FFmpeg speed presets, so the user can choosen from the range "Very slow" to "Ultra fast". By default no preset is used. - Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate depending on the desired quality and the input. This generally produces the best quality videos, at the expense of not knowing the exact bit-rate and file size. - Added optional maximum of non-B-frames between B-frames (`max_b_frames`). - Presets were adjusted for these changes, and new presets added. One of the new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264) for reviewing videos, as it allows players to scrub through it easily. Might be nice in weeklies. This preset also requires control over the `max_b_frames` setting. GUI-only changes: - Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more accurate. After all, FFmpeg is used when this option is chosen, which can also output non-MPEG files. - Certain parts of the GUI are disabled when not in use: - bit rate options are not used when a constant rate factor is given. - audio bitrate & volume are not used when no audio is exported. Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a good idea to determine whether we want to keep it at all. After this patch has been accepted, I'd be happy to go through the code and remove any then-obsolete bits, such as the handling of "XVID" as a container format. Reviewers: sergey, mont29, brecht Subscribers: mpan3, Blendify, brecht, fsiddi Tags: #bf_blender Differential Revision: https://developer.blender.org/D2242 --- source/blender/blenloader/intern/versioning_270.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index dfaa59c4e3f..aa5ef1c98cf 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1392,4 +1392,18 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + if (!MAIN_VERSION_ATLEAST(main, 279, 0)) { + if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "ffmpeg_preset")) { + for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { + /* "medium" is the preset FFmpeg uses when no presets are given. */ + scene->r.ffcodecdata.ffmpeg_preset = FFM_PRESET_MEDIUM; + } + } + if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "constant_rate_factor")) { + for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { + /* fall back to behaviour from before we introduced CRF for old files */ + scene->r.ffcodecdata.constant_rate_factor = FFM_CRF_NONE; + } + } + } } -- cgit v1.2.3 From 4446acbf17748f30b163016cfc4b88bba8653517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Sat, 24 Sep 2016 21:41:16 +0200 Subject: Viewport smoke: add support for axis aligned slicing. Current approach uses view aligned slicing to generate polygons for GL texturing such that the generated polygons are always facing the view plane. Now it is also possible to use object aligned slicing, which creates polygons by slicing the object perpendicular to whichever axis is facing the most the view plane. It is also possible to create a single slice for inspecting the volume, or for 2D rendering effects. Settings for this, along with a density multiplier setting, are to be found in a newly added "Smoke Display Settings" panel in the smoke domain properties tab. Reviewers: plasmasolutions, gottfried Differential Revision: https://developer.blender.org/D1733 --- source/blender/blenloader/intern/versioning_270.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index aa5ef1c98cf..0d4ff00b775 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -52,6 +52,7 @@ #include "DNA_linestyle_types.h" #include "DNA_actuator_types.h" #include "DNA_view3d_types.h" +#include "DNA_smoke_types.h" #include "DNA_genfile.h" @@ -1405,5 +1406,23 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) scene->r.ffcodecdata.constant_rate_factor = FFM_CRF_NONE; } } + + if (!DNA_struct_elem_find(fd->filesdna, "SmokeModifierData", "float", "slice_per_voxel")) { + Object *ob; + ModifierData *md; + + for (ob = main->object.first; ob; ob = ob->id.next) { + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if (smd->domain) { + smd->domain->slice_per_voxel = 5.0f; + smd->domain->slice_depth = 0.5f; + smd->domain->display_thickness = 1.0f; + } + } + } + } + } } } -- cgit v1.2.3 From cbd3827d839b2ff28ae535f674e63611cb1c2c6c Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Wed, 28 Sep 2016 15:06:50 +0200 Subject: Fix T49460: Particle group instance 'Use Count' value gets reset on file-load. Regression caused rBbcc863993ad, write code was assuming dw->ob was always valid, wich is no more the case right after reading file e.g. Another good example of how bad it is to use 'hidden' dependencies between datablocks. :( And another fix to be backported to 2.78a. :((( --- source/blender/blenloader/intern/writefile.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 49e5255eccc..6678189872c 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1306,13 +1306,11 @@ static void write_particlesettings(WriteData *wd, ListBase *idbase) dw = part->dupliweights.first; for (; dw; dw = dw->next) { - /* update indices */ - dw->index = 0; - if (part->dup_group) { /* can be NULL if lining fails or set to None */ - go = part->dup_group->gobject.first; - while (go && go->ob != dw->ob) { - go = go->next; - dw->index++; + /* update indices, but only if dw->ob is set (can be NULL after loading e.g.) */ + if (dw->ob != NULL) { + dw->index = 0; + if (part->dup_group) { /* can be NULL if lining fails or set to None */ + for (go = part->dup_group->gobject.first; go && go->ob != dw->ob; go = go->next, dw->index++); } } writestruct(wd, DATA, ParticleDupliWeight, 1, dw); -- cgit v1.2.3 From 85d543b4acb35750ea81e12cc7c1cc5db55ce361 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 30 Sep 2016 10:11:29 +0200 Subject: Fix T49489: Pose marker in camera action + marker bound to camera -> crash. 'camera' Object pointer of TimeMarkers is a 'temp' hack since Durian project... Would need to be either made definitive now, or removed/reworked/whatever. But since we intend to use that object pointer for other needs, and current code could lead to crashing .blend files, for now let's fix that mess (was missing some bits in read code, and also totally ignored in libquery code). Should be safe for 2.78a. --- source/blender/blenloader/intern/readfile.c | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 60f276b1744..d86a89a0e48 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2511,6 +2511,12 @@ static void lib_link_action(FileData *fd, Main *main) // >>> XXX deprecated - old animation system lib_link_fcurves(fd, &act->id, &act->curves); + + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + if (marker->camera) { + marker->camera = newlibadr(fd, act->id.lib, marker->camera); + } + } } } } @@ -5608,7 +5614,6 @@ static void lib_link_scene(FileData *fd, Main *main) Base *base, *next; Sequence *seq; SceneRenderLayer *srl; - TimeMarker *marker; FreestyleModuleConfig *fmc; FreestyleLineSet *fls; @@ -5709,15 +5714,11 @@ static void lib_link_scene(FileData *fd, Main *main) } SEQ_END -#ifdef DURIAN_CAMERA_SWITCH - for (marker = sce->markers.first; marker; marker = marker->next) { + for (TimeMarker *marker = sce->markers.first; marker; marker = marker->next) { if (marker->camera) { marker->camera = newlibadr(fd, sce->id.lib, marker->camera); } } -#else - (void)marker; -#endif BKE_sequencer_update_muting(sce->ed); BKE_sequencer_update_sound_bounds_all(sce); @@ -8860,6 +8861,12 @@ static void expand_action(FileData *fd, Main *mainvar, bAction *act) /* F-Curves in Action */ expand_fcurves(fd, mainvar, &act->curves); + + for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) { + if (marker->camera) { + expand_doit(fd, mainvar, marker->camera); + } + } } static void expand_keyingsets(FileData *fd, Main *mainvar, ListBase *list) @@ -9490,17 +9497,11 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce) expand_doit(fd, mainvar, sce->rigidbody_world->constraints); } -#ifdef DURIAN_CAMERA_SWITCH - { - TimeMarker *marker; - - for (marker = sce->markers.first; marker; marker = marker->next) { - if (marker->camera) { - expand_doit(fd, mainvar, marker->camera); - } + for (TimeMarker *marker = sce->markers.first; marker; marker = marker->next) { + if (marker->camera) { + expand_doit(fd, mainvar, marker->camera); } } -#endif expand_doit(fd, mainvar, sce->clip); } -- cgit v1.2.3 From 0a2a006775543292786e8642b20a594771fdc81c Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 7 Oct 2016 13:27:11 +0300 Subject: Collision: skip expensive BVH update if the collider doesn't move. Since the collision modifier cannot be disabled, it causes a constant hit on the viewport animation playback FPS. Most of this overhead can be automatically removed in the case when the collider is static. The updates are only skipped when the collider was stationary during the preceding update as well, so the state is stored in a field. Knowing that the collider is static can also be used to disable similar BVH updates for substeps in the actual cloth simulation code. Differential Revision: https://developer.blender.org/D2277 --- source/blender/blenloader/intern/readfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index d86a89a0e48..139cb84fea1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5192,6 +5192,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) collmd->time_x = collmd->time_xnew = -1000; collmd->mvert_num = 0; collmd->tri_num = 0; + collmd->is_static = false; collmd->bvhtree = NULL; collmd->tri = NULL; -- cgit v1.2.3 From 00dc0666b3fedfbb24aef0e636a3227746e465f2 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sat, 8 Oct 2016 15:18:35 +0200 Subject: Fix T49608: runtime-only particle's boid->ground Object pointer was left dangling to invalid value in read code... --- source/blender/blenloader/intern/readfile.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 139cb84fea1..e3b06b07222 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4277,12 +4277,14 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) psys->flag &= ~PSYS_KEYED; } - + if (psys->particles && psys->particles->boid) { pa = psys->particles; pa->boid = newdataadr(fd, pa->boid); - for (a=1, pa++; atotpart; a++, pa++) - pa->boid = (pa-1)->boid + 1; + for (a = 1, pa++; a < psys->totpart; a++, pa++) { + pa->boid = (pa - 1)->boid + 1; + pa->boid->ground = NULL; /* This is purely runtime data, but still can be an issue if left dangling. */ + } } else if (psys->particles) { for (a=0, pa=psys->particles; atotpart; a++, pa++) -- cgit v1.2.3 From c2758706732871166eef845ce017b2f0c7b1fddf Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sat, 8 Oct 2016 19:13:50 +0200 Subject: Ammend to rB00dc0666b3fe: forgot to fix boid->ground of first particle. This code is confusing, such dirty details should not sneak out of particles' own private code. :( --- source/blender/blenloader/intern/readfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index e3b06b07222..c1da78d3877 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4281,9 +4281,10 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles) if (psys->particles && psys->particles->boid) { pa = psys->particles; pa->boid = newdataadr(fd, pa->boid); + pa->boid->ground = NULL; /* This is purely runtime data, but still can be an issue if left dangling. */ for (a = 1, pa++; a < psys->totpart; a++, pa++) { pa->boid = (pa - 1)->boid + 1; - pa->boid->ground = NULL; /* This is purely runtime data, but still can be an issue if left dangling. */ + pa->boid->ground = NULL; } } else if (psys->particles) { -- cgit v1.2.3 From 7f19c4fdf920c47d288a279af64bcf151e021877 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 17 Oct 2016 12:37:50 +0200 Subject: Fix T49738: Hair Add Brush doesn't work the issue was caused by wrong default value for brush particle count which was clamped on display from 0 to 1. This is technically a regression but how to port this to 2.78a? --- source/blender/blenloader/intern/versioning_270.c | 14 ++++++++++++++ source/blender/blenloader/intern/versioning_defaults.c | 1 + 2 files changed, 15 insertions(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 0d4ff00b775..a2a10f5ccd8 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1425,4 +1425,18 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } + + { + for (Scene *scene = main->scene.first; scene != NULL; scene = scene->id.next) { + if (scene->toolsettings != NULL) { + ToolSettings *ts = scene->toolsettings; + ParticleEditSettings *pset = &ts->particle; + for (int a = 0; a < PE_TOT_BRUSH; a++) { + if (pset->brush[a].count == 0) { + pset->brush[a].count = 10; + } + } + } + } + } } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index ec817b9b261..99d9e140481 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -147,6 +147,7 @@ void BLO_update_defaults_startup_blend(Main *bmain) ParticleEditSettings *pset = &ts->particle; for (int a = 0; a < PE_TOT_BRUSH; a++) { pset->brush[a].strength = 0.5f; + pset->brush[a].count = 10; } pset->brush[PE_BRUSH_CUT].strength = 1.0f; } -- cgit v1.2.3 From cccd3eb5a8107cd215fc5e3b8ecdf275ed5c48f2 Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Mon, 17 Oct 2016 19:43:35 +0000 Subject: Fixup for doversion (rB8d573aa0 and rBa7e74791) --- source/blender/blenloader/intern/versioning_270.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index a2a10f5ccd8..14e02c9ffb6 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -1393,7 +1393,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main) } } } - if (!MAIN_VERSION_ATLEAST(main, 279, 0)) { + if (!MAIN_VERSION_ATLEAST(main, 278, 2)) { if (!DNA_struct_elem_find(fd->filesdna, "FFMpegCodecData", "int", "ffmpeg_preset")) { for (Scene *scene = main->scene.first; scene; scene = scene->id.next) { /* "medium" is the preset FFmpeg uses when no presets are given. */ -- cgit v1.2.3 From 5f0933f07a548719a850d9cac01aae6709b9dc0b Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 27 Oct 2016 09:51:10 +0200 Subject: Fix T49829: Removal of custom icon previews during add-on unregister crashes Blender. Issue was happening when removal of custom icons was done while they were still being rendered by preview job. Now add a 'deffered deletion' system, to prevent main thread to delete preview image until loading thread is done with them. Note that ideally, calling `ED_preview_kill_jobs()` on custom icon removal would have been simpler, but we don't have easy access to context here... --- source/blender/blenloader/intern/readfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index c1da78d3877..41b275751d1 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2147,6 +2147,7 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p prv->gputexture[i] = NULL; } prv->icon_id = 0; + prv->tag = 0; } return prv; -- cgit v1.2.3