Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/physics/particle_edit.c
| Show First 20 Lines • Show All 4,078 Lines • ▼ Show 20 Lines | typedef struct BrushAddCountIterData { | ||||
| Scene *scene; | Scene *scene; | ||||
| Object *object; | Object *object; | ||||
| Mesh *mesh; | Mesh *mesh; | ||||
| PEData *data; | PEData *data; | ||||
| int number; | int number; | ||||
| short size; | short size; | ||||
| float imat[4][4]; | float imat[4][4]; | ||||
| ParticleData *add_pars; | ParticleData *add_pars; | ||||
| int num_added; | |||||
| } BrushAddCountIterData; | } BrushAddCountIterData; | ||||
| typedef struct BrushAddCountIterTLSData { | typedef struct BrushAddCountIterTLSData { | ||||
| RNG *rng; | RNG *rng; | ||||
| int num_added; | int num_added; | ||||
| } BrushAddCountIterTLSData; | } BrushAddCountIterTLSData; | ||||
| static void brush_add_count_iter(void *__restrict iter_data_v, | static void brush_add_count_iter(void *__restrict iter_data_v, | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | else { | ||||
| add_pars[iter].num = add_pars[iter].num_dmcache; | add_pars[iter].num = add_pars[iter].num_dmcache; | ||||
| } | } | ||||
| if (add_pars[iter].num != DMCACHE_NOTFOUND) { | if (add_pars[iter].num != DMCACHE_NOTFOUND) { | ||||
| tls->num_added++; | tls->num_added++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void brush_add_count_iter_finalize(void *__restrict userdata_v, | static void brush_add_count_iter_reduce(const void *__restrict UNUSED(userdata), | ||||
| void *__restrict userdata_chunk_v) | void *__restrict join_v, | ||||
| void *__restrict chunk_v) | |||||
| { | |||||
| BrushAddCountIterTLSData *join = (BrushAddCountIterTLSData *)join_v; | |||||
| BrushAddCountIterTLSData *tls = (BrushAddCountIterTLSData *)chunk_v; | |||||
| join->num_added += tls->num_added; | |||||
| } | |||||
| static void brush_add_count_iter_free(const void *__restrict UNUSED(userdata_v), | |||||
| void *__restrict chunk_v) | |||||
| { | { | ||||
| BrushAddCountIterData *iter_data = (BrushAddCountIterData *)userdata_v; | BrushAddCountIterTLSData *tls = (BrushAddCountIterTLSData *)chunk_v; | ||||
| BrushAddCountIterTLSData *tls = (BrushAddCountIterTLSData *)userdata_chunk_v; | |||||
| iter_data->num_added += tls->num_added; | |||||
| if (tls->rng != NULL) { | if (tls->rng != NULL) { | ||||
| BLI_rng_free(tls->rng); | BLI_rng_free(tls->rng); | ||||
| } | } | ||||
| } | } | ||||
| static int brush_add(const bContext *C, PEData *data, short number) | static int brush_add(const bContext *C, PEData *data, short number) | ||||
| { | { | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | static int brush_add(const bContext *C, PEData *data, short number) | ||||
| iter_data.depsgraph = depsgraph; | iter_data.depsgraph = depsgraph; | ||||
| iter_data.scene = scene; | iter_data.scene = scene; | ||||
| iter_data.object = ob; | iter_data.object = ob; | ||||
| iter_data.mesh = mesh; | iter_data.mesh = mesh; | ||||
| iter_data.data = data; | iter_data.data = data; | ||||
| iter_data.number = number; | iter_data.number = number; | ||||
| iter_data.size = size; | iter_data.size = size; | ||||
| iter_data.add_pars = add_pars; | iter_data.add_pars = add_pars; | ||||
| iter_data.num_added = 0; | |||||
| copy_m4_m4(iter_data.imat, imat); | copy_m4_m4(iter_data.imat, imat); | ||||
| BrushAddCountIterTLSData tls = {NULL}; | BrushAddCountIterTLSData tls = {NULL}; | ||||
| TaskParallelSettings settings; | TaskParallelSettings settings; | ||||
| BLI_parallel_range_settings_defaults(&settings); | BLI_parallel_range_settings_defaults(&settings); | ||||
| settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; | settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; | ||||
| settings.userdata_chunk = &tls; | settings.userdata_chunk = &tls; | ||||
| settings.userdata_chunk_size = sizeof(BrushAddCountIterTLSData); | settings.userdata_chunk_size = sizeof(BrushAddCountIterTLSData); | ||||
| settings.func_finalize = brush_add_count_iter_finalize; | settings.func_reduce = brush_add_count_iter_reduce; | ||||
| settings.func_free = brush_add_count_iter_free; | |||||
| BLI_task_parallel_range(0, number, &iter_data, brush_add_count_iter, &settings); | BLI_task_parallel_range(0, number, &iter_data, brush_add_count_iter, &settings); | ||||
| /* Convert add_parse to a dense array, where all new particles are in the | /* Convert add_parse to a dense array, where all new particles are in the | ||||
| * beginning of the array. | * beginning of the array. | ||||
| */ | */ | ||||
| n = iter_data.num_added; | n = tls.num_added; | ||||
| for (int current_iter = 0, new_index = 0; current_iter < number; current_iter++) { | for (int current_iter = 0, new_index = 0; current_iter < number; current_iter++) { | ||||
| if (add_pars[current_iter].num == DMCACHE_NOTFOUND) { | if (add_pars[current_iter].num == DMCACHE_NOTFOUND) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (new_index != current_iter) { | if (new_index != current_iter) { | ||||
| new_index++; | new_index++; | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,234 Lines • Show Last 20 Lines | |||||