Line data Source code
1 : /*
2 : Minetest
3 : Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 :
5 : This program is free software; you can redistribute it and/or modify
6 : it under the terms of the GNU Lesser General Public License as published by
7 : the Free Software Foundation; either version 2.1 of the License, or
8 : (at your option) any later version.
9 :
10 : This program is distributed in the hope that it will be useful,
11 : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : GNU Lesser General Public License for more details.
14 :
15 : You should have received a copy of the GNU Lesser General Public License along
16 : with this program; if not, write to the Free Software Foundation, Inc.,
17 : 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 : */
19 :
20 : #ifndef SOUND_HEADER
21 : #define SOUND_HEADER
22 :
23 : #include "irrlichttypes_bloated.h"
24 : #include <string>
25 : #include <set>
26 :
27 2 : class OnDemandSoundFetcher
28 : {
29 : public:
30 : virtual void fetchSounds(const std::string &name,
31 : std::set<std::string> &dst_paths,
32 : std::set<std::string> &dst_datas) = 0;
33 : };
34 :
35 486890 : struct SimpleSoundSpec
36 : {
37 : std::string name;
38 : float gain;
39 74472 : SimpleSoundSpec(std::string name="", float gain=1.0):
40 : name(name),
41 74472 : gain(gain)
42 74472 : {}
43 38 : bool exists() {return name != "";}
44 : // Serialization intentionally left out
45 : };
46 :
47 3 : class ISoundManager
48 : {
49 : public:
50 3 : virtual ~ISoundManager(){}
51 :
52 : // Multiple sounds can be loaded per name; when played, the sound
53 : // should be chosen randomly from alternatives
54 : // Return value determines success/failure
55 : virtual bool loadSoundFile(const std::string &name,
56 : const std::string &filepath) = 0;
57 : virtual bool loadSoundData(const std::string &name,
58 : const std::string &filedata) = 0;
59 :
60 : virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
61 : virtual void setListenerGain(float gain) = 0;
62 :
63 : // playSound functions return -1 on failure, otherwise a handle to the
64 : // sound. If name=="", call should be ignored without error.
65 : virtual int playSound(const std::string &name, bool loop,
66 : float volume) = 0;
67 : virtual int playSoundAt(const std::string &name, bool loop,
68 : float volume, v3f pos) = 0;
69 : virtual void stopSound(int sound) = 0;
70 : virtual bool soundExists(int sound) = 0;
71 : virtual void updateSoundPosition(int sound, v3f pos) = 0;
72 :
73 38 : int playSound(const SimpleSoundSpec &spec, bool loop)
74 38 : { return playSound(spec.name, loop, spec.gain); }
75 26 : int playSoundAt(const SimpleSoundSpec &spec, bool loop, v3f pos)
76 26 : { return playSoundAt(spec.name, loop, spec.gain, pos); }
77 : };
78 :
79 2 : class DummySoundManager: public ISoundManager
80 : {
81 : public:
82 0 : virtual bool loadSoundFile(const std::string &name,
83 0 : const std::string &filepath) {return true;}
84 0 : virtual bool loadSoundData(const std::string &name,
85 0 : const std::string &filedata) {return true;}
86 0 : void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
87 0 : void setListenerGain(float gain) {}
88 0 : int playSound(const std::string &name, bool loop,
89 0 : float volume) {return 0;}
90 0 : int playSoundAt(const std::string &name, bool loop,
91 0 : float volume, v3f pos) {return 0;}
92 0 : void stopSound(int sound) {}
93 0 : bool soundExists(int sound) {return false;}
94 0 : void updateSoundPosition(int sound, v3f pos) {}
95 : };
96 :
97 : // Global DummySoundManager singleton
98 : extern DummySoundManager dummySoundManager;
99 :
100 : #endif
101 :
|