Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/pointcache.c
| Show First 20 Lines • Show All 1,721 Lines • ▼ Show 20 Lines | if (pm->totpoint > 0 && pm->data[BPHYS_DATA_INDEX]) { | ||||
| } | } | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| return (index < pm->totpoint ? index : -1); | return (index < pm->totpoint ? index : -1); | ||||
| } | } | ||||
| void BKE_ptcache_mem_pointers_init(PTCacheMem *pm) | void BKE_ptcache_mem_pointers_init(PTCacheMem *pm, void *cur[BPHYS_TOT_DATA]) | ||||
| { | { | ||||
| int data_types = pm->data_types; | int data_types = pm->data_types; | ||||
| int i; | int i; | ||||
| for (i = 0; i < BPHYS_TOT_DATA; i++) { | for (i = 0; i < BPHYS_TOT_DATA; i++) { | ||||
| pm->cur[i] = ((data_types & (1 << i)) ? pm->data[i] : NULL); | cur[i] = ((data_types & (1 << i)) ? pm->data[i] : NULL); | ||||
| } | } | ||||
| } | } | ||||
| void BKE_ptcache_mem_pointers_incr(PTCacheMem *pm) | void BKE_ptcache_mem_pointers_incr(void *cur[BPHYS_TOT_DATA]) | ||||
| { | { | ||||
| int i; | int i; | ||||
| for (i = 0; i < BPHYS_TOT_DATA; i++) { | for (i = 0; i < BPHYS_TOT_DATA; i++) { | ||||
| if (pm->cur[i]) { | if (cur[i]) { | ||||
| pm->cur[i] = (char *)pm->cur[i] + ptcache_data_size[i]; | cur[i] = (char *)cur[i] + ptcache_data_size[i]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| int BKE_ptcache_mem_pointers_seek(int point_index, PTCacheMem *pm) | int BKE_ptcache_mem_pointers_seek(int point_index, PTCacheMem *pm, void *cur[BPHYS_TOT_DATA]) | ||||
| { | { | ||||
| int data_types = pm->data_types; | int data_types = pm->data_types; | ||||
| int i, index = BKE_ptcache_mem_index_find(pm, point_index); | int i, index = BKE_ptcache_mem_index_find(pm, point_index); | ||||
| if (index < 0) { | if (index < 0) { | ||||
| /* Can't give proper location without reallocation, so don't give any location. | /* Can't give proper location without reallocation, so don't give any location. | ||||
| * Some points will be cached improperly, but this only happens with simulation | * Some points will be cached improperly, but this only happens with simulation | ||||
| * steps bigger than cache->step, so the cache has to be recalculated anyways | * steps bigger than cache->step, so the cache has to be recalculated anyways | ||||
| * at some point. | * at some point. | ||||
| */ | */ | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| for (i = 0; i < BPHYS_TOT_DATA; i++) { | for (i = 0; i < BPHYS_TOT_DATA; i++) { | ||||
| pm->cur[i] = data_types & (1 << i) ? (char *)pm->data[i] + index * ptcache_data_size[i] : NULL; | cur[i] = data_types & (1 << i) ? (char *)pm->data[i] + index * ptcache_data_size[i] : NULL; | ||||
| } | } | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| static void ptcache_data_alloc(PTCacheMem *pm) | static void ptcache_data_alloc(PTCacheMem *pm) | ||||
| { | { | ||||
| int data_types = pm->data_types; | int data_types = pm->data_types; | ||||
| int totpoint = pm->totpoint; | int totpoint = pm->totpoint; | ||||
| ▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | if (pf->flag & PTCACHE_TYPEFLAG_COMPRESS) { | ||||
| for (i = 0; i < BPHYS_TOT_DATA; i++) { | for (i = 0; i < BPHYS_TOT_DATA; i++) { | ||||
| unsigned int out_len = pm->totpoint * ptcache_data_size[i]; | unsigned int out_len = pm->totpoint * ptcache_data_size[i]; | ||||
| if (pf->data_types & (1 << i)) { | if (pf->data_types & (1 << i)) { | ||||
| ptcache_file_compressed_read(pf, (unsigned char *)(pm->data[i]), out_len); | ptcache_file_compressed_read(pf, (unsigned char *)(pm->data[i]), out_len); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_ptcache_mem_pointers_init(pm); | void *cur[BPHYS_TOT_DATA]; | ||||
| BKE_ptcache_mem_pointers_init(pm, cur); | |||||
| ptcache_file_pointers_init(pf); | ptcache_file_pointers_init(pf); | ||||
| for (i = 0; i < pm->totpoint; i++) { | for (i = 0; i < pm->totpoint; i++) { | ||||
| if (!ptcache_file_data_read(pf)) { | if (!ptcache_file_data_read(pf)) { | ||||
| error = 1; | error = 1; | ||||
| break; | break; | ||||
| } | } | ||||
| ptcache_data_copy(pf->cur, pm->cur); | ptcache_data_copy(pf->cur, cur); | ||||
| BKE_ptcache_mem_pointers_incr(pm); | BKE_ptcache_mem_pointers_incr(cur); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (!error && pf->flag & PTCACHE_TYPEFLAG_EXTRADATA) { | if (!error && pf->flag & PTCACHE_TYPEFLAG_EXTRADATA) { | ||||
| unsigned int extratype = 0; | unsigned int extratype = 0; | ||||
| while (ptcache_file_read(pf, &extratype, 1, sizeof(unsigned int))) { | while (ptcache_file_read(pf, &extratype, 1, sizeof(unsigned int))) { | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | if (pid->cache->compression) { | ||||
| "pointcache_lzo_buffer"); | "pointcache_lzo_buffer"); | ||||
| ptcache_file_compressed_write( | ptcache_file_compressed_write( | ||||
| pf, (unsigned char *)(pm->data[i]), in_len, out, pid->cache->compression); | pf, (unsigned char *)(pm->data[i]), in_len, out, pid->cache->compression); | ||||
| MEM_freeN(out); | MEM_freeN(out); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_ptcache_mem_pointers_init(pm); | void *cur[BPHYS_TOT_DATA]; | ||||
| BKE_ptcache_mem_pointers_init(pm, cur); | |||||
| ptcache_file_pointers_init(pf); | ptcache_file_pointers_init(pf); | ||||
| for (i = 0; i < pm->totpoint; i++) { | for (i = 0; i < pm->totpoint; i++) { | ||||
| ptcache_data_copy(pm->cur, pf->cur); | ptcache_data_copy(cur, pf->cur); | ||||
| if (!ptcache_file_data_write(pf)) { | if (!ptcache_file_data_write(pf)) { | ||||
| error = 1; | error = 1; | ||||
| break; | break; | ||||
| } | } | ||||
| BKE_ptcache_mem_pointers_incr(pm); | BKE_ptcache_mem_pointers_incr(cur); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (!error && pm->extradata.first) { | if (!error && pm->extradata.first) { | ||||
| PTCacheExtra *extra = pm->extradata.first; | PTCacheExtra *extra = pm->extradata.first; | ||||
| for (; extra; extra = extra->next) { | for (; extra; extra = extra->next) { | ||||
| ▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | if ((pid->data_types & (1 << BPHYS_DATA_INDEX)) == 0) { | ||||
| int pid_totpoint = pid->totpoint(pid->calldata, cfra); | int pid_totpoint = pid->totpoint(pid->calldata, cfra); | ||||
| if (totpoint != pid_totpoint) { | if (totpoint != pid_totpoint) { | ||||
| pid->error(pid->calldata, "Number of points in cache does not match mesh"); | pid->error(pid->calldata, "Number of points in cache does not match mesh"); | ||||
| totpoint = MIN2(totpoint, pid_totpoint); | totpoint = MIN2(totpoint, pid_totpoint); | ||||
| } | } | ||||
| } | } | ||||
| BKE_ptcache_mem_pointers_init(pm); | void *cur[BPHYS_TOT_DATA]; | ||||
| BKE_ptcache_mem_pointers_init(pm, cur); | |||||
| for (i = 0; i < totpoint; i++) { | for (i = 0; i < totpoint; i++) { | ||||
| if (pm->data_types & (1 << BPHYS_DATA_INDEX)) { | if (pm->data_types & (1 << BPHYS_DATA_INDEX)) { | ||||
| index = pm->cur[BPHYS_DATA_INDEX]; | index = cur[BPHYS_DATA_INDEX]; | ||||
| } | } | ||||
| pid->read_point(*index, pid->calldata, pm->cur, (float)pm->frame, NULL); | pid->read_point(*index, pid->calldata, cur, (float)pm->frame, NULL); | ||||
| BKE_ptcache_mem_pointers_incr(pm); | BKE_ptcache_mem_pointers_incr(cur); | ||||
| } | } | ||||
| if (pid->read_extra_data && pm->extradata.first) { | if (pid->read_extra_data && pm->extradata.first) { | ||||
| pid->read_extra_data(pid->calldata, pm, (float)pm->frame); | pid->read_extra_data(pid->calldata, pm, (float)pm->frame); | ||||
| } | } | ||||
| /* clean up temporary memory cache */ | /* clean up temporary memory cache */ | ||||
| if (pid->cache->flag & PTCACHE_DISK_CACHE) { | if (pid->cache->flag & PTCACHE_DISK_CACHE) { | ||||
| Show All 30 Lines | if ((pid->data_types & (1 << BPHYS_DATA_INDEX)) == 0) { | ||||
| int pid_totpoint = pid->totpoint(pid->calldata, (int)cfra); | int pid_totpoint = pid->totpoint(pid->calldata, (int)cfra); | ||||
| if (totpoint != pid_totpoint) { | if (totpoint != pid_totpoint) { | ||||
| pid->error(pid->calldata, "Number of points in cache does not match mesh"); | pid->error(pid->calldata, "Number of points in cache does not match mesh"); | ||||
| totpoint = MIN2(totpoint, pid_totpoint); | totpoint = MIN2(totpoint, pid_totpoint); | ||||
| } | } | ||||
| } | } | ||||
| BKE_ptcache_mem_pointers_init(pm); | void *cur[BPHYS_TOT_DATA]; | ||||
| BKE_ptcache_mem_pointers_init(pm, cur); | |||||
| for (i = 0; i < totpoint; i++) { | for (i = 0; i < totpoint; i++) { | ||||
| if (pm->data_types & (1 << BPHYS_DATA_INDEX)) { | if (pm->data_types & (1 << BPHYS_DATA_INDEX)) { | ||||
| index = pm->cur[BPHYS_DATA_INDEX]; | index = cur[BPHYS_DATA_INDEX]; | ||||
| } | } | ||||
| pid->interpolate_point( | pid->interpolate_point(*index, pid->calldata, cur, cfra, (float)cfra1, (float)cfra2, NULL); | ||||
| *index, pid->calldata, pm->cur, cfra, (float)cfra1, (float)cfra2, NULL); | BKE_ptcache_mem_pointers_incr(cur); | ||||
| BKE_ptcache_mem_pointers_incr(pm); | |||||
| } | } | ||||
| if (pid->interpolate_extra_data && pm->extradata.first) { | if (pid->interpolate_extra_data && pm->extradata.first) { | ||||
| pid->interpolate_extra_data(pid->calldata, pm, cfra, (float)cfra1, (float)cfra2); | pid->interpolate_extra_data(pid->calldata, pm, cfra, (float)cfra1, (float)cfra2); | ||||
| } | } | ||||
| /* clean up temporary memory cache */ | /* clean up temporary memory cache */ | ||||
| if (pid->cache->flag & PTCACHE_DISK_CACHE) { | if (pid->cache->flag & PTCACHE_DISK_CACHE) { | ||||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | static int ptcache_write(PTCacheID *pid, int cfra, int overwrite) | ||||
| int i, error = 0; | int i, error = 0; | ||||
| pm = MEM_callocN(sizeof(PTCacheMem), "Pointcache mem"); | pm = MEM_callocN(sizeof(PTCacheMem), "Pointcache mem"); | ||||
| pm->totpoint = pid->totwrite(pid->calldata, cfra); | pm->totpoint = pid->totwrite(pid->calldata, cfra); | ||||
| pm->data_types = cfra ? pid->data_types : pid->info_types; | pm->data_types = cfra ? pid->data_types : pid->info_types; | ||||
| ptcache_data_alloc(pm); | ptcache_data_alloc(pm); | ||||
| BKE_ptcache_mem_pointers_init(pm); | void *cur[BPHYS_TOT_DATA]; | ||||
| BKE_ptcache_mem_pointers_init(pm, cur); | |||||
| if (overwrite) { | if (overwrite) { | ||||
| if (cache->flag & PTCACHE_DISK_CACHE) { | if (cache->flag & PTCACHE_DISK_CACHE) { | ||||
| int fra = cfra - 1; | int fra = cfra - 1; | ||||
| while (fra >= cache->startframe && !BKE_ptcache_id_exist(pid, fra)) { | while (fra >= cache->startframe && !BKE_ptcache_id_exist(pid, fra)) { | ||||
| fra--; | fra--; | ||||
| } | } | ||||
| pm2 = ptcache_disk_frame_to_mem(pid, fra); | pm2 = ptcache_disk_frame_to_mem(pid, fra); | ||||
| } | } | ||||
| else { | else { | ||||
| pm2 = cache->mem_cache.last; | pm2 = cache->mem_cache.last; | ||||
| } | } | ||||
| } | } | ||||
| if (pid->write_point) { | if (pid->write_point) { | ||||
| for (i = 0; i < totpoint; i++) { | for (i = 0; i < totpoint; i++) { | ||||
| int write = pid->write_point(i, pid->calldata, pm->cur, cfra); | int write = pid->write_point(i, pid->calldata, cur, cfra); | ||||
| if (write) { | if (write) { | ||||
| BKE_ptcache_mem_pointers_incr(pm); | BKE_ptcache_mem_pointers_incr(cur); | ||||
| void *cur2[BPHYS_TOT_DATA]; | |||||
| /* newly born particles have to be copied to previous cached frame */ | /* newly born particles have to be copied to previous cached frame */ | ||||
| if (overwrite && write == 2 && pm2 && BKE_ptcache_mem_pointers_seek(i, pm2)) { | if (overwrite && write == 2 && pm2 && BKE_ptcache_mem_pointers_seek(i, pm2, cur2)) { | ||||
| pid->write_point(i, pid->calldata, pm2->cur, cfra); | pid->write_point(i, pid->calldata, cur2, cfra); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (pid->write_extra_data) { | if (pid->write_extra_data) { | ||||
| pid->write_extra_data(pid->calldata, pm, cfra); | pid->write_extra_data(pid->calldata, pm, cfra); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 655 Lines • ▼ Show 20 Lines | for (pm = cache->mem_cache.first; pm; pm = pm->next) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < BPHYS_TOT_DATA; i++) { | for (i = 0; i < BPHYS_TOT_DATA; i++) { | ||||
| if (pmn->data[i]) { | if (pmn->data[i]) { | ||||
| pmn->data[i] = MEM_dupallocN(pm->data[i]); | pmn->data[i] = MEM_dupallocN(pm->data[i]); | ||||
| } | } | ||||
| } | } | ||||
| BKE_ptcache_mem_pointers_init(pm); | |||||
| BLI_addtail(&ncache->mem_cache, pmn); | BLI_addtail(&ncache->mem_cache, pmn); | ||||
| } | } | ||||
| if (ncache->cached_frames) { | if (ncache->cached_frames) { | ||||
| ncache->cached_frames = MEM_dupallocN(cache->cached_frames); | ncache->cached_frames = MEM_dupallocN(cache->cached_frames); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 675 Lines • Show Last 20 Lines | |||||