int main( int argc, char* args[] ) { bool quit = false; if ( init() == false ) { return 1; } if ( load_files() == false ) { return 1; } //Make the timer Timer myTimer; //Generate the message surfaces startStop = TTF_RenderText_Solid( font, "Press S to start or stop the timer", textColor ); pauseMessage = TTF_RenderText_Solid( font, "Press P to pause or unpause the timer", textColor ); //Start the timer myTimer.start(); //While the user hasn't quit while ( quit == false ) { while ( SDL_PollEvent( &event ) ) { if ( event.type == SDL_KEYDOWN ) { if ( event.key.keysym.sym == SDLK_s) { if ( myTimer.is_started() == true ) { myTimer.stop(); } else { myTimer.start(); } } if ( event.key.keysym.sym == SDLK_p ) { if ( myTimer.is_paused() == true ) { myTimer.unpause(); } else { myTimer.pause(); } } } else if ( event.type == SDL_QUIT ) { quit = true; } } apply_surface( 0, 0, background, screen ); apply_surface( ( SCREEN_WIDTH - startStop->w ) / 2, 200, startStop, screen ); apply_surface( ( SCREEN_WIDTH - pauseMessage->w ) / 2, 250, pauseMessage, screen ); //The timer's time as a string std::stringstream time; time << "Timer: " << myTimer.get_ticks() / 1000.f; seconds = TTF_RenderText_Solid( font, time.str().c_str(), textColor ); apply_surface( ( SCREEN_WIDTH - seconds->w ) / 2, 0, seconds, screen ); SDL_FreeSurface( seconds ); if ( SDL_Flip( screen ) == -1 ) { return 1; } } //Clean up clean_up(); return 0; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //The ship that will be used Ship myShip; //Keeps track of time since last rendering Timer delta; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Start delta timer delta.start(); //While the user hasn't quit while( quit == false ) { //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the ship myShip.handle_input(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the ship myShip.move( delta.get_ticks() ); //Restart delta timer delta.start(); //Fill the screen white //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); //Show the ship on the screen myShip.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } } //Clean up clean_up(); return 0; }
int main(int argc, char* args[]) { //make sure the program waits for a quit bool quit = false; if (!init()) { std::cerr << "failed to initialize SDL" << std::endl; return 1; } //load files if(!load_files()) { std::cerr << "failed to load images" << std::endl; return 1; } //top left clip[0].x = 0; clip[0].y = 0; clip[0].w = 100; clip[0].h = 100; //top right clip[1].x = 100; clip[1].y = 0; clip[1].w = 100; clip[1].h = 100; //bottom left clip[2].x = 0; clip[2].y = 100; clip[2].w = 100; clip[2].h = 100; //bottom right clip[3].x = 100; clip[3].y = 100; clip[3].w = 100; clip[3].h = 100; SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF) ); //apply image to screen // apply_surface(0, 0, background, screen); apply_surface(0, 0, image, screen, &clip[0]); apply_surface(540, 0, image, screen, &clip[1]); apply_surface(0, 380, image, screen, &clip[2]); apply_surface(540, 380, image, screen, &clip[3]); //update screen if ( SDL_Flip(screen) == -1) { std::cerr << "error flipping screen" << std::endl; return 1; } //Pause while(!quit) { while( SDL_PollEvent(&event) ) { //if user quits if(event.type==SDL_QUIT) { //quit program quit = true; } } } clean_up(); return 0; }
int main (int argc, char *argv[]) { ret_t ret; cherokee_boolean_t single_time; const char *config_file_path; /* Find the worker exec */ figure_worker_path (argv[0]); /* Sanity check */ ret = check_worker_version (argv[0]); if (ret != ret_ok) exit (EXIT_ERROR); set_signals(); single_time = is_single_execution (argc, argv); /* Figure out some stuff */ config_file_path = figure_config_file (argc, argv); use_valgrind = figure_use_valgrind (argc, argv); pid_file_path = figure_pid_file_path (config_file_path); worker_uid = figure_worker_uid (config_file_path); worker_retcode = -1; /* Turn into a daemon */ if (! single_time) { may_daemonize (argc, argv); pid_file_save (pid_file_path, getpid()); } /* Launch the spawning thread */ #ifdef HAVE_SYSV_SEMAPHORES if (! single_time) { ret = spawn_init(); if (ret != ret_ok) { PRINT_MSG_S ("(warning) Couldn't initialize spawn mechanism.\n"); } } #endif while (true) { graceful_restart = false; pid = process_launch (cherokee_worker, argv); if (pid < 0) { PRINT_MSG ("(critical) Couldn't launch '%s'\n", cherokee_worker); exit (EXIT_ERROR); } ret = process_wait (pid); if (single_time) break; usleep ((ret == ret_ok) ? DELAY_RESTARTING : DELAY_ERROR); } if (! single_time) { clean_up(); } return (worker_retcode == 0) ? EXIT_OK : EXIT_ERROR; }
int main( int argc, char* args[] ) { bool quit = false; bool debug = false; int level = 1; Player control(200,700); Ball bullet(200 + PADDLE_WIDTH/2, 500); int tilesDestroyed = 0; float startTicks = 0; float deltaTicks = 0; char ballVelX[5]; char ballVelY[5]; char playerLife[5]; Tile *tiles[TOTAL_TILES]; int destroyedTile[TOTAL_TILES]; for( int t = 0; t < TOTAL_TILES; t++ ) { destroyedTile[t] = false; } if(init() == false) { return 5; } if(load_files() == false) { return 6; } clip_tiles(); if( set_tiles( tiles , level ) == false ) { return 1; } startTicks = SDL_GetTicks(); while(quit == false) { tilesDestroyed = 0; while(SDL_PollEvent(&event)) { if((event.type == SDL_KEYDOWN)) { if(event.key.keysym.sym == SDLK_1 && debug == true)//Adjusting velocity via the 1 number key in debuging mode { bullet.xVelocity += 100; bullet.yVelocity += 100; } else if(event.key.keysym.sym == SDLK_2 && debug == true)//Adjusting velocity via the 2 number key in debuging mode { bullet.xVelocity -= 100; bullet.yVelocity -= 100; } else if(event.key.keysym.sym == SDLK_F1)//Enabling or disabling debuging mode ( information of velocities) { if(debug == false) { debug = true; } else { debug = false; } } } control.handle_input();//Handle the paddle's movement if(event.type == SDL_QUIT) { quit = true; } } deltaTicks = SDL_GetTicks() - startTicks;//Frame rate control.move(deltaTicks); bullet.move(control.player,tiles,deltaTicks,destroyedTile);//Moving the ball SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) );//Black color every frame for( int t = 0; t < TOTAL_TILES; t++ ) { if(destroyedTile[t] == 0) { tiles[ t ]->show(); } } control.show(); bullet.show(); sprintf(ballVelX,"xVel %d",bullet.xVelocity);//Formating text to be displayed for the HUD sprintf(ballVelY,"yVel %d",bullet.yVelocity); sprintf(playerLife,"Life : %d",bullet.life); showBallvelocityX = TTF_RenderText_Solid(font,ballVelX,textColor); showBallvelocityY = TTF_RenderText_Solid(font,ballVelY,textColor); life = TTF_RenderText_Solid(font,playerLife,textColor); apply_surface(20, 10, life, screen ); if(debug == true) { apply_surface(20, 50, showBallvelocityX, screen ); apply_surface(20, 70, showBallvelocityY, screen ); SDL_FreeSurface(showBallvelocityY); SDL_FreeSurface(showBallvelocityX); } startTicks = SDL_GetTicks(); deltaTicks = 0; for( int t = 0; t < TOTAL_TILES; t++ )//Checking how many tiles are destroyed in the game { if(destroyedTile[t] == 1) { tilesDestroyed++; } } if(bullet.life == 0 || tilesDestroyed == TOTAL_TILES)//Close the game if life drops to zero or all the tiles are destroyed in the game { quit = true; } if( SDL_Flip( screen ) == -1 ) { return 1; } } clean_up(); return 0; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //The square Square mySquare; //The frame rate regulator Timer fps; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Set the wall wall.x = 300; wall.y = 40; wall.w = 40; wall.h = 400; //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the square mySquare.handle_input(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the square mySquare.move(); //Fill the screen white SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); //Show the wall SDL_FillRect( screen, &wall, SDL_MapRGB( screen->format, 0x77, 0x77, 0x77 ) ); //Show the square on the screen mySquare.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; }
static void cluster_shutdown(int nsig) { clean_up(0); }
int main( int argc, char* args[] ) { //Initialize if( init() == false ) { return 1; } SDL_Surface* images[4]; image = load_image("vida.png"); images[0]=load_image( "run01.png" ); images[1]=load_image( "run02.png" ); images[2]=load_image( "run03.png" ); images[3]=load_image( "run04.png" ); int a=50; int b=50; bool cont = true; int x=0; while(cont){ if(x>3){ x=0; } //If there was a problem in loading the image if( images == NULL ) { return 1; } SDL_Event event; //While there's events to handle while( SDL_PollEvent( &event ) ) { //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program // quit = true; cont = false; } } Uint8 *keystates = SDL_GetKeyState( NULL ); if(keystates[SDLK_RIGHT]){ a += 10; } if(keystates[SDLK_LEFT]){ a -= 10; } if(keystates[SDLK_UP]){ b -= 10; } if(keystates[SDLK_DOWN]){ b += 10; } //Apply the surface to the screen apply_surface(0,0, image,screen); apply_surface( a, b, images[x], screen ); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Wait 2 seconds SDL_Delay( 20 ); x++; } //Free the surface and quit SDL clean_up(); return 0; }
EXPORT void fprint_gas_data( FILE *file, Locstate state) { (void) fprintf(file,"State information for the "); if (state == NULL) { (void) fprintf(file,"NULL state 0x%p\n\n",(POINTER)state); return; } if (is_obstacle_state(state)) { (void) fprintf(file,"OBSTACLE state 0x%p\n\n",(POINTER)state); return; } (void) fprintf(file,"state 0x%p\n",(POINTER)state); (void) fprintf(file,"\tState Data "); if (is_binary_output() == YES) { uint64_t prms; float *x; int stype = state_type(state); int failed = material_failure(state); (void) fprintf(file,"\f%c",(char)Params(state)->sizest); x = &Dens(state); (void) fwrite((const void *)x,FLOAT,2+SMAXD,file); prms = gas_param_number(Params(state)); (void) fwrite((const void *)&prms,sizeof(uint64_t),1,file); (void) fwrite((const void *)&stype,sizeof(int),1,file); (void) fwrite((const void *)&failed,sizeof(int),1,file); #if defined(COMBUSTION_CODE) switch (Composition_type(state)) { case ZND: case PTFLAME: (void) fwrite((const void *)pdens(state),FLOAT,1,file); break; case TWO_CONSTITUENT_REACTIVE: (void) fwrite((const void *)pdens(state),FLOAT,2,file); break; case PURE_NON_REACTIVE: default: break; } #endif /* defined(COMBUSTION_CODE) */ if(g_composition_type() == MULTI_COMP_NON_REACTIVE) { if(Params(state) != NULL && Params(state)->n_comps != 1) { int i; for(i = 0; i < Params(state)->n_comps; i++) (void) fwrite((const void *)&(pdens(state)[i]),FLOAT,1,file); } } (void) fprintf(file,"\n"); return; } (void) fprintf(file,"\n"); switch (state_type(state)) { case GAS_STATE: g_fprint_state(file,state); break; case EGAS_STATE: g_fprint_Estate(file,state); break; case TGAS_STATE: g_fprint_Tstate(file,state); break; case FGAS_STATE: g_fprint_Fstate(file,state); break; case VGAS_STATE: verbose_fprint_state(file,"",state); break; default: screen("ERROR in fprint_gas_data(), " "unknown state type %d\n",state_type(state)); clean_up(ERROR); } } /*end fprint_gas_data*/
/** main * */ int main ( int argc, char **argv ) { fprintf( stderr, "lsmi-joystick" " v" VERSION "\n" ); get_args( argc, argv ); fprintf( stderr, "Registering MIDI port...\n" ); seq = open_client( CLIENT_NAME ); if ( NULL == seq ) { fprintf( stderr, "Error opening alsa sequencer!\n" ); exit( 1 ); } if ( ( port = open_output_port( seq ) ) < 0 ) { fprintf( stderr, "Error opening MIDI output port!\n" ); exit( 1 ); } if ( sub_name ) { snd_seq_addr_t addr; if ( snd_seq_parse_address( seq, &addr, sub_name ) < 0 ) fprintf( stderr, "Couldn't parse address '%s'", sub_name ); else if ( snd_seq_connect_to( seq, port, addr.client, addr.port ) < 0 ) { fprintf( stderr, "Error creating subscription for port %i:%i", addr.client, addr.port ); exit( 1 ); } } if ( daemonize ) { printf( "Running as daemon...\n" ); if ( fork() ) exit( 0 ); else { fclose( stdout ); fclose( stderr ); } } fprintf( stderr, "Initializing joystick...\n" ); if ( -1 == ( jfd = open( joydevice, O_RDONLY ) ) ) { fprintf( stderr, "Error opening event interface! (%s)\n", strerror( errno ) ); clean_up(); exit(1); } set_traps(); fprintf( stderr, "Waiting for events...\n" ); for ( ;; ) { struct js_event e; snd_seq_event_t ev; static int b1; static int b2; read (jfd, &e, sizeof(struct js_event)); snd_seq_ev_clear( &ev ); switch (e.type) { case JS_EVENT_BUTTON: switch (e.number) { case 0: if(e.value) b1 = 1; else { b1 = 0; snd_seq_ev_set_pitchbend( &ev, channel, 0 ); send_event( &ev ); } break; case 1: if (e.value) b2 = 1; else { b2 = 0; snd_seq_ev_set_controller( &ev, channel, 1, 0 ); send_event( &ev ); snd_seq_ev_set_controller( &ev, channel, 33, 0 ); send_event( &ev ); } break; } break; case JS_EVENT_AXIS: if ( e.number == 1 && ( b1 || nohold ) ) { snd_seq_ev_set_pitchbend( &ev, channel, 0 - (int)((e.value) * ((float)8191/32767) )); send_event( &ev ); } else if ( ( e.number == 1 && b2 ) || ( e.number == 0 && ( ( b1 && b2 ) || nohold ) ) ) { int fine = (int)((0 - e.value) + 32767) * ((float)16383/65534); int course = fine >> 7; fine &= 0x7F; snd_seq_ev_set_controller( &ev, channel, 1, course ); send_event( &ev ); snd_seq_ev_set_controller( &ev, channel, 33, fine ); send_event( &ev ); } break; default: break; } }
~RAII_guard() { clean_up(); }
int srv_run(const std::string& table_prefix, bool use_sql, const std::string& conf_file) { for (int i = 0; i < 8; i++) m_secret = m_secret << 8 ^ rand(); m_conf_file = conf_file; m_database.set_name("config", table_prefix + "config"); m_table_prefix = table_prefix; m_use_sql = use_sql; read_config(); if (test_sql()) return 1; if (m_epoll.create() == -1) { std::cerr << "epoll_create failed" << std::endl; return 1; } std::list<Ctcp_listen_socket> lt; std::list<Cudp_listen_socket> lu; for (auto& j : m_config.m_listen_ipas) { for (auto& i : m_config.m_listen_ports) { Csocket l; if (l.open(SOCK_STREAM) == INVALID_SOCKET) std::cerr << "socket failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; else if (l.setsockopt(SOL_SOCKET, SO_REUSEADDR, true), l.bind(j, htons(i))) std::cerr << "bind failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; else if (l.listen()) std::cerr << "listen failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; else { #ifdef SO_ACCEPTFILTER accept_filter_arg afa; bzero(&afa, sizeof(afa)); strcpy(afa.af_name, "httpready"); if (l.setsockopt(SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa))) std::cerr << "setsockopt failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; #elif 0 // TCP_DEFER_ACCEPT if (l.setsockopt(IPPROTO_TCP, TCP_DEFER_ACCEPT, 90)) std::cerr << "setsockopt failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; #endif lt.push_back(Ctcp_listen_socket(l)); if (!m_epoll.ctl(EPOLL_CTL_ADD, l, EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLERR | EPOLLHUP, <.back())) continue; } return 1; } for (auto& i : m_config.m_listen_ports) { Csocket l; if (l.open(SOCK_DGRAM) == INVALID_SOCKET) std::cerr << "socket failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; else if (l.setsockopt(SOL_SOCKET, SO_REUSEADDR, true), l.bind(j, htons(i))) std::cerr << "bind failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; else { lu.push_back(Cudp_listen_socket(l)); if (!m_epoll.ctl(EPOLL_CTL_ADD, l, EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP, &lu.back())) continue; } return 1; } } clean_up(); read_db_torrents(); read_db_users(); write_db_torrents(); write_db_users(); #ifndef NDEBUG // test_announce(); #endif #ifndef WIN32 if (m_config.m_daemon) { if (daemon(true, false)) std::cerr << "daemon failed" << std::endl; std::ofstream(m_config.m_pid_file.c_str()) << getpid() << std::endl; struct sigaction act; act.sa_handler = sig_handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; if (sigaction(SIGTERM, &act, NULL)) std::cerr << "sigaction failed" << std::endl; act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, NULL)) std::cerr << "sigaction failed" << std::endl; } #endif #ifdef EPOLL std::array<epoll_event, 64> events; #else fd_set fd_read_set; fd_set fd_write_set; fd_set fd_except_set; #endif while (!g_sig_term) { #ifdef EPOLL int r = m_epoll.wait(events.data(), events.size(), 5000); if (r == -1) std::cerr << "epoll_wait failed: " << errno << std::endl; else { time_t prev_time = m_time; m_time = ::time(NULL); for (int i = 0; i < r; i++) reinterpret_cast<Cclient*>(events[i].data.ptr)->process_events(events[i].events); if (m_time == prev_time) continue; for (auto i = m_connections.begin(); i != m_connections.end(); ) { if (i->run()) i = m_connections.erase(i); else i++; } } #else FD_ZERO(&fd_read_set); FD_ZERO(&fd_write_set); FD_ZERO(&fd_except_set); int n = 0; for (auto& i : m_connections) { int z = i.pre_select(&fd_read_set, &fd_write_set); n = std::max(n, z); } for (auto& i : lt) { FD_SET(i.s(), &fd_read_set); n = std::max<int>(n, i.s()); } for (auto& i : lu) { FD_SET(i.s(), &fd_read_set); n = std::max<int>(n, i.s()); } timeval tv; tv.tv_sec = 5; tv.tv_usec = 0; if (select(n + 1, &fd_read_set, &fd_write_set, &fd_except_set, &tv) == SOCKET_ERROR) std::cerr << "select failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; else { m_time = ::time(NULL); for (auto& i : lt) { if (FD_ISSET(i.s(), &fd_read_set)) accept(i.s()); } for (auto& i : lu) { if (FD_ISSET(i.s(), &fd_read_set)) Ctransaction(i.s()).recv(); } for (auto i = m_connections.begin(); i != m_connections.end(); ) { if (i->post_select(&fd_read_set, &fd_write_set)) i = m_connections.erase(i); else i++; } } #endif if (srv_time() - m_read_config_time > m_config.m_read_config_interval) read_config(); else if (srv_time() - m_clean_up_time > m_config.m_clean_up_interval) clean_up(); else if (srv_time() - m_read_db_torrents_time > m_config.m_read_db_interval) read_db_torrents(); else if (srv_time() - m_read_db_users_time > m_config.m_read_db_interval) read_db_users(); else if (m_config.m_write_db_interval && srv_time() - m_write_db_torrents_time > m_config.m_write_db_interval) write_db_torrents(); else if (m_config.m_write_db_interval && srv_time() - m_write_db_users_time > m_config.m_write_db_interval) write_db_users(); } write_db_torrents(); write_db_users(); unlink(m_config.m_pid_file.c_str()); return 0; }
void clean_up() { for (auto& i : m_torrents) clean_up(i.second, srv_time() - static_cast<int>(1.5 * m_config.m_announce_interval)); m_clean_up_time = srv_time(); }
int AVIBegin(const char* filename, struct AVIFile* _avi_out) { AVIFile& avi = *_avi_out; int result = 0; do { if(!avi.video_added) break; if(!truncate_existing(filename)) break; // open the file if(FAILED(AVIFileOpen(&avi.avi_file, filename, OF_CREATE | OF_WRITE, NULL))) break; // create the video stream memset(&avi.avi_video_header, 0, sizeof(AVISTREAMINFO)); avi.avi_video_header.fccType = streamtypeVIDEO; avi.avi_video_header.dwScale = ONE_DOT_CYCLE*SNES_HCOUNTER_MAX*SNES_MAX_NTSC_VCOUNTER; avi.avi_video_header.dwRate = (int)NTSC_MASTER_CLOCK; avi.avi_video_header.dwSuggestedBufferSize = avi.bitmap_format.biSizeImage; if(FAILED(AVIFileCreateStream(avi.avi_file, &avi.streams[VIDEO_STREAM], &avi.avi_video_header))) break; if(use_prev_options) { avi.compress_options[VIDEO_STREAM] = saved_avi_info.compress_options[VIDEO_STREAM]; avi.compress_options_ptr[VIDEO_STREAM] = &avi.compress_options[0]; } else { // get compression options memset(&avi.compress_options[VIDEO_STREAM], 0, sizeof(AVICOMPRESSOPTIONS)); avi.compress_options_ptr[VIDEO_STREAM] = &avi.compress_options[0]; if(!AVISaveOptions(GUI.hWnd, 0, 1, &avi.streams[VIDEO_STREAM], &avi.compress_options_ptr[VIDEO_STREAM])) break; } // create compressed stream if(FAILED(AVIMakeCompressedStream(&avi.compressed_streams[VIDEO_STREAM], avi.streams[VIDEO_STREAM], &avi.compress_options[VIDEO_STREAM], NULL))) break; // set the stream format if(FAILED(AVIStreamSetFormat(avi.compressed_streams[VIDEO_STREAM], 0, (void*)&avi.bitmap_format, avi.bitmap_format.biSize))) break; // add sound (if requested) if(avi.sound_added) { // create the audio stream memset(&avi.avi_sound_header, 0, sizeof(AVISTREAMINFO)); avi.avi_sound_header.fccType = streamtypeAUDIO; avi.avi_sound_header.dwQuality = (DWORD)-1; avi.avi_sound_header.dwScale = avi.wave_format.nBlockAlign; avi.avi_sound_header.dwRate = avi.wave_format.nAvgBytesPerSec; avi.avi_sound_header.dwSampleSize = avi.wave_format.nBlockAlign; avi.avi_sound_header.dwInitialFrames = 1; if(FAILED(AVIFileCreateStream(avi.avi_file, &avi.streams[AUDIO_STREAM], &avi.avi_sound_header))) break; // AVISaveOptions doesn't seem to work for audio streams // so here we just copy the pointer for the compressed stream avi.compressed_streams[AUDIO_STREAM] = avi.streams[AUDIO_STREAM]; // set the stream format if(FAILED(AVIStreamSetFormat(avi.compressed_streams[AUDIO_STREAM], 0, (void*)&avi.wave_format, sizeof(WAVEFORMATEX)))) break; } // initialize counters avi.video_frames = 0; avi.sound_samples = 0; avi.tBytes = 0; avi.ByteBuffer = 0; avi.audio_buffer_pos = 0; strncpy(saved_cur_avi_fnameandext,filename,MAX_PATH); strncpy(saved_avi_fname,filename,MAX_PATH); char* dot = strrchr(saved_avi_fname, '.'); if(dot && dot > strrchr(saved_avi_fname, '/') && dot > strrchr(saved_avi_fname, '\\')) { strcpy(saved_avi_ext,dot); dot[0]='\0'; } // success result = 1; avi.valid = true; } while(false); if(!result) { clean_up(&avi); avi.valid = false; } return result; }
int main(int argc, const char * argv[]) { get_ready(); /* stupid_tests(); printf("[tests.main]\tsanity check: sizeof(unsigned long) = %d\n", (int) sizeof(unsigned long)); printf("[tests.main]\trunning tests....\n"); Board board; setup(&board); printf("\n"); printb(&board); printf("\n"); test_to_play(&board); test_ply(&board); if(WIN == test_file_attacks()) printf("[tests.file_attacks]\tpassed\n"); else printf("[tests.file_attacks]\tFAILED!\n"); if(WIN == test_rank_attacks()) printf("[tests.rank_attacks]\tpassed\n"); else printf("[tests.rank_attacks]\tFAILED!\n"); if(WIN == test_initf()) printf("[tests.initf]\t\tpassed\n"); else printf("[tests.initf]\t\tFAILED!\n"); if(WIN == test_tl_br_attacks()) printf("[tests.tl_br_attacks]\tpassed\n"); else printf("[tests.tl_br_attacks]\tFAILED!\n"); if(WIN == test_knight_attacks()) printf("[tests.knight_attacks]\tpassed\n"); else printf("[tests.knight_attacks]\tFAILED!\n"); if(WIN == test_king_attacks()) printf("[tests.king_attacks]\tpassed\n"); else printf("[tests.king_attacks]\tFAILED!\n"); if(WIN == test_moves()) printf("[tests.moves]\t\tpassed\n"); else printf("[tests.moves]\t\tFAILED!\n"); if(WIN == test_conversions()) printf("[tests.conversions]\tpassed\n"); else printf("[tests.conversions]\tFAILED!\n"); if(WIN == test_apply_move()) printf("[tests.apply_move]\tpassed\n"); else printf("[tests.apply_move]\tFAILED!\n"); */ if(WIN == test_search()) printf("[tests.search]\t\tpassed\n"); else printf("[tests.search]\t\tFAILED!\n"); /* test_scout(); */ clean_up(); printf("\n[tests.main]\t\ttests complete\n"); return EXIT_SUCCESS; }
EXPORT void g_fprint_hsbdry_type( FILE *file, const char *mesg1, int hsbdry_type, const char *mesg2, INTERFACE *intfc) { const char *suffix; switch (intfc->dim) { case 3: suffix = "HSBDRY"; break; case 2: suffix = "NODE"; break; case 1: screen("ERROR in g_fprint_hsbdry_type(), " "invalid dimension %d\n",intfc->dim); clean_up(ERROR); } if (hsbdry_type < FIRST_PHYSICS_HSBDRY_TYPE) { f_fprint_hsbdry_type(file,mesg1,hsbdry_type,mesg2,intfc); return; } if (mesg1 != NULL) (void) fprintf(file,"%s",mesg1); switch(hsbdry_type) { case B_REFLECT_HSBDRY: (void) fprintf(file,"B_REFLECT_%s",suffix); break; case MACH_HSBDRY: (void) fprintf(file,"MACH_%s",suffix); break; case ATTACHED_B_HSBDRY: (void) fprintf(file,"ATTACHED_B_%s",suffix); break; case CROSS_HSBDRY: (void) fprintf(file,"CROSS_%s",suffix); break; case OVERTAKE_HSBDRY: (void) fprintf(file,"OVERTAKE_%s",suffix); break; case DIFFRACTION_HSBDRY: (void) fprintf(file,"DIFFRACTION_%s",suffix); break; case TRANSMISSION_HSBDRY: (void) fprintf(file,"TRANSMISSION_%s",suffix); break; case CC_HSBDRY: (void) fprintf(file,"CC_%s",suffix); break; case WAVE_END_HSBDRY: (void) fprintf(file,"WAVE_END_%s",suffix); break; case TOT_INT_REFL_HSBDRY: (void) fprintf(file,"TOT_INT_REFL_%s",suffix); break; //#bjet2 case NEUMANN_CURVE: (void) fprintf(file,"NEUMANN_CURVE"); break; default: (void) fprintf(file,"%d -- ** UNKNOWN %s TYPE **", hsbdry_type,suffix); break; } if (mesg2 != NULL) (void) fprintf(file,"%s",mesg2); } /*end g_fprint_hsbdry_type*/
static void catch_sigterm(int s) { (void) s; clean_up(); }
int mainMenu::run() // runs the main menu { int result=0; //Quit flag bool quit = false; //Initialize if( init() == false ) { return -1; } //Load the files if( load_files() == false ) { return -1; } //Apply the first screen show_Main(); //While the user hasn't quit while( quit == false ) { bgMusic.play(); //While there's events to handle while( SDL_PollEvent( &event ) ) { if(event.type==SDL_KEYDOWN) { if(event.key.keysym.sym==SDLK_UP) { if(arrowPos==2 && screenNum==0) // main menu is showing { arrowPos=0; } else if((arrowPos==1 || arrowPos==2 || arrowPos==3)&&screenNum==1) // options is showing { if(arrowPos==3) { arrowPos-=2; } else { arrowPos=0; } } else { arrowPos=arrowPos; } } else if(event.key.keysym.sym==SDLK_RIGHT) // moves arrow to the right { if(arrowPos==0 && screenNum==0) { arrowPos=1; } else if(arrowPos==1 && screenNum==1) { arrowPos=2; } else { arrowPos=arrowPos; } } else if(event.key.keysym.sym==SDLK_LEFT) // moves arrow to the left { if(arrowPos==1 && screenNum==0) { arrowPos=0; } else if(arrowPos==2 && screenNum==1) { arrowPos=1; } else { arrowPos=arrowPos; } } else if(event.key.keysym.sym==SDLK_DOWN) // moves arrow down { if((arrowPos==0 || arrowPos==1) && screenNum==0) { arrowPos=2; } else if(arrowPos<3 && screenNum==1) { if(arrowPos==0) { arrowPos++; } else { arrowPos=3; } } else { arrowPos=arrowPos; } } else if(event.key.keysym.sym==SDLK_e) // selects user's option { if((arrowPos==0 || arrowPos==1) && screenNum==0) { if(arrowPos==0) result = 1; else result = 2; screenNum=2; quit=true; } else if(arrowPos==2 && screenNum==0) { arrowPos=0; screenNum=1; } else if(arrowPos==3 && screenNum==1) { screenNum=0; arrowPos=0; } } } if(screenNum==0) { show_Main(); } else if(screenNum==1) { show_Options(); } else { show_Loading(); } } //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } SDL_Delay(500); //Free surfaces, fonts and sounds clean_up(); return result; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //Keep track of the frame count int frame = 0; //Timer used to calculate the frames per second Timer fps; //Timer used to update the caption Timer update; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Start the update timer update.start(); //Start the frame timer fps.start(); //While the user hasn't quit while( quit == false ) { //While there's events to handle while( SDL_PollEvent( &event ) ) { //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Apply the background apply_surface( 0, 0, image, screen ); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Increment the frame counter frame++; //If a second has passed since the caption was last updated if( update.get_ticks() > 1000 ) { //The frame rate as a string std::stringstream caption; //Calculate the frames per second and create the string caption << "Average Frames Per Second: " << frame / ( fps.get_ticks() / 1000.f ); //Reset the caption SDL_WM_SetCaption( caption.str().c_str(), NULL ); //Restart the update timer update.start(); } } //Clean up clean_up(); return 0; }
gboolean remove_from_tree(GNode *file, gboolean unmount) { int position = g_list_position(lines, FILE(file)->line); gboolean refresh_needed = FALSE; GList *line_ptr, *line_ptr2; GNode *dir_ptr; if (G_NODE_IS_ROOT(file)) { endwin(); clean_up(); printf("The tree root was removed\n"); exit(EXIT_SUCCESS); } if (g_node_is_ancestor(file, NODE(selected_line))) select_file(file); if (FILE(file)->type == directory_type) { close_directory(file); destroy_directory_content_real(file, FALSE); if (unmount) return TRUE; } else if (FILE(file)->type == file_type) { for (dir_ptr = file->parent; !G_NODE_IS_ROOT(dir_ptr); dir_ptr = dir_ptr->parent) { if (FILE(dir_ptr)->open == FALSE) { g_node_unlink(file); return FALSE; } } if (FILE(dir_ptr)->open == FALSE) { g_node_unlink(file); return FALSE; } } g_node_unlink(file); if (g_list_position(lines, first_line) <= position && position <= g_list_position(lines, last_line)) { if (first_line == FILE(file)->line && selected_line == FILE(file)->line) { selected_line = first_line = g_list_previous(first_line); lines = g_list_delete_link(lines, FILE(file)->line); print_lines(first_line, first_line, FALSE); } else if (position < g_list_position(lines, selected_line)) { if (first_line == FILE(file)->line) first_line = g_list_next(first_line); line_ptr = g_list_previous(FILE(file)->line); lines = g_list_delete_link(lines, FILE(file)->line); if ((line_ptr2 = g_list_previous(first_line)) != NULL) { first_line = line_ptr2; print_lines(first_line, line_ptr, FALSE); } else if ((line_ptr2 = g_list_next(last_line)) != NULL) { last_line = line_ptr2; print_lines(line_ptr, last_line, FALSE); } else print_lines(line_ptr, last_line, TRUE); } else { if (FILE(file)->line == selected_line) selected_line = g_list_previous(selected_line); if (last_line == FILE(file)->line) last_line = g_list_previous(last_line); line_ptr = g_list_previous(FILE(file)->line); lines = g_list_delete_link(lines, FILE(file)->line); if ((line_ptr2 = g_list_next(last_line)) != NULL) { last_line = line_ptr2; print_lines(line_ptr, last_line, FALSE); } else print_lines(line_ptr, last_line, TRUE); } refresh_needed = TRUE; } else { if (last_line == g_list_previous(FILE(file)->line)) { lines = g_list_delete_link(lines, FILE(file)->line); print_lines(last_line, last_line, FALSE); refresh_needed = TRUE; } else lines = g_list_delete_link(lines, FILE(file)->line); } free_node_data(file, NULL); g_node_destroy(file); return refresh_needed; }
LOCAL void rt_add_to_state( float *coords, Locstate state, /* assumed to be TGAS_STATE */ COMP_TYPE *ct, INIT_DATA *init) { #if defined(float) static const float ACC = 1.0e-14; /*TOLERANCE*/ #else /* defined(float) */ static const float ACC = 1.0e-7; /*TOLERANCE*/ #endif /* defined(float) */ int i, j, k0, k1, dim, layer_label, num_modes, nstep; float rho, csq, rho_prime, a_z, b_z, k_dot_r, sig, phase; float tmp, ub, lb, z0, z1, a0, a1, b0, b1, z, h_z, g_z; const float *grav; _RT_PERTURBED *rtp = Rt_perturbed(ct); NORMAL_MODE *n_m; dim = ct->params->dim; layer_label = rtp->layer_label; nstep = rtp->lin_pert_intvl; num_modes = rtp->num_modes; if (num_modes <= 0) return; z0 = lb = get_surf_height(coords, rtp->lower_surf); z1 = ub = get_surf_height(coords, rtp->upper_surf); h_z = (ub-lb)/nstep; z = coords[dim-1]; grav = gravity(coords,initial_time(init)); g_z = grav[dim-1]; /* find out which interval z belongs */ if (ub < lb) { screen("\nERROR in rt_add_to_state(), "); screen("Interfaces are already tangled.\n"); (void) printf("ub = %g, lb = %g\n",ub,lb); print_interface(current_interface()); clean_up(ERROR); } if (z >= ub) k0 = k1 = nstep; else if (z <= lb) k0 = k1 = 0; else { k0 = 0, k1 = nstep; for (;;) { tmp = (z0+z1)/2.0; if (z >= tmp) k0 = (k0+k1)/2, z0 = tmp; else k1 = (k0+k1)/2, z1 = tmp; if (k1-k0 == 1) break; } } z0 = lb+k0*h_z; z1 = lb+k1*h_z; rho = Dens(state); csq = sound_speed_squared(state); rho_prime = get_rho_prime(state,ct,g_z); /* sum over all the normal modes */ for (i = 0; i < num_modes; ++i) { n_m = rtp->normal_mode[i]; if (k0 == k1) { a_z = n_m->a[layer_label][k1]; b_z = n_m->b[layer_label][k1]; } else { a0 = n_m->a[layer_label][k0]; a1 = n_m->a[layer_label][k1]; a_z = ((a1-a0)*z+(a0*z1-a1*z0))/h_z; b0 = n_m->b[layer_label][k0]; b1 = n_m->b[layer_label][k1]; b_z = ((b1-b0)*z+(b0*z1-b1*z0))/h_z; } if ((fabs(a_z) < ACC) && (fabs(b_z) < ACC)) continue; sig = n_m->sigma_r; phase = n_m->phase; k_dot_r = 0.0; for (j = 0; j <= dim-2; ++j) k_dot_r += n_m->wv_num[j]*coords[j]; phase += k_dot_r; Dens(state) += ((g_z*rho/csq-rho_prime)*a_z+b_z/csq)/sig*sin(phase); Press(state) += b_z/sig*sin(phase); Vel(state)[dim-1] += a_z*sin(phase); set_type_of_state(state,TGAS_STATE); phase += 3.0*PI/2; for (j = 0; j <= dim-2; ++j) Vel(state)[j] += sin(phase)*n_m->wv_num[j]*b_z/(rho*sig*sig); reset_gamma(state); } } /*end rt_add_to_state*/
int main( int argc, char* args[] ) { bool quit = false; if( init() == false ) return 1; if( load_files() == false ) return 1; //clip the sprite sheet //set_clips(); //make button //Button myButton( 170, 120, 320, 240 ); /*up = TTF_RenderText_Solid(font, "Up", textColor); down = TTF_RenderText_Solid( font, "Down", textColor); left = TTF_RenderText_Solid( font, "Left", textColor ); right = TTF_RenderText_Solid( font, "Right", textColor ); if( up == NULL ) return 1; if( down == NULL ) return 1; if( left == NULL ) return 1; if( right == NULL ) return 1;*/ apply_surface( 0, 0, background, screen ); message = TTF_RenderText_Solid( font, "Press 1, 2, 3, or 4 to play a sound effect", textColor ); if( message == NULL ) return 1; apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 100, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 9 to play or pause the music", textColor ); if( message == NULL ) return 1; apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 200, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 0 to stop the music", textColor ); if( message == NULL ) return 1; apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 300, message, screen ); SDL_FreeSurface( message ); if( SDL_Flip( screen ) == -1 ) return 1; while( quit == false) { while( SDL_PollEvent(&event) ) { if( event.type == SDL_KEYDOWN ) { if( event.key.keysym.sym == SDLK_1 ) { //play scratch if( Mix_PlayChannel( -1, scratch, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_2 ) { //play high if( Mix_PlayChannel( -1, high, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_3 ) { //play med if( Mix_PlayChannel( -1, med, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_4 ) { //play low if( Mix_PlayChannel( -1, low, 0 ) == -1 ) return 1; } else if( event.key.keysym.sym == SDLK_9 ) { //if no music if( Mix_PlayingMusic() == 0 ) { //play music if( Mix_PlayMusic( music, -1 ) == -1 ) return 1; } else { if( Mix_PausedMusic() == 1 ) Mix_ResumeMusic(); else Mix_PauseMusic(); } } else if( event.key.keysym.sym == SDLK_0 ) Mix_HaltMusic(); } if( event.type == SDL_QUIT ) quit = true; } /* Uint8 *keystates = SDL_GetKeyState( NULL ); //if up if( keystates[ SDLK_UP ] ) { apply_surface( ( SCREEN_WIDTH - up->w ) / 2, ( SCREEN_HEIGHT / 2 - up->h ) / 2, up, screen ); } //if down if( keystates[ SDLK_DOWN ] ) apply_surface( ( SCREEN_WIDTH - down->w ) / 2, ( SCREEN_HEIGHT / 2 - down->h ) / 2 + ( SCREEN_HEIGHT / 2 ), down, screen ); //if left if( keystates[ SDLK_LEFT ] ) apply_surface( ( SCREEN_WIDTH / 2 - left->w ) / 2, ( SCREEN_HEIGHT - left->h ) / 2, left, screen ); //if right if( keystates[ SDLK_RIGHT ] ) apply_surface( ( SCREEN_WIDTH / 2 - right->w ) / 2 + (SCREEN_WIDTH / 2 ), ( SCREEN_HEIGHT - right->h ) / 2, right, screen ); if( SDL_Flip( screen ) == -1 ) return 1; */ } clean_up(); return 0; }
static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb) { struct mpoa_client *mpc = find_mpc_by_vcc(vcc); struct k_message *mesg = (struct k_message*)skb->data; atomic_sub(skb->truesize, &vcc->sk->sk_wmem_alloc); if (mpc == NULL) { printk("mpoa: msg_from_mpoad: no mpc found\n"); return 0; } dprintk("mpoa: (%s) msg_from_mpoad:", (mpc->dev) ? mpc->dev->name : "<unknown>"); switch(mesg->type) { case MPOA_RES_REPLY_RCVD: dprintk(" mpoa_res_reply_rcvd\n"); MPOA_res_reply_rcvd(mesg, mpc); break; case MPOA_TRIGGER_RCVD: dprintk(" mpoa_trigger_rcvd\n"); MPOA_trigger_rcvd(mesg, mpc); break; case INGRESS_PURGE_RCVD: dprintk(" nhrp_purge_rcvd\n"); ingress_purge_rcvd(mesg, mpc); break; case EGRESS_PURGE_RCVD: dprintk(" egress_purge_reply_rcvd\n"); egress_purge_rcvd(mesg, mpc); break; case MPS_DEATH: dprintk(" mps_death\n"); mps_death(mesg, mpc); break; case CACHE_IMPOS_RCVD: dprintk(" cache_impos_rcvd\n"); MPOA_cache_impos_rcvd(mesg, mpc); break; case SET_MPC_CTRL_ADDR: dprintk(" set_mpc_ctrl_addr\n"); set_mpc_ctrl_addr_rcvd(mesg, mpc); break; case SET_MPS_MAC_ADDR: dprintk(" set_mps_mac_addr\n"); set_mps_mac_addr_rcvd(mesg, mpc); break; case CLEAN_UP_AND_EXIT: dprintk(" clean_up_and_exit\n"); clean_up(mesg, mpc, DIE); break; case RELOAD: dprintk(" reload\n"); clean_up(mesg, mpc, RELOAD); break; case SET_MPC_PARAMS: dprintk(" set_mpc_params\n"); mpc->parameters = mesg->content.params; break; default: dprintk(" unknown message %d\n", mesg->type); break; } kfree_skb(skb); return 0; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Generate the message surfaces // upMessage = TTF_RenderText_Solid( font, "Up was pressed.", textColor ); // downMessage = TTF_RenderText_Solid( font, "Down was pressed.", textColor ); // leftMessage = TTF_RenderText_Solid( font, "Left was pressed", textColor ); // rightMessage = TTF_RenderText_Solid( font, "Right was pressed", textColor ); SDL_Surface* pasillo = load_image("tablero/path.png"); SDL_Surface* muro = load_image("tablero/brick.png"); SDL_Surface* obstaculo = load_image("tablero/green.png"); SDL_Surface* ventaja = load_image("tablero/adv.png"); char tablero[9][9]={{' ','#',' ','O','V',' ','#',' ','O'}, {' ','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#','#',' ',' ',' ','O'}, {' ','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#',' ',' ','#',' ','O'}, {'V','#',' ','#','#',' ','#',' ','O'}, {' ','#',' ','#',' ',' ','#',' ','O'}, {' ','O','O',' ',' ',' ','#',' ','O',}}; char tablero_de_pasos[9][9]={{' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}, {' ',' ',' ',' ',' ',' ',' ',' ',' '}}; SDL_Surface* pasos_surface = load_image("pasos.png"); SDL_Surface* atq_surface = load_image("ataque.png"); SDL_Surface* win_surface = load_image("win.png"); SDL_Surface* go_surface = load_image("go.png"); SDL_Surface* personaje_surface = load_image("player1/image1.png"); SDL_Surface* enemigo_surface = load_image("enem.png"); Personaje* personaje= new Personaje(2,3,personaje_surface); Personaje* enemigo=new Personaje(5,5,enemigo_surface); Personaje* actual=personaje; // enemigo.turn=false; SDL_Surface* cursor_surface = load_image("cursor.png"); int cursor_x=0; int cursor_y=0; //While the user hasn't quit while( quit == false ) { //If there's an event to handle if( SDL_PollEvent( &event ) ) { //If a key was pressed if( event.type == SDL_KEYDOWN ) { //Set the proper message surface switch( event.key.keysym.sym ) { case SDLK_UP: cursor_y--; // // limpiar(tablero_de_pasos); // if(cursor_x==personaje->x && cursor_y==personaje->y) // { // // marcar_atq(tablero,tablero_de_pasos,personaje->x,personaje->y,3); // // marcar(tablero,tablero_de_pasos,personaje->x,personaje->y,2); // } break; case SDLK_DOWN: cursor_y++; break; case SDLK_LEFT: cursor_x--; break; case SDLK_RIGHT: cursor_x++; break; case SDLK_F1: // personaje->atacar(enemigo); // enemigo->attacar(personaje); if(actual->x==personaje->x && actual->y==personaje->y){ enemigo->atacar(personaje); } if(actual->x==enemigo->x && actual->y==enemigo->y) personaje->atacar(enemigo); break; case SDLK_RETURN: if(turno){ if(puedoLLegar(tablero,personaje->x,personaje->y,2,cursor_x,cursor_y)) { actual = personaje; personaje->x=cursor_x; personaje->y=cursor_y; limpiar(tablero_de_pasos); marcar_atq(tablero,tablero_de_pasos,personaje->x,personaje->y,3); marcar(tablero,tablero_de_pasos,personaje->x,personaje->y,2); } turno=false; } else if(turno==false){ if(puedoLLegar(tablero,enemigo->x,enemigo->y,2,cursor_x,cursor_y)) { actual=enemigo; enemigo->x=cursor_x; enemigo->y=cursor_y; limpiar(tablero_de_pasos); marcar_atq(tablero,tablero_de_pasos,enemigo->x,enemigo->y,3); marcar(tablero,tablero_de_pasos,enemigo->x,enemigo->y,2); } turno =true; } break; } } //If the user has Xed out the window else if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Apply the background apply_surface( 0, 0, background, screen ); //If a message needs to be displayed if( message != NULL ) { //Apply the background to the screen apply_surface( 0, 0, background, screen ); //Apply the message centered on the screen apply_surface( ( SCREEN_WIDTH - message->w ) / 2, ( SCREEN_HEIGHT - message->h ) / 2, message, screen ); //Null the surface pointer message = NULL; } for(int x=0;x<9;x++) for(int y=0;y<9;y++) { if(tablero[y][x]==' ') apply_surface(x*75,y*75,pasillo,screen); if(tablero[y][x]=='#') apply_surface(x*75,y*75,muro,screen); if(tablero[y][x]=='O') apply_surface(x*75,y*75,obstaculo,screen); if(tablero[y][x]=='V') apply_surface(x*75,y*75,ventaja,screen); } for(int x=0;x<9;x++) for(int y=0;y<9;y++){ if(tablero_de_pasos[y][x]=='P') apply_surface(x*75,y*75,pasos_surface,screen); if(tablero_de_pasos[y][x]=='A') apply_surface(x*75,y*75,atq_surface,screen); } personaje->hp=TTF_RenderText_Solid( personaje->font, personaje->toString(personaje->vida).c_str(), personaje->textColor ); enemigo->hp=TTF_RenderText_Solid( enemigo->font, enemigo->toString(enemigo->vida).c_str(), enemigo->textColor ); personaje->dibujar(screen); // personaje->hp_dibujar(screen); enemigo->dibujar(screen); //enemigo->hp_dibujar(screen); apply_surface(cursor_x*75,cursor_y*75,cursor_surface,screen); if(personaje->vida==0) apply_surface(0,0,go_surface,screen); if(enemigo->vida==0) apply_surface(0,0,win_surface,screen); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } } //Clean up clean_up(); return 0; }
/*Foo::Foo() { offSet = 0; velocity = 0; frame = 0; status = FOO_RIGHT; } void Foo::move() { offSet += velocity; if( ( offSet < 0 ) || ( offSet + FOO_WIDTH > SCREEN_WIDTH ) ) offSet -= velocity; } void Foo::show() { if( velocity < 0 ) { status = FOO_LEFT; frame++; } else if( velocity > 0 ) { status = FOO_RIGHT; frame++; } else frame = 0; if( frame >= 4 ) frame = 0; if( status == FOO_RIGHT ) apply_surface( offSet, SCREEN_HEIGHT - FOO_HEIGHT, foo, screen, &clipsRight[frame] ); else if( status == FOO_LEFT ) apply_surface( offSet, SCREEN_HEIGHT - FOO_HEIGHT, foo, screen, &clipsLeft[frame] ); } void Foo::handle_events() { //If a key was pressed if( event.type == SDL_KEYDOWN ) { //Set the velocity switch( event.key.keysym.sym ) { case SDLK_RIGHT: velocity += FOO_WIDTH / 4; break; case SDLK_LEFT: velocity -= FOO_WIDTH / 4; break; } } //If a key was released else if( event.type == SDL_KEYUP ) { //Set the velocity switch( event.key.keysym.sym ) { case SDLK_RIGHT: velocity -= FOO_WIDTH / 4; break; case SDLK_LEFT: velocity += FOO_WIDTH / 4; break; } } } void set_clips() { //clip the sprite sheet clipsRight[0].x = 0; clipsRight[0].y = 0; clipsRight[0].w = FOO_WIDTH; clipsRight[0].h = FOO_HEIGHT; clipsRight[1].x = FOO_WIDTH; clipsRight[1].y = 0; clipsRight[1].w = FOO_WIDTH; clipsRight[1].h = FOO_HEIGHT; clipsRight[2].x = FOO_WIDTH * 2; clipsRight[2].y = 0; clipsRight[2].w = FOO_WIDTH; clipsRight[2].h = FOO_HEIGHT; clipsRight[3].x = FOO_WIDTH * 3; clipsRight[3].y = 0; clipsRight[3].w = FOO_WIDTH; clipsRight[3].h = FOO_HEIGHT; clipsLeft[0].x = 0; clipsLeft[0].y = FOO_HEIGHT; clipsLeft[0].w = FOO_WIDTH; clipsLeft[0].h = FOO_HEIGHT; clipsLeft[1].x = FOO_WIDTH; clipsLeft[1].y = FOO_HEIGHT; clipsLeft[1].w = FOO_WIDTH; clipsLeft[1].h = FOO_HEIGHT; clipsLeft[2].x = FOO_WIDTH * 2; clipsLeft[2].y = FOO_HEIGHT; clipsLeft[2].w = FOO_WIDTH; clipsLeft[2].h = FOO_HEIGHT; clipsLeft[3].x = FOO_WIDTH * 3; clipsLeft[3].y = FOO_HEIGHT; clipsLeft[3].w = FOO_WIDTH; clipsLeft[3].h = FOO_HEIGHT; }*/ int main( int argc, char* args[] ) { bool quit = false; int frame = 0; bool cap = true; Timer fps; Timer update; if( init() == false ) return 1; if( load_files() == false ) return 1; //set_clips(); Dot myDot; update.start(); while( quit == false) { fps.start(); while( SDL_PollEvent(&event) ) { myDot.handle_input(); if( event.type == SDL_QUIT ) quit = true; } myDot.move(); myDot.set_camera(); //std::stringstream fpsm; //fpsm << "FPS: " << frame / ( fps.get_ticks() / 1000.f ); apply_surface( 0, 0, background, screen, &camera ); //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); myDot.show(); if( update.get_ticks() > 1000.f ) { std::stringstream fpsm; fpsm << "FPS: " << ( frame ); fpsmessage = TTF_RenderText_Solid(font, fpsm.str().c_str(), textColor ); frame = 0; update.start(); } apply_surface( 10, 10, fpsmessage, screen); if( SDL_Flip( screen ) == -1 ) return 1; frame++; if( ( ( fps.get_ticks() ) < 1000 / FRAMES_PER_SECOND ) ) SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - ( fps.get_ticks() ) ); } clean_up(); return 0; }
virtual ~Task() { clean_up(); }
/** * @function main */ int main( int argc, char *argv[] ) { bool quit = false; countPath = 0; //-- Initialize if( init() == false ) { return 1; } //-- Load the files if( load_files() == false ) { return 1; } //-- Clip tiles clip_tiles(); //-- Create grid Grid2D g( SIZE_X, SIZE_Y ); //-- Create HomoPath object HP2D h( &g ); //-- Put the obstacles in the borders createBorderingObstacles( &g ); //-- Display options display_options(); //-- Start SDL while( quit == false ) { while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT ) { quit = true; } else if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case 's': { printf("-- Starting planner \n"); MOUSE_MODE = -1; CallPlanner( &g, &h ); printf("--* To see options again press [q] \n"); break; } case 'v': { printf("-- Click one location to be the initial vertex \n"); MOUSE_MODE = 0; break; } case 'o': { printf("-- Click one location to be obstacle \n"); MOUSE_MODE = 1; break; } case 'x': { printf("-- Pick a grid to check the possible paths \n"); MOUSE_MODE = 2; countPath = 0; // Start seeing the first path break; } case 'p': { printf("-- Check available paths for designated grid \n"); countPath++; countPath = ( countPath % numPaths ); } case 'q': { display_options(); } } } else if( event.type == SDL_MOUSEBUTTONDOWN ) { if( event.button.button == SDL_BUTTON_LEFT ) { int x = event.button.x; int y = event.button.y; Pos p = GetMousePos( x, y ); switch( MOUSE_MODE ) { case 0: { printf("--> V0 located at (%d, %d) \n", p.x, p.y ); p0.x = p.x; p0.y = p.y; printf("--* To see options again press [q] \n"); break; } case 1: { printf("--> Obstacle located at (%d, %d) \n", p.x, p.y ); if( g.GetState(p) == false ) { g.SetState( p, true ); } else { g.SetState( p, false ); } printf("--* To see options again press [q] \n"); break; } case 2: { printf( "--> Locating paths for (%d %d) \n", p.x, p.y ); gPaths = h.PrintPath(p); numPaths = gPaths.size(); printf("--* To see options again press [q] \n"); break; } } } } //-- Draw DrawScene( &g ); } // end while SDL_PollEvent } // end while quit clean_up(); return 0; }
int main(int argc, char *argv[]) { int sockServer,sock_client,yes = 1; uint64_t command = 600000; pthread_t thread; uint32_t IDN=0xb00b; uint32_t status; void *(*handler[3])(void *) = { ctrl_handler, rx_handler, tx_handler }; struct sockaddr_in addr; if (argc >=2 ) { if (argv[1][0]=='v' ) verbose = 1; if (argv[1][0]=='V' ) verbose = 2; } if(init_mem_map()) { perror("memory mapping"); return EXIT_FAILURE; } //put logic into reset *((uint32_t *)(cfg + 0)) &= ~0xf; if(init_temperature_scale()) { perror("temperature scale"); return EXIT_FAILURE; } if((sockServer = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); return EXIT_FAILURE; } setsockopt(sockServer, SOL_SOCKET, SO_REUSEADDR, (void *)&yes , sizeof(yes)); /* setup listening address */ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_port = htons(TCP_PORT); if(bind(sockServer, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); return EXIT_FAILURE; } listen(sockServer, 1024); signal(SIGINT, signal_handler); while(!interrupted) { int result, selector; if(verbose)printf("waiting for client\n"); if((sock_client = accept(sockServer, NULL, NULL)) < 0) { perror("accept"); return 1; } if(verbose)printf("new connection, waiting for command\n"); result = recv(sock_client, (char *)&command, sizeof(command), MSG_WAITALL); if(result >= sizeof(command) ) { switch(command >> 60) { case CMD_IDN: if(verbose)printf("MAIN: IDN query, socket=%d\n",sock_client); status=*((uint32_t *)(sts + 8)); if(verbose)printf("Status = %u\n", status); status = ( status & 0xffff0000 ) | (IDN & 0x0000ffff ); if(send(sock_client, &status, sizeof(status), 0) < 0){ perror("send");break;} close(sock_client); break; case CMD_CONNECT: if((selector = command & 0x3)<3) { if(sock_thread[selector] > -1) { int ret; if(verbose)printf("MAIN: closing thread connection sock=%d\n",sock_thread[selector]); ret=shutdown(sock_thread[selector],SHUT_RDWR); while(sock_thread[selector] > -1) usleep(1000); if(verbose)printf("MAIN: shutdown ret = %d, command = %llx, now sock=%d\n",ret,command,sock_thread[selector]); } sock_thread[selector] = sock_client; if(pthread_create(&thread, NULL, handler[selector], NULL) < 0) { perror("pthread_create"); return EXIT_FAILURE; } pthread_detach(thread); } break; case CMD_STOP: close(sock_client); clean_up(); if(verbose)printf("Exit program\n"); return 0; break; default: if(verbose)printf("Unexpected command, closing connection, socket = %d\n",sock_client); close(sock_client); break; } } else { if(verbose)printf("Unexpected communication, closing connection, socket = %d\n",sock_client); close(sock_client); } }
int init_kernel(const char* ipaddr_,const unsigned short port_,const int udp_packet_filter_thread_num_) { #ifdef WIN32 if(InitWinsock2()==-1) { print_error("WSAStartup failed to Init Winsock2."); return -1; } #endif /* Initialize socket address structure for Interner Protocols */ _numberOfWorkerThreads = udp_packet_filter_thread_num_; _udp_port = port_; memset(&_internetAddr, 0,sizeof(_internetAddr)); // empty data structure _internetAddr.sin_family = AF_INET; if(ipaddr_==NULL) _internetAddr.sin_addr.s_addr = htonl(INADDR_ANY); else _internetAddr.sin_addr.s_addr=inet_addr(ipaddr_); _internetAddr.sin_port = htons(port_); _hSocket = socket(AF_INET, SOCK_DGRAM, 0); if( bind(_hSocket, ( struct sockaddr * )&_internetAddr, sizeof(_internetAddr ) ) == -1 ) { print_error("WSAStartup failed to bind sock."); close_socket(_hSocket); clean_up(); return -1; } set_socket_recv_buf(_hSocket,16*1024);//HDS_UDP_SOCKET_RECV_BUF_SIZE); set_socket_send_buf(_hSocket,HDS_UDP_SOCKET_SEND_BUF_SIZE); if(set_socket_reuse(_hSocket) == -1) { print_error("WSAStartup failed to reuse sock."); close_socket(_hSocket); clean_up(); return -1; } if(HDS_Thread_Create(UDPServerRecvThread,NULL,&_recvThreadData)==-1) { print_error("A recv thread was not able to be created"); close_socket(_hSocket); clean_up(); return -1; } _workerThreadDataArray = (HDS_Thread_Data*)malloc(_numberOfWorkerThreads*sizeof(HDS_Thread_Data)); memset(_workerThreadDataArray, 0, sizeof(HDS_Thread_Data) * _numberOfWorkerThreads); for(int i= 0; i < _numberOfWorkerThreads; ++i) { // We only create in the suspended state so our workerThreadHandles object // is updated before the thread runs. if(HDS_Thread_Create(UDPServerWorkerThread,NULL,&_workerThreadDataArray[i])==-1) { print_error("A worker thread was not able to be created"); close_socket(_hSocket); free(_workerThreadDataArray); clean_up(); return -1; } } return 0; }
int main( int argc, char* args[] ) { int quit = false; if( init() == false ) { return false; } if( load_files() == false ) { return false; } apply_surface( 0, 0, background, screen ); message = TTF_RenderText_Solid( font, "Start game", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 100, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Options", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 200, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Exit", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 300, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 9 to play/pause the music", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 400, message, screen ); SDL_FreeSurface( message ); message = TTF_RenderText_Solid( font, "Press 0 to stop the music", textColor ); if( message == NULL ) { return false; } apply_surface( ( SCREEN_WIDTH - message->w ) / 2, 500, message, screen ); SDL_FreeSurface( message ); if( SDL_Flip( screen ) == -1 ) { return false; } while( quit == false ) { while( SDL_PollEvent( &event ) ) { if( event.type == SDL_KEYDOWN ) { if( event.key.keysym.sym == SDLK_6) { Mix_RewindMusic(); if(Mix_SetMusicPosition(60.0)==-1) { return false; } } else if( event.key.keysym.sym == SDLK_9 ) { if( Mix_PlayingMusic() == 0 ) { if( Mix_PlayMusic( music, -1 ) == -1 ) { return false; } } else { if( Mix_PausedMusic() == 1 ) { Mix_ResumeMusic(); } else { Mix_PauseMusic(); } } } else if( event.key.keysym.sym == SDLK_0 ) { Mix_HaltMusic(); } } if( event.type == SDL_QUIT ) { quit = true; } } } clean_up(); return 0; }