HatchitGame
ht_audiosource_component.h
1 
15 #pragma once
16 
17 #include <ht_component.h> //Component
18 #include <ht_jsonhelper.h> //Core::JSON
19 #include <ht_audio_resource.h> //AudioHandle
20 #include <ht_audiosource.h> //Audio::Source
21 #include <ht_audiobuffer.h> //Audio::Buffer
22 #include <array> //std::array
23 
24 struct stb_vorbis;
25 
26 namespace Hatchit
27 {
28  namespace Core
29  {
30  class Guid;
31  }
32 }
33 
34 namespace Hatchit
35 {
36  namespace Game
37  {
38  class AudioSource : public Component
39  {
40  public:
41  AudioSource();
42  AudioSource(const AudioSource& source);
43  AudioSource(AudioSource&& source);
44 
45  AudioSource& operator=(const AudioSource& source);
46  AudioSource& operator=(AudioSource&& source);
47 
48  virtual Core::JSON VSerialize() override;
49  virtual bool VDeserialize(const Core::JSON& jsonObject) override;
50 
51  virtual void VOnInit() override;
52  virtual void VOnUpdate() override;
53 
54  virtual Component* VClone() const override;
55 
56  virtual Core::Guid VGetComponentId(void) const override;
57 
58  void PlayAudio(Resource::AudioResourceHandle handle);
59  protected:
60 
61  virtual void VOnEnabled() override;
62  virtual void VOnDisabled() override;
63  virtual void VOnDestroy() override;
64 
65  private:
66  static constexpr size_t numBuffers = 16;
67 
68  Resource::AudioResourceHandle m_currentAudioHandle;
69  bool m_playing;
70  stb_vorbis* m_audioStream;
71  Audio::Source m_source;
72  std::array<Audio::Buffer, numBuffers> m_bufferList;
73  size_t m_nextBufferIndex;
74 
75  void SetupBuffer(Audio::Buffer& audioBuffer);
76  bool SetupAudioStream();
77 
78  };
79  }
80 }
Definition: ht_audiosource_component.h:38
Definition: ht_component.h:42
Hatchit Engine Copyright(c) 2015-2016 Third-Degree.
Definition: ht_glfwkeyboard.h:21