room_instance.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*************************************************************************/
  2. /* room_instance.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "room_instance.h"
  31. #include "servers/visual_server.h"
  32. // FIXME: Will be removed, kept as reference for new implementation
  33. #if 0
  34. #include "geometry.h"
  35. #include "project_settings.h"
  36. #include "scene/resources/surface_tool.h"
  37. void Room::_notification(int p_what) {
  38. switch (p_what) {
  39. case NOTIFICATION_ENTER_WORLD: {
  40. // go find parent level
  41. Node *parent_room = get_parent();
  42. level = 0;
  43. while (parent_room) {
  44. Room *r = Object::cast_to<Room>(parent_room);
  45. if (r) {
  46. level = r->level + 1;
  47. break;
  48. }
  49. parent_room = parent_room->get_parent();
  50. }
  51. } break;
  52. case NOTIFICATION_TRANSFORM_CHANGED: {
  53. } break;
  54. case NOTIFICATION_EXIT_WORLD: {
  55. } break;
  56. }
  57. }
  58. Rect3 Room::get_aabb() const {
  59. if (room.is_null())
  60. return Rect3();
  61. return Rect3();
  62. }
  63. PoolVector<Face3> Room::get_faces(uint32_t p_usage_flags) const {
  64. return PoolVector<Face3>();
  65. }
  66. void Room::set_room(const Ref<RoomBounds> &p_room) {
  67. room = p_room;
  68. update_gizmo();
  69. if (room.is_valid()) {
  70. set_base(room->get_rid());
  71. } else {
  72. set_base(RID());
  73. }
  74. if (!is_inside_tree())
  75. return;
  76. propagate_notification(NOTIFICATION_AREA_CHANGED);
  77. update_gizmo();
  78. }
  79. Ref<RoomBounds> Room::get_room() const {
  80. return room;
  81. }
  82. void Room::_parse_node_faces(PoolVector<Face3> &all_faces, const Node *p_node) const {
  83. const VisualInstance *vi = Object::cast_to<VisualInstance>(p_node);
  84. if (vi) {
  85. PoolVector<Face3> faces = vi->get_faces(FACES_ENCLOSING);
  86. if (faces.size()) {
  87. int old_len = all_faces.size();
  88. all_faces.resize(all_faces.size() + faces.size());
  89. int new_len = all_faces.size();
  90. PoolVector<Face3>::Write all_facesw = all_faces.write();
  91. Face3 *all_facesptr = all_facesw.ptr();
  92. PoolVector<Face3>::Read facesr = faces.read();
  93. const Face3 *facesptr = facesr.ptr();
  94. Transform tr = vi->get_relative_transform(this);
  95. for (int i = old_len; i < new_len; i++) {
  96. Face3 f = facesptr[i - old_len];
  97. for (int j = 0; j < 3; j++)
  98. f.vertex[j] = tr.xform(f.vertex[j]);
  99. all_facesptr[i] = f;
  100. }
  101. }
  102. }
  103. for (int i = 0; i < p_node->get_child_count(); i++) {
  104. _parse_node_faces(all_faces, p_node->get_child(i));
  105. }
  106. }
  107. void Room::_bounds_changed() {
  108. update_gizmo();
  109. }
  110. void Room::_bind_methods() {
  111. ClassDB::bind_method(D_METHOD("set_room", "room"), &Room::set_room);
  112. ClassDB::bind_method(D_METHOD("get_room"), &Room::get_room);
  113. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "room/room", PROPERTY_HINT_RESOURCE_TYPE, "Area"), "set_room", "get_room");
  114. }
  115. Room::Room() {
  116. // sound_enabled=false;
  117. level = 0;
  118. }
  119. Room::~Room() {
  120. }
  121. #endif