HammeriteAudioHearing
Audio. Inherits RefCounted
What a map's listeners can hear: the gameplay half of acoustics, apart from the mixing.
One per map, on its HammeriteAudioManager.hearing. A game's AI touches this and little else: a guard's HammeriteAudioReceiver3D registers itself here, and whatever makes a noise reports it - through HammeriteAudio.report_sound(), or by playing an HammeriteAudioEmitter3D with a HammeriteAudioEmitter3D.sound_type, both of which end up at report_sound(). Nothing happens for a type nothing has subscribed to. That is the whole cost model: a footstep in a level where nothing listens for footsteps is not propagated, or even measured. It asks the mixer how sound gets from one place to another, so that what a guard hears and what the player hears are one answer rather than two that disagree. What it decides itself is who was in earshot, how loud it arrived, and where it seemed to come from.
Methods
| Returns | Method |
|---|---|
void | register_listener(listener: HammeriteAudioReceiver3D) |
void | unregister_listener(listener: HammeriteAudioReceiver3D) |
bool | anyone_hears(type: StringName) |
void | report_sound(type: StringName, position: Vector3, emitter: Node = null) |
Method descriptions
register_listener()
func register_listener(listener: HammeriteAudioReceiver3D) -> void
Register a listener under each of the sound types it subscribes to. A HammeriteAudioReceiver3D does this itself on entering the tree, and again through HammeriteAudioReceiver3D.add_heard_type(); the types are read now, so a change made any other way needs a re-register.
unregister_listener()
func unregister_listener(listener: HammeriteAudioReceiver3D) -> void
Remove a listener from every type it was registered under.
anyone_hears()
func anyone_hears(type: StringName) -> bool
Whether anything is listening for type at all. What makes reporting a footstep affordable on every step: ask this and there is nothing more to do in a level with no ears for it.
report_sound()
func report_sound(type: StringName, position: Vector3, emitter: Node = null) -> void
Report a sound of type made at position, and tell whoever could hear it. The type is checked first and cheaply: with nothing subscribed there is no work to do. Then, per listener, straight-line distance against the type's range - a cheap reject that avoids pathfinding for sounds that could not possibly carry - and only then the propagation query, which is the expensive part. emitter is whatever made the noise, used so a listener can disregard its own.