Example #1
0
void Game::cleanup()
{
	//delete the timers
	delete mpLoopTimer;
	mpLoopTimer = NULL;
	delete mpMasterTimer;
	mpMasterTimer = NULL;

	//delete the graphics system
	delete mpGraphicsSystem;
	mpGraphicsSystem = NULL;

	delete mpGraphicsBufferManager;
	mpGraphicsBufferManager = NULL;
	delete mpSpriteManager;
	mpSpriteManager = NULL;

	al_destroy_font(mpFont);
	mpFont = NULL;

	//shutdown components
	al_uninstall_audio();
	al_shutdown_image_addon();
	al_shutdown_font_addon();
	al_shutdown_ttf_addon();
	al_uninstall_keyboard();
	al_uninstall_mouse();
	al_shutdown_primitives_addon();
}
Example #2
0
int main(void)
{
   int i;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_install_keyboard();

   open_log();
   
   display = al_create_display(640, 100);
   if (!display) {
      abort_example("Could not create display.\n");
   }

   if (!al_install_audio()) {
      abort_example("Could not init sound.\n");
   }
   al_reserve_samples(N);

   al_set_mixer_postprocess_callback(al_get_default_mixer(), update_waveform, NULL);

   mainloop();

   close_log(false);

   for (i = 0; i < N; i++) {
      al_destroy_audio_stream(stream[i]);
   }
   al_uninstall_audio();

   return 0;
}
Example #3
0
SoundManager::~SoundManager(void)
{
	DestroyAllSounds();
	DestroyMusic();
	DestroyMixer();
	DestroyVoice();
	al_uninstall_audio();
}
Example #4
0
void shutdown() {
    al_shutdown_image_addon();
    al_shutdown_ttf_addon();
    al_shutdown_font_addon();
    al_shutdown_primitives_addon();
    al_uninstall_keyboard();
    al_uninstall_mouse();
    al_uninstall_audio();
    al_uninstall_system();
}
Example #5
0
void shutdownSound(void)
{

    /* shutdown sound system when done */
    al_stop_samples();
    if (music != NULL)
    {
        al_destroy_audio_stream(music);
    }
    al_destroy_mixer(mixer);
    al_destroy_voice(voice);
    al_uninstall_audio();

}
Example #6
0
Audio::~Audio()
{
#ifdef WRITE_LOG
  fprintf( FRAMEWORK->LogFile, "Framework: Shutdown Audio\n" );
#endif
	if( audioVoice != 0 )
	{
		al_destroy_voice( audioVoice );
		audioVoice = 0;
	}
	if( audioMixer != 0 )
	{
		al_destroy_mixer( audioMixer );
		audioMixer = 0;
	}
	al_uninstall_audio();
}
Example #7
0
void uninstall() {
    // clear bgm
    bgm_stop();

    // clear samples
    for (SampleIter it = samples.begin(); it != samples.end(); it++)
        al_destroy_sample(it->second);
    samples.clear();

    // clear channels
    if (bgm_channel != NULL) {
        al_destroy_sample_instance(bgm_channel);
        bgm_channel = NULL;
    }
    for (unsigned int i=0; i<effects.size(); i++)
        al_destroy_sample_instance(effects[i]);
    effects.clear();

    // uninstall
    al_uninstall_audio();
}
Example #8
0
void main_close_allegro_library() {
  regular_message("shutdown primitive addon");
  al_shutdown_primitives_addon();

  regular_message("shutdown native dialog addon");
  al_shutdown_native_dialog_addon();

  regular_message("shutdown image addon");
  al_shutdown_image_addon();

  regular_message("uninstall audio");
  al_uninstall_audio();

  regular_message("uninstall keyboard");
  al_uninstall_keyboard();

  regular_message("uinstall mouse");
  al_uninstall_mouse();

  regular_message("uninstll allegro system");
  al_uninstall_system();
}
Example #9
0
Framework::~Framework()
{

  Settings->Save( "settings.cfg" );

#ifdef WRITE_LOG
  printf( "Framework: Shutdown\n" );
#endif

  al_destroy_event_queue( eventQueue );
  al_destroy_display( displaySurface );
  al_destroy_mutex( extraEventsMutex );

  delete imageMgr;
  delete audioMgr;
  delete fontMgr;
  delete networkMgr;
  delete downloadMgr;

  // Shutdown Allegro
  if( mixer != 0 )
  {
    al_destroy_mixer( mixer );
  }
  if( voice != 0 )
  {
    al_destroy_voice( voice );
  }

	al_uninstall_keyboard();
	al_uninstall_mouse();
	al_shutdown_primitives_addon();
	al_shutdown_ttf_addon();
	al_shutdown_image_addon();
	al_shutdown_font_addon();
	al_uninstall_audio();
  al_uninstall_joystick();
}
bool
deinitialize ()
{
  int i;

  al_destroy_font (global.programing_font);
  al_destroy_event_queue (global.queue);
  al_destroy_display (global.display);
  al_destroy_bitmap (global.arrow_bitmap);


  for (i = 0; i < NUM_OF_SPRITE_TYPES; i++)
    {
      al_destroy_bitmap (global.sprite_bitmap[i]);
    }

  for (i = 0; i < NUM_OF_BACKGROUNDS; i++)
    {
      al_destroy_bitmap (global.backgrounds[i]);
    }

  for (i = 0; i < NUM_OF_SOUNDS; i++)
    {
      al_destroy_sample (global.sounds[i]);
    }

  /*if (global.music)
     {
     al_drain_audio_stream (global.music);
     al_destroy_audio_stream (global.music);
     } */
  al_shutdown_image_addon ();
  al_uninstall_audio ();
  al_uninstall_keyboard ();
  return true;
}
Example #11
0
/* the main program body */
int main(int argc, char *argv[])
{
   ALLEGRO_PATH *font_path;
   int w = 0, h = 0;
   int www = FALSE;
   int i, n;
   int display_flags = ALLEGRO_GENERATE_EXPOSE_EVENTS;

   srand(time(NULL));
   
   al_set_org_name("liballeg.org");
   al_set_app_name("SPEED");

   if (!al_init()) {
      fprintf(stderr, "Could not initialise Allegro.\n");
      return 1;
   }
   al_init_primitives_addon();

   /* parse the commandline */
   for (i=1; i<argc; i++) {
      if (strcmp(argv[i], "-cheat") == 0) {
         cheat = TRUE;
      }
      else if (strcmp(argv[i], "-simple") == 0) {
         low_detail = TRUE;
      }
      else if (strcmp(argv[i], "-nogrid") == 0) {
         no_grid = TRUE;
      }
      else if (strcmp(argv[i], "-nomusic") == 0) {
         no_music = TRUE;
      }
      else if (strcmp(argv[i], "-www") == 0) {
         www = TRUE;
      }
      else if (strcmp(argv[i], "-fullscreen") == 0) {
         /* if no width is specified, assume fullscreen_window */
         display_flags |= w ? ALLEGRO_FULLSCREEN : ALLEGRO_FULLSCREEN_WINDOW;
      }
      else {
         n = atoi(argv[i]);

         if (!n) {
            usage();
            return 1;
         }

         if (!w) {
            w = n;
            if (display_flags & ALLEGRO_FULLSCREEN_WINDOW) {
               /* toggle from fullscreen_window to fullscreen */
               display_flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
               display_flags |= ALLEGRO_FULLSCREEN;
            }
         }
         else if (!h) {
            h = n;
         }
         else {
            usage();
            return 1;
         }
      }
   }

   /* it's a real shame that I had to take this out! */
   if (www) {
      printf(
	 "\n"
	 "Unfortunately the built-in web browser feature had to be removed.\n"
	 "\n"
	 "I did get it more or less working as of Saturday evening (forms and\n"
	 "Java were unsupported, but tables and images were mostly rendering ok),\n"
	 "but the US Department of Justice felt that this was an unacceptable\n"
	 "monopolistic attempt to tie in web browsing functionality to an\n"
	 "unrelated product, so they threatened me with being sniped at from\n"
	 "the top of tall buildings by guys with high powered rifles unless I\n"
	 "agreed to disable this code.\n"
	 "\n"
	 "We apologise for any inconvenience that this may cause you.\n"
      );

      return 1;
   }
   
   if (!w || !h) {
      if (argc == 1 || (display_flags & ALLEGRO_FULLSCREEN_WINDOW)) {
         w = 640;
         h = 480;
      }
      else {
         usage();
         return 1;
      }
   }

   /* set the screen mode */
   al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
   al_set_new_display_option(ALLEGRO_SAMPLES, 4, ALLEGRO_SUGGEST);

   al_set_new_display_flags(display_flags);
   screen = al_create_display(w, h);
   if (!screen) {
      fprintf(stderr, "Error setting %dx%d display mode\n", w, h);
      return 1;
   }

   al_init_image_addon();

   /* The Allegro 5 port introduced an external data dependency, sorry.
    * To avoid performance problems on graphics drivers that don't support
    * drawing to textures, we build up transition screens on memory bitmaps.
    * We need a font loaded into a memory bitmap for those, then a font
    * loaded into a video bitmap for the game view. Blech!
    */
   font_path = get_resources_path();
   al_set_path_filename(font_path, "a4_font.tga");

   al_init_font_addon();
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   font = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }

   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
   font_video = al_load_bitmap_font(al_path_cstr(font_path, '/'));
   if (!font_video) {
      fprintf(stderr, "Error loading %s\n", al_path_cstr(font_path, '/'));
      return 1;
   }
   
   al_destroy_path(font_path);

   /* set up everything else */
   al_install_keyboard();
   al_install_joystick();
   if (al_install_audio()) {
      if (!al_reserve_samples(8))
         al_uninstall_audio();
   }

   init_input();
   init_sound();
   init_hiscore();

   /* the main program body */
   while (title_screen()) {
      if (play_game()) {
	 show_results();
	 score_table();
      }
   }

   /* time to go away now */
   shutdown_hiscore();
   shutdown_sound();

   goodbye();

   shutdown_input();

   al_destroy_font(font);
   al_destroy_font(font_video);

   return 0;
}
Example #12
0
int main(int argc, char **argv)
{
    ALLEGRO_VOICE *voice;
    ALLEGRO_MIXER *mixer;
    ALLEGRO_MIXER *submixer[2];
    ALLEGRO_SAMPLE_INSTANCE *sample[2];
    ALLEGRO_SAMPLE *sample_data[2];
    float sample_time;
    float max_sample_time;
    int i;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    open_log();

    if (argc < 3) {
        log_printf("This example needs to be run from the command line.\nUsage: %s file1 file2\n", argv[0]);
        goto done;
    }

    al_init_acodec_addon();

    if (!al_install_audio()) {
        abort_example("Could not init sound!\n");
    }

    voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16,
                            ALLEGRO_CHANNEL_CONF_2);
    if (!voice) {
        abort_example("Could not create ALLEGRO_VOICE.\n");
    }

    mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
                            ALLEGRO_CHANNEL_CONF_2);
    submixer[0] = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
                                  ALLEGRO_CHANNEL_CONF_2);
    submixer[1] = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
                                  ALLEGRO_CHANNEL_CONF_2);
    if (!mixer || !submixer[0] || !submixer[1]) {
        abort_example("al_create_mixer failed.\n");
    }

    if (!al_attach_mixer_to_voice(mixer, voice)) {
        abort_example("al_attach_mixer_to_voice failed.\n");
    }

    for (i = 0; i < 2; i++) {
        const char *filename = argv[i + 1];
        sample_data[i] = al_load_sample(filename);
        if (!sample_data[i]) {
            abort_example("Could not load sample from '%s'!\n", filename);
        }
        sample[i] = al_create_sample_instance(NULL);
        if (!sample[i]) {
            abort_example("al_create_sample failed.\n");
        }
        if (!al_set_sample(sample[i], sample_data[i])) {
            abort_example("al_set_sample_ptr failed.\n");
        }
        if (!al_attach_sample_instance_to_mixer(sample[i], submixer[i])) {
            abort_example("al_attach_sample_instance_to_mixer failed.\n");
        }
        if (!al_attach_mixer_to_mixer(submixer[i], mixer)) {
            abort_example("al_attach_mixer_to_mixer failed.\n");
        }
    }

    /* Play sample in looping mode. */
    for (i = 0; i < 2; i++) {
        al_set_sample_instance_playmode(sample[i], ALLEGRO_PLAYMODE_LOOP);
        al_play_sample_instance(sample[i]);
    }

    max_sample_time = al_get_sample_instance_time(sample[0]);
    sample_time = al_get_sample_instance_time(sample[1]);
    if (sample_time > max_sample_time)
        max_sample_time = sample_time;

    log_printf("Playing...");

    al_rest(max_sample_time);

    al_set_sample_instance_gain(sample[0], 0.5);
    al_rest(max_sample_time);

    al_set_sample_instance_gain(sample[1], 0.25);
    al_rest(max_sample_time);

    al_stop_sample_instance(sample[0]);
    al_stop_sample_instance(sample[1]);
    log_printf("Done\n");

    /* Free the memory allocated. */
    for (i = 0; i < 2; i++) {
        al_set_sample(sample[i], NULL);
        al_destroy_sample(sample_data[i]);
        al_destroy_sample_instance(sample[i]);
        al_destroy_mixer(submixer[i]);
    }
    al_destroy_mixer(mixer);
    al_destroy_voice(voice);

    al_uninstall_audio();

