static void destructor(void *arg) { struct vidisp_st *st = arg; (void)st; sdl_close(); }
int main(int argc, char *argv[]) { int w = 222 * 2; int h = 222; int lebuf[w][h]; sdl_open(w, h); for (int c = 0; c < 22; c++) { for (int x = 0; x < (w * h); x++) lebuf[0][x] = c; sdl_plot(w, h, lebuf); if (sdl_waitkey()) return 1; } sdl_close(); return 0; }
int main(int argc, char *argv[]) { char *filename_base; char filename_table[100]; aero_model_t model; aero_env_t env; aero_table_output_t result; load_aero_model(&model, ""); load_aero_env(&env, ""); int w = 2 * 600 * MEGARES; int h = w; int *pix_buf = malloc(w * h * sizeof(int)); if (!pix_buf) { fprintf(stderr, "Unable to allocate %zu bytes for pix_buf\n", w * h * sizeof(int)); return 1; }; if (argc > 2) { if (strlen(argv[2]) + 10 > sizeof(filename_table)) { printf("Specify a shorter filename, please (max %zu)\n", sizeof(filename_table) - 10); return 1; } else filename_base = argv[2]; } else { printf("syntax: %s {w|r} basename\n",argv[0]); return 1; } snprintf(filename_table, sizeof(filename_table), "%s.table", filename_base); if (argv[1][0]=='r') { aero_table_t table; load_aero_table(&table,filename_table); aero_table_output_t result; sdl_open(w, h); for (int c=0; c<=1; c++) for (double a=-1; a<=1; a+=0.01) for (double b=-1; b<=1; b+=0.01) { if (a*a + b*b > 1.0001) continue; if (lookup_aero_table(&result,&table,a,b,c)) { printf("lookup fail for %.3f, %.3f, %d\n",a,b,c); continue; } double torque = xyz_norm(&result.torque); if (torque < 0.00015) { printf("Low torque position found: %.3f, %.3f, %d (%.4f)\n",a,b,c, torque); quat_t att; att_of_params(&att,a,b,c); memset(pix_buf, 0, w * h * sizeof(*pix_buf)); project_o_tron(&result, &model, att, w, h, pix_buf); sdl_plot(w, h, pix_buf); if (sdl_waitkey()) return 1; } } close_aero_table(&table); return 0; } if (argv[1][0]=='a') { aero_table_t table; load_aero_table(&table,filename_table); aero_table_output_t result; sdl_open(w, h); double a,b; int c; sscanf(argv[3],"%lf",&a); sscanf(argv[4],"%lf",&b); sscanf(argv[5],"%d",&c); if (lookup_aero_table(&result,&table,a,b,c)) { printf("lookup fail for %.3f, %.3f, %d\n",a,b,c); return 1; } double torque = xyz_norm(&result.torque); printf("Params: %.3f, %.3f, %d (%.4f)\n",a,b,c, torque); quat_t att; att_of_params(&att,a,b,c); memset(pix_buf, 0, w * h * sizeof(*pix_buf)); project_o_tron(&result, &model, att, w, h, pix_buf); sdl_plot(w, h, pix_buf); if (sdl_waitkey()) return 1; close_aero_table(&table); return 0; } FILE UU *table_file = fopen(filename_table, "wb"); const double param_step = 0.02; int UU o = 0; double max_torque = 0; int UU col=1; int coverage[600][600]; memset(coverage, 0, sizeof(coverage)); memset(pix_buf, 0, w * h * sizeof(*pix_buf)); int param_dim = round(2/param_step + 1); for (int c=0; c<2; c++) for (int ia = 0; ia < param_dim; ia ++) { for (int ib = 0; ib < param_dim; ib ++) { double a,b; a = 2.0 * ia / (param_dim-1) - 1; b = 2.0 * ib / (param_dim-1) - 1; if (a*a + b*b > 1.0001) { printf("skipping %f, %f\n",a,b); continue; } else printf("@ %f, %f \n",a,b); quat_t att; att_of_params(&att,a,b,c); /* if (c) pix_buf[(int)(100*a)+120 + w * ((int)(100*b)+120)] = col; else pix_buf[(int)(100*a)+420 + w * ((int)(100*b)+120)] = col; col%=7; col++; */ // printf("norm = %f\n",quat_norm(&att)); memset(pix_buf, 0, w * h * sizeof(*pix_buf)); project_o_tron(&result, &model, att, w, h, pix_buf); write_aero_table_entry(table_file, a, b,c, &result); #ifdef DRAW /* // Plot some color squares at the top, as a crude key / legend for (int i = 0; i < model.n_panels; i++) for (int y = 0; y < 22; y++) for (int x = 0; x < 22; x++) pix_buf[x + 22 * 2 * i + y * w] = i + 1; */ if (!o) { sdl_open(w, h); o = 1; } sdl_plot(w, h, pix_buf); if (sdl_poll_key()) goto end; // if (sdl_waitkey()) goto end; #endif double torque = .5 * env.rho * env.v * env.v * xyz_norm(&result.torque); if (torque > max_torque) { max_torque = torque; printf ("New max torque, %.2f microNewton meters\n", max_torque / 1E-6); // if (torque > 4e-6 && sdl_waitkey()) goto end; } } } #ifdef DRAW end: sdl_waitkey(); sdl_close(); #endif fclose(table_file); free(pix_buf); return 0; }
int main (int argc, char *argv[]) { if (sdl_init () != 0) return 1; if (textures_init ()) return 1; if (audio_init ()) { fprintf (stderr, "Error loading SFX: %s\n", SDL_GetError()); return 1; } if (music_init ()) { fprintf (stderr, "Error loading SFX: %s\n", SDL_GetError()); return 1; } if (config_load ()) { fprintf (stderr, "Error loading config\n"); } hiscore_init (); //gamestate = GAME_DEMO; running = 1; while (running) { sdl_read_input (); if (!paused) { SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); if (gamestate != GAME_OVER) SDL_RenderClear (renderer); switch (gamestate) { case GAME_DEMO: draw_test (); break; case GAME_RUNNING: game_loop (); break; case GAME_AMODE: default: amode_loop (); break; case GAME_OVER: gameover_loop (); break; case GAME_HSENTRY: hsentry_loop (); break; case GAME_CONFIG: case GAME_CONFIG_INPUT: config_loop (); break; case GAME_SELECT_RECORD: playback_loop (); break; } } SDL_RenderPresent (renderer); } hiscore_save (); sdl_close (); return 0; }