zone.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "T3D/zone.h"
  24. #include "console/consoleTypes.h"
  25. #include "console/engineAPI.h"
  26. #include "scene/mixin/sceneAmbientSoundObject.impl.h"
  27. #include "scene/mixin/scenePolyhedralObject.impl.h"
  28. #include "scene/sceneManager.h"
  29. #include "gui/worldEditor/worldEditor.h"
  30. IMPLEMENT_CO_NETOBJECT_V1( Zone );
  31. ConsoleDocClass( Zone,
  32. "@brief An object that represents an interior space.\n\n"
  33. "A zone is an invisible volume that encloses an interior space. All objects that have "
  34. "their world space axis-aligned bounding boxes (AABBs) intersect the zone's volume are "
  35. "assigned to the zone. This assignment happens automatically as objects are placed "
  36. "and transformed. Also, assignment is not exclusive meaning that an object can be assigned "
  37. "to many zones at the same time if it intersects all of them.\n\n"
  38. "In itself, the volume of a zone is fully sealed off from the outside. This means that while "
  39. "viewing the scene from inside the volume, only objects assigned to the zone are rendered while "
  40. "when viewing the scene from outside the volume, objects <em>exclusively</em> only assigned the "
  41. "zone are not rendered.\n\n"
  42. "Usually, you will want to connect zones to each other by means of portals. A portal overlapping "
  43. "with a zone \n\n"
  44. "@tsexample\n"
  45. "// Example declaration of a Zone. This creates a box-shaped zone.\n"
  46. "new Zone( TestZone )\n"
  47. "{\n"
  48. " position = \"3.61793 -1.01945 14.7442\";\n"
  49. " rotation = \"1 0 0 0\";\n"
  50. " scale = \"10 10 10\";\n"
  51. "};\n"
  52. "@endtsexample\n\n"
  53. "@section Zone_zoneGroups Zone Groups\n\n"
  54. "Normally, Zones will not connect to each other when they overlap. This means that if viewing "
  55. "the scene from one zone, the contents of the other zone will not be visible except when there "
  56. "is a portal connecting the zones. However, sometimes it is convenient to represent a single interior "
  57. "space through a combination of Zones so that when any of these zones is visible, all other zones "
  58. "that are part of the same interior space are visible. This is possible by employing \"zone groups\".\n\n"
  59. "@see Portal\n"
  60. "@ingroup enviroMisc\n"
  61. );
  62. //-----------------------------------------------------------------------------
  63. void Zone::consoleInit()
  64. {
  65. // Disable rendering of zones by default.
  66. getStaticClassRep()->mIsRenderEnabled = false;
  67. }
  68. #ifdef TORQUE_TOOLS
  69. void Zone::initPersistFields()
  70. {
  71. docsURL;
  72. addProtectedField("selectAll", TypeBool, Offset(mSelecting, Zone),
  73. &_doSelect, &defaultProtectedGetFn, "Select all in this zone", AbstractClassRep::FieldFlags::FIELD_ComponentInspectors);
  74. Parent::initPersistFields();
  75. }
  76. bool Zone::_doSelect(void* object, const char* index, const char* data)
  77. {
  78. Zone* zone = reinterpret_cast<Zone*>(object);
  79. zone->selectWithin();
  80. return false;
  81. }
  82. void Zone::selectWithin()
  83. {
  84. SimpleQueryList sql;
  85. Zone* zoneClient = (Zone*)getClientObject();
  86. if (zoneClient)
  87. {
  88. SceneZoneSpaceManager* zoneManager = zoneClient->getSceneManager()->getZoneManager();
  89. if (zoneManager)
  90. {
  91. for (U32 zoneId = zoneClient->mZoneRangeStart; zoneId < zoneClient->mZoneRangeStart + zoneClient->mNumZones; ++zoneId)
  92. for (SceneZoneSpaceManager::ZoneContentIterator iter(zoneManager, zoneId, false); iter.isValid(); ++iter)
  93. {
  94. SceneObject* obj = (SceneObject*)iter->getServerObject();
  95. bool fullyEnclosed = true;
  96. for (SceneObject::ObjectZonesIterator zoneIter(obj); zoneIter.isValid(); ++zoneIter)
  97. {
  98. if (*zoneIter != zoneId)
  99. fullyEnclosed = false;
  100. }
  101. if (fullyEnclosed)
  102. sql.insertObject(obj);
  103. }
  104. }
  105. }
  106. WorldEditor* wedit;
  107. if (Sim::findObject("EWorldEditor", wedit))
  108. {
  109. wedit->clearSelection();
  110. wedit->selectObject(this);
  111. for (SceneObject** i = sql.mList.begin(); i != sql.mList.end(); i++)
  112. {
  113. wedit->selectObject(*i);
  114. }
  115. }
  116. }
  117. #endif
  118. //=============================================================================
  119. // Console API.
  120. //=============================================================================
  121. // MARK: ---- Console API ----
  122. //-----------------------------------------------------------------------------
  123. DefineEngineMethod( Zone, getZoneId, S32, (),,
  124. "Get the unique numeric ID of the zone in its scene.\n\n"
  125. "@return The ID of the zone." )
  126. {
  127. return object->getZoneRangeStart();
  128. }
  129. //-----------------------------------------------------------------------------
  130. DefineEngineMethod( Zone, dumpZoneState, void, ( bool updateFirst ), ( true ),
  131. "Dump a list of all objects assigned to the zone to the console as well as a list "
  132. "of all connected zone spaces.\n\n"
  133. "@param updateFirst Whether to update the contents of the zone before dumping. Since zoning states of "
  134. "objects are updated on demand, the zone contents can be outdated." )
  135. {
  136. object->dumpZoneState( updateFirst );
  137. }
  138. #ifdef TORQUE_TOOLS
  139. DefineEngineMethod(Zone, selectWithin, void, () ,,
  140. "select a list of all objects assigned to the zone")
  141. {
  142. object->selectWithin();
  143. }
  144. #endif