From c1cf94fb46e3716c5e9131273c0f650cad2b566e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Oct 2012 00:38:49 +0200 Subject: [PATCH] Using fixed-size integer types also everywhere else. It solves issues with int/long int/long long int ambiguity, which is good. --- src/Color.h | 4 +- src/Math/Math.h | 7 ++-- src/Math/MathTypeTraits.h | 52 +++++++++++------------- src/Math/RectangularMatrix.h | 2 +- src/Math/Test/ConstantsTest.cpp | 2 - src/Math/Test/MathTest.cpp | 54 ++++++++++++------------- src/Math/Test/MathTypeTraitsTest.cpp | 20 ++++----- src/Math/Test/MatrixTest.cpp | 4 +- src/Math/Test/RectangularMatrixTest.cpp | 14 +++---- src/MeshTools/Test/CleanTest.h | 10 ++--- src/MeshTools/Test/InterleaveTest.cpp | 20 ++++----- src/MeshTools/Test/SubdivideTest.h | 10 ++--- src/MeshTools/Test/TipsifyTest.cpp | 8 ++-- src/Primitives/Capsule.cpp | 30 +++++++------- src/Primitives/Capsule.h | 12 +++--- src/Primitives/Cube.cpp | 2 +- src/Primitives/Cylinder.cpp | 4 +- src/Primitives/Cylinder.h | 2 +- src/Primitives/UVSphere.cpp | 2 +- src/Primitives/UVSphere.h | 2 +- src/Profiler.h | 2 +- src/Swizzle.h | 4 +- src/Test/ColorTest.cpp | 4 +- src/Test/ResourceManagerTest.cpp | 14 +++---- src/Test/ResourceManagerTest.h | 2 +- src/Test/SwizzleTest.cpp | 14 +++---- src/Timeline.cpp | 2 +- src/TypeTraits.cpp | 20 +++++---- src/TypeTraits.h | 12 +++--- 29 files changed, 167 insertions(+), 168 deletions(-) diff --git a/src/Color.h b/src/Color.h index 0dcecdb09..c24866b9d 100644 --- a/src/Color.h +++ b/src/Color.h @@ -160,7 +160,7 @@ template class Color3: public Math::Vector3 { * @brief Create integral color from floating-point color * * E.g. `{0.294118, 0.45098, 0.878431}` is converted to - * `{75, 115, 224}`, if resulting type is `unsigned char`. + * `{75, 115, 224}`, if resulting type is `uint8_t`. * * @note This function is enabled only if source type is floating-point * and destination type is integral. @@ -175,7 +175,7 @@ template class Color3: public Math::Vector3 { * @brief Create floating-point color from integral color * * E.g. `{75, 115, 224}` is converted to - * `{0.294118, 0.45098, 0.878431}`, if source type is `unsigned char`. + * `{0.294118, 0.45098, 0.878431}`, if source type is `uint8_t`. * * @note This function is enabled only if source type is integral * and destination type is floating-point. diff --git a/src/Math/Math.h b/src/Math/Math.h index 07ebea111..a11f3c142 100644 --- a/src/Math/Math.h +++ b/src/Math/Math.h @@ -74,11 +74,11 @@ type to value in range @f$ [0, 1] @f$. literals, this function should be called with both template parameters explicit, e.g.: @code -// Even if this is char literal, integral type is `int`, thus a = 0.1f +// Even if this is character literal, integral type is 32bit, thus a != 1.0f float a = normalize('\127'); // b = 1.0f -float b = normalize('\127'); +float b = normalize('\127'); @endcode @todo Signed normalization to [-1.0, 1.0] like in OpenGL? @@ -95,7 +95,8 @@ Converts floating-point value in range @f$ [0, 1] @f$ to full range of given integral type. @note For best precision, `FloatingPoint` type should be always larger that -resulting `Integral` type (e.g. `double` to `int`, `long double` to `long long`). +resulting `Integral` type (e.g. `double` to `std::int32_t`, `long double` to +`std::int64_t`). @todo Signed normalization to [-1.0, 1.0] like in OpenGL? @todo Stable behavior (working/broken) for long double and long long diff --git a/src/Math/MathTypeTraits.h b/src/Math/MathTypeTraits.h index adf408955..4bf013937 100644 --- a/src/Math/MathTypeTraits.h +++ b/src/Math/MathTypeTraits.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Math::MathTypeTraits */ -#include +#include #include /** @brief Precision when testing floats for equality */ @@ -53,7 +53,7 @@ support given feature, thus forcing the compilation stop with an error. template struct MathTypeTraits { #ifdef DOXYGEN_GENERATING_OUTPUT /** - * @brief Corresponding numeric type large at least as `int` + * @brief Corresponding numeric type large at least as 32bit integer * * Usable e.g. to prevent conversion of `char` to characters when printing * numeric types to output. @@ -114,58 +114,54 @@ template struct MathTypeTraitsFloatingPoint { template struct MathTypeTraitsLong {}; -template<> struct MathTypeTraitsLong { - typedef unsigned int UnsignedType; - typedef int Type; +template<> struct MathTypeTraitsLong<4> { + typedef std::uint32_t UnsignedType; + typedef std::int32_t Type; }; -template<> struct MathTypeTraitsLong { - typedef unsigned long long UnsignedType; - typedef long long Type; +template<> struct MathTypeTraitsLong<8> { + typedef std::uint64_t UnsignedType; + typedef std::int64_t Type; }; } -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int32_t NumericType; typedef float FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint32_t NumericType; typedef double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef int NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int32_t NumericType; typedef double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef unsigned long long NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::uint64_t NumericType; typedef long double FloatingPointType; }; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { - typedef long long NumericType; +template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral { + typedef std::int64_t NumericType; typedef long double FloatingPointType; }; -/* long is 32 bits somewhere and 64 bits elsewhere */ -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral::Type> {}; -template<> struct MathTypeTraits: public Implementation::MathTypeTraitsIntegral::Type> {}; - template<> struct MathTypeTraits: public Implementation::MathTypeTraitsFloatingPoint { typedef float NumericType; typedef float FloatingPointType; diff --git a/src/Math/RectangularMatrix.h b/src/Math/RectangularMatrix.h index d0bea5345..0ca329847 100644 --- a/src/Math/RectangularMatrix.h +++ b/src/Math/RectangularMatrix.h @@ -101,7 +101,7 @@ template class RectangularMatrix { * anything else. Example usage: * @code * RectangularMatrix<4, 1, float> floatingPoint(1.3f, 2.7f, -15.0f, 7.0f); - * RectangularMatrix<4, 1, int> integral(RectangularMatrix<4, 1, int>::from(floatingPoint)); + * RectangularMatrix<4, 1, std::int8_t> integral(RectangularMatrix<4, 1, std::int8_t>::from(floatingPoint)); * // integral == {1, 2, -15, 7} * @endcode */ diff --git a/src/Math/Test/ConstantsTest.cpp b/src/Math/Test/ConstantsTest.cpp index fb24fd8be..4a780de5c 100644 --- a/src/Math/Test/ConstantsTest.cpp +++ b/src/Math/Test/ConstantsTest.cpp @@ -18,8 +18,6 @@ #include "Constants.h" #include "Math.h" -using namespace std; - CORRADE_TEST_MAIN(Magnum::Math::Test::ConstantsTest) namespace Magnum { namespace Math { namespace Test { diff --git a/src/Math/Test/MathTest.cpp b/src/Math/Test/MathTest.cpp index 027f09c35..3aa7348ed 100644 --- a/src/Math/Test/MathTest.cpp +++ b/src/Math/Test/MathTest.cpp @@ -33,46 +33,46 @@ MathTest::MathTest() { void MathTest::normalize() { /* Range for signed and unsigned */ - CORRADE_COMPARE((Math::normalize(-128)), 0.0f); - CORRADE_COMPARE((Math::normalize(127)), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(255)), 1.0f); + CORRADE_COMPARE((Math::normalize(-128)), 0.0f); + CORRADE_COMPARE((Math::normalize(127)), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(255)), 1.0f); /* Between */ - CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); - CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); + CORRADE_COMPARE((Math::normalize(16384)), 0.750011f); + CORRADE_COMPARE((Math::normalize(-16384)), 0.250004f); /* Test overflow for large types */ - CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0f); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); - CORRADE_COMPARE((Math::normalize(0)), 0.0f); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); - - CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); - CORRADE_COMPARE((Math::normalize(0)), 0.0); - CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); + CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0f); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); + CORRADE_COMPARE((Math::normalize(0)), 0.0f); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0f); + + CORRADE_COMPARE((Math::normalize(numeric_limits::min())), 0.0); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); + CORRADE_COMPARE((Math::normalize(0)), 0.0); + CORRADE_COMPARE((Math::normalize(numeric_limits::max())), 1.0); } void MathTest::denormalize() { /* Range for signed and unsigned */ - CORRADE_COMPARE(Math::denormalize(0.0f), -128); - CORRADE_COMPARE(Math::denormalize(1.0f), 127); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(1.0f), 255); + CORRADE_COMPARE(Math::denormalize(0.0f), -128); + CORRADE_COMPARE(Math::denormalize(1.0f), 127); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(1.0f), 255); /* Between */ - CORRADE_COMPARE(Math::denormalize(0.33f), -11141); - CORRADE_COMPARE(Math::denormalize(0.66f), 10485); + CORRADE_COMPARE(Math::denormalize(0.33f), -11141); + CORRADE_COMPARE(Math::denormalize(0.66f), 10485); /* Test overflow for large types */ - CORRADE_COMPARE(Math::denormalize(0.0f), numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0f), 0); - CORRADE_COMPARE(Math::denormalize(0.0), numeric_limits::min()); - CORRADE_COMPARE(Math::denormalize(0.0), 0); + CORRADE_COMPARE(Math::denormalize(0.0f), numeric_limits::min()); + CORRADE_COMPARE(Math::denormalize(0.0f), 0); + CORRADE_COMPARE(Math::denormalize(0.0), numeric_limits::min()); + CORRADE_COMPARE(Math::denormalize(0.0), 0); - CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); - CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); + CORRADE_COMPARE(Math::denormalize(1.0), numeric_limits::max()); // { // CORRADE_EXPECT_FAIL("Denormalize doesn't work for large types well"); diff --git a/src/Math/Test/MathTypeTraitsTest.cpp b/src/Math/Test/MathTypeTraitsTest.cpp index 523b32017..cae312032 100644 --- a/src/Math/Test/MathTypeTraitsTest.cpp +++ b/src/Math/Test/MathTypeTraitsTest.cpp @@ -21,6 +21,8 @@ CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest) +using namespace std; + namespace Magnum { namespace Math { namespace Test { MathTypeTraitsTest::MathTypeTraitsTest() { @@ -29,16 +31,14 @@ MathTypeTraitsTest::MathTypeTraitsTest() { } void MathTypeTraitsTest::equalsIntegral() { - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); - _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); + _equalsIntegral(); } void MathTypeTraitsTest::equalsFloatingPoint() { diff --git a/src/Math/Test/MatrixTest.cpp b/src/Math/Test/MatrixTest.cpp index 2d803ec16..6a015b328 100644 --- a/src/Math/Test/MatrixTest.cpp +++ b/src/Math/Test/MatrixTest.cpp @@ -98,7 +98,7 @@ void MatrixTest::constructZero() { } void MatrixTest::trace() { - Matrix<5, int> m( + Matrix<5, int32_t> m( 1, 2, 3, 0, 0, 2, 3, 2, 1, -2, 1, 1, -20, 1, 0, @@ -127,7 +127,7 @@ void MatrixTest::ij() { } void MatrixTest::determinant() { - Matrix<5, int> m( + Matrix<5, int32_t> m( 1, 2, 2, 1, 0, 2, 3, 2, 1, -2, 1, 1, 1, 1, 0, diff --git a/src/Math/Test/RectangularMatrixTest.cpp b/src/Math/Test/RectangularMatrixTest.cpp index b575941c7..e43c6e5e2 100644 --- a/src/Math/Test/RectangularMatrixTest.cpp +++ b/src/Math/Test/RectangularMatrixTest.cpp @@ -29,7 +29,7 @@ namespace Magnum { namespace Math { namespace Test { typedef RectangularMatrix<4, 3, float> Matrix4x3; typedef RectangularMatrix<3, 4, float> Matrix3x4; typedef RectangularMatrix<2, 2, float> Matrix2; -typedef RectangularMatrix<2, 2, int> Matrix2i; +typedef RectangularMatrix<2, 2, int32_t> Matrix2i; typedef Vector<4, float> Vector4; RectangularMatrixTest::RectangularMatrixTest() { @@ -154,8 +154,8 @@ void RectangularMatrixTest::multiplyDivide() { CORRADE_COMPARE(-1.5f*vec, multiplied); CORRADE_COMPARE(multiplied/-1.5f, vec); - Math::RectangularMatrix<1, 1, char> vecChar(32); - Math::RectangularMatrix<1, 1, char> multipliedChar(-48); + Math::RectangularMatrix<1, 1, int8_t> vecChar(32); + Math::RectangularMatrix<1, 1, int8_t> multipliedChar(-48); CORRADE_COMPARE(vecChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, vecChar); CORRADE_COMPARE(-1.5f*vecChar, multipliedChar); @@ -168,14 +168,14 @@ void RectangularMatrixTest::multiplyDivide() { } void RectangularMatrixTest::multiply() { - RectangularMatrix<4, 6, int> left( + RectangularMatrix<4, 6, int32_t> left( -5, 27, 10, 33, 0, -15, 7, 56, 66, 1, 0, -24, 4, 41, 4, 0, 1, -4, 9, -100, 19, -49, 1, 9 ); - RectangularMatrix<5, 4, int> right( + RectangularMatrix<5, 4, int32_t> right( 1, -7, 0, 158, 2, 24, -3, 40, 3, -15, -2, -50, @@ -183,7 +183,7 @@ void RectangularMatrixTest::multiply() { 5, 30, 4, 18 ); - RectangularMatrix<5, 6, int> expected( + RectangularMatrix<5, 6, int32_t> expected( 1368, -16165, 2550, -7716, 158, 1575, 506, -2725, 2352, -1870, 37, -234, -578, 4159, -1918, 2534, -52, -127, @@ -226,7 +226,7 @@ void RectangularMatrixTest::debug() { " 4, 3, 0)\n"); o.str(""); - Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, char>(); + Debug(&o) << "a" << Matrix3x4() << "b" << RectangularMatrix<4, 3, int8_t>(); CORRADE_COMPARE(o.str(), "a Matrix(0, 0, 0,\n" " 0, 0, 0,\n" " 0, 0, 0,\n" diff --git a/src/MeshTools/Test/CleanTest.h b/src/MeshTools/Test/CleanTest.h index 1500ad601..57169d736 100644 --- a/src/MeshTools/Test/CleanTest.h +++ b/src/MeshTools/Test/CleanTest.h @@ -29,17 +29,17 @@ class CleanTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef int Type; + typedef std::int32_t Type; Vector1(): data(0) {} - Vector1(int i): data(i) {} - int operator[](std::size_t) const { return data; } - int& operator[](std::size_t) { return data; } + Vector1(Type i): data(i) {} + Type operator[](std::size_t) const { return data; } + Type& operator[](std::size_t) { return data; } bool operator==(Vector1 i) const { return i.data == data; } Vector1 operator-(Vector1 i) const { return data-i.data; } private: - int data; + Type data; }; }; diff --git a/src/MeshTools/Test/InterleaveTest.cpp b/src/MeshTools/Test/InterleaveTest.cpp index 9218a995f..b734ea39a 100644 --- a/src/MeshTools/Test/InterleaveTest.cpp +++ b/src/MeshTools/Test/InterleaveTest.cpp @@ -37,18 +37,18 @@ InterleaveTest::InterleaveTest() { void InterleaveTest::attributeCount() { stringstream ss; Error::setOutput(&ss); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, - vector{0, 1, 2, 3, 4, 5})), size_t(0)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, + vector{0, 1, 2, 3, 4, 5})), size_t(0)); CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n"); - CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, - vector{3, 4, 5})), size_t(3)); + CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector{0, 1, 2}, + vector{3, 4, 5})), size_t(3)); } void InterleaveTest::stride() { - CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(1)); - CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(4)); - CORRADE_COMPARE((Implementation::Interleave::stride(vector(), vector())), size_t(5)); + CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(1)); + CORRADE_COMPARE(Implementation::Interleave::stride(vector()), size_t(4)); + CORRADE_COMPARE((Implementation::Interleave::stride(vector(), vector())), size_t(5)); } void InterleaveTest::write() { @@ -56,9 +56,9 @@ void InterleaveTest::write() { size_t stride; char* data; tie(attributeCount, stride, data) = MeshTools::interleave( - vector{0, 1, 2}, - vector{3, 4, 5}, - vector{6, 7, 8}); + vector{0, 1, 2}, + vector{3, 4, 5}, + vector{6, 7, 8}); CORRADE_COMPARE(attributeCount, size_t(3)); CORRADE_COMPARE(stride, size_t(7)); diff --git a/src/MeshTools/Test/SubdivideTest.h b/src/MeshTools/Test/SubdivideTest.h index 1ed5cc4f0..b5ff7f0ef 100644 --- a/src/MeshTools/Test/SubdivideTest.h +++ b/src/MeshTools/Test/SubdivideTest.h @@ -30,17 +30,17 @@ class SubdivideTest: public Corrade::TestSuite::Tester { class Vector1 { public: static const std::size_t Size = 1; - typedef int Type; + typedef std::int32_t Type; Vector1(): data(0) {} - Vector1(int i): data(i) {} - int operator[](std::size_t) const { return data; } - int& operator[](std::size_t) { return data; } + Vector1(Type i): data(i) {} + Type operator[](std::size_t) const { return data; } + Type& operator[](std::size_t) { return data; } bool operator==(Vector1 i) const { return i.data == data; } Vector1 operator-(Vector1 i) const { return data-i.data; } private: - int data; + Type data; }; inline static Vector1 interpolator(Vector1 a, Vector1 b) { return (a[0]+b[0])/2; } diff --git a/src/MeshTools/Test/TipsifyTest.cpp b/src/MeshTools/Test/TipsifyTest.cpp index 67bcd4212..fc0a7c243 100644 --- a/src/MeshTools/Test/TipsifyTest.cpp +++ b/src/MeshTools/Test/TipsifyTest.cpp @@ -67,10 +67,10 @@ TipsifyTest::TipsifyTest(): indices{ } void TipsifyTest::buildAdjacency() { - vector liveTriangleCount, neighborOffset, neighbors; + vector liveTriangleCount, neighborOffset, neighbors; Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); - CORRADE_COMPARE(liveTriangleCount, (vector{ + CORRADE_COMPARE(liveTriangleCount, (vector{ 1, 3, 3, 2, 4, 6, 6, 2, 2, 6, 6, 4, @@ -78,7 +78,7 @@ void TipsifyTest::buildAdjacency() { 1, 1, 1 })); - CORRADE_COMPARE(neighborOffset, (vector{ + CORRADE_COMPARE(neighborOffset, (vector{ 0, 1, 4, 7, 9, 13, 19, 25, 27, 29, 35, 41, @@ -86,7 +86,7 @@ void TipsifyTest::buildAdjacency() { 54, 55, 56, 57 })); - CORRADE_COMPARE(neighbors, (vector{ + CORRADE_COMPARE(neighbors, (vector{ 0, 0, 7, 11, 2, 7, 13, diff --git a/src/Primitives/Capsule.cpp b/src/Primitives/Capsule.cpp index fb89c75f1..ff0a545e2 100644 --- a/src/Primitives/Capsule.cpp +++ b/src/Primitives/Capsule.cpp @@ -22,7 +22,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { +Capsule::Capsule(uint32_t hemisphereRings, uint32_t cylinderRings, uint32_t segments, GLfloat length, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new vector, {new vector()}, {new vector()}, textureCoords == TextureCoords::Generate ? vector*>{new vector()} : vector*>()), segments(segments), textureCoords(textureCoords) { CORRADE_ASSERT(hemisphereRings >= 1 && cylinderRings >= 1 && segments >= 3, "Capsule must have at least one hemisphere ring, one cylinder ring and three segments", ); GLfloat height = 2.0f+length; @@ -50,7 +50,7 @@ Capsule::Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsig topFaceRing(); } -Capsule::Capsule(unsigned int segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} +Capsule::Capsule(uint32_t segments, TextureCoords textureCoords): MeshData3D("", Mesh::Primitive::Triangles, new std::vector, {new std::vector()}, {new std::vector()}, textureCoords == TextureCoords::Generate ? std::vector*>{new std::vector()} : std::vector*>()), segments(segments), textureCoords(textureCoords) {} void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { positions(0)->push_back({0.0f, y, 0.0f}); @@ -60,15 +60,15 @@ void Capsule::capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV) { textureCoords2D(0)->push_back({0.5, textureCoordsV}); } -void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::hemisphereVertexRings(uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; GLfloat x, y, z; - for(unsigned int i = 0; i != count; ++i) { + for(uint32_t i = 0; i != count; ++i) { GLfloat ringAngle = startRingAngle + i*ringAngleIncrement; x = z = cos(ringAngle); y = sin(ringAngle); - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t j = 0; j != segments; ++j) { GLfloat segmentAngle = j*segmentAngleIncrement; positions(0)->push_back({x*sin(segmentAngle), centerY+y, z*cos(segmentAngle)}); normals(0)->push_back({x*sin(segmentAngle), y, z*cos(segmentAngle)}); @@ -86,10 +86,10 @@ void Capsule::hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat } } -void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { +void Capsule::cylinderVertexRings(uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; - for(unsigned int i = 0; i != count; ++i) { - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t i = 0; i != count; ++i) { + for(uint32_t j = 0; j != segments; ++j) { GLfloat segmentAngle = j*segmentAngleIncrement; positions(0)->push_back({sin(segmentAngle), startY, cos(segmentAngle)}); normals(0)->push_back({sin(segmentAngle), 0.0f, cos(segmentAngle)}); @@ -110,7 +110,7 @@ void Capsule::cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yI } void Capsule::bottomFaceRing() { - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t j = 0; j != segments; ++j) { /* Bottom vertex */ indices()->push_back(0); @@ -123,11 +123,11 @@ void Capsule::bottomFaceRing() { } } -void Capsule::faceRings(unsigned int count, unsigned int offset) { - unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); +void Capsule::faceRings(uint32_t count, uint32_t offset) { + uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(unsigned int i = 0; i != count; ++i) { - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t i = 0; i != count; ++i) { + for(uint32_t j = 0; j != segments; ++j) { uint32_t bottomLeft = i*vertexSegments+j+offset; uint32_t bottomRight = ((j != segments-1 || textureCoords == TextureCoords::Generate) ? i*vertexSegments+j+1+offset : i*segments+offset); @@ -145,9 +145,9 @@ void Capsule::faceRings(unsigned int count, unsigned int offset) { } void Capsule::topFaceRing() { - unsigned int vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); + uint32_t vertexSegments = segments + (textureCoords == TextureCoords::Generate ? 1 : 0); - for(unsigned int j = 0; j != segments; ++j) { + for(uint32_t j = 0; j != segments; ++j) { /* Bottom left vertex */ indices()->push_back(normals(0)->size()-vertexSegments+j-1); diff --git a/src/Primitives/Capsule.h b/src/Primitives/Capsule.h index b0b2b291f..76dd89984 100644 --- a/src/Primitives/Capsule.h +++ b/src/Primitives/Capsule.h @@ -53,19 +53,19 @@ class Capsule: public Trade::MeshData3D { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - Capsule(unsigned int hemisphereRings, unsigned int cylinderRings, unsigned int segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); + Capsule(std::uint32_t hemisphereRings, std::uint32_t cylinderRings, std::uint32_t segments, GLfloat length, TextureCoords textureCoords = TextureCoords::DontGenerate); private: - Capsule(unsigned int segments, TextureCoords textureCoords); + Capsule(std::uint32_t segments, TextureCoords textureCoords); void capVertex(GLfloat y, GLfloat normalY, GLfloat textureCoordsV); - void hemisphereVertexRings(unsigned int count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); - void cylinderVertexRings(unsigned int count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void hemisphereVertexRings(std::uint32_t count, GLfloat centerY, GLfloat startRingAngle, GLfloat ringAngleIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); + void cylinderVertexRings(std::uint32_t count, GLfloat startY, GLfloat yIncrement, GLfloat startTextureCoordsV, GLfloat textureCoordsVIncrement); void bottomFaceRing(); - void faceRings(unsigned int count, unsigned int offset = 1); + void faceRings(std::uint32_t count, std::uint32_t offset = 1); void topFaceRing(); - unsigned int segments; + std::uint32_t segments; TextureCoords textureCoords; }; diff --git a/src/Primitives/Cube.cpp b/src/Primitives/Cube.cpp index ed6d47217..739f2e6dd 100644 --- a/src/Primitives/Cube.cpp +++ b/src/Primitives/Cube.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ +Cube::Cube(): MeshData3D("", Mesh::Primitive::Triangles, new vector{ 0, 2, 1, 2, 3, 1, 1, 3, 5, diff --git a/src/Primitives/Cylinder.cpp b/src/Primitives/Cylinder.cpp index 709c7dfb9..ebe23b35c 100644 --- a/src/Primitives/Cylinder.cpp +++ b/src/Primitives/Cylinder.cpp @@ -21,7 +21,7 @@ using namespace std; namespace Magnum { namespace Primitives { -Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { +Cylinder::Cylinder(uint32_t rings, uint32_t segments, GLfloat length, Flags flags): Capsule(segments, flags & Flag::GenerateTextureCoords ? TextureCoords::Generate : TextureCoords::DontGenerate) { CORRADE_ASSERT(rings >= 1 && segments >= 3, "Cylinder must have at least one ring and three segments", ); GLfloat y = length*0.5f; @@ -51,7 +51,7 @@ Cylinder::Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Fl void Cylinder::capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal) { GLfloat segmentAngleIncrement = 2*Math::Constants::pi()/segments; - for(unsigned int i = 0; i != segments; ++i) { + for(uint32_t i = 0; i != segments; ++i) { GLfloat segmentAngle = i*segmentAngleIncrement; positions(0)->push_back({sin(segmentAngle), y, cos(segmentAngle)}); normals(0)->push_back(normal); diff --git a/src/Primitives/Cylinder.h b/src/Primitives/Cylinder.h index c2dcf5877..29da7a73b 100644 --- a/src/Primitives/Cylinder.h +++ b/src/Primitives/Cylinder.h @@ -58,7 +58,7 @@ class Cylinder: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - Cylinder(unsigned int rings, unsigned int segments, GLfloat length, Flags flags = Flags()); + Cylinder(std::uint32_t rings, std::uint32_t segments, GLfloat length, Flags flags = Flags()); private: void capVertexRing(GLfloat y, GLfloat textureCoordsV, const Vector3& normal); diff --git a/src/Primitives/UVSphere.cpp b/src/Primitives/UVSphere.cpp index 7a881cd43..e82814264 100644 --- a/src/Primitives/UVSphere.cpp +++ b/src/Primitives/UVSphere.cpp @@ -23,7 +23,7 @@ using namespace std; namespace Magnum { namespace Primitives { -UVSphere::UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords): Capsule(segments, textureCoords) { +UVSphere::UVSphere(uint32_t rings, uint32_t segments, TextureCoords textureCoords): Capsule(segments, textureCoords) { CORRADE_ASSERT(rings >= 2 && segments >= 3, "UVSphere must have at least two rings and three segments", ); GLfloat textureCoordsVIncrement = 1.0f/rings; diff --git a/src/Primitives/UVSphere.h b/src/Primitives/UVSphere.h index d61c60a3c..8d2f01054 100644 --- a/src/Primitives/UVSphere.h +++ b/src/Primitives/UVSphere.h @@ -39,7 +39,7 @@ class UVSphere: public Capsule { * If texture coordinates are generated, vertices of one segment are * duplicated for texture wrapping. */ - UVSphere(unsigned int rings, unsigned int segments, TextureCoords textureCoords = TextureCoords::DontGenerate); + UVSphere(std::uint32_t rings, std::uint32_t segments, TextureCoords textureCoords = TextureCoords::DontGenerate); }; }} diff --git a/src/Profiler.h b/src/Profiler.h index 1d52f14ed..3be943bd6 100644 --- a/src/Profiler.h +++ b/src/Profiler.h @@ -95,7 +95,7 @@ class MAGNUM_EXPORT Profiler { * * @see otherSection, addSection(), start(Section) */ - typedef unsigned int Section; + typedef std::uint32_t Section; /** * @brief Default section diff --git a/src/Swizzle.h b/src/Swizzle.h index 49b0870b8..529d538ec 100644 --- a/src/Swizzle.h +++ b/src/Swizzle.h @@ -90,7 +90,7 @@ namespace Implementation { Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); auto vec = swizzle<'a', '1', '0', 'r', 'g', 'b'>(original); // vec == { 4, 1, 0, -1, 2, 3 } @@ -118,7 +118,7 @@ template inline constexpr typename Implementation:: Creates new vector from given components. Example: @code -Vector4 original(-1, 2, 3, 4); +Vector4 original(-1, 2, 3, 4); auto vec = swizzle(original, "a10rgb"); // vec == { 4, 1, 0, -1, 2, 3 } diff --git a/src/Test/ColorTest.cpp b/src/Test/ColorTest.cpp index 7813b5f06..7625131af 100644 --- a/src/Test/ColorTest.cpp +++ b/src/Test/ColorTest.cpp @@ -25,8 +25,8 @@ using namespace Corrade::Utility; namespace Magnum { namespace Test { -typedef Magnum::Color3 Color3; -typedef Magnum::Color4 Color4; +typedef Magnum::Color3 Color3; +typedef Magnum::Color4 Color4; typedef Magnum::Color3 Color3f; typedef Magnum::Color4 Color4f; diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 872dfefa1..bf99d364f 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -39,29 +39,29 @@ ResourceManagerTest::ResourceManagerTest() { void ResourceManagerTest::state() { ResourceKey questionKey("the-question"); - rm->set(questionKey, new int(10), ResourceDataState::Mutable, ResourcePolicy::Resident); - Resource theQuestion = rm->get(questionKey); + rm->set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); + Resource theQuestion = rm->get(questionKey); CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable); CORRADE_COMPARE(*theQuestion, 10); /* Check that hash function is working properly */ ResourceKey answerKey("the-answer"); - rm->set(answerKey, new int(42), ResourceDataState::Final, ResourcePolicy::Resident); - Resource theAnswer = rm->get(answerKey); + rm->set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); + Resource theAnswer = rm->get(answerKey); CORRADE_VERIFY(theAnswer.state() == ResourceState::Final); CORRADE_COMPARE(*theAnswer, 42); - CORRADE_COMPARE(rm->count(), 2); + CORRADE_COMPARE(rm->count(), 2); /* Cannot change already final resource */ stringstream out; Error::setOutput(&out); - rm->set(answerKey, new int(43), ResourceDataState::Mutable, ResourcePolicy::Resident); + rm->set(answerKey, new int32_t(43), ResourceDataState::Mutable, ResourcePolicy::Resident); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(out.str(), "ResourceManager: cannot change already final resource\n"); /* Check non-final resource changes */ - rm->set(questionKey, new int(20), ResourceDataState::Final, ResourcePolicy::Resident); + rm->set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); CORRADE_VERIFY(theQuestion.state() == ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } diff --git a/src/Test/ResourceManagerTest.h b/src/Test/ResourceManagerTest.h index 5d3364eb9..ef7c1826a 100644 --- a/src/Test/ResourceManagerTest.h +++ b/src/Test/ResourceManagerTest.h @@ -31,7 +31,7 @@ class Data { inline ~Data() { --count; } }; -typedef Magnum::ResourceManager ResourceManager; +typedef Magnum::ResourceManager ResourceManager; class ResourceManagerTest: public Corrade::TestSuite::Tester { public: diff --git a/src/Test/SwizzleTest.cpp b/src/Test/SwizzleTest.cpp index 4f57462a8..fa36a4576 100644 --- a/src/Test/SwizzleTest.cpp +++ b/src/Test/SwizzleTest.cpp @@ -23,9 +23,9 @@ CORRADE_TEST_MAIN(Magnum::Test::SwizzleTest) namespace Magnum { namespace Test { -typedef Math::Vector2 Vector2; -typedef Math::Vector3 Vector3; -typedef Math::Vector4 Vector4; +typedef Math::Vector2 Vector2; +typedef Math::Vector3 Vector3; +typedef Math::Vector4 Vector4; SwizzleTest::SwizzleTest() { addTests(&SwizzleTest::xyzw, @@ -88,10 +88,10 @@ void SwizzleTest::type() { void SwizzleTest::defaultType() { Vector4 orig(1, 2, 3, 4); - CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int>(3))); - CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int>(3))); - CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1))); - CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle<'b'>(orig), (Math::Vector<1, int32_t>(3))); + CORRADE_COMPARE(swizzle(orig, "b"), (Math::Vector<1, int32_t>(3))); + CORRADE_COMPARE((swizzle<'b', 'r', 'a', 'g', 'z', 'y', 'x'>(orig)), (Math::Vector<7, int32_t>(3, 1, 4, 2, 3, 2, 1))); + CORRADE_COMPARE(swizzle(orig, "bragzyx"), (Math::Vector<7, int32_t>(3, 1, 4, 2, 3, 2, 1))); } }} diff --git a/src/Timeline.cpp b/src/Timeline.cpp index ccc8fbebe..7183c899d 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -37,7 +37,7 @@ void Timeline::nextFrame() { if(!running) return; auto now = high_resolution_clock::now(); - unsigned int duration = duration_cast(now-previousFrameTime).count(); + std::uint32_t duration = duration_cast(now-previousFrameTime).count(); _previousFrameDuration = duration/1e6f; if(_previousFrameDuration < _minimalFrameTime) { diff --git a/src/TypeTraits.cpp b/src/TypeTraits.cpp index f9936e742..4dad71afe 100644 --- a/src/TypeTraits.cpp +++ b/src/TypeTraits.cpp @@ -15,18 +15,22 @@ #include "TypeTraits.h" +#include + +using namespace std; + namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(sizeof(GLubyte) == sizeof(unsigned char), "GLubyte is not the same as unsigned char"); -static_assert(sizeof(GLbyte) == sizeof(char), "GLbyte is not the same as char"); -static_assert(sizeof(GLushort) == sizeof(unsigned short), "GLushort is not the same as unsigned short"); -static_assert(sizeof(GLshort) == sizeof(short), "GLshort is not the same as short"); -static_assert(sizeof(GLuint) == sizeof(unsigned int), "GLuint is not the same as unsigned int"); -static_assert(sizeof(GLint) == sizeof(int), "GLint is not the same as int"); -static_assert(sizeof(GLfloat) == sizeof(float), "GLfloat is not the same as float"); +static_assert(is_same::value, "GLubyte is not the same as uint8_t"); +static_assert(is_same::value, "GLbyte is not the same as int8_t"); +static_assert(is_same::value, "GLushort is not the same as uint16_t"); +static_assert(is_same::value, "GLshort is not the same as int16_t"); +static_assert(is_same::value, "GLuint is not the same as uint32_t"); +static_assert(is_same::value, "GLint is not the same as int32_t"); +static_assert(is_same::value, "GLfloat is not the same as float"); #ifndef MAGNUM_TARGET_GLES -static_assert(sizeof(GLdouble) == sizeof(double), "GLdouble is not the same as double"); +static_assert(is_same::value, "GLdouble is not the same as double"); #endif #endif diff --git a/src/TypeTraits.h b/src/TypeTraits.h index 2f01b0167..37dae7f43 100644 --- a/src/TypeTraits.h +++ b/src/TypeTraits.h @@ -165,7 +165,7 @@ template<> struct TypeOf { typedef GLfloat Type; }; template<> struct TypeOf { typedef GLdouble Type; }; #endif -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedByte; } inline constexpr static Type indexType() { return Type::UnsignedByte; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedByte; } @@ -173,7 +173,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Byte; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Byte; } @@ -181,7 +181,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedShort; } inline constexpr static Type indexType() { return Type::UnsignedShort; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedShort; } @@ -189,7 +189,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Short; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Short; } @@ -197,7 +197,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::UnsignedInt; } inline constexpr static Type indexType() { return Type::UnsignedInt; } inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::UnsignedInt; } @@ -205,7 +205,7 @@ template<> struct TypeTraits: public Math::MathTypeTraits inline constexpr static std::size_t count() { return 1; } }; -template<> struct TypeTraits: public Math::MathTypeTraits { +template<> struct TypeTraits: public Math::MathTypeTraits { inline constexpr static Type type() { return Type::Int; } /* Can not be used for indices */ inline constexpr static AbstractImage::ComponentType imageType() { return AbstractImage::ComponentType::Int; }