Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7318 in orxonox.OLD for trunk


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

orxonox/trunk: SoundSource in the Menu

Location:
trunk/src
Files:
5 edited

Legend:

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

    r7317 r7318  
    124124 * @param sourceNode The sourceNode to bind this SoundSource to.
    125125 * @returns The newly created SoundSource
    126 
    127    acctualy this is nothing more than a wrapper around the ResourceManager.
     126 *
     127 * acctualy this is nothing more than a wrapper around the ResourceManager.
    128128*/
    129129SoundSource* SoundEngine::createSource(const std::string& fileName, PNode* sourceNode)
    130130{
    131   return new SoundSource(sourceNode, (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL));
     131  SoundBuffer* buffer = NULL;
     132  if (!fileName.empty())
     133  {
     134     buffer= (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL);
     135     if (buffer == NULL)
     136       PRINTF(2)("Wav-Sound %s could not be loaded onto new Source\n", fileName.c_str());
     137  }
     138    return new SoundSource(sourceNode, buffer);
    132139}
    133140
     
    151158 * @param source the Source to fill with the Value.
    152159 */
    153 bool SoundEngine::popALSource(ALuint& source)
     160void SoundEngine::popALSource(ALuint& source)
    154161{
    155162  assert (source == 0);
    156 
    157163  /// @TODO try to create more sources if needed
    158164  if (!this->ALSources.empty())
     
    162168    this->ALSources.pop();
    163169    SDL_mutexV(this->sourceMutex);
    164     return true;
    165   }
    166   else
    167     return false;
     170  }
    168171}
    169172
  • trunk/src/lib/sound/sound_engine.h

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

    r7317 r7318  
    117117void SoundSource::play()
    118118{
    119   if (this->retrieveSource())
    120   {
    121     alSourcePlay(this->sourceID);
     119  if (this->buffer && this->retrieveSource())
     120  {
     121    if (this->bPlay)
     122      alSourceStop(this->sourceID);
     123    alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     124      alSourcePlay(this->sourceID);
     125
    122126    if (DEBUG >= 3)
    123127      SoundEngine::checkError("Play Source", __LINE__);
  • trunk/src/story_entities/simple_game_menu.cc

    r7317 r7318  
    3535#include "graphics_engine.h"
    3636#include "object_manager.h"
    37 
     37#include "sound_engine.h"
     38#include "sound_source.h"
    3839
    3940#include "cd_engine.h"
     
    6263  this->layerIndex = 0;
    6364  this->menuSelectedIndex = 0;
     65  this->selectorSource = NULL;
    6466
    6567  if (root != NULL)
     
    134136  if (this->dataXML != NULL)
    135137  {
     138    LoadParam(dataXML, "selector-sound", this, SimpleGameMenu, setSelectorSound);
     139
    136140    TiXmlElement* element = this->dataXML->FirstChildElement("Elements");
     141
    137142
    138143    if( element == NULL)
     
    237242}
    238243
     244/**
     245 * @brief set the Sound to play when switching menu entry.
     246 * @param selectorSound the sound to load.
     247 */
     248void SimpleGameMenu::setSelectorSound(const std::string& selectorSound)
     249{
     250  this->selectorSource = SoundEngine::getInstance()->createSource(selectorSound, NULL);
     251  printf("=============== %s\n", selectorSound.c_str());
     252}
    239253
    240254ErrorMessage SimpleGameMenu::unloadData()
     
    257271  }
    258272
     273  // delete the SoundSource.
     274  if (this->selectorSource != NULL)
     275    delete this->selectorSource;
     276  this->selectorSource = NULL;
    259277
    260278  GameWorld::unloadData();
     
    375393      this->menuSelected = this->menuLayers[this->layerIndex].menuList[++this->menuSelectedIndex];
    376394      this->sliderTo(this->menuSelected, 5.0f);
     395      if (this->selectorSource != NULL)
     396        this->selectorSource->play();
    377397
    378398      if( this->layerIndex == 1)
     
    389409      this->menuSelected = this->menuLayers[this->layerIndex].menuList[--this->menuSelectedIndex];
    390410      this->sliderTo(this->menuSelected, 5.0f);
     411      if (this->selectorSource != NULL)
     412        this->selectorSource->play();
    391413
    392414      if( this->layerIndex == 1)
  • trunk/src/story_entities/simple_game_menu.h

    r7063 r7318  
    2020class TiXmlElement;
    2121class ImageEntity;
     22class SoundSource;
    2223
    2324
     
    7071    void switchMenuLayer(int layer1, int layer2);
    7172    void sliderTo(const Element2D* element, float bias = 0.0f);
     73    void setSelectorSound(const std::string& selectorSound);
    7274
    7375
     
    8688
    8789    Vector                            cameraVector;
     90
     91    SoundSource*                      selectorSource;
    8892};
    8993
Note: See TracChangeset for help on using the changeset viewer.