int main(int argc, char *argv[]) { // Set the translation part to be the identity. locked_matrix[3][0] = locked_matrix[3][1] = locked_matrix[3][2] = 0; locked_matrix[0][3] = locked_matrix[1][3] = locked_matrix[2][3] = 0; locked_matrix[3][3] = 1; locked_matrix[0][0] = locked_matrix[1][1] = locked_matrix[2][2] = 1; locked_matrix[0][1] = locked_matrix[1][0] = locked_matrix[2][0] = locked_matrix[0][2]= locked_matrix[2][1] = locked_matrix[1][2]=0; memcpy(&final_matrix,locked_matrix[0],sizeof last_matrix); try { bcm_host_init(); opengl_init(); projection_init(); textures_init(); model_board_init(); printf("AHRS Textures loaded\n"); fflush(stdout); uint32_t time_start = 0; int missed = 0; uint32_t time_fps = 0; int fps = 0; uint32_t time_delay = 0; //non blocking sdtin read fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK); while(1) { time_start += 20; uint32_t predicted_delay = time_start - millis(); //calc predicted delay if (predicted_delay > 20) predicted_delay = 0; //check for overflow if (predicted_delay != 0){ delay(predicted_delay); time_delay += predicted_delay; }else{ time_start = millis(); //reset timer to now printf("AHRS Skipping Idle...\n"); missed++; } int count = 1; char buffer[100]; //stdin is line buffered so we can cheat a little bit while (count > 0){ // dump entire buffer count = read(STDIN_FILENO, buffer, sizeof(buffer)); if (count > 1){ //ignore blank lines buffer[count-1] = '\0'; //replace last char with string ending //printf("!%s!\n",buffer); //check the line int temp[4]; int result = sscanf(buffer,"%d %d %d", &temp[0], &temp[1], &temp[2]); if (result != 3){ fprintf(stderr, "AHRS Unrecognized input with %d items.\n", result); }else{ acceleration[0] = temp[1]; acceleration[1] = temp[2]; acceleration[2] = 0; frame = temp[0]; } } } if (state != frame){ printf("AHRS Entering Mode %d\n",frame); state = frame; changes++; } redraw_scene(); fps++; if (time_fps < millis()){ printf("AHRS FPS:%d mis:%d idle:%d%% changes:%d\n",fps,missed,time_delay/10, changes); fps = 0; time_delay = 0; time_fps += 1000; if (time_fps < millis()) time_fps = millis()+1000; } } opengl_deinit(); bcm_host_deinit(); return 0; } catch(const std::exception & error) { std::cerr << "Error: " << error.what() << std::endl; exit(9); } }
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; }