summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-01-08 22:50:05 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-01-08 22:50:05 +0100
commitc3c5eceb350aab5d0e6019ae4e346ab77add458f (patch)
treeb6415e7ea774b727388285c31a1d30fc81b99bf9 /modules
parent98131c0e3232d1812d02a7de8d4a68dee8090cb7 (diff)
parenta0715b30f94430078422ff05d81b9cfa85ddb4ce (diff)
Merge pull request #70463 from DarkKilauea/nav-server-const
[4.x] Rework const on NavigationServer methods
Diffstat (limited to 'modules')
-rw-r--r--modules/gridmap/grid_map.cpp10
-rw-r--r--modules/navigation/godot_navigation_server.cpp116
-rw-r--r--modules/navigation/godot_navigation_server.h26
3 files changed, 79 insertions, 73 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index faee36fb82..3c0bd56e86 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -1310,8 +1310,8 @@ RID GridMap::get_bake_mesh_instance(int p_idx) {
GridMap::GridMap() {
set_notify_transform(true);
#ifdef DEBUG_ENABLED
- NavigationServer3D::get_singleton_mut()->connect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
- NavigationServer3D::get_singleton_mut()->connect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
+ NavigationServer3D::get_singleton()->connect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
+ NavigationServer3D::get_singleton()->connect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
#endif // DEBUG_ENABLED
}
@@ -1338,8 +1338,8 @@ GridMap::~GridMap() {
clear();
#ifdef DEBUG_ENABLED
- NavigationServer3D::get_singleton_mut()->disconnect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
- NavigationServer3D::get_singleton_mut()->disconnect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
+ NavigationServer3D::get_singleton()->disconnect("map_changed", callable_mp(this, &GridMap::_navigation_map_changed));
+ NavigationServer3D::get_singleton()->disconnect("navigation_debug_changed", callable_mp(this, &GridMap::_update_navigation_debug_edge_connections));
#endif // DEBUG_ENABLED
}
@@ -1421,7 +1421,7 @@ void GridMap::_update_octant_navigation_debug_edge_connections_mesh(const Octant
return;
}
- Ref<StandardMaterial3D> edge_connections_material = NavigationServer3D::get_singleton_mut()->get_debug_navigation_edge_connections_material();
+ Ref<StandardMaterial3D> edge_connections_material = NavigationServer3D::get_singleton()->get_debug_navigation_edge_connections_material();
Array mesh_array;
mesh_array.resize(Mesh::ARRAY_MAX);
diff --git a/modules/navigation/godot_navigation_server.cpp b/modules/navigation/godot_navigation_server.cpp
index 4532ea9391..b9b92b77c9 100644
--- a/modules/navigation/godot_navigation_server.cpp
+++ b/modules/navigation/godot_navigation_server.cpp
@@ -52,7 +52,7 @@ using namespace NavigationUtilities;
server->MERGE(_cmd_, F_NAME)(d_0); \
} \
}; \
- void GodotNavigationServer::F_NAME(T_0 D_0) const { \
+ void GodotNavigationServer::F_NAME(T_0 D_0) { \
auto cmd = memnew(MERGE(F_NAME, _command)( \
D_0)); \
add_command(cmd); \
@@ -73,7 +73,7 @@ using namespace NavigationUtilities;
server->MERGE(_cmd_, F_NAME)(d_0, d_1); \
} \
}; \
- void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1) const { \
+ void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1) { \
auto cmd = memnew(MERGE(F_NAME, _command)( \
D_0, \
D_1)); \
@@ -81,34 +81,34 @@ using namespace NavigationUtilities;
} \
void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
-#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \
- struct MERGE(F_NAME, _command) : public SetCommand { \
- T_0 d_0; \
- T_1 d_1; \
- T_2 d_2; \
- T_3 d_3; \
- MERGE(F_NAME, _command) \
- ( \
- T_0 p_d_0, \
- T_1 p_d_1, \
- T_2 p_d_2, \
- T_3 p_d_3) : \
- d_0(p_d_0), \
- d_1(p_d_1), \
- d_2(p_d_2), \
- d_3(p_d_3) {} \
- virtual void exec(GodotNavigationServer *server) override { \
- server->MERGE(_cmd_, F_NAME)(d_0, d_1, d_2, d_3); \
- } \
- }; \
- void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) const { \
- auto cmd = memnew(MERGE(F_NAME, _command)( \
- D_0, \
- D_1, \
- D_2, \
- D_3)); \
- add_command(cmd); \
- } \
+#define COMMAND_4(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3) \
+ struct MERGE(F_NAME, _command) : public SetCommand { \
+ T_0 d_0; \
+ T_1 d_1; \
+ T_2 d_2; \
+ T_3 d_3; \
+ MERGE(F_NAME, _command) \
+ ( \
+ T_0 p_d_0, \
+ T_1 p_d_1, \
+ T_2 p_d_2, \
+ T_3 p_d_3) : \
+ d_0(p_d_0), \
+ d_1(p_d_1), \
+ d_2(p_d_2), \
+ d_3(p_d_3) {} \
+ virtual void exec(GodotNavigationServer *server) override { \
+ server->MERGE(_cmd_, F_NAME)(d_0, d_1, d_2, d_3); \
+ } \
+ }; \
+ void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) { \
+ auto cmd = memnew(MERGE(F_NAME, _command)( \
+ D_0, \
+ D_1, \
+ D_2, \
+ D_3)); \
+ add_command(cmd); \
+ } \
void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3)
GodotNavigationServer::GodotNavigationServer() {}
@@ -117,12 +117,10 @@ GodotNavigationServer::~GodotNavigationServer() {
flush_queries();
}
-void GodotNavigationServer::add_command(SetCommand *command) const {
- GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
- {
- MutexLock lock(commands_mutex);
- mut_this->commands.push_back(command);
- }
+void GodotNavigationServer::add_command(SetCommand *command) {
+ MutexLock lock(commands_mutex);
+
+ commands.push_back(command);
}
TypedArray<RID> GodotNavigationServer::get_maps() const {
@@ -137,12 +135,12 @@ TypedArray<RID> GodotNavigationServer::get_maps() const {
return all_map_rids;
}
-RID GodotNavigationServer::map_create() const {
- GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
- MutexLock lock(mut_this->operations_mutex);
+RID GodotNavigationServer::map_create() {
+ MutexLock lock(operations_mutex);
+
RID rid = map_owner.make_rid();
- NavMap *space = map_owner.get_or_null(rid);
- space->set_self(rid);
+ NavMap *map = map_owner.get_or_null(rid);
+ map->set_self(rid);
return rid;
}
@@ -279,8 +277,10 @@ TypedArray<RID> GodotNavigationServer::map_get_regions(RID p_map) const {
TypedArray<RID> regions_rids;
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_COND_V(map == nullptr, regions_rids);
+
const LocalVector<NavRegion *> regions = map->get_regions();
regions_rids.resize(regions.size());
+
for (uint32_t i = 0; i < regions.size(); i++) {
regions_rids[i] = regions[i]->get_self();
}
@@ -291,8 +291,10 @@ TypedArray<RID> GodotNavigationServer::map_get_agents(RID p_map) const {
TypedArray<RID> agents_rids;
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_COND_V(map == nullptr, agents_rids);
+
const LocalVector<RvoAgent *> agents = map->get_agents();
agents_rids.resize(agents.size());
+
for (uint32_t i = 0; i < agents.size(); i++) {
agents_rids[i] = agents[i]->get_self();
}
@@ -302,6 +304,7 @@ TypedArray<RID> GodotNavigationServer::map_get_agents(RID p_map) const {
RID GodotNavigationServer::region_get_map(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_COND_V(region == nullptr, RID());
+
if (region->get_map()) {
return region->get_map()->get_self();
}
@@ -311,15 +314,16 @@ RID GodotNavigationServer::region_get_map(RID p_region) const {
RID GodotNavigationServer::agent_get_map(RID p_agent) const {
RvoAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_COND_V(agent == nullptr, RID());
+
if (agent->get_map()) {
return agent->get_map()->get_self();
}
return RID();
}
-RID GodotNavigationServer::region_create() const {
- GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
- MutexLock lock(mut_this->operations_mutex);
+RID GodotNavigationServer::region_create() {
+ MutexLock lock(operations_mutex);
+
RID rid = region_owner.make_rid();
NavRegion *reg = region_owner.get_or_null(rid);
reg->set_self(rid);
@@ -402,6 +406,7 @@ ObjectID GodotNavigationServer::region_get_owner_id(RID p_region) const {
bool GodotNavigationServer::region_owns_point(RID p_region, const Vector3 &p_point) const {
const NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_COND_V(region == nullptr, false);
+
if (region->get_map()) {
RID closest_point_owner = map_get_closest_point_owner(region->get_map()->get_self(), p_point);
return closest_point_owner == region->get_self();
@@ -430,7 +435,7 @@ COMMAND_2(region_set_navigation_mesh, RID, p_region, Ref<NavigationMesh>, p_navi
region->set_mesh(p_navigation_mesh);
}
-void GodotNavigationServer::region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) const {
+void GodotNavigationServer::region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) {
ERR_FAIL_COND(p_navigation_mesh.is_null());
ERR_FAIL_COND(p_root_node == nullptr);
@@ -461,9 +466,9 @@ Vector3 GodotNavigationServer::region_get_connection_pathway_end(RID p_region, i
return region->get_connection_pathway_end(p_connection_id);
}
-RID GodotNavigationServer::link_create() const {
- GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
- MutexLock lock(mut_this->operations_mutex);
+RID GodotNavigationServer::link_create() {
+ MutexLock lock(operations_mutex);
+
RID rid = link_owner.make_rid();
NavLink *link = link_owner.get_or_null(rid);
link->set_self(rid);
@@ -600,9 +605,9 @@ ObjectID GodotNavigationServer::link_get_owner_id(RID p_link) const {
return link->get_owner_id();
}
-RID GodotNavigationServer::agent_create() const {
- GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
- MutexLock lock(mut_this->operations_mutex);
+RID GodotNavigationServer::agent_create() {
+ MutexLock lock(operations_mutex);
+
RID rid = agent_owner.make_rid();
RvoAgent *agent = agent_owner.get_or_null(rid);
agent->set_self(rid);
@@ -789,10 +794,10 @@ COMMAND_1(free, RID, p_object) {
}
}
-void GodotNavigationServer::set_active(bool p_active) const {
- GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
- MutexLock lock(mut_this->operations_mutex);
- mut_this->active = p_active;
+void GodotNavigationServer::set_active(bool p_active) {
+ MutexLock lock(operations_mutex);
+
+ active = p_active;
}
void GodotNavigationServer::flush_queries() {
@@ -800,6 +805,7 @@ void GodotNavigationServer::flush_queries() {
// even with mutable functions.
MutexLock lock(commands_mutex);
MutexLock lock2(operations_mutex);
+
for (size_t i(0); i < commands.size(); i++) {
commands[i]->exec(this);
memdelete(commands[i]);
diff --git a/modules/navigation/godot_navigation_server.h b/modules/navigation/godot_navigation_server.h
index 519034119d..7a6e5bb208 100644
--- a/modules/navigation/godot_navigation_server.h
+++ b/modules/navigation/godot_navigation_server.h
@@ -46,16 +46,16 @@
#define MERGE_INTERNAL(A, B) A##B
#define MERGE(A, B) MERGE_INTERNAL(A, B)
-#define COMMAND_1(F_NAME, T_0, D_0) \
- virtual void F_NAME(T_0 D_0) const override; \
+#define COMMAND_1(F_NAME, T_0, D_0) \
+ virtual void F_NAME(T_0 D_0) override; \
void MERGE(_cmd_, F_NAME)(T_0 D_0)
-#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \
- virtual void F_NAME(T_0 D_0, T_1 D_1) const override; \
+#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \
+ virtual void F_NAME(T_0 D_0, T_1 D_1) override; \
void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
-#define COMMAND_4_DEF(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, D_3_DEF) \
- virtual void F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3 = D_3_DEF) const override; \
+#define COMMAND_4_DEF(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, D_3_DEF) \
+ virtual void F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3 = D_3_DEF) override; \
void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3)
class GodotNavigationServer;
@@ -85,11 +85,11 @@ public:
GodotNavigationServer();
virtual ~GodotNavigationServer();
- void add_command(SetCommand *command) const;
+ void add_command(SetCommand *command);
virtual TypedArray<RID> get_maps() const override;
- virtual RID map_create() const override;
+ virtual RID map_create() override;
COMMAND_2(map_set_active, RID, p_map, bool, p_active);
virtual bool map_is_active(RID p_map) const override;
@@ -118,7 +118,7 @@ public:
virtual void map_force_update(RID p_map) override;
- virtual RID region_create() const override;
+ virtual RID region_create() override;
COMMAND_2(region_set_enter_cost, RID, p_region, real_t, p_enter_cost);
virtual real_t region_get_enter_cost(RID p_region) const override;
@@ -136,12 +136,12 @@ public:
virtual uint32_t region_get_navigation_layers(RID p_region) const override;
COMMAND_2(region_set_transform, RID, p_region, Transform3D, p_transform);
COMMAND_2(region_set_navigation_mesh, RID, p_region, Ref<NavigationMesh>, p_navigation_mesh);
- virtual void region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) const override;
+ virtual void region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) override;
virtual int region_get_connections_count(RID p_region) const override;
virtual Vector3 region_get_connection_pathway_start(RID p_region, int p_connection_id) const override;
virtual Vector3 region_get_connection_pathway_end(RID p_region, int p_connection_id) const override;
- virtual RID link_create() const override;
+ virtual RID link_create() override;
COMMAND_2(link_set_map, RID, p_link, RID, p_map);
virtual RID link_get_map(RID p_link) const override;
COMMAND_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional);
@@ -159,7 +159,7 @@ public:
COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id);
virtual ObjectID link_get_owner_id(RID p_link) const override;
- virtual RID agent_create() const override;
+ virtual RID agent_create() override;
COMMAND_2(agent_set_map, RID, p_agent, RID, p_map);
virtual RID agent_get_map(RID p_agent) const override;
COMMAND_2(agent_set_neighbor_distance, RID, p_agent, real_t, p_distance);
@@ -176,7 +176,7 @@ public:
COMMAND_1(free, RID, p_object);
- virtual void set_active(bool p_active) const override;
+ virtual void set_active(bool p_active) override;
void flush_queries();
virtual void process(real_t p_delta_time) override;