c55sound continued
[oweals/minetest.git] / src / sound.h
1 /*
2 Minetest-c55
3 Copyright (C) 2012 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 General Public License as published by
7 the Free Software Foundation; either version 2 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 General Public License for more details.
14
15 You should have received a copy of the GNU 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.h"
24 #include <string>
25 #include <vector>
26 #include <set>
27
28 class OnDemandSoundFetcher
29 {
30 public:
31         virtual void fetchSounds(const std::string &name,
32                         std::set<std::string> &dst_paths,
33                         std::set<std::vector<char> > &dst_datas) = 0;
34 };
35
36 class ISoundManager
37 {
38 public:
39         virtual ~ISoundManager(){}
40         
41         // Multiple sounds can be loaded per name; when played, the sound
42         // should be chosen randomly from alternatives
43         // Return value determines success/failure
44         virtual bool loadSound(const std::string &name,
45                         const std::string &filepath) = 0;
46         virtual bool loadSound(const std::string &name,
47                         const std::vector<char> &filedata) = 0;
48
49         virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
50         // playSound functions return -1 on failure, otherwise a handle to the
51         // sound
52         virtual int playSound(const std::string &name, bool loop,
53                         float volume) = 0;
54         virtual int playSoundAt(const std::string &name, bool loop,
55                         float volume, v3f pos) = 0;
56         virtual void stopSound(int sound) = 0;
57 };
58
59 class DummySoundManager: public ISoundManager
60 {
61 public:
62         virtual bool loadSound(const std::string &name,
63                         const std::string &filepath) {return true;}
64         virtual bool loadSound(const std::string &name,
65                         const std::vector<char> &filedata) {return true;}
66         void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
67         int playSound(const std::string &name, bool loop,
68                         float volume) {return 0;}
69         int playSoundAt(const std::string &name, bool loop,
70                         float volume, v3f pos) {return 0;}
71         void stopSound(int sound) {}
72 };
73
74 // Global DummySoundManager singleton
75 extern DummySoundManager dummySoundManager;
76
77 #endif
78