GameState events_menu_load(GameVars *game_vars) { SDL_Event ev; while (SDL_PollEvent(&ev)) { GameEvent gameev = events_parse(&ev); switch (gameev) { case EV_EXIT: return STATE_EXIT; case EV_KEY_ESC: return STATE_MAIN_MENU; case EV_KEY_SPACE: if (game_vars->grid == NULL) { game_vars->grid = grid_new(-1, -1); grid_init(game_vars->grid); file_load_grid(SAVE_FILE_NAME, game_vars); } return STATE_SIM_PAUSED; case EV_RESIZE: Event_SetWindowSize(game_vars, ev.window.data1, ev.window.data2); break; default: break; } } return game_vars->state; }
void jacobi( std::size_t n , std::size_t iterations, std::size_t block_size , std::string output_filename) { typedef std::vector<double> vector; std::shared_ptr<vector> grid_new(new vector(n * n, 1)); std::shared_ptr<vector> grid_old(new vector(n * n, 1)); hpx::util::high_resolution_timer t; for(std::size_t i = 0; i < iterations; ++i) { // MSVC is unhappy if the OMP loop variable is unsigned #pragma omp parallel for schedule(JACOBI_SMP_OMP_SCHEDULE) for(boost::int64_t y = 1; y < boost::int64_t(n-1); ++y) { double * dst = &(*grid_new)[y * n]; const double * src = &(*grid_new)[y * n]; jacobi_kernel( dst , src , n ); } std::swap(grid_new, grid_old); } report_timing(n, iterations, t.elapsed()); output_grid(output_filename, *grid_old, n); }
/*------------------------------------------------- main ----- | Function main | | Purpose: Reads input from STDIN using getchar(), iterates over | each character and determines whether the character | denotes the end of a sentence or word. After reaching | EOF, prints output of flesch kincaid algorithm results | and exits. | | | Parameters: argc (IN) -- number of arguments | argv (IN) -- Expects the program name, image file, and triples | | | Returns: Only success *-------------------------------------------------------------------*/ int main(int argc, char ** argv) { context = logging_init("prog10"); if (argc < 3) { error("Incorrect number of arguments. Need number of worms and size."); usage(*argv); exit(EXIT_FAILURE); } int worm_cnt = atoi(argv[1]); int worm_size = atoi(argv[2]); Worm worms[worm_cnt]; int rows, cols; initscr(); /* set up ncurses */ refresh(); /* clear screen */ getmaxyx(stdscr, rows, cols); debug("Got dimentions %d,%d", rows, cols); debug("Have %d rows ", rows); debug("Worm count is %d ", worm_cnt); debug("Worm size is %d ", worm_size); Grid grid = grid_new(cols, rows); time_t now = time(NULL); srand(localtime(&now)->tm_sec); // Set the seed for random numbers to the current second of the minute int i; for (i = 0; i < worm_cnt; i++) { info("Printing worm %d", i); worms[i] = worm_new(grid, worm_size); } /* while(1) { for (i = 0; i < worm_cnt; i++) { worm_move(worms[i]); } }*/ // usleep(PAUSE*10); /* wait for a bit */ free(grid); // Free the grid!!!! endwin(); logging_dest(context); return EXIT_SUCCESS; }
GameState events_menu_new(GameVars *game_vars) { SDL_Event ev; while (SDL_PollEvent(&ev)) { GameEvent gameev = events_parse(&ev); switch (gameev) { case EV_EXIT: return STATE_EXIT; case EV_KEY_ESC: return STATE_MAIN_MENU; case EV_KEY_SPACE: if (game_vars->grid == NULL) { game_vars->grid = grid_new(game_vars->grid_size.x, game_vars->grid_size.y); grid_init(game_vars->grid); } return STATE_SIM_PAUSED; case EV_KEY_UP: game_vars->grid_size.y++; break; case EV_KEY_DOWN: if (game_vars->grid_size.y > 1) { game_vars->grid_size.y--; } break; case EV_KEY_RIGHT: game_vars->grid_size.x++; break; case EV_KEY_LEFT: if (game_vars->grid_size.x > 1) { game_vars->grid_size.x--; } break; case EV_RESIZE: Event_SetWindowSize(game_vars, ev.window.data1, ev.window.data2); break; default: break; } } return game_vars->state; }
static struct pipeline *create_pipeline(struct gles *gles, int argc, char *argv[], bool regenerate, struct framebuffer *source) { struct framebuffer *target = NULL; struct geometry *plane, *output, *geometry; struct pipeline *pipeline; int i; pipeline = pipeline_new(gles); if (!pipeline) return NULL; /* * FIXME: Keep a reference to the created geometry so that it can be * properly disposed of. */ plane = grid_new(0); if (!plane) return NULL; output = grid_new(subdivisions); if (!output) return NULL; if (transform) grid_randomize(output); for (i = 0; i < argc; i++) { struct pipeline_stage *stage = NULL; /* * Render intermediate stages to a plane (2 triangles) geometry * and the final one to a randomized grid to simulate geometric * adaption. */ if (i >= argc - 1) geometry = output; else geometry = plane; /* * FIXME: Keep a reference to the created target framebuffers * so that they can be properly disposed of. */ if (i < argc - 1) { target = framebuffer_new(gles->width, gles->height); if (!target) { fprintf(stderr, "failed to create framebuffer\n"); goto error; } } else { target = display_framebuffer_new(gles->width, gles->height); if (!target) { fprintf(stderr, "failed to create display\n"); goto error; } } if (strcmp(argv[i], "fill") == 0) { stage = simple_fill_new(gles, geometry, target, 1.0, 0.0, 1.0); if (!stage) { fprintf(stderr, "simple_fill_new() failed\n"); goto error; } } else if (strcmp(argv[i], "checkerboard") == 0) { stage = checkerboard_new(gles, geometry, target); if (!stage) { fprintf(stderr, "checkerboard_new() failed\n"); goto error; } } else if (strcmp(argv[i], "clear") == 0) { stage = clear_new(gles, target, 1.0f, 1.0f, 0.0f); if (!stage) { fprintf(stderr, "clear_new() failed\n"); goto error; } } else if (strcmp(argv[i], "copy") == 0) { stage = simple_copy_new(gles, geometry, source, target); if (!stage) { fprintf(stderr, "simple_copy_new() failed\n"); goto error; } } else if (strcmp(argv[i], "copyone") == 0) { stage = copy_one_new(gles, geometry, source, target); if (!stage) { fprintf(stderr, "copy_one_new() failed\n"); goto error; } } else if (strcmp(argv[i], "deinterlace") == 0) { stage = deinterlace_new(gles, geometry, source, target); if (!stage) { fprintf(stderr, "deinterlace_new() failed\n"); goto error; } } else if (strcmp(argv[i], "cc") == 0) { stage = color_correct_new(gles, geometry, source, target); if (!stage) { fprintf(stderr, "color_correct_new() failed\n"); goto error; } } else { fprintf(stderr, "unsupported pipeline stage: %s\n", argv[i]); goto error; } /* * Only add the generator to the pipeline if the regenerate * flag was passed. Otherwise, render it only once. */ if (i > 0 || regenerate || argc == 1) { pipeline_add_stage(pipeline, stage); } else { stage->pipeline = pipeline; stage->render(stage); pipeline_stage_free(stage); } if (i < argc - 1) source = target; } return pipeline; error: framebuffer_free(target); pipeline_free(pipeline); return NULL; }
/** * \brief defines the drawing widget on which the actual schematic will be drawn * * @param height height of the content area * @param width width of the content area */ GtkWidget * sheet_new (gdouble height, gdouble width) { GooCanvas *sheet_canvas; GooCanvasGroup *sheet_group; GooCanvasPoints *points; Sheet *sheet; GtkWidget *sheet_widget; GooCanvasItem *root; // Creation of the Canvas sheet = SHEET (g_object_new (TYPE_SHEET, NULL)); sheet_canvas = GOO_CANVAS (sheet); g_object_set (G_OBJECT (sheet_canvas), "bounds-from-origin", FALSE, "bounds-padding", 4.0, "background-color-rgb", 0xFFFFFF, NULL); root = goo_canvas_get_root_item (sheet_canvas); sheet_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( root, NULL)); sheet_widget = GTK_WIDGET (sheet); goo_canvas_set_bounds (GOO_CANVAS (sheet_canvas), 0., 0., width + 20., height + 20.); // Define vicinity around GooCanvasItem //sheet_canvas->close_enough = 6.0; sheet->priv->width = width; sheet->priv->height = height; // Create the dot grid. sheet->grid = grid_new (GOO_CANVAS_ITEM (sheet_group), height, width); // Everything outside the sheet should be gray. // top // goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, 0.0, width + 20.0, 20.0, "fill_color", "gray", "line-width", 0.0, NULL); goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, height, width + 20.0, height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); // right // goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, 0.0, 20.0, height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), width, 0.0, width + 20.0, height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); if (oregano_options_debug_directions()) { goo_canvas_polyline_new_line (GOO_CANVAS_ITEM (sheet_group), 10.0, 10.0, 50.0, 10.0, "stroke-color", "green", "line-width", 2.0, "end-arrow", TRUE, NULL); goo_canvas_text_new (GOO_CANVAS_ITEM (sheet_group), "x", 90.0, 10.0, -1.0, GOO_CANVAS_ANCHOR_WEST, "fill-color", "green", NULL); goo_canvas_polyline_new_line (GOO_CANVAS_ITEM (sheet_group), 10.0, 10.0, 10.0, 50.0, "stroke-color", "red", "line-width", 2.0, "end-arrow", TRUE, NULL); goo_canvas_text_new (GOO_CANVAS_ITEM (sheet_group), "y", 10.0, 90.0, -1.0, GOO_CANVAS_ANCHOR_CENTER, "fill-color", "red", NULL); } // Draw a thin black border around the sheet. points = goo_canvas_points_new (5); points->coords[0] = 20.0; points->coords[1] = 20.0; points->coords[2] = width; points->coords[3] = 20.0; points->coords[4] = width; points->coords[5] = height; points->coords[6] = 20.0; points->coords[7] = height; points->coords[8] = 20.0; points->coords[9] = 20.0; goo_canvas_polyline_new (GOO_CANVAS_ITEM (sheet_group), FALSE, 0, "line-width", 1.0, "points", points, NULL); goo_canvas_points_unref (points); // Finally, create the object group that holds all objects. sheet->object_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( root, "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("root group %p", sheet->object_group); sheet->priv->selected_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( GOO_CANVAS_ITEM (sheet->object_group), "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("selected group %p", sheet->priv->selected_group); sheet->priv->floating_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( GOO_CANVAS_ITEM (sheet->object_group), "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("floating group %p", sheet->priv->floating_group); // Hash table that maps coordinates to a specific dot. sheet->priv->node_dots = g_hash_table_new_full (dot_hash, dot_equal, g_free, NULL); //this requires object_group to be setup properly sheet->priv->rubberband_info = rubberband_info_new (sheet); sheet->priv->create_wire_info = create_wire_info_new (sheet); return sheet_widget; }
void jacobi( std::size_t n , std::size_t iterations, std::size_t block_size , std::string output_filename) { typedef std::vector<double> vector; boost::shared_ptr<vector> grid_new(new vector(n * n, 1)); boost::shared_ptr<vector> grid_old(new vector(n * n, 1)); typedef std::vector<hpx::shared_future<void> > deps_vector; std::size_t n_block = static_cast<std::size_t>(std::ceil(double(n)/block_size)); boost::shared_ptr<deps_vector> deps_new( new deps_vector(n_block, hpx::make_ready_future())); boost::shared_ptr<deps_vector> deps_old( new deps_vector(n_block, hpx::make_ready_future())); hpx::util::high_resolution_timer t; for(std::size_t i = 0; i < iterations; ++i) { for(std::size_t y = 1, j = 0; y < n -1; y += block_size, ++j) { std::size_t y_end = (std::min)(y + block_size, n - 1); std::vector<hpx::shared_future<void> > trigger; trigger.reserve(3); trigger.push_back((*deps_old)[j]); if(j > 0) trigger.push_back((*deps_old)[j-1]); if(j + 1 < n_block) trigger.push_back((*deps_old)[j+1]); /* * FIXME: dataflow seems to have some raceconditions * left (*deps_new)[j] = hpx::dataflow( hpx::util::bind( jacobi_kernel_wrap , range(y, y_end) , n , boost::ref(*grid_new) , boost::cref(*grid_old) ) , trigger ); */ (*deps_new)[j] = hpx::when_all(std::move(trigger)).then( hpx::launch::async, hpx::util::bind( jacobi_kernel_wrap , range(y, y_end) , n , boost::ref(*grid_new) , boost::cref(*grid_old) ) ); } std::swap(grid_new, grid_old); std::swap(deps_new, deps_old); } hpx::wait_all(*deps_new); hpx::wait_all(*deps_old); report_timing(n, iterations, t.elapsed()); output_grid(output_filename, *grid_old, n); }