Skip to content

Commit

Permalink
Add Support for Distance Probes (#94)
Browse files Browse the repository at this point in the history
* Distance Probe Support

Super-duper basic implementation of Wwise Distance Probes. Requires the Game Objects used to have already been registered as a listener and an object respectively.

* Updated Github documentation

Added the methods to the Wwise GDExtension documentation.
  • Loading branch information
Snoopy20111 authored Apr 8, 2024
1 parent fedbae6 commit d163d4b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
20 changes: 20 additions & 0 deletions addons/Wwise/native/doc/Wwise.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,26 @@
Note: There can be only one Spatial Audio listener registered at any given time.
</description>
</method>
<method name="set_distance_probe">
<return type="bool" />
<param index="0" name="listener_game_object" type="Object" />
<param index="1" name="probe_game_object" type="Object" />
<description>
Sets the given [param probe_game_object] to be a Distance Probe for the given
[param listener_game_object. This means attenuation will be calculated from the probe's
position, but panning and spatialization will be calculated from the listener.
Returns [code]true[/code] if the process succeeded. Note: Both the listener and object
must be registered before this will succeed.
</description>
</method>
<method name="reset_distance_probe">
<return type="bool" />
<param index="0" name="listener_game_object" type="Object" />
<description>
Clears the Distance Probe for the given [param listener_game_object] and reverts to using
the listener position for distance calculations.
</description>
</method>
<method name="remove_game_object_from_room">
<return type="bool" />
<param index="0" name="game_object" type="Object" />
Expand Down
30 changes: 30 additions & 0 deletions addons/Wwise/native/src/wwise_gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void Wwise::_bind_methods()
ClassDB::bind_method(D_METHOD("register_listener", "game_object"), &Wwise::register_listener);
ClassDB::bind_method(D_METHOD("register_game_obj", "game_object", "name"), &Wwise::register_game_obj);
ClassDB::bind_method(D_METHOD("unregister_game_obj", "game_object"), &Wwise::unregister_game_obj);
ClassDB::bind_method(D_METHOD("set_distance_probe", "listener_game_object", "probe_game_object"), &Wwise::set_distance_probe);
ClassDB::bind_method(D_METHOD("reset_distance_probe", "listener_game_object"), &Wwise::reset_distance_probe);
ClassDB::bind_method(D_METHOD("set_listeners", "emtter", "listener"), &Wwise::set_listeners);
ClassDB::bind_method(D_METHOD("set_random_seed", "seed"), &Wwise::set_random_seed);
ClassDB::bind_method(D_METHOD("set_3d_position", "game_object", "transform_3d"), &Wwise::set_3d_position);
Expand Down Expand Up @@ -362,6 +364,34 @@ bool Wwise::unregister_game_obj(const Object* game_object)
return ERROR_CHECK(AK::SoundEngine::UnregisterGameObj(static_cast<AkGameObjectID>(game_object->get_instance_id())));
}

bool Wwise::set_distance_probe(const Object* listener_game_object, const Object* probe_game_object)
{
AKASSERT(listener_game_object);
AKASSERT(probe_game_object);

const AkGameObjectID listener = static_cast<AkGameObjectID>(listener_game_object->get_instance_id());
const AkGameObjectID probe = static_cast<AkGameObjectID>(probe_game_object->get_instance_id());

if (!ERROR_CHECK(AK::SoundEngine::SetDistanceProbe(listener, probe)))
{
return false;
}

return true;
}

bool Wwise::reset_distance_probe(const Object* listener_game_object)
{
AKASSERT(listener_game_object);
const AkGameObjectID listener = static_cast<AkGameObjectID>(listener_game_object->get_instance_id());
if (!ERROR_CHECK(AK::SoundEngine::SetDistanceProbe(listener, AK_INVALID_GAME_OBJECT)))
{
return false;
}

return true;
}

bool Wwise::set_listeners(const Object* emitter, const Object* listener)
{
AKASSERT(emitter);
Expand Down
3 changes: 3 additions & 0 deletions addons/Wwise/native/src/wwise_gdextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Wwise : public Object
bool register_listener(const Object* game_object);
bool register_game_obj(const Object* game_object, const String& game_object_name);
bool unregister_game_obj(const Object* game_object);

bool set_distance_probe(const Object* listener_game_object, const Object* probe_game_object);
bool reset_distance_probe(const Object* listener_game_object);

bool set_listeners(const Object* emitter, const Object* listener);
void set_random_seed(const unsigned int seed);
Expand Down

0 comments on commit d163d4b

Please sign in to comment.