done:
    close_log(true);

    return 0;
}
Example #13
0
int main(int argc, char **argv)
{
   ALLEGRO_VOICE *voice;
   ALLEGRO_MIXER *mixer;
   ALLEGRO_SAMPLE_INSTANCE *sample;
   int i;
   char const **filenames;
   int n;

   if (argc < 2) {
      n = 1;
      filenames = malloc(sizeof *filenames);
      filenames[0] = "data/testing.ogg";
   }
   else {
      n = argc - 1;
      filenames = malloc(sizeof *filenames * n);
      for (i = 1; i < argc; ++i) {
         filenames[i - 1] = argv[i];
      }
   }

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   open_log();

   al_init_acodec_addon();

   if (!al_install_audio()) {
      abort_example("Could not init sound!\n");
   }

   voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16,
      ALLEGRO_CHANNEL_CONF_2);
   if (!voice) {
      abort_example("Could not create ALLEGRO_VOICE.\n");
   }

   mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
      ALLEGRO_CHANNEL_CONF_2);
   if (!mixer) {
      abort_example("al_create_mixer failed.\n");
   }

   if (!al_attach_mixer_to_voice(mixer, voice)) {
      abort_example("al_attach_mixer_to_voice failed.\n");
   }

   sample = al_create_sample_instance(NULL);
   if (!sample) {
      abort_example("al_create_sample failed.\n");
   }

   for (i = 0; i < n; ++i) {
      ALLEGRO_SAMPLE *sample_data = NULL;
      const char *filename = filenames[i];
      float sample_time = 0;

      /* Load the entire sound file from disk. */
      sample_data = al_load_sample(filename);
      if (!sample_data) {
         abort_example("Could not load sample from '%s'!\n",
            filename);
         continue;
      }

      if (!al_set_sample(sample, sample_data)) {
         abort_example("al_set_sample_instance_ptr failed.\n");
         continue;
      }

      if (!al_attach_sample_instance_to_mixer(sample, mixer)) {
         abort_example("al_attach_sample_instance_to_mixer failed.\n");
         goto done;
      }

      /* Play sample in looping mode. */
      al_set_sample_instance_playmode(sample, ALLEGRO_PLAYMODE_LOOP);
      al_play_sample_instance(sample);

      sample_time = al_get_sample_instance_time(sample);
      log_printf("Playing '%s' (%.3f seconds) 3 times", filename,
         sample_time);

      al_rest(sample_time);

      if (!al_set_sample_instance_gain(sample, 0.5)) {
         abort_example("Failed to set gain.\n");
      }
      al_rest(sample_time);

      if (!al_set_sample_instance_gain(sample, 0.25)) {
         abort_example("Failed to set gain.\n");
      }
      al_rest(sample_time);

      al_stop_sample_instance(sample);
      log_printf("\nDone playing '%s'\n", filename);

      /* Free the memory allocated. */
      al_set_sample(sample, NULL);
      al_destroy_sample(sample_data);
   }

   al_destroy_sample_instance(sample);
   al_destroy_mixer(mixer);
   al_destroy_voice(voice);

   al_uninstall_audio();

