Created
May 30, 2019 07:01
-
-
Save oxycoder/5dc7be254b02e18e674e8b7f6733702a to your computer and use it in GitHub Desktop.
C++ game loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic c++ game loop | |
// idea: Render without affected to game logic and input | |
int main() | |
{ | |
bool hasFocus = true; // check if windows is focus and active | |
bool isMinimize = false; // check if windows is minized | |
DWORD currentTime = timeGetTime(); | |
DWORD lastFrameTime = 0; | |
int fpsLimitWithFocused = 60; | |
int fpsLimitWithoutFocus = 15; | |
while (!quit) { | |
currentTime = timeGetTime(); | |
if (hasFocus) { | |
ProccessInput(); | |
} | |
ProcessLogic(); | |
if (hasFocus) { | |
if ((currentTime - lastFrameTime) > (1000 / fpsLimitWithFocused)) { | |
Render(); | |
lastFrameTime = currentTime; | |
} | |
} | |
else { | |
if (!isMinimize && (currentTime - lastFrameTime) > (1000 / fpsLimitWithoutFocus)) | |
Render(); | |
lastFrameTime = currentTime; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment