Move 3D-only navigation code to its own subfolder

This commit is contained in:
Aaron Franke 2023-10-13 10:20:31 -05:00
parent fd582dca62
commit 138180fe01
No known key found for this signature in database
GPG Key ID: 40A1750B977E56BF
8 changed files with 155 additions and 153 deletions

View File

@ -1,5 +1,5 @@
/**************************************************************************/
/* godot_navigation_server.cpp */
/* godot_navigation_server_3d.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#include "godot_navigation_server.h"
#include "godot_navigation_server_3d.h"
#ifndef _3D_DISABLED
#include "nav_mesh_generator_3d.h"
@ -42,58 +42,58 @@ using namespace NavigationUtilities;
/// an instance of that struct with the submitted parameters.
/// Then, that struct is stored in an array; the `sync` function consume that array.
#define COMMAND_1(F_NAME, T_0, D_0) \
struct MERGE(F_NAME, _command) : public SetCommand { \
T_0 d_0; \
MERGE(F_NAME, _command) \
(T_0 p_d_0) : \
d_0(p_d_0) {} \
virtual void exec(GodotNavigationServer *server) override { \
server->MERGE(_cmd_, F_NAME)(d_0); \
} \
}; \
void GodotNavigationServer::F_NAME(T_0 D_0) { \
auto cmd = memnew(MERGE(F_NAME, _command)( \
D_0)); \
add_command(cmd); \
} \
void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0)
#define COMMAND_1(F_NAME, T_0, D_0) \
struct MERGE(F_NAME, _command) : public SetCommand { \
T_0 d_0; \
MERGE(F_NAME, _command) \
(T_0 p_d_0) : \
d_0(p_d_0) {} \
virtual void exec(GodotNavigationServer3D *server) override { \
server->MERGE(_cmd_, F_NAME)(d_0); \
} \
}; \
void GodotNavigationServer3D::F_NAME(T_0 D_0) { \
auto cmd = memnew(MERGE(F_NAME, _command)( \
D_0)); \
add_command(cmd); \
} \
void GodotNavigationServer3D::MERGE(_cmd_, F_NAME)(T_0 D_0)
#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \
struct MERGE(F_NAME, _command) : public SetCommand { \
T_0 d_0; \
T_1 d_1; \
MERGE(F_NAME, _command) \
( \
T_0 p_d_0, \
T_1 p_d_1) : \
d_0(p_d_0), \
d_1(p_d_1) {} \
virtual void exec(GodotNavigationServer *server) override { \
server->MERGE(_cmd_, F_NAME)(d_0, d_1); \
} \
}; \
void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1) { \
auto cmd = memnew(MERGE(F_NAME, _command)( \
D_0, \
D_1)); \
add_command(cmd); \
} \
void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
#define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \
struct MERGE(F_NAME, _command) : public SetCommand { \
T_0 d_0; \
T_1 d_1; \
MERGE(F_NAME, _command) \
( \
T_0 p_d_0, \
T_1 p_d_1) : \
d_0(p_d_0), \
d_1(p_d_1) {} \
virtual void exec(GodotNavigationServer3D *server) override { \
server->MERGE(_cmd_, F_NAME)(d_0, d_1); \
} \
}; \
void GodotNavigationServer3D::F_NAME(T_0 D_0, T_1 D_1) { \
auto cmd = memnew(MERGE(F_NAME, _command)( \
D_0, \
D_1)); \
add_command(cmd); \
} \
void GodotNavigationServer3D::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
GodotNavigationServer::GodotNavigationServer() {}
GodotNavigationServer3D::GodotNavigationServer3D() {}
GodotNavigationServer::~GodotNavigationServer() {
GodotNavigationServer3D::~GodotNavigationServer3D() {
flush_queries();
}
void GodotNavigationServer::add_command(SetCommand *command) {
void GodotNavigationServer3D::add_command(SetCommand *command) {
MutexLock lock(commands_mutex);
commands.push_back(command);
}
TypedArray<RID> GodotNavigationServer::get_maps() const {
TypedArray<RID> GodotNavigationServer3D::get_maps() const {
TypedArray<RID> all_map_rids;
List<RID> maps_owned;
map_owner.get_owned_list(&maps_owned);
@ -105,7 +105,7 @@ TypedArray<RID> GodotNavigationServer::get_maps() const {
return all_map_rids;
}
RID GodotNavigationServer::map_create() {
RID GodotNavigationServer3D::map_create() {
MutexLock lock(operations_mutex);
RID rid = map_owner.make_rid();
@ -131,7 +131,7 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
}
}
bool GodotNavigationServer::map_is_active(RID p_map) const {
bool GodotNavigationServer3D::map_is_active(RID p_map) const {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, false);
@ -145,7 +145,7 @@ COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) {
map->set_up(p_up);
}
Vector3 GodotNavigationServer::map_get_up(RID p_map) const {
Vector3 GodotNavigationServer3D::map_get_up(RID p_map) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector3());
@ -159,7 +159,7 @@ COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) {
map->set_cell_size(p_cell_size);
}
real_t GodotNavigationServer::map_get_cell_size(RID p_map) const {
real_t GodotNavigationServer3D::map_get_cell_size(RID p_map) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, 0);
@ -173,7 +173,7 @@ COMMAND_2(map_set_cell_height, RID, p_map, real_t, p_cell_height) {
map->set_cell_height(p_cell_height);
}
real_t GodotNavigationServer::map_get_cell_height(RID p_map) const {
real_t GodotNavigationServer3D::map_get_cell_height(RID p_map) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, 0);
@ -187,7 +187,7 @@ COMMAND_2(map_set_merge_rasterizer_cell_scale, RID, p_map, float, p_value) {
map->set_merge_rasterizer_cell_scale(p_value);
}
float GodotNavigationServer::map_get_merge_rasterizer_cell_scale(RID p_map) const {
float GodotNavigationServer3D::map_get_merge_rasterizer_cell_scale(RID p_map) const {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, false);
@ -201,7 +201,7 @@ COMMAND_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled) {
map->set_use_edge_connections(p_enabled);
}
bool GodotNavigationServer::map_get_use_edge_connections(RID p_map) const {
bool GodotNavigationServer3D::map_get_use_edge_connections(RID p_map) const {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, false);
@ -215,7 +215,7 @@ COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margi
map->set_edge_connection_margin(p_connection_margin);
}
real_t GodotNavigationServer::map_get_edge_connection_margin(RID p_map) const {
real_t GodotNavigationServer3D::map_get_edge_connection_margin(RID p_map) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, 0);
@ -229,49 +229,49 @@ COMMAND_2(map_set_link_connection_radius, RID, p_map, real_t, p_connection_radiu
map->set_link_connection_radius(p_connection_radius);
}
real_t GodotNavigationServer::map_get_link_connection_radius(RID p_map) const {
real_t GodotNavigationServer3D::map_get_link_connection_radius(RID p_map) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, 0);
return map->get_link_connection_radius();
}
Vector<Vector3> GodotNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_navigation_layers) const {
Vector<Vector3> GodotNavigationServer3D::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_navigation_layers) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector<Vector3>());
return map->get_path(p_origin, p_destination, p_optimize, p_navigation_layers, nullptr, nullptr, nullptr);
}
Vector3 GodotNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
Vector3 GodotNavigationServer3D::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector3());
return map->get_closest_point_to_segment(p_from, p_to, p_use_collision);
}
Vector3 GodotNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const {
Vector3 GodotNavigationServer3D::map_get_closest_point(RID p_map, const Vector3 &p_point) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector3());
return map->get_closest_point(p_point);
}
Vector3 GodotNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const {
Vector3 GodotNavigationServer3D::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector3());
return map->get_closest_point_normal(p_point);
}
RID GodotNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const {
RID GodotNavigationServer3D::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, RID());
return map->get_closest_point_owner(p_point);
}
TypedArray<RID> GodotNavigationServer::map_get_links(RID p_map) const {
TypedArray<RID> GodotNavigationServer3D::map_get_links(RID p_map) const {
TypedArray<RID> link_rids;
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, link_rids);
@ -285,7 +285,7 @@ TypedArray<RID> GodotNavigationServer::map_get_links(RID p_map) const {
return link_rids;
}
TypedArray<RID> GodotNavigationServer::map_get_regions(RID p_map) const {
TypedArray<RID> GodotNavigationServer3D::map_get_regions(RID p_map) const {
TypedArray<RID> regions_rids;
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, regions_rids);
@ -299,7 +299,7 @@ TypedArray<RID> GodotNavigationServer::map_get_regions(RID p_map) const {
return regions_rids;
}
TypedArray<RID> GodotNavigationServer::map_get_agents(RID p_map) const {
TypedArray<RID> GodotNavigationServer3D::map_get_agents(RID p_map) const {
TypedArray<RID> agents_rids;
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, agents_rids);
@ -313,7 +313,7 @@ TypedArray<RID> GodotNavigationServer::map_get_agents(RID p_map) const {
return agents_rids;
}
TypedArray<RID> GodotNavigationServer::map_get_obstacles(RID p_map) const {
TypedArray<RID> GodotNavigationServer3D::map_get_obstacles(RID p_map) const {
TypedArray<RID> obstacles_rids;
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, obstacles_rids);
@ -325,7 +325,7 @@ TypedArray<RID> GodotNavigationServer::map_get_obstacles(RID p_map) const {
return obstacles_rids;
}
RID GodotNavigationServer::region_get_map(RID p_region) const {
RID GodotNavigationServer3D::region_get_map(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, RID());
@ -335,7 +335,7 @@ RID GodotNavigationServer::region_get_map(RID p_region) const {
return RID();
}
RID GodotNavigationServer::agent_get_map(RID p_agent) const {
RID GodotNavigationServer3D::agent_get_map(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, RID());
@ -345,14 +345,14 @@ RID GodotNavigationServer::agent_get_map(RID p_agent) const {
return RID();
}
Vector3 GodotNavigationServer::map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const {
Vector3 GodotNavigationServer3D::map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector3());
return map->get_random_point(p_navigation_layers, p_uniformly);
}
RID GodotNavigationServer::region_create() {
RID GodotNavigationServer3D::region_create() {
MutexLock lock(operations_mutex);
RID rid = region_owner.make_rid();
@ -368,7 +368,7 @@ COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled) {
region->set_enabled(p_enabled);
}
bool GodotNavigationServer::region_get_enabled(RID p_region) const {
bool GodotNavigationServer3D::region_get_enabled(RID p_region) const {
const NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, false);
@ -382,7 +382,7 @@ COMMAND_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled) {
region->set_use_edge_connections(p_enabled);
}
bool GodotNavigationServer::region_get_use_edge_connections(RID p_region) const {
bool GodotNavigationServer3D::region_get_use_edge_connections(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, false);
@ -405,7 +405,7 @@ COMMAND_2(region_set_transform, RID, p_region, Transform3D, p_transform) {
region->set_transform(p_transform);
}
Transform3D GodotNavigationServer::region_get_transform(RID p_region) const {
Transform3D GodotNavigationServer3D::region_get_transform(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, Transform3D());
@ -420,7 +420,7 @@ COMMAND_2(region_set_enter_cost, RID, p_region, real_t, p_enter_cost) {
region->set_enter_cost(p_enter_cost);
}
real_t GodotNavigationServer::region_get_enter_cost(RID p_region) const {
real_t GodotNavigationServer3D::region_get_enter_cost(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, 0);
@ -435,7 +435,7 @@ COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost) {
region->set_travel_cost(p_travel_cost);
}
real_t GodotNavigationServer::region_get_travel_cost(RID p_region) const {
real_t GodotNavigationServer3D::region_get_travel_cost(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, 0);
@ -449,14 +449,14 @@ COMMAND_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id) {
region->set_owner_id(p_owner_id);
}
ObjectID GodotNavigationServer::region_get_owner_id(RID p_region) const {
ObjectID GodotNavigationServer3D::region_get_owner_id(RID p_region) const {
const NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, ObjectID());
return region->get_owner_id();
}
bool GodotNavigationServer::region_owns_point(RID p_region, const Vector3 &p_point) const {
bool GodotNavigationServer3D::region_owns_point(RID p_region, const Vector3 &p_point) const {
const NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, false);
@ -474,7 +474,7 @@ COMMAND_2(region_set_navigation_layers, RID, p_region, uint32_t, p_navigation_la
region->set_navigation_layers(p_navigation_layers);
}
uint32_t GodotNavigationServer::region_get_navigation_layers(RID p_region) const {
uint32_t GodotNavigationServer3D::region_get_navigation_layers(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, 0);
@ -489,7 +489,7 @@ COMMAND_2(region_set_navigation_mesh, RID, p_region, Ref<NavigationMesh>, p_navi
}
#ifndef DISABLE_DEPRECATED
void GodotNavigationServer::region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) {
void GodotNavigationServer3D::region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) {
ERR_FAIL_COND(p_navigation_mesh.is_null());
ERR_FAIL_NULL(p_root_node);
@ -505,35 +505,35 @@ void GodotNavigationServer::region_bake_navigation_mesh(Ref<NavigationMesh> p_na
}
#endif // DISABLE_DEPRECATED
int GodotNavigationServer::region_get_connections_count(RID p_region) const {
int GodotNavigationServer3D::region_get_connections_count(RID p_region) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, 0);
return region->get_connections_count();
}
Vector3 GodotNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const {
Vector3 GodotNavigationServer3D::region_get_connection_pathway_start(RID p_region, int p_connection_id) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, Vector3());
return region->get_connection_pathway_start(p_connection_id);
}
Vector3 GodotNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const {
Vector3 GodotNavigationServer3D::region_get_connection_pathway_end(RID p_region, int p_connection_id) const {
NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, Vector3());
return region->get_connection_pathway_end(p_connection_id);
}
Vector3 GodotNavigationServer::region_get_random_point(RID p_region, uint32_t p_navigation_layers, bool p_uniformly) const {
Vector3 GodotNavigationServer3D::region_get_random_point(RID p_region, uint32_t p_navigation_layers, bool p_uniformly) const {
const NavRegion *region = region_owner.get_or_null(p_region);
ERR_FAIL_NULL_V(region, Vector3());
return region->get_random_point(p_navigation_layers, p_uniformly);
}
RID GodotNavigationServer::link_create() {
RID GodotNavigationServer3D::link_create() {
MutexLock lock(operations_mutex);
RID rid = link_owner.make_rid();
@ -551,7 +551,7 @@ COMMAND_2(link_set_map, RID, p_link, RID, p_map) {
link->set_map(map);
}
RID GodotNavigationServer::link_get_map(const RID p_link) const {
RID GodotNavigationServer3D::link_get_map(const RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, RID());
@ -568,7 +568,7 @@ COMMAND_2(link_set_enabled, RID, p_link, bool, p_enabled) {
link->set_enabled(p_enabled);
}
bool GodotNavigationServer::link_get_enabled(RID p_link) const {
bool GodotNavigationServer3D::link_get_enabled(RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, false);
@ -582,7 +582,7 @@ COMMAND_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional) {
link->set_bidirectional(p_bidirectional);
}
bool GodotNavigationServer::link_is_bidirectional(RID p_link) const {
bool GodotNavigationServer3D::link_is_bidirectional(RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, false);
@ -596,7 +596,7 @@ COMMAND_2(link_set_navigation_layers, RID, p_link, uint32_t, p_navigation_layers
link->set_navigation_layers(p_navigation_layers);
}
uint32_t GodotNavigationServer::link_get_navigation_layers(const RID p_link) const {
uint32_t GodotNavigationServer3D::link_get_navigation_layers(const RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, 0);
@ -610,7 +610,7 @@ COMMAND_2(link_set_start_position, RID, p_link, Vector3, p_position) {
link->set_start_position(p_position);
}
Vector3 GodotNavigationServer::link_get_start_position(RID p_link) const {
Vector3 GodotNavigationServer3D::link_get_start_position(RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, Vector3());
@ -624,7 +624,7 @@ COMMAND_2(link_set_end_position, RID, p_link, Vector3, p_position) {
link->set_end_position(p_position);
}
Vector3 GodotNavigationServer::link_get_end_position(RID p_link) const {
Vector3 GodotNavigationServer3D::link_get_end_position(RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, Vector3());
@ -638,7 +638,7 @@ COMMAND_2(link_set_enter_cost, RID, p_link, real_t, p_enter_cost) {
link->set_enter_cost(p_enter_cost);
}
real_t GodotNavigationServer::link_get_enter_cost(const RID p_link) const {
real_t GodotNavigationServer3D::link_get_enter_cost(const RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, 0);
@ -652,7 +652,7 @@ COMMAND_2(link_set_travel_cost, RID, p_link, real_t, p_travel_cost) {
link->set_travel_cost(p_travel_cost);
}
real_t GodotNavigationServer::link_get_travel_cost(const RID p_link) const {
real_t GodotNavigationServer3D::link_get_travel_cost(const RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, 0);
@ -666,14 +666,14 @@ COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id) {
link->set_owner_id(p_owner_id);
}
ObjectID GodotNavigationServer::link_get_owner_id(RID p_link) const {
ObjectID GodotNavigationServer3D::link_get_owner_id(RID p_link) const {
const NavLink *link = link_owner.get_or_null(p_link);
ERR_FAIL_NULL_V(link, ObjectID());
return link->get_owner_id();
}
RID GodotNavigationServer::agent_create() {
RID GodotNavigationServer3D::agent_create() {
MutexLock lock(operations_mutex);
RID rid = agent_owner.make_rid();
@ -689,7 +689,7 @@ COMMAND_2(agent_set_avoidance_enabled, RID, p_agent, bool, p_enabled) {
agent->set_avoidance_enabled(p_enabled);
}
bool GodotNavigationServer::agent_get_avoidance_enabled(RID p_agent) const {
bool GodotNavigationServer3D::agent_get_avoidance_enabled(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, false);
@ -703,7 +703,7 @@ COMMAND_2(agent_set_use_3d_avoidance, RID, p_agent, bool, p_enabled) {
agent->set_use_3d_avoidance(p_enabled);
}
bool GodotNavigationServer::agent_get_use_3d_avoidance(RID p_agent) const {
bool GodotNavigationServer3D::agent_get_use_3d_avoidance(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, false);
@ -726,7 +726,7 @@ COMMAND_2(agent_set_paused, RID, p_agent, bool, p_paused) {
agent->set_paused(p_paused);
}
bool GodotNavigationServer::agent_get_paused(RID p_agent) const {
bool GodotNavigationServer3D::agent_get_paused(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, false);
@ -740,7 +740,7 @@ COMMAND_2(agent_set_neighbor_distance, RID, p_agent, real_t, p_distance) {
agent->set_neighbor_distance(p_distance);
}
real_t GodotNavigationServer::agent_get_neighbor_distance(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_neighbor_distance(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -754,7 +754,7 @@ COMMAND_2(agent_set_max_neighbors, RID, p_agent, int, p_count) {
agent->set_max_neighbors(p_count);
}
int GodotNavigationServer::agent_get_max_neighbors(RID p_agent) const {
int GodotNavigationServer3D::agent_get_max_neighbors(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -769,7 +769,7 @@ COMMAND_2(agent_set_time_horizon_agents, RID, p_agent, real_t, p_time_horizon) {
agent->set_time_horizon_agents(p_time_horizon);
}
real_t GodotNavigationServer::agent_get_time_horizon_agents(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_time_horizon_agents(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -784,7 +784,7 @@ COMMAND_2(agent_set_time_horizon_obstacles, RID, p_agent, real_t, p_time_horizon
agent->set_time_horizon_obstacles(p_time_horizon);
}
real_t GodotNavigationServer::agent_get_time_horizon_obstacles(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_time_horizon_obstacles(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -799,7 +799,7 @@ COMMAND_2(agent_set_radius, RID, p_agent, real_t, p_radius) {
agent->set_radius(p_radius);
}
real_t GodotNavigationServer::agent_get_radius(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_radius(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -814,7 +814,7 @@ COMMAND_2(agent_set_height, RID, p_agent, real_t, p_height) {
agent->set_height(p_height);
}
real_t GodotNavigationServer::agent_get_height(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_height(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -829,7 +829,7 @@ COMMAND_2(agent_set_max_speed, RID, p_agent, real_t, p_max_speed) {
agent->set_max_speed(p_max_speed);
}
real_t GodotNavigationServer::agent_get_max_speed(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_max_speed(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -843,7 +843,7 @@ COMMAND_2(agent_set_velocity, RID, p_agent, Vector3, p_velocity) {
agent->set_velocity(p_velocity);
}
Vector3 GodotNavigationServer::agent_get_velocity(RID p_agent) const {
Vector3 GodotNavigationServer3D::agent_get_velocity(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, Vector3());
@ -864,14 +864,14 @@ COMMAND_2(agent_set_position, RID, p_agent, Vector3, p_position) {
agent->set_position(p_position);
}
Vector3 GodotNavigationServer::agent_get_position(RID p_agent) const {
Vector3 GodotNavigationServer3D::agent_get_position(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, Vector3());
return agent->get_position();
}
bool GodotNavigationServer::agent_is_map_changed(RID p_agent) const {
bool GodotNavigationServer3D::agent_is_map_changed(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, false);
@ -893,7 +893,7 @@ COMMAND_2(agent_set_avoidance_callback, RID, p_agent, Callable, p_callback) {
}
}
bool GodotNavigationServer::agent_has_avoidance_callback(RID p_agent) const {
bool GodotNavigationServer3D::agent_has_avoidance_callback(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, false);
@ -906,7 +906,7 @@ COMMAND_2(agent_set_avoidance_layers, RID, p_agent, uint32_t, p_layers) {
agent->set_avoidance_layers(p_layers);
}
uint32_t GodotNavigationServer::agent_get_avoidance_layers(RID p_agent) const {
uint32_t GodotNavigationServer3D::agent_get_avoidance_layers(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -919,7 +919,7 @@ COMMAND_2(agent_set_avoidance_mask, RID, p_agent, uint32_t, p_mask) {
agent->set_avoidance_mask(p_mask);
}
uint32_t GodotNavigationServer::agent_get_avoidance_mask(RID p_agent) const {
uint32_t GodotNavigationServer3D::agent_get_avoidance_mask(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
@ -934,14 +934,14 @@ COMMAND_2(agent_set_avoidance_priority, RID, p_agent, real_t, p_priority) {
agent->set_avoidance_priority(p_priority);
}
real_t GodotNavigationServer::agent_get_avoidance_priority(RID p_agent) const {
real_t GodotNavigationServer3D::agent_get_avoidance_priority(RID p_agent) const {
NavAgent *agent = agent_owner.get_or_null(p_agent);
ERR_FAIL_NULL_V(agent, 0);
return agent->get_avoidance_priority();
}
RID GodotNavigationServer::obstacle_create() {
RID GodotNavigationServer3D::obstacle_create() {
MutexLock lock(operations_mutex);
RID rid = obstacle_owner.make_rid();
@ -964,7 +964,7 @@ COMMAND_2(obstacle_set_avoidance_enabled, RID, p_obstacle, bool, p_enabled) {
obstacle->set_avoidance_enabled(p_enabled);
}
bool GodotNavigationServer::obstacle_get_avoidance_enabled(RID p_obstacle) const {
bool GodotNavigationServer3D::obstacle_get_avoidance_enabled(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, false);
@ -978,7 +978,7 @@ COMMAND_2(obstacle_set_use_3d_avoidance, RID, p_obstacle, bool, p_enabled) {
obstacle->set_use_3d_avoidance(p_enabled);
}
bool GodotNavigationServer::obstacle_get_use_3d_avoidance(RID p_obstacle) const {
bool GodotNavigationServer3D::obstacle_get_use_3d_avoidance(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, false);
@ -994,7 +994,7 @@ COMMAND_2(obstacle_set_map, RID, p_obstacle, RID, p_map) {
obstacle->set_map(map);
}
RID GodotNavigationServer::obstacle_get_map(RID p_obstacle) const {
RID GodotNavigationServer3D::obstacle_get_map(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, RID());
if (obstacle->get_map()) {
@ -1010,7 +1010,7 @@ COMMAND_2(obstacle_set_paused, RID, p_obstacle, bool, p_paused) {
obstacle->set_paused(p_paused);
}
bool GodotNavigationServer::obstacle_get_paused(RID p_obstacle) const {
bool GodotNavigationServer3D::obstacle_get_paused(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, false);
@ -1025,7 +1025,7 @@ COMMAND_2(obstacle_set_radius, RID, p_obstacle, real_t, p_radius) {
obstacle->set_radius(p_radius);
}
real_t GodotNavigationServer::obstacle_get_radius(RID p_obstacle) const {
real_t GodotNavigationServer3D::obstacle_get_radius(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, 0);
@ -1038,7 +1038,7 @@ COMMAND_2(obstacle_set_height, RID, p_obstacle, real_t, p_height) {
obstacle->set_height(p_height);
}
real_t GodotNavigationServer::obstacle_get_height(RID p_obstacle) const {
real_t GodotNavigationServer3D::obstacle_get_height(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, 0);
@ -1052,7 +1052,7 @@ COMMAND_2(obstacle_set_velocity, RID, p_obstacle, Vector3, p_velocity) {
obstacle->set_velocity(p_velocity);
}
Vector3 GodotNavigationServer::obstacle_get_velocity(RID p_obstacle) const {
Vector3 GodotNavigationServer3D::obstacle_get_velocity(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, Vector3());
@ -1065,20 +1065,20 @@ COMMAND_2(obstacle_set_position, RID, p_obstacle, Vector3, p_position) {
obstacle->set_position(p_position);
}
Vector3 GodotNavigationServer::obstacle_get_position(RID p_obstacle) const {
Vector3 GodotNavigationServer3D::obstacle_get_position(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, Vector3());
return obstacle->get_position();
}
void GodotNavigationServer::obstacle_set_vertices(RID p_obstacle, const Vector<Vector3> &p_vertices) {
void GodotNavigationServer3D::obstacle_set_vertices(RID p_obstacle, const Vector<Vector3> &p_vertices) {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL(obstacle);
obstacle->set_vertices(p_vertices);
}
Vector<Vector3> GodotNavigationServer::obstacle_get_vertices(RID p_obstacle) const {
Vector<Vector3> GodotNavigationServer3D::obstacle_get_vertices(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, Vector<Vector3>());
@ -1091,14 +1091,14 @@ COMMAND_2(obstacle_set_avoidance_layers, RID, p_obstacle, uint32_t, p_layers) {
obstacle->set_avoidance_layers(p_layers);
}
uint32_t GodotNavigationServer::obstacle_get_avoidance_layers(RID p_obstacle) const {
uint32_t GodotNavigationServer3D::obstacle_get_avoidance_layers(RID p_obstacle) const {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
ERR_FAIL_NULL_V(obstacle, 0);
return obstacle->get_avoidance_layers();
}
void GodotNavigationServer::parse_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, Node *p_root_node, const Callable &p_callback) {
void GodotNavigationServer3D::parse_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, Node *p_root_node, const Callable &p_callback) {
#ifndef _3D_DISABLED
ERR_FAIL_COND_MSG(!Thread::is_main_thread(), "The SceneTree can only be parsed on the main thread. Call this function from the main thread or use call_deferred().");
ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh.");
@ -1110,7 +1110,7 @@ void GodotNavigationServer::parse_source_geometry_data(const Ref<NavigationMesh>
#endif // _3D_DISABLED
}
void GodotNavigationServer::bake_from_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, const Callable &p_callback) {
void GodotNavigationServer3D::bake_from_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, const Callable &p_callback) {
#ifndef _3D_DISABLED
ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh.");
ERR_FAIL_COND_MSG(!p_source_geometry_data.is_valid(), "Invalid NavigationMeshSourceGeometryData3D.");
@ -1120,7 +1120,7 @@ void GodotNavigationServer::bake_from_source_geometry_data(const Ref<NavigationM
#endif // _3D_DISABLED
}
void GodotNavigationServer::bake_from_source_geometry_data_async(const Ref<NavigationMesh> &p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, const Callable &p_callback) {
void GodotNavigationServer3D::bake_from_source_geometry_data_async(const Ref<NavigationMesh> &p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, const Callable &p_callback) {
#ifndef _3D_DISABLED
ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh.");
ERR_FAIL_COND_MSG(!p_source_geometry_data.is_valid(), "Invalid NavigationMeshSourceGeometryData3D.");
@ -1130,7 +1130,7 @@ void GodotNavigationServer::bake_from_source_geometry_data_async(const Ref<Navig
#endif // _3D_DISABLED
}
bool GodotNavigationServer::is_baking_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh) const {
bool GodotNavigationServer3D::is_baking_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh) const {
#ifdef _3D_DISABLED
return false;
#else
@ -1206,7 +1206,7 @@ COMMAND_1(free, RID, p_object) {
}
}
void GodotNavigationServer::internal_free_agent(RID p_object) {
void GodotNavigationServer3D::internal_free_agent(RID p_object) {
NavAgent *agent = agent_owner.get_or_null(p_object);
if (agent) {
if (agent->get_map() != nullptr) {
@ -1217,7 +1217,7 @@ void GodotNavigationServer::internal_free_agent(RID p_object) {
}
}
void GodotNavigationServer::internal_free_obstacle(RID p_object) {
void GodotNavigationServer3D::internal_free_obstacle(RID p_object) {
NavObstacle *obstacle = obstacle_owner.get_or_null(p_object);
if (obstacle) {
NavAgent *obstacle_agent = obstacle->get_agent();
@ -1234,13 +1234,13 @@ void GodotNavigationServer::internal_free_obstacle(RID p_object) {
}
}
void GodotNavigationServer::set_active(bool p_active) {
void GodotNavigationServer3D::set_active(bool p_active) {
MutexLock lock(operations_mutex);
active = p_active;
}
void GodotNavigationServer::flush_queries() {
void GodotNavigationServer3D::flush_queries() {
// In c++ we can't be sure that this is performed in the main thread
// even with mutable functions.
MutexLock lock(commands_mutex);
@ -1253,7 +1253,7 @@ void GodotNavigationServer::flush_queries() {
commands.clear();
}
void GodotNavigationServer::map_force_update(RID p_map) {
void GodotNavigationServer3D::map_force_update(RID p_map) {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL(map);
@ -1262,14 +1262,14 @@ void GodotNavigationServer::map_force_update(RID p_map) {
map->sync();
}
uint32_t GodotNavigationServer::map_get_iteration_id(RID p_map) const {
uint32_t GodotNavigationServer3D::map_get_iteration_id(RID p_map) const {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, 0);
return map->get_iteration_id();
}
void GodotNavigationServer::sync() {
void GodotNavigationServer3D::sync() {
#ifndef _3D_DISABLED
if (navmesh_generator_3d) {
navmesh_generator_3d->sync();
@ -1277,7 +1277,7 @@ void GodotNavigationServer::sync() {
#endif // _3D_DISABLED
}
void GodotNavigationServer::process(real_t p_delta_time) {
void GodotNavigationServer3D::process(real_t p_delta_time) {
flush_queries();
if (!active) {
@ -1328,13 +1328,13 @@ void GodotNavigationServer::process(real_t p_delta_time) {
pm_edge_free_count = _new_pm_edge_free_count;
}
void GodotNavigationServer::init() {
void GodotNavigationServer3D::init() {
#ifndef _3D_DISABLED
navmesh_generator_3d = memnew(NavMeshGenerator3D);
#endif // _3D_DISABLED
}
void GodotNavigationServer::finish() {
void GodotNavigationServer3D::finish() {
flush_queries();
#ifndef _3D_DISABLED
if (navmesh_generator_3d) {
@ -1345,7 +1345,7 @@ void GodotNavigationServer::finish() {
#endif // _3D_DISABLED
}
PathQueryResult GodotNavigationServer::_query_path(const PathQueryParameters &p_parameters) const {
PathQueryResult GodotNavigationServer3D::_query_path(const PathQueryParameters &p_parameters) const {
PathQueryResult r_query_result;
const NavMap *map = map_owner.get_or_null(p_parameters.map);
@ -1385,7 +1385,7 @@ PathQueryResult GodotNavigationServer::_query_path(const PathQueryParameters &p_
return r_query_result;
}
int GodotNavigationServer::get_process_info(ProcessInfo p_info) const {
int GodotNavigationServer3D::get_process_info(ProcessInfo p_info) const {
switch (p_info) {
case INFO_ACTIVE_MAPS: {
return active_maps.size();

View File

@ -1,5 +1,5 @@
/**************************************************************************/
/* godot_navigation_server.h */
/* godot_navigation_server_3d.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@ -28,14 +28,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef GODOT_NAVIGATION_SERVER_H
#define GODOT_NAVIGATION_SERVER_H
#ifndef GODOT_NAVIGATION_SERVER_3D_H
#define GODOT_NAVIGATION_SERVER_3D_H
#include "nav_agent.h"
#include "nav_link.h"
#include "nav_map.h"
#include "nav_obstacle.h"
#include "nav_region.h"
#include "../nav_agent.h"
#include "../nav_link.h"
#include "../nav_map.h"
#include "../nav_obstacle.h"
#include "../nav_region.h"
#include "core/templates/local_vector.h"
#include "core/templates/rid.h"
@ -55,17 +55,17 @@
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)
class GodotNavigationServer;
class GodotNavigationServer3D;
#ifndef _3D_DISABLED
class NavMeshGenerator3D;
#endif // _3D_DISABLED
struct SetCommand {
virtual ~SetCommand() {}
virtual void exec(GodotNavigationServer *server) = 0;
virtual void exec(GodotNavigationServer3D *server) = 0;
};
class GodotNavigationServer : public NavigationServer3D {
class GodotNavigationServer3D : public NavigationServer3D {
Mutex commands_mutex;
/// Mutex used to make any operation threadsafe.
Mutex operations_mutex;
@ -97,8 +97,8 @@ class GodotNavigationServer : public NavigationServer3D {
int pm_edge_free_count = 0;
public:
GodotNavigationServer();
virtual ~GodotNavigationServer();
GodotNavigationServer3D();
virtual ~GodotNavigationServer3D();
void add_command(SetCommand *command);
@ -286,4 +286,4 @@ private:
#undef COMMAND_1
#undef COMMAND_2
#endif // GODOT_NAVIGATION_SERVER_H
#endif // GODOT_NAVIGATION_SERVER_3D_H

View File

@ -75,6 +75,8 @@ module_obj = []
env_navigation.add_source_files(module_obj, "*.cpp")
env_navigation.add_source_files(module_obj, "2d/*.cpp")
if not env["disable_3d"]:
env_navigation.add_source_files(module_obj, "3d/*.cpp")
if env.editor_build:
env_navigation.add_source_files(module_obj, "editor/*.cpp")
env.modules_sources += module_obj

View File

@ -31,11 +31,11 @@
#include "register_types.h"
#include "2d/godot_navigation_server_2d.h"
#include "godot_navigation_server.h"
#include "3d/godot_navigation_server_3d.h"
#ifndef DISABLE_DEPRECATED
#ifndef _3D_DISABLED
#include "navigation_mesh_generator.h"
#include "3d/navigation_mesh_generator.h"
#endif
#endif // DISABLE_DEPRECATED
@ -53,8 +53,8 @@ NavigationMeshGenerator *_nav_mesh_generator = nullptr;
#endif
#endif // DISABLE_DEPRECATED
NavigationServer3D *new_server() {
return memnew(GodotNavigationServer);
NavigationServer3D *new_navigation_server_3d() {
return memnew(GodotNavigationServer3D);
}
NavigationServer2D *new_navigation_server_2d() {
@ -63,7 +63,7 @@ NavigationServer2D *new_navigation_server_2d() {
void initialize_navigation_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
NavigationServer3DManager::set_default_server(new_server);
NavigationServer3DManager::set_default_server(new_navigation_server_3d);
NavigationServer2DManager::set_default_server(new_navigation_server_2d);
#ifndef DISABLE_DEPRECATED