sceneTraversalState.h
Engine/source/scene/zones/sceneTraversalState.h
Classes:
class
Temporary state for zone traversals.
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _SCENETRAVERSALSTATE_H_ 25#define _SCENETRAVERSALSTATE_H_ 26 27#ifndef _TVECTOR_H_ 28#include "core/util/tVector.h" 29#endif 30 31#ifndef _MBOX_H_ 32#include "math/mBox.h" 33#endif 34 35#ifndef _MPLANESET_H_ 36#include "math/mPlaneSet.h" 37#endif 38 39 40class SceneCullingState; 41class SceneCullingVolume; 42class SceneZoneSpace; 43 44 45/// Temporary state for zone traversals. Keeps track of the zones 46/// that were visited in the current traversal chain as well as of 47/// the total area that so far has been visited in the traversal. 48class SceneTraversalState 49{ 50 protected: 51 52 /// Scene culling state. 53 SceneCullingState* mCullingState; 54 55 /// Stack of zones visited in current traversal chain. 56 Vector< U32> mZoneStack; 57 58 /// Stack of culling volumes. Topmost is current volume. 59 Vector< SceneCullingVolume> mCullingVolumeStack; 60 61 /// Area of scene visited in traversal. 62 Box3F mTraversedArea; 63 64 public: 65 66 /// Construct an empty scene traversal state. 67 /// @param cullingState Scene culling state. 68 SceneTraversalState( SceneCullingState* cullingState ); 69 70 /// Return the scene culling state for this traversal. 71 SceneCullingState* getCullingState() const { return mCullingState; } 72 73 /// Get the scene area that has been visited so far in the traversal. 74 const Box3F& getTraversedArea() const { return mTraversedArea; } 75 76 /// Add an area to what has been visited so far in the traversal. 77 void addToTraversedArea( const Box3F& area ) { mTraversedArea.intersect( area ); } 78 79 /// @name Zone Stack 80 /// @{ 81 82 /// Return the number of zones that are currently on the traversal stack. 83 U32 getTraversalDepth() const { return mZoneStack.size(); } 84 85 /// Push a zone onto the traversal stack. 86 void pushZone( U32 zoneId ) { mZoneStack.push_back( zoneId ); } 87 88 /// Pop the topmost zone from the traversal stack. 89 void popZone() { mZoneStack.pop_back(); } 90 91 /// Return true if the given zone has already been visited in the 92 /// current traversal chain, i.e. if it is currently on the traversal 93 /// stack. 94 bool haveVisitedZone( U32 zoneId ) const { return mZoneStack.contains( zoneId ); } 95 96 /// Return the zone ID of the topmost zone on the traversal stack. 97 U32 getZoneIdFromStack( U32 depth = 0 ) { return mZoneStack[ mZoneStack.size() - 1 - depth ]; } 98 99 /// Return the zone space that owns the topmost zone on the traversal stack. 100 SceneZoneSpace* getZoneFromStack( U32 depth = 0 ); 101 102 /// @} 103 104 /// @name Culling Volume Stack 105 /// @{ 106 107 /// Push a culling volume onto the stack so that it becomes the current culling 108 /// volume. 109 void pushCullingVolume( const SceneCullingVolume& volume ); 110 111 /// Pop the current culling volume from the stack. 112 void popCullingVolume(); 113 114 /// 115 const SceneCullingVolume& getCurrentCullingVolume() const { return mCullingVolumeStack.last(); } 116 117 /// @} 118}; 119 120#endif // !_SCENETRAVERSALSTATE_H_ 121