stream_set_grid(s, ox, oz) puts a stream's cells on a grid from a corner (0 keeps world zero, today's); stream_emit_baked(s, recs, count, keep, x0, z0, y_base, lo, hi) emits the first keep 12-byte records of a baked chunk (the layout agreed with Physics: u16 x, z in 1/65536 of the chunk, u16 y in cm above y_base, u8 scale over the kind's lo..hi, u8 yaw, seed, wind) into the chunk being filled, and stream_band_keep(count, share) is a band's prefix. Nothing calls them yet: behaviour unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 lines
1.8 KiB
Text
36 lines
1.8 KiB
Text
# stream_baked.ludic — a stream filled from baked chunks instead of generated ones (plan 26 of
|
|
# maroon-lake). The bake stores every instance of a kind once per 64 m chunk, at full density and in a
|
|
# shuffled order, so a distance band draws a PREFIX of it: a nearer band holds everything a farther one
|
|
# does. A record is 12 bytes: u16 x, u16 z (1/65536 of the chunk), u16 y (cm above the chunk's y_base),
|
|
# u8 scale (lo..hi, the kind's range), u8 yaw, u8 seed, u8 wind.
|
|
|
|
const SB_REC: int = 12
|
|
|
|
# the stream's cells laid on the baked chunks' grid: `size` metres from the corner (ox, oz)
|
|
export function stream_set_grid(s: Stream, ox: float, oz: float) -> void {
|
|
s.ox = ox
|
|
s.oz = oz
|
|
}
|
|
|
|
# the first `keep` records of a chunk emitted into the chunk being filled (inside r3d_stream_fill)
|
|
export function stream_emit_baked(render3d_st: mut Render3dState, s: Stream, recs: pointer, count: int, keep: int, x0: float, z0: float, y_base: float, lo: float, hi: float) -> void {
|
|
let n = min(keep, count)
|
|
let span = s.size / 65536.0
|
|
let sr = (hi - lo) / 255.0
|
|
for i in 0 .. n {
|
|
let o = i * SB_REC
|
|
let x = x0 + float(recs[o] | (recs[o + 1] << 8)) * span
|
|
let z = z0 + float(recs[o + 2] | (recs[o + 3] << 8)) * span
|
|
let y = y_base + float(recs[o + 4] | (recs[o + 5] << 8)) * 0.01
|
|
let scale = lo + float(recs[o + 6]) * sr
|
|
let yaw = float(recs[o + 7]) * (2.0 * PI / 256.0)
|
|
stream_emit(render3d_st, s, x, y, z, scale, yaw, float(recs[o + 8]) / 255.0, float(recs[o + 9]) / 255.0)
|
|
}
|
|
}
|
|
|
|
# how many of a chunk's records a band keeps: all at band 0, then the share each band out had of the
|
|
# generated density (the caller's table), rounded so a band is never empty where the chunk is not
|
|
export function stream_band_keep(count: int, share: float) -> int {
|
|
if count == 0 { return 0 }
|
|
return max(1, min(count, int(float(count) * share + 0.5)))
|
|
}
|