From 79feb8e6beb8296fb56aa2bbb1c74e8d7ffa3581 Mon Sep 17 00:00:00 2001 From: Ced Naru Date: Tue, 13 Feb 2024 16:06:49 +0100 Subject: [PATCH] Fix lifecycle callbacks --- demo/low_level_2D/Emitter.gd | 1 + src/nodes/fmod_event_emitter.h | 49 +++++++++++++++++++++------------- src/nodes/fmod_listener.h | 29 +++++++++++++++++--- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/demo/low_level_2D/Emitter.gd b/demo/low_level_2D/Emitter.gd index 249d7027..5190fb09 100644 --- a/demo/low_level_2D/Emitter.gd +++ b/demo/low_level_2D/Emitter.gd @@ -25,4 +25,5 @@ func _process(_delta): self.queue_free() var time = Time.get_ticks_msec()/1000.0 self.position.x = 300 * sin(time) + event.set_2d_attributes(self.global_transform) diff --git a/src/nodes/fmod_event_emitter.h b/src/nodes/fmod_event_emitter.h index 0917cab8..1c59e0a5 100644 --- a/src/nodes/fmod_event_emitter.h +++ b/src/nodes/fmod_event_emitter.h @@ -47,12 +47,13 @@ namespace godot { List _parameters; + void ready(); + void process(); + void exit_tree(); + public: - virtual void _ready() override; - virtual void _process(double delta) override; void _notification(int p_what); - virtual void _exit_tree() override; - + void play(); void stop(); Variant get_parameter(const String& p_name) const; @@ -110,7 +111,7 @@ namespace godot { } template - void FmodEventEmitter::_ready() { + void FmodEventEmitter::ready() { #ifdef TOOLS_ENABLED // ensure we only run FMOD when the game is running! if (Engine::get_singleton()->is_editor_hint()) { return; } @@ -134,7 +135,7 @@ namespace godot { } template - void FmodEventEmitter::_process(double delta) { + void FmodEventEmitter::process() { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { return; } #endif @@ -158,26 +159,39 @@ namespace godot { } template - void FmodEventEmitter::_notification(int p_what) { + void FmodEventEmitter::exit_tree() { #ifdef TOOLS_ENABLED - // ensure we only run FMOD when the game is running! if (Engine::get_singleton()->is_editor_hint()) { return; } #endif - if (p_what == Node::NOTIFICATION_PAUSED) { - set_paused(true); - } else if (p_what == Node::NOTIFICATION_UNPAUSED) { - if (is_paused()) { set_paused(false); } - } + stop(); } - + template - void FmodEventEmitter::_exit_tree() { + void FmodEventEmitter::_notification(int p_what) { #ifdef TOOLS_ENABLED + // ensure we only run FMOD when the game is running! if (Engine::get_singleton()->is_editor_hint()) { return; } #endif - - stop(); + switch(p_what){ + case Node::NOTIFICATION_PAUSED: + set_paused(true); + break; + case Node::NOTIFICATION_UNPAUSED: + if (is_paused()) { set_paused(false); } + break; + case Node::NOTIFICATION_READY: + ready(); + break; + case Node::NOTIFICATION_PROCESS: + process(); + break; + case Node::NOTIFICATION_EXIT_TREE: + exit_tree(); + break; + default: + break; + } } template @@ -746,7 +760,6 @@ namespace godot { ClassDB::bind_method(D_METHOD("is_allow_fadeout"), &Derived::is_allow_fadeout); ClassDB::bind_method(D_METHOD("set_preload_event", "preload_event"), &Derived::set_preload_event); ClassDB::bind_method(D_METHOD("is_preload_event"), &Derived::is_preload_event); - ClassDB::bind_method(D_METHOD("_notification", "p_what"), &Derived::_notification); ClassDB::bind_method(D_METHOD("get_volume"), &Derived::get_volume); ClassDB::bind_method(D_METHOD("set_volume", "p_volume"), &Derived::set_volume); ClassDB::bind_method(D_METHOD("_emit_callbacks", "dict", "type"), &Derived::_emit_callbacks); diff --git a/src/nodes/fmod_listener.h b/src/nodes/fmod_listener.h index 133a2a7c..2b41c789 100644 --- a/src/nodes/fmod_listener.h +++ b/src/nodes/fmod_listener.h @@ -8,9 +8,12 @@ namespace godot { template class FmodListener : public NodeType { + + void ready(); + void exit_tree(); + public: - virtual void _ready() override; - virtual void _exit_tree() override; + void _notification(int p_what); void set_listener_index(const int index); int get_listener_index() const; @@ -38,7 +41,25 @@ namespace godot { }; template - void FmodListener::_ready() { + void FmodListener::_notification(int p_what) { +#ifdef TOOLS_ENABLED + // ensure we only run FMOD when the game is running! + if (Engine::get_singleton()->is_editor_hint()) { return; } +#endif + switch(p_what){ + case Node::NOTIFICATION_READY: + ready(); + break; + case Node::NOTIFICATION_EXIT_TREE: + exit_tree(); + break; + default: + break; + } + } + + template + void FmodListener::ready() { #ifdef TOOLS_ENABLED // ensure we only run FMOD when the game is running! if (Engine::get_singleton()->is_editor_hint()) { return; } @@ -51,7 +72,7 @@ namespace godot { } template - void FmodListener::_exit_tree() { + void FmodListener::exit_tree() { #ifdef TOOLS_ENABLED // ensure we only run FMOD when the game is running! if (Engine::get_singleton()->is_editor_hint()) { return; }