File: soundList.h

package info (click to toggle)
asc 2.6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,592 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 606; perl: 138
file content (65 lines) | stat: -rw-r--r-- 1,952 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef soundListH
#define soundListH

/*! \file soundList.h
    \brief The collection of all sounds used by ASC
*/

#include <map>

#include "global.h"
#include "sdl/sound.h"
#include "ascstring.h"
#include "textfile_evaluation.h"

/** A helper class for managing looping sounds.
    A sound may be preloaded, later activated and this class assures that it is closed again.
    Or it simply can be loaded with a running sound and stops it on destruction
*/
class SoundLoopManager {
      Sound* sound;
      bool active;
   public:
      SoundLoopManager ( Sound* snd, bool _active = true );
      // void setSound ( Sound* snd ) { sound = snd; };
      void activate ( int dummy );
      void fadeOut ( int ms ) { if ( sound && active ) sound->fadeOut( ms ); };
      ~SoundLoopManager() { if ( sound && active ) sound->stop(); };
};



/** This class provides all the sounds required by the games user interface.
    It uses the singleton design pattern.
*/
class SoundList {
    SoundList() {};
    static SoundList* instance;
public:
    static SoundList& getInstance();
    enum Sample { shooting, unitExplodes, buildingCollapses, moving, menu_ack, conquer_building, repair, refuel, jumpdrive };

    static void init( );
    Sound* playSound ( Sample snd, int subType = 0, bool looping = false, const ASCString& label = "" );
    Sound* getSound ( Sample snd, int subType = 0, const ASCString& label = "", int height = -1);

   ~SoundList();
private:
     void initialize();

     typedef map<ASCString,Sound*> SoundFiles;
     SoundFiles  soundFiles;

     Sound* getSound( const ASCString& filename );

      struct SoundAssignment {
           SoundList::Sample sample;
           int subType;
           Sound* defaultSound;
           map<ASCString,Sound*> snd;
      };
     vector<SoundAssignment> soundAssignments;
     void readLine( PropertyContainer& pc, const ASCString& name, SoundList::Sample sample, int subtype = 0 );
};

#endif