gd_navigation_server.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************/
  2. /* gd_navigation_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. #ifndef GD_NAVIGATION_SERVER_H
  31. #define GD_NAVIGATION_SERVER_H
  32. #include "core/rid.h"
  33. #include "core/rid_owner.h"
  34. #include "servers/navigation_server.h"
  35. #include "nav_map.h"
  36. #include "nav_region.h"
  37. #include "rvo_agent.h"
  38. /**
  39. @author AndreaCatania
  40. */
  41. /// The commands are functions executed during the `sync` phase.
  42. #define MERGE_INTERNAL(A, B) A##B
  43. #define MERGE(A, B) MERGE_INTERNAL(A, B)
  44. #define COMMAND_1(F_NAME, T_0, D_0) \
  45. virtual void F_NAME(T_0 D_0) const; \
  46. void MERGE(_cmd_, F_NAME)(T_0 D_0)
  47. #define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \
  48. virtual void F_NAME(T_0 D_0, T_1 D_1) const; \
  49. void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
  50. #define COMMAND_4_DEF(F_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, D_3_DEF) \
  51. virtual void F_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3 = D_3_DEF) const; \
  52. void MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3)
  53. class GdNavigationServer;
  54. class Mutex;
  55. struct SetCommand {
  56. virtual ~SetCommand() {}
  57. virtual void exec(GdNavigationServer *server) = 0;
  58. };
  59. class GdNavigationServer : public NavigationServer {
  60. Mutex *commands_mutex;
  61. /// Mutex used to make any operation threadsafe.
  62. Mutex *operations_mutex;
  63. std::vector<SetCommand *> commands;
  64. mutable RID_PtrOwner<NavMap> map_owner;
  65. mutable RID_PtrOwner<NavRegion> region_owner;
  66. mutable RID_PtrOwner<RvoAgent> agent_owner;
  67. bool active;
  68. Vector<NavMap *> active_maps;
  69. public:
  70. GdNavigationServer();
  71. virtual ~GdNavigationServer();
  72. void add_command(SetCommand *command) const;
  73. virtual RID map_create() const;
  74. COMMAND_2(map_set_active, RID, p_map, bool, p_active);
  75. virtual bool map_is_active(RID p_map) const;
  76. COMMAND_2(map_set_up, RID, p_map, Vector3, p_up);
  77. virtual Vector3 map_get_up(RID p_map) const;
  78. COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size);
  79. virtual real_t map_get_cell_size(RID p_map) const;
  80. COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin);
  81. virtual real_t map_get_edge_connection_margin(RID p_map) const;
  82. virtual Vector<Vector3> map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const;
  83. virtual RID region_create() const;
  84. COMMAND_2(region_set_map, RID, p_region, RID, p_map);
  85. COMMAND_2(region_set_transform, RID, p_region, Transform, p_transform);
  86. COMMAND_2(region_set_navmesh, RID, p_region, Ref<NavigationMesh>, p_nav_mesh);
  87. virtual void region_bake_navmesh(Ref<NavigationMesh> r_mesh, Node *p_node) const;
  88. virtual RID agent_create() const;
  89. COMMAND_2(agent_set_map, RID, p_agent, RID, p_map);
  90. COMMAND_2(agent_set_neighbor_dist, RID, p_agent, real_t, p_dist);
  91. COMMAND_2(agent_set_max_neighbors, RID, p_agent, int, p_count);
  92. COMMAND_2(agent_set_time_horizon, RID, p_agent, real_t, p_time);
  93. COMMAND_2(agent_set_radius, RID, p_agent, real_t, p_radius);
  94. COMMAND_2(agent_set_max_speed, RID, p_agent, real_t, p_max_speed);
  95. COMMAND_2(agent_set_velocity, RID, p_agent, Vector3, p_velocity);
  96. COMMAND_2(agent_set_target_velocity, RID, p_agent, Vector3, p_velocity);
  97. COMMAND_2(agent_set_position, RID, p_agent, Vector3, p_position);
  98. COMMAND_2(agent_set_ignore_y, RID, p_agent, bool, p_ignore);
  99. virtual bool agent_is_map_changed(RID p_agent) const;
  100. COMMAND_4_DEF(agent_set_callback, RID, p_agent, Object *, p_receiver, StringName, p_method, Variant, p_udata, Variant());
  101. COMMAND_1(free, RID, p_object);
  102. virtual void set_active(bool p_active) const;
  103. virtual void step(real_t p_delta_time);
  104. };
  105. #undef COMMAND_1
  106. #undef COMMAND_2
  107. #undef COMMAND_4_DEF
  108. #endif // GD_NAVIGATION_SERVER_H