Skip to content

Commit

Permalink
Make enumeration counts constant expressions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ZXShady authored and ChrisThrasher committed Oct 4, 2024
1 parent cc92ca3 commit 884dcde
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 24 deletions.
12 changes: 8 additions & 4 deletions include/CSFML/Window/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion include/CSFML/Window/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions include/CSFML/Window/Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/CSFML/Window/Keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
#include <cstring>


////////////////////////////////////////////////////////////
const unsigned int sfKeyCount = sfKeyPause + 1;
const unsigned int sfScancodeCount = sfScanLaunchMediaSelect + 1;


////////////////////////////////////////////////////////////
bool sfKeyboard_isKeyPressed(sfKeyCode key)
{
Expand Down
4 changes: 0 additions & 4 deletions src/CSFML/Window/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
#include <SFML/Window/Mouse.hpp>


////////////////////////////////////////////////////////////
const unsigned int sfMouseButtonCount = sfMouseButtonExtra2 + 1;


////////////////////////////////////////////////////////////
bool sfMouse_isButtonPressed(sfMouseButton button)
{
Expand Down
4 changes: 0 additions & 4 deletions src/CSFML/Window/Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
#include <SFML/Window/Sensor.hpp>


////////////////////////////////////////////////////////////
const unsigned int sfSensorCount = sfSensorOrientation + 1;


////////////////////////////////////////////////////////////
bool sfSensor_isAvailable(sfSensorType sensor)
{
Expand Down
4 changes: 2 additions & 2 deletions test/Window/Keyboard.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_CASE("[Window] sfKeyboard")
STATIC_CHECK(sfKeyC == static_cast<int>(sf::Keyboard::Key::C));
STATIC_CHECK(sfKeyD == static_cast<int>(sf::Keyboard::Key::D));
STATIC_CHECK(sfKeyPause == static_cast<int>(sf::Keyboard::Key::Pause));
CHECK(sfKeyCount == sf::Keyboard::KeyCount);
STATIC_CHECK(sfKeyCount == sf::Keyboard::KeyCount);
}

SECTION("sfScancode")
Expand All @@ -24,6 +24,6 @@ TEST_CASE("[Window] sfKeyboard")
STATIC_CHECK(sfScanB == static_cast<int>(sf::Keyboard::Scan::B));
STATIC_CHECK(sfScanC == static_cast<int>(sf::Keyboard::Scan::C));
STATIC_CHECK(sfScanD == static_cast<int>(sf::Keyboard::Scan::D));
CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
STATIC_CHECK(sfScancodeCount == sf::Keyboard::ScancodeCount);
}
}
2 changes: 1 addition & 1 deletion test/Window/Mouse.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TEST_CASE("[Window] sfMouse")
STATIC_CHECK(sfMouseMiddle == static_cast<int>(sf::Mouse::Button::Middle));
STATIC_CHECK(sfMouseButtonExtra1 == static_cast<int>(sf::Mouse::Button::Extra1));
STATIC_CHECK(sfMouseButtonExtra2 == static_cast<int>(sf::Mouse::Button::Extra2));
CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount);
STATIC_CHECK(sfMouseButtonCount == sf::Mouse::ButtonCount);
}

SECTION("sfMouseWheel")
Expand Down
2 changes: 1 addition & 1 deletion test/Window/Sensor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ TEST_CASE("[Window] sfSensor")
STATIC_CHECK(sfSensorGravity == static_cast<int>(sf::Sensor::Type::Gravity));
STATIC_CHECK(sfSensorUserAcceleration == static_cast<int>(sf::Sensor::Type::UserAcceleration));
STATIC_CHECK(sfSensorOrientation == static_cast<int>(sf::Sensor::Type::Orientation));
CHECK(sfSensorCount == sf::Sensor::Count);
STATIC_CHECK(sfSensorCount == sf::Sensor::Count);
}
}

0 comments on commit 884dcde

Please sign in to comment.