Skip to content

[Navigation] Create a dedicated 2D navigation server#101504

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
AThousandShips:nav_split_new
Mar 30, 2025
Merged

[Navigation] Create a dedicated 2D navigation server#101504
Repiteo merged 1 commit into
godotengine:masterfrom
AThousandShips:nav_split_new

Conversation

@AThousandShips
Copy link
Copy Markdown
Member

@AThousandShips AThousandShips commented Jan 13, 2025

This is ready for extensive review but still a work in progress, keeping commits separate to handle transitioning changes and deciding on some more steps in this, but it should be feature complete

What it especially needs is:

  • Extensive testing, I've done some basic testing of pathing but haven't tested avoidance or internal details beyond the CI and basic testing, as I don't know the details of most of these systems
  • Some further simplification of the 2D code, I've made a number of simplifications based on the change from 3D to 2D (like removing all use of up, and removing some cases that are distinctly 3D) but I suspect there might be some areas that still can be simplified now that it is 2D, but would need some further insight and testing
  • Opinions on the decisions of restructuring of performance and the moving of the original module, and if Heap should instead be put in servers/navigation
  • Feedback on the tests, see TODOs there, and if any specific tests needs to be added or modified
  • Placement and potential splitting of settings between 2D and 3D (like debug settings)

Some additions I didn't make but that could be added, either in this or a follow-up:

  • Add an option to disable all navigation, disabling both the modules at once
  • Expand the Triangle2 class to be fully featured and move to core

Otherwise this is ready for testing, I will start using this in my own projects when I get around to working on them as well


For context, currently the 2D navigation system just runs as a frontend for the 3D navigation server, this is not only inefficient and involves a lot of magic to convert it also means that all navigation is unavailable when building without 3D support


Todo:

Comment thread modules/navigation_2d/nav_agent_2d.cpp Outdated
Comment thread modules/navigation_2d/nav_agent_2d.cpp Outdated
Comment thread modules/navigation_2d/nav_agent_2d.cpp Outdated
Comment thread modules/navigation_2d/nav_agent_2d.cpp Outdated
Comment thread modules/navigation_2d/nav_agent_2d.cpp Outdated
Comment thread modules/navigation_2d/nav_map_2d.cpp Outdated
Comment thread modules/navigation_3d/3d/nav_map_builder_3d.cpp Outdated
Comment thread servers/navigation_server_2d.h Outdated
Comment on lines 338 to 349
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to consider if we really want to stick with the same naming and enums. There have been multiple PRs that added new properties and debug info that at least I did withdraw because the timing for compatibility breaking was a problem. Before we now repeat all that old again for 2D and cement it further we might want to reconsider that.

Copy link
Copy Markdown
Member Author

@AThousandShips AThousandShips Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, open for any suggestions, would suggest keeping the old data in Performance as is

Comment thread main/performance.h Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the server enum we might want to reconsider the debug monitors if we are changing things now.

Comment thread core/config/project_settings.cpp Outdated
@smix8
Copy link
Copy Markdown
Contributor

smix8 commented Jan 14, 2025

Note (to self), the NavigationServer documentation needs more or less a full rewrite with this and other recent changes.
https://docs.godotengine.org/en/latest/tutorials/navigation/navigation_using_navigationservers.html

@AThousandShips
Copy link
Copy Markdown
Member Author

Will go over the navigation docs and the optimizing for size docs when this is done

@AThousandShips
Copy link
Copy Markdown
Member Author

Updated the agent and obstacle related code, will look at the signal code and other details as well

@AThousandShips
Copy link
Copy Markdown
Member Author

Will try to rebase this in the next few days

@AThousandShips
Copy link
Copy Markdown
Member Author

Successfuly rebased, going to go through some of the code to ensure it was transferred correctly but should be good to go now 🎉

@AThousandShips AThousandShips force-pushed the nav_split_new branch 2 times, most recently from 37320ef to c25ef7b Compare March 22, 2025 12:28
@smix8 smix8 modified the milestones: 4.x, 4.5 Mar 22, 2025
@AThousandShips AThousandShips force-pushed the nav_split_new branch 3 times, most recently from af64fb7 to 408e31f Compare March 28, 2025 17:08
Copy link
Copy Markdown
Contributor

@smix8 smix8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this before and I am in favor of doing this split, I just have no time to spend on reviewing and testing such a big PR in all detail atm. I did a quick test and so far nothing noticeable did break. Imo it should be merged now because we will not get a less painful window to merge such a big change anytime soon again. This PR affects way too many development branches and will be a constant rebase pita and bug source if delayed. There are a few things that I might want to change but it is not important to do now, it can be done before 4.5 release.

* Add a dedicated 2D server
* Create dedicated tests
* Split performance metrics between 2D and 3D
* Rename the 3D only server module
Copy link
Copy Markdown
Contributor

@Repiteo Repiteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This separation makes complete sense to me. Any reservations I have with the current implementation would amount to bikeshedding, and this shouldn't be held up any longer than it already has. Great work!

@Repiteo Repiteo merged commit 8b2952a into godotengine:master Mar 30, 2025
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Mar 30, 2025

Thanks!

@AThousandShips AThousandShips deleted the nav_split_new branch March 30, 2025 14:08
@AThousandShips
Copy link
Copy Markdown
Member Author

Thank you! Great to have this done and dusted!

Will follow up with potential performance improvements and keep things under supervision

@AThousandShips
Copy link
Copy Markdown
Member Author

Will update the building documentation to match this the coming week

Comment thread main/performance.cpp
PNAME("navigation_2d/edges_connected"),
PNAME("navigation_2d/edges_free"),
PNAME("navigation_2d/obstacles"),
PNAME("navigation_2d/active_maps"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, duplicate navigation_2d/active_maps and missing navigation_3d/active_maps

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for spotting, will fix today

@aaronfranke
Copy link
Copy Markdown
Member

I rebased PR #89409 on top of this PR, but instead of just moving the navigation servers into the navigation folder, I split the navigation folder into navigation_2d and navigation_3d. Now that the 2D and 3D navigation servers are independent, we can separate them into folders and allow compiling without them.

@WhalesState
Copy link
Copy Markdown
Contributor

I rebased PR #89409 on top of this PR, but instead of just moving the navigation servers into the navigation folder, I split the navigation folder into navigation_2d and navigation_3d. Now that the 2D and 3D navigation servers are independent, we can separate them into folders and allow compiling without them.

Was testing it and I have found that NavigationMesh is used by 2D navigation and it requires NavigationServer3D.

@AThousandShips
Copy link
Copy Markdown
Member Author

AThousandShips commented Apr 18, 2025

It is used strictly for debugging, which can be enabled in non-3D exports, please open a bug report for the issues this might cause

NavigationPolygon doesn't use any 3D features as far as I can see, you can just generate a mesh from a polygon, and that shouldn't depend on any 3D features unless used with 3D features

@WhalesState
Copy link
Copy Markdown
Contributor

It is used strictly for debugging, which can be enabled in non-3D exports, please open a bug report for the issues this might cause

I have allowed the editor to be built with 3D disabled, and the build failed because NavigationMesh includes NavigationServer3D for visual debugging so i will try to see if there's a workaround for that since BaseMaterial3D is not initialized when 3D is disabled.

Also I have spotted this in scene_debugger.cpp that may cause issues in the future, I know it's unrelated to this PR but i just wanted to let you know about it.

#ifndef PHYSICS_2D_DISABLED
			CollisionShape3D *collision_shape = Object::cast_to<CollisionShape3D>(node_3d);
			if (collision_shape) {
				Ref<Shape3D> shape = collision_shape->get_shape();
				if (shape.is_valid()) {
					bounds = shape->get_debug_mesh()->get_aabb();
				}
			}
#endif // PHYSICS_2D_DISABLED

I really appreciate The work you are doing since i have been waiting so long for this, thanks.

@AThousandShips
Copy link
Copy Markdown
Member Author

That doesn't sound like it comes from this PR but from:

But enabling building the editor without 3D should include fixing such things, so it's not really related to this PR if it fails with custom code, but if things fail while building the engine itself (not a modified version) please open an issue for it, but custom changes causing issues isn't really something that's related to my work

ERR_FAIL_NULL(parser);

generator_parsers.erase(parser);
#ifndef CLIPPER2_ENABLED
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a typo here. It seems like it should be #ifdef instead of #ifndef.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is it's a typo in the original code, bur worth investing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants