Browse Source

SceneGraph: FeatureGroup compilation optimization.

Created less-templated base for FeatureGroup and moved its
implementation into *.hpp file, allowing to remove <algorithm> header
from FeatureGroup.h (and meanwhile removing forgotten one also from
AbstractGroupedFeature.h). Saved another ~10 seconds of compilation time
(previously ~4:21, now ~4:11).
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
0dfc0d0821
  1. 11
      src/SceneGraph/AbstractGroupedFeature.h
  2. 1
      src/SceneGraph/CMakeLists.txt
  3. 88
      src/SceneGraph/FeatureGroup.h
  4. 50
      src/SceneGraph/FeatureGroup.hpp
  5. 4
      src/SceneGraph/Object.cpp
  6. 6
      src/SceneGraph/SceneGraph.h

11
src/SceneGraph/AbstractGroupedFeature.h

@ -28,7 +28,6 @@
* @brief Class Magnum::SceneGraph::AbstractGroupedFeature, alias Magnum::SceneGraph::AbstractGroupedFeature2D, Magnum::SceneGraph::AbstractGroupedFeature3D
*/
#include <algorithm>
#include <vector>
#include "AbstractFeature.h"
@ -53,6 +52,16 @@ class Drawable: public SceneGraph::AbstractGroupedFeature3D<Drawable> {
typedef SceneGraph::FeatureGroup3D<Drawable> DrawableGroup;
@endcode
@section AbstractGroupedFeature-explicit-specializations Explicit template specializations
The following specialization are explicitly compiled into %SceneGraph library.
For other specializations (e.g. using Double type) you have to use
AbstractGroupedFeature.hpp implementation file to avoid linker errors. See also
@ref compilation-speedup-hpp for more information.
- @ref AbstractFeatureGroup "AbstractFeatureGroup<2, Float>"
- @ref AbstractFeatureGroup "AbstractFeatureGroup<3, Float>"
@see @ref scenegraph, AbstractGroupedFeature2D, AbstractGroupedFeature3D,
FeatureGroup, FeatureGroup2D, FeatureGroup3D
*/

1
src/SceneGraph/CMakeLists.txt

@ -61,6 +61,7 @@ set(MagnumSceneGraph_HEADERS
RigidMatrixTransformation2D.h
RigidMatrixTransformation3D.h
FeatureGroup.h
FeatureGroup.hpp
MatrixTransformation2D.h
MatrixTransformation3D.h
Object.h

88
src/SceneGraph/FeatureGroup.h

@ -28,14 +28,36 @@
* @brief Class Magnum::SceneGraph::FeatureGroup, alias Magnum::SceneGraph::FeatureGroup2D, Magnum::SceneGraph::FeatureGroup3D
*/
#include <algorithm>
#include <vector>
#include <Utility/Assert.h>
#include "SceneGraph.h"
#include "SceneGraph/SceneGraph.h"
#include "SceneGraph/magnumSceneGraphVisibility.h"
namespace Magnum { namespace SceneGraph {
/**
@brief Base for group of features
See FeatureGroup.
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
template<UnsignedInt dimensions, class T>
#else
template<UnsignedInt dimensions, class T = Float>
#endif
class MAGNUM_SCENEGRAPH_EXPORT AbstractFeatureGroup {
template<UnsignedInt, class, class> friend class FeatureGroup;
explicit AbstractFeatureGroup();
~AbstractFeatureGroup();
void add(AbstractFeature<dimensions, T>* feature);
void remove(AbstractFeature<dimensions, T>* feature);
std::vector<AbstractFeature<dimensions, T>*> features;
};
/**
@brief Group of features
@ -47,7 +69,7 @@ template<UnsignedInt dimensions, class Feature, class T>
#else
template<UnsignedInt dimensions, class Feature, class T = Float>
#endif
class FeatureGroup {
class FeatureGroup: public AbstractFeatureGroup<dimensions, T> {
friend class AbstractGroupedFeature<dimensions, Feature, T>;
public:
@ -58,24 +80,22 @@ class FeatureGroup {
*
* Removes all features belonging to this group, but not deletes them.
*/
inline virtual ~FeatureGroup() {
for(auto i: features) i->_group = nullptr;
}
virtual ~FeatureGroup();
/** @brief Whether the group is empty */
inline bool isEmpty() const { return features.empty(); }
inline bool isEmpty() const { return this->features.empty(); }
/** @brief Count of features in the group */
inline std::size_t size() const { return features.size(); }
inline std::size_t size() const { return this->features.size(); }
/** @brief Feature at given index */
inline Feature* operator[](std::size_t index) {
return features[index];
return static_cast<Feature*>(this->features[index]);
}
/** @overload */
inline const Feature* operator[](std::size_t index) const {
return features[index];
return static_cast<Feature*>(this->features[index]);
}
/**
@ -85,16 +105,7 @@ class FeatureGroup {
* If the features is part of another group, it is removed from it.
* @see remove(), AbstractGroupedFeature::AbstractGroupedFeature()
*/
FeatureGroup<dimensions, Feature, T>* add(Feature* feature) {
/* Remove from previous group */
if(feature->_group)
feature->_group->remove(feature);
/* Crossreference the feature and group together */
features.push_back(feature);
feature->_group = this;
return this;
}
FeatureGroup<dimensions, Feature, T>* add(Feature* feature);
/**
* @brief Remove feature from the group
@ -103,18 +114,7 @@ class FeatureGroup {
* The feature must be part of the group.
* @see add()
*/
FeatureGroup<dimensions, Feature, T>* remove(Feature* feature) {
CORRADE_ASSERT(feature->_group == this,
"SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", this);
/* Remove the feature and reset group pointer */
features.erase(std::find(features.begin(), features.end(), feature));
feature->_group = nullptr;
return this;
}
private:
std::vector<Feature*> features;
FeatureGroup<dimensions, Feature, T>* remove(Feature* feature);
};
#ifndef CORRADE_GCC46_COMPATIBILITY
@ -151,6 +151,30 @@ template<class Feature, class T>
using FeatureGroup3D = FeatureGroup<3, Feature, T>;
#endif
template<UnsignedInt dimensions, class Feature, class T> FeatureGroup<dimensions, Feature, T>::~FeatureGroup() {
for(auto i: this->features) static_cast<Feature*>(i)->_group = nullptr;
}
template<UnsignedInt dimensions, class Feature, class T> FeatureGroup<dimensions, Feature, T>* FeatureGroup<dimensions, Feature, T>::add(Feature* feature) {
/* Remove from previous group */
if(feature->_group)
feature->_group->remove(feature);
/* Crossreference the feature and group together */
AbstractFeatureGroup<dimensions, T>::add(feature);
feature->_group = this;
return this;
}
template<UnsignedInt dimensions, class Feature, class T> FeatureGroup<dimensions, Feature, T>* FeatureGroup<dimensions, Feature, T>::remove(Feature* feature) {
CORRADE_ASSERT(feature->_group == this,
"SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", this);
AbstractFeatureGroup<dimensions, T>::remove(feature);
feature->_group = nullptr;
return this;
}
}}
#endif

50
src/SceneGraph/FeatureGroup.hpp

@ -0,0 +1,50 @@
#ifndef Magnum_SceneGraph_FeatureGroup_hpp
#define Magnum_SceneGraph_FeatureGroup_hpp
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief @ref compilation-speedup-hpp "Template implementation" for FeatureGroup.h
*/
#include "FeatureGroup.h"
#include <algorithm>
namespace Magnum { namespace SceneGraph {
template<UnsignedInt dimensions, class T> AbstractFeatureGroup<dimensions, T>::AbstractFeatureGroup() = default;
template<UnsignedInt dimensions, class T> AbstractFeatureGroup<dimensions, T>::~AbstractFeatureGroup() = default;
template<UnsignedInt dimensions, class T> void AbstractFeatureGroup<dimensions, T>::add(AbstractFeature<dimensions, T>* feature) {
features.push_back(feature);
}
template<UnsignedInt dimensions, class T> void AbstractFeatureGroup<dimensions, T>::remove(AbstractFeature<dimensions, T>* feature) {
features.erase(std::find(features.begin(), features.end(), feature));
}
}}
#endif

4
src/SceneGraph/Object.cpp

@ -23,6 +23,7 @@
*/
#include "Object.hpp"
#include "FeatureGroup.hpp"
namespace Magnum { namespace SceneGraph {
@ -31,4 +32,7 @@ template class AbstractObject<3>;
template class AbstractTransformation<2>;
template class AbstractTransformation<3>;
template class AbstractFeatureGroup<2>;
template class AbstractFeatureGroup<3>;
}}

6
src/SceneGraph/SceneGraph.h

@ -50,6 +50,12 @@ template<class T = Float> using AbstractFeature2D = AbstractFeature<2, T>;
template<class T = Float> using AbstractFeature3D = AbstractFeature<3, T>;
#endif
template<UnsignedInt dimensions, class T = Float> class AbstractFeatureGroup;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T = Float> using AbstractFeatureGroup2D = AbstractFeatureGroup<2, T>;
template<class T = Float> using AbstractFeatureGroup3D = AbstractFeatureGroup<3, T>;
#endif
template<UnsignedInt dimensions, class Derived, class T = Float> class AbstractGroupedFeature;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class Derived, class T = Float> using AbstractGroupedFeature2D = AbstractGroupedFeature<2, Derived, T>;

Loading…
Cancel
Save