Skip to content

Commit

Permalink
Stop leaving variables unused in release builds
Browse files Browse the repository at this point in the history
In a Release build, macros like `CSFML_CHECK_RETURN` expand into
nothing more than a cast-to-void which is meant to silence compiler
warnings about unused variables.

By declaring a temporary inside the macro argument, we ensure that
debug builds behave the same as always but Release builds expand
these macros into truly no code thus ensuring these temporary
variables are never created in the first place so there is now
nothing that we have to cast to void.
  • Loading branch information
ChrisThrasher committed Aug 27, 2024
1 parent 513a6c2 commit 10685c7
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 172 deletions.
3 changes: 1 addition & 2 deletions src/CSFML/Audio/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ float sfMusic_getVolume(const sfMusic* music)
////////////////////////////////////////////////////////////
sfVector3f sfMusic_getPosition(const sfMusic* music)
{
sfVector3f position = {0, 0, 0};
CSFML_CHECK_RETURN(music, position);
CSFML_CHECK_RETURN(music, {});

return convertVector3(music->This.getPosition());
}
Expand Down
3 changes: 1 addition & 2 deletions src/CSFML/Audio/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ float sfSound_getVolume(const sfSound* sound)
////////////////////////////////////////////////////////////
sfVector3f sfSound_getPosition(const sfSound* sound)
{
sfVector3f position = {0, 0, 0};
CSFML_CHECK_RETURN(sound, position);
CSFML_CHECK_RETURN(sound, {});

return convertVector3(sound->This.getPosition());
}
Expand Down
3 changes: 1 addition & 2 deletions src/CSFML/Audio/SoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ float sfSoundStream_getVolume(const sfSoundStream* soundStream)
////////////////////////////////////////////////////////////
sfVector3f sfSoundStream_getPosition(const sfSoundStream* soundStream)
{
sfVector3f position = {0, 0, 0};
CSFML_CHECK_RETURN(soundStream, position);
CSFML_CHECK_RETURN(soundStream, {});

return convertVector3(soundStream->This.getPosition());
}
Expand Down
27 changes: 9 additions & 18 deletions src/CSFML/Graphics/CircleShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ void sfCircleShape_setOrigin(sfCircleShape* shape, sfVector2f origin)
////////////////////////////////////////////////////////////
sfVector2f sfCircleShape_getPosition(const sfCircleShape* shape)
{
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(shape, position);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getPosition());
}
Expand All @@ -109,8 +108,7 @@ float sfCircleShape_getRotation(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfCircleShape_getScale(const sfCircleShape* shape)
{
sfVector2f scale = {0, 0};
CSFML_CHECK_RETURN(shape, scale);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getScale());
}
Expand All @@ -119,8 +117,7 @@ sfVector2f sfCircleShape_getScale(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfCircleShape_getOrigin(const sfCircleShape* shape)
{
sfVector2f origin = {0, 0};
CSFML_CHECK_RETURN(shape, origin);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getOrigin());
}
Expand Down Expand Up @@ -215,8 +212,7 @@ const sfTexture* sfCircleShape_getTexture(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfCircleShape_getTextureRect(const sfCircleShape* shape)
{
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getTextureRect());
}
Expand All @@ -225,8 +221,7 @@ sfIntRect sfCircleShape_getTextureRect(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfColor sfCircleShape_getFillColor(const sfCircleShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
CSFML_CHECK_RETURN(shape, {});

return convertColor(shape->This.getFillColor());
}
Expand All @@ -235,8 +230,7 @@ sfColor sfCircleShape_getFillColor(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfColor sfCircleShape_getOutlineColor(const sfCircleShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
CSFML_CHECK_RETURN(shape, {});

return convertColor(shape->This.getOutlineColor());
}
Expand All @@ -259,8 +253,7 @@ size_t sfCircleShape_getPointCount(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfCircleShape_getPoint(const sfCircleShape* shape, size_t index)
{
sfVector2f point = {0, 0};
CSFML_CHECK_RETURN(shape, point);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getPoint(index));
}
Expand Down Expand Up @@ -290,8 +283,7 @@ void sfCircleShape_setPointCount(sfCircleShape* shape, size_t count)
////////////////////////////////////////////////////////////
sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
{
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getLocalBounds());
}
Expand All @@ -300,8 +292,7 @@ sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfCircleShape_getGlobalBounds(const sfCircleShape* shape)
{
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getGlobalBounds());
}
27 changes: 9 additions & 18 deletions src/CSFML/Graphics/ConvexShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ void sfConvexShape_setOrigin(sfConvexShape* shape, sfVector2f origin)
////////////////////////////////////////////////////////////
sfVector2f sfConvexShape_getPosition(const sfConvexShape* shape)
{
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(shape, position);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getPosition());
}
Expand All @@ -106,8 +105,7 @@ float sfConvexShape_getRotation(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfConvexShape_getScale(const sfConvexShape* shape)
{
sfVector2f scale = {0, 0};
CSFML_CHECK_RETURN(shape, scale);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getScale());
}
Expand All @@ -116,8 +114,7 @@ sfVector2f sfConvexShape_getScale(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfConvexShape_getOrigin(const sfConvexShape* shape)
{
sfVector2f origin = {0, 0};
CSFML_CHECK_RETURN(shape, origin);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getOrigin());
}
Expand Down Expand Up @@ -212,8 +209,7 @@ const sfTexture* sfConvexShape_getTexture(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfConvexShape_getTextureRect(const sfConvexShape* shape)
{
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getTextureRect());
}
Expand All @@ -222,8 +218,7 @@ sfIntRect sfConvexShape_getTextureRect(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfColor sfConvexShape_getFillColor(const sfConvexShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
CSFML_CHECK_RETURN(shape, {});

return convertColor(shape->This.getFillColor());
}
Expand All @@ -232,8 +227,7 @@ sfColor sfConvexShape_getFillColor(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfColor sfConvexShape_getOutlineColor(const sfConvexShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
CSFML_CHECK_RETURN(shape, {});

return convertColor(shape->This.getOutlineColor());
}
Expand All @@ -256,8 +250,7 @@ size_t sfConvexShape_getPointCount(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfConvexShape_getPoint(const sfConvexShape* shape, size_t index)
{
sfVector2f point = {0, 0};
CSFML_CHECK_RETURN(shape, point);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getPoint(index));
}
Expand All @@ -280,8 +273,7 @@ void sfConvexShape_setPoint(sfConvexShape* shape, size_t index, sfVector2f point
////////////////////////////////////////////////////////////
sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
{
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getLocalBounds());
}
Expand All @@ -290,8 +282,7 @@ sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfConvexShape_getGlobalBounds(const sfConvexShape* shape)
{
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getGlobalBounds());
}
6 changes: 2 additions & 4 deletions src/CSFML/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ void sfImage_setPixel(sfImage* image, unsigned int x, unsigned int y, sfColor co
////////////////////////////////////////////////////////////
sfColor sfImage_getPixel(const sfImage* image, unsigned int x, unsigned int y)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(image, color);
CSFML_CHECK_RETURN(image, {});

return convertColor(image->This.getPixel({ x, y }));
}
Expand All @@ -177,8 +176,7 @@ const uint8_t* sfImage_getPixelsPtr(const sfImage* image)
////////////////////////////////////////////////////////////
sfVector2u sfImage_getSize(const sfImage* image)
{
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(image, size);
CSFML_CHECK_RETURN(image, {});

return convertVector2(image->This.getSize());
}
Expand Down
30 changes: 10 additions & 20 deletions src/CSFML/Graphics/RectangleShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ void sfRectangleShape_setOrigin(sfRectangleShape* shape, sfVector2f origin)
////////////////////////////////////////////////////////////
sfVector2f sfRectangleShape_getPosition(const sfRectangleShape* shape)
{
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(shape, position);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getPosition());
}
Expand All @@ -106,8 +105,7 @@ float sfRectangleShape_getRotation(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfRectangleShape_getScale(const sfRectangleShape* shape)
{
sfVector2f scale = {0, 0};
CSFML_CHECK_RETURN(shape, scale);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getScale());
}
Expand All @@ -116,8 +114,7 @@ sfVector2f sfRectangleShape_getScale(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfRectangleShape_getOrigin(const sfRectangleShape* shape)
{
sfVector2f origin = {0, 0};
CSFML_CHECK_RETURN(shape, origin);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getOrigin());
}
Expand Down Expand Up @@ -212,8 +209,7 @@ const sfTexture* sfRectangleShape_getTexture(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfRectangleShape_getTextureRect(const sfRectangleShape* shape)
{
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getTextureRect());
}
Expand All @@ -222,8 +218,7 @@ sfIntRect sfRectangleShape_getTextureRect(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfColor sfRectangleShape_getFillColor(const sfRectangleShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
CSFML_CHECK_RETURN(shape, {});

return convertColor(shape->This.getFillColor());
}
Expand All @@ -232,8 +227,7 @@ sfColor sfRectangleShape_getFillColor(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfColor sfRectangleShape_getOutlineColor(const sfRectangleShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
CSFML_CHECK_RETURN(shape, {});

return convertColor(shape->This.getOutlineColor());
}
Expand All @@ -256,8 +250,7 @@ size_t sfRectangleShape_getPointCount(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfVector2f sfRectangleShape_getPoint(const sfRectangleShape* shape, size_t index)
{
sfVector2f point = {0, 0};
CSFML_CHECK_RETURN(shape, point);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getPoint(index));
}
Expand All @@ -273,8 +266,7 @@ void sfRectangleShape_setSize(sfRectangleShape* shape, sfVector2f size)
////////////////////////////////////////////////////////////
sfVector2f sfRectangleShape_getSize(const sfRectangleShape* shape)
{
sfVector2f size = {0, 0};
CSFML_CHECK_RETURN(shape, size);
CSFML_CHECK_RETURN(shape, {});

return convertVector2(shape->This.getSize());
}
Expand All @@ -283,8 +275,7 @@ sfVector2f sfRectangleShape_getSize(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfRectangleShape_getLocalBounds(const sfRectangleShape* shape)
{
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getLocalBounds());
}
Expand All @@ -293,8 +284,7 @@ sfFloatRect sfRectangleShape_getLocalBounds(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfRectangleShape_getGlobalBounds(const sfRectangleShape* shape)
{
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
CSFML_CHECK_RETURN(shape, {});

return convertRect(shape->This.getGlobalBounds());
}
14 changes: 5 additions & 9 deletions src/CSFML/Graphics/RenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void sfRenderTexture_destroy(sfRenderTexture* renderTexture)
////////////////////////////////////////////////////////////
sfVector2u sfRenderTexture_getSize(const sfRenderTexture* renderTexture)
{
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(renderTexture, size);
CSFML_CHECK_RETURN(renderTexture, {});

return convertVector2(renderTexture->This.getSize());
}
Expand Down Expand Up @@ -139,9 +138,8 @@ const sfView* sfRenderTexture_getDefaultView(const sfRenderTexture* renderTextur
////////////////////////////////////////////////////////////
sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, const sfView* view)
{
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderTexture, rect);
CSFML_CHECK_RETURN(view, {});
CSFML_CHECK_RETURN(renderTexture, {});

return convertRect(renderTexture->This.getViewport(view->This));
}
Expand All @@ -150,8 +148,7 @@ sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, cons
////////////////////////////////////////////////////////////
sfVector2f sfRenderTexture_mapPixelToCoords(const sfRenderTexture* renderTexture, sfVector2i point, const sfView* targetView)
{
sfVector2f result = {0, 0};
CSFML_CHECK_RETURN(renderTexture, result);
CSFML_CHECK_RETURN(renderTexture, {});

if (targetView)
return convertVector2(renderTexture->This.mapPixelToCoords(convertVector2(point), targetView->This));
Expand All @@ -163,8 +160,7 @@ sfVector2f sfRenderTexture_mapPixelToCoords(const sfRenderTexture* renderTexture
////////////////////////////////////////////////////////////
sfVector2i sfRenderTexture_mapCoordsToPixel(const sfRenderTexture* renderTexture, sfVector2f point, const sfView* targetView)
{
sfVector2i result = {0, 0};
CSFML_CHECK_RETURN(renderTexture, result);
CSFML_CHECK_RETURN(renderTexture, {});

if (targetView)
return convertVector2(renderTexture->This.mapCoordsToPixel(convertVector2(point), targetView->This));
Expand Down
Loading

0 comments on commit 10685c7

Please sign in to comment.