From 7f89659110c3edfcf60c9cbbc34b26a3425bc7cf Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Sun, 21 Apr 2024 13:04:16 +0200 Subject: [PATCH] Support multiple debugger sessions --- editor/debugger/limbo_debugger_plugin.cpp | 52 ++++++++++++----------- editor/debugger/limbo_debugger_plugin.h | 14 +++--- editor/limbo_ai_editor_plugin.cpp | 6 +-- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/editor/debugger/limbo_debugger_plugin.cpp b/editor/debugger/limbo_debugger_plugin.cpp index 9d75e70..762b78b 100644 --- a/editor/debugger/limbo_debugger_plugin.cpp +++ b/editor/debugger/limbo_debugger_plugin.cpp @@ -315,40 +315,41 @@ void LimboDebuggerPlugin::_window_visibility_changed(bool p_visible) { } #ifdef LIMBOAI_MODULE -void LimboDebuggerPlugin::setup_session(int p_idx) { +void LimboDebuggerPlugin::setup_session(int p_session_id) { #elif LIMBOAI_GDEXTENSION -void LimboDebuggerPlugin::_setup_session(int32_t p_idx) { +void LimboDebuggerPlugin::_setup_session(int32_t p_session_id) { #endif - Ref session = get_session(p_idx); + Ref session = get_session(p_session_id); + ERR_FAIL_COND(session.is_null()); - if (tab != nullptr) { - tab->queue_free(); - window_wrapper->queue_free(); - } + CompatWindowWrapper *session_window = memnew(CompatWindowWrapper); + session_window->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("LimboAI Debugger"))); + session_window->set_margins_enabled(true); - window_wrapper = memnew(CompatWindowWrapper); - window_wrapper->set_window_title(vformat(TTR("%s - Godot Engine"), TTR("LimboAI Debugger"))); - window_wrapper->set_margins_enabled(true); - - tab = memnew(LimboDebuggerTab()); - tab->setup(session, window_wrapper); + LimboDebuggerTab *tab = memnew(LimboDebuggerTab()); + tab->setup(session, session_window); tab->set_name("LimboAI"); - window_wrapper->set_wrapped_control(tab); - window_wrapper->set_name("LimboAI"); + session_window->set_wrapped_control(tab); + session_window->set_name("LimboAI"); - window_wrapper->set_v_size_flags(Control::SIZE_EXPAND_FILL); - window_wrapper->connect(LW_NAME(window_visibility_changed), callable_mp(this, &LimboDebuggerPlugin::_window_visibility_changed)); + session_window->set_v_size_flags(Control::SIZE_EXPAND_FILL); + session_window->connect(LW_NAME(window_visibility_changed), callable_mp(this, &LimboDebuggerPlugin::_window_visibility_changed)); session->connect(LW_NAME(started), callable_mp(tab, &LimboDebuggerTab::start_session)); session->connect(LW_NAME(stopped), callable_mp(tab, &LimboDebuggerTab::stop_session)); - session->add_session_tab(window_wrapper); + session->add_session_tab(session_window); + + session_windows[p_session_id] = session_window; } #ifdef LIMBOAI_MODULE -bool LimboDebuggerPlugin::capture(const String &p_message, const Array &p_data, int p_session) { +bool LimboDebuggerPlugin::capture(const String &p_message, const Array &p_data, int p_session_id) { #elif LIMBOAI_GDEXTENSION -bool LimboDebuggerPlugin::_capture(const String &p_message, const Array &p_data, int32_t p_session) { +bool LimboDebuggerPlugin::_capture(const String &p_message, const Array &p_data, int32_t p_session_id) { #endif + ERR_FAIL_COND_V(!session_windows.has(p_session_id), false); + LimboDebuggerTab *tab = Object::cast_to(session_windows[p_session_id]->get_wrapped_control()); + ERR_FAIL_NULL_V(tab, false); bool captured = true; if (p_message == "limboai:active_bt_players") { tab->update_active_bt_players(p_data); @@ -371,22 +372,23 @@ bool LimboDebuggerPlugin::_has_capture(const String &p_capture) const { return p_capture == "limboai"; } -CompatWindowWrapper *LimboDebuggerPlugin::get_session_tab() const { - return window_wrapper; +CompatWindowWrapper *LimboDebuggerPlugin::get_first_session_window() const { + ERR_FAIL_COND_V(session_windows.is_empty(), nullptr); + return session_windows.begin()->value; } -int LimboDebuggerPlugin::get_session_tab_index() const { +int LimboDebuggerPlugin::get_first_session_tab_index() const { + ERR_FAIL_COND_V(session_windows.is_empty(), -1); + CompatWindowWrapper *window_wrapper = session_windows.begin()->value; TabContainer *c = Object::cast_to(window_wrapper->get_parent()); ERR_FAIL_COND_V(c == nullptr, -1); return c->get_tab_idx_from_control(window_wrapper); } void LimboDebuggerPlugin::_bind_methods() { - ClassDB::bind_method(D_METHOD("_window_visibility_changed"), &LimboDebuggerPlugin::_window_visibility_changed); } LimboDebuggerPlugin::LimboDebuggerPlugin() { - tab = nullptr; singleton = this; } diff --git a/editor/debugger/limbo_debugger_plugin.h b/editor/debugger/limbo_debugger_plugin.h index cfda769..ca48099 100644 --- a/editor/debugger/limbo_debugger_plugin.h +++ b/editor/debugger/limbo_debugger_plugin.h @@ -99,9 +99,7 @@ class LimboDebuggerPlugin : public EditorDebuggerPlugin { private: static LimboDebuggerPlugin *singleton; - LimboDebuggerTab *tab = nullptr; - - CompatWindowWrapper *window_wrapper = nullptr; + HashMap session_windows; void _window_visibility_changed(bool p_visible); @@ -112,17 +110,17 @@ public: static _FORCE_INLINE_ LimboDebuggerPlugin *get_singleton() { return singleton; } #ifdef LIMBOAI_MODULE - void setup_session(int p_idx) override; + void setup_session(int p_session_id) override; bool has_capture(const String &p_capture) const override; - bool capture(const String &p_message, const Array &p_data, int p_session) override; + bool capture(const String &p_message, const Array &p_data, int p_session_id) override; #elif LIMBOAI_GDEXTENSION void _setup_session(int32_t p_idx) override; bool _has_capture(const String &p_capture) const override; - bool _capture(const String &p_message, const Array &p_data, int32_t p_session) override; + bool _capture(const String &p_message, const Array &p_data, int32_t p_session_id) override; #endif - CompatWindowWrapper *get_session_tab() const; - int get_session_tab_index() const; + CompatWindowWrapper *get_first_session_window() const; + int get_first_session_tab_index() const; LimboDebuggerPlugin(); ~LimboDebuggerPlugin(); diff --git a/editor/limbo_ai_editor_plugin.cpp b/editor/limbo_ai_editor_plugin.cpp index 99ef897..82df889 100644 --- a/editor/limbo_ai_editor_plugin.cpp +++ b/editor/limbo_ai_editor_plugin.cpp @@ -678,13 +678,13 @@ void LimboAIEditor::_misc_option_selected(int p_id) { } break; case MISC_OPEN_DEBUGGER: { ERR_FAIL_COND(LimboDebuggerPlugin::get_singleton() == nullptr); - if (LimboDebuggerPlugin::get_singleton()->get_session_tab()->get_window_enabled()) { - LimboDebuggerPlugin::get_singleton()->get_session_tab()->set_window_enabled(true); + if (LimboDebuggerPlugin::get_singleton()->get_first_session_window()->get_window_enabled()) { + LimboDebuggerPlugin::get_singleton()->get_first_session_window()->set_window_enabled(true); } else { #ifdef LIMBOAI_MODULE EditorNode::get_singleton()->make_bottom_panel_item_visible(EditorDebuggerNode::get_singleton()); EditorDebuggerNode::get_singleton()->get_default_debugger()->switch_to_debugger( - LimboDebuggerPlugin::get_singleton()->get_session_tab_index()); + LimboDebuggerPlugin::get_singleton()->get_first_session_tab_index()); #elif LIMBOAI_GDEXTENSION // TODO: Unsure how to switch to debugger pane with GDExtension. #endif