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.
This commit is contained in:
ZXShady authored and Chris Thrasher committed 2024-10-04 09:05:55 -06:00
1 parent cc92ca36b7
commit 884dcde3c3
9 files changed
+20 -24

No files matched your search

+8 -4
View File
@@ -144,8 +144,10 @@ typedef enum
sfKeyPause, ///< The Pause key sfKeyPause, ///< The Pause key
} sfKeyCode; } 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 /// \brief Scancodes
@@ -312,8 +314,10 @@ typedef enum
sfScanLaunchMediaSelect, //!< Keyboard Launch Media Select key sfScanLaunchMediaSelect, //!< Keyboard Launch Media Select key
} sfScancode; } 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 /// \brief Check if a key is pressed
+4 -1
View File
@@ -46,7 +46,10 @@ typedef enum
sfMouseButtonExtra2, ///< The second extra mouse button sfMouseButtonExtra2, ///< The second extra mouse button
} sfMouseButton; } 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 /// \brief Mouse wheels
+4 -2
View File
@@ -47,8 +47,10 @@ typedef enum
sfSensorOrientation, ///< Measures the absolute 3D orientation (degrees) sfSensorOrientation, ///< Measures the absolute 3D orientation (degrees)
} sfSensorType; } 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 /// \brief Check if a sensor is available on the underlying platform
-5
View File
@@ -33,11 +33,6 @@
#include <cstring> #include <cstring>
////////////////////////////////////////////////////////////
const unsigned int sfKeyCount = sfKeyPause + 1;
const unsigned int sfScancodeCount = sfScanLaunchMediaSelect + 1;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool sfKeyboard_isKeyPressed(sfKeyCode key) bool sfKeyboard_isKeyPressed(sfKeyCode key)
{ {
-4
View File
@@ -33,10 +33,6 @@
#include <SFML/Window/Mouse.hpp> #include <SFML/Window/Mouse.hpp>
////////////////////////////////////////////////////////////
const unsigned int sfMouseButtonCount = sfMouseButtonExtra2 + 1;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool sfMouse_isButtonPressed(sfMouseButton button) bool sfMouse_isButtonPressed(sfMouseButton button)
{ {
-4
View File
@@ -31,10 +31,6 @@
#include <SFML/Window/Sensor.hpp> #include <SFML/Window/Sensor.hpp>
////////////////////////////////////////////////////////////
const unsigned int sfSensorCount = sfSensorOrientation + 1;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool sfSensor_isAvailable(sfSensorType sensor) bool sfSensor_isAvailable(sfSensorType sensor)
{ {
+2 -2
View File
@@ -14,7 +14,7 @@ TEST_CASE("[Window] sfKeyboard")
STATIC_CHECK(sfKeyC == static_cast<int>(sf::Keyboard::Key::C)); STATIC_CHECK(sfKeyC == static_cast<int>(sf::Keyboard::Key::C));
STATIC_CHECK(sfKeyD == static_cast<int>(sf::Keyboard::Key::D)); STATIC_CHECK(sfKeyD == static_cast<int>(sf::Keyboard::Key::D));
STATIC_CHECK(sfKeyPause == static_cast<int>(sf::Keyboard::Key::Pause)); STATIC_CHECK(sfKeyPause == static_cast<int>(sf::Keyboard::Key::Pause));
CHECK(sfKeyCount == sf::Keyboard::KeyCount); STATIC_CHECK(sfKeyCount == sf::Keyboard::KeyCount);
} }
SECTION("sfScancode") SECTION("sfScancode")
@@ -24,6 +24,6 @@ TEST_CASE("[Window] sfKeyboard")
STATIC_CHECK(sfScanB == static_cast<int>(sf::Keyboard::Scan::B)); STATIC_CHECK(sfScanB == static_cast<int>(sf::Keyboard::Scan::B));
STATIC_CHECK(sfScanC == static_cast<int>(sf::Keyboard::Scan::C)); STATIC_CHECK(sfScanC == static_cast<int>(sf::Keyboard::Scan::C));
STATIC_CHECK(sfScanD == static_cast<int>(sf::Keyboard::Scan::D)); STATIC_CHECK(sfScanD == static_cast<int>(sf::Keyboard::Scan::D));
CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount); STATIC_CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
} }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ TEST_CASE("[Window] sfMouse")
STATIC_CHECK(sfMouseMiddle == static_cast<int>(sf::Mouse::Button::Middle)); STATIC_CHECK(sfMouseMiddle == static_cast<int>(sf::Mouse::Button::Middle));
STATIC_CHECK(sfMouseButtonExtra1 == static_cast<int>(sf::Mouse::Button::Extra1)); STATIC_CHECK(sfMouseButtonExtra1 == static_cast<int>(sf::Mouse::Button::Extra1));
STATIC_CHECK(sfMouseButtonExtra2 == static_cast<int>(sf::Mouse::Button::Extra2)); STATIC_CHECK(sfMouseButtonExtra2 == static_cast<int>(sf::Mouse::Button::Extra2));
CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount); STATIC_CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount);
} }
SECTION("sfMouseWheel") SECTION("sfMouseWheel")
+1 -1
View File
@@ -14,6 +14,6 @@ TEST_CASE("[Window] sfSensor")
STATIC_CHECK(sfSensorGravity == static_cast<int>(sf::Sensor::Type::Gravity)); STATIC_CHECK(sfSensorGravity == static_cast<int>(sf::Sensor::Type::Gravity));
STATIC_CHECK(sfSensorUserAcceleration == static_cast<int>(sf::Sensor::Type::UserAcceleration)); STATIC_CHECK(sfSensorUserAcceleration == static_cast<int>(sf::Sensor::Type::UserAcceleration));
STATIC_CHECK(sfSensorOrientation == static_cast<int>(sf::Sensor::Type::Orientation)); STATIC_CHECK(sfSensorOrientation == static_cast<int>(sf::Sensor::Type::Orientation));
CHECK(sfSensorCount == sf::Sensor::Count); STATIC_CHECK(sfSensorCount == sf::Sensor::Count);
} }
} }