void test(int ix) {
	struct world_list *wl = NULL, *tmp;
	struct test test = all_tests[ix];
	char *cmd;
	int i;

	wl = calloc(1, sizeof(*wl));
	wl->world = read_test_file(test.filenames[0]);
	for (i = 1; test.filenames[i]; i++) {
		tmp = calloc(1, sizeof(*tmp));
		tmp->world = read_test_file(test.filenames[i]);
		tmp->next = wl;
		wl = tmp;
	}

	cmd = build_test_cmd(wl);
	test_results(4 + ix, cmd, test_everything, wl, test.score); /* syntax check */

	while (wl) {
		tmp = wl->next;
		free_world(wl->world);
		free(wl);
		wl = tmp;
	}
}
Пример #2
0
Файл: game.c Проект: phoboz/yz
void deinit_game(void)
{
  free_battle(game_battle);
  free_scanner(game_scanner);
  free_world(game_world);
  free_actor(game_hero);
}
Пример #3
0
static void
greets_uninit_effect (void *params, backbuffer_info *bbuf)
{
  greets_data *gdata = (greets_data *) params;

  free_world (gdata->world);
  free (gdata->tileidx);
  free_shader (gdata->tile_shader);
}
Пример #4
0
int wt_new_world(char *pszWorldFile)
{
   FILE *fp;

   if (w)
      free_world(w);

   if ((fp = fopen(pszWorldFile, "r")) == NULL) {
      perror(pszWorldFile);
      exit(EXIT_FAILURE);
   }
   w = read_world_file(fp);
   fclose(fp);
   return EXIT_SUCCESS;
}
Пример #5
0
int main (int argc, char * argv[]){
    int i, num_threads = 2, col_thread=0, num_gen = 100;
    if(argc < 5) {
        printf("Usage ./life <num_threads> <in_file> <col_th> <num_gen>\n");
        return 0;
    }
    world w;

    num_threads = atoi(argv[1]);
    col_thread = atoi(argv[3]);
    num_gen = atoi(argv[4]);

    srand(time(NULL));
    if(strcmp(argv[2], "none") == 0){
        world_size_t world_size;
        world_size.rows = 20;
        world_size.cols = 10;
        w = create_world(world_size);
        seed(w);
    }
    else {
        w = parse_world(argv[2]);
    }
    //    print(w);
    struct timeval start_time, end_time, diff_time;
    gettimeofday(&start_time, 0);
    for(i=0; i<num_gen; i++){
        if(col_thread == 0){
            w = evolve_rows(w, num_threads);
        }
        else{
            w = evolve_cols(w, num_threads);
        }
//        print(w);
        if(i == 60) {
            create_pulsar(w, 5, 10);
        }
    }
    free_world(w);
    gettimeofday(&end_time, 0);
    if(timeval_subtract(&diff_time, &end_time, &start_time) != 1){
        printf("num_threads: %d col_th: %d num_gen: %d time: %ld us\n", num_threads, col_thread, num_gen, diff_time.tv_sec * 1000000 + diff_time.tv_usec);
    }
    return 0;
}
Пример #6
0
int main (int argc, char * argv[]){
    int i, num_threads = 2, in_file = 0;
    world w;
    if(argc >= 2){
        num_threads = atoi(argv[1]);
    }
    if(argc == 3){
        in_file = 1;
    }
    srand(time(NULL));
    if(in_file == 0){
    world_size_t world_size;
    world_size.rows = 20;
    world_size.cols = 10;

    w = create_world(world_size);
    seed(w);
    }
    else {
        w = parse_world(argv[2]);
    }
    //    print(w);
    struct timeval start_time, end_time, diff_time;
    gettimeofday(&start_time, 0);
    for(i=0; i<1000; i++){
        w = evolve(w, num_threads);
//        print(w);
        if(i == 60) {
            create_pulsar(w, 5, 10);
        }
    }
    free_world(w);
    gettimeofday(&end_time, 0);
    if(timeval_subtract(&diff_time, &end_time, &start_time) != 1){
        printf("Time elapsed: %d us\n", diff_time.tv_sec * 1000000 + diff_time.tv_usec);
    }
    return 0;
}
Пример #7
0
/* used in headerbuttons.c image.c mesh.c screen.c sound.c and library.c */
void free_libblock(ListBase *lb, void *idv)
{
	ID *id= idv;

#ifdef WITH_PYTHON
	BPY_id_release(id);
#endif

	switch( GS(id->name) ) {	/* GetShort from util.h */
		case ID_SCE:
			free_scene((Scene *)id);
			break;
		case ID_LI:
			free_library((Library *)id);
			break;
		case ID_OB:
			free_object((Object *)id);
			break;
		case ID_ME:
			free_mesh((Mesh *)id);
			break;
		case ID_CU:
			free_curve((Curve *)id);
			break;
		case ID_MB:
			free_mball((MetaBall *)id);
			break;
		case ID_MA:
			free_material((Material *)id);
			break;
		case ID_TE:
			free_texture((Tex *)id);
			break;
		case ID_IM:
			free_image((Image *)id);
			break;
		case ID_LT:
			free_lattice((Lattice *)id);
			break;
		case ID_LA:
			free_lamp((Lamp *)id);
			break;
		case ID_CA:
			free_camera((Camera*) id);
			break;
		case ID_IP:
			free_ipo((Ipo *)id);
			break;
		case ID_KE:
			free_key((Key *)id);
			break;
		case ID_WO:
			free_world((World *)id);
			break;
		case ID_SCR:
			free_screen((bScreen *)id);
			break;
		case ID_VF:
			free_vfont((VFont *)id);
			break;
		case ID_TXT:
			free_text((Text *)id);
			break;
		case ID_SCRIPT:
			//XXX free_script((Script *)id);
			break;
		case ID_SPK:
			free_speaker((Speaker *)id);
			break;
		case ID_SO:
			sound_free((bSound*)id);
			break;
		case ID_GR:
			free_group_objects((Group *)id);
			break;
		case ID_AR:
			free_armature((bArmature *)id);
			break;
		case ID_AC:
			free_action((bAction *)id);
			break;
		case ID_NT:
			ntreeFreeTree((bNodeTree *)id);
			break;
		case ID_BR:
			free_brush((Brush *)id);
			break;
		case ID_PA:
			psys_free_settings((ParticleSettings *)id);
			break;
		case ID_WM:
			if(free_windowmanager_cb)
				free_windowmanager_cb(NULL, (wmWindowManager *)id);
			break;
		case ID_GD:
			free_gpencil_data((bGPdata *)id);
			break;
	}

	if (id->properties) {
		IDP_FreeProperty(id->properties);
		MEM_freeN(id->properties);
	}

	BLI_remlink(lb, id);

	/* this ID may be a driver target! */
	BKE_animdata_main_cb(G.main, animdata_dtar_clear_cb, (void *)id);

	MEM_freeN(id);
}
Пример #8
0
static void shader_preview_free(void *customdata)
{
	ShaderPreview *sp= customdata;
	
	if(sp->matcopy) {
		struct IDProperty *properties;
		int a;
		
		/* node previews */
		shader_preview_updatejob(sp);
		
		/* get rid of copied material */
		BLI_remlink(&pr_main->mat, sp->matcopy);
		
		/* free_material decrements texture, prevent this. hack alert! */
		for(a=0; a<MAX_MTEX; a++) {
			MTex *mtex= sp->matcopy->mtex[a];
			if(mtex && mtex->tex) mtex->tex= NULL;
		}
		
		free_material(sp->matcopy);

		properties= IDP_GetProperties((ID *)sp->matcopy, FALSE);
		if (properties) {
			IDP_FreeProperty(properties);
			MEM_freeN(properties);
		}
		MEM_freeN(sp->matcopy);
	}
	if(sp->texcopy) {
		struct IDProperty *properties;
		/* node previews */
		shader_preview_updatejob(sp);
		
		/* get rid of copied texture */
		BLI_remlink(&pr_main->tex, sp->texcopy);
		free_texture(sp->texcopy);
		
		properties= IDP_GetProperties((ID *)sp->texcopy, FALSE);
		if (properties) {
			IDP_FreeProperty(properties);
			MEM_freeN(properties);
		}
		MEM_freeN(sp->texcopy);
	}
	if(sp->worldcopy) {
		struct IDProperty *properties;
		/* node previews */
		shader_preview_updatejob(sp);
		
		/* get rid of copied world */
		BLI_remlink(&pr_main->world, sp->worldcopy);
		free_world(sp->worldcopy);
		
		properties= IDP_GetProperties((ID *)sp->worldcopy, FALSE);
		if (properties) {
			IDP_FreeProperty(properties);
			MEM_freeN(properties);
		}
		MEM_freeN(sp->worldcopy);
	}
	if(sp->lampcopy) {
		struct IDProperty *properties;
		/* node previews */
		shader_preview_updatejob(sp);
		
		/* get rid of copied lamp */
		BLI_remlink(&pr_main->lamp, sp->lampcopy);
		free_lamp(sp->lampcopy);
		
		properties= IDP_GetProperties((ID *)sp->lampcopy, FALSE);
		if (properties) {
			IDP_FreeProperty(properties);
			MEM_freeN(properties);
		}
		MEM_freeN(sp->lampcopy);
	}
	
	MEM_freeN(sp);
}
Пример #9
0
void free_all(uint8_t **worlds[2], uint8_t width, uint8_t height) {
	free_world(worlds[0], width, height);
	free_world(worlds[1], width, height);
}
Пример #10
0
world evolve_cols(world w, int num_threads) {
    int i, j, n, nedge=0;
    pthread_t bound_th[4];
    pthread_t *evolve_th = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
    evolve_param_cols_t *evp = (evolve_param_cols_t *)malloc(num_threads * sizeof(evolve_param_cols_t));

    world newworld;
    world nextgen = create_world(w.size);
    // threading and shared data
    num_threads = num_threads < w.size.cols ? num_threads : w.size.cols;
    for(i=0; i<num_threads; i++){
        evp[i].start_col = i * (w.size.cols / num_threads);
        if(i==num_threads-1) {
            evp[i].end_col = w.size.cols;
        }
        else {
            evp[i].end_col = (i+1) * (w.size.cols / num_threads);
        }
        evp[i].w = &w;
        evp[i].nw = &nextgen;
        pthread_create(&evolve_th[i], NULL, &process_world_slice_cols, (void *)(evp+i));
    }

    // wait for all threads; synchronization
    for(i=0;i<num_threads;i++){
        pthread_join(evolve_th[i], NULL);
    }

    free(evolve_th);
    free(evp);

    check_bound_params cbp;
    cbp.res = &nedge;
    cbp.w = nextgen;
    // num_threads threads
    for(j=0; j<4;){
        for(i=0; i<(num_threads<4?num_threads:4);i++){
            cbp.pos = i+j;
            pthread_create(&bound_th[i], NULL, &check_boundary, (void *)&cbp);
        }
        for(i=0;i<(num_threads<4?num_threads:4);i++){
            pthread_join(bound_th[i], NULL);
        }
        j += i;
    }

    free_world(w);
    newworld = nextgen;
    if(nedge != 0){
        // printf("Expanding world... %x\n", nedge);
        int pos_row = 0;
        int pos_col = 0;
        world_size_t new_world_size;
        new_world_size.rows = nextgen.size.rows;
        new_world_size.cols = nextgen.size.cols;

        if(nedge & NORTH){
            new_world_size.rows += nextgen.size.rows;
            pos_row += nextgen.size.rows;
        }
        if(nedge & SOUTH){
            new_world_size.rows += nextgen.size.rows;
        }

        if(nedge & EAST){
            new_world_size.cols += nextgen.size.cols;
        }
        if(nedge & WEST){
            new_world_size.cols += nextgen.size.cols;
            pos_col += nextgen.size.cols;
        }

        newworld = create_world(new_world_size);
        // TODO: multi-threaded
        populate_world_cols(nextgen, newworld, pos_row, pos_col, num_threads);
        free_world(nextgen);
    }
    return newworld;
}