sceneTracker.h

Engine/source/scene/sceneTracker.h

This file contains an abstract framework for tracking SceneObjects.

More...

Classes:

class

A SceneObjectLink represents the link between a SceneObject and a SceneTracker.

class

A SceneTracker tracks SceneObjects.

Detailed Description

This file contains an abstract framework for tracking SceneObjects.

  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 _SCENETRACKER_H_
 25#define _SCENETRACKER_H_
 26
 27#ifndef _SCENEOBJECT_H_
 28   #include "scene/sceneObject.h"
 29#endif
 30
 31
 32/// @file
 33/// This file contains an abstract framework for tracking SceneObjects.
 34
 35
 36class SceneTracker;
 37
 38
 39//-----------------------------------------------------------------------------
 40//    SceneObjectLink.
 41//-----------------------------------------------------------------------------
 42
 43
 44/// A SceneObjectLink represents the link between a SceneObject and a SceneTracker.
 45class SceneObjectLink
 46{
 47   public:
 48   
 49      typedef void Parent;
 50      friend class SceneTracker; // Administers our link fields.
 51
 52   protected:
 53   
 54      /// SceneObject being linked to; always set and never changes.
 55      SceneObject* mObject;
 56      
 57      /// The scene tracker to which this link belongs.
 58      SceneTracker* mTracker;
 59            
 60      /// Next scope link on this SceneObject; NULL if last.
 61      SceneObjectLink* mNextLink;
 62      
 63      /// Previous scope link on this SceneObject; NULL if first.
 64      SceneObjectLink* mPrevLink;
 65
 66   public:
 67   
 68      ///
 69      SceneObjectLink( SceneTracker* tracker, SceneObject* object );
 70      
 71      virtual ~SceneObjectLink();
 72
 73      /// @return The SceneScopeTracker managing this link.
 74      SceneTracker* getTracker() const { return mTracker; }
 75
 76      /// @return The object being linked to.
 77      SceneObject* getObject() const { return mObject; }
 78      
 79      /// @return The next link in this link chain.
 80      SceneObjectLink* getNextLink() const { return mNextLink; }
 81      
 82      /// @return The previous link in this link chain.
 83      SceneObjectLink* getPrevLink() const { return mPrevLink; }
 84
 85      /// Notify the associated tracker that the transform state of the
 86      /// scene object represented by this link has changed.
 87      void update();
 88
 89      ///
 90      static SceneObjectLink* getLinkForTracker( SceneTracker* tracker, SceneObject* fromObject );
 91};
 92
 93
 94//-----------------------------------------------------------------------------
 95//    SceneTracker.
 96//-----------------------------------------------------------------------------
 97
 98
 99/// A SceneTracker tracks SceneObjects.
100///
101/// This is an abstract base class.
102class SceneTracker
103{
104   public:
105   
106      typedef void Parent;
107      friend class SceneObjectLink; // SceneObjectLink::update() notifies us on SceneObject state changes.
108
109   protected:
110   
111      /// If true, only client SceneObjects will be tracked; otherwise it's only server SceneObjects.
112      bool mIsClientTracker;
113      
114      /// Type mask that SceneObjects must match in order to be allowed to register.
115      U32 mObjectTypeMask;
116      
117      /// Return true if the given object qualifies for being managed by this SceneTracker.
118      virtual bool _isTrackableObject( SceneObject* object ) const
119      {
120         return ( object->isClientObject() == mIsClientTracker
121                  && ( object->getTypeMask() & getObjectTypeMask() ) );
122      }
123
124      /// Callback used for the initial scan of objects in init().
125      static void _containerFindCallback( SceneObject* object, SceneTracker* tracker );
126
127   public:
128   
129      ///
130      SceneTracker( bool isClientTracker, U32 typeMask = 0xFFFFFFFF );
131      
132      virtual ~SceneTracker();
133      
134      /// Initialize the tracker from the current scene.
135      virtual void init();
136
137      /// @return The type mask that must be matched by objects in order to be allowed to register.
138      U32 getObjectTypeMask() const { return mObjectTypeMask; }
139      
140      /// Set the type mask that objects must match in order to be allowed to register.
141      void setObjectTypeMask( U32 typeMask ) { mObjectTypeMask = typeMask; }
142
143      /// @return True if this tracker only deals with client objects; false if only server objects.
144      bool isClientTracker() const { return mIsClientTracker; }
145
146      /// Register a SceneObject for being tracked by this tracker.
147      ///
148      /// Only objects that fit the tracker's client/server state and
149      /// object type mask will actually get registered.  For other objects,
150      /// this is a NOP.
151      ///
152      /// @param object Scene object.
153      virtual void registerObject( SceneObject* object ) = 0;
154
155      /// Unregister the given object from the tracker.
156      /// @param object Scene object.
157      virtual void unregisterObject( SceneObject* object ) = 0;
158
159      /// Notify the tracker that the transform state of the given scene object has changed.
160      /// @param object Scene object.
161      virtual void updateObject( SceneObjectLink* object ) = 0;
162};
163
164#endif // !_SCENETRACKER_H_
165