navigation_2d_server.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*************************************************************************/
  2. /* navigation_2d_server.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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.h"
  36. #include "core/rid.h"
  37. #include "scene/2d/navigation_polygon.h"
  38. // This server exposes the 3D `NavigationServer` features in the 2D world.
  39. class Navigation2DServer : public Object {
  40. GDCLASS(Navigation2DServer, Object);
  41. static Navigation2DServer *singleton;
  42. protected:
  43. static void _bind_methods();
  44. public:
  45. /// Thread safe, can be used accross many threads.
  46. static const Navigation2DServer *get_singleton() { return singleton; }
  47. /// MUST be used in single thread!
  48. static Navigation2DServer *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. /// Creates a new region.
  66. virtual RID region_create() const;
  67. /// Set the map of this region.
  68. virtual void region_set_map(RID p_region, RID p_map) const;
  69. /// Set the global transformation of this region.
  70. virtual void region_set_transform(RID p_region, Transform2D p_transform) const;
  71. /// Set the navigation poly of this region.
  72. virtual void region_set_navpoly(RID p_region, Ref<NavigationPolygon> p_nav_mesh) const;
  73. /// Creates the agent.
  74. virtual RID agent_create() const;
  75. /// Put the agent in the map.
  76. virtual void agent_set_map(RID p_agent, RID p_map) const;
  77. /// The maximum distance (center point to
  78. /// center point) to other agents this agent
  79. /// takes into account in the navigation. The
  80. /// larger this number, the longer the running
  81. /// time of the simulation. If the number is too
  82. /// low, the simulation will not be safe.
  83. /// Must be non-negative.
  84. virtual void agent_set_neighbor_dist(RID p_agent, real_t p_dist) const;
  85. /// The maximum number of other agents this
  86. /// agent takes into account in the navigation.
  87. /// The larger this number, the longer the
  88. /// running time of the simulation. If the
  89. /// number is too low, the simulation will not
  90. /// be safe.
  91. virtual void agent_set_max_neighbors(RID p_agent, int p_count) const;
  92. /// The minimal amount of time for which this
  93. /// agent's velocities that are computed by the
  94. /// simulation are safe with respect to other
  95. /// agents. The larger this number, the sooner
  96. /// this agent will respond to the presence of
  97. /// other agents, but the less freedom this
  98. /// agent has in choosing its velocities.
  99. /// Must be positive.
  100. virtual void agent_set_time_horizon(RID p_agent, real_t p_time) const;
  101. /// The radius of this agent.
  102. /// Must be non-negative.
  103. virtual void agent_set_radius(RID p_agent, real_t p_radius) const;
  104. /// The maximum speed of this agent.
  105. /// Must be non-negative.
  106. virtual void agent_set_max_speed(RID p_agent, real_t p_max_speed) const;
  107. /// Current velocity of the agent
  108. virtual void agent_set_velocity(RID p_agent, Vector2 p_velocity) const;
  109. /// The new target velocity.
  110. virtual void agent_set_target_velocity(RID p_agent, Vector2 p_velocity) const;
  111. /// Position of the agent in world space.
  112. virtual void agent_set_position(RID p_agent, Vector2 p_position) const;
  113. /// Agent ignore the Y axis and avoid collisions by moving only on the horizontal plane
  114. virtual void agent_set_ignore_y(RID p_agent, bool p_ignore) const;
  115. /// Returns true if the map got changed the previous frame.
  116. virtual bool agent_is_map_changed(RID p_agent) const;
  117. /// Callback called at the end of the RVO process
  118. virtual void agent_set_callback(RID p_agent, Object *p_receiver, StringName p_method, Variant p_udata = Variant()) const;
  119. /// Destroy the `RID`
  120. virtual void free(RID p_object) const;
  121. Navigation2DServer();
  122. virtual ~Navigation2DServer();
  123. };
  124. #endif