diff options
author | Janne Karhu <jhkarh@gmail.com> | 2011-01-09 21:23:41 +0300 |
---|---|---|
committer | Janne Karhu <jhkarh@gmail.com> | 2011-01-09 21:23:41 +0300 |
commit | 1786923afc85ede081dc3ed1a3970965a61dd761 (patch) | |
tree | bd1527f5a0ab8a9b25af9b4624b7ce34bd0c7196 | |
parent | 856d9c90572491a9c462b2e7a63535e2ffc3dcf6 (diff) |
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.
-rw-r--r-- | source/blender/blenkernel/BKE_pointcache.h | 28 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pointcache.c | 137 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 5 | ||||
-rw-r--r-- | source/blender/blenloader/intern/writefile.c | 11 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_boid_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_object_force.h | 2 |
6 files changed, 90 insertions, 95 deletions
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index c7f76c033c8..68c4177fe3a 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -89,7 +89,7 @@ struct SoftBody; /* 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 @@ typedef struct PTCacheData { 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 @@ typedef struct PTCacheID { 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_ids_from_object(struct ListBase *lb, struct Object *ob, struct 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 @@ void BKE_ptcache_update_info(PTCacheID *pid); 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 @@ void BKE_ptcache_data_set(void **data, int type, void *from); 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); diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 1d58f276117..eb0601b413e 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -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 void ptcache_file_close(PTCacheFile *pf) } } -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 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, 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 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, unsigned char *result, 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 @@ static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, siz #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 @@ static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, siz 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 @@ static int ptcache_file_compressed_write(PTCacheFile *pf, unsigned char *in, siz 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_data_write(PTCacheFile *pf) } 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 @@ static int ptcache_file_header_begin_read(PTCacheFile *pf) 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_read(PTCacheFile *pf) 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 @@ static void ptcache_file_pointers_init(PTCacheFile *pf) } /* 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 @@ static int ptcache_old_elemsize(PTCacheID *pid) 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 @@ static PTCacheMem *ptcache_disk_frame_to_mem(PTCacheID *pid, int cfra) { 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 @@ static PTCacheMem *ptcache_disk_frame_to_mem(PTCacheID *pid, int cfra) } if(!error && pf->flag & PTCACHE_TYPEFLAG_EXTRADATA) { - uint32_t extratype = 0; - uint32_t value; + unsigned int extratype = 0; - while(ptcache_file_read(pf, &extratype, 1, sizeof(uint32_t))) { + while(ptcache_file_read(pf, &extratype, 1, sizeof(unsigned int))) { PTCacheExtra *extra = MEM_callocN(sizeof(PTCacheExtra), "Pointcache extradata"); extra->type = extratype; - ptcache_file_read(pf, &value, 1, sizeof(uint32_t)); - extra->flag = value; - ptcache_file_read(pf, &value, 1, sizeof(uint32_t)); - extra->totdata = value; - ptcache_file_read(pf, &value, 1, sizeof(uint32_t)); - extra->datasize = value; + ptcache_file_read(pf, &extra->flag, 1, sizeof(unsigned int)); + ptcache_file_read(pf, &extra->totdata, 1, sizeof(unsigned int)); + ptcache_file_read(pf, &extra->datasize, 1, sizeof(unsigned int)); extra->data = MEM_callocN(extra->totdata * extra->datasize, "Pointcache extradata->data"); @@ -1425,7 +1415,7 @@ static PTCacheMem *ptcache_disk_frame_to_mem(PTCacheID *pid, int cfra) static int ptcache_mem_frame_to_disk(PTCacheID *pid, PTCacheMem *pm) { PTCacheFile *pf = NULL; - int i, error = 0; + unsigned int i, error = 0; BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_FRAME, pm->frame); @@ -1479,20 +1469,15 @@ static int ptcache_mem_frame_to_disk(PTCacheID *pid, PTCacheMem *pm) if(!error && pm->extradata.first) { PTCacheExtra *extra = pm->extradata.first; - uint32_t value; for(; extra; extra=extra->next) { if(extra->data == NULL || extra->totdata == 0) continue; - value = extra->type; - ptcache_file_write(pf, &value, 1, sizeof(uint32_t)); - value = extra->flag; - ptcache_file_write(pf, &value, 1, sizeof(uint32_t)); - value = extra->totdata; - ptcache_file_write(pf, &value, 1, sizeof(uint32_t)); - value = extra->datasize; - ptcache_file_write(pf, &value, 1, sizeof(uint32_t)); + ptcache_file_write(pf, &extra->type, 1, sizeof(unsigned int)); + ptcache_file_write(pf, &extra->flag, 1, sizeof(unsigned int)); + ptcache_file_write(pf, &extra->totdata, 1, sizeof(unsigned int)); + ptcache_file_write(pf, &extra->datasize, 1, sizeof(unsigned int)); if(pid->cache->compression) { unsigned int in_len = extra->totdata * extra->datasize; @@ -1868,7 +1853,7 @@ static int ptcache_write_needed(PTCacheID *pid, int cfra, int *overwrite) return 0; } /* writes cache to disk or memory */ -int BKE_ptcache_write(PTCacheID *pid, int cfra) +int BKE_ptcache_write(PTCacheID *pid, unsigned int cfra) { PointCache *cache = pid->cache; int totpoint = pid->totpoint(pid->calldata, cfra); @@ -1909,10 +1894,10 @@ int BKE_ptcache_write(PTCacheID *pid, int cfra) */ /* Clears & resets */ -void BKE_ptcache_id_clear(PTCacheID *pid, int mode, int cfra) +void BKE_ptcache_id_clear(PTCacheID *pid, int mode, unsigned int cfra) { - int len; /* store the length of the string */ - int sta, end; + unsigned int len; /* store the length of the string */ + unsigned int sta, end; /* mode is same as fopen's modes */ DIR *dir; @@ -1961,7 +1946,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, int cfra) BLI_delete(path_full, 0, 0); } else { /* read the number of the file */ - int frame, len2 = (int)strlen(de->d_name); + unsigned int frame, len2 = (int)strlen(de->d_name); char num[7]; if (len2 > 15) { /* could crash if trying to copy a string out of this range*/ @@ -2126,8 +2111,8 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra } if(cache->cached_frames==NULL && cache->endframe > cache->startframe) { - int sta=cache->startframe; - int end=cache->endframe; + unsigned int sta=cache->startframe; + unsigned int end=cache->endframe; cache->cached_frames = MEM_callocN(sizeof(char) * (cache->endframe-cache->startframe+1), "cached frames array"); @@ -2138,7 +2123,7 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra char path[MAX_PTCACHE_PATH]; char filename[MAX_PTCACHE_FILE]; char ext[MAX_PTCACHE_PATH]; - int len; /* store the length of the string */ + unsigned int len; /* store the length of the string */ ptcache_path(pid, path); @@ -2154,7 +2139,7 @@ void BKE_ptcache_id_time(PTCacheID *pid, Scene *scene, float cfra, int *startfra if (strstr(de->d_name, ext)) { /* do we have the right extension?*/ if (strncmp(filename, de->d_name, len ) == 0) { /* do we have the right prefix */ /* read the number of the file */ - int frame, len2 = (int)strlen(de->d_name); + unsigned int frame, len2 = (int)strlen(de->d_name); char num[7]; if (len2 > 15) { /* could crash if trying to copy a string out of this range*/ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 9772074207d..cc2b73d87f5 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2939,12 +2939,11 @@ static void direct_link_pointcache(FileData *fd, PointCache *cache) for(i=0; i<BPHYS_TOT_DATA; i++) { pm->data[i] = newdataadr(fd, pm->data[i]); - /* XXX the cache saves structs and data without DNA */ - if(pm->data[i] && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { + /* the cache saves non-struct data without DNA */ + if(pm->data[i] && strcmp(ptcache_datastruct[i], "")==0 && (fd->flags & FD_FLAGS_SWITCH_ENDIAN)) { int j, tot= (BKE_ptcache_data_size (i) * pm->totpoint)/4; /* data_size returns bytes */ int *poin= pm->data[i]; - /* XXX fails for boid struct, it has 2 shorts */ for(j= 0; j<tot; j++) SWITCH_INT(poin[j]); } diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 050fd5bcaf1..8230050fc2f 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -768,9 +768,6 @@ static void write_boid_state(WriteData *wd, BoidState *state) //for(; cond; cond=cond->next) // writestruct(wd, DATA, "BoidCondition", 1, cond); } -/* TODO: replace *cache with *cachelist once it's coded */ -#define PTCACHE_WRITE_PSYS 0 -#define PTCACHE_WRITE_CLOTH 1 static void write_pointcaches(WriteData *wd, ListBase *ptcaches) { PointCache *cache = ptcaches->first; @@ -786,8 +783,12 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches) writestruct(wd, DATA, "PTCacheMem", 1, pm); for(i=0; i<BPHYS_TOT_DATA; i++) { - if(pm->data[i] && pm->data_types & (1<<i)) - writedata(wd, DATA, MEM_allocN_len(pm->data[i]), pm->data[i]); + if(pm->data[i] && pm->data_types & (1<<i)) { + if(strcmp(ptcache_datastruct[i], "")==0) + writedata(wd, DATA, MEM_allocN_len(pm->data[i]), pm->data[i]); + else + writestruct(wd, DATA, ptcache_datastruct[i], pm->totpoint, pm->data[i]); + } } } } diff --git a/source/blender/makesdna/DNA_boid_types.h b/source/blender/makesdna/DNA_boid_types.h index cabdb748a60..83f8f4d0199 100644 --- a/source/blender/makesdna/DNA_boid_types.h +++ b/source/blender/makesdna/DNA_boid_types.h @@ -106,8 +106,6 @@ typedef enum BoidMode { } BoidMode; -/* XXX WARNING!!! */ -/* BoidData is NOT in DNA, it gets saved via write_data. Do not change struct */ typedef struct BoidData { float health, acc[3]; short state_id, mode; diff --git a/source/blender/makesdna/DNA_object_force.h b/source/blender/makesdna/DNA_object_force.h index 1d1ad6ad021..a6898279a1d 100644 --- a/source/blender/makesdna/DNA_object_force.h +++ b/source/blender/makesdna/DNA_object_force.h @@ -150,7 +150,7 @@ typedef struct PTCacheExtra { typedef struct PTCacheMem { struct PTCacheMem *next, *prev; - int frame, totpoint; + unsigned int frame, totpoint; unsigned int data_types, flag; void *data[8]; /* BPHYS_TOT_DATA */ |