Skip to content

Commit

Permalink
GH-383 Split out Orchestration contract and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Jun 8, 2024
1 parent 54d990b commit b0d2b27
Show file tree
Hide file tree
Showing 125 changed files with 4,613 additions and 4,059 deletions.
97 changes: 21 additions & 76 deletions src/api/extension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,21 @@
//
#include "extension_interface.h"

#include "common/logger.h"
#include "common/version.h"
#include "editor/register_editor_types.h"
#include "script/register_script_types.h"

#include <gdextension_interface.h>
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/resource_saver.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

// Godot helpers
#include "common/logger.h"
#include "common/version.h"

// Plugin bits
#include "plugin/plugin.h"
#include "plugin/settings.h"

// Script bits
#include "script/nodes/script_nodes.h"
#include "script/resource/format_loader.h"
#include "script/resource/format_saver.h"
#include "script/script.h"

// Editor bits
#include "editor/editor.h"

#include "extension_db.h"

using namespace godot;

namespace orchestrator
{
OScriptLanguage* script_language_extension = nullptr;
OrchestratorSettings* settings = nullptr;
Ref<OScriptResourceLoader> loader;
Ref<OScriptResourceSaver> saver;
Logger* logger = nullptr;
ExtensionDB* extension_db = nullptr;

void initialize_extension_module(ModuleInitializationLevel p_level)
{
Expand All @@ -65,78 +44,44 @@ namespace orchestrator
internal::gdextension_interface_get_godot_version(&godot_version);
Logger::info("Using ", godot_version.string);

extension_db = new ExtensionDB();

internal::ExtensionDBLoader db_loader;
db_loader.prime();
register_extension_db();
}

if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS)
{
ORCHESTRATOR_REGISTER_INTERNAL_CLASS(OrchestratorSettings)

register_script_classes();
script_language_extension = memnew(OScriptLanguage);
register_script_types();
}
if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
{
settings = memnew(OrchestratorSettings);

// Adjust logger level based on project settings
const String level = settings->get_setting("settings/log_level");
Logger::set_level(Logger::get_level_from_name(level));

Engine::get_singleton()->register_script_language(script_language_extension);

loader.instantiate();
ResourceLoader::get_singleton()->add_resource_format_loader(loader);

saver.instantiate();
ResourceSaver::get_singleton()->add_resource_format_saver(saver);

register_script_node_classes();
register_script_extension();
register_script_resource_formats();
register_script_node_types();
}
if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR)
{
register_editor_classes();
register_plugin_classes();

EditorPlugins::add_by_type<OrchestratorPlugin>();
register_editor_types();
}
}

void uninitialize_extension_module(ModuleInitializationLevel p_level)
{
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS)
if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR)
{
if (script_language_extension)
memdelete(script_language_extension);

if (loader.is_valid())
{
ResourceLoader::get_singleton()->remove_resource_format_loader(loader);
loader.unref();
}

if (saver.is_valid())
{
ResourceSaver::get_singleton()->remove_resource_format_saver(saver);
saver.unref();
}
unregister_editor_types();
}

if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE)
{
if (settings)
memdelete(settings);

if (script_language_extension)
Engine::get_singleton()->unregister_script_language(script_language_extension);
unregister_script_node_types();
unregister_script_extension();
}
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS)
{
unregister_script_resource_formats();
unregister_script_types();
}

if (p_level == MODULE_INITIALIZATION_LEVEL_CORE)
{
delete(extension_db);
unregister_extension_db();

Logger::info("Shutting down " VERSION_FULL_NAME);
delete(logger);
Expand Down
2 changes: 1 addition & 1 deletion src/common/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
#include "common/file_utils.h"

#include "plugin/plugin.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/editor_paths.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/common/scene_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
#include "scene_utils.h"

#include "plugin/plugin.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/engine.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/settings.cpp → src/common/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "settings.h"
#include "common/settings.h"

#include "common/dictionary_utils.h"
#include "common/logger.h"
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions src/editor/about_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "about_dialog.h"

#include "authors.gen.h"
#include "common/version.h"
#include "donors.gen.h"
#include "editor/plugins/orchestrator_editor_plugin.h"
#include "license.gen.h"
#include "about_dialog.h"
#include "common/version.h"
#include "plugin/plugin.h"

#include <godot_cpp/classes/display_server.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
Expand Down
7 changes: 3 additions & 4 deletions src/editor/component_panels/component_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
#include "common/callable_lambda.h"
#include "common/name_utils.h"
#include "common/scene_utils.h"
#include "plugin/plugin.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/accept_dialog.hpp>
#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/confirmation_dialog.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/input_event_mouse_button.hpp>
#include <godot_cpp/classes/label.hpp>
Expand Down Expand Up @@ -339,9 +338,9 @@ void OrchestratorScriptComponentPanel::_bind_methods()
ADD_SIGNAL(MethodInfo("scroll_to_item", PropertyInfo(Variant::OBJECT, "item")));
}

OrchestratorScriptComponentPanel::OrchestratorScriptComponentPanel(const String& p_title, const Ref<OScript>& p_script)
OrchestratorScriptComponentPanel::OrchestratorScriptComponentPanel(const String& p_title, Orchestration* p_orchestration)
: _title(p_title)
, _script(p_script)
, _orchestration(p_orchestration)
{
set_v_size_flags(SIZE_SHRINK_BEGIN);
set_h_size_flags(SIZE_EXPAND_FILL);
Expand Down
6 changes: 3 additions & 3 deletions src/editor/component_panels/component_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OrchestratorScriptComponentPanel : public VBoxContainer

protected:
String _title; //! Title
Ref<OScript> _script; //! The script
Orchestration* _orchestration; //! The owning orchestration
PanelContainer* _panel{ nullptr }; //! Panel container
HBoxContainer* _panel_hbox{ nullptr }; //! Panel HBox container
Tree* _tree{ nullptr }; //! The tree list
Expand Down Expand Up @@ -185,8 +185,8 @@ class OrchestratorScriptComponentPanel : public VBoxContainer

/// Constructs a component panel
/// @param p_title the panel title
/// @param p_script the script
OrchestratorScriptComponentPanel(const String& p_title, const Ref<OScript>& p_script);
/// @param p_orchestration the owning orchestration
OrchestratorScriptComponentPanel(const String& p_title, Orchestration* p_orchestration);
};

#endif // ORCHESTRATOR_SCRIPT_COMPONENT_PANEL_H
45 changes: 30 additions & 15 deletions src/editor/component_panels/functions_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#include "editor/component_panels/functions_panel.h"

#include "common/callable_lambda.h"
#include "common/dictionary_utils.h"
#include "common/scene_utils.h"
#include "editor/plugins/orchestrator_editor_plugin.h"
#include "editor/script_connections.h"
#include "editor/script_view.h"
#include "plugin/plugin.h"
#include "script/script.h"

#include <godot_cpp/classes/button.hpp>
#include <godot_cpp/classes/editor_interface.hpp>
#include <godot_cpp/classes/h_box_container.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/tree.hpp>
Expand All @@ -34,13 +34,13 @@ void OrchestratorScriptFunctionsComponentPanel::_show_function_graph(TreeItem* p
// Function name and graph names are synonymous
const String function_name = p_item->get_text(0);
emit_signal("show_graph_requested", function_name);
emit_signal("focus_node_requested", function_name, _script->get_function_node_id(function_name));
emit_signal("focus_node_requested", function_name, _orchestration->get_function_node_id(function_name));
_tree->deselect_all();
}

PackedStringArray OrchestratorScriptFunctionsComponentPanel::_get_existing_names() const
{
return _script->get_function_names();
return _orchestration->get_function_names();
}

String OrchestratorScriptFunctionsComponentPanel::_get_tooltip_text() const
Expand Down Expand Up @@ -93,7 +93,7 @@ void OrchestratorScriptFunctionsComponentPanel::_handle_item_selected()
const TreeItem* item = _tree->get_selected();
if (item)
{
const Ref<OScriptFunction> function = _script->find_function(StringName(item->get_text(0)));
const Ref<OScriptFunction> function = _orchestration->find_function(StringName(item->get_text(0)));
if (function.is_valid())
{
const Ref<OScriptNode> node = function->get_owning_node();
Expand All @@ -116,7 +116,7 @@ bool OrchestratorScriptFunctionsComponentPanel::_handle_item_renamed(const Strin
return false;
}

_script->rename_function(p_old_name, p_new_name);
_orchestration->rename_function(p_old_name, p_new_name);
emit_signal("graph_renamed", p_old_name, p_new_name);
return true;
}
Expand All @@ -127,13 +127,17 @@ void OrchestratorScriptFunctionsComponentPanel::_handle_remove(TreeItem* p_item)
const String function_name = p_item->get_text(0);
emit_signal("close_graph_requested", function_name);

_script->remove_function(function_name);
_orchestration->remove_function(function_name);
}

