Skip to content

Commit

Permalink
Refactor: change usages of _ready and _process to _notification
Browse files Browse the repository at this point in the history
(closes #36).
  • Loading branch information
stechyo committed Apr 6, 2024
1 parent 2c3db8a commit 709bf6d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
16 changes: 14 additions & 2 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,35 @@ void SteamAudioConfig::_bind_methods() {
SteamAudioConfig::SteamAudioConfig() {}
SteamAudioConfig::~SteamAudioConfig() {}

void SteamAudioConfig::_ready() {
void SteamAudioConfig::ready_internal() {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}

// Initialize global state
SteamAudioServer::get_singleton()->get_global_state();
set_physics_process(true);
}

void SteamAudioConfig::_physics_process(double delta) {
void SteamAudioConfig::process_internal(double delta) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}

SteamAudioServer::get_singleton()->tick();
}

void SteamAudioConfig::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
ready_internal();
break;
case NOTIFICATION_PHYSICS_PROCESS:
process_internal(get_physics_process_delta_time());
break;
}
}

SteamAudio::GodotSteamAudioLogLevel SteamAudioConfig::get_global_log_level() { return log_level; }
void SteamAudioConfig::set_global_log_level(SteamAudio::GodotSteamAudioLogLevel p_global_log_level) { log_level = p_global_log_level; }

Expand Down
6 changes: 4 additions & 2 deletions src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class SteamAudioConfig : public Node3D {
private:
std::vector<IPLStaticMesh> meshes;

void process_internal(double delta);
void ready_internal();

protected:
static void _bind_methods();

Expand All @@ -34,8 +37,7 @@ class SteamAudioConfig : public Node3D {

SteamAudioConfig();
~SteamAudioConfig();
void _ready() override;
void _physics_process(double delta) override;
void _notification(int p_what);

SteamAudio::GodotSteamAudioLogLevel get_global_log_level();
void set_global_log_level(SteamAudio::GodotSteamAudioLogLevel p_global_log_level);
Expand Down
10 changes: 9 additions & 1 deletion src/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SteamAudioGeometry::~SteamAudioGeometry() {
destroy_geometry();
}

void SteamAudioGeometry::_ready() {
void SteamAudioGeometry::ready_internal() {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
Expand All @@ -38,6 +38,14 @@ void SteamAudioGeometry::_ready() {
register_geometry();
}

void SteamAudioGeometry::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
ready_internal();
break;
}
}

void SteamAudioGeometry::set_disabled(bool p_disabled) {
if (disabled == p_disabled) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class SteamAudioGeometry : public Node3D {
void register_geometry();
void unregister_geometry();

void ready_internal();

protected:
static void _bind_methods();

Expand All @@ -28,7 +30,7 @@ class SteamAudioGeometry : public Node3D {

SteamAudioGeometry();
~SteamAudioGeometry();
void _ready() override;
void _notification(int p_what);

void recalculate();
Ref<SteamAudioMaterial> get_material();
Expand Down
5 changes: 3 additions & 2 deletions src/geometry_dynamic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ class SteamAudioDynamicGeometry : public Node3D {
void register_geometry();
void unregister_geometry();

void ready_internal();
void process_internal(double delta);

protected:
static void _bind_methods();

public:
SteamAudioDynamicGeometry();
~SteamAudioDynamicGeometry();
void ready_internal();
void process_internal(double delta);
void _notification(int p_what);

void recalculate();
Expand Down
10 changes: 9 additions & 1 deletion src/listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void SteamAudioListener::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "reflection_ambisonics_order", PROPERTY_HINT_RANGE, "0,5,1"), "set_refl_ambisonics_order", "get_refl_ambisonics_order");
}

void SteamAudioListener::_ready() {
void SteamAudioListener::ready_internal() {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
Expand All @@ -38,6 +38,14 @@ void SteamAudioListener::_ready() {
SteamAudioServer::get_singleton()->add_listener(this);
}

void SteamAudioListener::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
ready_internal();
break;
}
}

SteamAudioListener::SteamAudioListener() {}
SteamAudioListener::~SteamAudioListener() {}

Expand Down
5 changes: 4 additions & 1 deletion src/listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class SteamAudioListener : public Node3D {
int refl_ambisonics_order = 1;
float irradiance_min_dist = 1.0f;

void ready_internal();

protected:
static void _bind_methods();

public:
void _ready() override;
SteamAudioListener();
~SteamAudioListener();

void _notification(int p_what);

int get_num_refl_rays();
void set_num_refl_rays(int p_num_refl_rays);
int get_num_refl_bounces();
Expand Down

0 comments on commit 709bf6d

Please sign in to comment.