mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Remove unnecessary static casts
This commit is contained in:
parent
3f38738a08
commit
5484824948
@ -474,8 +474,8 @@ void processWorkItem(std::vector<sf::Vertex>& vertices, const WorkItem& workItem
|
|||||||
const unsigned int rowEnd = std::min(rowStart + rowBlockSize, resolutionY);
|
const unsigned int rowEnd = std::min(rowStart + rowBlockSize, resolutionY);
|
||||||
const unsigned int rowCount = rowEnd - rowStart;
|
const unsigned int rowCount = rowEnd - rowStart;
|
||||||
|
|
||||||
const float scalingFactorX = static_cast<float>(windowWidth) / static_cast<float>(resolutionX);
|
const float scalingFactorX = float{windowWidth} / float{resolutionX};
|
||||||
const float scalingFactorY = static_cast<float>(windowHeight) / static_cast<float>(resolutionY);
|
const float scalingFactorY = float{windowHeight} / float{resolutionY};
|
||||||
|
|
||||||
for (unsigned int y = rowStart; y < rowEnd; ++y)
|
for (unsigned int y = rowStart; y < rowEnd; ++y)
|
||||||
{
|
{
|
||||||
|
@ -494,7 +494,7 @@ private:
|
|||||||
|
|
||||||
static constexpr unsigned int sampleRate{44100};
|
static constexpr unsigned int sampleRate{44100};
|
||||||
static constexpr std::size_t chunkSize{sampleRate / 100};
|
static constexpr std::size_t chunkSize{sampleRate / 100};
|
||||||
static constexpr float timePerSample{1.f / static_cast<float>(sampleRate)};
|
static constexpr float timePerSample{1.f / float{sampleRate}};
|
||||||
|
|
||||||
std::vector<std::int16_t> m_sampleBuffer = std::vector<std::int16_t>(chunkSize, 0);
|
std::vector<std::int16_t> m_sampleBuffer = std::vector<std::int16_t>(chunkSize, 0);
|
||||||
Type m_type{Type::Triangle};
|
Type m_type{Type::Triangle};
|
||||||
@ -600,7 +600,7 @@ private:
|
|||||||
|
|
||||||
static constexpr unsigned int sampleRate{44100};
|
static constexpr unsigned int sampleRate{44100};
|
||||||
static constexpr std::size_t chunkSize{sampleRate / 100};
|
static constexpr std::size_t chunkSize{sampleRate / 100};
|
||||||
static constexpr float timePerSample{1.f / static_cast<float>(sampleRate)};
|
static constexpr float timePerSample{1.f / float{sampleRate}};
|
||||||
|
|
||||||
std::vector<std::int16_t> m_sampleBuffer = std::vector<std::int16_t>(chunkSize, 0);
|
std::vector<std::int16_t> m_sampleBuffer = std::vector<std::int16_t>(chunkSize, 0);
|
||||||
float m_amplitude{0.05f};
|
float m_amplitude{0.05f};
|
||||||
|
@ -227,7 +227,7 @@ std::optional<std::uint64_t> Music::onLoop()
|
|||||||
// Looping is enabled, and either we're at the loop end, or we're at the EOF
|
// Looping is enabled, and either we're at the loop end, or we're at the EOF
|
||||||
// when it's equivalent to the loop end (loop end takes priority). Send us to loop begin
|
// when it's equivalent to the loop end (loop end takes priority). Send us to loop begin
|
||||||
m_file->seek(m_loopSpan.offset);
|
m_file->seek(m_loopSpan.offset);
|
||||||
return static_cast<std::int64_t>(m_file->getSampleOffset());
|
return m_file->getSampleOffset();
|
||||||
}
|
}
|
||||||
else if (getLoop() && (currentOffset >= m_file->getSampleCount()))
|
else if (getLoop() && (currentOffset >= m_file->getSampleCount()))
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ void SoundFileReaderMp3::seek(std::uint64_t sampleOffset)
|
|||||||
std::uint64_t SoundFileReaderMp3::read(std::int16_t* samples, std::uint64_t maxCount)
|
std::uint64_t SoundFileReaderMp3::read(std::int16_t* samples, std::uint64_t maxCount)
|
||||||
{
|
{
|
||||||
std::uint64_t toRead = std::min(maxCount, m_numSamples - m_position);
|
std::uint64_t toRead = std::min(maxCount, m_numSamples - m_position);
|
||||||
toRead = static_cast<std::uint64_t>(mp3dec_ex_read(&m_decoder, samples, static_cast<std::size_t>(toRead)));
|
toRead = std::uint64_t{mp3dec_ex_read(&m_decoder, samples, static_cast<std::size_t>(toRead))};
|
||||||
m_position += toRead;
|
m_position += toRead;
|
||||||
return toRead;
|
return toRead;
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ void SoundFileWriterWav::writeHeader(unsigned int sampleRate, unsigned int chann
|
|||||||
m_file.write(mainChunkId.data(), mainChunkId.size());
|
m_file.write(mainChunkId.data(), mainChunkId.size());
|
||||||
|
|
||||||
// Write the main chunk header
|
// Write the main chunk header
|
||||||
encode(m_file, static_cast<std::uint32_t>(0)); // 0 is a placeholder, will be written later
|
encode(m_file, std::uint32_t{0}); // 0 is a placeholder, will be written later
|
||||||
std::array mainChunkFormat = {'W', 'A', 'V', 'E'};
|
std::array mainChunkFormat = {'W', 'A', 'V', 'E'};
|
||||||
m_file.write(mainChunkFormat.data(), mainChunkFormat.size());
|
m_file.write(mainChunkFormat.data(), mainChunkFormat.size());
|
||||||
|
|
||||||
|
@ -84,8 +84,7 @@ inline T reinterpret(const U& input)
|
|||||||
// Combine outline thickness, boldness and font glyph index into a single 64-bit key
|
// Combine outline thickness, boldness and font glyph index into a single 64-bit key
|
||||||
std::uint64_t combine(float outlineThickness, bool bold, std::uint32_t index)
|
std::uint64_t combine(float outlineThickness, bool bold, std::uint32_t index)
|
||||||
{
|
{
|
||||||
return (static_cast<std::uint64_t>(reinterpret<std::uint32_t>(outlineThickness)) << 32) |
|
return (std::uint64_t{reinterpret<std::uint32_t>(outlineThickness)} << 32) | (std::uint64_t{bold} << 31) | index;
|
||||||
(static_cast<std::uint64_t>(bold) << 31) | index;
|
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -365,8 +364,7 @@ float Font::getKerning(std::uint32_t first, std::uint32_t second, unsigned int c
|
|||||||
|
|
||||||
// Combine kerning with compensation deltas and return the X advance
|
// Combine kerning with compensation deltas and return the X advance
|
||||||
// Flooring is required as we use FT_KERNING_UNFITTED flag which is not quantized in 64 based grid
|
// Flooring is required as we use FT_KERNING_UNFITTED flag which is not quantized in 64 based grid
|
||||||
return std::floor(
|
return std::floor((secondLsbDelta - firstRsbDelta + static_cast<float>(kerning.x) + 32) / float{1 << 6});
|
||||||
(secondLsbDelta - firstRsbDelta + static_cast<float>(kerning.x) + 32) / static_cast<float>(1 << 6));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -385,7 +383,7 @@ float Font::getLineSpacing(unsigned int characterSize) const
|
|||||||
|
|
||||||
if (setCurrentSize(characterSize))
|
if (setCurrentSize(characterSize))
|
||||||
{
|
{
|
||||||
return static_cast<float>(face->size->metrics.height) / static_cast<float>(1 << 6);
|
return static_cast<float>(face->size->metrics.height) / float{1 << 6};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -407,8 +405,7 @@ float Font::getUnderlinePosition(unsigned int characterSize) const
|
|||||||
if (!FT_IS_SCALABLE(face))
|
if (!FT_IS_SCALABLE(face))
|
||||||
return static_cast<float>(characterSize) / 10.f;
|
return static_cast<float>(characterSize) / 10.f;
|
||||||
|
|
||||||
return -static_cast<float>(FT_MulFix(face->underline_position, face->size->metrics.y_scale)) /
|
return -static_cast<float>(FT_MulFix(face->underline_position, face->size->metrics.y_scale)) / float{1 << 6};
|
||||||
static_cast<float>(1 << 6);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -430,8 +427,7 @@ float Font::getUnderlineThickness(unsigned int characterSize) const
|
|||||||
if (!FT_IS_SCALABLE(face))
|
if (!FT_IS_SCALABLE(face))
|
||||||
return static_cast<float>(characterSize) / 14.f;
|
return static_cast<float>(characterSize) / 14.f;
|
||||||
|
|
||||||
return static_cast<float>(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)) /
|
return static_cast<float>(FT_MulFix(face->underline_thickness, face->size->metrics.y_scale)) / float{1 << 6};
|
||||||
static_cast<float>(1 << 6);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -519,7 +515,7 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool
|
|||||||
FT_Stroker stroker = m_fontHandles->stroker;
|
FT_Stroker stroker = m_fontHandles->stroker;
|
||||||
|
|
||||||
FT_Stroker_Set(stroker,
|
FT_Stroker_Set(stroker,
|
||||||
static_cast<FT_Fixed>(outlineThickness * static_cast<float>(1 << 6)),
|
static_cast<FT_Fixed>(outlineThickness * float{1 << 6}),
|
||||||
FT_STROKER_LINECAP_ROUND,
|
FT_STROKER_LINECAP_ROUND,
|
||||||
FT_STROKER_LINEJOIN_ROUND,
|
FT_STROKER_LINEJOIN_ROUND,
|
||||||
0);
|
0);
|
||||||
@ -547,7 +543,7 @@ Glyph Font::loadGlyph(std::uint32_t codePoint, unsigned int characterSize, bool
|
|||||||
// Compute the glyph's advance offset
|
// Compute the glyph's advance offset
|
||||||
glyph.advance = static_cast<float>(bitmapGlyph->root.advance.x >> 16);
|
glyph.advance = static_cast<float>(bitmapGlyph->root.advance.x >> 16);
|
||||||
if (bold)
|
if (bold)
|
||||||
glyph.advance += static_cast<float>(weight) / static_cast<float>(1 << 6);
|
glyph.advance += static_cast<float>(weight) / float{1 << 6};
|
||||||
|
|
||||||
glyph.lsbDelta = static_cast<int>(face->glyph->lsb_delta);
|
glyph.lsbDelta = static_cast<int>(face->glyph->lsb_delta);
|
||||||
glyph.rsbDelta = static_cast<int>(face->glyph->rsb_delta);
|
glyph.rsbDelta = static_cast<int>(face->glyph->rsb_delta);
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
CHECK(packet.getData() != nullptr); \
|
CHECK(packet.getData() != nullptr); \
|
||||||
CHECK(packet.getDataSize() == sizeof(expected)); \
|
CHECK(packet.getDataSize() == sizeof(expected)); \
|
||||||
CHECK(!packet.endOfPacket()); \
|
CHECK(!packet.endOfPacket()); \
|
||||||
CHECK(static_cast<bool>(packet)); \
|
CHECK(bool{packet}); \
|
||||||
\
|
\
|
||||||
decltype(expected) received; \
|
decltype(expected) received; \
|
||||||
packet >> received; \
|
packet >> received; \
|
||||||
@ -30,7 +30,7 @@
|
|||||||
CHECK(packet.getData() != nullptr); \
|
CHECK(packet.getData() != nullptr); \
|
||||||
CHECK(packet.getDataSize() == sizeof(expected)); \
|
CHECK(packet.getDataSize() == sizeof(expected)); \
|
||||||
CHECK(packet.endOfPacket()); \
|
CHECK(packet.endOfPacket()); \
|
||||||
CHECK(static_cast<bool>(packet)); \
|
CHECK(bool{packet}); \
|
||||||
CHECK((expected) == received); \
|
CHECK((expected) == received); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
@ -43,7 +43,7 @@
|
|||||||
CHECK(packet.getData() != nullptr); \
|
CHECK(packet.getData() != nullptr); \
|
||||||
CHECK(packet.getDataSize() == (size)); \
|
CHECK(packet.getDataSize() == (size)); \
|
||||||
CHECK(!packet.endOfPacket()); \
|
CHECK(!packet.endOfPacket()); \
|
||||||
CHECK(static_cast<bool>(packet)); \
|
CHECK(bool{packet}); \
|
||||||
\
|
\
|
||||||
std::remove_const_t<decltype(expected)> received; \
|
std::remove_const_t<decltype(expected)> received; \
|
||||||
packet >> received; \
|
packet >> received; \
|
||||||
@ -51,7 +51,7 @@
|
|||||||
CHECK(packet.getData() != nullptr); \
|
CHECK(packet.getData() != nullptr); \
|
||||||
CHECK(packet.getDataSize() == (size)); \
|
CHECK(packet.getDataSize() == (size)); \
|
||||||
CHECK(packet.endOfPacket()); \
|
CHECK(packet.endOfPacket()); \
|
||||||
CHECK(static_cast<bool>(packet)); \
|
CHECK(bool{packet}); \
|
||||||
CHECK(sf::String(expected) == sf::String(received)); \
|
CHECK(sf::String(expected) == sf::String(received)); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ TEST_CASE("[Network] sf::Packet")
|
|||||||
CHECK(packet.getData() == nullptr);
|
CHECK(packet.getData() == nullptr);
|
||||||
CHECK(packet.getDataSize() == 0);
|
CHECK(packet.getDataSize() == 0);
|
||||||
CHECK(packet.endOfPacket());
|
CHECK(packet.endOfPacket());
|
||||||
CHECK(static_cast<bool>(packet));
|
CHECK(bool{packet});
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr std::array data = {1, 2, 3, 4, 5, 6};
|
static constexpr std::array data = {1, 2, 3, 4, 5, 6};
|
||||||
@ -91,14 +91,14 @@ TEST_CASE("[Network] sf::Packet")
|
|||||||
CHECK(packet.getData() != nullptr);
|
CHECK(packet.getData() != nullptr);
|
||||||
CHECK(packet.getDataSize() == data.size());
|
CHECK(packet.getDataSize() == data.size());
|
||||||
CHECK(!packet.endOfPacket());
|
CHECK(!packet.endOfPacket());
|
||||||
CHECK(static_cast<bool>(packet));
|
CHECK(bool{packet});
|
||||||
|
|
||||||
packet.clear();
|
packet.clear();
|
||||||
CHECK(packet.getReadPosition() == 0);
|
CHECK(packet.getReadPosition() == 0);
|
||||||
CHECK(packet.getData() == nullptr);
|
CHECK(packet.getData() == nullptr);
|
||||||
CHECK(packet.getDataSize() == 0);
|
CHECK(packet.getDataSize() == 0);
|
||||||
CHECK(packet.endOfPacket());
|
CHECK(packet.endOfPacket());
|
||||||
CHECK(static_cast<bool>(packet));
|
CHECK(bool{packet});
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Network ordering")
|
SECTION("Network ordering")
|
||||||
|
@ -26,11 +26,10 @@ auto select(const std::basic_string<T>& string16, const std::basic_string<T>& st
|
|||||||
return string32;
|
return string32;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename CharT>
|
auto toHex(const std::uint32_t character)
|
||||||
auto toHex(const CharT character)
|
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "[\\x" << std::uppercase << std::hex << static_cast<std::uint32_t>(character) << ']';
|
stream << "[\\x" << std::uppercase << std::hex << character << ']';
|
||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -243,7 +243,7 @@ TEST_CASE("[System] sf::Time")
|
|||||||
SECTION("operator*=")
|
SECTION("operator*=")
|
||||||
{
|
{
|
||||||
sf::Time time = sf::milliseconds(1'000);
|
sf::Time time = sf::milliseconds(1'000);
|
||||||
time *= static_cast<std::int64_t>(10);
|
time *= std::int64_t{10};
|
||||||
CHECK(time == sf::milliseconds(10'000));
|
CHECK(time == sf::milliseconds(10'000));
|
||||||
time *= 0.1f;
|
time *= 0.1f;
|
||||||
CHECK(time.asMilliseconds() == 1'000);
|
CHECK(time.asMilliseconds() == 1'000);
|
||||||
@ -262,7 +262,7 @@ TEST_CASE("[System] sf::Time")
|
|||||||
SECTION("operator/=")
|
SECTION("operator/=")
|
||||||
{
|
{
|
||||||
sf::Time time = sf::milliseconds(1'000);
|
sf::Time time = sf::milliseconds(1'000);
|
||||||
time /= static_cast<std::int64_t>(2);
|
time /= std::int64_t{2};
|
||||||
CHECK(time == sf::milliseconds(500));
|
CHECK(time == sf::milliseconds(500));
|
||||||
time /= 0.5f;
|
time /= 0.5f;
|
||||||
CHECK(time.asMilliseconds() == 1'000);
|
CHECK(time.asMilliseconds() == 1'000);
|
||||||
|
@ -62,7 +62,7 @@ template std::ostream& operator<<(std::ostream&, const Vector3<float>&);
|
|||||||
|
|
||||||
bool operator==(const float& lhs, const Approx<float>& rhs)
|
bool operator==(const float& lhs, const Approx<float>& rhs)
|
||||||
{
|
{
|
||||||
return static_cast<double>(lhs) == Catch::Approx(static_cast<double>(rhs.value)).margin(1e-5);
|
return lhs == Catch::Approx(rhs.value).margin(1e-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const sf::Vector2f& lhs, const Approx<sf::Vector2f>& rhs)
|
bool operator==(const sf::Vector2f& lhs, const Approx<sf::Vector2f>& rhs)
|
||||||
|
Loading…
Reference in New Issue
Block a user