navigation_server_2d.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*************************************************************************/
  2. /* navigation_server_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. @author AndreaCatania
  32. */
  33. #ifndef NAVIGATION_2D_SERVER_H
  34. #define NAVIGATION_2D_SERVER_H
  35. #include "core/object/class_db.h"
  36. #include "core/templates/rid.h"
  37. #include "scene/2d/navigation_region_2d.h"
  38. // This server exposes the `NavigationServer3D` features in the 2D world.
  39. class NavigationServer2D : public Object {
  40. GDCLASS(NavigationServer2D, Object);
  41. static NavigationServer2D *singleton;
  42. protected:
  43. static void _bind_methods();
  44. public:
  45. /// Thread safe, can be used across many threads.
  46. static const NavigationServer2D *get_singleton() { return singleton; }
  47. /// MUST be used in single thread!
  48. static NavigationServer2D *get_singleton_mut() { return singleton; }
  49. /// Create a new map.
  50. virtual RID map_create() const;
  51. /// Set map active.
  52. virtual void map_set_active(RID p_map, bool p_active) const;
  53. /// Returns true if the map is active.
  54. virtual bool map_is_active(RID p_map) const;
  55. /// Set the map cell size used to weld the navigation mesh polygons.
  56. virtual void map_set_cell_size(RID p_map, real_t p_cell_size) const;
  57. /// Returns the map cell size.
  58. virtual real_t map_get_cell_size(RID p_map) const;
  59. /// Set the map edge connection margin used to weld the compatible region edges.
  60. virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) const;
  61. /// Returns the edge connection margin of this map.
  62. virtual real_t map_get_edge_connection_margin(RID p_map) const;
  63. /// Returns the navigation path to reach the destination from the origin.
  64. virtual Vector<Vector2> map_get_path(RID p_map, Vector2 p_origin, Vector2 p_destination, bool p_optimize) const;
  65. virtual Vector2 map_get_closest_point(RID p_map, const Vector2 &p_point) const;
  66. virtual RID map_get_closest_point_owner(RID p_map, const Vector2 &p_point) const;
  67. /// Creates a new region.
  68. virtual RID region_create() const;
  69. /// Set the map of this region.
  70. virtual void region_set_map(RID p_region, RID p_map) const;
  71. /// Set the global transformation of this region.
  72. virtual void region_set_transform(RID p_region, Transform2D p_transform) const;
  73. /// Set the navigation poly of this region.
  74. virtual void region_set_navpoly(RID p_region, Ref<NavigationPolygon> p_nav_mesh) const;
  75. /// Creates the agent.
  76. virtual RID agent_create() const;
  77. /// Put the agent in the map.
  78. virtual void agent_set_map(RID p_agent, RID p_map) const;
  79. /// The maximum distance (center point to
  80. /// center point) to other agents this agent
  81. /// takes into account in the navigation. The
  82. /// larger this number, the longer the running
  83. /// time of the simulation. If the number is too
  84. /// low, the simulation will not be safe.
  85. /// Must be non-negative.
  86. virtual void agent_set_neighbor_dist(RID p_agent, real_t p_dist) const;
  87. /// The maximum number of other agents this
  88. /// agent takes into account in the navigation.
  89. /// The larger this number, the longer the
  90. /// running time of the simulation. If the
  91. /// number is too low, the simulation will not
  92. /// be safe.
  93. virtual void agent_set_max_neighbors(RID p_agent, int p_count) const;
  94. /// The minimal amount of time for which this
  95. /// agent's velocities that are computed by the
  96. /// simulation are safe with respect to other
  97. /// agents. The larger this number, the sooner
  98. /// this agent will respond to the presence of
  99. /// other agents, but the less freedom this
  100. /// agent has in choosing its velocities.
  101. /// Must be positive.
  102. virtual void agent_set_time_horizon(RID p_agent, real_t p_time) const;
  103. /// The radius of this agent.
  104. /// Must be non-negative.
  105. virtual void agent_set_radius(RID p_agent, real_t p_radius) const;
  106. /// The maximum speed of this agent.
  107. /// Must be non-negative.
  108. virtual void agent_set_max_speed(RID p_agent, real_t p_max_speed) const;
  109. /// Current velocity of the agent
  110. virtual void agent_set_velocity(RID p_agent, Vector2 p_velocity) const;
  111. /// The new target velocity.
  112. virtual void agent_set_target_velocity(RID p_agent, Vector2 p_velocity) const;
  113. /// Position of the agent in world space.
  114. virtual void agent_set_position(RID p_agent, Vector2 p_position) const;
  115. /// Agent ignore the Y axis and avoid collisions by moving only on the horizontal plane
  116. virtual void agent_set_ignore_y(RID p_agent, bool p_ignore) const;
  117. /// Returns true if the map got changed the previous frame.
  118. virtual bool agent_is_map_changed(RID p_agent) const;
  119. /// Callback called at the end of the RVO process
  120. virtual void agent_set_callback(RID p_agent, Object *p_receiver, StringName p_method, Variant p_udata = Variant()) const;
  121. /// Destroy the `RID`
  122. virtual void free(RID p_object) const;
  123. NavigationServer2D();
  124. virtual ~NavigationServer2D();
  125. };
  126. #endif