Toast Engine
Loading...
Searching...
No Matches
audio_volume.hpp
1
8
9#pragma once
10#include <toast/export.hpp>
11#include <toast/world/box.hpp>
13#include <vector>
14
15namespace toast {
16class AudioListener;
17
25class TOAST_API [[ToastNode, Hidden, Interface, Color("Beige")]] AudioVolume : public Volume {
26public:
27 virtual void onAudioTargetEnter(const VolumeTarget& target) = 0;
28 virtual void onAudioTargetExit(const VolumeTarget& target) = 0;
29 void resetAccumulators() override;
30 void finalizeAccumulators();
31
32 void setListeners(const std::vector<Box<AudioListener>>& listeners);
33
34protected:
35 [[nodiscard]]
36 auto trackTarget(const VolumeTarget& target, bool inside) -> bool;
37 [[nodiscard]]
38 auto hasListenersInside() const -> bool;
39
40 virtual void onVolumeTick() { }
41
42private:
43 void begin();
44 void end();
45 void onEnable();
46 void onDisable();
47 void lateTick();
48
49 struct ListenerState {
50 VolumeTarget target;
51 bool inside = false;
52 };
53
54 std::vector<ListenerState> m_listeners_inside;
55 std::vector<ListenerState> m_pending_targets;
56 std::vector<Box<AudioListener>> m_listeners;
57};
58
59}
pseudo shared pointer for Nodes
Definition audio_listener.hpp:15
Base interface for audio-reactive volumes.
Definition audio_volume.hpp:25
virtual void onVolumeTick()
called after accumulators are finalized, safe to push to FMOD here
Definition audio_volume.hpp:40
auto trackTarget(const VolumeTarget &target, bool inside) -> bool
returns true if the inside state changed
Definition audio_volume.cpp:34
Intrusive reference-counted handle to a Node.
Definition box.hpp:35
Definition volume.hpp:27
What a volume is being evaluated against: a listener, a camera, anything with a position.
Definition volume.hpp:19
Generic cubic volume.