Skip to main content
Don't repeat tags in title
Link
DMGregory
  • 141k
  • 23
  • 258
  • 401

C++ - Should polymorphism be avoided for 2D-related math How to avoidhandle collision detection with different 2D shapes while maintaining performance issues? Is polymorphism appropriate?

Source Link
JensB
  • 157
  • 9

C++ - Should polymorphism be avoided for 2D-related math to avoid performance issues?

If I'm making a small library for handling 2D shapes, should polymorphism generally be avoided? I know that it can worsen performance but it's not like polymorphism is never used in game development so I'm unsure of where it actually isn't appropriate.

If we assume we have quite many shapes that all need constant collision detection and similar, how detrimental will polymorphism be to performance? I ask because it's tempting to have an abstract Shape that concrete child classes like Polygon and Circle could inherit from, allowing me to iterate over and handle different kinds of shapes quite smoothly. But will calling purely virtual functions of Shape many many times cause performance hits? I'm not too familiar with exactly how polymorphism can affect performance.