[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34205] trunk/blender/source/blender: Replace uint32_t in pointcache code with unsigned int as it' s supported in dna

Janne Karhu jhkarh at gmail.com
Sun Jan 9 19:23:42 CET 2011


Revision: 34205
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34205
Author:   jhk
Date:     2011-01-09 18:23:41 +0000 (Sun, 09 Jan 2011)
Log Message:
-----------
Replace uint32_t in pointcache code with unsigned int as it's supported in dna
* Not strictly necessary right now, but better for future.
* Struct data (only boids at the moment) is now written as structs (with dna) so they work between 64 and 32 bit machines too.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_pointcache.h
    trunk/blender/source/blender/blenkernel/intern/pointcache.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/makesdna/DNA_boid_types.h
    trunk/blender/source/blender/makesdna/DNA_object_force.h

Modified: trunk/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2011-01-09 18:15:00 UTC (rev 34204)
+++ trunk/blender/source/blender/blenkernel/BKE_pointcache.h	2011-01-09 18:23:41 UTC (rev 34205)
@@ -89,7 +89,7 @@
 
 /* temp structure for read/write */
 typedef struct PTCacheData {
-	uint32_t index;
+	unsigned int index;
 	float loc[3];
 	float vel[3];
 	float rot[4];
@@ -99,10 +99,22 @@
 	struct BoidData boids;
 } PTCacheData;
 
+static char *ptcache_datastruct[] = {
+	"", // BPHYS_DATA_INDEX
+	"", // BPHYS_DATA_LOCATION
+	"", // BPHYS_DATA_VELOCITY
+	"", // BPHYS_DATA_ROTATION
+	"", // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST */
+	"", // BPHYS_DATA_SIZE:
+	"", // BPHYS_DATA_TIMES:	
+	"BoidData" // case BPHYS_DATA_BOIDS:
+};
+
 typedef struct PTCacheFile {
 	FILE *fp;
 
-	int totpoint, type, frame, old_format;
+	int frame, old_format;
+	unsigned int totpoint, type;
 	unsigned int data_types, flag;
 
 	struct PTCacheData data;
@@ -117,9 +129,9 @@
 	struct Scene *scene;
 	struct Object *ob;
 	void *calldata;
-	int type;
-	int stack_index;
-	int flag;
+	unsigned int type;
+	unsigned int stack_index;
+	unsigned int flag;
 
 	/* flags defined in DNA_object_force.h */
 	unsigned int data_types, info_types;
@@ -257,7 +269,7 @@
 void BKE_ptcache_remove(void);
 
 /************ ID specific functions ************************/
-void	BKE_ptcache_id_clear(PTCacheID *id, int mode, int cfra);
+void	BKE_ptcache_id_clear(PTCacheID *id, int mode, unsigned int cfra);
 int		BKE_ptcache_id_exist(PTCacheID *id, int cfra);
 int		BKE_ptcache_id_reset(struct Scene *scene, PTCacheID *id, int mode);
 void	BKE_ptcache_id_time(PTCacheID *pid, struct Scene *scene, float cfra, int *startframe, int *endframe, float *timescale);
@@ -271,7 +283,7 @@
 int		BKE_ptcache_data_size(int data_type);
 
 /* Is point with indes in memory cache */
-int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, int index);
+int BKE_ptcache_mem_index_find(struct PTCacheMem *pm, unsigned int index);
 
 /* Memory cache read/write helpers. */
 void BKE_ptcache_mem_pointers_init(struct PTCacheMem *pm);
@@ -288,7 +300,7 @@
 int		BKE_ptcache_read(PTCacheID *pid, float cfra);
 
 /* Main cache writing call. */
