Skip to content

Commit

Permalink
Remove 1ms "compensation" from frame delay
Browse files Browse the repository at this point in the history
Removing this make the SDL_Delay() call last 1ms longer, and reduces the
"rest of the frame" spinlock by 1ms. I don't think this should cause an
issue (if anything, it should become less likely that SDL_Delay() is
called with a value that the OS can't honor). The lower CPU usage under
normal circumstances is more desirable in my opinion.
  • Loading branch information
dorkster committed Oct 6, 2024
1 parent d512b6e commit 5b3ce47
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/

#include <SDL.h>

Version VersionInfo::ENGINE(1, 14, 64);
Version VersionInfo::ENGINE(1, 14, 65);
Version VersionInfo::MIN(0, 0, 0);
Version VersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);

Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static void mainLoop () {
// delay quick frames
// thanks to David Gow: https://davidgow.net/handmadepenguin/ch18.html
if (getSecondsElapsed(prev_ticks, SDL_GetPerformanceCounter()) < seconds_per_frame) {
int32_t delay_ms = static_cast<int32_t>((seconds_per_frame - getSecondsElapsed(prev_ticks, SDL_GetPerformanceCounter())) * 1000.f) - 1;
int32_t delay_ms = static_cast<int32_t>((seconds_per_frame - getSecondsElapsed(prev_ticks, SDL_GetPerformanceCounter())) * 1000.f);
if (delay_ms > 0) {
SDL_Delay(delay_ms);
}
Expand Down

0 comments on commit 5b3ce47

Please sign in to comment.