done:
   close_log(true);

   return 0;
}
Example #14
0
int main(int argc, const char *argv[])
{
    ALLEGRO_SAMPLE *sample_data[MAX_SAMPLE_DATA] = {NULL};
    ALLEGRO_DISPLAY *display;
    ALLEGRO_EVENT_QUEUE *event_queue;
    ALLEGRO_EVENT event;
    int i;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s {audio_files}\n", argv[0]);
        return 1;
    }
    argc--;
    argv++;

    if (!al_init()) {
        abort_example("Could not init Allegro.\n");
    }

    al_install_keyboard();

    display = al_create_display(640, 480);
    if (!display) {
        abort_example("Could not create display\n");
    }

    event_queue = al_create_event_queue();
    al_register_event_source(event_queue, al_get_keyboard_event_source());

    al_init_acodec_addon();

Restart:

    if (!al_install_audio()) {
        fprintf(stderr, "Could not init sound!\n");
        return 1;
    }

    if (!al_reserve_samples(RESERVED_SAMPLES)) {
        fprintf(stderr, "Could not set up voice and mixer.\n");
        return 1;
    }

    memset(sample_data, 0, sizeof(sample_data));
    for (i = 0; i < argc && i < MAX_SAMPLE_DATA; i++) {
        const char *filename = argv[i];

        /* Load the entire sound file from disk. */
        sample_data[i] = al_load_sample(argv[i]);
        if (!sample_data[i]) {
            fprintf(stderr, "Could not load sample from '%s'!\n", filename);
            continue;
        }
    }

    printf("Press digits to play sounds, space to stop sounds, "
           "Escape to quit.\n");

    while (true) {
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
                break;
            }
            if (event.keyboard.unichar == ' ') {
                al_stop_samples();
            }

            if (event.keyboard.unichar >= '0' && event.keyboard.unichar <= '9') {
                i = (event.keyboard.unichar - '0' + 9) % 10;
                if (sample_data[i]) {
                    printf("Playing %d\n",i);
                    if (!al_play_sample(sample_data[i], 1.0, 0.5, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL)) {
                        fprintf(stderr,
                                "al_play_sample_data failed, perhaps too many sounds\n");
                    }
                }
            }

            /* Hidden feature: restart audio subsystem.
             * For debugging race conditions on shutting down the audio.
             */
            if (event.keyboard.unichar == 'r') {
                al_uninstall_audio();
                goto Restart;
            }
        }
    }

    /* Sample data and other objects will be automatically freed. */
    al_uninstall_audio();

    return 0;
}
Example #15
0
int main( int argc, char* argv[] )
{
	ALLEGRO_EVENT e;
	ALLEGRO_TIMER* t;
	int64_t framesToUpdate = 0;

	if( !al_init() )
	{
		return -1;
	}
	
	al_init_font_addon();
	if( !al_install_keyboard() || !al_install_mouse() || !al_init_primitives_addon() || !al_init_ttf_addon() || !al_init_image_addon() )
	{
		return -1;
	}

#if NETWORK_SUPPORT != 0
	if( !install_network() )
	{
		return -1;
	}
#endif

#if HTTP_SUPPORT
	if( !install_http() )
	{
		return -1;
	}
#ifdef PANDORA
	Downloads = new HttpManager(2);
#else
	Downloads = new HttpManager(6);
#endif
#endif

#if EXIT_IF_NO_AUDIO != 0

	if( !al_install_audio() || !al_init_acodec_addon() )
	{
		return -1;
	}

	voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
	if (!voice)
		return 1;
	mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
	if (!mixer)
		return 1;
	if (!al_attach_mixer_to_voice(mixer, voice))
		return 1;

#else

	if( al_install_audio() )
	{
		if( al_init_acodec_addon() )
		{
			voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16, ALLEGRO_CHANNEL_CONF_2);
			if( voice != 0 )
			{
				mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32, ALLEGRO_CHANNEL_CONF_2);
				if( mixer != 0 )
					al_attach_mixer_to_voice(mixer, voice);
			}
		}
	}

