ENTRYPOINT void draw_voronoi (ModeInfo *mi) { voronoi_configuration *vp = &vps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (!vp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(vp->glx_context)); glShadeModel(GL_FLAT); glEnable(GL_POINT_SMOOTH); /* glEnable(GL_LINE_SMOOTH);*/ /* glEnable(GL_POLYGON_SMOOTH);*/ glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mi->polygon_count = 0; draw_cells (mi); move_points (vp); prune_points (vp); state_change (mi); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
int main(int argc, char**argv) { cellgrid *cgrid; cellgrid *tmpgrid; //*initialize program initscr(); start_color(); cbreak(); noecho(); nonl(); intrflush(stdscr,FALSE); keypad(stdscr, TRUE); assume_default_colors(COLOR_GREEN,COLOR_BLACK); clear(); gol_set_default_rules(); cgrid=create_cellgrid(LINES-2,COLS-1); generate_random_cells(cgrid); while(1) { draw_cells(cgrid); //getch(); gol_do_iteration(&cgrid); if(cgrid->iteration%5==0){ if(gol_is_repeating(cgrid)==TRUE){ sleep(2); free_cellgrid(cgrid); cgrid=create_cellgrid(LINES-2,COLS-1); generate_random_cells(cgrid); //generate_pulsar(cgrid); } } } sleep(3); endwin(); return 0; }
void update_and_render(Memory *memory, GameState *game_state, FrameBuffer *frame_buffer, Keys *keys, Mouse *mouse, u64 time_us, u32 last_frame_dt, u32 fps , u32 argc, char *argv[]) { if (!game_state->init) { init_render_segments(memory, game_state, frame_buffer); init_game(memory, game_state, keys, time_us, argc, argv); load_maze(memory, game_state, argc, argv); reset_zoom(game_state); } update_inputs(keys, &game_state->inputs, time_us); if (game_state->inputs.maps[SAVE].active) { serialize_maze(&game_state->maze, &game_state->functions, game_state->filename); } if (game_state->inputs.maps[RELOAD].active) { strcpy(game_state->persistent_str, "Reload!"); load_maze(memory, game_state, argc, argv); } if (game_state->inputs.maps[RESET].active) { strcpy(game_state->persistent_str, "Reset!"); reset_zoom(game_state); } if (game_state->inputs.maps[RESTART].active) { strcpy(game_state->persistent_str, "Restart!"); delete_all_cars(&game_state->cars); reset_car_inputs(&game_state->ui); game_state->finish_sim_step_move = false; game_state->last_sim_tick = 0; game_state->sim_steps = 0; } if (game_state->inputs.maps[STEP_MODE_TOGGLE].active) { game_state->single_step = !game_state->single_step; log(L_GameLoop, "Changing stepping mode"); } // // UPDATE VIEW // update_pan_and_zoom(game_state, mouse); RenderBasis render_basis; render_basis.world_per_pixel = game_state->world_per_pixel; render_basis.scale = squared(game_state->zoom / 30.0f); render_basis.scale_focus = game_state->scale_focus; render_basis.origin = game_state->maze_pos * game_state->world_per_pixel; render_basis.clip_region = game_state->world_render_region * game_state->world_per_pixel; RenderBasis orthographic_basis; get_orthographic_basis(&orthographic_basis, game_state->screen_render_region); // // UPDATE WORLD // ui_consume_mouse_clicks(game_state, &orthographic_basis, &game_state->ui, mouse, time_us); if (game_state->inputs.maps[SIM_TICKS_INC].active) { game_state->sim_ticks_per_s += .5f; } if (game_state->inputs.maps[SIM_TICKS_DEC].active) { game_state->sim_ticks_per_s -= .5f; } game_state->sim_ticks_per_s = clamp(.5, game_state->sim_ticks_per_s, 20); update_cells_ui_state(game_state, &render_basis, mouse, time_us); b32 sim = sim_tick(game_state, time_us); if (sim && game_state->ui.car_inputs == 0 && !game_state->finish_sim_step_move) { perform_cells_sim_tick(memory, game_state, &(game_state->maze.tree), time_us); perform_cars_sim_tick(memory, game_state, time_us); } if (sim && game_state->ui.car_inputs == 0) { move_cars(game_state); game_state->finish_sim_step_move = false; ++game_state->sim_steps; } annimate_cars(game_state, last_frame_dt); step_particles(&(game_state->particles), time_us); update_ui(game_state, &orthographic_basis, &game_state->ui, mouse, &game_state->inputs, time_us); // // RENDER // // Add render operations to queue game_state->render_operations.next_free = 0; add_fast_box_to_render_list(&game_state->render_operations, &orthographic_basis, (Rectangle) { (V2) {0,0},size(game_state->screen_render_region) }, (PixelColor) { 255, 255, 255 }); draw_cells(game_state, &game_state->render_operations, &render_basis, &(game_state->maze.tree), time_us); draw_cars(game_state, &game_state->render_operations, &render_basis, &(game_state->cars), time_us); // render_particles(&(game_state->particles), &game_state->render_operations, &render_basis); r32 text_scale = 0.3; draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, size(game_state->screen_render_region) - CHAR_SIZE*text_scale*(V2) { strlen(game_state->persistent_str), 1 }, game_state->persistent_str, text_scale, (V4) { 1, 0, 0, 0 }); draw_ui(&game_state->render_operations, &orthographic_basis, &render_basis, &game_state->bitmaps.font, &game_state->cell_bitmaps, &game_state->ui, time_us); char str[4]; fmted_str(str, 4, "%d", fps); draw_string(&game_state->render_operations, &orthographic_basis, &game_state->bitmaps.font, (V2) { 0, 0 }, str, 0.3, (V4) { 1, 0, 0, 0 }); // Add render segments to render queue V2 ns = game_state->render_segs.n_segments; V2 s; for (s.y = 0; s.y < ns.y; ++s.y) { for (s.x = 0; s.x < ns.x; ++s.x) { RenderQueueData render_data; Rectangle *segment = game_state->render_segs.segments + (u32)s.y + (u32)ns.y*(u32)s.x; render_data.clip_region = *segment; render_data.frame_buffer = frame_buffer; render_data.render_operations = &game_state->render_operations; #ifdef THREADED_RENDERING pthread_mutex_lock(&game_state->render_queue.mut); while (game_state->render_queue.full) { log(L_RenderQueue, "producer: queue FULL."); pthread_cond_wait(&game_state->render_queue.not_full, &game_state->render_queue.mut); } log(L_RenderQueue, "producer: Adding."); queue_add(&game_state->render_queue, render_data); pthread_mutex_unlock(&game_state->render_queue.mut); pthread_cond_signal(&game_state->render_queue.not_empty); #else consume_render_operations(render_data.frame_buffer, render_data.render_operations, render_data.clip_region); #endif } } // TODO: Wait for frame rendering to finish // TODO: Get rid of this game_state->last_render_basis = render_basis; }
/* * paint event that draws the state of the game and is called by an update */ void Widget::paintEvent(QPaintEvent *) { QPainter p(this); // painter draw_board(p); // draw the board margins draw_cells(p); // draw the live cells }