diff options
Diffstat (limited to 'source/blender/blenkernel/intern/pointcache.c')
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 87 |
1 files changed, 56 insertions, 31 deletions
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 4784df6e4c3..be06d4c7348 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1366,6 +1366,58 @@ static int ptcache_path(PTCacheID *pid, char *filename) return BLI_path_slash_ensure(filename); /* new strlen() */ } +static size_t ptcache_filename_ext_append(PTCacheID *pid, + char *filename, + const size_t filename_len, + const bool use_frame_number, + const int cfra) +{ + size_t len = filename_len; + char *filename_ext; + filename_ext = filename + filename_len; + *filename_ext = '\0'; + + /* PointCaches are inserted in object's list on demand, we need a valid index now. */ + if (pid->cache->index < 0) { + BLI_assert(GS(pid->owner_id->name) == ID_OB); + pid->cache->index = pid->stack_index = BKE_object_insert_ptcache((Object *)pid->owner_id); + } + + const char *ext = ptcache_file_extension(pid); + if (use_frame_number) { + if (pid->cache->flag & PTCACHE_EXTERNAL) { + if (pid->cache->index >= 0) { + len += BLI_snprintf_rlen( + filename_ext, MAX_PTCACHE_FILE - len, "_%06d_%02u%s", cfra, pid->stack_index, ext); + } + else { + len += BLI_snprintf_rlen(filename_ext, MAX_PTCACHE_FILE - len, "_%06d%s", cfra, ext); + } + } + else { + len += BLI_snprintf_rlen( + filename_ext, MAX_PTCACHE_FILE - len, "_%06d_%02u%s", cfra, pid->stack_index, ext); + } + } + else { + if (pid->cache->flag & PTCACHE_EXTERNAL) { + if (pid->cache->index >= 0) { + len += BLI_snprintf_rlen( + filename_ext, MAX_PTCACHE_FILE - len, "_%02u%s", pid->stack_index, ext); + } + else { + len += BLI_snprintf_rlen(filename_ext, MAX_PTCACHE_FILE - len, "%s", ext); + } + } + else { + len += BLI_snprintf_rlen( + filename_ext, MAX_PTCACHE_FILE - len, "_%02u%s", pid->stack_index, ext); + } + } + + return len; +} + static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_path, short do_ext) { int len = 0; @@ -1400,28 +1452,7 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p } if (do_ext) { - if (pid->cache->index < 0) { - BLI_assert(GS(pid->owner_id->name) == ID_OB); - pid->cache->index = pid->stack_index = BKE_object_insert_ptcache((Object *)pid->owner_id); - } - - const char *ext = ptcache_file_extension(pid); - - if (pid->cache->flag & PTCACHE_EXTERNAL) { - if (pid->cache->index >= 0) { - /* Always 6 chars. */ - BLI_snprintf(newname, MAX_PTCACHE_FILE - len, "_%06d_%02u%s", cfra, pid->stack_index, ext); - } - else { - /* Always 6 chars. */ - BLI_snprintf(newname, MAX_PTCACHE_FILE - len, "_%06d%s", cfra, ext); - } - } - else { - /* Always 6 chars. */ - BLI_snprintf(newname, MAX_PTCACHE_FILE - len, "_%06d_%02u%s", cfra, pid->stack_index, ext); - } - len += 16; + len += ptcache_filename_ext_append(pid, filename, (size_t)len, true, cfra); } return len; /* make sure the above string is always 16 chars */ @@ -2591,8 +2622,6 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) /*if (!G.relbase_valid) return; */ /* save blend file before using pointcache */ - const char *fext = ptcache_file_extension(pid); - /* clear all files in the temp dir with the prefix of the ID and the ".bphys" suffix */ switch (mode) { case PTCACHE_CLEAR_ALL: @@ -2615,7 +2644,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) len += 1; } - BLI_snprintf(ext, sizeof(ext), "_%02u%s", pid->stack_index, fext); + ptcache_filename_ext_append(pid, ext, 0, false, 0); while ((de = readdir(dir)) != NULL) { if (strstr(de->d_name, ext)) { /* do we have the right extension?*/ @@ -2812,9 +2841,7 @@ void BKE_ptcache_id_time( return; } - const char *fext = ptcache_file_extension(pid); - - BLI_snprintf(ext, sizeof(ext), "_%02u%s", pid->stack_index, fext); + ptcache_filename_ext_append(pid, ext, 0, false, 0); while ((de = readdir(dir)) != NULL) { if (strstr(de->d_name, ext)) { /* do we have the right extension?*/ @@ -3526,9 +3553,7 @@ void BKE_ptcache_disk_cache_rename(PTCacheID *pid, const char *name_src, const c return; } - const char *fext = ptcache_file_extension(pid); - - BLI_snprintf(ext, sizeof(ext), "_%02u%s", pid->stack_index, fext); + ptcache_filename_ext_append(pid, ext, 0, false, 0); /* put new name into cache */ BLI_strncpy(pid->cache->name, name_dst, sizeof(pid->cache->name)); |