Browse Source

SceneGraph: allow features to access scene and object's dirty status.

The downside of this is that the functions are now virtual, which makes
them slower than before. Maybe final qualifier would help?

AbstractObject::sceneObject() is marked as private in Object to avoid
confusion.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
342d2f46ac
  1. 55
      src/SceneGraph/AbstractObject.h
  2. 47
      src/SceneGraph/Object.h
  3. 14
      src/SceneGraph/Object.hpp

55
src/SceneGraph/AbstractObject.h

@ -79,6 +79,19 @@ template<std::uint8_t dimensions, class T = GLfloat> class AbstractObject
return Corrade::Containers::LinkedList<AbstractFeature<dimensions, T>>::last();
}
/**
* @brief %Scene object
* @return Root object which is also scene or `nullptr`, if the object
* is not part of any scene.
*
* @todo Rename to scene() when I fully understand and fix covariant
* return issues.
*/
virtual AbstractObject<dimensions, T>* sceneObject() = 0;
/** @overload */
virtual const AbstractObject<dimensions, T>* sceneObject() const = 0;
/** @{ @name Object transformation */
/**
@ -89,6 +102,48 @@ template<std::uint8_t dimensions, class T = GLfloat> class AbstractObject
virtual typename DimensionTraits<dimensions, T>::MatrixType absoluteTransformationMatrix() const = 0;
/*@}*/
/**
* @{ @name Transformation caching
*
* See @ref scenegraph-caching for more information.
*/
/**
* @brief Whether absolute transformation is dirty
*
* Returns `true` if transformation of the object or any parent has
* changed since last call to setClean(), `false` otherwise.
*
* All objects are dirty by default.
*
* @see @ref scenegraph-caching
*/
virtual bool isDirty() const = 0;
/**
* @brief Set object absolute transformation as dirty
*
* Calls AbstractFeature::markDirty() on all object features and
* recursively calls setDirty() on every child object which is not
* already dirty. If the object is already marked as dirty, the
* function does nothing.
* @see @ref scenegraph-caching, setClean(), isDirty()
*/
virtual void setDirty() = 0;
/**
* @brief Clean object absolute transformation
*
* Calls AbstractFeature::clean() and/or AbstractFeature::cleanInverted()
* on all object features which have caching enabled and recursively
* calls setClean() on every parent which is not already clean. If the
* object is already clean, the function does nothing.
* @see @ref scenegraph-caching, setDirty(), isDirty()
*/
virtual void setClean() = 0;
/*@}*/
};
/**

47
src/SceneGraph/Object.h

@ -188,49 +188,14 @@ template<class Transformation> class Object: public AbstractObject<Transformatio
/*@}*/
/**
* @{ @name Transformation caching
*
* See @ref scenegraph-caching for more information.
*/
/**
* @brief Whether absolute transformation is dirty
*
* Returns `true` if transformation of the object or any parent has
* changed since last call to setClean(), `false` otherwise.
*
* All objects are dirty by default.
*
* @see @ref scenegraph-caching
*/
inline bool isDirty() const { return !!(flags & Flag::Dirty); }
/**
* @brief Set object absolute transformation as dirty
*
* Calls AbstractFeature::markDirty() on all object features and
* recursively calls setDirty() on every child object which is not
* already dirty. If the object is already marked as dirty, the
* function does nothing.
* @see @ref scenegraph-caching, setClean(), isDirty()
*/
void setDirty();
/**
* @brief Clean object absolute transformation
*
* Calls AbstractFeature::clean() and/or AbstractFeature::cleanInverted()
* on all object features which have caching enabled and recursively
* calls setClean() on every parent which is not already clean. If the
* object is already clean, the function does nothing.
* @see @ref scenegraph-caching, setDirty(), isDirty()
*/
void setClean();
/*@}*/
inline bool isDirty() const override { return !!(flags & Flag::Dirty); }
void setDirty() override;
void setClean() override;
private:
Object<Transformation>* sceneObject() override;
const Object<Transformation>* sceneObject() const override;
typedef Implementation::ObjectFlag Flag;
typedef Implementation::ObjectFlags Flags;
Flags flags;

14
src/SceneGraph/Object.hpp

@ -28,15 +28,23 @@
namespace Magnum { namespace SceneGraph {
template<class Transformation> Scene<Transformation>* Object<Transformation>::scene() {
return static_cast<Scene<Transformation>*>(sceneObject());
}
template<class Transformation> const Scene<Transformation>* Object<Transformation>::scene() const {
return static_cast<const Scene<Transformation>*>(sceneObject());
}
template<class Transformation> Object<Transformation>* Object<Transformation>::sceneObject() {
Object<Transformation>* p(this);
while(p && !p->isScene()) p = p->parent();
return static_cast<Scene<Transformation>*>(p);
return p;
}
template<class Transformation> const Scene<Transformation>* Object<Transformation>::scene() const {
template<class Transformation> const Object<Transformation>* Object<Transformation>::sceneObject() const {
const Object<Transformation>* p(this);
while(p && !p->isScene()) p = p->parent();
return static_cast<const Scene<Transformation>*>(p);
return p;
}
template<class Transformation> Object<Transformation>* Object<Transformation>::setParent(Object<Transformation>* parent) {

Loading…
Cancel
Save