Replace sf::Int32 with std::int32_t

This commit is contained in:
Chris Thrasher 2022-09-12 14:12:53 -06:00 committed by Vittorio Romeo
parent ff9c9131b3
commit 056f66a2b8
14 changed files with 63 additions and 58 deletions

View File

@ -185,8 +185,15 @@ GLADapiproc getVulkanFunction(const char* name)
} }
// Debug we pass to Vulkan to call when it detects warnings or errors // Debug we pass to Vulkan to call when it detects warnings or errors
VKAPI_ATTR VkBool32 VKAPI_CALL VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(
debugCallback(VkDebugReportFlagsEXT, VkDebugReportObjectTypeEXT, uint64_t, size_t, int32_t, const char*, const char* pMessage, void*) VkDebugReportFlagsEXT,
VkDebugReportObjectTypeEXT,
uint64_t,
std::size_t,
std::int32_t,
const char*,
const char* pMessage,
void*)
{ {
std::cerr << pMessage << std::endl; std::cerr << pMessage << std::endl;

View File

@ -344,7 +344,7 @@ private:
unsigned int m_buffers[BufferCount]; //!< Sound buffers used to store temporary audio data 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_channelCount; //!< Number of channels (1 = mono, 2 = stereo, ...)
unsigned int m_sampleRate; //!< Frequency (samples / second) 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) bool m_loop; //!< Loop flag (true to loop, false to play once)
Uint64 m_samplesProcessed; //!< Number of samples processed since beginning of the stream 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. Int64 m_bufferSeeks[BufferCount]; //!< If buffer is an "end buffer", holds next seek position, else NoLoop. For play offset calculation.

View File

@ -168,7 +168,6 @@
namespace sf namespace sf
{ {
// 32 bits integer types // 32 bits integer types
using Int32 = std::int32_t;
using Uint32 = std::uint32_t; using Uint32 = std::uint32_t;
// 64 bits integer types // 64 bits integer types

View File

@ -233,7 +233,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator>>(Int32& data); Packet& operator>>(std::int32_t& data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
@ -314,7 +314,7 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Packet& operator<<(Int32 data); Packet& operator<<(std::int32_t data);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \overload /// \overload
@ -461,7 +461,7 @@ private:
/// It is designed to follow the behavior of standard C++ streams, /// It is designed to follow the behavior of standard C++ streams,
/// using operators >> and << to extract and insert data. /// 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. /// to avoid possible differences between the sender and the receiver.
/// Indeed, the native C++ types may have different sizes on two platforms /// Indeed, the native C++ types may have different sizes on two platforms
/// and your data may be corrupted if that happens. /// and your data may be corrupted if that happens.

View File

@ -75,7 +75,7 @@ public:
/// \see asSeconds, asMicroseconds /// \see asSeconds, asMicroseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Int32 asMilliseconds() const; constexpr std::int32_t asMilliseconds() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Return the time value as a number of microseconds /// \brief Return the time value as a number of microseconds
@ -111,7 +111,7 @@ public:
private: private:
friend constexpr Time seconds(float); friend constexpr Time seconds(float);
friend constexpr Time milliseconds(Int32); friend constexpr Time milliseconds(std::int32_t);
friend constexpr Time microseconds(Int64); friend constexpr Time microseconds(Int64);
private: private:
@ -145,7 +145,7 @@ constexpr Time seconds(float amount);
/// \see seconds, microseconds /// \see seconds, microseconds
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
constexpr Time milliseconds(Int32 amount); constexpr Time milliseconds(std::int32_t amount);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \relates Time /// \relates Time
@ -482,7 +482,7 @@ constexpr Time& operator%=(Time& left, Time right);
/// Usage example: /// Usage example:
/// \code /// \code
/// sf::Time t1 = sf::seconds(0.1f); /// 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); /// sf::Time t2 = sf::milliseconds(30);
/// Int64 micro = t2.asMicroseconds(); // 30000 /// Int64 micro = t2.asMicroseconds(); // 30000

View File

@ -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<std::chrono::duration<Int32, std::milli>>(m_microseconds).count(); return std::chrono::duration_cast<std::chrono::duration<std::int32_t, std::milli>>(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)); return Time(std::chrono::milliseconds(amount));
} }

View File

@ -100,9 +100,9 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
FLAC__StreamEncoder* m_encoder; //!< FLAC stream encoder FLAC__StreamEncoder* m_encoder; //!< FLAC stream encoder
unsigned int m_channelCount; //!< Number of channels unsigned int m_channelCount; //!< Number of channels
std::vector<Int32> m_samples32; //!< Conversion buffer std::vector<std::int32_t> m_samples32; //!< Conversion buffer
}; };
} // namespace priv } // namespace priv