#endif // EXIT_IF_NO_AUDIO

	// Random number is guarenteed to be random
	srand( 5 );

	GameStack = new StageStack();
	CurrentConfiguration = new Configuration();

	if( CurrentConfiguration->FullScreen )
		al_set_new_display_flags( ALLEGRO_FULLSCREEN_WINDOW );

	al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST);

	bool foundMode = false;
	int fallbackW = 640;
	int fallbackH = 480;

	if( CurrentConfiguration->ForceResolution )
	{
		foundMode = true;
	} else {
		for( int modeIdx = 0; modeIdx < al_get_num_display_modes(); modeIdx++ )
		{
			if( al_get_display_mode( modeIdx, &ScreenMode ) != NULL )
			{
				if( ScreenMode.width == CurrentConfiguration->ScreenWidth && ScreenMode.height == CurrentConfiguration->ScreenHeight )
				{
					foundMode = true;
				} else {
					fallbackW = ScreenMode.width;
					fallbackH = ScreenMode.height;
				}
			}

			if( foundMode )
				break;
		}
	}

	if( foundMode )
	{
		Screen = al_create_display( CurrentConfiguration->ScreenWidth, CurrentConfiguration->ScreenHeight );
	} else {
		Screen = al_create_display( fallbackW, fallbackH );
		CurrentConfiguration->ScreenWidth = fallbackW;
		CurrentConfiguration->ScreenHeight = fallbackH;
	}

	al_hide_mouse_cursor( Screen );

	t = al_create_timer( 1.0 / SCREEN_FPS );
  if( t == NULL )
    Quit = true;
  al_start_timer( t );

	EventQueue = al_create_event_queue();
	al_register_event_source( EventQueue, al_get_display_event_source( Screen ) );
	al_register_event_source( EventQueue, al_get_keyboard_event_source() );
	al_register_event_source( EventQueue, al_get_mouse_event_source() );
	al_register_event_source( EventQueue, al_get_timer_event_source( t ) );
