3 Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "irrlichttypes.h"
28 class OnDemandSoundFetcher
31 virtual void fetchSounds(const std::string &name,
32 std::set<std::string> &dst_paths,
33 std::set<std::vector<char> > &dst_datas) = 0;
36 struct SimpleSoundSpec
40 SimpleSoundSpec(std::string name="", float gain=1.0):
44 bool exists() {return name != "";}
45 // Serialization intentionally left out
51 virtual ~ISoundManager(){}
53 // Multiple sounds can be loaded per name; when played, the sound
54 // should be chosen randomly from alternatives
55 // Return value determines success/failure
56 virtual bool loadSound(const std::string &name,
57 const std::string &filepath) = 0;
58 virtual bool loadSound(const std::string &name,
59 const std::vector<char> &filedata) = 0;
61 virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0;
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,
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;
73 int playSound(const SimpleSoundSpec &spec, bool loop)
74 { return playSound(spec.name, loop, spec.gain); }
75 int playSoundAt(const SimpleSoundSpec &spec, bool loop, v3f pos)
76 { return playSoundAt(spec.name, loop, spec.gain, pos); }
79 class DummySoundManager: public ISoundManager
82 virtual bool loadSound(const std::string &name,
83 const std::string &filepath) {return true;}
84 virtual bool loadSound(const std::string &name,
85 const std::vector<char> &filedata) {return true;}
86 void updateListener(v3f pos, v3f vel, v3f at, v3f up) {}
87 int playSound(const std::string &name, bool loop,
88 float volume) {return 0;}
89 int playSoundAt(const std::string &name, bool loop,
90 float volume, v3f pos) {return 0;}
91 void stopSound(int sound) {}
92 bool soundExists(int sound) {return false;}
93 void updateSoundPosition(int sound, v3f pos) {}
96 // Global DummySoundManager singleton
97 extern DummySoundManager dummySoundManager;