i6engine  1.0
AudioManager.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_MODULES_AUDIOMANAGER_H__
26 #define __I6ENGINE_MODULES_AUDIOMANAGER_H__
27 
28 #include <map>
29 
31 
34 
37 
38 #include "AL/al.h"
39 #include "AL/alc.h"
40 
41 namespace i6e {
42 namespace modules {
43 
44  class AudioController;
45  class AudioMailbox;
46  class AudioNode;
47  struct WavFile;
48 
49  class AudioManager {
50  friend class AudioMailbox;
51 
52  public:
56  AudioManager();
57 
61  ~AudioManager();
62 
66  void Tick();
67 
68  private:
69  bool _initialized;
70  ALCdevice * _device;
71  ALCcontext * _context;
72 
73  std::map<int64_t, boost::shared_ptr<AudioNode>> _nodes;
74 
75  enum SoundEntry {
76  Source,
77  Buffer,
78  Callback,
79  Handle,
80  Category
81  };
82  std::vector<std::tuple<ALuint, ALuint, std::function<void(bool)>, api::audio::SoundHandle, std::string>> _sounds;
83 
84  std::map<std::string, boost::shared_ptr<WavFile>> _cachedSounds;
85 
89  void NewsCreate(const api::GameMessage::Ptr & msg);
90  void NewsUpdate(const api::GameMessage::Ptr & msg);
91  void NewsDelete(const api::GameMessage::Ptr & msg);
92  void NewsNodeCreate(const api::GameMessage::Ptr & msg);
93  void NewsNodeUpdate(const api::GameMessage::Ptr & msg);
94  void NewsNodeDelete(const api::GameMessage::Ptr & msg);
95 
99  void updateListener(const Vec3 & pos, const Quaternion & rot, const Vec3 & vel);
100 
104  void playSound(api::audio::SoundHandle handle, const std::string & file, double maxDistance, const Vec3 & pos, const Vec3 & dir, bool cacheable, const std::string & category, const std::function<void(bool)> & callback = [](bool) {});
105 
109  AudioManager(const AudioManager &) = delete;
110 
114  AudioManager & operator=(const AudioManager &) = delete;
115 
117  };
118 
119 } /* namespace modules */
120 } /* namespace i6e */
121 
122 #endif /* __I6ENGINE_MODULES_AUDIOMANAGER_H__ */
123 
uint64_t SoundHandle
Definition: AudioConfig.h:37
Class describing a 3d rotation.
Definition: i6eQuaternion.h:58
boost::shared_ptr< Message > Ptr
Definition: Message.h:66
struct i6e::modules::WavFile WavFile
parsed wave file
Implements 3-dimensional vectors.
Definition: i6eVector.h:48
#define ASSERT_THREAD_SAFETY_HEADER
void Tick()
ticks the audio subsystem
Handles the incoming messages on the audio channel and calls the corresponding methods.
Definition: AudioMailbox.h:42