| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "nav_rid_2d.h" |
| 34 |
|
| 35 |
#include "core/object/class_db.h" |
| 36 |
#include "core/templates/self_list.h" |
| 37 |
#include "servers/navigation_2d/navigation_constants_2d.h" |
| 38 |
|
| 39 |
#include <Agent2d.h> |
| 40 |
|
| 41 |
class NavMap2D; |
| 42 |
|
| 43 |
class NavAgent2D : public NavRid2D { |
| 44 |
Vector2 position; |
| 45 |
Vector2 target_position; |
| 46 |
Vector2 velocity; |
| 47 |
Vector2 velocity_forced; |
| 48 |
real_t radius = NavigationDefaults2D::AVOIDANCE_AGENT_RADIUS; |
| 49 |
real_t max_speed = NavigationDefaults2D::AVOIDANCE_AGENT_MAX_SPEED; |
| 50 |
real_t time_horizon_agents = NavigationDefaults2D::AVOIDANCE_AGENT_TIME_HORIZON_AGENTS; |
| 51 |
real_t time_horizon_obstacles = NavigationDefaults2D::AVOIDANCE_AGENT_TIME_HORIZON_OBSTACLES; |
| 52 |
int max_neighbors = NavigationDefaults2D::AVOIDANCE_AGENT_MAX_NEIGHBORS; |
| 53 |
real_t neighbor_distance = NavigationDefaults2D::AVOIDANCE_AGENT_NEIGHBOR_DISTANCE; |
| 54 |
Vector2 safe_velocity; |
| 55 |
bool clamp_speed = true; |
| 56 |
|
| 57 |
NavMap2D *map = nullptr; |
| 58 |
|
| 59 |
RVO2D::Agent2D rvo_agent; |
| 60 |
bool avoidance_enabled = false; |
| 61 |
|
| 62 |
uint32_t avoidance_layers = 1; |
| 63 |
uint32_t avoidance_mask = 1; |
| 64 |
real_t avoidance_priority = 1.0; |
| 65 |
|
| 66 |
Callable avoidance_callback; |
| 67 |
|
| 68 |
bool agent_dirty = true; |
| 69 |
|
| 70 |
uint32_t last_map_iteration_id = 0; |
| 71 |
bool paused = false; |
| 72 |
|
| 73 |
SelfList<NavAgent2D> sync_dirty_request_list_element; |
| 74 |
|
| 75 |
public: |
| 76 |
NavAgent2D(); |
| 77 |
~NavAgent2D(); |
| 78 |
|
| 79 |
void set_avoidance_enabled(bool p_enabled); |
| 80 |
bool is_avoidance_enabled() { return avoidance_enabled; } |
| 81 |
|
| 82 |
void set_map(NavMap2D *p_map); |
| 83 |
NavMap2D *get_map() { return map; } |
| 84 |
|
| 85 |
bool is_map_changed(); |
| 86 |
|
| 87 |
RVO2D::Agent2D *get_rvo_agent() { return &rvo_agent; } |
| 88 |
|
| 89 |
void set_avoidance_callback(Callable p_callback); |
| 90 |
bool has_avoidance_callback() const; |
| 91 |
|
| 92 |
void dispatch_avoidance_callback(); |
| 93 |
|
| 94 |
void set_neighbor_distance(real_t p_neighbor_distance); |
| 95 |
real_t get_neighbor_distance() const { return neighbor_distance; } |
| 96 |
|
| 97 |
void set_max_neighbors(int p_max_neighbors); |
| 98 |
int get_max_neighbors() const { return max_neighbors; } |
| 99 |
|
| 100 |
void set_time_horizon_agents(real_t p_time_horizon); |
| 101 |
real_t get_time_horizon_agents() const { return time_horizon_agents; } |
| 102 |
|
| 103 |
void set_time_horizon_obstacles(real_t p_time_horizon); |
| 104 |
real_t get_time_horizon_obstacles() const { return time_horizon_obstacles; } |
| 105 |
|
| 106 |
void set_radius(real_t p_radius); |
| 107 |
real_t get_radius() const { return radius; } |
| 108 |
|
| 109 |
void set_max_speed(real_t p_max_speed); |
| 110 |
real_t get_max_speed() const { return max_speed; } |
| 111 |
|
| 112 |
void set_position(const Vector2 &p_position); |
| 113 |
Vector2 get_position() const { return position; } |
| 114 |
|
| 115 |
void set_target_position(const Vector2 &p_target_position); |
| 116 |
Vector2 get_target_position() const { return target_position; } |
| 117 |
|
| 118 |
void set_velocity(const Vector2 &p_velocity); |
| 119 |
Vector2 get_velocity() const { return velocity; } |
| 120 |
|
| 121 |
void set_velocity_forced(const Vector2 &p_velocity); |
| 122 |
Vector2 get_velocity_forced() const { return velocity_forced; } |
| 123 |
|
| 124 |
void set_avoidance_layers(uint32_t p_layers); |
| 125 |
uint32_t get_avoidance_layers() const { return avoidance_layers; } |
| 126 |
|
| 127 |
void set_avoidance_mask(uint32_t p_mask); |
| 128 |
uint32_t get_avoidance_mask() const { return avoidance_mask; } |
| 129 |
|
| 130 |
void set_avoidance_priority(real_t p_priority); |
| 131 |
real_t get_avoidance_priority() const { return avoidance_priority; } |
| 132 |
|
| 133 |
void set_paused(bool p_paused); |
| 134 |
bool get_paused() const; |
| 135 |
|
| 136 |
bool is_dirty() const; |
| 137 |
void sync(); |
| 138 |
void request_sync(); |
| 139 |
void cancel_sync_request(); |
| 140 |
|
| 141 |
|
| 142 |
void update(); |
| 143 |
|
| 144 |
|
| 145 |
const Dictionary get_avoidance_data() const; |
| 146 |
|
| 147 |
private: |
| 148 |
void _update_rvo_agent_properties(); |
| 149 |
}; |