#if NETWORK_SUPPORT != 0
	al_register_event_source( EventQueue, get_network_event_source() );
#endif
#if HTTP_SUPPORT
	Downloads->urlDownloads = CurrentConfiguration->MaxConcurrentDownloads;
	al_register_event_source( EventQueue, get_http_event_source() );
#endif

	Fonts = new FontManager();
	Images = new ImageManager();
	Audio = new SoundManager();

	al_set_blender( ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA );

	GameStack->Push( (Stage*)new BootUp() );

	while( !Quit )
	{
		if( GameStack->IsEmpty() )
		{
			Quit = true;
		} else {
			while( al_get_next_event( EventQueue, &e ) )
			{
#if HTTP_SUPPORT
				Downloads->Event( &e );
#endif
				switch( e.type )
				{
					case ALLEGRO_EVENT_DISPLAY_CLOSE:
						Quit = true;
						break;
					case ALLEGRO_EVENT_JOYSTICK_CONFIGURATION:
						al_reconfigure_joysticks();
						break;
					case ALLEGRO_EVENT_TIMER:
						if( e.timer.source == t )
							framesToUpdate++;
						else if( !GameStack->IsEmpty() )
							GameStack->Current()->Event( &e );
						break;
					default:
						if( !GameStack->IsEmpty() )
							GameStack->Current()->Event( &e );
						switch( e.type )
						{
#if HTTP_SUPPORT
							case ALLEGRO_EVENT_HTTP:
#endif
#if NETWORK_SUPPORT
							case ALLEGRO_EVENT_NETWORK_CONNECTION:
							case ALLEGRO_EVENT_NETWORK_RECEIVEPACKET:
							case ALLEGRO_EVENT_NETWORK_DISCONNECTION:
#endif
							case ALLEGRO_EVENT_BUTTON_CLICK:
							case ALLEGRO_EVENT_MOUSEEX_MOVE:
							case ALLEGRO_EVENT_MOUSEEX_DOWN:
							case ALLEGRO_EVENT_MOUSEEX_UP:
							case ALLEGRO_EVENT_MOUSEEX_CLICK:
							case ALLEGRO_EVENT_MOUSEEX_DOUBLECLICK:
							case ALLEGRO_EVENT_MOUSEEX_BOXED:
							case ALLEGRO_EVENT_MOUSEEX_WHEEL:
								al_unref_user_event( &e.user );
								break;
						}
						break;
				}
			}

			if( framesToUpdate > 0 )
			{
				for( int frmUp = 0; frmUp < framesToUpdate; frmUp++ )
				{
					if( !GameStack->IsEmpty() )
						GameStack->Current()->Update();
				}
				framesToUpdate = 0;
			}

			al_clear_to_color( al_map_rgb( 128, 128, 128 ) );
			if( !GameStack->IsEmpty() )
				GameStack->Current()->Render();
			al_flip_display();

			Images->Tidy();
			Fonts->Tidy();
			Audio->Tidy();
		}
	}

	while( !GameStack->IsEmpty() )
	{
		GameStack->Pop();
	}

	delete Downloads;
	delete Fonts;
	delete Images;
	delete Audio;

	al_destroy_event_queue( EventQueue );
	al_destroy_display( Screen );

