Difference between revisions of "Intermediate C++ Game Programming Tutorial 21"

From Chilipedia
Jump to: navigation, search
(Bonus Video)
(Bonus Video)
Line 10: Line 10:
  
 
== Bonus Video ==
 
== Bonus Video ==
The addition of smart pointers to Surface has allowed us to reduce the amount of code we need to write for Surface, making it simpler and correct by default. But we still need to write logic for those pesky copy operations... What if we used a container like std::vector<>! Then
+
The addition of smart pointers to <code>Surface</code> has allowed us to reduce the amount of code we need to write for <code>Surface</code>, making it simpler and correct by default. But we still need to write logic for those pesky copy operations... What if we used a container like <code>std::vector</code>! Then all that copying bullshit will be taken care of for us.
 +
 
 +
This is what we do in the bonus video. The only problem is, although adding <code>std::vector</code> will not make our release build any slower (the compiler optimizes out all of the extra abstraction for us), it does make the debug build slow. Usually, we don't worry about performance under debug, but for stuff like <code>PutPixel</code>, since we're calling it potentially millions of times per second, if our debug build is too slow it will become unusable for development and testing.
 +
 
 +
So the second goal of this bonus video is to optimize the debug build so that <code>PutPixel</code>-related operation run very fast, regardless of the fact that we are using <code>std::vector</code> to manage the array of pixels. The end result is that we can achieve rendering speeds which are over 100x faster than without the optimized debug configuration.
 +
 
 +
Video coming soon!
  
 
== Notes ==
 
== Notes ==

Revision as of 00:25, 14 January 2018

Smart pointers. I know pointers, I have the smartest pointers. In this video we learn about std::unique_ptr<>, which is by far the most frequently-used and important smart pointer. std::shared_ptr<> can go suck on an egg.

Topics Covered

  • std::unique_ptr<>
  • How to pass (and not to pass) smart pointers
  • Custom deleters

Video Timestamp Index

Bonus Video

The addition of smart pointers to Surface has allowed us to reduce the amount of code we need to write for Surface, making it simpler and correct by default. But we still need to write logic for those pesky copy operations... What if we used a container like std::vector! Then all that copying bullshit will be taken care of for us.

This is what we do in the bonus video. The only problem is, although adding std::vector will not make our release build any slower (the compiler optimizes out all of the extra abstraction for us), it does make the debug build slow. Usually, we don't worry about performance under debug, but for stuff like PutPixel, since we're calling it potentially millions of times per second, if our debug build is too slow it will become unusable for development and testing.

So the second goal of this bonus video is to optimize the debug build so that PutPixel-related operation run very fast, regardless of the fact that we are using std::vector to manage the array of pixels. The end result is that we can achieve rendering speeds which are over 100x faster than without the optimized debug configuration.

Video coming soon!

Notes

Although Chili uses std::unique_ptr<> in Surface, which allows us to = default the move members and leave the destructor undeclared, the astute student will realize that Surface should actually be setting the width and height of the donor surface to 0 when pilfering, so we actually still need to declare move members in this case. This is done in the Bonus Video where we perfect Surface.

Source Code


See also