Massive framerate loss when drawing.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Magei00
Posts: 3
Joined: September 28th, 2017, 2:13 pm
Location: Denmark

Massive framerate loss when drawing.

Post by Magei00 » September 30th, 2017, 6:25 pm

Hi there.
I have been following the beginner series ( also some of the intermediate) to learn some c++, and a few days ago i finally decided to create my own project.
It's a simple arkanoid clone, using the basic concepts from lesson 1-8 + arrays and classes/objects.

My problem is now, that when i draw the breakable blocks my frame rate tanks, going from 120 to 37. I feel like this shouldn't be happening since it's not a complicated game by any means, but i also don't know what causes it or how to avoid it.

The only cause i can think of at this point is that the putPixel command isn't intended to be used so much?
Right now i call it approx. 218916 times each frame, which is a lot.

I've included my code, if that helps.

I hope you can help me out here :?
Attachments
Chili Framework 2016.rar
(9.68 MiB) Downloaded 118 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Massive framerate loss when drawing.

Post by albinopapa » October 1st, 2017, 5:27 am

Are you in Release mode or Debug mode?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Massive framerate loss when drawing.

Post by albinopapa » October 1st, 2017, 5:41 am

I get about 27 fps in Debug mode which you shouldn't really base your performance off of. As a comparison, I get 60+ fps in Release, with vsync enabled in the framework, I can't go above 60 fps on my monitor. You are probably correct about the PutPixel calls, though mostly because of the debug information attached when in Debug mode.

You could do away with the abundant putpixel calls with some procedurally generated objects. If you know how to interpolate between two numbers, you can write a draw function that will calculate the gradients used in your project.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Magei00
Posts: 3
Joined: September 28th, 2017, 2:13 pm
Location: Denmark

Re: Massive framerate loss when drawing.

Post by Magei00 » October 1st, 2017, 12:17 pm

Thank you!

I was running in debug mode and that caused the low framerate.
Changing to release fixed it :)

I'm not quite following the solution with procedurally generated objects. Even if the putPixel calls were done in a smarter way wouldn't I still be required to call them the same ammount of times?

I'm probably not gonna be toying with a solution like that anyway, but thanks for helping out.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Massive framerate loss when drawing.

Post by albinopapa » October 1st, 2017, 5:58 pm

Yes, you would, doing it procedurally would really only cut down on the compile time in Release mode.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply