Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/particle_system.c
| Show First 20 Lines • Show All 469 Lines • ▼ Show 20 Lines | |||||
| void psys_tasks_create(ParticleThreadContext *ctx, | void psys_tasks_create(ParticleThreadContext *ctx, | ||||
| int startpart, | int startpart, | ||||
| int endpart, | int endpart, | ||||
| ParticleTask **r_tasks, | ParticleTask **r_tasks, | ||||
| int *r_numtasks) | int *r_numtasks) | ||||
| { | { | ||||
| ParticleTask *tasks; | ParticleTask *tasks; | ||||
| int numtasks = min_ii(BLI_system_thread_count() * 4, endpart - startpart); | int numtasks = min_ii(BLI_system_thread_count() * 4, endpart - startpart); | ||||
| float particles_per_task = numtasks > 0 ? (float)(endpart - startpart) / (float)numtasks : 0; | int particles_per_task = numtasks > 0 ? (endpart - startpart) / numtasks : 0; | ||||
| int remainder = numtasks > 0 ? (endpart - startpart) - particles_per_task * numtasks : 0; | |||||
oxben: Out of curiosity, why not use the modulo operator here ?
int remainder = numtasks > 0 ? | |||||
| tasks = MEM_callocN(sizeof(ParticleTask) * numtasks, "ParticleThread"); | tasks = MEM_callocN(sizeof(ParticleTask) * numtasks, "ParticleThread"); | ||||
| *r_numtasks = numtasks; | *r_numtasks = numtasks; | ||||
| *r_tasks = tasks; | *r_tasks = tasks; | ||||
| float pnext; | int p = startpart; | ||||
| float p = (float)startpart; | for (int i = 0; i < numtasks; i++) { | ||||
| for (int i = 0; i < numtasks; i++, p = pnext) { | |||||
| pnext = p + particles_per_task; | |||||
| tasks[i].ctx = ctx; | tasks[i].ctx = ctx; | ||||
| tasks[i].begin = (int)p; | tasks[i].begin = p; | ||||
| tasks[i].end = min_ii((int)pnext, endpart); | p = p + particles_per_task + (i < remainder ? 1 : 0); | ||||
| tasks[i].end = p; | |||||
| } | |||||
| /* Verify that all particles are accounted for. */ | |||||
| if (numtasks > 0) { | |||||
| BLI_assert(tasks[numtasks - 1].end == endpart); | |||||
| } | } | ||||
| } | } | ||||
| void psys_tasks_free(ParticleTask *tasks, int numtasks) | void psys_tasks_free(ParticleTask *tasks, int numtasks) | ||||
| { | { | ||||
| int i; | int i; | ||||
| /* threads */ | /* threads */ | ||||
| ▲ Show 20 Lines • Show All 4,562 Lines • Show Last 20 Lines | |||||
Out of curiosity, why not use the modulo operator here ?
int remainder = numtasks > 0 ? (endpart - startpart) % numtasks : 0;