zone.cpp 6.5 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 "gui/worldEditor/worldEditor.h"
  29. IMPLEMENT_CO_NETOBJECT_V1( Zone );
  30. ConsoleDocClass( Zone,
  31. "@brief An object that represents an interior space.\n\n"
  32. "A zone is an invisible volume that encloses an interior space. All objects that have "
  33. "their world space axis-aligned bounding boxes (AABBs) intersect the zone's volume are "
  34. "assigned to the zone. This assignment happens automatically as objects are placed "
  35. "and transformed. Also, assignment is not exclusive meaning that an object can be assigned "
  36. "to many zones at the same time if it intersects all of them.\n\n"
  37. "In itself, the volume of a zone is fully sealed off from the outside. This means that while "
  38. "viewing the scene from inside the volume, only objects assigned to the zone are rendered while "
  39. "when viewing the scene from outside the volume, objects <em>exclusively</em> only assigned the "
  40. "zone are not rendered.\n\n"
  41. "Usually, you will want to connect zones to each other by means of portals. A portal overlapping "
  42. "with a zone \n\n"
  43. "@tsexample\n"
  44. "// Example declaration of a Zone. This creates a box-shaped zone.\n"
  45. "new Zone( TestZone )\n"
  46. "{\n"
  47. " position = \"3.61793 -1.01945 14.7442\";\n"
  48. " rotation = \"1 0 0 0\";\n"
  49. " scale = \"10 10 10\";\n"
  50. "};\n"
  51. "@endtsexample\n\n"
  52. "@section Zone_zoneGroups Zone Groups\n\n"
  53. "Normally, Zones will not connect to each other when they overlap. This means that if viewing "
  54. "the scene from one zone, the contents of the other zone will not be visible except when there "
  55. "is a portal connecting the zones. However, sometimes it is convenient to represent a single interior "
  56. "space through a combination of Zones so that when any of these zones is visible, all other zones "
  57. "that are part of the same interior space are visible. This is possible by employing \"zone groups\".\n\n"
  58. "@see Portal\n"
  59. "@ingroup enviroMisc\n"
  60. );
  61. //-----------------------------------------------------------------------------
  62. void Zone::consoleInit()
  63. {
  64. // Disable rendering of zones by default.
  65. getStaticClassRep()->mIsRenderEnabled = false;
  66. }
  67. void Zone::initPersistFields()
  68. {
  69. addProtectedField("selectAll", TypeBool, Offset(mSelecting, Zone),
  70. &_doSelect, &defaultProtectedGetFn, "Select all in this zone", AbstractClassRep::FieldFlags::FIELD_ComponentInspectors);
  71. Parent::initPersistFields();
  72. }
  73. bool Zone::_doSelect(void* object, const char* index, const char* data)
  74. {
  75. Zone* zone = reinterpret_cast<Zone*>(object);
  76. zone->selectWithin();
  77. return false;
  78. }
  79. void Zone::selectWithin()
  80. {
  81. SimpleQueryList sql;
  82. //getContainer()->polyhedronFindObjects(getPolyhedron(), 0xFFFFFFFF, SimpleQueryList::insertionCallback, &sql);
  83. //replace the above with this once we stort out how to look up the managed zoneID from the insatnce itself
  84. Zone* zoneClient = (Zone*)getClientObject();
  85. SceneZoneSpaceManager* zoneManager = zoneClient->getSceneManager()->getZoneManager();
  86. if (zoneManager)
  87. {
  88. for (U32 zoneId = zoneClient->mZoneRangeStart; zoneId < zoneClient->mZoneRangeStart + zoneClient->mNumZones; ++zoneId)
  89. for (SceneZoneSpaceManager::ZoneContentIterator iter(zoneManager, zoneId, false); iter.isValid(); ++iter)
  90. {
  91. SceneObject* obj = (SceneObject*)iter->getServerObject();
  92. bool fullyEnclosed = true;
  93. for (SceneObject::ObjectZonesIterator zoneIter(obj); zoneIter.isValid(); ++zoneIter)
  94. {
  95. if (*zoneIter != zoneId);
  96. fullyEnclosed = false;
  97. }
  98. if (fullyEnclosed)
  99. sql.insertObject(obj);
  100. }
  101. }
  102. WorldEditor* wedit;
  103. if (Sim::findObject("EWorldEditor", wedit))
  104. {
  105. wedit->clearSelection();
  106. wedit->selectObject(this);
  107. for (SceneObject** i = sql.mList.begin(); i != sql.mList.end(); i++)
  108. {
  109. wedit->selectObject(*i);
  110. }
  111. }
  112. }
  113. //=============================================================================
  114. // Console API.
  115. //=============================================================================
  116. // MARK: ---- Console API ----
  117. //-----------------------------------------------------------------------------
  118. DefineEngineMethod( Zone, getZoneId, S32, (),,
  119. "Get the unique numeric ID of the zone in its scene.\n\n"
  120. "@return The ID of the zone." )
  121. {
  122. return object->getZoneRangeStart();
  123. }
  124. //-----------------------------------------------------------------------------
  125. DefineEngineMethod( Zone, dumpZoneState, void, ( bool updateFirst ), ( true ),
  126. "Dump a list of all objects assigned to the zone to the console as well as a list "
  127. "of all connected zone spaces.\n\n"
  128. "@param updateFirst Whether to update the contents of the zone before dumping. Since zoning states of "
  129. "objects are updated on demand, the zone contents can be outdated." )
  130. {
  131. object->dumpZoneState( updateFirst );
  132. }
  133. DefineEngineMethod(Zone, selectWithin, void, () ,,
  134. "select a list of all objects assigned to the zone")
  135. {
  136. object->selectWithin();
  137. }