diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml index 873a5594..25f58ea4 100644 --- a/.github/workflows/linux_builds.yml +++ b/.github/workflows/linux_builds.yml @@ -9,16 +9,23 @@ on: # Global Settings env: - GODOT_BASE_BRANCH: master - SCONSFLAGS: platform=linuxbsd verbose=yes warnings=extra werror=yes debug_symbols=no --jobs=2 module_text_server_fb_enabled=yes + GODOT_REF: 7e79aead99a53ee7cdf383add9a6a2aea4f15beb + SCONSFLAGS: platform=linuxbsd verbose=yes warnings=extra werror=yes debug_symbols=no module_text_server_fb_enabled=yes SCONS_CACHE_LIMIT: 4096 jobs: linux-editor: runs-on: "ubuntu-20.04" - name: Editor (target=release_debug, tools=yes, tests=yes) + name: Editor (target=editor, tools=yes, tests=yes) steps: + - name: Wait for static checks + uses: lewagon/wait-on-check-action@v1.3.1 + with: + ref: ${{ github.ref }} + check-name: 'Static Checks (clang-format, black format, file format, documentation checks)' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 - name: Make godot dir run: | mkdir godot @@ -33,10 +40,15 @@ jobs: - name: Clone godot for godex uses: actions/checkout@v2 with: - repository: GodotECS/godot - ref: refs/heads/godex_version + repository: godotengine/godot + ref: ${{ env.GODOT_REF }} path: godot + - name: Apply patch + run: | + cd godot + git apply ../modules/godex/patches/add_custom_iterator.patch --reject --ignore-space-change --ignore-whitespace + # Azure repositories are not reliable, we need to prevent azure giving us packages. - name: Make apt sources.list use the default Ubuntu repositories run: | @@ -56,11 +68,11 @@ jobs: uses: actions/cache@v2 with: path: ${{github.workspace}}/.scons_cache/ - key: ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}} + key: ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-{{env.GODOT_REF}}-${{github.ref}}-${{github.sha}} restore-keys: | - ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}} - ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}} - ${{github.job}}-${{env.GODOT_BASE_BRANCH}} + ${{github.job}}-{{env.GODOT_REF}}-${{github.ref}}-${{github.sha}} + ${{github.job}}-{{env.GODOT_REF}}-${{github.ref}} + ${{github.job}}-{{env.GODOT_REF}} # Use python 3.x release (works cross platform; best to keep self contained in it's own step) - name: Set up Python 3.x @@ -84,14 +96,14 @@ jobs: SCONS_CACHE: ${{github.workspace}}/.scons_cache/ run: | cd godot - scons tools=yes tests=yes target=release_debug custom_modules="../modules" -j2 + scons tools=yes tests=yes target=editor custom_modules="../modules" ls -l bin/ # Execute unit tests for the editor - name: Unit Tests run: | cd ./godot - ./bin/godot.linuxbsd.opt.tools.64 --test + ./bin/godot.linuxbsd.editor.x86_64 --test --headless cd ../ - uses: actions/upload-artifact@v2 diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 923c4940..b9e2b7c5 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -20,7 +20,7 @@ jobs: sudo apt-get install -qq dos2unix recode clang-format-11 sudo update-alternatives --remove-all clang-format sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-11 100 - sudo pip3 install black==20.8b1 pygments + sudo pip3 install black==22.3.0 pygments - name: File formatting checks (file_format.sh) run: | bash ./misc/scripts/file_format.sh diff --git a/.github/workflows/windows_builds.yml b/.github/workflows/windows_builds.yml index c2571948..f7538c73 100644 --- a/.github/workflows/windows_builds.yml +++ b/.github/workflows/windows_builds.yml @@ -10,8 +10,8 @@ on: # Global Settings # SCONS_CACHE for windows must be set in the build environment env: - GODOT_BASE_BRANCH: master - SCONSFLAGS: platform=windows verbose=yes warnings=all werror=yes debug_symbols=no --jobs=2 module_text_server_fb_enabled=yes + GODOT_REF: 7e79aead99a53ee7cdf383add9a6a2aea4f15beb + SCONSFLAGS: platform=windows verbose=yes warnings=all werror=yes debug_symbols=no module_text_server_fb_enabled=yes SCONS_CACHE_MSVC_CONFIG: true SCONS_CACHE_LIMIT: 3072 @@ -19,9 +19,16 @@ jobs: windows-editor: # Windows 10 with latest image runs-on: "windows-latest" - name: Editor (target=release_debug, tools=yes, tests=yes) + name: Editor (target=editor, tools=yes, tests=yes) steps: + - name: Wait for static checks + uses: lewagon/wait-on-check-action@v1.3.1 + with: + ref: ${{ github.ref }} + check-name: 'Static Checks (clang-format, black format, file format, documentation checks)' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 - name: Make dir run: | mkdir godot @@ -36,10 +43,15 @@ jobs: - name: Clone godot for godex uses: actions/checkout@v2 with: - repository: GodotECS/godot - ref: refs/heads/godex_version + repository: godotengine/godot + ref: ${{ env.GODOT_REF }} path: godot + - name: Apply patch + run: | + cd godot + git apply ../modules/godex/patches/add_custom_iterator.patch --reject --ignore-space-change --ignore-whitespace + # Upload cache on completion and check it out now # Editing this is pretty dangerous for Windows since it can break and needs to be properly tested with a fresh cache. - name: Load .scons_cache directory @@ -49,9 +61,9 @@ jobs: path: ${{github.workspace}}/.scons_cache/ key: ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}} restore-keys: | - ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}} - ${{github.job}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}} - ${{github.job}}-${{env.GODOT_BASE_BRANCH}} + ${{github.job}}-${{env.GODOT_REF}}-${{github.ref}}-${{github.sha}} + ${{github.job}}-${{env.GODOT_REF}}-${{github.ref}} + ${{github.job}}-${{env.GODOT_REF}} # Use python 3.x release (works cross platform; best to keep self contained in it's own step) - name: Set up Python 3.x @@ -76,14 +88,14 @@ jobs: SCONS_CACHE: ${{github.workspace}}/.scons_cache/ run: | cd godot - scons tools=yes tests=yes target=release_debug custom_modules="../modules" + scons tools=yes tests=yes target=editor custom_modules="../modules" ls -l bin/ # Execute unit tests for the editor - name: Unit Tests run: | cd ./godot - ./bin/godot.windows.opt.tools.64.exe --test + ./bin/godot.windows.editor.x86_64.exe --test cd ../ - uses: actions/upload-artifact@v2 diff --git a/README.md b/README.md index 565fc4c4..56871b47 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Godex is a Godot Engine ecs library. **Disclaimer:** this module is still in development, open an [issues](https://github.com/GodotECS/godex/issues) to report any problem or a new [discussion](https://github.com/GodotECS/godex/discussions) if you need any help. Any form of contribution is welcome. ### The tested Godot version -Is `master` `35cfaafda8073f700c9d2fe42a43d3d81eaaea67`, please open an issue if the current master is not working or doesn't compile. +Is `master` `7e79aead99a53ee7cdf383add9a6a2aea4f15beb`, please open an issue if the current master is not working or doesn't compile. ### What is ECS Shortened as ECS, the Entity Component System is an architectural design pattern that allow to organize the data in a way so that the workload can be split into small and easy programs. diff --git a/SCsub b/SCsub index 97b6641c..4bf7e88a 100644 --- a/SCsub +++ b/SCsub @@ -6,7 +6,7 @@ Import("env") Import("env_modules") env_ecs = env_modules.Clone() -if env_ecs["float"] == "64": +if env_ecs["precision"] == "double": env_ecs.Append(CPPDEFINES=["BT_USE_DOUBLE_PRECISION=1"]) methods_ecs.generate_system_structs() diff --git a/ecs.cpp b/ecs.cpp index 9c75da92..d3d19b6f 100644 --- a/ecs.cpp +++ b/ecs.cpp @@ -1,5 +1,8 @@ #include "ecs.h" +#include +#include +#include #include "components/dynamic_component.h" #include "core/object/message_queue.h" @@ -159,6 +162,43 @@ ECS::ECS() : } } +void get_script_files(const String &p_path, Vector &scripts) { + for (const auto &directory : DirAccess::get_directories_at(p_path)) { + get_script_files(p_path.path_join(directory), scripts); + } + for (const auto &file : DirAccess::get_files_at(p_path)) { + auto file_path = p_path.path_join(file); + if (ResourceLoader::get_resource_type(file_path) == "GDScript") { + scripts.push_back(file_path); + } + } +} + +void ECS::preload_scripts() { + if (Engine::get_singleton()->is_project_manager_hint()) { + return; + } + + Vector scripts; + print_line("Preloading component and system scripts"); + get_script_files("res://", scripts); + + for (const auto &script : scripts) { + auto code = FileAccess::get_file_as_string(script); + GDScriptParser parser; + if (parser.parse(code, script, false) == OK) { + auto tree = parser.get_tree(); + if (tree->extends.has("System")) { + register_dynamic_system(script.get_file()); + } + + if (tree->extends.has("Component")) { + register_or_get_id_for_component_name(script.get_file()); + } + } + } +} + ECS::~ECS() { } @@ -1041,11 +1081,7 @@ const LocalVector &ECS::get_spawnable_components(godex::spa return spawners_info[p_spawner].components; } -uint32_t ECS::register_or_update_script_component( - const StringName &p_name, - const LocalVector &p_properties, - StorageType p_storage_type, - Vector p_spawners) { +uint32_t ECS::register_or_get_id_for_component_name(const StringName &p_name) { godex::component_id id = get_component_id(p_name); DynamicComponentInfo *info; @@ -1058,18 +1094,38 @@ uint32_t ECS::register_or_update_script_component( components.push_back(p_name); components_info.push_back(ComponentInfo()); components_info[id].dynamic_component_info = info; - } else { - // This is an old component, verify is a script component. - ERR_FAIL_COND_V_MSG(components_info[id].dynamic_component_info == nullptr, godex::COMPONENT_NONE, "This component " + p_name + " is not a script component and can't be updated. Your component must be an unique name."); - info = components_info[id].dynamic_component_info; + + // Add a new scripting constant, for fast and easy `component` access. + ClassDB::bind_integer_constant(get_class_static(), StringName(), String(p_name).replace(".", "_"), id); + print_line("ComponentScript: " + p_name + " registered with ID: " + itos(id)); } + return id; +} + +uint32_t ECS::register_or_update_script_component( + const StringName &p_name, + const LocalVector &p_properties, + StorageType p_storage_type, + Vector p_spawners) { + godex::component_id id = register_or_get_id_for_component_name(p_name); + DynamicComponentInfo *info; + ERR_FAIL_COND_V_MSG(components_info[id].dynamic_component_info == nullptr, godex::COMPONENT_NONE, "This component " + p_name + " is not a script component and can't be updated. Your component must be an unique name."); + info = components_info[id].dynamic_component_info; + info->property_map.resize(p_properties.size()); info->properties.resize(p_properties.size()); info->defaults.resize(p_properties.size()); // Validate and initialize the parameters. for (uint32_t i = 0; i < p_properties.size(); i += 1) { + if ( + // Filter GDScript file name + p_properties[i].property.name == p_name + // Filter C# file name. It uses only the class name + || p_properties[i].property.name + ".cs" == p_name) { + continue; + } // Is type supported? switch (p_properties[i].property.type) { case Variant::NIL: @@ -1078,7 +1134,7 @@ uint32_t ECS::register_or_update_script_component( case Variant::SIGNAL: case Variant::CALLABLE: // TODO what about dictionary and arrays? - ERR_PRINT("The script component " + p_name + " is using a pointer variable. This is unsafe, so not supported. Please use a databag."); + ERR_PRINT("The property " + p_properties[i].property.name + " of script component " + p_name + " is using a pointer variable. This is unsafe, so not supported. Please use a databag."); return UINT32_MAX; default: // Valid! @@ -1108,10 +1164,6 @@ uint32_t ECS::register_or_update_script_component( spawners_info[spawner].components.push_back(info->component_id); } - // Add a new scripting constant, for fast and easy `component` access. - ClassDB::bind_integer_constant(get_class_static(), StringName(), String(p_name).replace(".", "_"), id); - print_line("ComponentScript: " + p_name + " registered with ID: " + itos(id)); - return id; } diff --git a/ecs.h b/ecs.h index 505f70c2..73922f9f 100644 --- a/ecs.h +++ b/ecs.h @@ -224,6 +224,7 @@ class ECS : public Object { template static void register_component(StorageBase *(*create_storage)()); + static uint32_t register_or_get_id_for_component_name(const StringName &p_name); static uint32_t register_or_update_script_component(const StringName &p_name, const LocalVector &p_properties, StorageType p_storage_type, Vector p_spawners); static uint32_t get_components_count(); @@ -488,6 +489,8 @@ class ECS : public Object { /// time, making the pipeline switch immediate. static void system_set_active_system(godex::system_id p_id, uint8_t *p_mem, bool p_active); + static void preload_scripts(); + private: static void clear_emitters_for_system(godex::system_id p_id); diff --git a/iterators/dynamic_query.cpp b/iterators/dynamic_query.cpp index ea9d3668..f697a2bf 100644 --- a/iterators/dynamic_query.cpp +++ b/iterators/dynamic_query.cpp @@ -13,7 +13,7 @@ void DynamicQuery::_bind_methods() { ClassDB::bind_method(D_METHOD("not_component", "component_id"), &DynamicQuery::not_component); ClassDB::bind_method(D_METHOD("is_valid"), &DynamicQuery::is_valid); - ClassDB::bind_method(D_METHOD("prepare_world"), &DynamicQuery::prepare_world_script); + ClassDB::bind_method(D_METHOD("prepare_world", "world"), &DynamicQuery::prepare_world_script); ClassDB::bind_method(D_METHOD("reset"), &DynamicQuery::reset); ClassDB::bind_method(D_METHOD("get_component", "index"), &DynamicQuery::get_access_by_index_gd); diff --git a/modules/bullet_physics/SCsub b/modules/bullet_physics/SCsub index 813129c2..935abe2d 100644 --- a/modules/bullet_physics/SCsub +++ b/modules/bullet_physics/SCsub @@ -2,12 +2,15 @@ Import("env") Import("env_modules") +import methods env_bullet = env_modules.Clone() thirdparty_obj = [] env.Append(builtin_bullet=True) +if methods.using_clang(env_bullet) or methods.using_emcc(env_bullet): + env_bullet.Append(CXXFLAGS=["-frelaxed-template-template-args"]) # Add bullet header, no need to compile Bullet third party, because it's # already done by the godot bullet module. @@ -208,7 +211,7 @@ if env["builtin_bullet"]: if env["target"] == "debug" or env["target"] == "release_debug": env_bullet.Append(CPPDEFINES=["DEBUG"]) - if env["float"] == "64": + if env["precision"] == "double": env_bullet.Append(CPPDEFINES=["BT_USE_DOUBLE_PRECISION"]) env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD"]) @@ -220,3 +223,6 @@ if env["builtin_bullet"]: # Bullet Physics ECS env_bullet.add_source_files(env.modules_sources, "*.cpp") + +if env_bullet.editor_build: + env_bullet.add_source_files(env.modules_sources, "editor/*.cpp") diff --git a/modules/bullet_physics/debug_utilities.cpp b/modules/bullet_physics/debug_utilities.cpp index 477755f3..cd8a0a76 100644 --- a/modules/bullet_physics/debug_utilities.cpp +++ b/modules/bullet_physics/debug_utilities.cpp @@ -65,9 +65,9 @@ Ref generate_mesh_from_points(const Vector &p_points) { Error err = QuickHull::build(varr, md); if (err == OK) { lines.resize(md.edges.size() * 2); - for (int i = 0; i < md.edges.size(); i++) { - lines.write[i * 2 + 0] = md.vertices[md.edges[i].a]; - lines.write[i * 2 + 1] = md.vertices[md.edges[i].b]; + for (uint32_t i = 0; i < md.edges.size(); i++) { + lines.write[i * 2 + 0] = md.vertices[md.edges[i].vertex_a]; + lines.write[i * 2 + 1] = md.vertices[md.edges[i].vertex_b]; } } } diff --git a/modules/bullet_physics/components_gizmos.cpp b/modules/bullet_physics/editor/components_gizmos.cpp similarity index 91% rename from modules/bullet_physics/components_gizmos.cpp rename to modules/bullet_physics/editor/components_gizmos.cpp index f9aad4e6..39d03bd0 100644 --- a/modules/bullet_physics/components_gizmos.cpp +++ b/modules/bullet_physics/editor/components_gizmos.cpp @@ -1,10 +1,10 @@ #include "components_gizmos.h" -#include "../godot/nodes/entity.h" -#include "debug_utilities.h" +#include "../debug_utilities.h" +#include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "editor/editor_undo_redo_manager.h" #include "editor/plugins/node_3d_editor_plugin.h" -#include "scene/3d/camera_3d.h" void BtBoxGizmo::init() { const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); @@ -18,7 +18,7 @@ void BtBoxGizmo::init() { } void BtBoxGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(box_component_name)) { @@ -55,7 +55,7 @@ void BtBoxGizmo::redraw(EditorNode3DGizmo *p_gizmo) { } int BtBoxGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, 0); if (entity->has_component(box_component_name)) { @@ -76,7 +76,7 @@ String BtBoxGizmo::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) } Variant BtBoxGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, Variant()); ERR_FAIL_COND_V(entity->has_component(box_component_name) == false, Variant()); @@ -86,7 +86,7 @@ Variant BtBoxGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx } void BtBoxGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(box_component_name) == false); @@ -118,7 +118,7 @@ void BtBoxGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3 } void BtBoxGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(box_component_name) == false); @@ -127,7 +127,7 @@ void BtBoxGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, cons if (p_cancel) { entity->set_component_value(box_component_name, half_extents_name, p_restore); } else { - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change Shape Box Half Extent")); ur->add_do_method(entity, "set_component_value", box_component_name, half_extents_name, half_extents); Vector3 restore = half_extents; @@ -143,7 +143,7 @@ void BtSphereGizmo::init() { } void BtSphereGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(sphere_component_name)) { @@ -156,8 +156,8 @@ void BtSphereGizmo::redraw(EditorNode3DGizmo *p_gizmo) { Vector points; for (int i = 0; i <= 360; i++) { - float ra = Math::deg2rad((float)i); - float rb = Math::deg2rad((float)i + 1); + float ra = Math::deg_to_rad((float)i); + float rb = Math::deg_to_rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius; @@ -194,7 +194,7 @@ void BtSphereGizmo::redraw(EditorNode3DGizmo *p_gizmo) { } int BtSphereGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, 0); if (entity->has_component(sphere_component_name)) { @@ -209,7 +209,7 @@ String BtSphereGizmo::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id } Variant BtSphereGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, Variant()); ERR_FAIL_COND_V(entity->has_component(sphere_component_name) == false, Variant()); @@ -217,7 +217,7 @@ Variant BtSphereGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_ } void BtSphereGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(sphere_component_name) == false); @@ -244,7 +244,7 @@ void BtSphereGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Came } void BtSphereGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(sphere_component_name) == false); @@ -253,7 +253,7 @@ void BtSphereGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, c if (p_cancel) { entity->set_component_value(sphere_component_name, radius_name, p_restore); } else { - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change Shape Sphere Radius")); ur->add_do_method(entity, "set_component_value", sphere_component_name, radius_name, radius); ur->add_undo_method(entity, "set_component_value", sphere_component_name, radius_name, p_restore); @@ -267,7 +267,7 @@ void BtCapsuleGizmo::init() { } void BtCapsuleGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(capsule_component_name)) { @@ -282,8 +282,8 @@ void BtCapsuleGizmo::redraw(EditorNode3DGizmo *p_gizmo) { Vector3 d(0, height * 0.5, 0); for (int i = 0; i < 360; i++) { - float ra = Math::deg2rad((float)i); - float rb = Math::deg2rad((float)i + 1); + float ra = Math::deg_to_rad((float)i); + float rb = Math::deg_to_rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius; @@ -345,7 +345,7 @@ void BtCapsuleGizmo::redraw(EditorNode3DGizmo *p_gizmo) { } int BtCapsuleGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, 0); if (entity->has_component(capsule_component_name)) { @@ -364,7 +364,7 @@ String BtCapsuleGizmo::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_i } Variant BtCapsuleGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, Variant()); ERR_FAIL_COND_V(entity->has_component(capsule_component_name) == false, Variant()); @@ -376,7 +376,7 @@ Variant BtCapsuleGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p } void BtCapsuleGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(capsule_component_name) == false); @@ -414,7 +414,7 @@ void BtCapsuleGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Cam } void BtCapsuleGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(capsule_component_name) == false); @@ -423,7 +423,7 @@ void BtCapsuleGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, if (p_cancel) { entity->set_component_value(capsule_component_name, p_idx == 0 ? radius_name : height_name, p_restore); } else { - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change Shape Capsule Radius")); ur->add_do_method(entity, "set_component_value", capsule_component_name, p_idx == 0 ? radius_name : height_name, v); ur->add_undo_method(entity, "set_component_value", capsule_component_name, p_idx == 0 ? radius_name : height_name, p_restore); @@ -437,7 +437,7 @@ void BtConeGizmo::init() { } void BtConeGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(cone_component_name)) { @@ -452,8 +452,8 @@ void BtConeGizmo::redraw(EditorNode3DGizmo *p_gizmo) { Vector3 d(0, height * 0.5, 0); for (int i = 0; i < 360; i++) { - float ra = Math::deg2rad((float)i); - float rb = Math::deg2rad((float)i + 1); + float ra = Math::deg_to_rad((float)i); + float rb = Math::deg_to_rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius; @@ -495,7 +495,7 @@ void BtConeGizmo::redraw(EditorNode3DGizmo *p_gizmo) { } int BtConeGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, 0); if (entity->has_component(cone_component_name)) { @@ -514,7 +514,7 @@ String BtConeGizmo::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) } Variant BtConeGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, Variant()); ERR_FAIL_COND_V(entity->has_component(cone_component_name) == false, Variant()); @@ -526,7 +526,7 @@ Variant BtConeGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id } void BtConeGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(cone_component_name) == false); @@ -560,7 +560,7 @@ void BtConeGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera } void BtConeGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(cone_component_name) == false); @@ -569,7 +569,7 @@ void BtConeGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, con if (p_cancel) { entity->set_component_value(cone_component_name, p_idx == 0 ? radius_name : height_name, p_restore); } else { - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change Shape Cone Radius")); ur->add_do_method(entity, "set_component_value", cone_component_name, p_idx == 0 ? radius_name : height_name, v); ur->add_undo_method(entity, "set_component_value", cone_component_name, p_idx == 0 ? radius_name : height_name, p_restore); @@ -583,7 +583,7 @@ void BtCylinderGizmo::init() { } void BtCylinderGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(cylinder_component_name)) { @@ -598,8 +598,8 @@ void BtCylinderGizmo::redraw(EditorNode3DGizmo *p_gizmo) { Vector3 d(0, height * 0.5, 0); for (int i = 0; i < 360; i++) { - float ra = Math::deg2rad((float)i); - float rb = Math::deg2rad((float)i + 1); + float ra = Math::deg_to_rad((float)i); + float rb = Math::deg_to_rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius; @@ -659,7 +659,7 @@ void BtCylinderGizmo::redraw(EditorNode3DGizmo *p_gizmo) { } int BtCylinderGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, 0); if (entity->has_component(cylinder_component_name)) { @@ -678,7 +678,7 @@ String BtCylinderGizmo::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_ } Variant BtCylinderGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, Variant()); ERR_FAIL_COND_V(entity->has_component(cylinder_component_name) == false, Variant()); @@ -690,7 +690,7 @@ Variant BtCylinderGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int } void BtCylinderGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(cylinder_component_name) == false); @@ -723,7 +723,7 @@ void BtCylinderGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Ca } void BtCylinderGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(cylinder_component_name) == false); @@ -732,7 +732,7 @@ void BtCylinderGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, if (p_cancel) { entity->set_component_value(cylinder_component_name, p_idx == 0 ? radius_name : height_name, p_restore); } else { - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change Shape Capsule Radius")); ur->add_do_method(entity, "set_component_value", cylinder_component_name, p_idx == 0 ? radius_name : height_name, v); ur->add_undo_method(entity, "set_component_value", cylinder_component_name, p_idx == 0 ? radius_name : height_name, p_restore); @@ -752,7 +752,8 @@ void BtConvexGizmo::init() { } void BtConvexGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); +#ifdef TOOLS_ENABLED + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(convex_component_name)) { @@ -767,7 +768,6 @@ void BtConvexGizmo::redraw(EditorNode3DGizmo *p_gizmo) { mesh = td->mesh; } } - if (mesh.is_null()) { const Vector points = entity->get_component_value(convex_component_name, points_name); mesh = generate_mesh_from_points(points); @@ -778,6 +778,7 @@ void BtConvexGizmo::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_mesh(mesh, material); } +#endif } int BtConvexGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { @@ -804,7 +805,8 @@ void BtTrimeshGizmo::init() { } void BtTrimeshGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); +#ifdef TOOLS_ENABLED + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(trimesh_component_name)) { @@ -819,7 +821,6 @@ void BtTrimeshGizmo::redraw(EditorNode3DGizmo *p_gizmo) { mesh = td->mesh; } } - if (mesh.is_null()) { const Vector faces = entity->get_component_value(trimesh_component_name, faces_name); mesh = generate_mesh_from_faces(faces); @@ -830,6 +831,7 @@ void BtTrimeshGizmo::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_mesh(mesh, material); } +#endif } int BtTrimeshGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { @@ -859,7 +861,7 @@ void BtPawnGizmo::init() { } void BtPawnGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); if (entity->has_component(pawn_component_name)) { @@ -904,8 +906,8 @@ void BtPawnGizmo::redraw_capsule(EditorNode3DGizmo *p_gizmo, const Ref Vector3 d(0, p_height * 0.5, 0); for (int i = 0; i < 360; i++) { - float ra = Math::deg2rad((float)i); - float rb = Math::deg2rad((float)i + 1); + float ra = Math::deg_to_rad((float)i); + float rb = Math::deg_to_rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * p_radius; Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * p_radius; @@ -967,7 +969,7 @@ void BtPawnGizmo::redraw_capsule(EditorNode3DGizmo *p_gizmo, const Ref } int BtPawnGizmo::get_handle_count(const EditorNode3DGizmo *p_gizmo) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, 0); if (entity->has_component(pawn_component_name)) { @@ -990,7 +992,7 @@ String BtPawnGizmo::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) } Variant BtPawnGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND_V(entity == nullptr, Variant()); ERR_FAIL_COND_V(entity->has_component(pawn_component_name) == false, Variant()); @@ -1006,7 +1008,7 @@ Variant BtPawnGizmo::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id } void BtPawnGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(pawn_component_name) == false); @@ -1059,7 +1061,7 @@ void BtPawnGizmo::set_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, Camera } void BtPawnGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); ERR_FAIL_COND(entity == nullptr); ERR_FAIL_COND(entity->has_component(pawn_component_name) == false); @@ -1079,7 +1081,7 @@ void BtPawnGizmo::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_idx, con if (p_cancel) { entity->set_component_value(pawn_component_name, prop_name, p_restore); } else { - UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); ur->create_action(TTR("Change Shape Capsule Radius")); ur->add_do_method(entity, "set_component_value", pawn_component_name, prop_name, v); ur->add_undo_method(entity, "set_component_value", pawn_component_name, prop_name, p_restore); diff --git a/modules/bullet_physics/components_gizmos.h b/modules/bullet_physics/editor/components_gizmos.h similarity index 99% rename from modules/bullet_physics/components_gizmos.h rename to modules/bullet_physics/editor/components_gizmos.h index ae3038de..566548a4 100644 --- a/modules/bullet_physics/components_gizmos.h +++ b/modules/bullet_physics/editor/components_gizmos.h @@ -1,6 +1,6 @@ #pragma once -#include "../godot/editor_plugins/components_gizmo_3d.h" +#include "../../godot/editor_plugins/components_gizmo_3d.h" class BtBoxGizmo : public ComponentGizmo { StringName box_component_name = "BtBox"; diff --git a/modules/bullet_physics/register_types.cpp b/modules/bullet_physics/register_types.cpp index 9f8827a3..9ef59002 100644 --- a/modules/bullet_physics/register_types.cpp +++ b/modules/bullet_physics/register_types.cpp @@ -4,7 +4,9 @@ #include "../godot/editor_plugins/components_gizmo_3d.h" #include "components_area.h" #include "components_generic.h" -#include "components_gizmos.h" +#ifdef TOOLS_ENABLED +#include "editor/components_gizmos.h" +#endif #include "components_pawn.h" #include "components_rigid_body.h" #include "databag_space.h" @@ -153,6 +155,7 @@ void initialize_bullet_physics_module(ModuleInitializationLevel p_level) { .add("BtOverlapCheck"); } else if (p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { +#ifdef TOOLS_ENABLED // Register gizmos Components3DGizmoPlugin::get_singleton()->add_component_gizmo(memnew(BtBoxGizmo)); Components3DGizmoPlugin::get_singleton()->add_component_gizmo(memnew(BtSphereGizmo)); @@ -162,6 +165,7 @@ void initialize_bullet_physics_module(ModuleInitializationLevel p_level) { Components3DGizmoPlugin::get_singleton()->add_component_gizmo(memnew(BtConvexGizmo)); Components3DGizmoPlugin::get_singleton()->add_component_gizmo(memnew(BtTrimeshGizmo)); Components3DGizmoPlugin::get_singleton()->add_component_gizmo(memnew(BtPawnGizmo)); +#endif } } diff --git a/modules/godot/SCsub b/modules/godot/SCsub index 40165c6f..c9885e14 100644 --- a/modules/godot/SCsub +++ b/modules/godot/SCsub @@ -8,7 +8,9 @@ env_godot_module = env_modules.Clone() env_godot_module.add_source_files(env.modules_sources, "*.cpp") env_godot_module.add_source_files(env.modules_sources, "components/*.cpp") env_godot_module.add_source_files(env.modules_sources, "components/physics/*.cpp") -env_godot_module.add_source_files(env.modules_sources, "editor_plugins/*.cpp") env_godot_module.add_source_files(env.modules_sources, "nodes/*.cpp") env_godot_module.add_source_files(env.modules_sources, "databags/*.cpp") env_godot_module.add_source_files(env.modules_sources, "systems/*.cpp") + +if env_godot_module.editor_build: + env_godot_module.add_source_files(env.modules_sources, "editor_plugins/*.cpp") diff --git a/modules/godot/components/transform_component.cpp b/modules/godot/components/transform_component.cpp index e80000df..26b14999 100644 --- a/modules/godot/components/transform_component.cpp +++ b/modules/godot/components/transform_component.cpp @@ -38,17 +38,17 @@ const Vector3 TransformComponent::get_rotation() const { void TransformComponent::set_rotation_deg(const Vector3 &p_euler) { set_rotation(Vector3( - Math::deg2rad(p_euler[0]), - Math::deg2rad(p_euler[1]), - Math::deg2rad(p_euler[2]))); + Math::deg_to_rad(p_euler[0]), + Math::deg_to_rad(p_euler[1]), + Math::deg_to_rad(p_euler[2]))); } const Vector3 TransformComponent::get_rotation_deg() const { const Vector3 r = get_rotation(); return Vector3( - Math::rad2deg(r[0]), - Math::rad2deg(r[1]), - Math::rad2deg(r[2])); + Math::rad_to_deg(r[0]), + Math::rad_to_deg(r[1]), + Math::rad_to_deg(r[2])); } void TransformComponent::set_scale(const Vector3 &p_scale) { diff --git a/modules/godot/editor_plugins/components_mesh_gizmo_3d.cpp b/modules/godot/editor_plugins/components_mesh_gizmo_3d.cpp index 7f512dc7..2e1cbf6c 100644 --- a/modules/godot/editor_plugins/components_mesh_gizmo_3d.cpp +++ b/modules/godot/editor_plugins/components_mesh_gizmo_3d.cpp @@ -28,7 +28,7 @@ void MeshComponentGizmo::init() {} void MeshComponentGizmo::redraw(EditorNode3DGizmo *p_gizmo) { #ifdef TOOLS_ENABLED - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); RID scenario = entity->get_world_3d()->get_scenario(); Ref component_data = entity->get_component_depot(SNAME("MeshComponent")); diff --git a/modules/godot/editor_plugins/components_transform_gizmo_3d.cpp b/modules/godot/editor_plugins/components_transform_gizmo_3d.cpp index 1d12a7a0..026e251f 100644 --- a/modules/godot/editor_plugins/components_transform_gizmo_3d.cpp +++ b/modules/godot/editor_plugins/components_transform_gizmo_3d.cpp @@ -16,7 +16,7 @@ void TransformComponentGizmo::init() { } void TransformComponentGizmo::redraw(EditorNode3DGizmo *p_gizmo) { - Entity3D *entity = static_cast(p_gizmo->get_spatial_node()); + Entity3D *entity = static_cast(p_gizmo->get_node_3d()); if (entity->has_component(transform_component_name) == false) { // Nothing to do. diff --git a/modules/godot/editor_plugins/editor_world_ecs.cpp b/modules/godot/editor_plugins/editor_world_ecs.cpp index 9af61dde..4d833523 100644 --- a/modules/godot/editor_plugins/editor_world_ecs.cpp +++ b/modules/godot/editor_plugins/editor_world_ecs.cpp @@ -8,9 +8,11 @@ #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" +#include "editor/editor_undo_redo_manager.h" #include "scene/gui/color_rect.h" #include "scene/gui/reference_rect.h" #include "scene/gui/separator.h" +#include "scene/gui/tree.h" PipelineElementInfoBox::PipelineElementInfoBox(EditorNode *p_editor, EditorWorldECS *p_editor_world_ecs) : editor(p_editor), @@ -841,10 +843,10 @@ void EditorWorldECS::pipeline_change_name(const String &p_name) { return; } - editor->get_undo_redo()->create_action(TTR("Change pipeline name")); - editor->get_undo_redo()->add_do_method(pipeline.ptr(), SNAME("set_pipeline_name"), p_name); - editor->get_undo_redo()->add_undo_method(pipeline.ptr(), SNAME("set_pipeline_name"), pipeline->get_pipeline_name()); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Change pipeline name")); + EditorUndoRedoManager::get_singleton()->add_do_method(pipeline.ptr(), SNAME("set_pipeline_name"), p_name); + EditorUndoRedoManager::get_singleton()->add_undo_method(pipeline.ptr(), SNAME("set_pipeline_name"), pipeline->get_pipeline_name()); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EditorWorldECS::pipeline_list_update() { @@ -914,10 +916,10 @@ void EditorWorldECS::pipeline_add() { pip->set_pipeline_name(name); set_pipeline(pip); - editor->get_undo_redo()->create_action(TTR("Add pipeline")); - editor->get_undo_redo()->add_do_method(world_ecs, SNAME("add_pipeline"), pip); - editor->get_undo_redo()->add_undo_method(world_ecs, SNAME("remove_pipeline"), pip); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Add pipeline")); + EditorUndoRedoManager::get_singleton()->add_do_method(world_ecs, SNAME("add_pipeline"), pip); + EditorUndoRedoManager::get_singleton()->add_undo_method(world_ecs, SNAME("remove_pipeline"), pip); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EditorWorldECS::pipeline_rename_show_window() { @@ -937,10 +939,10 @@ void EditorWorldECS::pipeline_remove() { return; } - editor->get_undo_redo()->create_action(TTR("Pipeline remove")); - editor->get_undo_redo()->add_do_method(world_ecs, SNAME("remove_pipeline"), pipeline); - editor->get_undo_redo()->add_undo_method(world_ecs, SNAME("add_pipeline"), pipeline); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Pipeline remove")); + EditorUndoRedoManager::get_singleton()->add_do_method(world_ecs, SNAME("remove_pipeline"), pipeline); + EditorUndoRedoManager::get_singleton()->add_undo_method(world_ecs, SNAME("add_pipeline"), pipeline); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EditorWorldECS::pipeline_toggle_pipeline_view() { @@ -1092,10 +1094,10 @@ void EditorWorldECS::pipeline_system_bundle_remove(const StringName &p_name) { return; } - editor->get_undo_redo()->create_action(TTR("Remove system")); - editor->get_undo_redo()->add_do_method(pipeline.ptr(), SNAME("remove_system_bundle"), p_name); - editor->get_undo_redo()->add_undo_method(pipeline.ptr(), SNAME("add_system_bundle"), p_name); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Remove system")); + EditorUndoRedoManager::get_singleton()->add_do_method(pipeline.ptr(), SNAME("remove_system_bundle"), p_name); + EditorUndoRedoManager::get_singleton()->add_undo_method(pipeline.ptr(), SNAME("add_system_bundle"), p_name); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EditorWorldECS::pipeline_system_remove(const StringName &p_name) { @@ -1103,10 +1105,10 @@ void EditorWorldECS::pipeline_system_remove(const StringName &p_name) { return; } - editor->get_undo_redo()->create_action(TTR("Remove system")); - editor->get_undo_redo()->add_do_method(pipeline.ptr(), SNAME("remove_system"), p_name); - editor->get_undo_redo()->add_undo_method(pipeline.ptr(), SNAME("insert_system"), p_name); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Remove system")); + EditorUndoRedoManager::get_singleton()->add_do_method(pipeline.ptr(), SNAME("remove_system"), p_name); + EditorUndoRedoManager::get_singleton()->add_undo_method(pipeline.ptr(), SNAME("insert_system"), p_name); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EditorWorldECS::add_sys_show() { @@ -1238,15 +1240,15 @@ void EditorWorldECS::add_sys_add() { } if (selected->has_meta("system_name")) { - editor->get_undo_redo()->create_action(TTR("Add system")); - editor->get_undo_redo()->add_do_method(pipeline.ptr(), SNAME("insert_system"), selected->get_meta("system_name")); - editor->get_undo_redo()->add_undo_method(pipeline.ptr(), SNAME("remove_system"), selected->get_meta("system_name")); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Add system")); + EditorUndoRedoManager::get_singleton()->add_do_method(pipeline.ptr(), SNAME("insert_system"), selected->get_meta("system_name")); + EditorUndoRedoManager::get_singleton()->add_undo_method(pipeline.ptr(), SNAME("remove_system"), selected->get_meta("system_name")); } else { - editor->get_undo_redo()->create_action(TTR("Add system bundle")); - editor->get_undo_redo()->add_do_method(pipeline.ptr(), SNAME("add_system_bundle"), selected->get_meta("system_bundle_name")); - editor->get_undo_redo()->add_undo_method(pipeline.ptr(), SNAME("remove_system_bundle"), selected->get_meta("system_bundle_name")); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Add system bundle")); + EditorUndoRedoManager::get_singleton()->add_do_method(pipeline.ptr(), SNAME("add_system_bundle"), selected->get_meta("system_bundle_name")); + EditorUndoRedoManager::get_singleton()->add_undo_method(pipeline.ptr(), SNAME("remove_system_bundle"), selected->get_meta("system_bundle_name")); } - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EditorWorldECS::components_manage_show() { @@ -1275,10 +1277,41 @@ void EditorWorldECS::add_warning(const String &p_msg) { errors_warnings_container->add_child(lbl); } +void EditorWorldECS::remove_node_and_reparent_children(Node *p_node) { + List children; + + while (true) { + bool clear = true; + for (int i = 0; i < p_node->get_child_count(false); i++) { + Node *c_node = p_node->get_child(i, false); + if (!c_node->get_owner()) { + continue; + } + + p_node->remove_child(c_node); + children.push_back(c_node); + clear = false; + break; + } + + if (clear) { + break; + } + } + + while (!children.is_empty()) { + Node *c_node = children.front()->get(); + p_node->get_parent()->add_child(c_node); + children.pop_front(); + } + + p_node->get_parent()->remove_child(p_node); +} + void EditorWorldECS::clear_errors_warnings() { for (int i = errors_warnings_container->get_child_count() - 1; i >= 0; i -= 1) { Node *n = errors_warnings_container->get_child(i); - errors_warnings_container->get_child(i)->remove_and_skip(); + remove_node_and_reparent_children(n); memdelete(n); } } @@ -1304,7 +1337,7 @@ PipelineElementInfoBox *EditorWorldECS::pipeline_panel_add_entry() { void EditorWorldECS::pipeline_panel_clear() { for (int i = pipeline_panel->get_child_count() - 1; i >= 0; i -= 1) { Node *n = pipeline_panel->get_child(i); - pipeline_panel->get_child(i)->remove_and_skip(); + remove_node_and_reparent_children(n); memdelete(n); } } @@ -1318,7 +1351,7 @@ DispatcherPipelineView *EditorWorldECS::pipeline_view_add_dispatcher() { void EditorWorldECS::pipeline_view_clear() { for (int i = pipeline_view_panel->get_child_count() - 1; i >= 0; i -= 1) { Node *n = pipeline_view_panel->get_child(i); - pipeline_view_panel->get_child(i)->remove_and_skip(); + remove_node_and_reparent_children(n); memdelete(n); } } @@ -1326,17 +1359,20 @@ void EditorWorldECS::pipeline_view_clear() { WorldECSEditorPlugin::WorldECSEditorPlugin(EditorNode *p_node) : editor(p_node) { ecs_editor = memnew(EditorWorldECS(p_node)); - editor->get_main_control()->add_child(ecs_editor); + editor->get_main_screen_control()->add_child(ecs_editor); ecs_editor->hide_editor(); } WorldECSEditorPlugin::~WorldECSEditorPlugin() { - editor->get_main_control()->remove_child(ecs_editor); + editor->get_main_screen_control()->remove_child(ecs_editor); memdelete(ecs_editor); ecs_editor = nullptr; } void WorldECSEditorPlugin::edit(Object *p_object) { + if (p_object == nullptr) { + return; + } world_ecs = Object::cast_to(p_object); ERR_FAIL_COND_MSG(world_ecs == nullptr, "The object should be of type WorldECS [BUG]."); ecs_editor->set_world_ecs(world_ecs); diff --git a/modules/godot/editor_plugins/editor_world_ecs.h b/modules/godot/editor_plugins/editor_world_ecs.h index 5fabde60..03067672 100644 --- a/modules/godot/editor_plugins/editor_world_ecs.h +++ b/modules/godot/editor_plugins/editor_world_ecs.h @@ -2,6 +2,12 @@ #define EDITORWORLDECS_H #include "editor/editor_plugin.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/line_edit.h" +#include "scene/gui/margin_container.h" +#include "scene/gui/option_button.h" +#include "scene/gui/panel_container.h" +#include "scene/gui/text_edit.h" class EditorNode; class WorldECS; @@ -204,6 +210,7 @@ class EditorWorldECS : public PanelContainer { DispatcherPipelineView *pipeline_view_add_dispatcher(); void pipeline_view_clear(); + static void remove_node_and_reparent_children(Node *p_node); }; class WorldECSEditorPlugin : public EditorPlugin { diff --git a/modules/godot/editor_plugins/entity_editor_plugin.cpp b/modules/godot/editor_plugins/entity_editor_plugin.cpp index b70fd2af..e4db0c6f 100644 --- a/modules/godot/editor_plugins/entity_editor_plugin.cpp +++ b/modules/godot/editor_plugins/entity_editor_plugin.cpp @@ -4,6 +4,8 @@ #include "core/io/marshalls.h" #include "editor/editor_properties.h" #include "editor/editor_properties_array_dict.h" +#include "editor/editor_settings.h" +#include "editor/editor_undo_redo_manager.h" void EntityEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("update_editors"), &EntityEditor::update_editors); @@ -67,7 +69,7 @@ void EntityEditor::update_editors() { if (components_section) { // Remove old childs. for (int i = components_section->get_vbox()->get_child_count() - 1; i >= 0; i -= 1) { - components_section->get_vbox()->get_child(i)->queue_delete(); // TODO is this enough to also destroy the internally created things? + components_section->get_vbox()->get_child(i)->queue_free(); // TODO is this enough to also destroy the internally created things? } components_properties.clear(); @@ -184,6 +186,7 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } else { EditorPropertyInteger *editor = memnew(EditorPropertyInteger); int min = 0, max = 65535, step = 1; + bool hide_slider = false; bool greater = true, lesser = true; if (e.hint == PROPERTY_HINT_RANGE && e.hint_string.get_slice_count(",") >= 2) { @@ -207,7 +210,7 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - editor->setup(min, max, step, greater, lesser); + editor->setup(min, max, step, hide_slider, greater, lesser); prop = editor; } } break; @@ -335,46 +338,6 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const editor->set_save_mode(); } prop = editor; - - } else if (e.hint == PROPERTY_HINT_METHOD_OF_VARIANT_TYPE || - e.hint == PROPERTY_HINT_METHOD_OF_BASE_TYPE || - e.hint == PROPERTY_HINT_METHOD_OF_INSTANCE || - e.hint == PROPERTY_HINT_METHOD_OF_SCRIPT || - e.hint == PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE || - e.hint == PROPERTY_HINT_PROPERTY_OF_BASE_TYPE || - e.hint == PROPERTY_HINT_PROPERTY_OF_INSTANCE || - e.hint == PROPERTY_HINT_PROPERTY_OF_SCRIPT) { - EditorPropertyMember *editor = memnew(EditorPropertyMember); - - EditorPropertyMember::Type type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE; - switch (e.hint) { - case PROPERTY_HINT_METHOD_OF_BASE_TYPE: - type = EditorPropertyMember::MEMBER_METHOD_OF_BASE_TYPE; - break; - case PROPERTY_HINT_METHOD_OF_INSTANCE: - type = EditorPropertyMember::MEMBER_METHOD_OF_INSTANCE; - break; - case PROPERTY_HINT_METHOD_OF_SCRIPT: - type = EditorPropertyMember::MEMBER_METHOD_OF_SCRIPT; - break; - case PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE: - type = EditorPropertyMember::MEMBER_PROPERTY_OF_VARIANT_TYPE; - break; - case PROPERTY_HINT_PROPERTY_OF_BASE_TYPE: - type = EditorPropertyMember::MEMBER_PROPERTY_OF_BASE_TYPE; - break; - case PROPERTY_HINT_PROPERTY_OF_INSTANCE: - type = EditorPropertyMember::MEMBER_PROPERTY_OF_INSTANCE; - break; - case PROPERTY_HINT_PROPERTY_OF_SCRIPT: - type = EditorPropertyMember::MEMBER_PROPERTY_OF_SCRIPT; - break; - default: { - } - } - editor->setup(type, e.hint_string); - prop = editor; - } else { EditorPropertyText *editor = memnew(EditorPropertyText); if (e.hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { @@ -386,15 +349,13 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const #define SETUP_MATH_RANGE(editor, prop_info, type) \ type min = -65535, max = 65535; \ - bool hide_slider = true; \ \ if (prop_info.hint == PROPERTY_HINT_RANGE && prop_info.hint_string.get_slice_count(",") >= 2) { \ min = e.hint_string.get_slice(",", 0).to_float(); \ max = e.hint_string.get_slice(",", 1).to_float(); \ - hide_slider = false; \ } \ \ - editor->setup(min, max, hide_slider); + editor->setup(min, max); #define SETUP_MATH_RANGE_WITH_STEP(editor, prop_info, type) \ type min = -65535, max = 65535, step = default_float_step; \ @@ -660,21 +621,21 @@ void EntityEditor::_add_component_pressed(uint32_t p_index) { component_name = add_component_menu->get_popup()->get_item_text(p_index); } - editor->get_undo_redo()->create_action(TTR("Add component")); - editor->get_undo_redo()->add_do_method(entity, SNAME("add_component"), component_name); - editor->get_undo_redo()->add_do_method(this, SNAME("update_editors")); - editor->get_undo_redo()->add_undo_method(entity, SNAME("remove_component"), component_name); - editor->get_undo_redo()->add_undo_method(this, SNAME("update_editors")); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Add component")); + EditorUndoRedoManager::get_singleton()->add_do_method(entity, SNAME("add_component"), component_name); + EditorUndoRedoManager::get_singleton()->add_do_method(this, SNAME("update_editors")); + EditorUndoRedoManager::get_singleton()->add_undo_method(entity, SNAME("remove_component"), component_name); + EditorUndoRedoManager::get_singleton()->add_undo_method(this, SNAME("update_editors")); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EntityEditor::_remove_component_pressed(StringName p_component_name) { - editor->get_undo_redo()->create_action(TTR("Drop component")); - editor->get_undo_redo()->add_do_method(entity, SNAME("remove_component"), p_component_name); - editor->get_undo_redo()->add_do_method(this, SNAME("update_editors")); - editor->get_undo_redo()->add_undo_method(entity, SNAME("add_component"), p_component_name, entity_get_component_props_data(p_component_name)); - editor->get_undo_redo()->add_undo_method(this, SNAME("update_editors")); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Drop component")); + EditorUndoRedoManager::get_singleton()->add_do_method(entity, SNAME("remove_component"), p_component_name); + EditorUndoRedoManager::get_singleton()->add_do_method(this, SNAME("update_editors")); + EditorUndoRedoManager::get_singleton()->add_undo_method(entity, SNAME("add_component"), p_component_name, entity_get_component_props_data(p_component_name)); + EditorUndoRedoManager::get_singleton()->add_undo_method(this, SNAME("update_editors")); + EditorUndoRedoManager::get_singleton()->commit_action(); } void EntityEditor::_property_changed(const String &p_path, const Variant &p_value, const String &p_name, bool p_changing) { @@ -683,11 +644,11 @@ void EntityEditor::_property_changed(const String &p_path, const Variant &p_valu return; } - editor->get_undo_redo()->create_action(TTR("Set component value")); - editor->get_undo_redo()->add_do_method(entity, SNAME("set"), p_path, p_value); - editor->get_undo_redo()->add_undo_method(entity, SNAME("set"), p_path, entity->get(p_path)); - editor->get_undo_redo()->add_undo_method(this, SNAME("update_editors")); - editor->get_undo_redo()->commit_action(); + EditorUndoRedoManager::get_singleton()->create_action(TTR("Set component value")); + EditorUndoRedoManager::get_singleton()->add_do_method(entity, SNAME("set"), p_path, p_value); + EditorUndoRedoManager::get_singleton()->add_undo_method(entity, SNAME("set"), p_path, entity->get(p_path)); + EditorUndoRedoManager::get_singleton()->add_undo_method(this, SNAME("update_editors")); + EditorUndoRedoManager::get_singleton()->commit_action(); if (p_value.get_type() != Variant::STRING) { // This is needed because string update is special: If string is updated diff --git a/modules/godot/editor_plugins/entity_editor_plugin.h b/modules/godot/editor_plugins/entity_editor_plugin.h index b049318d..7db101fa 100644 --- a/modules/godot/editor_plugins/entity_editor_plugin.h +++ b/modules/godot/editor_plugins/entity_editor_plugin.h @@ -2,6 +2,7 @@ #define ENTITY_EDITOR_PLUGIN_H #include "core/templates/oa_hash_map.h" +#include "editor/editor_inspector.h" #include "editor/editor_node.h" #include "editor/editor_plugin.h" diff --git a/modules/godot/nodes/ecs_utilities.cpp b/modules/godot/nodes/ecs_utilities.cpp index 7816ca53..62946ee4 100644 --- a/modules/godot/nodes/ecs_utilities.cpp +++ b/modules/godot/nodes/ecs_utilities.cpp @@ -7,9 +7,11 @@ #include "core/config/project_settings.h" #include "core/io/resource_loader.h" #include "core/object/script_language.h" -#include "editor/editor_node.h" #include "entity.h" #include "shared_component_resource.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_node.h" +#endif void System::_bind_methods() { ClassDB::bind_method(D_METHOD("execute_in", "phase", "dispatcher"), &System::execute_in, DEFVAL(godex::SYSTEM_NONE)); @@ -113,13 +115,13 @@ void System::prepare(godex::DynamicSystemExecutionData *p_info) { String System::validate_script(Ref