mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Replace sf::Uint16
with std::uint16_t
This commit is contained in:
parent
e21ae3204e
commit
ff9c9131b3
@ -137,7 +137,7 @@ public:
|
||||
{
|
||||
std::uniform_real_distribution<float> x_distribution(0, 800);
|
||||
std::uniform_real_distribution<float> y_distribution(0, 600);
|
||||
std::uniform_int_distribution<sf::Uint16> color_distribution(0, 255);
|
||||
std::uniform_int_distribution<std::uint16_t> color_distribution(0, 255);
|
||||
|
||||
// Create the points
|
||||
m_points.setPrimitiveType(sf::Points);
|
||||
|
@ -167,9 +167,6 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace sf
|
||||
{
|
||||
// 16 bits integer types
|
||||
using Uint16 = std::uint16_t;
|
||||
|
||||
// 32 bits integer types
|
||||
using Int32 = std::int32_t;
|
||||
using Uint32 = std::uint32_t;
|
||||
|
@ -107,7 +107,8 @@ constexpr Color operator*(const Color& left, const Color& right)
|
||||
{
|
||||
const auto scaledMul = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
|
||||
{
|
||||
const auto uint16Result = static_cast<Uint16>(static_cast<Uint16>(lhs) * static_cast<Uint16>(rhs));
|
||||
const auto uint16Result = static_cast<std::uint16_t>(
|
||||
static_cast<std::uint16_t>(lhs) * static_cast<std::uint16_t>(rhs));
|
||||
return static_cast<std::uint8_t>(uint16Result / 255u);
|
||||
};
|
||||
|
||||
|
@ -228,7 +228,7 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \overload
|
||||
////////////////////////////////////////////////////////////
|
||||
Packet& operator>>(Uint16& data);
|
||||
Packet& operator>>(std::uint16_t& data);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \overload
|
||||
@ -309,7 +309,7 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \overload
|
||||
////////////////////////////////////////////////////////////
|
||||
Packet& operator<<(Uint16 data);
|
||||
Packet& operator<<(std::uint16_t data);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \overload
|
||||
|
@ -296,7 +296,7 @@ public:
|
||||
/// \see toUtf8, toUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint16> toUtf16() const;
|
||||
std::basic_string<std::uint16_t> toUtf16() const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert the Unicode string to a UTF-32 string
|
||||
|
@ -292,7 +292,7 @@ public:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
static Out encode(Uint32 input, Out output, Uint16 replacement = 0);
|
||||
static Out encode(Uint32 input, Out output, std::uint16_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Advance to the next UTF-16 character
|
||||
|
@ -301,7 +301,7 @@ Out Utf<8>::toUtf32(In begin, In end, Out output)
|
||||
template <typename In>
|
||||
In Utf<16>::decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
{
|
||||
Uint16 first = *begin++;
|
||||
std::uint16_t first = *begin++;
|
||||
|
||||
// If it's a surrogate pair, first convert to a single UTF-32 character
|
||||
if ((first >= 0xD800) && (first <= 0xDBFF))
|
||||
@ -339,7 +339,7 @@ In Utf<16>::decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename Out>
|
||||
Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement)
|
||||
Out Utf<16>::encode(Uint32 input, Out output, std::uint16_t replacement)
|
||||
{
|
||||
if (input <= 0xFFFF)
|
||||
{
|
||||
@ -353,7 +353,7 @@ Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement)
|
||||
else
|
||||
{
|
||||
// Valid character directly convertible to a single UTF-16 character
|
||||
*output++ = static_cast<Uint16>(input);
|
||||
*output++ = static_cast<std::uint16_t>(input);
|
||||
}
|
||||
}
|
||||
else if (input > 0x0010FFFF)
|
||||
@ -366,8 +366,8 @@ Out Utf<16>::encode(Uint32 input, Out output, Uint16 replacement)
|
||||
{
|
||||
// The input character will be converted to two UTF-16 elements
|
||||
input -= 0x0010000;
|
||||
*output++ = static_cast<Uint16>((input >> 10) + 0xD800);
|
||||
*output++ = static_cast<Uint16>((input & 0x3FFUL) + 0xDC00);
|
||||
*output++ = static_cast<std::uint16_t>((input >> 10) + 0xD800);
|
||||
*output++ = static_cast<std::uint16_t>((input & 0x3FFUL) + 0xDC00);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
@ -57,13 +57,13 @@ bool decode(sf::InputStream& stream, std::int16_t& value)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool decode(sf::InputStream& stream, sf::Uint16& value)
|
||||
bool decode(sf::InputStream& stream, std::uint16_t& value)
|
||||
{
|
||||
unsigned char bytes[sizeof(value)];
|
||||
if (static_cast<std::size_t>(stream.read(bytes, static_cast<sf::Int64>(sizeof(bytes)))) != sizeof(bytes))
|
||||
return false;
|
||||
|
||||
value = static_cast<sf::Uint16>(bytes[0] | (bytes[1] << 8));
|
||||
value = static_cast<std::uint16_t>(bytes[0] | (bytes[1] << 8));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -92,9 +92,9 @@ bool decode(sf::InputStream& stream, sf::Uint32& value)
|
||||
|
||||
const sf::Uint64 mainChunkSize = 12;
|
||||
|
||||
const sf::Uint16 waveFormatPcm = 1;
|
||||
const std::uint16_t waveFormatPcm = 1;
|
||||
|
||||
const sf::Uint16 waveFormatExtensible = 65534;
|
||||
const std::uint16_t waveFormatExtensible = 65534;
|
||||
|
||||
const char* waveSubformatPcm =
|
||||
"\x01\x00\x00\x00\x00\x00\x10\x00"
|
||||
@ -249,14 +249,14 @@ bool SoundFileReaderWav::parseHeader(Info& info)
|
||||
// "fmt" chunk
|
||||
|
||||
// Audio format
|
||||
Uint16 format = 0;
|
||||
std::uint16_t format = 0;
|
||||
if (!decode(*m_stream, format))
|
||||
return false;
|
||||
if ((format != waveFormatPcm) && (format != waveFormatExtensible))
|
||||
return false;
|
||||
|
||||
// Channel count
|
||||
Uint16 channelCount = 0;
|
||||
std::uint16_t channelCount = 0;
|
||||
if (!decode(*m_stream, channelCount))
|
||||
return false;
|
||||
info.channelCount = channelCount;
|
||||
@ -273,12 +273,12 @@ bool SoundFileReaderWav::parseHeader(Info& info)
|
||||
return false;
|
||||
|
||||
// Block align
|
||||
Uint16 blockAlign = 0;
|
||||
std::uint16_t blockAlign = 0;
|
||||
if (!decode(*m_stream, blockAlign))
|
||||
return false;
|
||||
|
||||
// Bits per sample
|
||||
Uint16 bitsPerSample = 0;
|
||||
std::uint16_t bitsPerSample = 0;
|
||||
if (!decode(*m_stream, bitsPerSample))
|
||||
return false;
|
||||
if (bitsPerSample != 8 && bitsPerSample != 16 && bitsPerSample != 24 && bitsPerSample != 32)
|
||||
@ -292,12 +292,12 @@ bool SoundFileReaderWav::parseHeader(Info& info)
|
||||
if (format == waveFormatExtensible)
|
||||
{
|
||||
// Extension size
|
||||
Uint16 extensionSize = 0;
|
||||
std::uint16_t extensionSize = 0;
|
||||
if (!decode(*m_stream, extensionSize))
|
||||
return false;
|
||||
|
||||
// Valid bits per sample
|
||||
Uint16 validBitsPerSample = 0;
|
||||
std::uint16_t validBitsPerSample = 0;
|
||||
if (!decode(*m_stream, validBitsPerSample))
|
||||
return false;
|
||||
|
||||
|
@ -44,7 +44,7 @@ void encode(std::ostream& stream, std::int16_t value)
|
||||
stream.write(reinterpret_cast<const char*>(bytes), sizeof(bytes));
|
||||
}
|
||||
|
||||
void encode(std::ostream& stream, sf::Uint16 value)
|
||||
void encode(std::ostream& stream, std::uint16_t value)
|
||||
{
|
||||
unsigned char bytes[] = {static_cast<unsigned char>(value & 0xFF), static_cast<unsigned char>(value >> 8)};
|
||||
stream.write(reinterpret_cast<const char*>(bytes), sizeof(bytes));
|
||||
@ -139,17 +139,17 @@ bool SoundFileWriterWav::writeHeader(unsigned int sampleRate, unsigned int chann
|
||||
encode(m_file, fmtChunkSize);
|
||||
|
||||
// Write the format (PCM)
|
||||
Uint16 format = 1;
|
||||
std::uint16_t format = 1;
|
||||
encode(m_file, format);
|
||||
|
||||
// Write the sound attributes
|
||||
encode(m_file, static_cast<Uint16>(channelCount));
|
||||
encode(m_file, static_cast<std::uint16_t>(channelCount));
|
||||
encode(m_file, sampleRate);
|
||||
Uint32 byteRate = sampleRate * channelCount * 2;
|
||||
encode(m_file, byteRate);
|
||||
auto blockAlign = static_cast<Uint16>(channelCount * 2);
|
||||
auto blockAlign = static_cast<std::uint16_t>(channelCount * 2);
|
||||
encode(m_file, blockAlign);
|
||||
Uint16 bitsPerSample = 16;
|
||||
std::uint16_t bitsPerSample = 16;
|
||||
encode(m_file, bitsPerSample);
|
||||
|
||||
// Write the sub-chunk 2 ("data") id and size
|
||||
|
@ -160,7 +160,7 @@ Packet& Packet::operator>>(std::int16_t& data)
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
std::memcpy(&data, &m_data[m_readPos], sizeof(data));
|
||||
data = static_cast<std::int16_t>(ntohs(static_cast<uint16_t>(data)));
|
||||
data = static_cast<std::int16_t>(ntohs(static_cast<std::uint16_t>(data)));
|
||||
m_readPos += sizeof(data);
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ Packet& Packet::operator>>(std::int16_t& data)
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator>>(Uint16& data)
|
||||
Packet& Packet::operator>>(std::uint16_t& data)
|
||||
{
|
||||
if (checkSize(sizeof(data)))
|
||||
{
|
||||
@ -418,16 +418,16 @@ Packet& Packet::operator<<(std::uint8_t data)
|
||||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator<<(std::int16_t data)
|
||||
{
|
||||
auto toWrite = static_cast<std::int16_t>(htons(static_cast<uint16_t>(data)));
|
||||
auto toWrite = static_cast<std::int16_t>(htons(static_cast<std::uint16_t>(data)));
|
||||
append(&toWrite, sizeof(toWrite));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Packet& Packet::operator<<(Uint16 data)
|
||||
Packet& Packet::operator<<(std::uint16_t data)
|
||||
{
|
||||
Uint16 toWrite = htons(data);
|
||||
std::uint16_t toWrite = htons(data);
|
||||
append(&toWrite, sizeof(toWrite));
|
||||
return *this;
|
||||
}
|
||||
|
@ -196,10 +196,10 @@ std::basic_string<std::uint8_t> String::toUtf8() const
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::basic_string<Uint16> String::toUtf16() const
|
||||
std::basic_string<std::uint16_t> String::toUtf16() const
|
||||
{
|
||||
// Prepare the output string
|
||||
std::basic_string<Uint16> output;
|
||||
std::basic_string<std::uint16_t> output;
|
||||
output.reserve(m_string.length());
|
||||
|
||||
// Convert
|
||||
|
@ -718,7 +718,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if ((character >= 0xD800) && (character <= 0xDBFF))
|
||||
{
|
||||
// First part of a surrogate pair: store it and wait for the second one
|
||||
m_surrogate = static_cast<Uint16>(character);
|
||||
m_surrogate = static_cast<std::uint16_t>(character);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -726,7 +726,7 @@ void WindowImplWin32::processEvent(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if ((character >= 0xDC00) && (character <= 0xDFFF))
|
||||
{
|
||||
// Convert the UTF-16 surrogate pair to a single UTF-32 value
|
||||
Uint16 utf16[] = {m_surrogate, static_cast<Uint16>(character)};
|
||||
std::uint16_t utf16[] = {m_surrogate, static_cast<std::uint16_t>(character)};
|
||||
sf::Utf16::toUtf32(utf16, utf16 + 2, &character);
|
||||
m_surrogate = 0;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ private:
|
||||
bool m_keyRepeatEnabled; //!< Automatic key-repeat state for keydown events
|
||||
Vector2u m_lastSize; //!< The last handled size of the window
|
||||
bool m_resizing; //!< Is the window being resized?
|
||||
Uint16 m_surrogate; //!< First half of the surrogate pair, in case we're receiving a Unicode character in two events
|
||||
std::uint16_t m_surrogate; //!< First half of the surrogate pair, in case we're receiving a Unicode character in two events
|
||||
bool m_mouseInside; //!< Mouse is inside the window?
|
||||
bool m_fullscreen; //!< Is the window fullscreen?
|
||||
bool m_cursorGrabbed; //!< Is the mouse cursor trapped?
|
||||
|
@ -14,8 +14,6 @@ TEST_CASE("SFML/Config.hpp")
|
||||
|
||||
SUBCASE("Fixed width types")
|
||||
{
|
||||
CHECK(sizeof(sf::Uint16) == 2);
|
||||
|
||||
CHECK(sizeof(sf::Int32) == 4);
|
||||
CHECK(sizeof(sf::Uint32) == 4);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user