From a20d73aafa602c9c9ecda94cc51367fd3107d425 Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Sun, 19 Dec 2021 14:00:20 +0100 Subject: [PATCH] Make 'Vertex' a 'constexpr' class --- include/SFML/Graphics/Vertex.hpp | 15 ++++++++------- .../SFML/Graphics/Vertex.inl | 19 +++++-------------- src/SFML/Graphics/CMakeLists.txt | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) rename src/SFML/Graphics/Vertex.cpp => include/SFML/Graphics/Vertex.inl (77%) diff --git a/include/SFML/Graphics/Vertex.hpp b/include/SFML/Graphics/Vertex.hpp index f4e109b2..42386e8c 100644 --- a/include/SFML/Graphics/Vertex.hpp +++ b/include/SFML/Graphics/Vertex.hpp @@ -28,7 +28,6 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include #include #include @@ -39,7 +38,7 @@ namespace sf /// \brief Define a point with color and texture coordinates /// //////////////////////////////////////////////////////////// -class SFML_GRAPHICS_API Vertex +class Vertex { public: @@ -47,7 +46,7 @@ public: /// \brief Default constructor /// //////////////////////////////////////////////////////////// - Vertex(); + constexpr Vertex(); //////////////////////////////////////////////////////////// /// \brief Construct the vertex from its position @@ -57,7 +56,7 @@ public: /// \param thePosition Vertex position /// //////////////////////////////////////////////////////////// - Vertex(const Vector2f& thePosition); + constexpr Vertex(const Vector2f& thePosition); //////////////////////////////////////////////////////////// /// \brief Construct the vertex from its position and color @@ -68,7 +67,7 @@ public: /// \param theColor Vertex color /// //////////////////////////////////////////////////////////// - Vertex(const Vector2f& thePosition, const Color& theColor); + constexpr Vertex(const Vector2f& thePosition, const Color& theColor); //////////////////////////////////////////////////////////// /// \brief Construct the vertex from its position and texture coordinates @@ -79,7 +78,7 @@ public: /// \param theTexCoords Vertex texture coordinates /// //////////////////////////////////////////////////////////// - Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords); + constexpr Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords); //////////////////////////////////////////////////////////// /// \brief Construct the vertex from its position, color and texture coordinates @@ -89,7 +88,7 @@ public: /// \param theTexCoords Vertex texture coordinates /// //////////////////////////////////////////////////////////// - Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords); + constexpr Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords); //////////////////////////////////////////////////////////// // Member data @@ -99,6 +98,8 @@ public: Vector2f texCoords; //!< Coordinates of the texture's pixel to map to the vertex }; +#include + } // namespace sf diff --git a/src/SFML/Graphics/Vertex.cpp b/include/SFML/Graphics/Vertex.inl similarity index 77% rename from src/SFML/Graphics/Vertex.cpp rename to include/SFML/Graphics/Vertex.inl index 2b066091..9bcef347 100644 --- a/src/SFML/Graphics/Vertex.cpp +++ b/include/SFML/Graphics/Vertex.inl @@ -22,16 +22,9 @@ // //////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - -namespace sf -{ //////////////////////////////////////////////////////////// -Vertex::Vertex() : +constexpr Vertex::Vertex() : position (0, 0), color (255, 255, 255), texCoords(0, 0) @@ -40,7 +33,7 @@ texCoords(0, 0) //////////////////////////////////////////////////////////// -Vertex::Vertex(const Vector2f& thePosition) : +constexpr Vertex::Vertex(const Vector2f& thePosition) : position (thePosition), color (255, 255, 255), texCoords(0, 0) @@ -49,7 +42,7 @@ texCoords(0, 0) //////////////////////////////////////////////////////////// -Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) : +constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor) : position (thePosition), color (theColor), texCoords(0, 0) @@ -58,7 +51,7 @@ texCoords(0, 0) //////////////////////////////////////////////////////////// -Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) : +constexpr Vertex::Vertex(const Vector2f& thePosition, const Vector2f& theTexCoords) : position (thePosition), color (255, 255, 255), texCoords(theTexCoords) @@ -67,11 +60,9 @@ texCoords(theTexCoords) //////////////////////////////////////////////////////////// -Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) : +constexpr Vertex::Vertex(const Vector2f& thePosition, const Color& theColor, const Vector2f& theTexCoords) : position (thePosition), color (theColor), texCoords(theTexCoords) { } - -} // namespace sf diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 36320089..3b5eaf28 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -47,8 +47,8 @@ set(SRC ${INCROOT}/Transformable.hpp ${SRCROOT}/View.cpp ${INCROOT}/View.hpp - ${SRCROOT}/Vertex.cpp ${INCROOT}/Vertex.hpp + ${INCROOT}/Vertex.inl ) source_group("" FILES ${SRC})