void start_world_simulation(void){ register int i, j; for(; number_of_generations > 0; --number_of_generations){ copy_world(); /* update 'red' cells, think chessboard */ for(i = 0; i < grid_size; ++i) for (j = i & 1; j < grid_size; j += 2) update_world_cell(i, j); copy_world(); /* update 'black' cells, think chessboard */ for(i = 0; i < grid_size; ++i) for (j = !(i & 1); j < grid_size; j += 2) update_world_cell(i, j); if(number_of_generations == 1) return; for(i = 0; i < grid_size; ++i){ for (j = 0; j < grid_size; ++j){ if (world[i][j].moved){ if (world[i][j].type == SQUIRREL || world[i][j].type == SQUIRREL_IN_TREE){ world[i][j].breeding_period++; } else if (world[i][j].type == WOLF){ world[i][j].starvation_period--; world[i][j].breeding_period++; /* wolf dies of starvation */ if(world[i][j].starvation_period <= 0){ cleanup_cell(&world[i][j]); } } } world[i][j].moved = 0; } } } }
void make_local_world(World *wrld) { Scene *sce; World *wrldn; int local=0, lib=0; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ if(wrld->id.lib==0) return; if(wrld->id.us==1) { wrld->id.lib= 0; wrld->id.flag= LIB_LOCAL; new_id(0, (ID *)wrld, 0); return; } sce= G.main->scene.first; while(sce) { if(sce->world==wrld) { if(sce->id.lib) lib= 1; else local= 1; } sce= sce->id.next; } if(local && lib==0) { wrld->id.lib= 0; wrld->id.flag= LIB_LOCAL; new_id(0, (ID *)wrld, 0); } else if(local && lib) { wrldn= copy_world(wrld); wrldn->id.us= 0; sce= G.main->scene.first; while(sce) { if(sce->world==wrld) { if(sce->id.lib==0) { sce->world= wrldn; wrldn->id.us++; wrld->id.us--; } } sce= sce->id.next; } } }
int id_copy(ID *id, ID **newid, int test) { if(!test) *newid= NULL; /* conventions: * - make shallow copy, only this ID block * - id.us of the new ID is set to 1 */ switch(GS(id->name)) { case ID_SCE: return 0; /* can't be copied from here */ case ID_LI: return 0; /* can't be copied from here */ case ID_OB: if(!test) *newid= (ID*)copy_object((Object*)id); return 1; case ID_ME: if(!test) *newid= (ID*)copy_mesh((Mesh*)id); return 1; case ID_CU: if(!test) *newid= (ID*)copy_curve((Curve*)id); return 1; case ID_MB: if(!test) *newid= (ID*)copy_mball((MetaBall*)id); return 1; case ID_MA: if(!test) *newid= (ID*)copy_material((Material*)id); return 1; case ID_TE: if(!test) *newid= (ID*)copy_texture((Tex*)id); return 1; case ID_IM: if(!test) *newid= (ID*)copy_image((Image*)id); return 1; case ID_LT: if(!test) *newid= (ID*)copy_lattice((Lattice*)id); return 1; case ID_LA: if(!test) *newid= (ID*)copy_lamp((Lamp*)id); return 1; case ID_SPK: if(!test) *newid= (ID*)copy_speaker((Speaker*)id); return 1; case ID_CA: if(!test) *newid= (ID*)copy_camera((Camera*)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: if(!test) *newid= (ID*)copy_key((Key*)id); return 1; case ID_WO: if(!test) *newid= (ID*)copy_world((World*)id); return 1; case ID_SCR: return 0; /* can't be copied from here */ case ID_VF: return 0; /* not implemented */ case ID_TXT: if(!test) *newid= (ID*)copy_text((Text*)id); return 1; case ID_SCRIPT: return 0; /* deprecated */ case ID_SO: return 0; /* not implemented */ case ID_GR: if(!test) *newid= (ID*)copy_group((Group*)id); return 1; case ID_AR: if(!test) *newid= (ID*)copy_armature((bArmature*)id); return 1; case ID_AC: if(!test) *newid= (ID*)copy_action((bAction*)id); return 1; case ID_NT: if(!test) *newid= (ID*)ntreeCopyTree((bNodeTree*)id); return 1; case ID_BR: if(!test) *newid= (ID*)copy_brush((Brush*)id); return 1; case ID_PA: if(!test) *newid= (ID*)psys_copy_settings((ParticleSettings*)id); return 1; case ID_WM: return 0; /* can't be copied from here */ case ID_GD: return 0; /* not implemented */ } return 0; }
void start_world_simulation(void){ register int i, j, btm_lim = bottom, top_lim = top; for(; number_of_generations > 0; --number_of_generations){ copy_world(); if(taskid != MASTER) btm_lim = bottom - 1; if(taskid != numtasks-1) top_lim = top + 1; /* update 'red' cells, think chessboard */ #pragma omp parallel for private(j) for(i = btm_lim; i < top_lim; ++i){ for (j = 0; j < grid_size; j++){ if(get_cell_color(&world[i][j]) == RED){ update_world_cell(i, j); } } } resolve_conflicts(RED, number_of_generations); copy_world(); /* update 'black' cells, think chessboard */ #pragma omp parallel for private(j) for(i = btm_lim; i < top_lim; ++i){ for (j = 0; j < grid_size; j++){ if(get_cell_color(&world[i][j]) == BLACK){ update_world_cell(i, j); } } } resolve_conflicts(BLACK, number_of_generations); if(number_of_generations == 1) return; #pragma omp parallel for private(j) for(i = 0; i < payload; ++i){ for (j = 0; j < grid_size; ++j){ if (world[i][j].moved == UPDATED || world[i][j].moved == MOVED){ if (world[i][j].type == SQUIRREL || world[i][j].type == SQUIRREL_IN_TREE){ world[i][j].breeding_period++; } else if (world[i][j].type == WOLF){ world[i][j].starvation_period--; world[i][j].breeding_period++; /* wolf dies of starvation */ if(world[i][j].starvation_period <= 0){ cleanup_cell(&world[i][j]); } } } world[i][j].moved = 0; } } } }