Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Muzak Namespace Reference

Functions

void * readerThread (void *input)
 

Variables

std::map< std::string,
AUDSoundProperties > 
cachedSongs
 

Function Documentation

void * Muzak::readerThread ( void *  input)

Definition at line 397 of file music.cpp.

References AUDLoadSoundFile(), cachedSongs, checkerr, fNET_fgetc(), VegaConfig::getVariable(), VsnetOSS::memcpy(), micro_sleep, vs_config, and VSFileSystem::vs_dprintf().

Referenced by Music::Listen().

404 {
405  Music *me = (Music*) input;
406  me->threadalive = 1;
407 #ifdef USE_SOUNDSERVER
408  int socketr = me->socketr;
409  while (!me->killthread) {
410  printf( "Reading from socket %d\n", socketr );
411  char data = fNET_fgetc( socketr );
412  printf( "Got data from socket %c\n", data );
413  if (data == 'e')
414  me->moredata = 1;
415  micro_sleep( 100000 );
416  }
417 #else
418  while (!me->killthread) {
419 #ifdef _WIN32
420  WaitForSingleObject( me->musicinfo_mutex, INFINITE );
421 #else
422  checkerr( pthread_mutex_lock( &me->musicinfo_mutex ) );
423 #endif
424  if (me->killthread) break;
425  me->music_loading = true;
426  me->music_loaded = false;
427  me->music_load_info->success = false;
428  size_t len = me->music_load_info->hashname.length();
429  char *songname = (char*) malloc( len+1 );
430  songname[len] = '\0';
431  memcpy( songname, me->music_load_info->hashname.data(), len );
432  std::map< std::string, AUDSoundProperties >::iterator wherecache = cachedSongs.find( songname );
433  bool foundcache = wherecache != cachedSongs.end();
434  static std::string cachable_songs = vs_config->getVariable( "audio", "cache_songs", "../music/land.ogg" );
435  bool docacheme = cachable_songs.find( songname ) != std::string::npos;
436  if (foundcache == false && docacheme) {
437  me->music_load_info->wave = NULL;
438  cachedSongs[songname] = *me->music_load_info;
439  wherecache = cachedSongs.find( songname );
440  }
441 #ifdef _WIN32
442  ReleaseMutex( me->musicinfo_mutex );
443 #else
444  checkerr( pthread_mutex_unlock( &me->musicinfo_mutex ) );
445 #endif
446  {
447  me->freeWav = true;
448  if (foundcache) {
449  *me->music_load_info = wherecache->second;
450  me->freeWav = false;
451  }else if
452  ( !AUDLoadSoundFile( songname, me->music_load_info, true ) )
453  {VSFileSystem::vs_dprintf(1, "Failed to load music file \"%s\"", songname);}
454 
455  }
456  if (me->freeWav && docacheme) {
457  me->freeWav = false;
458  wherecache->second = *me->music_load_info;
459  }
460  free( songname );
461  me->music_loaded = true;
462  while (me->music_loaded)
463  micro_sleep( 10000 ); //10ms of busywait for now... wait until end of frame.
464  }
465 #endif /* !USE_SOUNDSERVER */
466  me->threadalive = 0;
467  return NULL;
468 }

Variable Documentation

std::map< std::string, AUDSoundProperties > Muzak::cachedSongs

Definition at line 389 of file music.cpp.

Referenced by readerThread().