[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [12632] branches/particles/source/blender: added the options to PTCache_id_clear, remove frames before, after and only the current one.
Campbell Barton
ideasman42 at gmail.com
Tue Nov 20 11:56:13 CET 2007
Revision: 12632
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=12632
Author: campbellbarton
Date: 2007-11-20 11:56:12 +0100 (Tue, 20 Nov 2007)
Log Message:
-----------
added the options to PTCache_id_clear, remove frames before,after and only the current one.
Modified Paths:
--------------
branches/particles/source/blender/blenkernel/BKE_pointcache.h
branches/particles/source/blender/blenkernel/intern/particle_system.c
branches/particles/source/blender/blenkernel/intern/pointcache.c
branches/particles/source/blender/blenkernel/intern/softbody.c
branches/particles/source/blender/src/buttons_editing.c
Modified: branches/particles/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- branches/particles/source/blender/blenkernel/BKE_pointcache.h 2007-11-19 23:45:26 UTC (rev 12631)
+++ branches/particles/source/blender/blenkernel/BKE_pointcache.h 2007-11-20 10:56:12 UTC (rev 12632)
@@ -31,11 +31,18 @@
#include "DNA_ID.h"
+/* options for clearing pointcache - used for PTCache_id_clear
+ Before and after are non inclusive (they wont remove the cfra) */
+#define PTCache_CLEAR_ALL 0
+#define PTCache_CLEAR_FRAME 1
+#define PTCache_CLEAR_BEFORE 2
+#define PTCache_CLEAR_AFTER 3
+
#define PTCache_EXT ".bphys"
#define PTCache_PATH "//pointcache/"
int PTCache_id_filename(struct ID *id, char *filename, int cfra, int stack_index, short do_path, short do_ext);
FILE * PTCache_id_fopen(struct ID *id, char mode, int cfra, int stack_index);
-void PTCache_id_clear(struct ID *id, int cfra, int stack_index);
+void PTCache_id_clear(struct ID *id, char mode, int cfra, int stack_index);
#endif
Modified: branches/particles/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle_system.c 2007-11-19 23:45:26 UTC (rev 12631)
+++ branches/particles/source/blender/blenkernel/intern/particle_system.c 2007-11-20 10:56:12 UTC (rev 12632)
@@ -1761,7 +1761,7 @@
ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys);
int stack_index = modifiers_indexInObject(ob,(ModifierData*)psmd);
- PTCache_id_clear((ID *)ob, cfra, stack_index);
+ PTCache_id_clear((ID *)ob, PTCache_CLEAR_ALL, cfra, stack_index);
}
static void write_particles_to_cache(Object *ob, ParticleSystem *psys, int cfra)
{
Modified: branches/particles/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/pointcache.c 2007-11-19 23:45:26 UTC (rev 12631)
+++ branches/particles/source/blender/blenkernel/intern/pointcache.c 2007-11-20 10:56:12 UTC (rev 12632)
@@ -78,7 +78,7 @@
newname += len;
}
idname = (id->name+2);
- /* convert chars to hex so they are always a valid file */
+ /* convert chars to hex so they are always a valid filename */
while('\0' != *idname) {
sprintf(newname, "%02X", (char)(*idname++));
newname+=2;
@@ -104,7 +104,6 @@
if (mode=='r') {
if (!BLI_exists(filename)) {
- printf("Error, file does not exist '%s'\n", filename);
return NULL;
}
fp = fopen(filename, "rb");
@@ -114,15 +113,18 @@
}
if (!fp) {
- printf("Error creating file filename '%s'\n", filename);
return NULL;
}
return fp;
}
-/* youll need to close yourself after! */
-void PTCache_id_clear(struct ID *id, int cfra, int stack_index)
+/* youll need to close yourself after!
+ * mode,
+
+*/
+
+void PTCache_id_clear(struct ID *id, char mode, int cfra, int stack_index)
{
int len; /* store the length of the string */
@@ -132,28 +134,52 @@
char path[FILE_MAX];
char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
char path_full[(FILE_MAXDIR+FILE_MAXFILE)*2];
-
- PTCache_path(path);
- len = PTCache_id_filename(id, filename, cfra, stack_index, 0, 0); /* no path */
/* clear all files in the temp dir with the prefix of the ID and the ".bphys" suffix */
-
- dir = opendir(path);
- if (dir==NULL)
- return;
-
- while ((de = readdir(dir)) != NULL) {
- //if (S_ISREG(status.st_mode)) { /* is file */
+ switch (mode) {
+ case PTCache_CLEAR_ALL:
+ case PTCache_CLEAR_BEFORE:
+ case PTCache_CLEAR_AFTER:
+ PTCache_path(path);
+ len = PTCache_id_filename(id, filename, cfra, stack_index, 0, 0); /* no path */
+
+ dir = opendir(path);
+ if (dir==NULL)
+ return;
+
+ while ((de = readdir(dir)) != NULL) {
if (strstr(de->d_name, PTCache_EXT)) { /* do we have the right extension?*/
if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */
- BLI_join_dirfile(path_full, path, de->d_name);
- BLI_delete(path_full, 0, 0);
+ if (mode == PTCache_CLEAR_ALL) {
+ BLI_join_dirfile(path_full, path, de->d_name);
+ BLI_delete(path_full, 0, 0);
+ } else {
+ /* read the number of the file */
+ int frame, len2 = strlen(de->d_name);
+ char num[7];
+ if (len2 > 15) { /* could crash if trying to copy a string out of this range*/
+ strncpy(num, de->d_name + (strlen(de->d_name) - 15), 6);
+ frame = atoi(num);
+
+ if((mode==PTCache_CLEAR_BEFORE && frame < cfra) ||
+ (mode==PTCache_CLEAR_AFTER && frame > cfra) ) {
+
+ BLI_join_dirfile(path_full, path, de->d_name);
+ BLI_delete(path_full, 0, 0);
+ }
+ }
+ }
}
}
- //}
+ }
+ closedir(dir);
+ break;
+
+ case PTCache_CLEAR_FRAME:
+ len = PTCache_id_filename(id, filename, cfra, stack_index, 1, 1); /* no path */
+ BLI_delete(filename, 0, 0);
+ break;
}
-
- closedir(dir);
return;
}
Modified: branches/particles/source/blender/blenkernel/intern/softbody.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/softbody.c 2007-11-19 23:45:26 UTC (rev 12631)
+++ branches/particles/source/blender/blenkernel/intern/softbody.c 2007-11-20 10:56:12 UTC (rev 12632)
@@ -3203,7 +3203,7 @@
}
}
- PTCache_id_clear((ID *)ob, framenr, stack_index);
+ PTCache_id_clear((ID *)ob, PTCache_CLEAR_ALL, framenr, stack_index);
}
static void softbody_write_cache(Object *ob, float framenr)
{
Modified: branches/particles/source/blender/src/buttons_editing.c
===================================================================
--- branches/particles/source/blender/src/buttons_editing.c 2007-11-19 23:45:26 UTC (rev 12631)
+++ branches/particles/source/blender/src/buttons_editing.c 2007-11-20 10:56:12 UTC (rev 12632)
@@ -1499,7 +1499,7 @@
Object *ob = ob_v;
ModifierData *md = md_v;
int stack_index = modifiers_indexInObject(ob, md);
- PTCache_id_clear((ID *)ob, CFRA, stack_index);
+ PTCache_id_clear((ID *)ob, PTCache_CLEAR_ALL, CFRA, stack_index);
}
static void build_uvlayer_menu_vars(CustomData *data, char **menu_string,
More information about the Bf-blender-cvs
mailing list