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
@@ -591,12 +591,19 @@ drawPut:
|
|||||||
|
|
||||||
; ---- Waiting ----
|
; ---- Waiting ----
|
||||||
;
|
;
|
||||||
; There is no clock on this machine, so time is counted in instructions. At the emulated
|
; There is no clock on this machine, so time is counted in cycles. At the emulated rate this
|
||||||
; rate this is about an eighth of a second, which is a speed a person can play at. Running
|
; is about an eighth of a second, which is a speed a person can play at. Running the emulator
|
||||||
; the emulator faster or slower moves it, and that is the honest answer: the machine has
|
; faster or slower moves it, and that is the honest answer: the machine has no way to know
|
||||||
; no way to know how long a second is and this program is not going to pretend it does.
|
; how long a second is and this program is not going to pretend it does.
|
||||||
|
;
|
||||||
|
; THE COUNT USED TO BE 256 AND THE COMMENT USED TO SAY INSTRUCTIONS. When a cycle stopped
|
||||||
|
; being an instruction and became a memory access, every loop in the machine got dearer and
|
||||||
|
; this one silently doubled - the game has been running at half the speed it says ever since,
|
||||||
|
; in a terminal as much as in a window. The inner loop is a DECA and a BNA, one byte and
|
||||||
|
; three, so four cycles a turn: 122 times 256 times 4 is about 125,000, which is an eighth of
|
||||||
|
; a second at a megahertz.
|
||||||
pause:
|
pause:
|
||||||
RSTB
|
INIB 0d122
|
||||||
pauseOuter:
|
pauseOuter:
|
||||||
RSTA
|
RSTA
|
||||||
pauseInner:
|
pauseInner:
|
||||||
|
|||||||
@@ -242,7 +242,13 @@ int main(int argc, char *argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
// Resizable, because how big somebody wants a screen is not the machine's business.
|
// 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.
|
// 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,
|
InitWindow(VIDEO_MAX_WIDTH * SCREEN_SCALE, VIDEO_MAX_HEIGHT * SCREEN_SCALE,
|
||||||
"Segan Voyager");
|
"Segan Voyager");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ CosmOS
|
|||||||
> greet.sbx 211
|
> greet.sbx 211
|
||||||
hello.sbx 53
|
hello.sbx 53
|
||||||
Life.sbx 1396
|
Life.sbx 1396
|
||||||
Snake.sbx 2163
|
Snake.sbx 2164
|
||||||
Keys.sbx 664
|
Keys.sbx 664
|
||||||
Say.sbx 156
|
Say.sbx 156
|
||||||
Break.sbx 149
|
Break.sbx 149
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ CosmOS
|
|||||||
> greet.sbx 211
|
> greet.sbx 211
|
||||||
hello.sbx 53
|
hello.sbx 53
|
||||||
Life.sbx 1396
|
Life.sbx 1396
|
||||||
Snake.sbx 2163
|
Snake.sbx 2164
|
||||||
Keys.sbx 664
|
Keys.sbx 664
|
||||||
Say.sbx 156
|
Say.sbx 156
|
||||||
Break.sbx 149
|
Break.sbx 149
|
||||||
|
|||||||
Reference in New Issue
Block a user