Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7317 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Apr 17, 2006, 2:25:27 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: retrieve Source is better now (more modular)

Location:
trunk/src
Files:
5 edited

Legend:

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

    r7299 r7317  
    151151 * @param source the Source to fill with the Value.
    152152 */
    153 void SoundEngine::popALSource(ALuint& source)
     153bool SoundEngine::popALSource(ALuint& source)
    154154{
    155155  assert (source == 0);
     
    162162    this->ALSources.pop();
    163163    SDL_mutexV(this->sourceMutex);
    164   }
     164    return true;
     165  }
     166  else
     167    return false;
    165168}
    166169
  • trunk/src/lib/sound/sound_engine.h

    r7299 r7317  
    4949
    5050  // administrative
    51     void popALSource(ALuint& source);
     51    bool popALSource(ALuint& source);
    5252    void pushALSource(ALuint& source);
    5353
  • trunk/src/lib/sound/sound_source.cc

    r7299 r7317  
    3434  this->buffer = buffer;
    3535  this->sourceNode = sourceNode;
     36  this->resident = false;
    3637
    3738  this->sourceID = 0;
    3839  this->bPlay = false;
    3940}
     41
    4042
    4143/**
     
    5355  this->buffer = source.buffer;
    5456  this->sourceNode = source.sourceNode;
     57  this->resident = source.resident;
    5558
    5659  this->sourceID = 0;
     
    6366    this->bPlay = false;
    6467}
     68
    6569
    6670/**
     
    7478  this->buffer = source.buffer;
    7579  this->sourceNode = sourceNode;
     80  this->resident = source.resident;
    7681
    7782  if (source.bPlay)
     
    8186}
    8287
     88
    8389/**
    8490 * @brief compares two Sources with each other.
     
    94100}
    95101
     102
    96103/**
    97104 * @brief deletes a SoundSource
     
    100107{
    101108  this->stop();
    102 }
     109  if (this->sourceID != 0)
     110    SoundEngine::getInstance()->pushALSource(this->sourceID);
     111}
     112
    103113
    104114/**
     
    107117void SoundSource::play()
    108118{
    109   if (this->sourceID == 0)
    110     SoundEngine::getInstance()->popALSource(this->sourceID);
    111   alSourcePlay(this->sourceID);
    112   if (DEBUG >= 3)
    113     SoundEngine::checkError("Play Source", __LINE__);
    114   this->bPlay = true;
    115 }
    116 
    117 /**
    118  * Plays back buffer on this Source
     119  if (this->retrieveSource())
     120  {
     121    alSourcePlay(this->sourceID);
     122    if (DEBUG >= 3)
     123      SoundEngine::checkError("Play Source", __LINE__);
     124    this->bPlay = true;
     125  }
     126}
     127
     128
     129/**
     130 * @brief Plays back buffer on this Source
    119131 * @param buffer the buffer to play back on this Source
    120132 */
    121133void SoundSource::play(const SoundBuffer* buffer)
    122134{
    123   if (unlikely(this->sourceID == 0))
    124   {
    125     SoundEngine::getInstance()->popALSource(this->sourceID);
    126     if (sourceID == 0)
    127     {
    128       PRINTF(2)("No more Free source\n");
    129       return;
    130     }
    131   }
    132   //  assert (this->sourceID != 0);
     135  if (!this->retrieveSource())
     136  {
     137    PRINTF(2)("No more Free sources (You might consider raising the Source-Count).\n");
     138    return;
     139  }
    133140
    134141  alSourceStop(this->sourceID);
     
    143150    SoundEngine::checkError("Play Source", __LINE__);
    144151}
     152
    145153
    146154/**
     
    156164      SoundEngine::checkError("StopSource", __LINE__);
    157165    alSourcei(this->sourceID, AL_BUFFER, 0);
    158     SoundEngine::getInstance()->pushALSource(this->sourceID);
     166    if (!this->resident)
     167      SoundEngine::getInstance()->pushALSource(this->sourceID);
    159168    this->sourceID = 0;
    160169  }
    161170}
    162171
     172
    163173/**
    164174 * @brief Pauses Playback of a SoundSource
     
    171181}
    172182
     183
    173184/**
    174185 * @brief Rewinds Playback of a SoundSource
     
    181192    SoundEngine::checkError("Rewind Source", __LINE__);
    182193}
     194
    183195
    184196/**
     
    196208}
    197209
     210
     211/**
     212 * @brief sets the Positional this Source should be attached to.
     213 * @param sourceNode the Source this is attached to.
     214 * If sourceNode == NULL then the Source will be centered, and Audio will be played on all channels.
     215 */
     216void SoundSource::setSourceNode(const PNode* sourceNode)
     217{
     218  this->sourceNode = sourceNode;
     219}
     220
     221/**
     222 * @brief retrieve a Source.
     223 */
     224bool SoundSource::retrieveSource()
     225{
     226  if (this->sourceID != 0)
     227    return true;
     228  else
     229  {
     230    SoundEngine::getInstance()->popALSource(this->sourceID);
     231    if (this->sourceID != 0)
     232    {
     233      if (unlikely(this->sourceNode == NULL))
     234        resetSource(this->sourceID);
     235      return true;
     236    }
     237  }
     238  return false;
     239}
     240
     241
     242/**
     243 * @brief reset an alSource to its default Values.
     244 */
     245void SoundSource::resetSource(ALuint sourceID)
     246{
     247  alSource3f(sourceID, AL_POSITION,        0.0, 0.0, 0.0);
     248  alSource3f(sourceID, AL_VELOCITY,        0.0, 0.0, 0.0);
     249  alSource3f(sourceID, AL_DIRECTION,       0.0, 0.0, 0.0);
     250  alSourcef (sourceID, AL_ROLLOFF_FACTOR,  0.0          );
     251  alSourcei (sourceID, AL_SOURCE_RELATIVE, AL_TRUE      );
     252  alSourcef (sourceID, AL_GAIN,            SoundEngine::getInstance()->getEffectsVolume());
     253}
  • trunk/src/lib/sound/sound_source.h

    r7299 r7317  
    3434  // development functions
    3535    /** @returns The ID of this Source */
    36     inline ALuint getID() const { return this->sourceID; }
     36    inline ALuint getID() const { return this->sourceID; };
    3737    /** @returns true, if the Source is Playing */
    3838    inline bool   isPlaying() const { return this->bPlay; };
    39     /** @param sourceNode the Source this is attached to. */
    40     inline void setSourceNode(const PNode* sourceNode) { this->sourceNode = sourceNode;};
     39    void setSourceNode(const PNode* sourceNode);
    4140    /** @returns the SoundBuffer of this Source */
    42     inline const SoundBuffer* getBuffer() const { return this->buffer; }
     41    inline const SoundBuffer* getBuffer() const { return this->buffer; };
    4342    /** @returns the SourceNode of this Source */
    44     inline const PNode* getNode() const { return this->sourceNode;}
     43    inline const PNode* getNode() const { return this->sourceNode; };
     44    /** @param resident if the Source is Resident */
     45    inline void setResident(bool resident) { this->resident = resident; };
     46    /** @returns true if the alSource is Resident */
     47    inline bool isResident() const { return this->resident; };
    4548
    4649    void setRolloffFactor(ALfloat rolloffFactor);
    4750
     51    static void resetSource(ALuint sourceID);
     52
     53  private:
     54    bool retrieveSource();
     55
    4856  private:
    4957    bool                   bPlay;                 //!< If the Source is Playing.
     58    bool                   resident;              //!< If the alSource should be resident (if true, the alSource will be returned on deletion).
    5059    ALuint                 sourceID;              //!< The ID of the Source
    5160    const SoundBuffer*     buffer;                //!< The buffer to play in this source.
  • trunk/src/story_entities/simple_game_menu.cc

    r7316 r7317  
    401401
    402402/**
    403  * switches to from one meny layer to an other
     403 * @brief switches to from one meny layer to an other
    404404 * @param layer1 from layer
    405405 * @param layer2 to layer
Note: See TracChangeset for help on using the changeset viewer.