2020-01-10 12:22:34 +01:00
|
|
|
/*************************************************************************/
|
2020-02-11 14:01:43 +01:00
|
|
|
/* nav_map.h */
|
2020-01-10 12:22:34 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2020-01-10 12:22:34 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2022-05-18 14:53:52 +02:00
|
|
|
#ifndef NAV_MAP_H
|
|
|
|
#define NAV_MAP_H
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
#include "nav_rid.h"
|
|
|
|
|
|
|
|
#include "core/math/math_defs.h"
|
2022-07-23 19:12:41 +02:00
|
|
|
#include "core/object/worker_thread_pool.h"
|
2022-05-13 15:04:37 +02:00
|
|
|
#include "core/templates/rb_map.h"
|
2020-01-10 12:22:34 +01:00
|
|
|
#include "nav_utils.h"
|
|
|
|
|
2022-01-04 20:26:22 +01:00
|
|
|
#include <KdTree.h>
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-01-31 00:39:52 +01:00
|
|
|
class NavLink;
|
2020-01-10 12:22:34 +01:00
|
|
|
class NavRegion;
|
|
|
|
class RvoAgent;
|
|
|
|
|
|
|
|
class NavMap : public NavRid {
|
|
|
|
/// Map Up
|
2020-05-12 17:01:17 +02:00
|
|
|
Vector3 up = Vector3(0, 1, 0);
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// To find the polygons edges the vertices are displaced in a grid where
|
|
|
|
/// each cell has the following cell_size.
|
2022-06-03 18:47:54 +02:00
|
|
|
real_t cell_size = 0.25;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// This value is used to detect the near edges to connect.
|
2022-06-03 18:47:54 +02:00
|
|
|
real_t edge_connection_margin = 0.25;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-01-31 00:39:52 +01:00
|
|
|
/// This value is used to limit how far links search to find polygons to connect to.
|
|
|
|
real_t link_connection_radius = 1.0;
|
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
bool regenerate_polygons = true;
|
|
|
|
bool regenerate_links = true;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-01-31 00:39:52 +01:00
|
|
|
/// Map regions
|
2022-07-28 19:24:14 +02:00
|
|
|
LocalVector<NavRegion *> regions;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
2022-01-31 00:39:52 +01:00
|
|
|
/// Map links
|
|
|
|
LocalVector<NavLink *> links;
|
|
|
|
LocalVector<gd::Polygon> link_polygons;
|
|
|
|
|
2020-01-10 12:22:34 +01:00
|
|
|
/// Map polygons
|
2022-07-28 19:24:14 +02:00
|
|
|
LocalVector<gd::Polygon> polygons;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// Rvo world
|
|
|
|
RVO::KdTree rvo;
|
|
|
|
|
|
|
|
/// Is agent array modified?
|
2020-05-12 17:01:17 +02:00
|
|
|
bool agents_dirty = false;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// All the Agents (even the controlled one)
|
2022-07-28 19:24:14 +02:00
|
|
|
LocalVector<RvoAgent *> agents;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// Controlled agents
|
2022-07-28 19:24:14 +02:00
|
|
|
LocalVector<RvoAgent *> controlled_agents;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// Physics delta time
|
2020-05-12 17:01:17 +02:00
|
|
|
real_t deltatime = 0.0;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
/// Change the id each time the map is updated.
|
2020-05-12 17:01:17 +02:00
|
|
|
uint32_t map_update_id = 0;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
public:
|
2022-04-18 21:57:23 +02:00
|
|
|
NavMap();
|
|
|
|
~NavMap();
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
void set_up(Vector3 p_up);
|
|
|
|
Vector3 get_up() const {
|
|
|
|
return up;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_cell_size(float p_cell_size);
|
|
|
|
float get_cell_size() const {
|
|
|
|
return cell_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_edge_connection_margin(float p_edge_connection_margin);
|
|
|
|
float get_edge_connection_margin() const {
|
|
|
|
return edge_connection_margin;
|
|
|
|
}
|
|
|
|
|
2022-01-31 00:39:52 +01:00
|
|
|
void set_link_connection_radius(float p_link_connection_radius);
|
|
|
|
float get_link_connection_radius() const {
|
|
|
|
return link_connection_radius;
|
|
|
|
}
|
|
|
|
|
2020-01-10 12:22:34 +01:00
|
|
|
gd::PointKey get_point_key(const Vector3 &p_pos) const;
|
|
|
|
|
2022-10-06 01:24:45 +02:00
|
|
|
Vector<Vector3> get_path(Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_navigation_layers, Vector<int32_t> *r_path_types, TypedArray<RID> *r_path_rids, Vector<int64_t> *r_path_owners) const;
|
2020-02-18 17:08:34 +01:00
|
|
|
Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const;
|
|
|
|
Vector3 get_closest_point(const Vector3 &p_point) const;
|
|
|
|
Vector3 get_closest_point_normal(const Vector3 &p_point) const;
|
2022-02-13 16:07:01 +01:00
|
|
|
gd::ClosestPointQueryResult get_closest_point_info(const Vector3 &p_point) const;
|
2020-02-18 17:08:34 +01:00
|
|
|
RID get_closest_point_owner(const Vector3 &p_point) const;
|
2020-01-10 12:22:34 +01:00
|
|
|
|
|
|
|
void add_region(NavRegion *p_region);
|
|
|
|
void remove_region(NavRegion *p_region);
|
2022-07-28 19:24:14 +02:00
|
|
|
const LocalVector<NavRegion *> &get_regions() const {
|
2020-01-10 12:22:34 +01:00
|
|
|
return regions;
|
|
|
|
}
|
|
|
|
|
2022-01-31 00:39:52 +01:00
|
|
|
void add_link(NavLink *p_link);
|
|
|
|
void remove_link(NavLink *p_link);
|
|
|
|
const LocalVector<NavLink *> &get_links() const {
|
|
|
|
return links;
|
|
|
|
}
|
|
|
|
|
2020-01-10 12:22:34 +01:00
|
|
|
bool has_agent(RvoAgent *agent) const;
|
|
|
|
void add_agent(RvoAgent *agent);
|
|
|
|
void remove_agent(RvoAgent *agent);
|
2022-07-28 19:24:14 +02:00
|
|
|
const LocalVector<RvoAgent *> &get_agents() const {
|
2020-01-10 12:22:34 +01:00
|
|
|
return agents;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_agent_as_controlled(RvoAgent *agent);
|
|
|
|
void remove_agent_as_controlled(RvoAgent *agent);
|
|
|
|
|
|
|
|
uint32_t get_map_update_id() const {
|
|
|
|
return map_update_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sync();
|
|
|
|
void step(real_t p_deltatime);
|
|
|
|
void dispatch_callbacks();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void compute_single_step(uint32_t index, RvoAgent **agent);
|
2022-10-06 01:24:45 +02:00
|
|
|
void clip_path(const LocalVector<gd::NavigationPoly> &p_navigation_polys, Vector<Vector3> &path, const gd::NavigationPoly *from_poly, const Vector3 &p_to_point, const gd::NavigationPoly *p_to_poly, Vector<int32_t> *r_path_types, TypedArray<RID> *r_path_rids, Vector<int64_t> *r_path_owners) const;
|
2020-01-10 12:22:34 +01:00
|
|
|
};
|
|
|
|
|
2022-05-18 14:53:52 +02:00
|
|
|
#endif // NAV_MAP_H
|