Skip to content

Commit

Permalink
Update ElasticSprite Code Style
Browse files Browse the repository at this point in the history
updates Elastic Sprite's code style, including using constexpr where possible.
  • Loading branch information
Hapaxia committed Feb 20, 2025
1 parent 081f94a commit 17942d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
32 changes: 16 additions & 16 deletions src/SelbaWard/ElasticSprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
namespace
{

const sf::PrimitiveType primitiveType{ sf::PrimitiveType::TriangleFan };
constexpr sf::PrimitiveType primitiveType{ sf::PrimitiveType::TriangleFan };
bool areShadersLoaded{ false };
sf::Shader bilinearShader;
sf::Shader perspectiveShader;
Expand Down Expand Up @@ -153,9 +153,9 @@ ElasticSprite::ElasticSprite()
, m_weights(0u)
, m_offsets(4u)
, m_pTexture{ nullptr }
, m_baseTextureRect()
, m_actualTextureRect()
, m_useShader(sf::Shader::isAvailable())
, m_baseTextureRect{}
, m_actualTextureRect{}
, m_useShader{ sf::Shader::isAvailable() }
, m_usePerspectiveInterpolation{ false }
, m_textureFlipX{ false }
, m_textureFlipY{ false }
Expand Down Expand Up @@ -266,7 +266,7 @@ bool ElasticSprite::isActivePerspectiveInterpolation() const
return m_usePerspectiveInterpolation;
}

void ElasticSprite::setVertexOffset(const unsigned int vertexIndex, const sf::Vector2f offset)
void ElasticSprite::setVertexOffset(const std::size_t vertexIndex, const sf::Vector2f offset)
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));
Expand All @@ -275,7 +275,7 @@ void ElasticSprite::setVertexOffset(const unsigned int vertexIndex, const sf::Ve
m_requiresVerticesUpdate = true;
}

sf::Vector2f ElasticSprite::getVertexOffset(const unsigned int vertexIndex) const
sf::Vector2f ElasticSprite::getVertexOffset(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));
Expand All @@ -290,7 +290,7 @@ void ElasticSprite::setColor(const sf::Color color)
m_requiresVerticesUpdate = true;
}

void ElasticSprite::setVertexColor(const unsigned int vertexIndex, const sf::Color color)
void ElasticSprite::setVertexColor(const std::size_t vertexIndex, const sf::Color color)
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));
Expand All @@ -308,7 +308,7 @@ sf::Color ElasticSprite::getColor() const
return{ static_cast<uint8_t>(totalR / 4), static_cast<uint8_t>(totalG / 4), static_cast<uint8_t>(totalB / 4), static_cast<uint8_t>(totalA / 4) };
}

sf::Color ElasticSprite::getVertexColor(const unsigned int vertexIndex) const
sf::Color ElasticSprite::getVertexColor(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));
Expand All @@ -324,31 +324,31 @@ void ElasticSprite::resetVertexOffsets()
setVertexOffset(3, { 0.f, 0.f });
}

sf::Vector2f ElasticSprite::getVertexLocalPosition(const unsigned int vertexIndex) const
sf::Vector2f ElasticSprite::getVertexLocalPosition(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));

return getTransform().transformPoint(priv_getVertexBasePosition(vertexIndex) + m_offsets[vertexIndex]);
}

sf::Vector2f ElasticSprite::getVertexBaseLocalPosition(const unsigned int vertexIndex) const
sf::Vector2f ElasticSprite::getVertexBaseLocalPosition(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));

return getTransform().transformPoint(priv_getVertexBasePosition(vertexIndex));
}

sf::Vector2f ElasticSprite::getVertexGlobalPosition(const unsigned int vertexIndex) const
sf::Vector2f ElasticSprite::getVertexGlobalPosition(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));

return getTransform().transformPoint(priv_getVertexBasePosition(vertexIndex) + m_offsets[vertexIndex]);
}

sf::Vector2f ElasticSprite::getVertexBaseGlobalPosition(const unsigned int vertexIndex) const
sf::Vector2f ElasticSprite::getVertexBaseGlobalPosition(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));
Expand Down Expand Up @@ -528,19 +528,19 @@ void ElasticSprite::priv_updateVertices(sf::Transform transform) const
}
}

sf::Vector2f ElasticSprite::priv_getVertexBasePosition(const unsigned int vertexIndex) const
sf::Vector2f ElasticSprite::priv_getVertexBasePosition(const std::size_t vertexIndex) const
{
// must be valid vertex index
assert(isValidVertexIndex(vertexIndex));

switch (vertexIndex)
{
case 1u:
return sf::Vector2f(0.f, m_baseTextureRect.size.y);
return { 0.f, m_baseTextureRect.size.y };
case 2u:
return sf::Vector2f(m_baseTextureRect.size.x, m_baseTextureRect.size.y);
return { m_baseTextureRect.size.x, m_baseTextureRect.size.y };
case 3u:
return sf::Vector2f(m_baseTextureRect.size.x, 0.f);
return { m_baseTextureRect.size.x, 0.f };
case 0u:
default:
return { 0.f, 0.f };
Expand Down
18 changes: 9 additions & 9 deletions src/SelbaWard/ElasticSprite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ class ElasticSprite : public sf::Drawable, public sf::Transformable
bool isActivePerspectiveInterpolation() const;

void setColor(sf::Color color);
void setVertexColor(unsigned int vertexIndex, sf::Color color);
void setVertexColor(std::size_t vertexIndex, sf::Color color);
sf::Color getColor() const; // returns the average of all four vertices' colours
sf::Color getVertexColor(unsigned int vertexIndex) const;
sf::Color getVertexColor(std::size_t vertexIndex) const;

void resetVertexOffsets();
void setVertexOffset(unsigned int vertexIndex, sf::Vector2f offset);
sf::Vector2f getVertexOffset(unsigned int vertexIndex) const;
void setVertexOffset(std::size_t vertexIndex, sf::Vector2f offset);
sf::Vector2f getVertexOffset(std::size_t vertexIndex) const;

sf::Vector2f getVertexLocalPosition(unsigned int vertexIndex) const;
sf::Vector2f getVertexBaseLocalPosition(unsigned int vertexIndex) const;
sf::Vector2f getVertexGlobalPosition(unsigned int vertexIndex) const;
sf::Vector2f getVertexBaseGlobalPosition(unsigned int vertexIndex) const;
sf::Vector2f getVertexLocalPosition(std::size_t vertexIndex) const;
sf::Vector2f getVertexBaseLocalPosition(std::size_t vertexIndex) const;
sf::Vector2f getVertexGlobalPosition(std::size_t vertexIndex) const;
sf::Vector2f getVertexBaseGlobalPosition(std::size_t vertexIndex) const;

sf::FloatRect getLocalBounds() const;
sf::FloatRect getBaseLocalBounds() const;
Expand All @@ -112,7 +112,7 @@ class ElasticSprite : public sf::Drawable, public sf::Transformable

void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
void priv_updateVertices(sf::Transform Transform) const;
sf::Vector2f priv_getVertexBasePosition(const unsigned int vertexIndex) const;
sf::Vector2f priv_getVertexBasePosition(const std::size_t vertexIndex) const;
};

} // namespace selbaward
Expand Down

0 comments on commit 17942d0

Please sign in to comment.