diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-07-04 12:22:15 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2018-07-04 12:33:27 +0300 |
commit | 769c57b38a707397ac7fdda15b1deb561194b66c (patch) | |
tree | c618131eb63627c5a353c8ba1437c359b72ddbad /source/blender/blenloader | |
parent | 9e4d667c2cfd4a81f9a69628b69facd8fd4e0a01 (diff) |
SoftBody: share point cache between CoW copies
This is the same approach as 98a0bcd4252e952fa5438e9d1b69b0204f8a8746
applied to soft body simulation. In short, CoW copies share the point cache,
and treat it as read-only except when the depsgraph is active.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 13 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 19 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 8 |
3 files changed, 37 insertions, 3 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 79a552a5b86..2a48bf8fc5a 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5437,7 +5437,18 @@ static void direct_link_object(FileData *fd, Object *ob) if (!sb->effector_weights) sb->effector_weights = BKE_add_effector_weights(NULL); - direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, 0); + sb->shared = newdataadr(fd, sb->shared); + if (sb->shared == NULL) { + /* Link deprecated caches if they exist, so we can use them for versioning. + * We should only do this when sb->shared == NULL, because those pointers + * are always set (for compatibility with older Blenders). We mustn't link + * the same pointcache twice. */ + direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, false); + } + else { + /* link caches */ + direct_link_pointcache_list(fd, &sb->shared->ptcaches, &sb->shared->pointcache, false); + } } ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */ diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 3fa059989a3..757e17ce82b 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -1559,5 +1559,24 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!DNA_struct_elem_find(fd->filesdna, "SoftBody", "SoftBody_Shared", "*shared")) { + for (Object *ob = bmain->object.first; ob; ob = ob->id.next) { + SoftBody *sb = ob->soft; + if (sb == NULL) { + continue; + } + if (sb->shared == NULL) { + sb->shared = MEM_callocN(sizeof(*sb->shared), "SoftBody_Shared"); + } + + /* Move shared pointers from deprecated location to current location */ + sb->shared->pointcache = sb->pointcache; + sb->shared->ptcaches = sb->ptcaches; + + sb->pointcache = NULL; + BLI_listbase_clear(&sb->ptcaches); + } + } + } } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index e7bca4c7e5b..146494e6196 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -1816,9 +1816,13 @@ static void write_object(WriteData *wd, Object *ob) write_motionpath(wd, ob->mpath); writestruct(wd, DATA, PartDeflect, 1, ob->pd); - writestruct(wd, DATA, SoftBody, 1, ob->soft); if (ob->soft) { - write_pointcaches(wd, &ob->soft->ptcaches); + /* Set deprecated pointers to prevent crashes of older Blenders */ + ob->soft->pointcache = ob->soft->shared->pointcache; + ob->soft->ptcaches = ob->soft->shared->ptcaches; + writestruct(wd, DATA, SoftBody, 1, ob->soft); + writestruct(wd, DATA, SoftBody_Shared, 1, ob->soft->shared); + write_pointcaches(wd, &(ob->soft->shared->ptcaches)); writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights); } |