From 056f66a2b8753dd35bdc991eb426b68d64c84454 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 12 Sep 2022 14:12:53 -0600 Subject: [PATCH] Replace `sf::Int32` with `std::int32_t` --- examples/vulkan/Vulkan.cpp | 11 +++- include/SFML/Audio/SoundStream.hpp | 2 +- include/SFML/Config.hpp | 1 - include/SFML/Network/Packet.hpp | 6 +- include/SFML/System/Time.hpp | 8 +-- include/SFML/System/Time.inl | 6 +- src/SFML/Audio/SoundFileWriterFlac.hpp | 6 +- src/SFML/Network/Packet.cpp | 8 +-- src/SFML/Window/Android/SensorImpl.cpp | 2 +- src/SFML/Window/Android/WindowImplAndroid.cpp | 56 +++++++++---------- src/SFML/Window/Android/WindowImplAndroid.hpp | 2 +- test/Graphics/Color.cpp | 2 +- test/Network/Packet.cpp | 10 ++-- test/System/Config.cpp | 1 - 14 files changed, 63 insertions(+), 58 deletions(-) diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index e5826f42..42bb247c 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -185,8 +185,15 @@ GLADapiproc getVulkanFunction(const char* name) } // Debug we pass to Vulkan to call when it detects warnings or errors -VKAPI_ATTR VkBool32 VKAPI_CALL - debugCallback(VkDebugReportFlagsEXT, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char*, const char* pMessage, void*) +VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback( + VkDebugReportFlagsEXT, + VkDebugReportObjectTypeEXT, + uint64_t, + std::size_t, + std::int32_t, + const char*, + const char* pMessage, + void*) { std::cerr << pMessage << std::endl; diff --git a/include/SFML/Audio/SoundStream.hpp b/include/SFML/Audio/SoundStream.hpp index 560e6e7f..2dd2ddd4 100644 --- a/include/SFML/Audio/SoundStream.hpp +++ b/include/SFML/Audio/SoundStream.hpp @@ -344,7 +344,7 @@ private: unsigned int m_buffers[BufferCount]; //!< Sound buffers used to store temporary audio data unsigned int m_channelCount; //!< Number of channels (1 = mono, 2 = stereo, ...) unsigned int m_sampleRate; //!< Frequency (samples / second) - Int32 m_format; //!< Format of the internal sound buffers + std::int32_t m_format; //!< Format of the internal sound buffers bool m_loop; //!< Loop flag (true to loop, false to play once) Uint64 m_samplesProcessed; //!< Number of samples processed since beginning of the stream Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation. diff --git a/include/SFML/Config.hpp b/include/SFML/Config.hpp index 84cbacc2..b5c93f6f 100644 --- a/include/SFML/Config.hpp +++ b/include/SFML/Config.hpp @@ -168,7 +168,6 @@ namespace sf { // 32 bits integer types -using Int32 = std::int32_t; using Uint32 = std::uint32_t; // 64 bits integer types diff --git a/include/SFML/Network/Packet.hpp b/include/SFML/Network/Packet.hpp index d835c50d..ee118f5d 100644 --- a/include/SFML/Network/Packet.hpp +++ b/include/SFML/Network/Packet.hpp @@ -233,7 +233,7 @@ public: //////////////////////////////////////////////////////////// /// \overload //////////////////////////////////////////////////////////// - Packet& operator>>(Int32& data); + Packet& operator>>(std::int32_t& data); //////////////////////////////////////////////////////////// /// \overload @@ -314,7 +314,7 @@ public: //////////////////////////////////////////////////////////// /// \overload //////////////////////////////////////////////////////////// - Packet& operator<<(Int32 data); + Packet& operator<<(std::int32_t data); //////////////////////////////////////////////////////////// /// \overload @@ -461,7 +461,7 @@ private: /// It is designed to follow the behavior of standard C++ streams, /// using operators >> and << to extract and insert data. /// -/// It is recommended to use only fixed-size types (like sf::Int32, etc.), +/// It is recommended to use only fixed-size types (like std::int32_t, etc.), /// to avoid possible differences between the sender and the receiver. /// Indeed, the native C++ types may have different sizes on two platforms /// and your data may be corrupted if that happens. diff --git a/include/SFML/System/Time.hpp b/include/SFML/System/Time.hpp index b856408c..44aa99d7 100644 --- a/include/SFML/System/Time.hpp +++ b/include/SFML/System/Time.hpp @@ -75,7 +75,7 @@ public: /// \see asSeconds, asMicroseconds /// //////////////////////////////////////////////////////////// - constexpr Int32 asMilliseconds() const; + constexpr std::int32_t asMilliseconds() const; //////////////////////////////////////////////////////////// /// \brief Return the time value as a number of microseconds @@ -111,7 +111,7 @@ public: private: friend constexpr Time seconds(float); - friend constexpr Time milliseconds(Int32); + friend constexpr Time milliseconds(std::int32_t); friend constexpr Time microseconds(Int64); private: @@ -145,7 +145,7 @@ constexpr Time seconds(float amount); /// \see seconds, microseconds /// //////////////////////////////////////////////////////////// -constexpr Time milliseconds(Int32 amount); +constexpr Time milliseconds(std::int32_t amount); //////////////////////////////////////////////////////////// /// \relates Time @@ -482,7 +482,7 @@ constexpr Time& operator%=(Time& left, Time right); /// Usage example: /// \code /// sf::Time t1 = sf::seconds(0.1f); -/// Int32 milli = t1.asMilliseconds(); // 100 +/// std::int32_t milli = t1.asMilliseconds(); // 100 /// /// sf::Time t2 = sf::milliseconds(30); /// Int64 micro = t2.asMicroseconds(); // 30000 diff --git a/include/SFML/System/Time.inl b/include/SFML/System/Time.inl index 213bba1d..f776490c 100644 --- a/include/SFML/System/Time.inl +++ b/include/SFML/System/Time.inl @@ -44,9 +44,9 @@ constexpr float Time::asSeconds() const //////////////////////////////////////////////////////////// -constexpr Int32 Time::asMilliseconds() const +constexpr std::int32_t Time::asMilliseconds() const { - return std::chrono::duration_cast>(m_microseconds).count(); + return std::chrono::duration_cast>(m_microseconds).count(); } @@ -80,7 +80,7 @@ constexpr Time seconds(float amount) //////////////////////////////////////////////////////////// -constexpr Time milliseconds(Int32 amount) +constexpr Time milliseconds(std::int32_t amount) { return Time(std::chrono::milliseconds(amount)); } diff --git a/src/SFML/Audio/SoundFileWriterFlac.hpp b/src/SFML/Audio/SoundFileWriterFlac.hpp index 66b0d1ef..79fc0e06 100644 --- a/src/SFML/Audio/SoundFileWriterFlac.hpp +++ b/src/SFML/Audio/SoundFileWriterFlac.hpp @@ -100,9 +100,9 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - FLAC__StreamEncoder* m_encoder; //!< FLAC stream encoder - unsigned int m_channelCount; //!< Number of channels - std::vector m_samples32; //!< Conversion buffer + FLAC__StreamEncoder* m_encoder; //!< FLAC stream encoder + unsigned int m_channelCount; //!< Number of channels + std::vector m_samples32; //!< Conversion buffer }; } // namespace priv diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index c202cb76..a3d1c492 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -183,12 +183,12 @@ Packet& Packet::operator>>(std::uint16_t& data) //////////////////////////////////////////////////////////// -Packet& Packet::operator>>(Int32& data) +Packet& Packet::operator>>(std::int32_t& data) { if (checkSize(sizeof(data))) { std::memcpy(&data, &m_data[m_readPos], sizeof(data)); - data = static_cast(ntohl(static_cast(data))); + data = static_cast(ntohl(static_cast(data))); m_readPos += sizeof(data); } @@ -434,9 +434,9 @@ Packet& Packet::operator<<(std::uint16_t data) //////////////////////////////////////////////////////////// -Packet& Packet::operator<<(Int32 data) +Packet& Packet::operator<<(std::int32_t data) { - Int32 toWrite = static_cast(htonl(static_cast(data))); + std::int32_t toWrite = static_cast(htonl(static_cast(data))); append(&toWrite, sizeof(toWrite)); return *this; } diff --git a/src/SFML/Window/Android/SensorImpl.cpp b/src/SFML/Window/Android/SensorImpl.cpp index 7f97aca6..bbfb4e47 100644 --- a/src/SFML/Window/Android/SensorImpl.cpp +++ b/src/SFML/Window/Android/SensorImpl.cpp @@ -101,7 +101,7 @@ bool SensorImpl::open(Sensor::Type sensor) Time minimumDelay = microseconds(ASensor_getMinDelay(m_sensor)); // Set the event rate (not to consume too much battery) - ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast(minimumDelay.asMicroseconds())); + ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast(minimumDelay.asMicroseconds())); // Save the index of the sensor m_index = static_cast(sensor); diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 62676593..76215e63 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -260,12 +260,12 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat int handled = 0; - int32_t type = AInputEvent_getType(_event); + std::int32_t type = AInputEvent_getType(_event); if (type == AINPUT_EVENT_TYPE_KEY) { - int32_t action = AKeyEvent_getAction(_event); - int32_t key = AKeyEvent_getKeyCode(_event); + std::int32_t action = AKeyEvent_getAction(_event); + std::int32_t key = AKeyEvent_getKeyCode(_event); if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) && key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN) @@ -275,7 +275,7 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat } else if (type == AINPUT_EVENT_TYPE_MOTION) { - int32_t action = AMotionEvent_getAction(_event); + std::int32_t action = AMotionEvent_getAction(_event); switch (action & AMOTION_EVENT_ACTION_MASK) { @@ -341,18 +341,18 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates& s } // Retrieve everything we need to create this MotionEvent in Java - Int64 downTime = AMotionEvent_getDownTime(_event); - Int64 eventTime = AMotionEvent_getEventTime(_event); - Int32 action = AMotionEvent_getAction(_event); - float x = AMotionEvent_getX(_event, 0); - float y = AMotionEvent_getY(_event, 0); - float pressure = AMotionEvent_getPressure(_event, 0); - float size = AMotionEvent_getSize(_event, 0); - Int32 metaState = AMotionEvent_getMetaState(_event); - float xPrecision = AMotionEvent_getXPrecision(_event); - float yPrecision = AMotionEvent_getYPrecision(_event); - Int32 deviceId = AInputEvent_getDeviceId(_event); - Int32 edgeFlags = AMotionEvent_getEdgeFlags(_event); + Int64 downTime = AMotionEvent_getDownTime(_event); + Int64 eventTime = AMotionEvent_getEventTime(_event); + std::int32_t action = AMotionEvent_getAction(_event); + float x = AMotionEvent_getX(_event, 0); + float y = AMotionEvent_getY(_event, 0); + float pressure = AMotionEvent_getPressure(_event, 0); + float size = AMotionEvent_getSize(_event, 0); + std::int32_t metaState = AMotionEvent_getMetaState(_event); + float xPrecision = AMotionEvent_getXPrecision(_event); + float yPrecision = AMotionEvent_getYPrecision(_event); + std::int32_t deviceId = AInputEvent_getDeviceId(_event); + std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(_event); // Create the MotionEvent object in Java trough its static constructor obtain() jclass ClassMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent"); @@ -404,10 +404,10 @@ int WindowImplAndroid::processScrollEvent(AInputEvent* _event, ActivityStates& s //////////////////////////////////////////////////////////// int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* states */) { - int32_t action = AKeyEvent_getAction(_event); + std::int32_t action = AKeyEvent_getAction(_event); - int32_t key = AKeyEvent_getKeyCode(_event); - int32_t metakey = AKeyEvent_getMetaState(_event); + std::int32_t key = AKeyEvent_getKeyCode(_event); + std::int32_t metakey = AKeyEvent_getMetaState(_event); Event event; event.key.code = androidKeyToSF(key); @@ -453,8 +453,8 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s event.type = Event::TextEntered; event.text.unicode = static_cast(unicode); - int32_t repeats = AKeyEvent_getRepeatCount(_event); - for (int32_t i = 0; i < repeats; ++i) + std::int32_t repeats = AKeyEvent_getRepeatCount(_event); + for (std::int32_t i = 0; i < repeats; ++i) forwardEvent(event); return 1; } @@ -467,7 +467,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s //////////////////////////////////////////////////////////// int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& states) { - int32_t device = AInputEvent_getSource(_event); + std::int32_t device = AInputEvent_getSource(_event); Event event; @@ -480,7 +480,7 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s for (std::size_t p = 0; p < pointerCount; ++p) { - int32_t id = AMotionEvent_getPointerId(_event, p); + std::int32_t id = AMotionEvent_getPointerId(_event, p); int x = static_cast(AMotionEvent_getX(_event, p)); int y = static_cast(AMotionEvent_getY(_event, p)); @@ -513,11 +513,11 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s //////////////////////////////////////////////////////////// int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, ActivityStates& states) { - int32_t device = AInputEvent_getSource(_event); - int32_t action = AMotionEvent_getAction(_event); + std::int32_t device = AInputEvent_getSource(_event); + std::int32_t action = AMotionEvent_getAction(_event); - std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; - int32_t id = AMotionEvent_getPointerId(_event, index); + std::size_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; + std::int32_t id = AMotionEvent_getPointerId(_event, index); int x = static_cast(AMotionEvent_getX(_event, index)); int y = static_cast(AMotionEvent_getY(_event, index)); @@ -575,7 +575,7 @@ int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, Act //////////////////////////////////////////////////////////// -Keyboard::Key WindowImplAndroid::androidKeyToSF(int32_t key) +Keyboard::Key WindowImplAndroid::androidKeyToSF(std::int32_t key) { // clang-format off switch (key) diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index cfbf446a..01bfdc47 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -220,7 +220,7 @@ private: /// \return Corresponding SFML key code /// //////////////////////////////////////////////////////////// - static Keyboard::Key androidKeyToSF(int32_t key); + static Keyboard::Key androidKeyToSF(std::int32_t key); //////////////////////////////////////////////////////////// /// \brief Get Unicode decoded from the input event diff --git a/test/Graphics/Color.cpp b/test/Graphics/Color.cpp index 986751a0..7f5e8804 100644 --- a/test/Graphics/Color.cpp +++ b/test/Graphics/Color.cpp @@ -35,7 +35,7 @@ TEST_CASE("sf::Color class - [graphics]") CHECK(color.a == 4); } - SUBCASE("Int32 constructor") + SUBCASE("std::int32_t constructor") { CHECK(sf::Color(0x00000000) == sf::Color(0, 0, 0, 0)); CHECK(sf::Color(0x01020304) == sf::Color(1, 2, 3, 4)); diff --git a/test/Network/Packet.cpp b/test/Network/Packet.cpp index aaa3b41f..4a693532 100644 --- a/test/Network/Packet.cpp +++ b/test/Network/Packet.cpp @@ -34,12 +34,12 @@ TEST_CASE("sf::Packet class - [network]") testPacketStreamOperators(std::numeric_limits::max()); } - SUBCASE("Int32") + SUBCASE("std::int32_t") { - testPacketStreamOperators(sf::Int32(0)); - testPacketStreamOperators(sf::Int32(1)); - testPacketStreamOperators(std::numeric_limits::min()); - testPacketStreamOperators(std::numeric_limits::max()); + testPacketStreamOperators(std::int32_t(0)); + testPacketStreamOperators(std::int32_t(1)); + testPacketStreamOperators(std::numeric_limits::min()); + testPacketStreamOperators(std::numeric_limits::max()); } SUBCASE("Int64") diff --git a/test/System/Config.cpp b/test/System/Config.cpp index 1c610714..daf3ea70 100644 --- a/test/System/Config.cpp +++ b/test/System/Config.cpp @@ -14,7 +14,6 @@ TEST_CASE("SFML/Config.hpp") SUBCASE("Fixed width types") { - CHECK(sizeof(sf::Int32) == 4); CHECK(sizeof(sf::Uint32) == 4); CHECK(sizeof(sf::Int64) == 8);