⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oasisaudible.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
字号:
/******************************************************************************

 * This source file is part of Bad Camel Gaming

 * Copyright (C) 2003  Zephie Greyvenstein

 * See Readme.html for acknowledgements

 *

 * This library is free software; you can redistribute it and/or

 * modify it under the terms of the GNU Lesser General Public

 * License as published by the Free Software Foundation; either

 * version 2.1 of the License, or (at your option) any later version.

 *

 * This library is distributed in the hope that it will be useful,

 * but WITHOUT ANY WARRANTY; without even the implied warranty of

 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

 * Lesser General Public License for more details.

 *

 * You should have received a copy of the GNU Lesser General Public

 * License along with this library; if not, write to the Free Software

 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 *****************************************************************************/



/******************************************************************************

 * FILENAME    : oasisAudible.cpp

 * DESCRIPTION : An audible object

 * AUTHOR      : Zephie Greyvenstein

 *****************************************************************************/



#include "oasisAudible.h"

#include "oasisSoundSystem.h"

#include "oasisSound.h"

#include "oasisException.h"



namespace Oasis {

  

  audible::audible( ) {  

    sounds.clear( );

  }

  

  audible::~audible( ) {

    removeAndDestroyAllSounds( );

  }

  

  sound *audible::addSound( const string &name, const string &templateName ) {

    // If there is no sound system, error. Perhaps we could start it?

    if ( !soundSystem::getPtr( ) ) {

      oasisError( exception::ET_INTERNAL_ERROR,

      "To include sounds in audibles, start the sound system",

      "audible::addSound" );

    }

    

    sound *object = soundSystem::get( ).

      createSound( soundSystem::get( ).getNextUniqueName( ),

       templateName );

    addSound( name, object );

    return object;

  }

  

  void audible::addSound( const string &name, sound *soundObject ) {

    if ( !soundObject ) {

      oasisError( exception::ET_NULL_POINTER,

      "Sound was null",

      "audible::addSound" );

    }



    _processNewSound( soundObject );

    sounds[ name ] = soundObject;

  }



 sound *audible::getSound( const string &name ) {

   // Find sound

   soundMap::iterator it = sounds.find( name );

   

   if ( it == sounds.end( ) ) {   

     oasisError( exception::ET_ITEM_NOT_FOUND,

     "Sound item " + name + " not found",

     "audible::getSound" );    

   } else {

     return it->second;

   }    

 }



  sound *audible::playSound( const string &name ) {

    sound *object = getSound( name );

    object->play( );



    return object;

  }       



  sound *audible::stopSound( const string &name ) {

    sound *object = getSound( name );  

    object->stop( );

    

    return object;

  }



  void audible::stopAllSounds( void ) {

    // Stop everything

    for( soundMap::iterator it = sounds.begin( );

   it != sounds.end( ); ++it ) {

      ( it->second )->stop( );

    }

  }



  void audible::removeAllSounds( void ) {

    stopAllSounds( );

    sounds.clear( );

  }



  void audible::removeAndDestroyAllSounds( void ) {

    // Destroy everything

    for( soundMap::iterator it = sounds.begin( );

   it != sounds.end( ); ++it ) {

      soundSystem::get( ).removeSound( it->second );

    }

    sounds.clear( );

  }



  void audible::removeSound( const string &name ) {   

    sounds.erase( name );

  }



  void audible::removeAndDestroySound( const string &name ) {

    sound *object = getSound( name );

    soundSystem::get( ).removeSound( object );

    sounds.erase( name );

  }

  

  audible::soundIterator audible::getSoundIterator( void ) {

    return soundIterator( sounds.begin( ), sounds.end( ) );

  }



  void audible::_setSoundPosition( sound *soundObject,

           const vector3 &newPosition ) {

    soundObject->setPosition( newPosition );

  }



  void audible::_setAllSoundPositions( const vector3 &newPosition ) {

    for ( soundMap::iterator it = sounds.begin( );

    it != sounds.end( ); ++it ) {

      it->second->setPosition( newPosition );

    }

  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -