room_group.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**************************************************************************/
  2. /* room_group.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 "room_group.h"
  31. #include "room.h"
  32. #include "room_manager.h"
  33. void RoomGroup::_bind_methods() {
  34. ClassDB::bind_method(D_METHOD("set_roomgroup_priority", "p_priority"), &RoomGroup::set_roomgroup_priority);
  35. ClassDB::bind_method(D_METHOD("get_roomgroup_priority"), &RoomGroup::get_roomgroup_priority);
  36. ADD_PROPERTY(PropertyInfo(Variant::INT, "roomgroup_priority", PROPERTY_HINT_RANGE, "-16,16,1", PROPERTY_USAGE_DEFAULT), "set_roomgroup_priority", "get_roomgroup_priority");
  37. }
  38. RoomGroup::RoomGroup() {
  39. _room_group_rid = RID_PRIME(VisualServer::get_singleton()->roomgroup_create());
  40. }
  41. RoomGroup::~RoomGroup() {
  42. if (_room_group_rid != RID()) {
  43. VisualServer::get_singleton()->free(_room_group_rid);
  44. }
  45. }
  46. String RoomGroup::get_configuration_warning() const {
  47. String warning = Spatial::get_configuration_warning();
  48. if (Room::detect_nodes_of_type<RoomManager>(this)) {
  49. if (!warning.empty()) {
  50. warning += "\n\n";
  51. }
  52. warning += TTR("The RoomManager should not be placed inside a RoomGroup.");
  53. }
  54. return warning;
  55. }
  56. void RoomGroup::clear() {
  57. _roomgroup_ID = -1;
  58. }
  59. void RoomGroup::add_room(Room *p_room) {
  60. VisualServer::get_singleton()->roomgroup_add_room(_room_group_rid, p_room->_room_rid);
  61. }
  62. // extra editor links to the room manager to allow unloading
  63. // on change, or re-converting
  64. void RoomGroup::_changed() {
  65. #ifdef TOOLS_ENABLED
  66. RoomManager *rm = RoomManager::active_room_manager;
  67. if (!rm) {
  68. return;
  69. }
  70. rm->_rooms_changed("changed RoomGroup " + get_name());
  71. #endif
  72. }
  73. void RoomGroup::_notification(int p_what) {
  74. switch (p_what) {
  75. case NOTIFICATION_ENTER_WORLD: {
  76. ERR_FAIL_COND(get_world().is_null());
  77. VisualServer::get_singleton()->roomgroup_set_scenario(_room_group_rid, get_world()->get_scenario());
  78. } break;
  79. case NOTIFICATION_EXIT_WORLD: {
  80. VisualServer::get_singleton()->roomgroup_set_scenario(_room_group_rid, RID());
  81. } break;
  82. }
  83. }