feat(rendering): add Screen.camera/clip/blend_mode/oval + Camera.* + Screen.pixel (#23)
Completes the transform/state-based rendering #23 tracked as blocked on new renderer state. All of it threads through the two framebuffer chokepoints every draw primitive already funnels through (rt_put_px / rt_fill_rect), so one place gives the whole draw API a camera, a clip rect, and a blend mode. Defaults are neutral — camera (0,0), clip = full screen, blend = replace — so every existing golden render is byte-identical (the 60+ render tests still pass unchanged). New renderer state (runtime/native/core.ludic): - Screen.camera(x, y) / Camera.set(x, y) world-space draw offset; a world point draws at (wx-x, wy-y). Moves everything — reset to (0,0) for a HUD. - Camera.follow(x, y, lerp) ease the offset toward centring a target (fixed lerp 0..1) - Camera.shake(amount) +/- amount jitter from the seeded RNG (replay shakes identically); 0 clears - Screen.clip(x,y,w,h) / clip_reset() screen-space clip rectangle - Screen.blend_mode(m) 0 = replace, 1 = additive (clamped) New primitives: - Screen.oval(x, y, rx, ry, color) axis-aligned ellipse outline (midpoint) - Screen.measure_text(text) -> int advance width in the 5x7 font - Screen.pixel(x, y) -> int read a framebuffer pixel (0x00RRGGBB) Everything stays integer and deterministic (the camera, shake, and blend all reproduce exactly under identical inputs), so headless renders remain diffable. Camera.follow interpolates in the fixed domain (fixed*fixed then floor) to avoid the int*fixed coercion trap. Screen.pixel makes the whole surface testable by reading rendered pixels back: examples/library/render.ludic asserts 18 cases — pixel round-trip, camera and Camera.set/follow offsets, clip in/out + reset, additive blend with 255 clamp, oval extremes vs hollow centre, and text measurement — all verified against the actual framebuffer, not just that the call compiled. Wired into x test (now 65 passed). Docs: 7 new Screen pages + a Camera section with 3 pages, inventory/coverage green. Seed reseeded; the C-free bootstrap fixpoint holds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
12f2dbe958
commit
31cfbc2465
16 changed files with 8383 additions and 7183 deletions
7
docs/language/camera/_section.md
Normal file
7
docs/language/camera/_section.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
id: camera
|
||||
title: Camera
|
||||
order: 32
|
||||
---
|
||||
|
||||
A world-space camera — a draw offset threaded through the render path (the same offset <a href="screen-camera"><code>Screen.camera</code></a> sets). <a href="camera-set"><code>Camera.set</code></a> places it, <a href="camera-follow"><code>Camera.follow</code></a> eases it toward a target, and <a href="camera-shake"><code>Camera.shake</code></a> jitters it from the seeded RNG for impact and explosions. Everything is integer and deterministic — driven off the same seed and inputs, a replay reproduces the exact camera path, shake included. The camera moves everything drawn; reset it to <code>(0, 0)</code> to draw a fixed HUD.
|
||||
29
docs/language/camera/camera-follow.md
Normal file
29
docs/language/camera/camera-follow.md
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
id: camera-follow
|
||||
name: Camera.follow
|
||||
category: camera
|
||||
kind: namespace-method
|
||||
tokens: Camera.follow
|
||||
sig: Camera.follow(x, y, lerp)
|
||||
tip: Ease the camera toward centring a target point.
|
||||
order: 2
|
||||
ns: Camera
|
||||
member: follow
|
||||
---
|
||||
|
||||
Moves the camera a fraction <code>lerp</code> of the way toward centring the world point <code>(x, y)</code> on screen. <code>lerp</code> is a <code>fixed</code> in <code>0.0</code>..<code>1.0</code>: <code>0</code> holds still, a small value trails smoothly behind a moving target, <code>1.0</code> snaps it centred. Call it each frame with the target's position for a classic smooth-follow camera. Deterministic.
|
||||
|
||||
Parameters:
|
||||
- `x`, `y` — the world point to centre on (usually the player)
|
||||
- `lerp` — how far to move this frame (a `fixed`, 0..1)
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
property Position { x: int = 0, y: int = 0 }
|
||||
model Player { Position }
|
||||
handler DrawWorld phase Render {
|
||||
Camera.follow(Position.x, Position.y, fixed(1) / fixed(8)) # smooth trail
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
```
|
||||
25
docs/language/camera/camera-set.md
Normal file
25
docs/language/camera/camera-set.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
id: camera-set
|
||||
name: Camera.set
|
||||
category: camera
|
||||
kind: namespace-method
|
||||
tokens: Camera.set
|
||||
sig: Camera.set(x, y)
|
||||
tip: Place the camera at a world-space offset.
|
||||
order: 1
|
||||
ns: Camera
|
||||
member: set
|
||||
---
|
||||
|
||||
Sets the camera offset directly: a world point <code>(wx, wy)</code> draws on screen at <code>(wx - x, wy - y)</code>. The same control as <a href="screen-camera"><code>Screen.camera</code></a>, under the <code>Camera</code> namespace. Use it to snap the view, or as the base that <a href="camera-follow"><code>Camera.follow</code></a> and <a href="camera-shake"><code>Camera.shake</code></a> build on.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
property Position { x: int = 0, y: int = 0 }
|
||||
model Player { Position }
|
||||
handler DrawWorld phase Render {
|
||||
Camera.set(Position.x - 160, Position.y - 120)
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
```
|
||||
29
docs/language/camera/camera-shake.md
Normal file
29
docs/language/camera/camera-shake.md
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
id: camera-shake
|
||||
name: Camera.shake
|
||||
category: camera
|
||||
kind: namespace-method
|
||||
tokens: Camera.shake
|
||||
sig: Camera.shake(amount)
|
||||
tip: Jitter the camera by up to +/- amount pixels (seeded RNG).
|
||||
order: 3
|
||||
ns: Camera
|
||||
member: shake
|
||||
---
|
||||
|
||||
Adds a random screen shake of up to <code>+/- amount</code> pixels on top of the camera's base offset, drawn from the seeded RNG so a replay shakes identically. Call it each frame with a decaying <code>amount</code> for a hit or explosion; <code>Camera.shake(0)</code> clears it. It stacks on <a href="camera-set"><code>Camera.set</code></a> / <a href="camera-follow"><code>Camera.follow</code></a>, so follow and shake compose.
|
||||
|
||||
Parameters:
|
||||
- `amount` — the maximum shake magnitude in pixels (0 clears it)
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
property Hit { timer: int = 0 }
|
||||
model Cam { Hit }
|
||||
handler DrawWorld phase Render {
|
||||
if Hit.timer > 0 { Camera.shake(Hit.timer) }
|
||||
else { Camera.shake(0) }
|
||||
Screen.show()
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue