Ported: Backport default World navigation maps.

Backports default navigation maps created with each World or World2D.
- smix8
96d98d8c4e
This commit is contained in:
Relintai 2022-07-28 15:04:42 +02:00
parent f23274bbf2
commit a1a7c32f68
7 changed files with 50 additions and 0 deletions

View File

@ -1033,6 +1033,18 @@
<member name="memory/limits/multithreaded_server/rid_pool_prealloc" type="int" setter="" getter="" default="60"> <member name="memory/limits/multithreaded_server/rid_pool_prealloc" type="int" setter="" getter="" default="60">
This is used by servers when used in multi-threading mode (servers and visual). RIDs are preallocated to avoid stalling the server requesting them on threads. If servers get stalled too often when loading resources in a thread, increase this number. This is used by servers when used in multi-threading mode (servers and visual). RIDs are preallocated to avoid stalling the server requesting them on threads. If servers get stalled too often when loading resources in a thread, increase this number.
</member> </member>
<member name="navigation/2d/default_cell_size" type="int" setter="" getter="" default="1">
Default cell size for 2D navigation maps. See [method Navigation2DServer.map_set_cell_size].
</member>
<member name="navigation/2d/default_edge_connection_margin" type="int" setter="" getter="" default="1">
Default edge connection margin for 2D navigation maps. See [method Navigation2DServer.map_set_edge_connection_margin].
</member>
<member name="navigation/3d/default_cell_size" type="float" setter="" getter="" default="0.25">
Default cell size for 3D navigation maps. See [method NavigationServer.map_set_cell_size].
</member>
<member name="navigation/3d/default_edge_connection_margin" type="float" setter="" getter="" default="0.25">
Default edge connection margin for 3D navigation maps. See [method NavigationServer.map_set_edge_connection_margin].
</member>
<member name="network/limits/debugger_stdout/max_chars_per_second" type="int" setter="" getter="" default="2048"> <member name="network/limits/debugger_stdout/max_chars_per_second" type="int" setter="" getter="" default="2048">
Maximum amount of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection. Maximum amount of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection.
</member> </member>

View File

@ -21,6 +21,9 @@
<member name="fallback_environment" type="Environment" setter="set_fallback_environment" getter="get_fallback_environment"> <member name="fallback_environment" type="Environment" setter="set_fallback_environment" getter="get_fallback_environment">
The World's fallback_environment will be used if the World's [Environment] fails or is missing. The World's fallback_environment will be used if the World's [Environment] fails or is missing.
</member> </member>
<member name="navigation_map" type="RID" setter="" getter="get_navigation_map">
The [RID] of this world's navigation map. Used by the [NavigationServer].
</member>
<member name="scenario" type="RID" setter="" getter="get_scenario"> <member name="scenario" type="RID" setter="" getter="get_scenario">
The World's visual scenario. The World's visual scenario.
</member> </member>

View File

@ -18,6 +18,9 @@
<member name="direct_space_state" type="Physics2DDirectSpaceState" setter="" getter="get_direct_space_state"> <member name="direct_space_state" type="Physics2DDirectSpaceState" setter="" getter="get_direct_space_state">
Direct access to the world's physics 2D space state. Used for querying current and potential collisions. When using multi-threaded physics, access is limited to [code]_physics_process(delta)[/code] in the main thread. Direct access to the world's physics 2D space state. Used for querying current and potential collisions. When using multi-threaded physics, access is limited to [code]_physics_process(delta)[/code] in the main thread.
</member> </member>
<member name="navigation_map" type="RID" setter="" getter="get_navigation_map">
The [RID] of this world's navigation map. Used by the [Navigation2DServer].
</member>
<member name="space" type="RID" setter="" getter="get_space"> <member name="space" type="RID" setter="" getter="get_space">
The [RID] of this world's physics space resource. Used by the [Physics2DServer] for 2D physics, treating it as both a space and an area. The [RID] of this world's physics space resource. Used by the [Physics2DServer] for 2D physics, treating it as both a space and an area.
</member> </member>

View File