#if HTTP_SUPPORT
	uninstall_http();
#endif
#if NETWORK_SUPPORT != 0
	uninstall_network();
#endif
	al_uninstall_keyboard();
	al_uninstall_mouse();
	al_shutdown_primitives_addon();
	al_shutdown_ttf_addon();
	al_shutdown_image_addon();
	al_uninstall_audio();
	al_shutdown_font_addon();

	return 0;
}
Example #16
0
File: audio.c Project: Luiji/allua
static int allua_audio_uninstall(lua_State * L)
{
   al_uninstall_audio();
   return 0;
}
EVENT AllegroFlasher::EventType()
{
	EVENT event_type = UPDATE;
	ALLEGRO_EVENT ev;							// Create a new event
	al_wait_for_event(event_queue, &ev);		// Wait for an event (timer overflow, keyboard, display)

	if(ev.type == ALLEGRO_EVENT_KEY_DOWN)		// If event type is a key press (down)
	{
		switch(ev.keyboard.keycode)				// Switch to the appropriate key code
		{
			case ALLEGRO_KEY_UP:				// If the specific key is pressed
				event_type = UP;				// Set the status of the key (only changed once we release the key)
				break;
			case ALLEGRO_KEY_DOWN:
				event_type = DOWN;
				break;
			case ALLEGRO_KEY_RIGHT:
				event_type = RIGHT;
				break;
			case ALLEGRO_KEY_LEFT:
				event_type = LEFT;
				break;
			case ALLEGRO_KEY_ESCAPE:
				al_uninstall_audio();
				event_type = ESCAPE;
				break;
			case ALLEGRO_KEY_SPACE:
				event_type = SPACE;
				break;
			case ALLEGRO_KEY_ENTER:
				event_type = ENTER;
				break;
			case ALLEGRO_KEY_L:
				event_type = LAY_MAZE;
				break;
			case ALLEGRO_KEY_R:
				event_type = RELOAD;
				break;
			default:
				event_type = UPDATE;
				break;
		}
	}

	else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)		// Mouse click the close button
	{
		event_type = ESCAPE;
	}

	else if(ev.type == ALLEGRO_EVENT_TIMER)
		event_type = UPDATE;

	if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN)
	{
		if(ev.mouse.button & 1)
			event_type = LEFT_CLICK;
		else if(ev.mouse.button & 2)
			event_type = RIGHT_CLICK;
	}

	else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES)
	{
		event_type = MOVE_MOUSE;
		mouse_xpos = ev.mouse.x;
		mouse_ypos = ev.mouse.y;
	}

	return event_type;
}
Example #18
0
int main(int argc, char *argv[])
{
   ALLEGRO_DISPLAY *display;
   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   open_log();

   al_install_keyboard();
   al_install_mouse();

   al_init_primitives_addon();
   al_init_font_addon();
   al_init_ttf_addon();

   al_set_new_display_flags(ALLEGRO_GENERATE_EXPOSE_EVENTS);
   display = al_create_display(800, 600);
   if (!display) {
      abort_example("Unable to create display\n");
   }
   al_set_window_title(display, "Synthesiser of sorts");

   font_gui = al_load_ttf_font("data/DejaVuSans.ttf", 12, 0);
   if (!font_gui) {
      abort_example("Failed to load data/fixed_font.tga\n");
   }

   if (!al_install_audio()) {
      abort_example("Could not init sound!\n");
   }

   if (!al_reserve_samples(0)) {
      abort_example("Could not set up voice and mixer.\n");
   }

   size_t buffers = 8;
   unsigned samples = SAMPLES_PER_BUFFER;
   unsigned freq = STREAM_FREQUENCY;
   ALLEGRO_AUDIO_DEPTH depth = ALLEGRO_AUDIO_DEPTH_FLOAT32;
   ALLEGRO_CHANNEL_CONF ch = ALLEGRO_CHANNEL_CONF_1;

   stream1 = al_create_audio_stream(buffers, samples, freq, depth, ch);
   stream2 = al_create_audio_stream(buffers, samples, freq, depth, ch);
   stream3 = al_create_audio_stream(buffers, samples, freq, depth, ch);
   stream4 = al_create_audio_stream(buffers, samples, freq, depth, ch);
   stream5 = al_create_audio_stream(buffers, samples, freq, depth, ch);
   if (!stream1 || !stream2 || !stream3 || !stream4 || !stream5) {
      abort_example("Could not create stream.\n");
   }

   ALLEGRO_MIXER *mixer = al_get_default_mixer();
   if (
      !al_attach_audio_stream_to_mixer(stream1, mixer) ||
      !al_attach_audio_stream_to_mixer(stream2, mixer) ||
      !al_attach_audio_stream_to_mixer(stream3, mixer) ||
      !al_attach_audio_stream_to_mixer(stream4, mixer) ||
      !al_attach_audio_stream_to_mixer(stream5, mixer)
   ) {
      abort_example("Could not attach stream to mixer.\n");
   }

   al_set_mixer_postprocess_callback(mixer, mixer_pp_callback, mixer);

   /* Prog is destroyed at the end of this scope. */
   {
      Theme theme(font_gui);
      Prog prog(theme, display);
      prog.run();
   }

   al_destroy_audio_stream(stream1);
   al_destroy_audio_stream(stream2);
   al_destroy_audio_stream(stream3);
   al_destroy_audio_stream(stream4);
   al_destroy_audio_stream(stream5);
   al_uninstall_audio();

   al_destroy_font(font_gui);

   al_fclose(save_fp);

   close_log(false);

   return 0;
}
int main(int argc, char **argv)
{
   ALLEGRO_VOICE *voice;
   ALLEGRO_SAMPLE_INSTANCE *sample;
   int i;

   if (argc < 2) {
      fprintf(stderr, "Usage: %s {audio_files}\n", argv[0]);
      return 1;
   }

   if (!al_init()) {
      fprintf(stderr, "Could not init Allegro.\n");
      return 1;
   }

   al_init_acodec_addon();

   if (!al_install_audio()) {
      fprintf(stderr, "Could not init sound!\n");
      return 1;
   }

   for (i = 1; i < argc; ++i) {
      ALLEGRO_SAMPLE *sample_data = NULL;
      const char *filename = argv[i];
      ALLEGRO_CHANNEL_CONF chan;
      ALLEGRO_AUDIO_DEPTH depth;
      unsigned long freq;
      float sample_time = 0;

      /* Load the entire sound file from disk. */
      sample_data = al_load_sample(filename);
      if (!sample_data) {
         fprintf(stderr, "Could not load sample from '%s'!\n",
            filename);
         continue;
      }

      sample = al_create_sample_instance(NULL);
      if (!sample) {
         fprintf(stderr, "al_create_sample failed.\n");
        return 1;
      }

      if (!al_set_sample(sample, sample_data)) {
         fprintf(stderr, "al_set_sample failed.\n");
         continue;
      }

      depth = al_get_sample_instance_depth(sample);
      chan = al_get_sample_instance_channels(sample);
      freq = al_get_sample_instance_frequency(sample);
      fprintf(stderr, "Loaded sample: %i-bit depth, %i channels, %li Hz\n",
         (depth < 8) ? (8+depth*8) : 0, (chan>>4)+(chan%0xF), freq);
      fprintf(stderr, "Trying to create a voice with the same specs... ");
      voice = al_create_voice(freq, depth, chan);
      if (!voice) {
         fprintf(stderr, "Could not create ALLEGRO_VOICE.\n");
         return 1;
      }
      fprintf(stderr, "done.\n");

      if (!al_attach_sample_instance_to_voice(sample, voice)) {
         fprintf(stderr, "al_attach_sample_instance_to_voice failed.\n");
         return 1;
      }

      /* Play sample in looping mode. */
      al_set_sample_instance_playmode(sample, ALLEGRO_PLAYMODE_LOOP);
      al_play_sample_instance(sample);

      sample_time = al_get_sample_instance_time(sample);
      fprintf(stderr, "Playing '%s' (%.3f seconds) 3 times", filename,
         sample_time);

      al_rest(sample_time * 3);

      al_stop_sample_instance(sample);
      fprintf(stderr, "\n");

      /* Free the memory allocated. */
      al_set_sample(sample, NULL);
      al_destroy_sample(sample_data);
      al_destroy_sample_instance(sample);
      al_destroy_voice(voice);
   }

   al_uninstall_audio();

   return 0;
}
Example #20
0
void
shutdown_sound(void)
{
	al_uninstall_audio();
}
int main(int argc, char **argv)
{
   const char *filename = "../demos/cosmic_protector/data/sfx/title_music.ogg";
   ALLEGRO_VOICE *voice;
   ALLEGRO_MIXER *mixer;
   ALLEGRO_AUDIO_STREAM *stream;

   if (argc > 1) {
      filename = argv[1];
   }

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

   al_init_primitives_addon();
   al_init_image_addon();
   al_init_acodec_addon();
   
   al_install_keyboard();

   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Could not create display.\n");
      return 1;
   }

   dbuf = al_create_bitmap(640, 480);

   bmp = al_load_bitmap("data/mysha.pcx");
   if (!bmp) {
      abort_example("Could not load data/mysha.pcx\n");
      return 1;
   }

   if (!al_install_audio()) {
      abort_example("Could not init sound.\n");
      return 1;
   }

   voice = al_create_voice(44100, ALLEGRO_AUDIO_DEPTH_INT16,
      ALLEGRO_CHANNEL_CONF_2);
   if (!voice) {
      abort_example("Could not create voice.\n");
      return 1;
   }

   mixer = al_create_mixer(44100, ALLEGRO_AUDIO_DEPTH_FLOAT32,
      ALLEGRO_CHANNEL_CONF_2);
   if (!mixer) {
      abort_example("Could not create mixer.\n");
      return 1;
   }

   if (!al_attach_mixer_to_voice(mixer, voice)) {
      abort_example("al_attach_mixer_to_voice failed.\n");
      return 1;
   }

   stream = al_load_audio_stream(filename, 4, 2048);
   if (!stream) {
      abort_example("Could not load '%s'\n", filename);
      return 1;
   }

   al_set_audio_stream_playmode(stream, ALLEGRO_PLAYMODE_LOOP);
   al_attach_audio_stream_to_mixer(stream, mixer);

   al_set_mixer_postprocess_callback(mixer, update_meter, NULL);

   main_loop();

   al_destroy_audio_stream(stream);
   al_destroy_mixer(mixer);
   al_destroy_voice(voice);
   al_uninstall_audio();

   al_destroy_bitmap(dbuf);
   al_destroy_bitmap(bmp);

   return 0;
}