| 1 | /**************************************************************************/ |
| 2 | /* navigation_obstacle_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 | #ifndef NAVIGATION_OBSTACLE_2D_H |
| 32 | #define NAVIGATION_OBSTACLE_2D_H |
| 33 | |
| 34 | #include "scene/2d/node_2d.h" |
| 35 | |
| 36 | class NavigationObstacle2D : public Node2D { |
| 37 | GDCLASS(NavigationObstacle2D, Node2D); |
| 38 | |
| 39 | RID obstacle; |
| 40 | RID map_before_pause; |
| 41 | RID map_override; |
| 42 | RID map_current; |
| 43 | |
| 44 | real_t radius = 0.0; |
| 45 | |
| 46 | Vector<Vector2> vertices; |
| 47 | |
| 48 | bool avoidance_enabled = true; |
| 49 | uint32_t avoidance_layers = 1; |
| 50 | |
| 51 | Transform2D previous_transform; |
| 52 | |
| 53 | Vector2 velocity; |
| 54 | Vector2 previous_velocity; |
| 55 | bool velocity_submitted = false; |
| 56 | |
| 57 | #ifdef DEBUG_ENABLED |
| 58 | private: |
| 59 | void _update_fake_agent_radius_debug(); |
| 60 | void _update_static_obstacle_debug(); |
| 61 | #endif // DEBUG_ENABLED |
| 62 | |
| 63 | protected: |
| 64 | static void _bind_methods(); |
| 65 | void _notification(int p_what); |
| 66 | |
| 67 | public: |
| 68 | NavigationObstacle2D(); |
| 69 | virtual ~NavigationObstacle2D(); |
| 70 | |
| 71 | RID get_rid() const { return obstacle; } |
| 72 | |
| 73 | void set_avoidance_enabled(bool p_enabled); |
| 74 | bool get_avoidance_enabled() const; |
| 75 | |
| 76 | void set_navigation_map(RID p_navigation_map); |
| 77 | RID get_navigation_map() const; |
| 78 | |
| 79 | void set_radius(real_t p_radius); |
| 80 | real_t get_radius() const { return radius; } |
| 81 | |
| 82 | void set_vertices(const Vector<Vector2> &p_vertices); |
| 83 | const Vector<Vector2> &get_vertices() const { return vertices; }; |
| 84 | |
| 85 | void set_avoidance_layers(uint32_t p_layers); |
| 86 | uint32_t get_avoidance_layers() const; |
| 87 | |
| 88 | void set_avoidance_mask(uint32_t p_mask); |
| 89 | uint32_t get_avoidance_mask() const; |
| 90 | |
| 91 | void set_avoidance_layer_value(int p_layer_number, bool p_value); |
| 92 | bool get_avoidance_layer_value(int p_layer_number) const; |
| 93 | |
| 94 | void set_velocity(const Vector2 p_velocity); |
| 95 | Vector2 get_velocity() const { return velocity; }; |
| 96 | |
| 97 | void _avoidance_done(Vector3 p_new_velocity); // Dummy |
| 98 | |
| 99 | private: |
| 100 | void _update_map(RID p_map); |
| 101 | void _update_position(const Vector2 p_position); |
| 102 | }; |
| 103 | |
| 104 | #endif // NAVIGATION_OBSTACLE_2D_H |
| 105 | |