View File

@ -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))) if (checkSize(sizeof(data)))
{ {
std::memcpy(&data, &m_data[m_readPos], sizeof(data)); std::memcpy(&data, &m_data[m_readPos], sizeof(data));
data = static_cast<Int32>(ntohl(static_cast<uint32_t>(data))); data = static_cast<std::int32_t>(ntohl(static_cast<uint32_t>(data)));
m_readPos += sizeof(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<Int32>(htonl(static_cast<uint32_t>(data))); std::int32_t toWrite = static_cast<std::int32_t>(htonl(static_cast<uint32_t>(data)));
append(&toWrite, sizeof(toWrite)); append(&toWrite, sizeof(toWrite));
return *this; return *this;
} }

View File

@ -101,7 +101,7 @@ bool SensorImpl::open(Sensor::Type sensor)
Time minimumDelay = microseconds(ASensor_getMinDelay(m_sensor)); Time minimumDelay = microseconds(ASensor_getMinDelay(m_sensor));
// Set the event rate (not to consume too much battery) // Set the event rate (not to consume too much battery)
ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast<Int32>(minimumDelay.asMicroseconds())); ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, static_cast<std::int32_t>(minimumDelay.asMicroseconds()));
// Save the index of the sensor // Save the index of the sensor
m_index = static_cast<unsigned int>(sensor); m_index = static_cast<unsigned int>(sensor);

View File