@ -36,6 +36,7 @@
#include "scene/3d/camera.h" #include "scene/3d/camera.h"
#include "scene/3d/visibility_notifier.h" #include "scene/3d/visibility_notifier.h"
#include "scene/scene_string_names.h" #include "scene/scene_string_names.h"
#include "servers/navigation_server.h"
struct SpatialIndexer { struct SpatialIndexer {
Octree<VisibilityNotifier> octree; Octree<VisibilityNotifier> octree;
@ -261,6 +262,10 @@ RID World::get_scenario() const {
return scenario; return scenario;
} }
RID World::get_navigation_map() const {
return navigation_map;
}
void World::set_environment(const Ref<Environment> &p_environment) { void World::set_environment(const Ref<Environment> &p_environment) {
if (environment == p_environment) { if (environment == p_environment) {
return; return;
@ -312,6 +317,7 @@ void World::get_camera_list(List<Camera *> *r_cameras) {
void World::_bind_methods() { void World::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_space"), &World::get_space); ClassDB::bind_method(D_METHOD("get_space"), &World::get_space);
ClassDB::bind_method(D_METHOD("get_scenario"), &World::get_scenario); ClassDB::bind_method(D_METHOD("get_scenario"), &World::get_scenario);
ClassDB::bind_method(D_METHOD("get_navigation_map"), &World::get_navigation_map);
ClassDB::bind_method(D_METHOD("set_environment", "env"), &World::set_environment); ClassDB::bind_method(D_METHOD("set_environment", "env"), &World::set_environment);
ClassDB::bind_method(D_METHOD("get_environment"), &World::get_environment); ClassDB::bind_method(D_METHOD("get_environment"), &World::get_environment);
ClassDB::bind_method(D_METHOD("set_fallback_environment", "env"), &World::set_fallback_environment); ClassDB::bind_method(D_METHOD("set_fallback_environment", "env"), &World::set_fallback_environment);
@ -321,6 +327,7 @@ void World::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "scenario", PROPERTY_HINT_NONE, "", 0), "", "get_scenario"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "scenario", PROPERTY_HINT_NONE, "", 0), "", "get_scenario");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "navigation_map", PROPERTY_HINT_NONE, "", 0), "", "get_navigation_map");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState", 0), "", "get_direct_space_state"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState", 0), "", "get_direct_space_state");
} }
@ -336,6 +343,11 @@ World::World() {
PhysicsServer::get_singleton()->area_set_param(space, PhysicsServer::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/3d/default_angular_damp", 0.1)); PhysicsServer::get_singleton()->area_set_param(space, PhysicsServer::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/3d/default_angular_damp", 0.1));
ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_angular_damp", PropertyInfo(Variant::REAL, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/default_angular_damp", PropertyInfo(Variant::REAL, "physics/3d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"));
navigation_map = NavigationServer::get_singleton()->map_create();
NavigationServer::get_singleton()->map_set_active(navigation_map, true);
NavigationServer::get_singleton()->map_set_cell_size(navigation_map, GLOBAL_DEF("navigation/3d/default_cell_size", 0.25));
NavigationServer::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_DEF("navigation/3d/default_edge_connection_margin", 0.25));
#ifdef _3D_DISABLED #ifdef _3D_DISABLED
indexer = NULL; indexer = NULL;
#else #else
@ -346,6 +358,7 @@ World::World() {
World::~World() { World::~World() {
PhysicsServer::get_singleton()->free(space); PhysicsServer::get_singleton()->free(space);
VisualServer::get_singleton()->free(scenario); VisualServer::get_singleton()->free(scenario);
NavigationServer::get_singleton()->free(navigation_map);
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
memdelete(indexer); memdelete(indexer);

View File

@ -46,6 +46,7 @@ class World : public Resource {
private: private:
RID space; RID space;
RID scenario; RID scenario;
RID navigation_map;
SpatialIndexer *indexer; SpatialIndexer *indexer;
Ref<Environment> environment; Ref<Environment> environment;
Ref<Environment> fallback_environment; Ref<Environment> fallback_environment;
@ -69,6 +70,7 @@ protected:
public: public:
RID get_space() const; RID get_space() const;
RID get_scenario() const; RID get_scenario() const;
RID get_navigation_map() const;
void set_environment(const Ref<Environment> &p_environment); void set_environment(const Ref<Environment> &p_environment);
Ref<Environment> get_environment() const; Ref<Environment> get_environment() const;

View File

@ -34,6 +34,7 @@
#include "scene/2d/camera_2d.h" #include "scene/2d/camera_2d.h"
#include "scene/2d/visibility_notifier_2d.h" #include "scene/2d/visibility_notifier_2d.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
#include "servers/navigation_2d_server.h"
#include "servers/physics_2d_server.h" #include "servers/physics_2d_server.h"
#include "servers/visual_server.h" #include "servers/visual_server.h"
@ -326,6 +327,10 @@ RID World2D::get_space() {
return space; return space;
} }
RID World2D::get_navigation_map() {
return navigation_map;
}
void World2D::get_viewport_list(List<Viewport *> *r_viewports) { void World2D::get_viewport_list(List<Viewport *> *r_viewports) {
for (Map<Viewport *, SpatialIndexer2D::ViewportData>::Element *E = indexer->viewports.front(); E; E = E->next()) { for (Map<Viewport *, SpatialIndexer2D::ViewportData>::Element *E = indexer->viewports.front(); E; E = E->next()) {
r_viewports->push_back(E->key()); r_viewports->push_back(E->key());
@ -335,11 +340,13 @@ void World2D::get_viewport_list(List<Viewport *> *r_viewports) {
void World2D::_bind_methods() { void World2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_canvas"), &World2D::get_canvas); ClassDB::bind_method(D_METHOD("get_canvas"), &World2D::get_canvas);
ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space); ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space);
ClassDB::bind_method(D_METHOD("get_navigation_map"), &World2D::get_navigation_map);
ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World2D::get_direct_space_state); ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World2D::get_direct_space_state);
ADD_PROPERTY(PropertyInfo(Variant::_RID, "canvas", PROPERTY_HINT_NONE, "", 0), "", "get_canvas"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "canvas", PROPERTY_HINT_NONE, "", 0), "", "get_canvas");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space"); ADD_PROPERTY(PropertyInfo(Variant::_RID, "space", PROPERTY_HINT_NONE, "", 0), "", "get_space");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "navigation_map", PROPERTY_HINT_NONE, "", 0), "", "get_navigation_map");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "Physics2DDirectSpaceState", 0), "", "get_direct_space_state"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "Physics2DDirectSpaceState", 0), "", "get_direct_space_state");
} }
@ -359,11 +366,19 @@ World2D::World2D() {
ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_linear_damp", PropertyInfo(Variant::REAL, "physics/2d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_linear_damp", PropertyInfo(Variant::REAL, "physics/2d/default_linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"));
Physics2DServer::get_singleton()->area_set_param(space, Physics2DServer::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/2d/default_angular_damp", 1.0)); Physics2DServer::get_singleton()->area_set_param(space, Physics2DServer::AREA_PARAM_ANGULAR_DAMP, GLOBAL_DEF("physics/2d/default_angular_damp", 1.0));
ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_angular_damp", PropertyInfo(Variant::REAL, "physics/2d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater")); ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/default_angular_damp", PropertyInfo(Variant::REAL, "physics/2d/default_angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"));
// Create and configure the navigation_map to be more friendly with pixels than meters.
navigation_map = Navigation2DServer::get_singleton()->map_create();
Navigation2DServer::get_singleton()->map_set_active(navigation_map, true);
Navigation2DServer::get_singleton()->map_set_cell_size(navigation_map, GLOBAL_DEF("navigation/2d/default_cell_size", 1));
Navigation2DServer::get_singleton()->map_set_edge_connection_margin(navigation_map, GLOBAL_DEF("navigation/2d/default_edge_connection_margin", 1));
indexer = memnew(SpatialIndexer2D); indexer = memnew(SpatialIndexer2D);
} }
World2D::~World2D() { World2D::~World2D() {
VisualServer::get_singleton()->free(canvas); VisualServer::get_singleton()->free(canvas);
Physics2DServer::get_singleton()->free(space); Physics2DServer::get_singleton()->free(space);
Navigation2DServer::get_singleton()->free(navigation_map);
memdelete(indexer); memdelete(indexer);
} }

View File

@ -43,6 +43,7 @@ class World2D : public Resource {
RID canvas; RID canvas;
RID space; RID space;
RID navigation_map;
SpatialIndexer2D *indexer; SpatialIndexer2D *indexer;
@ -64,6 +65,7 @@ protected:
public: public:
RID get_canvas(); RID get_canvas();
RID get_space(); RID get_space();
RID get_navigation_map();
Physics2DDirectSpaceState *get_direct_space_state(); Physics2DDirectSpaceState *get_direct_space_state();