void OrchestratorScriptFunctionsComponentPanel::_handle_button_clicked(TreeItem* p_item, int p_column, int p_id,
int p_mouse_button)
{
const Vector<Node*> nodes = SceneUtils::find_all_nodes_for_script_in_edited_scene(_script);
if (_orchestration->get_type() != OrchestrationType::OT_Script)
return;

const Ref<OScript> script = _orchestration->get_self();
const Vector<Node*> nodes = SceneUtils::find_all_nodes_for_script_in_edited_scene(script);

OrchestratorScriptConnectionsDialog* dialog = memnew(OrchestratorScriptConnectionsDialog);
add_child(dialog);
Expand All @@ -147,8 +151,12 @@ Dictionary OrchestratorScriptFunctionsComponentPanel::_handle_drag_data(const Ve
TreeItem* selected = _tree->get_selected();
if (selected)
{
data["type"] = "function";
data["functions"] = Array::make(selected->get_text(0));
Ref<OScriptFunction> function = _orchestration->find_function(StringName(selected->get_text(0)));
if (function.is_valid())
{
data["type"] = "function";
data["functions"] = DictionaryUtils::from_method(function->get_method_info());
}
}
return data;
}
Expand All @@ -157,10 +165,17 @@ void OrchestratorScriptFunctionsComponentPanel::update()
{
_clear_tree();

const Vector<Node*> script_nodes = SceneUtils::find_all_nodes_for_script_in_edited_scene(_script);
const String base_type = _script->get_instance_base_type();
Vector<Node*> script_nodes;
String base_type;

if (_orchestration->get_type() == OrchestrationType::OT_Script)
{
const Ref<OScript> script = _orchestration->get_self();
script_nodes = SceneUtils::find_all_nodes_for_script_in_edited_scene(script);
base_type = script->get_instance_base_type();
}

for (const Ref<OScriptGraph>& graph : _script->get_graphs())
for (const Ref<OScriptGraph>& graph : _orchestration->get_graphs())
{
if (!(graph->get_flags().has_flag(OScriptGraph::GraphFlags::GF_FUNCTION)))
continue;
Expand Down Expand Up @@ -213,7 +228,7 @@ void OrchestratorScriptFunctionsComponentPanel::_bind_methods()
ADD_SIGNAL(MethodInfo("override_function_requested"));
}

OrchestratorScriptFunctionsComponentPanel::OrchestratorScriptFunctionsComponentPanel(const Ref<OScript>& p_script, OrchestratorScriptView* p_view)
: OrchestratorScriptComponentPanel("Functions", p_script), _view(p_view)
OrchestratorScriptFunctionsComponentPanel::OrchestratorScriptFunctionsComponentPanel(Orchestration* p_orchestration, OrchestratorScriptView* p_view)
: OrchestratorScriptComponentPanel("Functions", p_orchestration), _view(p_view)
{
}
4 changes: 2 additions & 2 deletions src/editor/component_panels/functions_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class OrchestratorScriptFunctionsComponentPanel : public OrchestratorScriptCompo
void _notification(int p_what);

/// Construct the function component panel
/// @param p_script the script
explicit OrchestratorScriptFunctionsComponentPanel(const Ref<OScript>& p_script, OrchestratorScriptView* p_view);
/// @param p_orchestration the orchestration
explicit OrchestratorScriptFunctionsComponentPanel(Orchestration* p_orchestration, OrchestratorScriptView* p_view);
};

#endif // ORCHESTRATOR_SCRIPT_FUNCTIONS_COMPONENT_PANEL_H
Loading

0 comments on commit b0d2b27

Please sign in to comment.