Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7304 in orxonox.OLD


Ignore:
Timestamp:
Apr 16, 2006, 8:27:32 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: moved the AudioThread completely to the OggPlayer. This cleans out the unnecesary overFULLNESS from game_world

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/sound/ogg_player.cc

    r7303 r7304  
    4040  this->buffers[0] = 0;
    4141  this->buffers[1] = 0;
     42  this->musicThread = NULL;
    4243
    4344  if (!fileName.empty())
     
    135136  return true;
    136137}
     138
     139
     140
     141int OggPlayer::createAudioThread(void* oggPlayer)
     142{
     143  if (oggPlayer == NULL)
     144    return -1;
     145  OggPlayer* ogg = (OggPlayer*)oggPlayer;
     146  PRINTF(4)("STARTIG AUDIO THREAD\n");
     147
     148  ogg->playback();
     149
     150  while (ogg->state & Playing)
     151  {
     152    ogg->update();
     153    SDL_Delay(1);
     154  }
     155  PRINTF(4)("End the AudioThread\n");
     156}
     157
    137158
    138159/**
     
    171192    this->state &= ! FileOpened;
    172193  }
    173 }
    174 
     194
     195  // Kill the Music Thread.
     196  if (this->musicThread != NULL)
     197  {
     198    assert (!(this->state & Playing));
     199    SDL_WaitThread(this->musicThread, NULL);
     200    this->musicThread = NULL;
     201  }
     202}
     203
     204
     205bool OggPlayer::play()
     206{
     207  if (this->musicThread == NULL)
     208    this->musicThread = SDL_CreateThread(OggPlayer::createAudioThread, (void*)this);
     209}
    175210
    176211/**
  • trunk/src/lib/sound/ogg_player.h

    r7303 r7304  
    1515#include <ogg/ogg.h>
    1616#include <vorbis/vorbisfile.h>
     17#include <SDL_thread.h>
    1718
    1819struct File;
     
    3132  bool open(const std::string& fileName);
    3233  void release();
    33   void debug();
    34   bool playback();
     34  bool play();
    3535  bool playing();
    3636  bool update();
     
    3838  void jumpTo(float timeCode);
    3939
     40  void debug();
    4041  void printState();
     42
     43  static int createAudioThread(void* oggPlayer);
     44
    4145
    4246protected:
     
    4549  const char* errorString(int code);
    4650
    47   public:
    48     typedef enum {
    49       None                   = 0x000,
    50       FileOpened             = 0x100,
    51       SourceAllocated        = 0x200,
    52       BuffersAllocated       = 0x400,
    53       Stopped                = 0x010,
    54       Playing                = 0x020,
    55       Paused                 = 0x040,
    56       Error                  = 0x001,
    57     } State;
     51private:
     52  bool playback();
     53
     54
     55public:
     56  typedef enum {
     57    None                   = 0x000,
     58    FileOpened             = 0x100,
     59    SourceAllocated        = 0x200,
     60    BuffersAllocated       = 0x400,
     61    Stopped                = 0x010,
     62    Playing                = 0x020,
     63    Paused                 = 0x040,
     64    Error                  = 0x001,
     65  } State;
    5866
    5967private:
     
    6775  ALenum              format;               //!< The format we play back
    6876  unsigned int        state;
    69   //bool                trackLoaded;          //!< If a Track has been loaded.
     77
     78  SDL_Thread*         musicThread;          //!< The Thread in which music is Played back.
    7079};
    7180
  • trunk/src/story_entities/game_world.cc

    r7297 r7304  
    8989
    9090  this->dataXML = NULL;
    91 
    92   this->audioThread = NULL;
    9391}
    9492
     
    134132}
    135133
    136 int GameWorld::createAudioThread(void* gameWorld)
    137 {
    138   GameWorld* gw = (GameWorld*)gameWorld;
    139   printf("STARTIG AUDIO THREAD\n");
    140   if(gw->dataTank && gw->dataTank->music != NULL)
    141     gw->dataTank->music->playback();
    142 
    143   while (gw->bRunning)
    144   {
    145     if(gw->dataTank && gw->dataTank->music != NULL)
    146       gw->dataTank->music->update();
    147     SDL_Delay(1);
    148   }
    149   printf("End the AudioThread\n");
    150 }
    151134
    152135/**
     
    204187  PRINTF(3)("GameWorld::~GameWorld() - unloading the current GameWorld\n");
    205188
    206   if (this->audioThread != NULL)
    207   {
    208     this->bRunning = false;
    209     SDL_WaitThread(this->audioThread, NULL);
    210     this->audioThread = NULL;
    211   }
    212 
    213189  this->dataTank->unloadData();
    214190
     
    227203  this->bRunning = true;
    228204
    229   if (this->audioThread == NULL)
    230     this->audioThread = SDL_CreateThread(GameWorld::createAudioThread, (void*)this);
    231 
    232205  this->run();
    233206}
     
    241214  PRINTF(3)("GameWorld::stop() - got stop signal\n");
    242215  this->bRunning = false;
    243 
    244   if (this->audioThread != NULL)
    245   {
    246     this->bRunning = false;
    247     SDL_WaitThread(this->audioThread, NULL);
    248     this->audioThread = NULL;
    249   }
    250 
    251   this->audioThread = NULL;
    252216}
    253217
     
    288252  this->dtS = 0.0f;
    289253  this->lastFrame = SDL_GetTicks ();
     254
     255  if (this->dataTank->music != NULL)
     256    this->dataTank->music->play();
    290257
    291258  while( this->bRunning) /* @todo implement pause */
  • trunk/src/story_entities/game_world.h

    r7283 r7304  
    1010#include "story_entity.h"
    1111#include "game_world_data.h"
    12 
    13 #include <SDL_thread.h>
    1412
    1513class Shell;
     
    5654    static void toggleBVVisibility();
    5755
    58     static int createAudioThread(void* GameWorld);
    59 
    60 
    6156    inline void setSky(WorldEntity* sky) { this->dataTank->sky = sky; }
    6257
     
    8075
    8176  protected:
    82     SDL_Thread*         audioThread;
    8377    GameWorldData*      dataTank;                     //!< reference to the GameWorld Data Tank
    8478    TiXmlElement*       dataXML;                      //!< The XML-Element this World has been loaded with.
Note: See TracChangeset for help on using the changeset viewer.