From 884dcde3c380e28847a18f962517b65b530ea90a Mon Sep 17 00:00:00 2001 From: ZXShady <153229951+ZXShady@users.noreply.github.com> Date: Wed, 2 Oct 2024 23:16:53 +0100 Subject: [PATCH] Make enumeration counts constant expressions This change allows now having these variables as array sizes that are not Variable Length Arrays like in structs for example. To note however that this changes the type from unsigned int to an implementation defined type which usually `int` which is signed and not unsigned. --- include/CSFML/Window/Keyboard.h | 12 ++++++++---- include/CSFML/Window/Mouse.h | 5 ++++- include/CSFML/Window/Sensor.h | 6 ++++-- src/CSFML/Window/Keyboard.cpp | 5 ----- src/CSFML/Window/Mouse.cpp | 4 ---- src/CSFML/Window/Sensor.cpp | 4 ---- test/Window/Keyboard.test.cpp | 4 ++-- test/Window/Mouse.test.cpp | 2 +- test/Window/Sensor.test.cpp | 2 +- 9 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/CSFML/Window/Keyboard.h b/include/CSFML/Window/Keyboard.h index 3cf5ee35..f13f02ba 100644 --- a/include/CSFML/Window/Keyboard.h +++ b/include/CSFML/Window/Keyboard.h @@ -144,8 +144,10 @@ typedef enum sfKeyPause, ///< The Pause key } sfKeyCode; -CSFML_WINDOW_API const unsigned int sfKeyCount; ///< The total number of keyboard keys - +enum +{ + sfKeyCount = sfKeyPause + 1 ///< The total number of keyboard keys +}; //////////////////////////////////////////////////////////// /// \brief Scancodes @@ -312,8 +314,10 @@ typedef enum sfScanLaunchMediaSelect, //!< Keyboard Launch Media Select key } sfScancode; -CSFML_WINDOW_API const unsigned int sfScancodeCount; //!< The total number of scancodes - +enum +{ + sfScancodeCount = sfScanLaunchMediaSelect + 1 //!< The total number of scancodes +}; //////////////////////////////////////////////////////////// /// \brief Check if a key is pressed diff --git a/include/CSFML/Window/Mouse.h b/include/CSFML/Window/Mouse.h index 098d2e50..a92bfb87 100644 --- a/include/CSFML/Window/Mouse.h +++ b/include/CSFML/Window/Mouse.h @@ -46,7 +46,10 @@ typedef enum sfMouseButtonExtra2, ///< The second extra mouse button } sfMouseButton; -CSFML_WINDOW_API const unsigned int sfMouseButtonCount; ///< The total number of mouse buttons +enum +{ + sfMouseButtonCount = sfMouseButtonExtra2 + 1 ///< The total number of mouse buttons +}; //////////////////////////////////////////////////////////// /// \brief Mouse wheels diff --git a/include/CSFML/Window/Sensor.h b/include/CSFML/Window/Sensor.h index fda6decf..2f38b761 100644 --- a/include/CSFML/Window/Sensor.h +++ b/include/CSFML/Window/Sensor.h @@ -47,8 +47,10 @@ typedef enum sfSensorOrientation, ///< Measures the absolute 3D orientation (degrees) } sfSensorType; -CSFML_WINDOW_API const unsigned int sfSensorCount; ///< The total number of sensor types - +enum +{ + sfSensorCount = sfSensorOrientation + 1 ///< The total number of sensor types +}; //////////////////////////////////////////////////////////// /// \brief Check if a sensor is available on the underlying platform diff --git a/src/CSFML/Window/Keyboard.cpp b/src/CSFML/Window/Keyboard.cpp index 1d05071a..c66b96ff 100644 --- a/src/CSFML/Window/Keyboard.cpp +++ b/src/CSFML/Window/Keyboard.cpp @@ -33,11 +33,6 @@ #include -//////////////////////////////////////////////////////////// -const unsigned int sfKeyCount = sfKeyPause + 1; -const unsigned int sfScancodeCount = sfScanLaunchMediaSelect + 1; - - //////////////////////////////////////////////////////////// bool sfKeyboard_isKeyPressed(sfKeyCode key) { diff --git a/src/CSFML/Window/Mouse.cpp b/src/CSFML/Window/Mouse.cpp index b794bb18..45e61c6d 100644 --- a/src/CSFML/Window/Mouse.cpp +++ b/src/CSFML/Window/Mouse.cpp @@ -33,10 +33,6 @@ #include -//////////////////////////////////////////////////////////// -const unsigned int sfMouseButtonCount = sfMouseButtonExtra2 + 1; - - //////////////////////////////////////////////////////////// bool sfMouse_isButtonPressed(sfMouseButton button) { diff --git a/src/CSFML/Window/Sensor.cpp b/src/CSFML/Window/Sensor.cpp index 255af27b..5c5f2db4 100644 --- a/src/CSFML/Window/Sensor.cpp +++ b/src/CSFML/Window/Sensor.cpp @@ -31,10 +31,6 @@ #include -//////////////////////////////////////////////////////////// -const unsigned int sfSensorCount = sfSensorOrientation + 1; - - //////////////////////////////////////////////////////////// bool sfSensor_isAvailable(sfSensorType sensor) { diff --git a/test/Window/Keyboard.test.cpp b/test/Window/Keyboard.test.cpp index 5adfc39e..812520ed 100644 --- a/test/Window/Keyboard.test.cpp +++ b/test/Window/Keyboard.test.cpp @@ -14,7 +14,7 @@ TEST_CASE("[Window] sfKeyboard") STATIC_CHECK(sfKeyC == static_cast(sf::Keyboard::Key::C)); STATIC_CHECK(sfKeyD == static_cast(sf::Keyboard::Key::D)); STATIC_CHECK(sfKeyPause == static_cast(sf::Keyboard::Key::Pause)); - CHECK(sfKeyCount == sf::Keyboard::KeyCount); + STATIC_CHECK(sfKeyCount == sf::Keyboard::KeyCount); } SECTION("sfScancode") @@ -24,6 +24,6 @@ TEST_CASE("[Window] sfKeyboard") STATIC_CHECK(sfScanB == static_cast(sf::Keyboard::Scan::B)); STATIC_CHECK(sfScanC == static_cast(sf::Keyboard::Scan::C)); STATIC_CHECK(sfScanD == static_cast(sf::Keyboard::Scan::D)); - CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount); + STATIC_CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount); } } diff --git a/test/Window/Mouse.test.cpp b/test/Window/Mouse.test.cpp index d627a22d..86cfdcbc 100644 --- a/test/Window/Mouse.test.cpp +++ b/test/Window/Mouse.test.cpp @@ -13,7 +13,7 @@ TEST_CASE("[Window] sfMouse") STATIC_CHECK(sfMouseMiddle == static_cast(sf::Mouse::Button::Middle)); STATIC_CHECK(sfMouseButtonExtra1 == static_cast(sf::Mouse::Button::Extra1)); STATIC_CHECK(sfMouseButtonExtra2 == static_cast(sf::Mouse::Button::Extra2)); - CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount); + STATIC_CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount); } SECTION("sfMouseWheel") diff --git a/test/Window/Sensor.test.cpp b/test/Window/Sensor.test.cpp index 29340bc8..bbce5e3e 100644 --- a/test/Window/Sensor.test.cpp +++ b/test/Window/Sensor.test.cpp @@ -14,6 +14,6 @@ TEST_CASE("[Window] sfSensor") STATIC_CHECK(sfSensorGravity == static_cast(sf::Sensor::Type::Gravity)); STATIC_CHECK(sfSensorUserAcceleration == static_cast(sf::Sensor::Type::UserAcceleration)); STATIC_CHECK(sfSensorOrientation == static_cast(sf::Sensor::Type::Orientation)); - CHECK(sfSensorCount == sf::Sensor::Count); + STATIC_CHECK(sfSensorCount == sf::Sensor::Count); } }