zone.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. void Zone::initPersistFields()
  69. {
  70. addProtectedField("selectAll", TypeBool, Offset(mSelecting, Zone),
  71. &_doSelect, &defaultProtectedGetFn, "Select all in this zone", AbstractClassRep::FieldFlags::FIELD_ComponentInspectors);
  72. Parent::initPersistFields();
  73. }
  74. bool Zone::_doSelect(void* object, const char* index, const char* data)
  75. {
  76. Zone* zone = reinterpret_cast<Zone*>(object);
  77. zone->selectWithin();
  78. return false;
  79. }
  80. void Zone::selectWithin()
  81. {
  82. SimpleQueryList sql;
  83. Zone* zoneClient = (Zone*)getClientObject();
  84. if (zoneClient)
  85. {
  86. SceneZoneSpaceManager* zoneManager = zoneClient->getSceneManager()->getZoneManager();
  87. if (zoneManager)
  88. {
  89. for (U32 zoneId = zoneClient->mZoneRangeStart; zoneId < zoneClient->mZoneRangeStart + zoneClient->mNumZones; ++zoneId)
  90. for (SceneZoneSpaceManager::ZoneContentIterator iter(zoneManager, zoneId, false); iter.isValid(); ++iter)
  91. {
  92. SceneObject* obj = (SceneObject*)iter->getServerObject();
  93. bool fullyEnclosed = true;
  94. for (SceneObject::ObjectZonesIterator zoneIter(obj); zoneIter.isValid(); ++zoneIter)
  95. {
  96. if (*zoneIter != zoneId)
  97. fullyEnclosed = false;
  98. }
  99. if (fullyEnclosed)
  100. sql.insertObject(obj);
  101. }
  102. }
  103. }
  104. WorldEditor* wedit;
  105. if (Sim::findObject("EWorldEditor", wedit))
  106. {
  107. wedit->clearSelection();
  108. wedit->selectObject(this);
  109. for (SceneObject** i = sql.mList.begin(); i != sql.mList.end(); i++)
  110. {
  111. wedit->selectObject(*i);
  112. }
  113. }
  114. }
  115. //=============================================================================
  116. // Console API.
  117. //=============================================================================
  118. // MARK: ---- Console API ----
  119. //-----------------------------------------------------------------------------
  120. DefineEngineMethod( Zone, getZoneId, S32, (),,
  121. "Get the unique numeric ID of the zone in its scene.\n\n"
  122. "@return The ID of the zone." )
  123. {
  124. return object->getZoneRangeStart();
  125. }
  126. //-----------------------------------------------------------------------------
  127. DefineEngineMethod( Zone, dumpZoneState, void, ( bool updateFirst ), ( true ),
  128. "Dump a list of all objects assigned to the zone to the console as well as a list "
  129. "of all connected zone spaces.\n\n"
  130. "@param updateFirst Whether to update the contents of the zone before dumping. Since zoning states of "
  131. "objects are updated on demand, the zone contents can be outdated." )
  132. {
  133. object->dumpZoneState( updateFirst );
  134. }
  135. DefineEngineMethod(Zone, selectWithin, void, () ,,
  136. "select a list of all objects assigned to the zone")
  137. {
  138. object->selectWithin();
  139. }