~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-engine/core/src/audio/code/sound_manager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  Bear Engine
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
35
35
#include <claw/exception.hpp>
36
36
#include <fstream>
37
37
#include <vector>
38
 
#include <boost/thread/mutex.hpp>
39
38
 
40
39
/*----------------------------------------------------------------------------*/
41
40
bool bear::audio::sound_manager::s_initialized = false;
93
92
  CLAW_PRECOND( !sound_exists(name) );
94
93
 
95
94
  if (s_initialized)
96
 
    m_sounds[name] = new sdl_sound(file, *this);
 
95
    m_sounds[name] = new sdl_sound(file, name, *this);
97
96
  else
98
 
    m_sounds[name] = new sound(*this);
 
97
    m_sounds[name] = new sound(name, *this);
99
98
} // sound_manager::load_sound()
100
99
 
101
100
/*----------------------------------------------------------------------------*/
150
149
 
151
150
/*----------------------------------------------------------------------------*/
152
151
/**
 
152
 * \brief Get a copy of a sound sample.
 
153
 * \param s The sample to copy.
 
154
 * \remark You are responsible of deleting the sample.
 
155
 */
 
156
bear::audio::sample* bear::audio::sound_manager::new_sample( const sample& s )
 
157
{
 
158
  return new_sample(s.get_sound_name());
 
159
} // sound_manager::new_sample()
 
160
 
 
161
/*----------------------------------------------------------------------------*/
 
162
/**
153
163
 * \brief Play a music.
154
164
 * \param name The name of the music to play.
155
165
 * \param loops How many times the music loops (zero means infinite).
199
209
 
200
210
  muted_music_list::const_iterator it;
201
211
 
202
 
  for (it=m_muted_musics.begin(); (m==NULL) && (it!=m_muted_musics.end()); ++it)
 
212
  for (it=m_muted_musics.begin(); (m==NULL) && (it!=m_muted_musics.end());
 
213
       ++it)
203
214
    if (it->first->get_id() == id )
204
215
      m = it->first;
205
216
 
256
267
  std::map<sample*, bool>::iterator it;
257
268
 
258
269
  for ( it=m_samples.begin(); it!=m_samples.end(); ++it )
259
 
    it->first->set_volume(m_sound_volume);
 
270
    if ( !is_music(it->first) )
 
271
      it->first->set_volume(m_sound_volume);
260
272
} // sound_manager::set_sound_volume()
261
273
 
262
274
/*----------------------------------------------------------------------------*/
324
336
 */
325
337
void bear::audio::sound_manager::sample_finished( sample* s )
326
338
{
327
 
  boost::mutex samples_mutex;
328
 
  std::map<sample*, bool>::iterator it = m_samples.find(s);
329
 
 
330
 
  if ( it!=m_samples.end() )
331
 
    if ( it->second )
332
 
      {
333
 
        m_samples.erase(it);
334
 
        delete s;
335
 
      }
 
339
  std::map<sample*, bool>::iterator it;
 
340
  bool do_delete(false);
 
341
 
 
342
  it = m_samples.find(s);
 
343
  if ( it==m_samples.end() )
 
344
    do_delete = it->second;
 
345
 
 
346
  if ( do_delete )
 
347
    delete s; // will call sample_deleted()
336
348
 
337
349
  if ( s == m_current_music )
338
350
    {
427
439
/*----------------------------------------------------------------------------*/
428
440
/**
429
441
 * \brief Remove a music from m_muted_musics.
 
442
 * \param m The music to remove.
430
443
 */
431
444
void bear::audio::sound_manager::remove_muted_music( sample* m )
432
445
{
433
 
  boost::mutex remove_mutex;
434
446
  muted_music_list::iterator it(m_muted_musics.begin());
435
447
  bool found(false);
436
448
 
443
455
  if (found)
444
456
    m_muted_musics.erase(it);
445
457
} // sound_manager::remove_muted_music()
 
458
 
 
459
/*----------------------------------------------------------------------------*/
 
460
/**
 
461
 * \brief Tell if a sample is used as a music.
 
462
 */
 
463
bool bear::audio::sound_manager::is_music( const sample* m ) const
 
464
{
 
465
  bool result( m == m_current_music );
 
466
  muted_music_list::const_iterator it;
 
467
 
 
468
  for ( it=m_muted_musics.begin(); !result && (it!=m_muted_musics.end()); ++it )
 
469
    result = (it->first == m);
 
470
 
 
471
  return result;
 
472
} // sound_manager::is_music()