mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Remove unnecessary casts
This commit is contained in:
parent
b2009e2fca
commit
badb388507
@ -73,7 +73,7 @@ constexpr Color operator+(const Color& left, const Color& right)
|
|||||||
{
|
{
|
||||||
const auto clampedAdd = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
|
const auto clampedAdd = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
|
||||||
{
|
{
|
||||||
const int intResult = static_cast<int>(lhs) + static_cast<int>(rhs);
|
const int intResult = int{lhs} + int{rhs};
|
||||||
return static_cast<std::uint8_t>(intResult < 255 ? intResult : 255);
|
return static_cast<std::uint8_t>(intResult < 255 ? intResult : 255);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ constexpr Color operator-(const Color& left, const Color& right)
|
|||||||
{
|
{
|
||||||
const auto clampedSub = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
|
const auto clampedSub = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
|
||||||
{
|
{
|
||||||
const int intResult = static_cast<int>(lhs) - static_cast<int>(rhs);
|
const int intResult = int{lhs} - int{rhs};
|
||||||
return static_cast<std::uint8_t>(intResult > 0 ? intResult : 0);
|
return static_cast<std::uint8_t>(intResult > 0 ? intResult : 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,8 +105,7 @@ 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 scaledMul = [](std::uint8_t lhs, std::uint8_t rhs) -> std::uint8_t
|
||||||
{
|
{
|
||||||
const auto uint16Result = static_cast<std::uint16_t>(
|
const auto uint16Result = static_cast<std::uint16_t>(std::uint16_t{lhs} * std::uint16_t{rhs});
|
||||||
static_cast<std::uint16_t>(lhs) * static_cast<std::uint16_t>(rhs));
|
|
||||||
return static_cast<std::uint8_t>(uint16Result / 255u);
|
return static_cast<std::uint8_t>(uint16Result / 255u);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ void Music::initialize()
|
|||||||
m_loopSpan.length = m_file.getSampleCount();
|
m_loopSpan.length = m_file.getSampleCount();
|
||||||
|
|
||||||
// Resize the internal buffer so that it can contain 1 second of audio samples
|
// Resize the internal buffer so that it can contain 1 second of audio samples
|
||||||
m_samples.resize(static_cast<std::size_t>(m_file.getSampleRate()) * static_cast<std::size_t>(m_file.getChannelCount()));
|
m_samples.resize(m_file.getSampleRate() * m_file.getChannelCount());
|
||||||
|
|
||||||
// Initialize the stream
|
// Initialize the stream
|
||||||
SoundStream::initialize(m_file.getChannelCount(), m_file.getSampleRate());
|
SoundStream::initialize(m_file.getChannelCount(), m_file.getSampleRate());
|
||||||
|
@ -331,7 +331,7 @@ Image Texture::copyToImage() const
|
|||||||
priv::TextureSaver save;
|
priv::TextureSaver save;
|
||||||
|
|
||||||
// Create an array of pixels
|
// Create an array of pixels
|
||||||
std::vector<std::uint8_t> pixels(static_cast<std::size_t>(m_size.x) * static_cast<std::size_t>(m_size.y) * 4);
|
std::vector<std::uint8_t> pixels(m_size.x * m_size.y * 4);
|
||||||
|
|
||||||
#ifdef SFML_OPENGL_ES
|
#ifdef SFML_OPENGL_ES
|
||||||
|
|
||||||
@ -365,8 +365,7 @@ Image Texture::copyToImage() const
|
|||||||
// Texture is either padded or flipped, we have to use a slower algorithm
|
// Texture is either padded or flipped, we have to use a slower algorithm
|
||||||
|
|
||||||
// All the pixels will first be copied to a temporary array
|
// All the pixels will first be copied to a temporary array
|
||||||
std::vector<std::uint8_t> allPixels(
|
std::vector<std::uint8_t> allPixels(m_actualSize.x * m_actualSize.y * 4);
|
||||||
static_cast<std::size_t>(m_actualSize.x) * static_cast<std::size_t>(m_actualSize.y) * 4);
|
|
||||||
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
glCheck(glBindTexture(GL_TEXTURE_2D, m_texture));
|
||||||
glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, allPixels.data()));
|
glCheck(glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, allPixels.data()));
|
||||||
|
|
||||||
|
@ -16,9 +16,8 @@ std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode)
|
|||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Color& color)
|
std::ostream& operator<<(std::ostream& os, const Color& color)
|
||||||
{
|
{
|
||||||
return os << "0x" << std::hex << color.toInteger() << std::dec << " (r=" << static_cast<int>(color.r)
|
return os << "0x" << std::hex << color.toInteger() << std::dec << " (r=" << int{color.r} << ", g=" << int{color.g}
|
||||||
<< ", g=" << static_cast<int>(color.g) << ", b=" << static_cast<int>(color.b)
|
<< ", b=" << int{color.b} << ", a=" << int{color.a} << ")";
|
||||||
<< ", a=" << static_cast<int>(color.a) << ")";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const Transform& transform)
|
std::ostream& operator<<(std::ostream& os, const Transform& transform)
|
||||||
|
Loading…
Reference in New Issue
Block a user