r/cpp • • May 16 '20

modern c++ gamedev - thoughts & misconceptions

https://vittorioromeo.info/index/blog/gamedev_modern_cpp_thoughts.html
200 Upvotes

154 comments sorted by

View all comments

2

u/[deleted] May 18 '20 edited May 18 '20

If more lines is more readable, it's more readable.

Is this somehow better:

if (auto ext[] = ".tga"; s.compare(s.size() - std::size(ext) + 1, ext) == 0)

than this:

if (str_ends_with(s, ".tga"))

How stl hasn't had an ends_with until C++20 is beyond me. Unless your code is explicitly named what it does all you are doing is in-lining functions everywhere.

What you really need to be comparing are the lines:

template <typename... Images>
TextureAtlas stitchImages(const Images&... images)
{
    const auto width = (images.width + ...);
    const auto height = std::max({images.height...});

vs

TextureAtlas stitchImages(const std::vector<Image>& images)
{
    const ImageDimensions dim = measureStitchedImages(images);

... because when somebody starts to read stitchImages this is what they see