IterationStack IterationForest::iterate(World& world) { //////////////////////////////////////// // actual iteration, implemented by subclass //////////////////////////////////////// auto ret = iterate_forest( world ); // TODO: finish up, free mem (events, ...) // events_step( world.events ); // count number of IterationForest-iterations ++world.frames; return ret; }
void test() { struct forest forest; int i; FILE *forest_file = NULL; char *home = getenv("HOME"); char *forest_filename = NULL; pthread_t draw_thread; forest_filename = malloc(strlen(home) + 10); sprintf(forest_filename, "%s/.lforest", home); forest.config.nrays = 10000; forest.config.init_score = 5; forest.config.init_iterations = 1; forest.config.replace_trees = 0.125; forest.config.leaf_cost = 0.5; forest.config.branch_cost = 1.0; forest.config.re_init_chance = 0.25; forest.config.width = 640; forest.config.height = 480; forest_file = fopen(forest_filename, "rb"); if(NULL == forest_file) { forest.config.ntrees = 250; init_forest(&forest); printf("%s not found: using random trees\n", forest_filename); fflush(NULL); } else { printf("%s found: using saved trees\n", forest_filename); fflush(NULL); read_forest(forest_file, &forest); fclose(forest_file); forest_file = NULL; } /* Launch the display thread */ forest.stop = 0; pthread_create(&draw_thread, NULL, draw_forest_thread_start, (void*)&forest); for(i = 0; 0 == forest.stop; ++i) { iterate_forest(&forest); breed_forest(&forest); printf("."); fflush(NULL); } pthread_join(draw_thread, NULL); printf("%i iterations\n", i); forest_file = fopen(forest_filename, "wb"); if(NULL == forest_file) printf("Failed to open %s: not saving\n", forest_filename); else { printf("saving to %s\n", forest_filename); write_forest(forest_file, &forest); fclose(forest_file); } free_forest(&forest); free(forest_filename); }