sceneTraversalState.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifndef _SCENETRAVERSALSTATE_H_
  23. #define _SCENETRAVERSALSTATE_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. #ifndef _MBOX_H_
  28. #include "math/mBox.h"
  29. #endif
  30. #ifndef _MPLANESET_H_
  31. #include "math/mPlaneSet.h"
  32. #endif
  33. class SceneCullingState;
  34. class SceneCullingVolume;
  35. class SceneZoneSpace;
  36. /// Temporary state for zone traversals. Keeps track of the zones
  37. /// that were visited in the current traversal chain as well as of
  38. /// the total area that so far has been visited in the traversal.
  39. class SceneTraversalState
  40. {
  41. protected:
  42. /// Scene culling state.
  43. SceneCullingState* mCullingState;
  44. /// Stack of zones visited in current traversal chain.
  45. Vector< U32 > mZoneStack;
  46. /// Stack of culling volumes. Topmost is current volume.
  47. Vector< SceneCullingVolume > mCullingVolumeStack;
  48. /// Area of scene visited in traversal.
  49. Box3F mTraversedArea;
  50. public:
  51. /// Construct an empty scene traversal state.
  52. /// @param cullingState Scene culling state.
  53. SceneTraversalState( SceneCullingState* cullingState );
  54. /// Return the scene culling state for this traversal.
  55. SceneCullingState* getCullingState() const { return mCullingState; }
  56. /// Get the scene area that has been visited so far in the traversal.
  57. const Box3F& getTraversedArea() const { return mTraversedArea; }
  58. /// Add an area to what has been visited so far in the traversal.
  59. void addToTraversedArea( const Box3F& area ) { mTraversedArea.intersect( area ); }
  60. /// @name Zone Stack
  61. /// @{
  62. /// Return the number of zones that are currently on the traversal stack.
  63. U32 getTraversalDepth() const { return mZoneStack.size(); }
  64. /// Push a zone onto the traversal stack.
  65. void pushZone( U32 zoneId ) { mZoneStack.push_back( zoneId ); }
  66. /// Pop the topmost zone from the traversal stack.
  67. void popZone() { mZoneStack.pop_back(); }
  68. /// Return true if the given zone has already been visited in the
  69. /// current traversal chain, i.e. if it is currently on the traversal
  70. /// stack.
  71. bool haveVisitedZone( U32 zoneId ) const { return mZoneStack.contains( zoneId ); }
  72. /// Return the zone ID of the topmost zone on the traversal stack.
  73. U32 getZoneIdFromStack( U32 depth = 0 ) { return mZoneStack[ mZoneStack.size() - 1 - depth ]; }
  74. /// Return the zone space that owns the topmost zone on the traversal stack.
  75. SceneZoneSpace* getZoneFromStack( U32 depth = 0 );
  76. /// @}
  77. /// @name Culling Volume Stack
  78. /// @{
  79. /// Push a culling volume onto the stack so that it becomes the current culling
  80. /// volume.
  81. void pushCullingVolume( const SceneCullingVolume& volume );
  82. /// Pop the current culling volume from the stack.
  83. void popCullingVolume();
  84. ///
  85. const SceneCullingVolume& getCurrentCullingVolume() const { return mCullingVolumeStack.last(); }
  86. /// @}
  87. };
  88. #endif // !_SCENETRAVERSALSTATE_H_