From 1077370937f159007cf997ff64ddb0e6c13e9bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Oct 2012 16:27:09 +0200 Subject: [PATCH] Using fixed-size 8bit integer for dimension count. There can be only one, two or three dimensions, so why to use eight times larger type than needed? --- src/AbstractTexture.h | 4 +++- src/BufferedImage.cpp | 2 +- src/BufferedImage.h | 4 ++-- src/Framebuffer.h | 4 ++-- src/Image.cpp | 2 +- src/Image.h | 4 ++-- src/ImageWrapper.h | 4 ++-- src/Physics/AbstractShape.cpp | 2 +- src/Physics/AbstractShape.h | 6 +++--- src/Physics/AxisAlignedBox.cpp | 2 +- src/Physics/AxisAlignedBox.h | 2 +- src/Physics/Box.cpp | 2 +- src/Physics/Box.h | 2 +- src/Physics/Capsule.cpp | 8 ++++---- src/Physics/Capsule.h | 10 +++++----- src/Physics/Line.cpp | 2 +- src/Physics/Line.h | 2 +- src/Physics/LineSegment.h | 2 +- src/Physics/Plane.h | 4 ++-- src/Physics/Point.cpp | 2 +- src/Physics/Point.h | 2 +- src/Physics/ShapeGroup.cpp | 10 +++++----- src/Physics/ShapeGroup.h | 6 +++--- src/Physics/ShapedObject.cpp | 8 ++++---- src/Physics/ShapedObject.h | 6 +++--- src/Physics/ShapedObjectGroup.cpp | 2 +- src/Physics/ShapedObjectGroup.h | 5 +++-- src/Physics/Sphere.cpp | 14 +++++++------- src/Physics/Sphere.h | 14 +++++++------- src/SceneGraph/Camera.cpp | 12 ++++++------ src/SceneGraph/Camera.h | 8 ++++---- src/SceneGraph/Object.cpp | 12 ++++++------ src/SceneGraph/Object.h | 14 +++++++------- src/SceneGraph/Scene.h | 2 +- src/Texture.h | 4 ++-- src/Trade/ImageData.h | 4 ++-- 36 files changed, 98 insertions(+), 95 deletions(-) diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index a4c10e9a4..549588ea3 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -19,6 +19,8 @@ * @brief Class Magnum::AbstractTexture */ +#include + #include "Magnum.h" #include "Color.h" @@ -660,7 +662,7 @@ class MAGNUM_EXPORT AbstractTexture { protected: #ifndef DOXYGEN_GENERATING_OUTPUT - template struct DataHelper {}; + template struct DataHelper {}; #endif const GLenum _target; /**< @brief Target */ diff --git a/src/BufferedImage.cpp b/src/BufferedImage.cpp index 43c43227b..7a8b80936 100644 --- a/src/BufferedImage.cpp +++ b/src/BufferedImage.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { +template void BufferedImage::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { _components = components; _type = type; _size = size; diff --git a/src/BufferedImage.h b/src/BufferedImage.h index 99062b105..4ec955e47 100644 --- a/src/BufferedImage.h +++ b/src/BufferedImage.h @@ -36,9 +36,9 @@ Trade::ImageData. @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @requires_gles30 (no extension providing this functionality) */ -template class BufferedImage: public AbstractImage { +template class BufferedImage: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 1c69674d9..873562572 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -29,8 +29,8 @@ namespace Magnum { -template class BufferedImage; -template class Image; +template class BufferedImage; +template class Image; typedef BufferedImage<1> BufferedImage1D; typedef BufferedImage<2> BufferedImage2D; diff --git a/src/Image.cpp b/src/Image.cpp index a5fa6c4d1..637001733 100644 --- a/src/Image.cpp +++ b/src/Image.cpp @@ -17,7 +17,7 @@ namespace Magnum { -template void Image::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data) { +template void Image::setData(const typename DimensionTraits::VectorType& size, Components components, ComponentType type, GLvoid* data) { delete[] _data; _components = components; _type = type; diff --git a/src/Image.h b/src/Image.h index 83a1187a2..ec7ad719b 100644 --- a/src/Image.h +++ b/src/Image.h @@ -34,9 +34,9 @@ ImageWrapper, BufferedImage, which stores image data in GPU memory, or for example with Trade::ImageData. @see Image1D, Image2D, Image3D */ -template class Image: public AbstractImage { +template class Image: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor diff --git a/src/ImageWrapper.h b/src/ImageWrapper.h index 6699d680e..8b45d9c43 100644 --- a/src/ImageWrapper.h +++ b/src/ImageWrapper.h @@ -40,9 +40,9 @@ to change image properties, only data pointer. See also Image, BufferedImage and Trade::ImageData. */ -template class ImageWrapper: public AbstractImage { +template class ImageWrapper: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index cb920047e..23a15ec0d 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -17,7 +17,7 @@ namespace Magnum { namespace Physics { -template bool AbstractShape::collides(const AbstractShape* other) const { +template bool AbstractShape::collides(const AbstractShape* other) const { /* Operate only with simpler types than this */ if(static_cast(other->type()) > static_cast(type())) return other->collides(this); diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 62b60acfc..479482ad4 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct ShapeDimensionTraits {}; + template struct ShapeDimensionTraits {}; template<> struct ShapeDimensionTraits<2> { enum class Type { @@ -65,10 +65,10 @@ namespace Implementation { See @ref collision-detection for brief introduction. @see AbstractShape2D, AbstractShape3D */ -template class PHYSICS_EXPORT AbstractShape { +template class PHYSICS_EXPORT AbstractShape { public: /** @brief Dimension count */ - static const size_t Dimensions = dimensions; + static const std::uint8_t Dimensions = dimensions; /** * @brief Shape type diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 64b832394..63b288fcc 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void AxisAlignedBox::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); _transformedSize = transformation.rotationScaling()*_size; } diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index f6b9e87c7..2f67eb456 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Physics { @see AxisAlignedBox2D, AxisAlignedBox3D */ -template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { +template class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ inline AxisAlignedBox(const typename DimensionTraits::VectorType& position, const typename DimensionTraits::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 8b63ad5dd..2b0eb5725 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Box::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedTransformation = (transformation*_transformation); } diff --git a/src/Physics/Box.h b/src/Physics/Box.h index f52b265d1..25eed9345 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Physics { @see Box2D, Box3D */ -template class PHYSICS_EXPORT Box: public AbstractShape { +template class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index f05b19858..0c9c1b288 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -27,14 +27,14 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Capsule::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); float scaling = (transformation.rotationScaling()*typename DimensionTraits::VectorType(1/Math::Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } -template bool Capsule::collides(const AbstractShape* other) const { +template bool Capsule::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Sphere) @@ -43,12 +43,12 @@ template bool Capsule::collides(const AbstractSha return AbstractShape::collides(other); } -template bool Capsule::operator%(const Point& other) const { +template bool Capsule::operator%(const Point& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Capsule::operator%(const Sphere& other) const { +template bool Capsule::operator%(const Sphere& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 93b950527..9ee660ef0 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -24,8 +24,8 @@ namespace Magnum { namespace Physics { -template class Point; -template class Sphere; +template class Point; +template class Sphere; /** @brief %Capsule defined by cylinder start and end point and radius @@ -34,7 +34,7 @@ Unlike other elements the capsule doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Capsule2D, Capsule3D */ -template class PHYSICS_EXPORT Capsule: public AbstractShape { +template class PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ inline Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} @@ -113,10 +113,10 @@ typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; /** @collisionoperator{Point,Capsule} */ -template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } /** @collisionoperator{Sphere,Capsule} */ -template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } }} diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index bfe5362ed..c067306c0 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Line::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedA = (transformation*typename DimensionTraits::PointType(_a)).vector(); _transformedB = (transformation*typename DimensionTraits::PointType(_b)).vector(); } diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 90332cf9a..880bc2ea6 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -30,7 +30,7 @@ namespace Magnum { namespace Physics { @see Line2D, Line3D @todo collision detection of two Line2D */ -template class PHYSICS_EXPORT Line: public AbstractShape { +template class PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ inline Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index 407fdc382..2a5f1739c 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { @see LineSegment2D, LineSegment3D */ -template class LineSegment: public Line { +template class LineSegment: public Line { public: /** @brief Constructor */ inline LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} diff --git a/src/Physics/Plane.h b/src/Physics/Plane.h index 8c547dc8e..6afea764b 100644 --- a/src/Physics/Plane.h +++ b/src/Physics/Plane.h @@ -24,9 +24,9 @@ namespace Magnum { namespace Physics { -template class Line; +template class Line; typedef Line<3> Line3D; -template class LineSegment; +template class LineSegment; typedef LineSegment<3> LineSegment3D; /** @brief Infinite plane, defined by position and normal (3D only) */ diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index f2a15267f..6ca6df6f4 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Point::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); } diff --git a/src/Physics/Point.h b/src/Physics/Point.h index f390c4f02..60557b6b8 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -29,7 +29,7 @@ namespace Magnum { namespace Physics { @see Point2D, Point3D */ -template class PHYSICS_EXPORT Point: public AbstractShape { +template class PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ inline Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index be94a88f2..83a5f7178 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -17,18 +17,18 @@ namespace Magnum { namespace Physics { -template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { +template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { other.operation = Implementation::GroupOperation::AlwaysFalse; other.a = nullptr; other.b = nullptr; } -template ShapeGroup::~ShapeGroup() { +template ShapeGroup::~ShapeGroup() { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; } -template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { +template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; @@ -43,12 +43,12 @@ template ShapeGroup& ShapeGroup::oper return *this; } -template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void ShapeGroup::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { if(a) a->applyTransformation(transformation); if(b) b->applyTransformation(transformation); } -template bool ShapeGroup::collides(const AbstractShape* other) const { +template bool ShapeGroup::collides(const AbstractShape* other) const { switch(operation & ~Implementation::GroupOperation::RefAB) { case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other); case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other); diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index 83d19b920..1f5900148 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -55,7 +55,7 @@ Result of logical operations on shapes. See @ref collision-detection for brief introduction. @see ShapeGroup2D, ShapeGroup3D */ -template class PHYSICS_EXPORT ShapeGroup: public AbstractShape { +template class PHYSICS_EXPORT ShapeGroup: public AbstractShape { #ifndef DOXYGEN_GENERATING_OUTPUT // template friend constexpr operator~(const T& a) -> enableIfIsBaseType; // template friend constexpr operator~(T&& a) -> enableIfIsBaseType; @@ -173,7 +173,7 @@ is used here, so this operation can be used for providing simplified shape version, because collision with @p b is computed only if @p a collides. See @ref collision-detection-shape-simplification for an example. */ -template inline constexpr ShapeGroup operator&&(T a, U b); +template inline constexpr ShapeGroup operator&&(T a, U b); /** @relates ShapeGroup @brief Logical OR of two shapes @@ -182,7 +182,7 @@ template inline constexpr ShapeGroup inline constexpr ShapeGroup operator||(T a, U b); +template inline constexpr ShapeGroup operator||(T a, U b); #else #define op(type, char) \ template inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \ diff --git a/src/Physics/ShapedObject.cpp b/src/Physics/ShapedObject.cpp index dd34a52a9..aee0750a2 100644 --- a/src/Physics/ShapedObject.cpp +++ b/src/Physics/ShapedObject.cpp @@ -27,22 +27,22 @@ using namespace std; namespace Magnum { namespace Physics { -template ShapedObject::ShapedObject(ShapedObjectGroup* group, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), group(group), _shape(nullptr) { +template ShapedObject::ShapedObject(ShapedObjectGroup* group, typename SceneGraph::AbstractObject::ObjectType* parent): SceneGraph::AbstractObject::ObjectType(parent), group(group), _shape(nullptr) { group->objects.push_back(this); } -template ShapedObject::~ShapedObject() { +template ShapedObject::~ShapedObject() { group->objects.erase(find(group->objects.begin(), group->objects.end(), this)); delete _shape; } -template void ShapedObject::setDirty() { +template void ShapedObject::setDirty() { SceneGraph::AbstractObject::ObjectType::setDirty(); group->setDirty(); } -template void ShapedObject::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { +template void ShapedObject::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { SceneGraph::AbstractObject::ObjectType::clean(absoluteTransformation); if(_shape) _shape->applyTransformation(absoluteTransformation); diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h index 2c04c962a..fceee5c3b 100644 --- a/src/Physics/ShapedObject.h +++ b/src/Physics/ShapedObject.h @@ -25,15 +25,15 @@ namespace Magnum { namespace Physics { -template class ShapedObjectGroup; -template class AbstractShape; +template class ShapedObjectGroup; +template class AbstractShape; /** @brief Object with assigned shape @see ShapedObject2D, ShapedObject3D */ -template class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject::ObjectType { +template class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject::ObjectType { public: /** * @brief Constructor diff --git a/src/Physics/ShapedObjectGroup.cpp b/src/Physics/ShapedObjectGroup.cpp index 89a901449..ae02018f5 100644 --- a/src/Physics/ShapedObjectGroup.cpp +++ b/src/Physics/ShapedObjectGroup.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { -template void ShapedObjectGroup::setClean() { +template void ShapedObjectGroup::setClean() { for(ShapedObject* object: objects) if(object->isDirty()) object->setClean(); diff --git a/src/Physics/ShapedObjectGroup.h b/src/Physics/ShapedObjectGroup.h index 74d38c816..874cb53e5 100644 --- a/src/Physics/ShapedObjectGroup.h +++ b/src/Physics/ShapedObjectGroup.h @@ -20,6 +20,7 @@ */ #include +#include #include #include "magnumPhysicsVisibility.h" @@ -31,7 +32,7 @@ template class Resource; namespace Physics { -template class ShapedObject; +template class ShapedObject; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { @@ -51,7 +52,7 @@ specifying it in the constructor. When the group is deleted, all objects belogning to it are deleted too. @see ShapedObjectGroup2D, ShapedObjectGroup3D */ -template class PHYSICS_EXPORT ShapedObjectGroup { +template class PHYSICS_EXPORT ShapedObjectGroup { friend class ShapedObject; public: diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index af9a668a2..b0f578871 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -28,7 +28,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { namespace { - template static typename DimensionTraits::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Math::Constants::sqrt2()); @@ -39,13 +39,13 @@ namespace { } } -template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { +template void Sphere::applyTransformation(const typename DimensionTraits::MatrixType& transformation) { _transformedPosition = (transformation*typename DimensionTraits::PointType(_position)).vector(); float scaling = (transformation.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } -template bool Sphere::collides(const AbstractShape* other) const { +template bool Sphere::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Line) @@ -58,22 +58,22 @@ template bool Sphere::collides(const AbstractShap return AbstractShape::collides(other); } -template bool Sphere::operator%(const Point& other) const { +template bool Sphere::operator%(const Point& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Line& other) const { +template bool Sphere::operator%(const Line& other) const { return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const LineSegment& other) const { +template bool Sphere::operator%(const LineSegment& other) const { return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Sphere& other) const { +template bool Sphere::operator%(const Sphere& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index dda4e5161..9c92db521 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -24,9 +24,9 @@ namespace Magnum { namespace Physics { -template class Line; -template class LineSegment; -template class Point; +template class Line; +template class LineSegment; +template class Point; /** @brief %Sphere defined by position and radius @@ -35,7 +35,7 @@ Unlike other elements the sphere doesn't support asymmetric scaling. When applying transformation, the scale factor is averaged from all axes. @see Sphere2D, Sphere3D */ -template class PHYSICS_EXPORT Sphere: public AbstractShape { +template class PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ inline Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} @@ -105,13 +105,13 @@ typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; /** @collisionoperator{Point,Sphere} */ -template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } /** @collisionoperator{Line,Sphere} */ -template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } /** @collisionoperator{LineSegment,Sphere} */ -template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } +template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } }} diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 81c39d354..d51a9ff7b 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -45,26 +45,26 @@ template Matrix4 aspectRatioFix(AspectRatioPolicy, const Vector2&, cons } #endif -template AbstractCamera::AbstractCamera(typename AbstractObject::ObjectType* parent): AbstractObject::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} +template AbstractCamera::AbstractCamera(typename AbstractObject::ObjectType* parent): AbstractObject::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} -template typename AbstractObject::CameraType* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { +template typename AbstractObject::CameraType* AbstractCamera::setAspectRatioPolicy(AspectRatioPolicy policy) { _aspectRatioPolicy = policy; fixAspectRatio(); return static_cast::CameraType*>(this); } -template void AbstractCamera::setViewport(const Math::Vector2& size) { +template void AbstractCamera::setViewport(const Math::Vector2& size) { _viewport = size; fixAspectRatio(); } -template void AbstractCamera::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { +template void AbstractCamera::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { AbstractObject::ObjectType::clean(absoluteTransformation); _cameraMatrix = absoluteTransformation.inverted(); } -template void AbstractCamera::draw() { +template void AbstractCamera::draw() { typename AbstractObject::SceneType* s = this->scene(); CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", ); @@ -72,7 +72,7 @@ template void AbstractCamera::draw() { drawChildren(s, cameraMatrix()); } -template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix) { +template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix) { for(typename AbstractObject::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { /* Transformation matrix for the object */ typename DimensionTraits::MatrixType matrix = transformationMatrix*i->transformation(); diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 3e473c4a7..6f8c68bbb 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -36,8 +36,6 @@ namespace Implementation { NotPreserved, Extend, Clip }; - template class Camera {}; - template MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Vector2& projectionScale, const Math::Vector2& viewport); /* These templates are instantiated in source file */ @@ -49,7 +47,7 @@ namespace Implementation { /** @brief %Camera object */ -template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject::ObjectType { +template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject::ObjectType { public: /** * @brief Aspect ratio policy @@ -160,7 +158,7 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr Math::Vector2 _viewport; }; -template inline AbstractCamera::~AbstractCamera() {} +template inline AbstractCamera::~AbstractCamera() {} #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ @@ -168,6 +166,8 @@ extern template class SCENEGRAPH_EXPORT AbstractCamera<2>; extern template class SCENEGRAPH_EXPORT AbstractCamera<3>; namespace Implementation { + template class Camera {}; + template<> class Camera<2> { public: inline constexpr static Matrix3 aspectRatioScale(const Vector2& scale) { diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index b723a55a5..3cf9b2316 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -25,7 +25,7 @@ using namespace Magnum::Math; namespace Magnum { namespace SceneGraph { -template typename AbstractObject::ObjectType* AbstractObject::setParent(ObjectType* parent) { +template typename AbstractObject::ObjectType* AbstractObject::setParent(ObjectType* parent) { /* Skip if nothing to do or this is scene */ if(this->parent() == parent || isScene()) return static_cast(this); @@ -49,7 +49,7 @@ template typename AbstractObject::ObjectType* Abs return static_cast(this); } -template typename DimensionTraits::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { +template typename DimensionTraits::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { /* Shortcut for absolute transformation of camera relative to itself */ if(camera == this) return typename DimensionTraits::MatrixType(); @@ -77,7 +77,7 @@ template typename DimensionTraits::Matri return t; } -template typename AbstractObject::SceneType* AbstractObject::scene() { +template typename AbstractObject::SceneType* AbstractObject::scene() { /* Goes up the family tree until it finds object which is parent of itself (that's the scene) */ ObjectType* p = parent(); @@ -89,7 +89,7 @@ template typename AbstractObject::SceneType* Abst return nullptr; } -template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const typename DimensionTraits::MatrixType& transformation) { +template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const typename DimensionTraits::MatrixType& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ if(isScene()) return static_cast(this); @@ -99,7 +99,7 @@ template typename AbstractObject::ObjectType* Abs return static_cast(this); } -template void AbstractObject::setDirty() { +template void AbstractObject::setDirty() { /* The object (and all its children) are already dirty, nothing to do */ if(dirty) return; @@ -110,7 +110,7 @@ template void AbstractObject::setDirty() { i->setDirty(); } -template void AbstractObject::setClean() { +template void AbstractObject::setClean() { /* The object (and all its parents) are already clean, nothing to do */ if(!dirty) return; diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 3b2e5dca0..cd1d929fe 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -34,13 +34,13 @@ class Camera2D; class Camera3D; class Object2D; class Object3D; -template class Scene; +template class Scene; typedef Scene<2> Scene2D; typedef Scene<3> Scene3D; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct ObjectDimensionTraits {}; + template struct ObjectDimensionTraits {}; template<> struct ObjectDimensionTraits<2> { typedef Object2D ObjectType; @@ -72,7 +72,7 @@ namespace Implementation { @todo Transform transformation when changing parent, so the object stays in place. */ -template class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { +template class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList::ObjectType>, public Corrade::Containers::LinkedListItem::ObjectType, typename Implementation::ObjectDimensionTraits::ObjectType> { #ifndef DOXYGEN_GENERATING_OUTPUT AbstractObject(const AbstractObject& other) = delete; AbstractObject(AbstractObject&& other) = delete; @@ -81,7 +81,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra #endif public: - static const size_t Dimensions = dimensions; /**< @brief %Object dimension count */ + static const std::uint8_t Dimensions = dimensions; /**< @brief %Object dimension count */ /** @brief %Object type for given dimension count */ typedef typename Implementation::ObjectDimensionTraits::ObjectType ObjectType; @@ -306,11 +306,11 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra bool dirty; }; -template inline AbstractObject::~AbstractObject() {} +template inline AbstractObject::~AbstractObject() {} /* Implementations for inline functions with unused parameters */ -template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} -template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } +template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} +template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 90d0e2ca7..42417426c 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -28,7 +28,7 @@ namespace Magnum { namespace SceneGraph { @see Scene2D, Scene3D */ -template class SCENEGRAPH_EXPORT Scene: public AbstractObject::ObjectType { +template class SCENEGRAPH_EXPORT Scene: public AbstractObject::ObjectType { public: /** @copydoc AbstractObject::isScene() */ inline bool isScene() const { return true; } diff --git a/src/Texture.h b/src/Texture.h index 49bcf536c..ba57c8d23 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -50,9 +50,9 @@ for more information. @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @todo @extension{AMD,sparse_texture} */ -template class Texture: public AbstractTexture { +template class Texture: public AbstractTexture { public: - static const size_t Dimensions = dimensions; /**< @brief %Texture dimension count */ + static const std::uint8_t Dimensions = dimensions; /**< @brief %Texture dimension count */ #ifdef DOXYGEN_GENERATING_OUTPUT /** diff --git a/src/Trade/ImageData.h b/src/Trade/ImageData.h index bde311640..a0383d806 100644 --- a/src/Trade/ImageData.h +++ b/src/Trade/ImageData.h @@ -32,9 +32,9 @@ namespace Magnum { namespace Trade { Provides access to image data and additional information about data type and dimensions. Can be used in the same situations as Image and BufferedImage. */ -template class ImageData: public AbstractImage { +template class ImageData: public AbstractImage { public: - const static size_t Dimensions = dimensions; /**< @brief %Image dimension count */ + const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */ /** * @brief Constructor