user1437050
user1437050

Reputation: 41

Is there a way to reduce CPU and GPU load in my simple 2D DirectX game?

I guess I have some explaining to do:

The situation: Despite of being very simple in both game logic and graphics, it still takes my CPU and GPU load to 100%. Even the menu is displayed with more than 2000 frames per second.

My problem is not that the game runs too fast. I already timed sprite animations and game logic using the QueryPerformanceCounter function.

The actual problem is that the game calculates the same code numerous times without anything happening on the screen, therefore putting a massive load on my hardware.

In what ways can I decrease the hardware load of my game? I feel like using Sleep is "cheating".

Upvotes: 2

Views: 1597

Answers (2)

user1437050
user1437050

Reputation: 41

Thank to Damon for pointing me in the right direction, I looked into the present function. (http://msdn.microsoft.com/en-us/library/windows/desktop/bb174576(v=vs.85).aspx)

All it took to solve both CPU and GPU load problems was changing

swapChain->Present(0, 0);

to

swapChain->Present(1, 0);

Upvotes: 2

tobsen
tobsen

Reputation: 5398

Just a quick suggestion:

Everytime you enter the game loop calculate the time passed since the last time you entered. If this time is below a given threshold just return without processing anything.

Upvotes: 0

Related Questions