[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33996] trunk/blender: Pointcache code cleanup and disk cache compression options:

Janne Karhu jhkarh at gmail.com
Sun Jan 2 07:53:16 CET 2011


Revision: 33996
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33996
Author:   jhk
Date:     2011-01-02 07:52:47 +0100 (Sun, 02 Jan 2011)

Log Message:
-----------
Pointcache code cleanup and disk cache compression options:
* Massive reorganization of pointcache code, things are now cleaner than ever.
* For all but smoke the cache is first written to memory when using disk cache and after that written to disk in one operation. This allows less disk operations and the possibility to compress the data before writing it to disk.
* Previously only smoke cache could be compressed, now the same options exist for other physics types too (when using disk cache). For now the default compression option is still "no compression", but if there aren't any problems this can be set to "light compression" as it's actually faster than no compression in most cases since there's less data to write to the disk. Based on quick tests heavy compression can reduce the file size down to 1/3rd of the original size, but is really slow compared to other options, so it should be used only if file size is critical!
* The pointcache code wasn't really 64bit compatible (for disk cache) until now, so this update should fix some crashes on 64bit builds too. Now all integer data that's saved to disk uses 32 bit unsigned integers, so simulations done on 64bit should load fine on 32bit machines and vice versa. (Important disk cache simulations made on 64bit builds should be converted to memory cache in a revision before this commit).
* There are also the beginnings of extradata handling code in pointcache in anticipation of adding the dynamic springs for particle fluids (the springs need to be stored as extradata into point cache).
* Particles were being read from the cache with a slightly wrong framerate. In most cases this probably wasn't noticeable, but none the less the code is now correct in every way.
* Small other fixes here and there & some cosmetic changes to cache panel, but over all there should be no functional changes other than the new disk cache compression options.
* This whole re-organization also seems to fix bug #25436 and hopefully shouldn't introduce any new ones!

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/properties_physics_common.py
    trunk/blender/source/blender/blenkernel/BKE_pointcache.h
    trunk/blender/source/blender/blenkernel/intern/cloth.c
    trunk/blender/source/blender/blenkernel/intern/particle_system.c
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/blenkernel/intern/smoke.c
    trunk/blender/source/blender/blenkernel/intern/softbody.c
    trunk/blender/source/blender/makesdna/DNA_object_force.h
    trunk/blender/source/blender/makesrna/intern/rna_object_force.c

Modified: trunk/blender/release/scripts/ui/properties_physics_common.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_physics_common.py	2011-01-02 04:16:19 UTC (rev 33995)
+++ trunk/blender/release/scripts/ui/properties_physics_common.py	2011-01-02 06:52:47 UTC (rev 33996)
@@ -69,23 +69,27 @@
             row.prop(cache, "frame_end")
         if cachetype not in ('SMOKE', 'CLOTH'):
             row.prop(cache, "frame_step")
+            row.prop(cache, "use_quick_cache")
         if cachetype != 'SMOKE':
             layout.label(text=cache.info)
 
         if cachetype != 'SMOKE':
             split = layout.split()
+            split.enabled = enabled and (not bpy.data.is_dirty)
 
             col = split.column()
-            col.enabled = enabled
-            col.prop(cache, "use_quick_cache")
+            col.prop(cache, "use_disk_cache")
 
             col = split.column()
-            col.enabled = (not bpy.data.is_dirty)
-            col.prop(cache, "use_disk_cache")
-            sub = col.column()
-            sub.enabled = cache.use_disk_cache
-            sub.prop(cache, "use_library_path", "Use Lib Path")
+            col.active = cache.use_disk_cache
+            col.prop(cache, "use_library_path", "Use Lib Path")
 
+            row = layout.row()
+            row.enabled = enabled and (not bpy.data.is_dirty)
+            row.active = cache.use_disk_cache
+            row.label(text="Compression:")
+            row.prop(cache, "compression", expand=True)
+
         layout.separator()
 
         split = layout.split()

Modified: trunk/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2011-01-02 04:16:19 UTC (rev 33995)
+++ trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2011-01-02 06:52:47 UTC (rev 33996)
@@ -63,6 +63,13 @@
 #define PTCACHE_TYPE_SMOKE_DOMAIN		3
 #define PTCACHE_TYPE_SMOKE_HIGHRES		4
 
+/* high bits reserved for flags that need to be stored in file */
+#define PTCACHE_TYPEFLAG_COMPRESS		(1<<16)
+#define PTCACHE_TYPEFLAG_EXTRADATA		(1<<17)
+
+#define PTCACHE_TYPEFLAG_TYPEMASK			0x0000FFFF
+#define PTCACHE_TYPEFLAG_FLAGMASK			0xFFFF0000
+
 /* PTCache read return code */
 #define PTCACHE_READ_EXACT				1
 #define PTCACHE_READ_INTERPOLATED		2
@@ -96,7 +103,7 @@
 	FILE *fp;
 
 	int totpoint, type, frame, old_format;
-	unsigned int data_types;
+	unsigned int data_types, flag;
 
 	struct PTCacheData data;
 	void *cur[BPHYS_TOT_DATA];
@@ -118,16 +125,24 @@
 	unsigned int data_types, info_types;
 
 	/* copies point data to cache data */
-	int (*write_elem)(int index, void *calldata, void **data, int cfra);
+	int (*write_point)(int index, void *calldata, void **data, int cfra);
+	/* copies cache cata to point data */
+	void (*read_point)(int index, void *calldata, void **data, float cfra, float *old_data);
+	/* interpolated between previously read point data and cache data */
+	void (*interpolate_point)(int index, void *calldata, void **data, float cfra, float cfra1, float cfra2, float *old_data);
+
 	/* copies point data to cache data */
 	int (*write_stream)(PTCacheFile *pf, void *calldata);
 	/* copies cache cata to point data */
-	void (*read_elem)(int index, void *calldata, void **data, float frs_sec, float cfra, float *old_data);
-	/* copies cache cata to point data */
 	void (*read_stream)(PTCacheFile *pf, void *calldata);
-	/* interpolated between previously read point data and cache data */
-	void (*interpolate_elem)(int index, void *calldata, void **data, float frs_sec, float cfra, float cfra1, float cfra2, float *old_data);
 
+	/* copies custom extradata to cache data */
+	int (*write_extra_data)(void *calldata, struct PTCacheMem *pm, int cfra);
+	/* copies custom extradata to cache data */
+	int (*read_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra);
+	/* copies custom extradata to cache data */
+	int (*interpolate_extra_data)(void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2);
+
 	/* total number of simulated points (the cfra parameter is just for using same function pointer with totwrite) */
 	int (*totpoint)(void *calldata, int cfra);
 	/* number of points written for current cache frame */
@@ -267,7 +282,7 @@
 void	BKE_ptcache_data_set(void **data, int type, void *from);
 
 /* Main cache reading call. */
-int		BKE_ptcache_read(PTCacheID *pid, float cfra, float frs_sec);
+int		BKE_ptcache_read(PTCacheID *pid, float cfra);
 
 /* Main cache writing call. */
 int		BKE_ptcache_write(PTCacheID *pid, int cfra);

Modified: trunk/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/cloth.c	2011-01-02 04:16:19 UTC (rev 33995)
+++ trunk/blender/source/blender/blenkernel/intern/cloth.c	2011-01-02 06:52:47 UTC (rev 33996)
@@ -504,7 +504,7 @@
 	}
 
 	/* try to read from cache */
-	cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, scene->r.frs_sec);
+	cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe);
 
 	if(cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
 		implicit_set_positions(clmd);

Modified: trunk/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle_system.c	2011-01-02 04:16:19 UTC (rev 33995)
+++ trunk/blender/source/blender/blenkernel/intern/particle_system.c	2011-01-02 06:52:47 UTC (rev 33996)
@@ -2244,7 +2244,9 @@
 	if(cache->flag & PTCACHE_DISK_CACHE && cache->mem_cache.first == NULL) {
 		PTCacheID pid;
 		BKE_ptcache_id_from_particles(&pid, ob, psys);
+		cache->flag &= ~PTCACHE_DISK_CACHE;
 		BKE_ptcache_disk_to_mem(&pid);
+		cache->flag |= PTCACHE_DISK_CACHE;
 	}
 }
 static void psys_clear_temp_pointcache(ParticleSystem *psys)
