Esempio n. 1
0
File: naev.c Progetto: ekrumme/naev
/**
 * @brief Loads a loading screen.
 */
void loadscreen_load (void)
{
   unsigned int i;
   char file_path[PATH_MAX];
   char **loadscreens;
   uint32_t nload;

   /* Count the loading screens */
   loadscreens = ndata_list( "gfx/loading/", &nload );

   /* Must have loading screens */
   if (nload==0) {
      WARN("No loading screens found!");
      loading = NULL;
      return;
   }

   /* Set the zoom. */
   gl_cameraZoom( conf.zoom_far );

   /* Load the texture */
   snprintf( file_path, PATH_MAX, "gfx/loading/%s", loadscreens[ RNG_SANE(0,nload-1) ] );
   loading = gl_newImage( file_path, 0 );

   /* Create the stars. */
   space_initStars( 1000 );

   /* Clean up. */
   for (i=0; i<nload; i++)
      free(loadscreens[i]);
   free(loadscreens);
}
Esempio n. 2
0
File: music.c Progetto: Arakash/naev
/**
 * @brief Internal music loading routines.
 *
 *    @return 0 on success.
 */
static int music_find (void)
{
   char** files;
   uint32_t nfiles,i;
   char tmp[64];
   int len, suflen, flen;
   int mem;

   if (music_disabled)
      return 0;

   /* get the file list */
   files = ndata_list( MUSIC_PREFIX, &nfiles );

   /* load the profiles */
   mem = 0;
   suflen = strlen(MUSIC_SUFFIX);
   for (i=0; i<nfiles; i++) {
      flen = strlen(files[i]);
      if ((flen > suflen) &&
            strncmp( &files[i][flen - suflen], MUSIC_SUFFIX, suflen)==0) {

         /* grow the selection size */
         nmusic_selection++;
         if (nmusic_selection > mem) {
            mem += CHUNK_SIZE;
            music_selection = realloc( music_selection, sizeof(char*)*mem);
         }

         /* remove the prefix and suffix */
         len = flen - suflen;
         strncpy( tmp, files[i], len );
         tmp[MIN(len,64-1)] = '\0';
         
         /* give it the new name */
         music_selection[nmusic_selection-1] = strdup(tmp);
      }

      /* Clean up. */
      free(files[i]);
   }
   music_selection = realloc( music_selection, sizeof(char*)*nmusic_selection);

   DEBUG("Loaded %d song%c", nmusic_selection, (nmusic_selection==1)?' ':'s');

   /* More clean up. */
   free(files);

   return 0;
}
Esempio n. 3
0
/**
 * @brief Internal music loading routines.
 *
 *    @return 0 on success.
 */
static int music_find (void)
{
   char** files;
   uint32_t nfiles,i;
   int suflen, flen;
   int nmusic;

   if (music_disabled)
      return 0;

   /* get the file list */
   files = ndata_list( MUSIC_PREFIX, &nfiles );

   /* load the profiles */
   nmusic = 0;
   suflen = strlen(MUSIC_SUFFIX);
   for (i=0; i<nfiles; i++) {
      flen = strlen(files[i]);
      if ((flen > suflen) &&
            strncmp( &files[i][flen - suflen], MUSIC_SUFFIX, suflen)==0) {

         /* grow the selection size */
         nmusic++;
      }

      /* Clean up. */
      free(files[i]);
   }

   DEBUG("Loaded %d song%c", nmusic, (nmusic==1)?' ':'s');

   /* More clean up. */
   free(files);

   return 0;
}
Esempio n. 4
0
/**
 * @brief Makes the list of available sounds.
 */
static int sound_makeList (void)
{
   char** files;
   uint32_t nfiles,i;
   char path[PATH_MAX];
   char tmp[64];
   int len, suflen, flen;
   int mem;

   if (sound_disabled)
      return 0;

   /* get the file list */
   files = ndata_list( SOUND_PREFIX, &nfiles );

   /* load the profiles */
   mem = 0;
   suflen = strlen(SOUND_SUFFIX_WAV);
   for (i=0; i<nfiles; i++) {
      flen = strlen(files[i]);

      /* Must be longer than suffix. */
      if (flen < suflen) {
         free(files[i]);
         continue;
      }

      /* Make sure is wav or ogg. */
      if ((strncmp( &files[i][flen - suflen], SOUND_SUFFIX_WAV, suflen)!=0) &&
            (strncmp( &files[i][flen - suflen], SOUND_SUFFIX_OGG, suflen)!=0)) {
         free(files[i]);
         continue;
      }

      /* grow the selection size */
      sound_nlist++;
      if (sound_nlist > mem) { /* we must grow */
         mem += 32; /* we'll overallocate most likely */
         sound_list = realloc( sound_list, mem*sizeof(alSound));
      }

      /* remove the suffix */
      len = flen - suflen;
      strncpy( tmp, files[i], len );
      tmp[len] = '\0';

      /* Load the sound. */
      sound_list[sound_nlist-1].name = strdup(tmp);
      snprintf( path, PATH_MAX, SOUND_PREFIX"%s", files[i] );
      if (sound_load( &sound_list[sound_nlist-1], path )) {
         sound_nlist--; /* Song not actually added. */
      }

      /* Clean up. */
      free(files[i]);
   }
   /* shrink to minimum ram usage */
   sound_list = realloc( sound_list, sound_nlist*sizeof(alSound));

   DEBUG("Loaded %d sound%s", sound_nlist, (sound_nlist==1)?"":"s");

   /* More clean up. */
   free(files);

   return 0;
}