Give Snake back the speed its comment promised, and present in step with the display
Two things, one certain and one likely. THE CERTAIN ONE IS NOT THE WINDOW'S FAULT. Snake's pause loop said "at the emulated rate this is about an eighth of a second", and it was, when a cycle was one instruction. A cycle became one memory access, every loop in the machine got dearer, and this one silently doubled: the game has been running at half the speed it documents ever since, in a terminal as much as in a window. Measured rather than guessed - the inner loop is a DECA and a BNA, one byte and three, so four cycles a turn, and a whole run went from 3,848,610 cycles to 1,920,504 when the outer count came down from 256 to 122. Almost exactly half, which is what the arithmetic said it would be. That is the cost model change reaching a program nobody thought to re-measure. Worth looking for others: any loop tuned by eye before that change is running at half its intended speed. THE LIKELY ONE is the frame limiter. Without the vsync hint, Raylib sleeps towards sixty frames a second on its own clock, which beats against a display refreshing on its own - frames shown twice or skipped, and the machine handed an uneven number of cycles each time, since it takes its budget from the wall clock. The hint puts presentation in step with the screen. SetTargetFPS stays for a driver that ignores it. Snake is one byte bigger, because RSTB became INIB. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
43a05b3df1
commit
310804e267
@@ -242,7 +242,13 @@ int main(int argc, char *argv[]) {
|
||||
} else {
|
||||
// Resizable, because how big somebody wants a screen is not the machine's business.
|
||||
// The picture is rescaled to whatever the window becomes, in whole pixels.
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
|
||||
//
|
||||
// And presented in step with the display. Without the hint the frame limiter sleeps
|
||||
// towards sixty a second on its own clock, which beats against a screen refreshing on
|
||||
// its own - some frames shown twice, some skipped, and the machine handed an uneven
|
||||
// number of cycles each time because it takes them from the wall clock. The target
|
||||
// stays as well, for a driver that ignores the hint.
|
||||
SetConfigFlags(FLAG_WINDOW_RESIZABLE | FLAG_VSYNC_HINT);
|
||||
InitWindow(VIDEO_MAX_WIDTH * SCREEN_SCALE, VIDEO_MAX_HEIGHT * SCREEN_SCALE,
|
||||
"Segan Voyager");
|
||||
SetTargetFPS(60);
|
||||
|
||||
Reference in New Issue
Block a user