-int		BKE_ptcache_write(PTCacheID *pid, int cfra);
+int		BKE_ptcache_write(PTCacheID *pid, unsigned int cfra);
 
 /****************** Continue physics ***************/
 void BKE_ptcache_set_continue_physics(struct Main *bmain, struct Scene *scene, int enable);

Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c	2011-01-09 18:15:00 UTC (rev 34204)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c	2011-01-09 18:23:41 UTC (rev 34205)
@@ -98,49 +98,43 @@
 #define DURIAN_POINTCACHE_LIB_OK 1
 
 int ptcache_data_size[] = {	
-		sizeof(uint32_t), // BPHYS_DATA_INDEX
-		3 * sizeof(float), // BPHYS_DATA_LOCATION:
-		3 * sizeof(float), // BPHYS_DATA_VELOCITY:
-		4 * sizeof(float), // BPHYS_DATA_ROTATION:
-		3 * sizeof(float), // BPHYS_DATA_AVELOCITY: /* also BPHYS_DATA_XCONST */
-		sizeof(float), // BPHYS_DATA_SIZE:
-		3 * sizeof(float), // BPHYS_DATA_TIMES:	
-		sizeof(BoidData) // case BPHYS_DATA_BOIDS:
+		sizeof(unsigned int), // BPHYS_DATA_INDEX
+		3 * sizeof(float), // BPHYS_DATA_LOCATION
+		3 * sizeof(float), // BPHYS_DATA_VELOCITY
+		4 * sizeof(float), // BPHYS_DATA_ROTATION
+		3 * sizeof(float), // BPHYS_DATA_AVELOCITY / BPHYS_DATA_XCONST
+		sizeof(float), // BPHYS_DATA_SIZE
+		3 * sizeof(float), // BPHYS_DATA_TIMES
+		sizeof(BoidData) // case BPHYS_DATA_BOIDS
 };
 
 /* forward declerations */
