Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: add setPoints  (Read 3539 times)

0 Members and 1 Guest are viewing this topic.

Keith99

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
add setPoints
« on: June 26, 2018, 01:32:16 pm »
Hi, I hope this is the right place for this. I would like to request a small addition to the ConvexShape:

Add a setPoints function (with an s at the end) to it.

Currently I am doing some experiments involving drawing convex shapes with 1000s of points and calling addPoint for each one kills performance (I think due to SFML updating internal data each time a point is added). All I would like is:

void ConvexShape::setPoints(std::vector<Vector2f> points)
{
     m_points=points;
     Update();
}

(points could be passed by reference but there may be a case for by value if std::move can be used?)

thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: add setPoints
« Reply #1 on: June 26, 2018, 03:11:10 pm »
What kills performances is probably the call to update(), which recomputes the shape's geometry, for each new point, while it could be done once at the end. Instead of a setPoints function, we should probably do lazy updates (like in other classes).

In the meantime, you can easily work around this problem: look at sf::ConvexShape, it is made of 7 lines of code so I think you can create your own shape class based on it, with the optimizations that you need ;)
Laurent Gomila - SFML developer

Keith99

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: add setPoints
« Reply #2 on: June 26, 2018, 10:18:33 pm »
Good point yes, I had forgotten SFML shape class can be user extended.