area.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**************************************************************************/
  2. /* area.cpp */
  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. #include "area.h"
  31. #include "scene/scene_string_names.h"
  32. #include "servers/audio_server.h"
  33. #include "servers/physics_server.h"
  34. void Area::set_space_override_mode(SpaceOverride p_mode) {
  35. space_override = p_mode;
  36. PhysicsServer::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer::AreaSpaceOverrideMode(p_mode));
  37. }
  38. Area::SpaceOverride Area::get_space_override_mode() const {
  39. return space_override;
  40. }
  41. void Area::set_gravity_is_point(bool p_enabled) {
  42. gravity_is_point = p_enabled;
  43. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT, p_enabled);
  44. }
  45. bool Area::is_gravity_a_point() const {
  46. return gravity_is_point;
  47. }
  48. void Area::set_gravity_distance_scale(real_t p_scale) {
  49. gravity_distance_scale = p_scale;
  50. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
  51. }
  52. real_t Area::get_gravity_distance_scale() const {
  53. return gravity_distance_scale;
  54. }
  55. void Area::set_gravity_vector(const Vector3 &p_vec) {
  56. gravity_vec = p_vec;
  57. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_VECTOR, p_vec);
  58. }
  59. Vector3 Area::get_gravity_vector() const {
  60. return gravity_vec;
  61. }
  62. void Area::set_gravity(real_t p_gravity) {
  63. gravity = p_gravity;
  64. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY, p_gravity);
  65. }
  66. real_t Area::get_gravity() const {
  67. return gravity;
  68. }
  69. void Area::set_linear_damp(real_t p_linear_damp) {
  70. linear_damp = p_linear_damp;
  71. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
  72. }
  73. real_t Area::get_linear_damp() const {
  74. return linear_damp;
  75. }
  76. void Area::set_angular_damp(real_t p_angular_damp) {
  77. angular_damp = p_angular_damp;
  78. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_ANGULAR_DAMP, p_angular_damp);
  79. }
  80. real_t Area::get_angular_damp() const {
  81. return angular_damp;
  82. }
  83. void Area::set_priority(real_t p_priority) {
  84. priority = p_priority;
  85. PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_PRIORITY, p_priority);
  86. }
  87. real_t Area::get_priority() const {
  88. return priority;
  89. }
  90. void Area::_body_enter_tree(ObjectID p_id) {
  91. Object *obj = ObjectDB::get_instance(p_id);
  92. Node *node = Object::cast_to<Node>(obj);
  93. ERR_FAIL_COND(!node);
  94. Map<ObjectID, BodyState>::Element *E = body_map.find(p_id);
  95. ERR_FAIL_COND(!E);
  96. ERR_FAIL_COND(E->get().in_tree);
  97. E->get().in_tree = true;
  98. emit_signal(SceneStringNames::get_singleton()->body_entered, node);
  99. for (int i = 0; i < E->get().shapes.size(); i++) {
  100. emit_signal(SceneStringNames::get_singleton()->body_shape_entered, E->get().rid, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
  101. }
  102. }
  103. void Area::_body_exit_tree(ObjectID p_id) {
  104. Object *obj = ObjectDB::get_instance(p_id);
  105. Node *node = Object::cast_to<Node>(obj);
  106. ERR_FAIL_COND(!node);
  107. Map<ObjectID, BodyState>::Element *E = body_map.find(p_id);
  108. ERR_FAIL_COND(!E);
  109. ERR_FAIL_COND(!E->get().in_tree);
  110. E->get().in_tree = false;
  111. emit_signal(SceneStringNames::get_singleton()->body_exited, node);
  112. for (int i = 0; i < E->get().shapes.size(); i++) {
  113. emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->get().rid, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
  114. }
  115. }
  116. void Area::_body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape) {
  117. bool body_in = p_status == PhysicsServer::AREA_BODY_ADDED;
  118. ObjectID objid = p_instance;
  119. Object *obj = ObjectDB::get_instance(objid);
  120. Node *node = Object::cast_to<Node>(obj);
  121. Map<ObjectID, BodyState>::Element *E = body_map.find(objid);
  122. if (!body_in && !E) {
  123. return; //likely removed from the tree
  124. }
  125. locked = true;
  126. if (body_in) {
  127. if (!E) {
  128. E = body_map.insert(objid, BodyState());
  129. E->get().rid = p_body;
  130. E->get().rc = 0;
  131. E->get().in_tree = node && node->is_inside_tree();
  132. if (node) {
  133. node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid));
  134. node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid));
  135. if (E->get().in_tree) {
  136. emit_signal(SceneStringNames::get_singleton()->body_entered, node);
  137. }
  138. }
  139. }
  140. E->get().rc++;
  141. if (node) {
  142. E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape));
  143. }
  144. if (E->get().in_tree) {
  145. emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_body, node, p_body_shape, p_area_shape);
  146. }
  147. } else {
  148. E->get().rc--;
  149. if (node) {
  150. E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape));
  151. }
  152. bool in_tree = E->get().in_tree;
  153. if (E->get().rc == 0) {
  154. body_map.erase(E);
  155. if (node) {
  156. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
  157. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
  158. if (in_tree) {
  159. emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
  160. }
  161. }
  162. }
  163. if (node && in_tree) {
  164. emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_body, obj, p_body_shape, p_area_shape);
  165. }
  166. }
  167. locked = false;
  168. }
  169. void Area::_clear_monitoring() {
  170. ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal.");
  171. {
  172. Map<ObjectID, BodyState> bmcopy = body_map;
  173. body_map.clear();
  174. //disconnect all monitored stuff
  175. for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) {
  176. Object *obj = ObjectDB::get_instance(E->key());
  177. Node *node = Object::cast_to<Node>(obj);
  178. if (!node) { //node may have been deleted in previous frame or at other legiminate point
  179. continue;
  180. }
  181. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
  182. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
  183. if (!E->get().in_tree) {
  184. continue;
  185. }
  186. for (int i = 0; i < E->get().shapes.size(); i++) {
  187. emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->get().rid, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
  188. }
  189. emit_signal(SceneStringNames::get_singleton()->body_exited, node);
  190. }
  191. }
  192. {
  193. Map<ObjectID, AreaState> bmcopy = area_map;
  194. area_map.clear();
  195. //disconnect all monitored stuff
  196. for (Map<ObjectID, AreaState>::Element *E = bmcopy.front(); E; E = E->next()) {
  197. Object *obj = ObjectDB::get_instance(E->key());
  198. Node *node = Object::cast_to<Node>(obj);
  199. if (!node) { //node may have been deleted in previous frame or at other legiminate point
  200. continue;
  201. }
  202. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
  203. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree);
  204. if (!E->get().in_tree) {
  205. continue;
  206. }
  207. for (int i = 0; i < E->get().shapes.size(); i++) {
  208. emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->get().rid, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
  209. }
  210. emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
  211. }
  212. }
  213. }
  214. void Area::_notification(int p_what) {
  215. if (p_what == NOTIFICATION_EXIT_TREE) {
  216. _clear_monitoring();
  217. }
  218. }
  219. void Area::set_monitoring(bool p_enable) {
  220. ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false).");
  221. if (p_enable == monitoring) {
  222. return;
  223. }
  224. monitoring = p_enable;
  225. if (monitoring) {
  226. PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout);
  227. PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout);
  228. } else {
  229. PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), nullptr, StringName());
  230. PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), nullptr, StringName());
  231. _clear_monitoring();
  232. }
  233. }
  234. void Area::_area_enter_tree(ObjectID p_id) {
  235. Object *obj = ObjectDB::get_instance(p_id);
  236. Node *node = Object::cast_to<Node>(obj);
  237. ERR_FAIL_COND(!node);
  238. Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
  239. ERR_FAIL_COND(!E);
  240. ERR_FAIL_COND(E->get().in_tree);
  241. E->get().in_tree = true;
  242. emit_signal(SceneStringNames::get_singleton()->area_entered, node);
  243. for (int i = 0; i < E->get().shapes.size(); i++) {
  244. emit_signal(SceneStringNames::get_singleton()->area_shape_entered, E->get().rid, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
  245. }
  246. }
  247. void Area::_area_exit_tree(ObjectID p_id) {
  248. Object *obj = ObjectDB::get_instance(p_id);
  249. Node *node = Object::cast_to<Node>(obj);
  250. ERR_FAIL_COND(!node);
  251. Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
  252. ERR_FAIL_COND(!E);
  253. ERR_FAIL_COND(!E->get().in_tree);
  254. E->get().in_tree = false;
  255. emit_signal(SceneStringNames::get_singleton()->area_exited, node);
  256. for (int i = 0; i < E->get().shapes.size(); i++) {
  257. emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->get().rid, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
  258. }
  259. }
  260. void Area::_area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape) {
  261. bool area_in = p_status == PhysicsServer::AREA_BODY_ADDED;
  262. ObjectID objid = p_instance;
  263. Object *obj = ObjectDB::get_instance(objid);
  264. Node *node = Object::cast_to<Node>(obj);
  265. Map<ObjectID, AreaState>::Element *E = area_map.find(objid);
  266. if (!area_in && !E) {
  267. return; //likely removed from the tree
  268. }
  269. locked = true;
  270. if (area_in) {
  271. if (!E) {
  272. E = area_map.insert(objid, AreaState());
  273. E->get().rid = p_area;
  274. E->get().rc = 0;
  275. E->get().in_tree = node && node->is_inside_tree();
  276. if (node) {
  277. node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree, make_binds(objid));
  278. node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid));
  279. if (E->get().in_tree) {
  280. emit_signal(SceneStringNames::get_singleton()->area_entered, node);
  281. }
  282. }
  283. }
  284. E->get().rc++;
  285. if (node) {
  286. E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape));
  287. }
  288. if (!node || E->get().in_tree) {
  289. emit_signal(SceneStringNames::get_singleton()->area_shape_entered, p_area, node, p_area_shape, p_self_shape);
  290. }
  291. } else {
  292. E->get().rc--;
  293. if (node) {
  294. E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape));
  295. }
  296. bool in_tree = E->get().in_tree;
  297. if (E->get().rc == 0) {
  298. area_map.erase(E);
  299. if (node) {
  300. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
  301. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree);
  302. if (in_tree) {
  303. emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
  304. }
  305. }
  306. }
  307. if (!node || in_tree) {
  308. emit_signal(SceneStringNames::get_singleton()->area_shape_exited, p_area, obj, p_area_shape, p_self_shape);
  309. }
  310. }
  311. locked = false;
  312. }
  313. bool Area::is_monitoring() const {
  314. return monitoring;
  315. }
  316. Array Area::get_overlapping_bodies() const {
  317. ERR_FAIL_COND_V(!monitoring, Array());
  318. Array ret;
  319. ret.resize(body_map.size());
  320. int idx = 0;
  321. for (const Map<ObjectID, BodyState>::Element *E = body_map.front(); E; E = E->next()) {
  322. Object *obj = ObjectDB::get_instance(E->key());
  323. if (!obj) {
  324. ret.resize(ret.size() - 1); //ops
  325. } else {
  326. ret[idx++] = obj;
  327. }
  328. }
  329. return ret;
  330. }
  331. void Area::set_monitorable(bool p_enable) {
  332. ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false).");
  333. if (p_enable == monitorable) {
  334. return;
  335. }
  336. monitorable = p_enable;
  337. PhysicsServer::get_singleton()->area_set_monitorable(get_rid(), monitorable);
  338. }
  339. bool Area::is_monitorable() const {
  340. return monitorable;
  341. }
  342. Array Area::get_overlapping_areas() const {
  343. ERR_FAIL_COND_V(!monitoring, Array());
  344. Array ret;
  345. ret.resize(area_map.size());
  346. int idx = 0;
  347. for (const Map<ObjectID, AreaState>::Element *E = area_map.front(); E; E = E->next()) {
  348. Object *obj = ObjectDB::get_instance(E->key());
  349. if (!obj) {
  350. ret.resize(ret.size() - 1); //ops
  351. } else {
  352. ret[idx++] = obj;
  353. }
  354. }
  355. return ret;
  356. }
  357. bool Area::overlaps_area(Node *p_area) const {
  358. ERR_FAIL_NULL_V(p_area, false);
  359. const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id());
  360. if (!E) {
  361. return false;
  362. }
  363. return E->get().in_tree;
  364. }
  365. bool Area::overlaps_body(Node *p_body) const {
  366. ERR_FAIL_NULL_V(p_body, false);
  367. const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id());
  368. if (!E) {
  369. return false;
  370. }
  371. return E->get().in_tree;
  372. }
  373. void Area::set_audio_bus_override(bool p_override) {
  374. audio_bus_override = p_override;
  375. }
  376. bool Area::is_overriding_audio_bus() const {
  377. return audio_bus_override;
  378. }
  379. void Area::set_audio_bus(const StringName &p_audio_bus) {
  380. audio_bus = p_audio_bus;
  381. }
  382. StringName Area::get_audio_bus() const {
  383. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  384. if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) {
  385. return audio_bus;
  386. }
  387. }
  388. return "Master";
  389. }
  390. void Area::set_use_reverb_bus(bool p_enable) {
  391. use_reverb_bus = p_enable;
  392. }
  393. bool Area::is_using_reverb_bus() const {
  394. return use_reverb_bus;
  395. }
  396. void Area::set_reverb_bus(const StringName &p_audio_bus) {
  397. reverb_bus = p_audio_bus;
  398. }
  399. StringName Area::get_reverb_bus() const {
  400. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  401. if (AudioServer::get_singleton()->get_bus_name(i) == reverb_bus) {
  402. return reverb_bus;
  403. }
  404. }
  405. return "Master";
  406. }
  407. void Area::set_reverb_amount(float p_amount) {
  408. reverb_amount = p_amount;
  409. }
  410. float Area::get_reverb_amount() const {
  411. return reverb_amount;
  412. }
  413. void Area::set_reverb_uniformity(float p_uniformity) {
  414. reverb_uniformity = p_uniformity;
  415. }
  416. float Area::get_reverb_uniformity() const {
  417. return reverb_uniformity;
  418. }
  419. void Area::_validate_property(PropertyInfo &property) const {
  420. if (property.name == "audio_bus_name" || property.name == "reverb_bus_name") {
  421. String options;
  422. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  423. if (i > 0) {
  424. options += ",";
  425. }
  426. String name = AudioServer::get_singleton()->get_bus_name(i);
  427. options += name;
  428. }
  429. property.hint_string = options;
  430. }
  431. }
  432. void Area::_bind_methods() {
  433. ClassDB::bind_method(D_METHOD("_body_enter_tree", "id"), &Area::_body_enter_tree);
  434. ClassDB::bind_method(D_METHOD("_body_exit_tree", "id"), &Area::_body_exit_tree);
  435. ClassDB::bind_method(D_METHOD("_area_enter_tree", "id"), &Area::_area_enter_tree);
  436. ClassDB::bind_method(D_METHOD("_area_exit_tree", "id"), &Area::_area_exit_tree);
  437. ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area::set_space_override_mode);
  438. ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area::get_space_override_mode);
  439. ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area::set_gravity_is_point);
  440. ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area::is_gravity_a_point);
  441. ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area::set_gravity_distance_scale);
  442. ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area::get_gravity_distance_scale);
  443. ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area::set_gravity_vector);
  444. ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area::get_gravity_vector);
  445. ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area::set_gravity);
  446. ClassDB::bind_method(D_METHOD("get_gravity"), &Area::get_gravity);
  447. ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area::set_angular_damp);
  448. ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area::get_angular_damp);
  449. ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area::set_linear_damp);
  450. ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area::get_linear_damp);
  451. ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area::set_priority);
  452. ClassDB::bind_method(D_METHOD("get_priority"), &Area::get_priority);
  453. ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area::set_monitorable);
  454. ClassDB::bind_method(D_METHOD("is_monitorable"), &Area::is_monitorable);
  455. ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area::set_monitoring);
  456. ClassDB::bind_method(D_METHOD("is_monitoring"), &Area::is_monitoring);
  457. ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area::get_overlapping_bodies);
  458. ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area::get_overlapping_areas);
  459. ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area::overlaps_body);
  460. ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area::overlaps_area);
  461. ClassDB::bind_method(D_METHOD("_body_inout"), &Area::_body_inout);
  462. ClassDB::bind_method(D_METHOD("_area_inout"), &Area::_area_inout);
  463. ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area::set_audio_bus_override);
  464. ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area::is_overriding_audio_bus);
  465. ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area::set_audio_bus);
  466. ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area::get_audio_bus);
  467. ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area::set_use_reverb_bus);
  468. ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area::is_using_reverb_bus);
  469. ClassDB::bind_method(D_METHOD("set_reverb_bus", "name"), &Area::set_reverb_bus);
  470. ClassDB::bind_method(D_METHOD("get_reverb_bus"), &Area::get_reverb_bus);
  471. ClassDB::bind_method(D_METHOD("set_reverb_amount", "amount"), &Area::set_reverb_amount);
  472. ClassDB::bind_method(D_METHOD("get_reverb_amount"), &Area::get_reverb_amount);
  473. ClassDB::bind_method(D_METHOD("set_reverb_uniformity", "amount"), &Area::set_reverb_uniformity);
  474. ClassDB::bind_method(D_METHOD("get_reverb_uniformity"), &Area::get_reverb_uniformity);
  475. ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::_RID, "body_rid"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape_index"), PropertyInfo(Variant::INT, "local_shape_index")));
  476. ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::_RID, "body_rid"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape_index"), PropertyInfo(Variant::INT, "local_shape_index")));
  477. ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
  478. ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
  479. ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::_RID, "area_rid"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape_index"), PropertyInfo(Variant::INT, "local_shape_index")));
  480. ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::_RID, "area_rid"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape_index"), PropertyInfo(Variant::INT, "local_shape_index")));
  481. ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area")));
  482. ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area")));
  483. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitoring"), "set_monitoring", "is_monitoring");
  484. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitorable"), "set_monitorable", "is_monitorable");
  485. ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,128,1"), "set_priority", "get_priority");
  486. ADD_GROUP("Physics Overrides", "");
  487. ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode");
  488. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point");
  489. ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity_distance_scale", PROPERTY_HINT_EXP_RANGE, "0,1024,0.001,or_greater"), "set_gravity_distance_scale", "get_gravity_distance_scale");
  490. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_vec"), "set_gravity_vector", "get_gravity_vector");
  491. ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity", PROPERTY_HINT_RANGE, "-32,32,0.001,or_lesser,or_greater"), "set_gravity", "get_gravity");
  492. ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp");
  493. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp");
  494. ADD_GROUP("Audio Bus", "audio_bus_");
  495. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_bus_override"), "set_audio_bus_override", "is_overriding_audio_bus");
  496. ADD_PROPERTY(PropertyInfo(Variant::STRING, "audio_bus_name", PROPERTY_HINT_ENUM, ""), "set_audio_bus", "get_audio_bus");
  497. ADD_GROUP("Reverb Bus", "reverb_bus_");
  498. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reverb_bus_enable"), "set_use_reverb_bus", "is_using_reverb_bus");
  499. ADD_PROPERTY(PropertyInfo(Variant::STRING, "reverb_bus_name", PROPERTY_HINT_ENUM, ""), "set_reverb_bus", "get_reverb_bus");
  500. ADD_PROPERTY(PropertyInfo(Variant::REAL, "reverb_bus_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_reverb_amount", "get_reverb_amount");
  501. ADD_PROPERTY(PropertyInfo(Variant::REAL, "reverb_bus_uniformity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_reverb_uniformity", "get_reverb_uniformity");
  502. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_DISABLED);
  503. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_COMBINE);
  504. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_COMBINE_REPLACE);
  505. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE);
  506. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE_COMBINE);
  507. }
  508. Area::Area() :
  509. CollisionObject(RID_PRIME(PhysicsServer::get_singleton()->area_create()), true) {
  510. space_override = SPACE_OVERRIDE_DISABLED;
  511. set_gravity(9.8);
  512. locked = false;
  513. set_gravity_vector(Vector3(0, -1, 0));
  514. gravity_is_point = false;
  515. gravity_distance_scale = 0;
  516. linear_damp = 0.1;
  517. angular_damp = 0.1;
  518. priority = 0;
  519. monitoring = false;
  520. monitorable = false;
  521. set_monitoring(true);
  522. set_monitorable(true);
  523. audio_bus_override = false;
  524. audio_bus = "Master";
  525. use_reverb_bus = false;
  526. reverb_bus = "Master";
  527. reverb_amount = 0.0;
  528. reverb_uniformity = 0.0;
  529. }
  530. Area::~Area() {
  531. }