diff --git a/Apps/Gargantua/main.vp b/Apps/Gargantua/main.vp index 17e0ec9..86a0775 100644 --- a/Apps/Gargantua/main.vp +++ b/Apps/Gargantua/main.vp @@ -19,7 +19,8 @@ define DISK_OUT = 11.0 define CAM_DIST = 22.0 define CAM_ELEV = 9.0 define FOVF = 0.55 -define YIELD_ROWS = 4 +define SLICE_PIXELS = 64 +define FLUSH_ROWS = 4 define V3_POOL_SIZE = 8192 define V3_POOL_BYTES = V3_POOL_SIZE * 24 + 512 @@ -249,6 +250,8 @@ export def _start() -> int: gT: double = 0.0 rendered: int = 0 + rx: int = 0 + ry: int = 0 evt: window.InputEvent while window.is_active(root.win_id): @@ -263,22 +266,21 @@ export def _start() -> int: canvas.set_fb(fb, new_w, new_h) if rendered == 0: - y: int = 0 - while y < GH: - for x in range(GW): - pixel: uint32 = shade_pixel(x, y, gT) - fb[y * GW + x] = pixel - y += 1 - if y % YIELD_ROWS == 0: - root.redraw() - process.yield_cpu() - result2: int = window.poll_event(&evt) - if result2 != 0: - if evt.type == window.EVENT_TYPE_PING: - window.flush(root.win_id) - root.redraw() - rendered = 1 - gT += 50.0 + # 固定像素预算切片,保证单次占用时间片有上界 + budget: int = SLICE_PIXELS + while budget > 0 and ry < GH: + fb[ry * GW + rx] = shade_pixel(rx, ry, gT) + rx += 1 + budget -= 1 + if rx >= GW: + rx = 0 + ry += 1 + if ry % FLUSH_ROWS == 0: + root.redraw() + if ry >= GH: + root.redraw() + rendered = 1 + gT += 50.0 process.yield_cpu()