Debian Codegraph @

modules/navigation_2d/nav_agent_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* nav_agent_2d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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; // Experimental, clamps velocity to max_speed.
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 // Updates this agent with rvo data after the rvo simulation avoidance step.
142 void update();
143
144 // RVO debug data from the last frame update.
145 const Dictionary get_avoidance_data() const;
146
147 private:
148 void _update_rvo_agent_properties();
149 };