@ -260,12 +260,12 @@ int WindowImplAndroid::processEvent(int /* fd */, int /* events */, void* /* dat
int handled = 0; int handled = 0;
int32_t type = AInputEvent_getType(_event); std::int32_t type = AInputEvent_getType(_event);
if (type == AINPUT_EVENT_TYPE_KEY) if (type == AINPUT_EVENT_TYPE_KEY)
{ {
int32_t action = AKeyEvent_getAction(_event); std::int32_t action = AKeyEvent_getAction(_event);
int32_t key = AKeyEvent_getKeyCode(_event); std::int32_t key = AKeyEvent_getKeyCode(_event);
if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) && if ((action == AKEY_EVENT_ACTION_DOWN || action == AKEY_EVENT_ACTION_UP || action == AKEY_EVENT_ACTION_MULTIPLE) &&
key != AKEYCODE_VOLUME_UP && key != AKEYCODE_VOLUME_DOWN) 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) 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) 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 // Retrieve everything we need to create this MotionEvent in Java
Int64 downTime = AMotionEvent_getDownTime(_event); Int64 downTime = AMotionEvent_getDownTime(_event);
Int64 eventTime = AMotionEvent_getEventTime(_event); Int64 eventTime = AMotionEvent_getEventTime(_event);
Int32 action = AMotionEvent_getAction(_event); std::int32_t action = AMotionEvent_getAction(_event);
float x = AMotionEvent_getX(_event, 0); float x = AMotionEvent_getX(_event, 0);
float y = AMotionEvent_getY(_event, 0); float y = AMotionEvent_getY(_event, 0);
float pressure = AMotionEvent_getPressure(_event, 0); float pressure = AMotionEvent_getPressure(_event, 0);
float size = AMotionEvent_getSize(_event, 0); float size = AMotionEvent_getSize(_event, 0);
Int32 metaState = AMotionEvent_getMetaState(_event); std::int32_t metaState = AMotionEvent_getMetaState(_event);
float xPrecision = AMotionEvent_getXPrecision(_event); float xPrecision = AMotionEvent_getXPrecision(_event);
float yPrecision = AMotionEvent_getYPrecision(_event); float yPrecision = AMotionEvent_getYPrecision(_event);
Int32 deviceId = AInputEvent_getDeviceId(_event); std::int32_t deviceId = AInputEvent_getDeviceId(_event);
Int32 edgeFlags = AMotionEvent_getEdgeFlags(_event); std::int32_t edgeFlags = AMotionEvent_getEdgeFlags(_event);
// Create the MotionEvent object in Java trough its static constructor obtain() // Create the MotionEvent object in Java trough its static constructor obtain()
jclass ClassMotionEvent = lJNIEnv->FindClass("android/view/MotionEvent"); 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 */) 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); std::int32_t key = AKeyEvent_getKeyCode(_event);
int32_t metakey = AKeyEvent_getMetaState(_event); std::int32_t metakey = AKeyEvent_getMetaState(_event);
Event event; Event event;
event.key.code = androidKeyToSF(key); event.key.code = androidKeyToSF(key);
@ -453,8 +453,8 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s
event.type = Event::TextEntered; event.type = Event::TextEntered;
event.text.unicode = static_cast<Uint32>(unicode); event.text.unicode = static_cast<Uint32>(unicode);
int32_t repeats = AKeyEvent_getRepeatCount(_event); std::int32_t repeats = AKeyEvent_getRepeatCount(_event);
for (int32_t i = 0; i < repeats; ++i) for (std::int32_t i = 0; i < repeats; ++i)
forwardEvent(event); forwardEvent(event);
return 1; return 1;
} }
@ -467,7 +467,7 @@ int WindowImplAndroid::processKeyEvent(AInputEvent* _event, ActivityStates& /* s
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& states) int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& states)
{ {
int32_t device = AInputEvent_getSource(_event); std::int32_t device = AInputEvent_getSource(_event);
Event event; Event event;
@ -480,7 +480,7 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s
for (std::size_t p = 0; p < pointerCount; ++p) 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<int>(AMotionEvent_getX(_event, p)); int x = static_cast<int>(AMotionEvent_getX(_event, p));
int y = static_cast<int>(AMotionEvent_getY(_event, p)); int y = static_cast<int>(AMotionEvent_getY(_event, p));
@ -513,11 +513,11 @@ int WindowImplAndroid::processMotionEvent(AInputEvent* _event, ActivityStates& s
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, ActivityStates& states) int WindowImplAndroid::processPointerEvent(bool isDown, AInputEvent* _event, ActivityStates& states)
{ {
int32_t device = AInputEvent_getSource(_event); std::int32_t device = AInputEvent_getSource(_event);
int32_t action = AMotionEvent_getAction(_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; 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::int32_t id = AMotionEvent_getPointerId(_event, index);
int x = static_cast<int>(AMotionEvent_getX(_event, index)); int x = static_cast<int>(AMotionEvent_getX(_event, index));
int y = static_cast<int>(AMotionEvent_getY(_event, index)); int y = static_cast<int>(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 // clang-format off
switch (key) switch (key)

View File

@ -220,7 +220,7 @@ private:
/// \return Corresponding SFML key code /// \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 /// \brief Get Unicode decoded from the input event

View File

@ -35,7 +35,7 @@ TEST_CASE("sf::Color class - [graphics]")
CHECK(color.a == 4); 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(0x00000000) == sf::Color(0, 0, 0, 0));
CHECK(sf::Color(0x01020304) == sf::Color(1, 2, 3, 4)); CHECK(sf::Color(0x01020304) == sf::Color(1, 2, 3, 4));

View File

@ -34,12 +34,12 @@ TEST_CASE("sf::Packet class - [network]")
testPacketStreamOperators(std::numeric_limits<std::int16_t>::max()); testPacketStreamOperators(std::numeric_limits<std::int16_t>::max());
} }
SUBCASE("Int32") SUBCASE("std::int32_t")
{ {
testPacketStreamOperators(sf::Int32(0)); testPacketStreamOperators(std::int32_t(0));
testPacketStreamOperators(sf::Int32(1)); testPacketStreamOperators(std::int32_t(1));
testPacketStreamOperators(std::numeric_limits<sf::Int32>::min()); testPacketStreamOperators(std::numeric_limits<std::int32_t>::min());
testPacketStreamOperators(std::numeric_limits<sf::Int32>::max()); testPacketStreamOperators(std::numeric_limits<std::int32_t>::max());
} }
SUBCASE("Int64") SUBCASE("Int64")

View File

@ -14,7 +14,6 @@ TEST_CASE("SFML/Config.hpp")
SUBCASE("Fixed width types") SUBCASE("Fixed width types")
{ {
CHECK(sizeof(sf::Int32) == 4);
CHECK(sizeof(sf::Uint32) == 4); CHECK(sizeof(sf::Uint32) == 4);
CHECK(sizeof(sf::Int64) == 8); CHECK(sizeof(sf::Int64) == 8);