diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml index 873a5594..de0e735c 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: ab7cb2a95d060a6533e6ff5111c11f71972ab43f + 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.event_name != 'pull_request' && github.sha || github.event.pull_request.head.sha }} + 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..75382ddc 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: ab7cb2a95d060a6533e6ff5111c11f71972ab43f + 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.event_name != 'pull_request' && github.sha || github.event.pull_request.head.sha }} + 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..c473f798 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` `ab7cb2a95d060a6533e6ff5111c11f71972ab43f`, 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..e5538aaa 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,47 @@ 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(); + + for (auto extend : tree->extends) { + if (extend->name == "System") { + register_dynamic_system(script.get_file()); + break; + } + if (extend->name == "Component") { + register_or_get_id_for_component_name(script.get_file()); + break; + } + } + } + } +} + ECS::~ECS() { } @@ -1041,11 +1085,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 +1098,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 +1138,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 +1168,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..38aee047 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); @@ -630,11 +633,11 @@ void ECS::register_component(StorageBase *(*create_storage)()) { get_storage_config = C::_get_storage_config; } - LocalVector spawners; + LocalVector tmp_spawners; if constexpr (godex_has_get_spawners::value) { - spawners = C::get_spawners(); - for (uint32_t i = 0; i < spawners.size(); i += 1) { - spawners_info[spawners[i]].components.push_back(C::component_id); + tmp_spawners = C::get_spawners(); + for (uint32_t i = 0; i < tmp_spawners.size(); i += 1) { + spawners_info[tmp_spawners[i]].components.push_back(C::component_id); } } @@ -648,7 +651,7 @@ void ECS::register_component(StorageBase *(*create_storage)()) { nullptr, notify_release_write, shared_component_storage, - spawners, + tmp_spawners, DataAccessorFuncs{ C::get_static_properties, C::get_property_list, diff --git a/iterators/dynamic_query.cpp b/iterators/dynamic_query.cpp index ea9d3668..3566b4d6 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); @@ -110,15 +110,15 @@ void DynamicQuery::get_system_info(SystemExeInfo *p_info) const { } void DynamicQuery::prepare_world_script(Object *p_world) { - WorldECS *world = Object::cast_to(p_world); - ERR_FAIL_COND_MSG(world == nullptr, "The given object is not a `WorldECS`."); - prepare_world(world->get_world()); + WorldECS *tmp_world = Object::cast_to(p_world); + ERR_FAIL_COND_MSG(tmp_world == nullptr, "The given object is not a `WorldECS`."); + prepare_world(tmp_world->get_world()); } void DynamicQuery::begin_script(Object *p_world) { - WorldECS *world = Object::cast_to(p_world); - ERR_FAIL_COND_MSG(world == nullptr, "The given object is not a `WorldECS`."); - initiate_process(world->get_world()); + WorldECS *tmp_world = Object::cast_to(p_world); + ERR_FAIL_COND_MSG(tmp_world == nullptr, "The given object is not a `WorldECS`."); + initiate_process(tmp_world->get_world()); } void DynamicQuery::end_script() { diff --git a/iterators/query.h b/iterators/query.h index 1a5e22b4..3ffbdd8b 100644 --- a/iterators/query.h +++ b/iterators/query.h @@ -825,8 +825,8 @@ struct QueryStorage, Cs...> : public QueryStorage { if (unlikely(storage == nullptr)) { return o_entities; } - const EntitiesBuffer entities(changed.size(), changed.get_entities_ptr()); - return entities.count < o_entities.count ? entities : o_entities; + const EntitiesBuffer tmp_entities(changed.size(), changed.get_entities_ptr()); + return tmp_entities.count < o_entities.count ? tmp_entities : o_entities; } bool filter_satisfied(EntityID p_entity) const { @@ -1321,8 +1321,8 @@ struct QueryStorage : QueryStorage { if (unlikely(storage == nullptr)) { return o_entities; } - const EntitiesBuffer entities = storage->get_stored_entities(); - return entities.count < o_entities.count ? entities : o_entities; + const EntitiesBuffer tmp_entities = storage->get_stored_entities(); + return tmp_entities.count < o_entities.count ? tmp_entities : o_entities; } bool filter_satisfied(EntityID p_entity) const { diff --git a/modules/bullet_physics/SCsub b/modules/bullet_physics/SCsub index 813129c2..511d919b 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"]) diff --git a/modules/bullet_physics/bt_def_type.h b/modules/bullet_physics/bt_def_type.h index 775c577e..4e163c05 100644 --- a/modules/bullet_physics/bt_def_type.h +++ b/modules/bullet_physics/bt_def_type.h @@ -11,8 +11,8 @@ enum BtSpaceIndex : int { }; enum BtBodyType : int { - TYPE_AREA = 0, - TYPE_RIGID_BODY, - TYPE_SOFT_BODY, - TYPE_KINEMATIC_GHOST_BODY + BODY_TYPE_AREA = 0, + BODY_TYPE_RIGID_BODY, + BODY_TYPE_SOFT_BODY, + BODY_TYPE_KINEMATIC_GHOST_BODY }; diff --git a/modules/bullet_physics/bullet_collision_dispatcher.cpp b/modules/bullet_physics/bullet_collision_dispatcher.cpp index 295834ec..6483b1bc 100644 --- a/modules/bullet_physics/bullet_collision_dispatcher.cpp +++ b/modules/bullet_physics/bullet_collision_dispatcher.cpp @@ -6,7 +6,7 @@ GodexBtCollisionDispatcher::GodexBtCollisionDispatcher(btCollisionConfiguration btCollisionDispatcher(collisionConfiguration) {} bool GodexBtCollisionDispatcher::needsCollision(const btCollisionObject *body0, const btCollisionObject *body1) { - if (body0->getUserIndex() == BtBodyType::TYPE_AREA || body1->getUserIndex() == BtBodyType::TYPE_AREA) { + if (body0->getUserIndex() == BtBodyType::BODY_TYPE_AREA || body1->getUserIndex() == BtBodyType::BODY_TYPE_AREA) { // Avoid area narrow phase return false; } @@ -14,7 +14,7 @@ bool GodexBtCollisionDispatcher::needsCollision(const btCollisionObject *body0, } bool GodexBtCollisionDispatcher::needsResponse(const btCollisionObject *body0, const btCollisionObject *body1) { - if (body0->getUserIndex() == BtBodyType::TYPE_AREA || body1->getUserIndex() == BtBodyType::TYPE_AREA) { + if (body0->getUserIndex() == BtBodyType::BODY_TYPE_AREA || body1->getUserIndex() == BtBodyType::BODY_TYPE_AREA) { // Avoid area narrow phase return false; } diff --git a/modules/bullet_physics/components_gizmos.cpp b/modules/bullet_physics/components_gizmos.cpp index f9aad4e6..2e7b91d0 100644 --- a/modules/bullet_physics/components_gizmos.cpp +++ b/modules/bullet_physics/components_gizmos.cpp @@ -1,10 +1,10 @@ #include "components_gizmos.h" -#include "../godot/nodes/entity.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,7 @@ void BtConvexGizmo::init() { } void BtConvexGizmo::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(convex_component_name)) { @@ -804,7 +804,7 @@ void BtTrimeshGizmo::init() { } void BtTrimeshGizmo::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(trimesh_component_name)) { @@ -859,7 +859,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 +904,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 +967,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 +990,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 +1006,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 +1059,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 +1079,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_rigid_body.cpp b/modules/bullet_physics/components_rigid_body.cpp index 5b20378f..2e158136 100644 --- a/modules/bullet_physics/components_rigid_body.cpp +++ b/modules/bullet_physics/components_rigid_body.cpp @@ -45,7 +45,7 @@ void BtRigidBody::_get_storage_config(Dictionary &r_config) { BtRigidBody::BtRigidBody() { body.setUserPointer(this); // Used by `GodotCollisionDispatcher` - body.setUserIndex(BtBodyType::TYPE_RIGID_BODY); + body.setUserIndex(BtBodyType::BODY_TYPE_RIGID_BODY); } btRigidBody *BtRigidBody::get_body() { 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/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..091eb6e8 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(); @@ -143,16 +145,16 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } break; case Variant::INT: { if (e.hint == PROPERTY_HINT_ENUM) { - EditorPropertyEnum *editor = memnew(EditorPropertyEnum); + EditorPropertyEnum *property_enum = memnew(EditorPropertyEnum); Vector options = e.hint_string.split(","); - editor->setup(options); - prop = editor; + property_enum->setup(options); + prop = property_enum; } else if (e.hint == PROPERTY_HINT_FLAGS) { - EditorPropertyFlags *editor = memnew(EditorPropertyFlags); + EditorPropertyFlags *property_flags = memnew(EditorPropertyFlags); Vector options = e.hint_string.split(","); - editor->setup(options); - prop = editor; + property_flags->setup(options); + prop = property_flags; } else if (e.hint == PROPERTY_HINT_LAYERS_2D_PHYSICS || e.hint == PROPERTY_HINT_LAYERS_2D_RENDER || e.hint == PROPERTY_HINT_LAYERS_3D_PHYSICS || e.hint == PROPERTY_HINT_LAYERS_3D_RENDER) { EditorPropertyLayers::LayerType lt = EditorPropertyLayers::LAYER_RENDER_2D; @@ -172,18 +174,19 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const default: { } } - EditorPropertyLayers *editor = memnew(EditorPropertyLayers); - editor->setup(lt); - prop = editor; + EditorPropertyLayers *property_layers = memnew(EditorPropertyLayers); + property_layers->setup(lt); + prop = property_layers; } else if (e.hint == PROPERTY_HINT_OBJECT_ID) { - EditorPropertyObjectID *editor = memnew(EditorPropertyObjectID); - editor->setup("Object"); - prop = editor; + EditorPropertyObjectID *property_object_id = memnew(EditorPropertyObjectID); + property_object_id->setup("Object"); + prop = property_object_id; } else { - EditorPropertyInteger *editor = memnew(EditorPropertyInteger); + EditorPropertyInteger *property_integer = 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,13 +210,13 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - editor->setup(min, max, step, greater, lesser); - prop = editor; + property_integer->setup(min, max, step, hide_slider, greater, lesser); + prop = property_integer; } } break; case Variant::FLOAT: { if (e.hint == PROPERTY_HINT_EXP_EASING) { - EditorPropertyEasing *editor = memnew(EditorPropertyEasing); + EditorPropertyEasing *property_easing = memnew(EditorPropertyEasing); bool full = true; bool flip = false; Vector hints = e.hint_string.split(","); @@ -227,11 +230,11 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - editor->setup(full, flip); - prop = editor; + property_easing->setup(full, flip); + prop = property_easing; } else { - EditorPropertyFloat *editor = memnew(EditorPropertyFloat); + EditorPropertyFloat *property_float = memnew(EditorPropertyFloat); double min = -65535, max = 65535, step = default_float_step; bool hide_slider = true; bool exp_range = false; @@ -261,17 +264,17 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - editor->setup(min, max, step, hide_slider, exp_range, greater, lesser); - prop = editor; + property_float->setup(min, max, step, hide_slider, exp_range, greater, lesser); + prop = property_float; } } break; case Variant::STRING: { if (e.hint == PROPERTY_HINT_ENUM) { - EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); + EditorPropertyTextEnum *property_text_enum = memnew(EditorPropertyTextEnum); Vector options = e.hint_string.split(","); - editor->setup(options); - prop = editor; + property_text_enum->setup(options); + prop = property_text_enum; } else if (e.hint == godex::PROPERTY_HINT_ECS_EVENT_EMITTER) { // Show a full list of available event emitters for this event. @@ -292,9 +295,9 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); - editor->setup(enum_component_list, false); - prop = editor; + EditorPropertyTextEnum *property_text_enum = memnew(EditorPropertyTextEnum); + property_text_enum->setup(enum_component_list, false); + prop = property_text_enum; } else if (e.hint == godex::PROPERTY_HINT_ECS_SPAWNER) { // Show the full list of available spawners for this component. @@ -311,90 +314,48 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); - editor->setup(enum_component_list, false); - prop = editor; + EditorPropertyTextEnum *property_text_enum = memnew(EditorPropertyTextEnum); + property_text_enum->setup(enum_component_list, false); + prop = property_text_enum; } else if (e.hint == PROPERTY_HINT_MULTILINE_TEXT) { - EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText); - prop = editor; + EditorPropertyMultilineText *property_multiline_text = memnew(EditorPropertyMultilineText); + prop = property_multiline_text; } else if (e.hint == PROPERTY_HINT_TYPE_STRING) { - EditorPropertyClassName *editor = memnew(EditorPropertyClassName); - editor->setup("Object", e.hint_string); - prop = editor; + EditorPropertyClassName *property_class_name = memnew(EditorPropertyClassName); + property_class_name->setup("Object", e.hint_string); + prop = property_class_name; } else if (e.hint == PROPERTY_HINT_DIR || e.hint == PROPERTY_HINT_FILE || e.hint == PROPERTY_HINT_SAVE_FILE || e.hint == PROPERTY_HINT_GLOBAL_DIR || e.hint == PROPERTY_HINT_GLOBAL_FILE) { Vector extensions = e.hint_string.split(","); bool global = e.hint == PROPERTY_HINT_GLOBAL_DIR || e.hint == PROPERTY_HINT_GLOBAL_FILE; bool folder = e.hint == PROPERTY_HINT_DIR || e.hint == PROPERTY_HINT_GLOBAL_DIR; bool save = e.hint == PROPERTY_HINT_SAVE_FILE; - EditorPropertyPath *editor = memnew(EditorPropertyPath); - editor->setup(extensions, folder, global); + EditorPropertyPath *property_path = memnew(EditorPropertyPath); + property_path->setup(extensions, folder, global); if (save) { - editor->set_save_mode(); + property_path->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; - + prop = property_path; } else { - EditorPropertyText *editor = memnew(EditorPropertyText); + EditorPropertyText *property_text = memnew(EditorPropertyText); if (e.hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { - editor->set_placeholder(e.hint_string); + property_text->set_placeholder(e.hint_string); } - prop = editor; + prop = property_text; } } break; #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; \ @@ -412,91 +373,91 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const editor->setup(min, max, step, hide_slider); // math types case Variant::VECTOR2: { - EditorPropertyVector2 *editor = memnew(EditorPropertyVector2); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyVector2 *property_vector2 = memnew(EditorPropertyVector2); + SETUP_MATH_RANGE_WITH_STEP(property_vector2, e, double); + prop = property_vector2; } break; case Variant::VECTOR2I: { - EditorPropertyVector2i *editor = memnew(EditorPropertyVector2i); - SETUP_MATH_RANGE(editor, e, int); - prop = editor; + EditorPropertyVector2i *property_vector2i = memnew(EditorPropertyVector2i); + SETUP_MATH_RANGE(property_vector2i, e, int); + prop = property_vector2i; } break; case Variant::RECT2: { - EditorPropertyRect2 *editor = memnew(EditorPropertyRect2); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyRect2 *property_rect2 = memnew(EditorPropertyRect2); + SETUP_MATH_RANGE_WITH_STEP(property_rect2, e, double); + prop = property_rect2; } break; case Variant::RECT2I: { - EditorPropertyRect2i *editor = memnew(EditorPropertyRect2i); - SETUP_MATH_RANGE(editor, e, int); - prop = editor; + EditorPropertyRect2i *property_rect2i = memnew(EditorPropertyRect2i); + SETUP_MATH_RANGE(property_rect2i, e, int); + prop = property_rect2i; } break; case Variant::VECTOR3: { - EditorPropertyVector3 *editor = memnew(EditorPropertyVector3); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyVector3 *property_vector3 = memnew(EditorPropertyVector3); + SETUP_MATH_RANGE_WITH_STEP(property_vector3, e, double); + prop = property_vector3; } break; case Variant::VECTOR3I: { - EditorPropertyVector3i *editor = memnew(EditorPropertyVector3i); - SETUP_MATH_RANGE(editor, e, int); - prop = editor; + EditorPropertyVector3i *property_vector3i = memnew(EditorPropertyVector3i); + SETUP_MATH_RANGE(property_vector3i, e, int); + prop = property_vector3i; } break; case Variant::TRANSFORM2D: { - EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyTransform2D *transform_2d = memnew(EditorPropertyTransform2D); + SETUP_MATH_RANGE_WITH_STEP(transform_2d, e, double); + prop = transform_2d; } break; case Variant::PLANE: { - EditorPropertyPlane *editor = memnew(EditorPropertyPlane); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyPlane *property_plane = memnew(EditorPropertyPlane); + SETUP_MATH_RANGE_WITH_STEP(property_plane, e, double); + prop = property_plane; } break; case Variant::QUATERNION: { - EditorPropertyQuaternion *editor = memnew(EditorPropertyQuaternion); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyQuaternion *property_quaternion = memnew(EditorPropertyQuaternion); + SETUP_MATH_RANGE_WITH_STEP(property_quaternion, e, double); + prop = property_quaternion; } break; case Variant::AABB: { - EditorPropertyAABB *editor = memnew(EditorPropertyAABB); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyAABB *property_aabb = memnew(EditorPropertyAABB); + SETUP_MATH_RANGE_WITH_STEP(property_aabb, e, double); + prop = property_aabb; } break; case Variant::BASIS: { - EditorPropertyBasis *editor = memnew(EditorPropertyBasis); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyBasis *property_basis = memnew(EditorPropertyBasis); + SETUP_MATH_RANGE_WITH_STEP(property_basis, e, double); + prop = property_basis; } break; case Variant::TRANSFORM3D: { - EditorPropertyTransform3D *editor = memnew(EditorPropertyTransform3D); - SETUP_MATH_RANGE_WITH_STEP(editor, e, double); - prop = editor; + EditorPropertyTransform3D *transform_3d = memnew(EditorPropertyTransform3D); + SETUP_MATH_RANGE_WITH_STEP(transform_3d, e, double); + prop = transform_3d; } break; // misc types case Variant::COLOR: { - EditorPropertyColor *editor = memnew(EditorPropertyColor); - editor->setup(e.hint != PROPERTY_HINT_COLOR_NO_ALPHA); - prop = editor; + EditorPropertyColor *property_color = memnew(EditorPropertyColor); + property_color->setup(e.hint != PROPERTY_HINT_COLOR_NO_ALPHA); + prop = property_color; } break; case Variant::STRING_NAME: { if (e.hint == PROPERTY_HINT_ENUM) { - EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); + EditorPropertyTextEnum *property_text_enum = memnew(EditorPropertyTextEnum); Vector options = e.hint_string.split(","); - editor->setup(options, true); - prop = editor; + property_text_enum->setup(options, true); + prop = property_text_enum; } else if (e.hint == godex::PROPERTY_HINT_ECS_SPAWNER) { const StringName spawner_name = e.hint_string; @@ -512,32 +473,32 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } } - EditorPropertyTextEnum *editor = memnew(EditorPropertyTextEnum); - editor->setup(enum_component_list, true); - prop = editor; + EditorPropertyTextEnum *property_text_enum = memnew(EditorPropertyTextEnum); + property_text_enum->setup(enum_component_list, true); + prop = property_text_enum; } else { - EditorPropertyText *editor = memnew(EditorPropertyText); + EditorPropertyText *property_text = memnew(EditorPropertyText); if (e.hint == PROPERTY_HINT_PLACEHOLDER_TEXT) { - editor->set_placeholder(e.hint_string); + property_text->set_placeholder(e.hint_string); } - editor->set_string_name(true); - prop = editor; + property_text->set_string_name(true); + prop = property_text; } } break; case Variant::NODE_PATH: { - EditorPropertyNodePath *editor = memnew(EditorPropertyNodePath); - const int usage = 0; // TODO how to integrate this? check /modules/godot/editor/editor_properties.cpp::parse_property + EditorPropertyNodePath *property_node_path = memnew(EditorPropertyNodePath); + const int usage = 0; // TODO how to integrate this? check /modules/godot/property_node_path/editor_properties.cpp::parse_property if (e.hint == PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE && e.hint_string != String()) { - editor->setup(e.hint_string, Vector(), (usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT)); + property_node_path->setup(e.hint_string, Vector(), (usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT)); } if (e.hint == PROPERTY_HINT_NODE_PATH_VALID_TYPES && e.hint_string != String()) { Vector types = e.hint_string.split(",", false); Vector sn = Variant(types); // convert via variant - editor->setup(NodePath(), sn, (usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT)); + property_node_path->setup(NodePath(), sn, (usage & PROPERTY_USAGE_NODE_PATH_FROM_SCENE_ROOT)); } - prop = editor; + prop = property_node_path; } break; case Variant::RID: { @@ -545,23 +506,23 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } break; case Variant::OBJECT: { - EditorPropertyResource *editor = memnew(EditorPropertyResource); + EditorPropertyResource *property_resource = memnew(EditorPropertyResource); if (e.hint == PROPERTY_HINT_RESOURCE_TYPE) { - editor->setup(entity, entity ? entity->get_path() : NodePath(), e.hint_string); + property_resource->setup(entity, entity ? entity->get_path() : NodePath(), e.hint_string); const String open_in_new = EDITOR_GET("interface/inspector/resources_to_open_in_new_inspector"); for (int i = 0; i < open_in_new.get_slice_count(","); i++) { const String type = open_in_new.get_slicec(',', i).strip_edges(); for (int j = 0; j < e.hint_string.get_slice_count(","); j++) { String inherits = e.hint_string.get_slicec(',', j); if (ClassDB::is_parent_class(inherits, type)) { - editor->set_use_sub_inspector(false); + property_resource->set_use_sub_inspector(false); } } } } else { - editor->setup(entity, entity ? entity->get_path() : NodePath(), "Resource"); + property_resource->setup(entity, entity ? entity->get_path() : NodePath(), "Resource"); } - prop = editor; + prop = property_resource; } break; case Variant::DICTIONARY: { @@ -569,56 +530,56 @@ void EntityEditor::create_component_inspector(StringName p_component_name, const } break; case Variant::ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::ARRAY, e.hint_string); + prop = property_array; } break; // arrays case Variant::PACKED_BYTE_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_BYTE_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_BYTE_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_INT32_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_INT32_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_INT32_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_FLOAT32_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_FLOAT32_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_FLOAT32_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_INT64_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_INT64_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_INT64_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_FLOAT64_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_FLOAT64_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_FLOAT64_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_STRING_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_STRING_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_STRING_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_VECTOR2_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_VECTOR2_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_VECTOR2_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_VECTOR3_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_VECTOR3_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_VECTOR3_ARRAY, e.hint_string); + prop = property_array; } break; case Variant::PACKED_COLOR_ARRAY: { - EditorPropertyArray *editor = memnew(EditorPropertyArray); - editor->setup(Variant::PACKED_COLOR_ARRAY, e.hint_string); - prop = editor; + EditorPropertyArray *property_array = memnew(EditorPropertyArray); + property_array->setup(Variant::PACKED_COLOR_ARRAY, e.hint_string); + prop = property_array; } break; default: { } @@ -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..de819dea 100644 --- a/modules/godot/nodes/ecs_utilities.cpp +++ b/modules/godot/nodes/ecs_utilities.cpp @@ -43,9 +43,9 @@ System::~System() {} void System::execute_in(Phase p_phase, uint32_t p_dispatcher_id) { ERR_FAIL_COND_MSG(info == nullptr, "No info set. This function can be called only within the `_prepare`."); if (p_dispatcher_id != godex::SYSTEM_NONE) { - const StringName name = ECS::get_system_name(p_dispatcher_id); - ERR_FAIL_COND(name == StringName()); - info->execute_in(p_phase, name); + const StringName system_name = ECS::get_system_name(p_dispatcher_id); + ERR_FAIL_COND(system_name == StringName()); + info->execute_in(p_phase, system_name); } else { info->execute_in(p_phase); } @@ -53,16 +53,16 @@ void System::execute_in(Phase p_phase, uint32_t p_dispatcher_id) { void System::execute_after(uint32_t p_system) { ERR_FAIL_COND_MSG(info == nullptr, "No info set. This function can be called only within the `_prepare`."); - const StringName name = ECS::get_system_name(p_system); - ERR_FAIL_COND(name == StringName()); - info->execute_after(name); + const StringName system_name = ECS::get_system_name(p_system); + ERR_FAIL_COND(system_name == StringName()); + info->execute_after(system_name); } void System::execute_before(uint32_t p_system) { ERR_FAIL_COND_MSG(info == nullptr, "No info set. This function can be called only within the `_prepare`."); - const StringName name = ECS::get_system_name(p_system); - ERR_FAIL_COND(name == StringName()); - info->execute_before(name); + const StringName system_name = ECS::get_system_name(p_system); + ERR_FAIL_COND(system_name == StringName()); + info->execute_before(system_name); } void System::with_query_gd(Object *p_query) { @@ -143,6 +143,12 @@ String System::validate_script(Ref