Skip to content

Commit

Permalink
Fix lifecycle callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
CedNaru committed Feb 13, 2024
1 parent 228094f commit 79feb8e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
1 change: 1 addition & 0 deletions demo/low_level_2D/Emitter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

49 changes: 31 additions & 18 deletions src/nodes/fmod_event_emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ namespace godot {

List<Parameter> _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;
Expand Down Expand Up @@ -110,7 +111,7 @@ namespace godot {
}

template<class Derived, class NodeType>
void FmodEventEmitter<Derived, NodeType>::_ready() {
void FmodEventEmitter<Derived, NodeType>::ready() {
#ifdef TOOLS_ENABLED
// ensure we only run FMOD when the game is running!
if (Engine::get_singleton()->is_editor_hint()) { return; }
Expand All @@ -134,7 +135,7 @@ namespace godot {
}

template<class Derived, class NodeType>
void FmodEventEmitter<Derived, NodeType>::_process(double delta) {
void FmodEventEmitter<Derived, NodeType>::process() {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) { return; }
#endif
Expand All @@ -158,26 +159,39 @@ namespace godot {
}

template<class Derived, class NodeType>
void FmodEventEmitter<Derived, NodeType>::_notification(int p_what) {
void FmodEventEmitter<Derived, NodeType>::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<class Derived, class NodeType>
void FmodEventEmitter<Derived, NodeType>::_exit_tree() {
void FmodEventEmitter<Derived, NodeType>::_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<class Derived, class NodeType>
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 25 additions & 4 deletions src/nodes/fmod_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
namespace godot {
template<class Derived, class NodeType>
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;
Expand Down Expand Up @@ -38,7 +41,25 @@ namespace godot {
};

template<class Derived, class NodeType>
void FmodListener<Derived, NodeType>::_ready() {
void FmodListener<Derived, NodeType>::_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<class Derived, class NodeType>
void FmodListener<Derived, NodeType>::ready() {
#ifdef TOOLS_ENABLED
// ensure we only run FMOD when the game is running!
if (Engine::get_singleton()->is_editor_hint()) { return; }
Expand All @@ -51,7 +72,7 @@ namespace godot {
}

template<class Derived, class NodeType>
void FmodListener<Derived, NodeType>::_exit_tree() {
void FmodListener<Derived, NodeType>::exit_tree() {
#ifdef TOOLS_ENABLED
// ensure we only run FMOD when the game is running!
if (Engine::get_singleton()->is_editor_hint()) { return; }
Expand Down

0 comments on commit 79feb8e

Please sign in to comment.