-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);
+static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, unsigned int len);
+static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, unsigned int in_len, unsigned char *out, int mode);
+static int ptcache_file_write(PTCacheFile *pf, void *f, unsigned int tot, unsigned int size);
+static int ptcache_file_read(PTCacheFile *pf, void *f, unsigned int tot, unsigned int size);
 
 /* Common functions */
 static int ptcache_basic_header_read(PTCacheFile *pf)
 {
-	uint32_t totpoint, data_types= 0;
 	int error=0;
 
 	/* Custom functions should read these basic elements too! */
-	if(!error && !fread(&totpoint, sizeof(int), 1, pf->fp))
+	if(!error && !fread(&pf->totpoint, sizeof(unsigned int), 1, pf->fp))
 		error = 1;
-	pf->totpoint = totpoint;
 	
-	if(!error && !fread(&data_types, sizeof(int), 1, pf->fp))
+	if(!error && !fread(&pf->data_types, sizeof(unsigned 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(&totpoint, sizeof(int), 1, pf->fp))
+	if(!fwrite(&pf->totpoint, sizeof(unsigned int), 1, pf->fp))
 		return 0;
 	
-	if(!fwrite(&data_types, sizeof(int), 1, pf->fp))
+	if(!fwrite(&pf->data_types, sizeof(unsigned int), 1, pf->fp))
 		return 0;
 
 	return 1;
@@ -969,7 +963,7 @@
 	}
 }
 
-static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, size_t len)
+static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, unsigned int len)
 {
 	int r = 0;
 	unsigned char compressed = 0;
@@ -983,8 +977,8 @@
 
 	ptcache_file_read(pf, &compressed, 1, sizeof(unsigned char));
 	if(compressed) {
-		uint32_t size;
-		ptcache_file_read(pf, &size, 1, sizeof(uint32_t));
+		unsigned int size;
+		ptcache_file_read(pf, &size, 1, sizeof(unsigned int));
 		in_len = (size_t)size;
 		if(in_len==0) {
 			/* do nothing */
@@ -1017,7 +1011,7 @@
 
 	return r;
 }
-static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, size_t in_len, unsigned char *out, int mode)
+static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, unsigned int in_len, unsigned char *out, int mode)
 {
 	int r = 0;
 	unsigned char compressed = 0;
@@ -1042,7 +1036,7 @@
 #ifdef WITH_LZMA
 	if(mode == 2) {
 		
-		r = LzmaCompress(out, (size_t *)&out_len, in, in_len,//assume sizeof(char)==1....
+		r = LzmaCompress(out, &out_len, in, in_len,//assume sizeof(char)==1....
 						props, &sizeOfIt, 5, 1 << 24, 3, 0, 2, 32, 2);
 
 		if(!(r == SZ_OK) || (out_len >= in_len))
@@ -1054,8 +1048,8 @@
 	
 	ptcache_file_write(pf, &compressed, 1, sizeof(unsigned char));
 	if(compressed) {
-		uint32_t size = (uint32_t) out_len;
-		ptcache_file_write(pf, &size, 1, sizeof(uint32_t));
+		unsigned int size = out_len;
+		ptcache_file_write(pf, &size, 1, sizeof(unsigned int));
 		ptcache_file_write(pf, out, out_len, sizeof(unsigned char));
 	}
 	else
@@ -1063,19 +1057,20 @@
 
 	if(compressed == 2)
 	{
-		ptcache_file_write(pf, &sizeOfIt, 1, sizeof(uint32_t));
-		ptcache_file_write(pf, props, sizeOfIt, sizeof(unsigned char));
+		unsigned int size = sizeOfIt;
+		ptcache_file_write(pf, &sizeOfIt, 1, sizeof(unsigned int));
+		ptcache_file_write(pf, props, size, sizeof(unsigned char));
 	}
 
 	MEM_freeN(props);
 
 	return r;
 }
-static int ptcache_file_read(PTCacheFile *pf, void *f, size_t tot, size_t size)
+static int ptcache_file_read(PTCacheFile *pf, void *f, unsigned int tot, unsigned int size)
 {
 	return (fread(f, size, tot, pf->fp) == tot);
 }
-static int ptcache_file_write(PTCacheFile *pf, void *f, size_t tot, size_t size)
+static int ptcache_file_write(PTCacheFile *pf, void *f, unsigned int tot, unsigned int size)
 {
 	return (fwrite(f, size, tot, pf->fp) == tot);
 }
@@ -1103,7 +1098,7 @@
 }
 static int ptcache_file_header_begin_read(PTCacheFile *pf)
 {
-	uint32_t typeflag=0;
+	unsigned int typeflag=0;
 	int error=0;
 	char bphysics[8];
 	
@@ -1115,7 +1110,7 @@
 	if(!error && strncmp(bphysics, "BPHYSICS", 8))
 		error = 1;
 
-	if(!error && !fread(&typeflag, sizeof(uint32_t), 1, pf->fp))
+	if(!error && !fread(&typeflag, sizeof(unsigned int), 1, pf->fp))
 		error = 1;
 
 	pf->type = (typeflag & PTCACHE_TYPEFLAG_TYPEMASK);
@@ -1130,12 +1125,12 @@
 static int ptcache_file_header_begin_write(PTCacheFile *pf)
 {
 	const char *bphysics = "BPHYSICS";
-	uint32_t typeflag = pf->type + pf->flag;
+	unsigned int typeflag = pf->type + pf->flag;
 	
 	if(fwrite(bphysics, sizeof(char), 8, pf->fp) != 8)
 		return 0;
 
-	if(!fwrite(&typeflag, sizeof(uint32_t), 1, pf->fp))
+	if(!fwrite(&typeflag, sizeof(unsigned int), 1, pf->fp))
 		return 0;
 	
 	return 1;
@@ -1162,26 +1157,25 @@
 }
 
 /* Check to see if point number "index" is in pm, uses binary search for index data. */
-int BKE_ptcache_mem_index_find(PTCacheMem *pm, int index)
+int BKE_ptcache_mem_index_find(PTCacheMem *pm, unsigned int index)
 {
 	if(pm->data[BPHYS_DATA_INDEX]) {
-		uint32_t key = index;
-		uint32_t *data = pm->data[BPHYS_DATA_INDEX];
-		uint32_t mid, low = 0, high = pm->totpoint - 1;
+		unsigned int *data = pm->data[BPHYS_DATA_INDEX];
+		unsigned int mid, low = 0, high = pm->totpoint - 1;
 
-		if(key < *data || key > *(data+high))
+		if(index < *data || index > *(data+high))
 			return -1;
 
 		/* check simple case for continuous indexes first */
-		if(data[key-*data]==key)
-			return key-*data;
+		if(data[index-*data]==index)
+			return index-*data;
 
 		while(low <= high) {
 			mid= (low + high)/2;
 
-			if(data[mid] > key)
+			if(data[mid] > index)
 				high = mid - 1;
-			else if(data[mid] < key)
+			else if(data[mid] < index)
 				low = mid + 1;
 			else
 				return mid;
@@ -1284,7 +1278,7 @@
 	return 0;
 }
 
-static void ptcache_find_frames_around(PTCacheID *pid, int frame, int *fra1, int *fra2)
+static void ptcache_find_frames_around(PTCacheID *pid, unsigned int frame, int *fra1, int *fra2)
 {
 	if(pid->cache->flag & PTCACHE_DISK_CACHE) {
 		int cfra1=frame-1, cfra2=frame+1;
@@ -1339,7 +1333,7 @@
 {
 	PTCacheFile *pf = ptcache_file_open(pid, PTCACHE_FILE_READ, cfra);
 	PTCacheMem *pm = NULL;
-	int i, error = 0;
+	unsigned int i, error = 0;
 
 	if(pf == NULL)
 		return 0;
@@ -1382,20 +1376,16 @@
 	}
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list