@@ -3795,7 +3797,7 @@
 
 /* 2. try to read from the cache */
 	if(pid) {
-		int cache_result = BKE_ptcache_read(pid, cache_cfra, sim->scene->r.frs_sec);
+		int cache_result = BKE_ptcache_read(pid, cache_cfra);
 
 		if(ELEM(cache_result, PTCACHE_READ_EXACT, PTCACHE_READ_INTERPOLATED)) {
 			cached_step(sim, cfra);

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2011-01-02 04:16:19 UTC (rev 33995)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2011-01-02 06:52:47 UTC (rev 33996)
@@ -96,7 +96,7 @@
 #define DURIAN_POINTCACHE_LIB_OK 1
 
 int ptcache_data_size[] = {	
-		sizeof(int), // BPHYS_DATA_INDEX
+		sizeof(uint32_t), // BPHYS_DATA_INDEX
 		3 * sizeof(float), // BPHYS_DATA_LOCATION:
 		3 * sizeof(float), // BPHYS_DATA_VELOCITY:
 		4 * sizeof(float), // BPHYS_DATA_ROTATION:
@@ -107,30 +107,38 @@
 };
 
 /* forward declerations */
-static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, int size);
-static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, int size);
+static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, size_t len);
+static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, size_t in_len, unsigned char *out, int mode);
+static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, size_t size);
+static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, size_t size);
 
 /* Common functions */
 static int ptcache_basic_header_read(PTCacheFile *pf)
 {
+	uint32_t totpoint, data_types;
 	int error=0;
 
 	/* Custom functions should read these basic elements too! */
-	if(!error && !fread(&pf->totpoint, sizeof(int), 1, pf->fp))
+	if(!error && !fread(&totpoint, sizeof(int), 1, pf->fp))
 		error = 1;
+	pf->totpoint = totpoint;
 	
-	if(!error && !fread(&pf->data_types, sizeof(int), 1, pf->fp))
+	if(!error && !fread(&data_types, sizeof(int), 1, pf->fp))
 		error = 1;
+	pf->data_types = data_types;
 
 	return !error;
 }
 static int ptcache_basic_header_write(PTCacheFile *pf)
 {
+	uint32_t totpoint = pf->totpoint;
+	uint32_t data_types = pf->data_types;
+
 	/* Custom functions should write these basic elements too! */
-	if(!fwrite(&pf->totpoint, sizeof(int), 1, pf->fp))
+	if(!fwrite(&totpoint, sizeof(int), 1, pf->fp))
 		return 0;
 	
-	if(!fwrite(&pf->data_types, sizeof(int), 1, pf->fp))
+	if(!fwrite(&data_types, sizeof(int), 1, pf->fp))
 		return 0;
 
 	return 1;
@@ -146,7 +154,7 @@
 
 	return 1;
 }
-static void ptcache_softbody_read(int index, void *soft_v, void **data, float UNUSED(frs_sec), float UNUSED(cfra), float *old_data)
+static void ptcache_softbody_read(int index, void *soft_v, void **data, float UNUSED(cfra), float *old_data)
 {
 	SoftBody *soft= soft_v;
 	BodyPoint *bp = soft->bpoint + index;
@@ -160,7 +168,7 @@
 		PTCACHE_DATA_TO(data, BPHYS_DATA_VELOCITY, 0, bp->vec);
 	}
 }
-static void ptcache_softbody_interpolate(int index, void *soft_v, void **data, float UNUSED(frs_sec), float cfra, float cfra1, float cfra2, float *old_data)
+static void ptcache_softbody_interpolate(int index, void *soft_v, void **data, float cfra, float cfra1, float cfra2, float *old_data)
 {
 	SoftBody *soft= soft_v;
 	BodyPoint *bp = soft->bpoint + index;
@@ -244,11 +252,12 @@
 	/* return flag 1+1=2 for newly born particles to copy exact birth location to previously cached frame */
 	return 1 + (pa->state.time >= pa->time && pa->prev_state.time <= pa->time);
 }
-static void ptcache_particle_read(int index, void *psys_v, void **data, float frs_sec, float cfra, float *old_data)
+static void ptcache_particle_read(int index, void *psys_v, void **data, float cfra, float *old_data)
 {
 	ParticleSystem *psys= psys_v;
 	ParticleData *pa;
 	BoidParticle *boid;
+	float timestep = 0.04f*psys->part->timetweak;
 
 	if(index >= psys->totpart)
 		return;
@@ -289,11 +298,11 @@
 	if(data[BPHYS_DATA_LOCATION] && !data[BPHYS_DATA_VELOCITY]) {
 		if(cfra > pa->prev_state.time) {
 			sub_v3_v3v3(pa->state.vel, pa->state.co, pa->prev_state.co);
-			mul_v3_fl(pa->state.vel, (cfra - pa->prev_state.time) / frs_sec);
+			mul_v3_fl(pa->state.vel, (cfra - pa->prev_state.time) * timestep);
 		}
 		else {
 			sub_v3_v3v3(pa->state.vel, pa->prev_state.co, pa->state.co);
-			mul_v3_fl(pa->state.vel, (pa->prev_state.time - cfra) / frs_sec);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list