Commit 8db0781
committed
fix: address fps limiter review bugs + add unit tests
Bug fixes:
- PresentExtension: nextScheduledUst now uses max(last+interval, now) so
already-late frames are not penalised with an extra full interval of delay
- PresentExtension: setFrameRateLimit increments a generation counter so
in-flight scheduled lambdas detect the change and fire immediately instead
of stalling the game at the old cadence
- PresentExtension: lastScheduledUst watermark is reset on every limit change
(not just when going to 0) so the new cadence starts clean
- PresentExtension: add close() / Extension.close() default so the scheduler
thread is shut down when the XServer is released (no more thread leak per
game session)
- XServerView: setFrameRateLimit now cancels any pending delayed render and
re-kicks requestRender() on any change, not just when going to 0 — fixes
stale render cadence when changing e.g. 5fps -> 60fps
- XServerScreen: frameRating.update() moved to runOnUiThread() — was being
called from the GL thread with no synchronisation
- XServerScreen: LaunchedEffect uses applyFpsLimiterToEngines() helper to
remove duplicated set calls
Refactor:
- Extract fpsLimiterSteps/CurrentIndex/Progress/Next/Previous to
FpsLimiterUtils.kt (internal) so they are testable without Compose
- fpsLimiterCurrentIndex uses indexOfLast { it <= value } floor lookup
instead of exact-match, fixing wrong direction on a restored non-step value
Tests (FpsLimiterUtilsTest — 20 cases):
- fpsLimiterSteps: 60/90/120/144Hz, exact multiples, sub-5 clamp, ordering
- fpsLimiterCurrentIndex: exact match, floor, below-min clamp, 144Hz edge
- nextFpsLimiterValue: normal, clamped at max, non-step floor, 144Hz top
- previousFpsLimiterValue: normal, clamped at min, non-step floor, 144Hz top
- fpsLimiterProgress: min=0, max=1, midpoint, 144Hz, non-step floor1 parent 8c90c40 commit 8db0781
7 files changed
Lines changed: 268 additions & 55 deletions
File tree
- app/src
- main/java
- app/gamenative/ui
- component
- screen/xserver
- com/winlator
- widget
- xserver/extensions
- test/java/app/gamenative/ui/component
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
Lines changed: 2 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
| 215 | + | |
| 216 | + | |
245 | 217 | | |
246 | 218 | | |
247 | 219 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
502 | | - | |
503 | | - | |
504 | | - | |
505 | | - | |
| 502 | + | |
506 | 503 | | |
507 | 504 | | |
508 | 505 | | |
| |||
1426 | 1423 | | |
1427 | 1424 | | |
1428 | 1425 | | |
1429 | | - | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
1430 | 1429 | | |
1431 | 1430 | | |
1432 | 1431 | | |
| |||
1920 | 1919 | | |
1921 | 1920 | | |
1922 | 1921 | | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
1923 | 1925 | | |
1924 | 1926 | | |
1925 | 1927 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
92 | 93 | | |
93 | 94 | | |
94 | | - | |
95 | | - | |
| 95 | + | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
Lines changed: 30 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
67 | 72 | | |
68 | 73 | | |
69 | | - | |
70 | | - | |
71 | 74 | | |
72 | 75 | | |
73 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
74 | 79 | | |
75 | 80 | | |
76 | 81 | | |
| |||
200 | 205 | | |
201 | 206 | | |
202 | 207 | | |
| 208 | + | |
203 | 209 | | |
204 | 210 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
209 | 224 | | |
210 | 225 | | |
211 | 226 | | |
| |||
0 commit comments