area.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*************************************************************************/
  2. /* area.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #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, p_id, 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, p_id, 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().rc = 0;
  130. E->get().in_tree = node && node->is_inside_tree();
  131. if (node) {
  132. node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid));
  133. node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid));
  134. if (E->get().in_tree) {
  135. emit_signal(SceneStringNames::get_singleton()->body_entered, node);
  136. }
  137. }
  138. }
  139. E->get().rc++;
  140. if (node)
  141. E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape));
  142. if (E->get().in_tree) {
  143. emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_area_shape);
  144. }
  145. } else {
  146. E->get().rc--;
  147. if (node)
  148. E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape));
  149. bool eraseit = false;
  150. if (E->get().rc == 0) {
  151. if (node) {
  152. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
  153. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
  154. if (E->get().in_tree)
  155. emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
  156. }
  157. eraseit = true;
  158. }
  159. if (node && E->get().in_tree) {
  160. emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_area_shape);
  161. }
  162. if (eraseit)
  163. body_map.erase(E);
  164. }
  165. locked = false;
  166. }
  167. void Area::_clear_monitoring() {
  168. if (locked) {
  169. ERR_EXPLAIN("This function can't be used during the in/out signal.");
  170. }
  171. ERR_FAIL_COND(locked);
  172. {
  173. Map<ObjectID, BodyState> bmcopy = body_map;
  174. body_map.clear();
  175. //disconnect all monitored stuff
  176. for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) {
  177. Object *obj = ObjectDB::get_instance(E->key());
  178. Node *node = Object::cast_to<Node>(obj);
  179. if (!node) //node may have been deleted in previous frame or at other legiminate point
  180. continue;
  181. //ERR_CONTINUE(!node);
  182. if (!E->get().in_tree)
  183. continue;
  184. for (int i = 0; i < E->get().shapes.size(); i++) {
  185. emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
  186. }
  187. emit_signal(SceneStringNames::get_singleton()->body_exited, node);
  188. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
  189. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
  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. //ERR_CONTINUE(!node);
  202. if (!E->get().in_tree)
  203. continue;
  204. for (int i = 0; i < E->get().shapes.size(); i++) {
  205. emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
  206. }
  207. emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
  208. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
  209. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree);
  210. }
  211. }
  212. }
  213. void Area::_notification(int p_what) {
  214. if (p_what == NOTIFICATION_EXIT_TREE) {
  215. _clear_monitoring();
  216. }
  217. }
  218. void Area::set_monitoring(bool p_enable) {
  219. if (locked) {
  220. ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitoring\",true/false)");
  221. }
  222. ERR_FAIL_COND(locked);
  223. if (p_enable == monitoring)
  224. return;
  225. monitoring = p_enable;
  226. if (monitoring) {
  227. PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout);
  228. PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout);
  229. } else {
  230. PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), NULL, StringName());
  231. PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), NULL, StringName());
  232. _clear_monitoring();
  233. }
  234. }
  235. void Area::_area_enter_tree(ObjectID p_id) {
  236. Object *obj = ObjectDB::get_instance(p_id);
  237. Node *node = Object::cast_to<Node>(obj);
  238. ERR_FAIL_COND(!node);
  239. Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
  240. ERR_FAIL_COND(!E);
  241. ERR_FAIL_COND(E->get().in_tree);
  242. E->get().in_tree = true;
  243. emit_signal(SceneStringNames::get_singleton()->area_entered, node);
  244. for (int i = 0; i < E->get().shapes.size(); i++) {
  245. emit_signal(SceneStringNames::get_singleton()->area_shape_entered, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
  246. }
  247. }
  248. void Area::_area_exit_tree(ObjectID p_id) {
  249. Object *obj = ObjectDB::get_instance(p_id);
  250. Node *node = Object::cast_to<Node>(obj);
  251. ERR_FAIL_COND(!node);
  252. Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
  253. ERR_FAIL_COND(!E);
  254. ERR_FAIL_COND(!E->get().in_tree);
  255. E->get().in_tree = false;
  256. emit_signal(SceneStringNames::get_singleton()->area_exited, node);
  257. for (int i = 0; i < E->get().shapes.size(); i++) {
  258. emit_signal(SceneStringNames::get_singleton()->area_shape_exited, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
  259. }
  260. }
  261. void Area::_area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape) {
  262. bool area_in = p_status == PhysicsServer::AREA_BODY_ADDED;
  263. ObjectID objid = p_instance;
  264. Object *obj = ObjectDB::get_instance(objid);
  265. Node *node = Object::cast_to<Node>(obj);
  266. Map<ObjectID, AreaState>::Element *E = area_map.find(objid);
  267. ERR_FAIL_COND(!area_in && !E);
  268. locked = true;
  269. if (area_in) {
  270. if (!E) {
  271. E = area_map.insert(objid, AreaState());
  272. E->get().rc = 0;
  273. E->get().in_tree = node && node->is_inside_tree();
  274. if (node) {
  275. node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree, make_binds(objid));
  276. node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid));
  277. if (E->get().in_tree) {
  278. emit_signal(SceneStringNames::get_singleton()->area_entered, node);
  279. }
  280. }
  281. }
  282. E->get().rc++;
  283. if (node)
  284. E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape));
  285. if (!node || E->get().in_tree) {
  286. emit_signal(SceneStringNames::get_singleton()->area_shape_entered, objid, node, p_area_shape, p_self_shape);
  287. }
  288. } else {
  289. E->get().rc--;
  290. if (node)
  291. E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape));
  292. bool eraseit = false;
  293. if (E->get().rc == 0) {
  294. if (node) {
  295. node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
  296. node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree);
  297. if (E->get().in_tree) {
  298. emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
  299. }
  300. }
  301. eraseit = true;
  302. }
  303. if (!node || E->get().in_tree) {
  304. emit_signal(SceneStringNames::get_singleton()->area_shape_exited, objid, obj, p_area_shape, p_self_shape);
  305. }
  306. if (eraseit)
  307. area_map.erase(E);
  308. }
  309. locked = false;
  310. }
  311. bool Area::is_monitoring() const {
  312. return monitoring;
  313. }
  314. Array Area::get_overlapping_bodies() const {
  315. ERR_FAIL_COND_V(!monitoring, Array());
  316. Array ret;
  317. ret.resize(body_map.size());
  318. int idx = 0;
  319. for (const Map<ObjectID, BodyState>::Element *E = body_map.front(); E; E = E->next()) {
  320. Object *obj = ObjectDB::get_instance(E->key());
  321. if (!obj) {
  322. ret.resize(ret.size() - 1); //ops
  323. } else {
  324. ret[idx++] = obj;
  325. }
  326. }
  327. return ret;
  328. }
  329. void Area::set_monitorable(bool p_enable) {
  330. if (locked || PhysicsServer::get_singleton()->is_flushing_queries()) {
  331. ERR_EXPLAIN("Function blocked during in/out signal. Use set_deferred(\"monitorable\",true/false)");
  332. }
  333. ERR_FAIL_COND(locked || PhysicsServer::get_singleton()->is_flushing_queries());
  334. if (p_enable == monitorable)
  335. return;
  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. return E->get().in_tree;
  363. }
  364. bool Area::overlaps_body(Node *p_body) const {
  365. ERR_FAIL_NULL_V(p_body, false);
  366. const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id());
  367. if (!E)
  368. return false;
  369. return E->get().in_tree;
  370. }
  371. void Area::set_collision_mask(uint32_t p_mask) {
  372. collision_mask = p_mask;
  373. PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask);
  374. }
  375. uint32_t Area::get_collision_mask() const {
  376. return collision_mask;
  377. }
  378. void Area::set_collision_layer(uint32_t p_layer) {
  379. collision_layer = p_layer;
  380. PhysicsServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer);
  381. }
  382. uint32_t Area::get_collision_layer() const {
  383. return collision_layer;
  384. }
  385. void Area::set_collision_mask_bit(int p_bit, bool p_value) {
  386. uint32_t mask = get_collision_mask();
  387. if (p_value)
  388. mask |= 1 << p_bit;
  389. else
  390. mask &= ~(1 << p_bit);
  391. set_collision_mask(mask);
  392. }
  393. bool Area::get_collision_mask_bit(int p_bit) const {
  394. return get_collision_mask() & (1 << p_bit);
  395. }
  396. void Area::set_collision_layer_bit(int p_bit, bool p_value) {
  397. uint32_t layer = get_collision_layer();
  398. if (p_value)
  399. layer |= 1 << p_bit;
  400. else
  401. layer &= ~(1 << p_bit);
  402. set_collision_layer(layer);
  403. }
  404. bool Area::get_collision_layer_bit(int p_bit) const {
  405. return get_collision_layer() & (1 << p_bit);
  406. }
  407. void Area::set_audio_bus_override(bool p_override) {
  408. audio_bus_override = p_override;
  409. }
  410. bool Area::is_overriding_audio_bus() const {
  411. return audio_bus_override;
  412. }
  413. void Area::set_audio_bus(const StringName &p_audio_bus) {
  414. audio_bus = p_audio_bus;
  415. }
  416. StringName Area::get_audio_bus() const {
  417. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  418. if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) {
  419. return audio_bus;
  420. }
  421. }
  422. return "Master";
  423. }
  424. void Area::set_use_reverb_bus(bool p_enable) {
  425. use_reverb_bus = p_enable;
  426. }
  427. bool Area::is_using_reverb_bus() const {
  428. return use_reverb_bus;
  429. }
  430. void Area::set_reverb_bus(const StringName &p_audio_bus) {
  431. reverb_bus = p_audio_bus;
  432. }
  433. StringName Area::get_reverb_bus() const {
  434. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  435. if (AudioServer::get_singleton()->get_bus_name(i) == reverb_bus) {
  436. return reverb_bus;
  437. }
  438. }
  439. return "Master";
  440. }
  441. void Area::set_reverb_amount(float p_amount) {
  442. reverb_amount = p_amount;
  443. }
  444. float Area::get_reverb_amount() const {
  445. return reverb_amount;
  446. }
  447. void Area::set_reverb_uniformity(float p_uniformity) {
  448. reverb_uniformity = p_uniformity;
  449. }
  450. float Area::get_reverb_uniformity() const {
  451. return reverb_uniformity;
  452. }
  453. void Area::_validate_property(PropertyInfo &property) const {
  454. if (property.name == "audio_bus_name" || property.name == "reverb_bus_name") {
  455. String options;
  456. for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
  457. if (i > 0)
  458. options += ",";
  459. String name = AudioServer::get_singleton()->get_bus_name(i);
  460. options += name;
  461. }
  462. property.hint_string = options;
  463. }
  464. }
  465. void Area::_bind_methods() {
  466. ClassDB::bind_method(D_METHOD("_body_enter_tree", "id"), &Area::_body_enter_tree);
  467. ClassDB::bind_method(D_METHOD("_body_exit_tree", "id"), &Area::_body_exit_tree);
  468. ClassDB::bind_method(D_METHOD("_area_enter_tree", "id"), &Area::_area_enter_tree);
  469. ClassDB::bind_method(D_METHOD("_area_exit_tree", "id"), &Area::_area_exit_tree);
  470. ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area::set_space_override_mode);
  471. ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area::get_space_override_mode);
  472. ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area::set_gravity_is_point);
  473. ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area::is_gravity_a_point);
  474. ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area::set_gravity_distance_scale);
  475. ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area::get_gravity_distance_scale);
  476. ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area::set_gravity_vector);
  477. ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area::get_gravity_vector);
  478. ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area::set_gravity);
  479. ClassDB::bind_method(D_METHOD("get_gravity"), &Area::get_gravity);
  480. ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area::set_angular_damp);
  481. ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area::get_angular_damp);
  482. ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area::set_linear_damp);
  483. ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area::get_linear_damp);
  484. ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area::set_priority);
  485. ClassDB::bind_method(D_METHOD("get_priority"), &Area::get_priority);
  486. ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area::set_collision_mask);
  487. ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area::get_collision_mask);
  488. ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area::set_collision_layer);
  489. ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area::get_collision_layer);
  490. ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area::set_collision_mask_bit);
  491. ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area::get_collision_mask_bit);
  492. ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area::set_collision_layer_bit);
  493. ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area::get_collision_layer_bit);
  494. ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area::set_monitorable);
  495. ClassDB::bind_method(D_METHOD("is_monitorable"), &Area::is_monitorable);
  496. ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area::set_monitoring);
  497. ClassDB::bind_method(D_METHOD("is_monitoring"), &Area::is_monitoring);
  498. ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area::get_overlapping_bodies);
  499. ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area::get_overlapping_areas);
  500. ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area::overlaps_body);
  501. ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area::overlaps_area);
  502. ClassDB::bind_method(D_METHOD("_body_inout"), &Area::_body_inout);
  503. ClassDB::bind_method(D_METHOD("_area_inout"), &Area::_area_inout);
  504. ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area::set_audio_bus_override);
  505. ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area::is_overriding_audio_bus);
  506. ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area::set_audio_bus);
  507. ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area::get_audio_bus);
  508. ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area::set_use_reverb_bus);
  509. ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area::is_using_reverb_bus);
  510. ClassDB::bind_method(D_METHOD("set_reverb_bus", "name"), &Area::set_reverb_bus);
  511. ClassDB::bind_method(D_METHOD("get_reverb_bus"), &Area::get_reverb_bus);
  512. ClassDB::bind_method(D_METHOD("set_reverb_amount", "amount"), &Area::set_reverb_amount);
  513. ClassDB::bind_method(D_METHOD("get_reverb_amount"), &Area::get_reverb_amount);
  514. ClassDB::bind_method(D_METHOD("set_reverb_uniformity", "amount"), &Area::set_reverb_uniformity);
  515. ClassDB::bind_method(D_METHOD("get_reverb_uniformity"), &Area::get_reverb_uniformity);
  516. ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape")));
  517. ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape")));
  518. ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
  519. ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
  520. ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape")));
  521. ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape")));
  522. ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area")));
  523. ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area")));
  524. 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");
  525. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point");
  526. 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");
  527. ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "gravity_vec"), "set_gravity_vector", "get_gravity_vector");
  528. ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_gravity", "get_gravity");
  529. ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "0,1024,0.001"), "set_linear_damp", "get_linear_damp");
  530. ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "0,1024,0.001"), "set_angular_damp", "get_angular_damp");
  531. ADD_PROPERTY(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,128,1"), "set_priority", "get_priority");
  532. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitoring"), "set_monitoring", "is_monitoring");
  533. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "monitorable"), "set_monitorable", "is_monitorable");
  534. ADD_GROUP("Collision", "collision_");
  535. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
  536. ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
  537. ADD_GROUP("Audio Bus", "audio_bus_");
  538. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_bus_override"), "set_audio_bus_override", "is_overriding_audio_bus");
  539. ADD_PROPERTY(PropertyInfo(Variant::STRING, "audio_bus_name", PROPERTY_HINT_ENUM, ""), "set_audio_bus", "get_audio_bus");
  540. ADD_GROUP("Reverb Bus", "reverb_bus_");
  541. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reverb_bus_enable"), "set_use_reverb_bus", "is_using_reverb_bus");
  542. ADD_PROPERTY(PropertyInfo(Variant::STRING, "reverb_bus_name", PROPERTY_HINT_ENUM, ""), "set_reverb_bus", "get_reverb_bus");
  543. ADD_PROPERTY(PropertyInfo(Variant::REAL, "reverb_bus_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_reverb_amount", "get_reverb_amount");
  544. ADD_PROPERTY(PropertyInfo(Variant::REAL, "reverb_bus_uniformity", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_reverb_uniformity", "get_reverb_uniformity");
  545. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_DISABLED);
  546. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_COMBINE);
  547. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_COMBINE_REPLACE);
  548. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE);
  549. BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE_COMBINE);
  550. }
  551. Area::Area() :
  552. CollisionObject(PhysicsServer::get_singleton()->area_create(), true) {
  553. space_override = SPACE_OVERRIDE_DISABLED;
  554. set_gravity(9.8);
  555. locked = false;
  556. set_gravity_vector(Vector3(0, -1, 0));
  557. gravity_is_point = false;
  558. gravity_distance_scale = 0;
  559. linear_damp = 0.1;
  560. angular_damp = 1;
  561. priority = 0;
  562. monitoring = false;
  563. collision_mask = 1;
  564. collision_layer = 1;
  565. set_ray_pickable(false);
  566. set_monitoring(true);
  567. set_monitorable(true);
  568. audio_bus_override = false;
  569. audio_bus = "Master";
  570. use_reverb_bus = false;
  571. reverb_bus = "Master";
  572. reverb_amount = 0.0;
  573. reverb_uniformity = 0.0;
  574. }
  575. Area::~Area() {
  576. }