wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run

ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:31:34 +03:00
parent 5ffe50ed02
commit 19fcf60599
459 changed files with 17862 additions and 17603 deletions

View file

@ -1,32 +1,32 @@
# config.ludic - how many kinds of print, how many of each the ground remembers, how the reader
# reads, and the port's defaults
export function tracks_config(kinds: int, cap: int) -> void {
tk_kinds = kinds
tk_cap = cap
tk_ring = new []Track
tk_count = new []int
tk_next = new []int
for i in 0 .. kinds * cap { push(tk_ring, new Track) }
export function tracks_config(tracks_st: mut TracksState, kinds: int, cap: int) -> void {
tracks_st.tk_kinds = kinds
tracks_st.tk_cap = cap
tracks_st.tk_ring = new []Track
tracks_st.tk_count = new []int
tracks_st.tk_next = new []int
for i in 0 .. kinds * cap { push(tracks_st.tk_ring, new Track) }
for k in 0 .. kinds {
push(tk_count, 0)
push(tk_next, 0)
push(tracks_st.tk_count, 0)
push(tracks_st.tk_next, 0)
}
}
# a reader at `name_at` or above can tell the animal; a print is fresh under `fresh` hours old,
# recent under `recent`, and old after
export function tracks_config_reading(name_at: int, fresh: float, recent: float) -> void {
tk_name_at = name_at
tk_fresh_h = fresh
tk_recent_h = recent
export function tracks_config_reading(tracks_st: mut TracksState, name_at: int, fresh: float, recent: float) -> void {
tracks_st.tk_name_at = name_at
tracks_st.tk_fresh_h = fresh
tracks_st.tk_recent_h = recent
}
function tk_now() -> float {
return TracksWorld.now()
}
function tk_named() -> bool {
return TracksWorld.skill() >= tk_name_at
function tk_named(tracks_st: TracksState) -> bool {
return TracksWorld.skill() >= tracks_st.tk_name_at
}
function tk_bearing(yaw: float) -> string {

View file

@ -1,17 +1,17 @@
# leave.ludic - a print put down. Each kind is a ring: past its cap the oldest is written over, and
# a slot written over is a new print, unread
function tk_ok(kind: int) -> bool { return tk_ring != null and kind >= 0 and kind < tk_kinds }
function tk_ok(tracks_st: TracksState, kind: int) -> bool { return tracks_st.tk_ring != null and kind >= 0 and kind < tracks_st.tk_kinds }
# a print made at `made` game hours (another machine's, arriving here); the ring index, or -1
export function tracks_leave_at(kind: int, x: float, z: float, yaw: float, sp: int, legend: bool, made: float) -> int {
if not tk_ok(kind) { return -1 }
var i = tk_next[kind]
if tk_count[kind] < tk_cap {
i = tk_count[kind]
tk_count[kind] = tk_count[kind] + 1
export function tracks_leave_at(tracks_st: mut TracksState, kind: int, x: float, z: float, yaw: float, sp: int, legend: bool, made: float) -> int {
if not tk_ok(tracks_st, kind) { return -1 }
var i = tracks_st.tk_next[kind]
if tracks_st.tk_count[kind] < tracks_st.tk_cap {
i = tracks_st.tk_count[kind]
tracks_st.tk_count[kind] = tracks_st.tk_count[kind] + 1
}
tk_next[kind] = (i + 1) % tk_cap
let t = tk_ring[kind * tk_cap + i]
tracks_st.tk_next[kind] = (i + 1) % tracks_st.tk_cap
let t = tracks_st.tk_ring[kind * tracks_st.tk_cap + i]
t.x = x
t.z = z
t.yaw = yaw
@ -23,15 +23,15 @@ export function tracks_leave_at(kind: int, x: float, z: float, yaw: float, sp: i
return i
}
export function tracks_leave(kind: int, x: float, z: float, yaw: float, sp: int, legend: bool) -> int {
return tracks_leave_at(kind, x, z, yaw, sp, legend, tk_now())
export function tracks_leave(tracks_st: mut TracksState, kind: int, x: float, z: float, yaw: float, sp: int, legend: bool) -> int {
return tracks_leave_at(tracks_st, kind, x, z, yaw, sp, legend, tk_now())
}
# the ground forgets every print (a new world)
export function tracks_clear() -> void {
if tk_ring == null { return }
for k in 0 .. tk_kinds {
tk_count[k] = 0
tk_next[k] = 0
export function tracks_clear(tracks_st: mut TracksState) -> void {
if tracks_st.tk_ring == null { return }
for k in 0 .. tracks_st.tk_kinds {
tracks_st.tk_count[k] = 0
tracks_st.tk_next[k] = 0
}
}

View file

@ -1,38 +1,38 @@
# queries.ludic - what the world asks the ground. A slot is kind * cap + ring index.
export function tracks_kinds() -> int { return tk_kinds }
export function tracks_cap() -> int { return tk_cap }
export function tracks_kinds(tracks_st: TracksState) -> int { return tracks_st.tk_kinds }
export function tracks_cap(tracks_st: TracksState) -> int { return tracks_st.tk_cap }
export function tracks_count(kind: int) -> int {
if not tk_ok(kind) { return 0 }
return tk_count[kind]
export function tracks_count(tracks_st: TracksState, kind: int) -> int {
if not tk_ok(tracks_st, kind) { return 0 }
return tracks_st.tk_count[kind]
}
export function tracks_slot(kind: int, i: int) -> int { return kind * tk_cap + i }
export function tracks_slot(tracks_st: TracksState, kind: int, i: int) -> int { return kind * tracks_st.tk_cap + i }
export function tracks_x(slot: int) -> float { return tk_ring[slot].x }
export function tracks_z(slot: int) -> float { return tk_ring[slot].z }
export function tracks_yaw(slot: int) -> float { return tk_ring[slot].yaw }
export function tracks_sp(slot: int) -> int { return tk_ring[slot].sp }
export function tracks_legend(slot: int) -> bool { return tk_ring[slot].legend }
export function tracks_made(slot: int) -> float { return tk_ring[slot].made }
export function tracks_was_read(slot: int) -> bool { return tk_ring[slot].read }
export function tracks_x(tracks_st: TracksState, slot: int) -> float { return tracks_st.tk_ring[slot].x }
export function tracks_z(tracks_st: TracksState, slot: int) -> float { return tracks_st.tk_ring[slot].z }
export function tracks_yaw(tracks_st: TracksState, slot: int) -> float { return tracks_st.tk_ring[slot].yaw }
export function tracks_sp(tracks_st: TracksState, slot: int) -> int { return tracks_st.tk_ring[slot].sp }
export function tracks_legend(tracks_st: TracksState, slot: int) -> bool { return tracks_st.tk_ring[slot].legend }
export function tracks_made(tracks_st: TracksState, slot: int) -> float { return tracks_st.tk_ring[slot].made }
export function tracks_was_read(tracks_st: TracksState, slot: int) -> bool { return tracks_st.tk_ring[slot].read }
# game hours since it was made; never below 0
export function tracks_age(slot: int) -> float { return Math.max(0.0, tk_now() - tk_ring[slot].made) }
export function tracks_age(tracks_st: TracksState, slot: int) -> float { return Math.max(0.0, tk_now() - tracks_st.tk_ring[slot].made) }
# the nearest print within `r` of (x, z), as a slot; -1 when there is none
export function tracks_nearest(x: float, z: float, r: float) -> int {
export function tracks_nearest(tracks_st: TracksState, x: float, z: float, r: float) -> int {
var best = r * r
var at = -1
for k in 0 .. tk_kinds {
for i in 0 .. tk_count[k] {
let t = tk_ring[k * tk_cap + i]
for k in 0 .. tracks_st.tk_kinds {
for i in 0 .. tracks_st.tk_count[k] {
let t = tracks_st.tk_ring[k * tracks_st.tk_cap + i]
let dx = t.x - x
let dz = t.z - z
let d2 = dx * dx + dz * dz
if d2 < best {
best = d2
at = k * tk_cap + i
at = k * tracks_st.tk_cap + i
}
}
}
@ -40,8 +40,8 @@ export function tracks_nearest(x: float, z: float, r: float) -> int {
}
# signs read for the first time, of every source
export function tracks_read_count() -> int { return tk_read_n }
export function tracks_read_count(tracks_st: TracksState) -> int { return tracks_st.tk_read_n }
# the heading of the last sign read, and whether there has been one
export function tracks_last_yaw() -> float { return tk_yaw }
export function tracks_has_bearing() -> bool { return tk_has_yaw }
export function tracks_last_yaw(tracks_st: TracksState) -> float { return tracks_st.tk_yaw }
export function tracks_has_bearing(tracks_st: TracksState) -> bool { return tracks_st.tk_has_yaw }

View file

@ -1,54 +1,54 @@
# read.ludic - reading the ground. A print is read once: reading it again says the same thing
# and counts nothing, so pressing a key over one print is not as good as walking a trail.
export function tracks_fresh_of(age: float) -> int {
if age > tk_recent_h { return TRACK_OLD }
if age > tk_fresh_h { return TRACK_RECENT }
export function tracks_fresh_of(tracks_st: TracksState, age: float) -> int {
if age > tracks_st.tk_recent_h { return TRACK_OLD }
if age > tracks_st.tk_fresh_h { return TRACK_RECENT }
return TRACK_FRESH
}
function tk_push(f: TrackRead) -> void {
if f.first { tk_read_n += 1 }
q_push(tracks_reads(), f)
function tk_push(base_st: mut BaseState, tracks_st: mut TracksState, f: TrackRead) -> void {
if f.first { tracks_st.tk_read_n += 1 }
q_push(base_st, tracks_reads(base_st, tracks_st), f)
}
# read the print at a slot (tracks_nearest's answer): a fact every time, a count the first time
export function tracks_read(slot: int) -> void {
if slot < 0 or tk_ring == null or slot >= len(tk_ring) { return }
let t = tk_ring[slot]
export function tracks_read(base_st: mut BaseState, tracks_st: mut TracksState, slot: int) -> void {
if slot < 0 or tracks_st.tk_ring == null or slot >= len(tracks_st.tk_ring) { return }
let t = tracks_st.tk_ring[slot]
let f = new TrackRead
f.sp = t.sp
f.source = TRACK_PRINT
f.kind = slot / tk_cap
f.kind = slot / tracks_st.tk_cap
f.legend = t.legend
f.age = tracks_age(slot)
f.fresh = tracks_fresh_of(f.age)
f.age = tracks_age(tracks_st, slot)
f.fresh = tracks_fresh_of(tracks_st, f.age)
f.yaw = t.yaw
f.named = tk_named()
f.named = tk_named(tracks_st)
f.bearing = tk_bearing(t.yaw)
f.first = not t.read
t.read = true
tracks_note_bearing(t.yaw)
tk_push(f)
tracks_note_bearing(tracks_st, t.yaw)
tk_push(base_st, tracks_st, f)
}
# a sign that is not a print (droppings, a legend's mark): the caller knows whether it is the
# first reading of it
export function tracks_note(sp: int, source: int, legend: bool, yaw: float, first: bool) -> void {
export function tracks_note(base_st: mut BaseState, tracks_st: mut TracksState, sp: int, source: int, legend: bool, yaw: float, first: bool) -> void {
let f = new TrackRead
f.sp = sp
f.source = source
f.legend = legend
f.yaw = yaw
f.named = tk_named()
f.named = tk_named(tracks_st)
f.bearing = tk_bearing(yaw)
f.first = first
tk_push(f)
tk_push(base_st, tracks_st, f)
}
# the way the last thing read went (a bed, droppings, a print)
export function tracks_note_bearing(yaw: float) -> void {
tk_yaw = yaw
tk_has_yaw = true
export function tracks_note_bearing(tracks_st: mut TracksState, yaw: float) -> void {
tracks_st.tk_yaw = yaw
tracks_st.tk_has_yaw = true
}
export function tracks_set_read_count(n: int) -> void { tk_read_n = n }
export function tracks_set_read_count(tracks_st: mut TracksState, n: int) -> void { tracks_st.tk_read_n = n }

View file

@ -47,22 +47,24 @@ export property TrackRead {
first: bool = false
}
var tk_kinds: int = 0
var tk_cap: int = 0
var tk_ring: []Track = null # kinds x cap, kind-major
var tk_count: []int = null # per kind: how many of the ring are in use
var tk_next: []int = null # per kind: where the next print goes
var tk_name_at: int = 0 # the skill that tells the animal from its print
var tk_fresh_h: float = 0.5
var tk_recent_h: float = 2.5
var tk_read_n: int = 0 # signs read for the first time, of every source
var tk_yaw: float = 0.0 # the heading of the last sign read
var tk_has_yaw: bool = false
var tk_reads: Queue<TrackRead> = null
export state TracksState {
tk_kinds: int = 0
tk_cap: int = 0
tk_ring: []Track = null # kinds x cap, kind-major
tk_count: []int = null # per kind: how many of the ring are in use
tk_next: []int = null # per kind: where the next print goes
tk_name_at: int = 0 # the skill that tells the animal from its print
tk_fresh_h: float = 0.5
tk_recent_h: float = 2.5
tk_read_n: int = 0 # signs read for the first time, of every source
tk_yaw: float = 0.0 # the heading of the last sign read
tk_has_yaw: bool = false
tk_reads: Queue<TrackRead> = null
}
# the facts: every sign read, oldest first
export function tracks_reads() -> Queue<TrackRead> {
if tk_reads == null { tk_reads = queue_new("tracks.reads") }
return tk_reads
export function tracks_reads(base_st: mut BaseState, tracks_st: mut TracksState) -> Queue<TrackRead> {
if tracks_st.tk_reads == null { tracks_st.tk_reads = queue_new(base_st, "tracks.reads") }
return tracks_st.tk_reads
}

View file

@ -1,25 +1,25 @@
# system.ludic - the reader as a system: what has been read and the last bearing are saved; the
# prints themselves are the ground's and are not (the animals leave new ones)
export function tracks_reset() -> void {
tk_read_n = 0
tk_yaw = 0.0
tk_has_yaw = false
q_clear(tracks_reads())
export function tracks_reset(base_st: mut BaseState, tracks_st: mut TracksState) -> void {
tracks_st.tk_read_n = 0
tracks_st.tk_yaw = 0.0
tracks_st.tk_has_yaw = false
q_clear(base_st, tracks_reads(base_st, tracks_st))
}
export function tracks_save() -> Val {
export function tracks_save(tracks_st: TracksState) -> Val {
let v = Value.object()
sv_put_int(v, "read", tk_read_n)
sv_put_bool(v, "has_yaw", tk_has_yaw)
sv_put_float(v, "yaw", tk_yaw)
sv_put_int(v, "read", tracks_st.tk_read_n)
sv_put_bool(v, "has_yaw", tracks_st.tk_has_yaw)
sv_put_float(v, "yaw", tracks_st.tk_yaw)
return v
}
export function tracks_load(v: Val, version: int) -> void {
tracks_reset()
tk_read_n = sv_int(v, "read", 0)
tk_has_yaw = sv_bool(v, "has_yaw", false)
tk_yaw = sv_float(v, "yaw", 0.0)
export function tracks_load(base_st: mut BaseState, tracks_st: mut TracksState, v: Val, version: int) -> void {
tracks_reset(base_st, tracks_st)
tracks_st.tk_read_n = sv_int(v, "read", 0)
tracks_st.tk_has_yaw = sv_bool(v, "has_yaw", false)
tracks_st.tk_yaw = sv_float(v, "yaw", 0.0)
}
export function tracks_system() -> System {

View file

@ -5,138 +5,140 @@ import "ludic.tracks"
import "ludic.base"
program TracksTest {
numbers float
var now: float = 0.0
var skill: int = 1
var placed_n: int = 0
var placed_last: int = -1
state TracksTestState {
now: float = 0.0
skill: int = 1
placed_n: int = 0
placed_last: int = -1
}
function fake_now() -> float { return now }
function fake_skill() -> int { return skill }
function fake_now(tracks_test_st: TracksTestState) -> float { return tracks_test_st.now }
function fake_skill(tracks_test_st: TracksTestState) -> int { return tracks_test_st.skill }
function fake_bearing(yaw: float) -> string {
if yaw > 0.0 { return "east" }
return "west"
}
function fake_placed(kind: int, i: int) -> void {
placed_n += 1
placed_last = i
function fake_placed(tracks_test_st: mut TracksTestState, kind: int, i: int) -> void {
tracks_test_st.placed_n += 1
tracks_test_st.placed_last = i
}
bind TracksWorld { now: fn fake_now, skill: fn fake_skill, bearing: fn fake_bearing, placed: fn fake_placed }
function fresh() -> void {
now = 10.0
skill = 1
placed_n = 0
placed_last = -1
tracks_config(3, 4)
tracks_config_reading(1, 0.5, 2.5)
tracks_reset()
function fresh(base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) -> void {
tracks_test_st.now = 10.0
tracks_test_st.skill = 1
tracks_test_st.placed_n = 0
tracks_test_st.placed_last = -1
tracks_config(tracks_st, 3, 4)
tracks_config_reading(tracks_st, 1, 0.5, 2.5)
tracks_reset(base_st, tracks_st)
}
function reads() -> []TrackRead { return q_drain(tracks_reads()) }
function reads(base_st: mut BaseState, tracks_st: mut TracksState) -> []TrackRead { return q_drain(base_st, tracks_reads(base_st, tracks_st)) }
test "a print goes into its kind's ring and is drawn" {
fresh()
let i = tracks_leave(1, 5.0, 6.0, 1.0, 7, false)
test "a print goes into its kind's ring and is drawn" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
let i = tracks_leave(tracks_st, 1, 5.0, 6.0, 1.0, 7, false)
expect_eq(i, 0)
expect_eq(tracks_count(1), 1)
expect_eq(tracks_count(0), 0)
expect_eq(placed_n, 1)
let s = tracks_slot(1, 0)
expect(tracks_x(s) == 5.0 and tracks_z(s) == 6.0)
expect_eq(tracks_sp(s), 7)
expect_eq(tracks_count(tracks_st, 1), 1)
expect_eq(tracks_count(tracks_st, 0), 0)
expect_eq(tracks_test_st.placed_n, 1)
let s = tracks_slot(tracks_st, 1, 0)
expect(tracks_x(tracks_st, s) == 5.0 and tracks_z(tracks_st, s) == 6.0)
expect_eq(tracks_sp(tracks_st, s), 7)
}
test "a full ring writes over its oldest print" {
fresh()
for n in 0 .. 5 { tracks_leave(2, float(n), 0.0, 0.0, n, false) }
expect_eq(tracks_count(2), 4)
expect_eq(placed_last, 0)
expect_eq(tracks_sp(tracks_slot(2, 0)), 4)
test "a full ring writes over its oldest print" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
for n in 0 .. 5 { tracks_leave(tracks_st, 2, float(n), 0.0, 0.0, n, false) }
expect_eq(tracks_count(tracks_st, 2), 4)
expect_eq(tracks_test_st.placed_last, 0)
expect_eq(tracks_sp(tracks_st, tracks_slot(tracks_st, 2, 0)), 4)
}
test "a print ages on the world's clock" {
fresh()
tracks_leave(1, 0.0, 0.0, 0.0, 1, false)
now = 13.0
let s = tracks_slot(1, 0)
expect(tracks_age(s) == 3.0)
expect_eq(tracks_fresh_of(tracks_age(s)), TRACK_OLD)
expect_eq(tracks_fresh_of(0.2), TRACK_FRESH)
expect_eq(tracks_fresh_of(1.0), TRACK_RECENT)
test "a print ages on the world's clock" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_leave(tracks_st, 1, 0.0, 0.0, 0.0, 1, false)
tracks_test_st.now = 13.0
let s = tracks_slot(tracks_st, 1, 0)
expect(tracks_age(tracks_st, s) == 3.0)
expect_eq(tracks_fresh_of(tracks_st, tracks_age(tracks_st, s)), TRACK_OLD)
expect_eq(tracks_fresh_of(tracks_st, 0.2), TRACK_FRESH)
expect_eq(tracks_fresh_of(tracks_st, 1.0), TRACK_RECENT)
}
test "the nearest print within reach, or none" {
fresh()
tracks_leave(1, 10.0, 0.0, 0.0, 1, false)
tracks_leave(2, 1.0, 1.0, 0.0, 2, false)
expect_eq(tracks_nearest(0.0, 0.0, 2.0), tracks_slot(2, 0))
expect_eq(tracks_nearest(50.0, 50.0, 2.0), -1)
test "the nearest print within reach, or none" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_leave(tracks_st, 1, 10.0, 0.0, 0.0, 1, false)
tracks_leave(tracks_st, 2, 1.0, 1.0, 0.0, 2, false)
expect_eq(tracks_nearest(tracks_st, 0.0, 0.0, 2.0), tracks_slot(tracks_st, 2, 0))
expect_eq(tracks_nearest(tracks_st, 50.0, 50.0, 2.0), -1)
}
test "a print read twice is two facts and one count" {
fresh()
tracks_leave(1, 0.0, 0.0, 1.0, 3, true)
let s = tracks_nearest(0.0, 0.0, 2.0)
tracks_read(s)
tracks_read(s)
let rs = reads()
test "a print read twice is two facts and one count" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_leave(tracks_st, 1, 0.0, 0.0, 1.0, 3, true)
let s = tracks_nearest(tracks_st, 0.0, 0.0, 2.0)
tracks_read(base_st, tracks_st, s)
tracks_read(base_st, tracks_st, s)
let rs = reads(base_st, tracks_st)
expect_eq(len(rs), 2)
expect(rs[0].first and not rs[1].first)
expect_eq(rs[0].source, TRACK_PRINT)
expect_eq(rs[0].kind, 1)
expect(rs[0].legend)
expect(rs[0].bearing == "east")
expect_eq(tracks_read_count(), 1)
expect(tracks_has_bearing() and tracks_last_yaw() == 1.0)
expect_eq(tracks_read_count(tracks_st), 1)
expect(tracks_has_bearing(tracks_st) and tracks_last_yaw(tracks_st) == 1.0)
}
test "a reader without the skill cannot name the animal" {
fresh()
skill = 0
tracks_leave(1, 0.0, 0.0, 0.0, 3, false)
tracks_read(tracks_slot(1, 0))
expect(not reads()[0].named)
test "a reader without the skill cannot name the animal" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_test_st.skill = 0
tracks_leave(tracks_st, 1, 0.0, 0.0, 0.0, 3, false)
tracks_read(base_st, tracks_st, tracks_slot(tracks_st, 1, 0))
expect(not reads(base_st, tracks_st)[0].named)
}
test "a sign that is not a print is told, and counts when it is the first" {
fresh()
tracks_note(4, TRACK_SCAT, false, -1.0, true)
tracks_note(4, TRACK_SCAT, false, -1.0, false)
let rs = reads()
test "a sign that is not a print is told, and counts when it is the first" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_note(base_st, tracks_st, 4, TRACK_SCAT, false, -1.0, true)
tracks_note(base_st, tracks_st, 4, TRACK_SCAT, false, -1.0, false)
let rs = reads(base_st, tracks_st)
expect_eq(len(rs), 2)
expect_eq(rs[0].source, TRACK_SCAT)
expect_eq(tracks_read_count(), 1)
expect_eq(tracks_read_count(tracks_st), 1)
}
test "a written-over slot is a new, unread print" {
fresh()
tracks_leave(0, 0.0, 0.0, 0.0, 1, false)
tracks_read(tracks_slot(0, 0))
for n in 0 .. 4 { tracks_leave(0, 0.0, 0.0, 0.0, 2, false) }
expect(not tracks_was_read(tracks_slot(0, 0)))
test "a written-over slot is a new, unread print" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_leave(tracks_st, 0, 0.0, 0.0, 0.0, 1, false)
tracks_read(base_st, tracks_st, tracks_slot(tracks_st, 0, 0))
for n in 0 .. 4 { tracks_leave(tracks_st, 0, 0.0, 0.0, 0.0, 2, false) }
expect(not tracks_was_read(tracks_st, tracks_slot(tracks_st, 0, 0)))
}
test "clearing the ground forgets the prints, not the reader" {
fresh()
tracks_leave(1, 0.0, 0.0, 0.0, 1, false)
tracks_read(tracks_slot(1, 0))
tracks_clear()
expect_eq(tracks_count(1), 0)
expect_eq(tracks_read_count(), 1)
test "clearing the ground forgets the prints, not the reader" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_leave(tracks_st, 1, 0.0, 0.0, 0.0, 1, false)
tracks_read(base_st, tracks_st, tracks_slot(tracks_st, 1, 0))
tracks_clear(tracks_st)
expect_eq(tracks_count(tracks_st, 1), 0)
expect_eq(tracks_read_count(tracks_st), 1)
}
test "a save section reads back the same reader" {
fresh()
tracks_note(1, TRACK_SIGN, true, 0.0, true)
tracks_note_bearing(2.5)
test "a save section reads back the same reader" (base_st: mut BaseState, tracks_st: mut TracksState, tracks_test_st: mut TracksTestState) {
fresh(base_st, tracks_st, tracks_test_st)
tracks_note(base_st, tracks_st, 1, TRACK_SIGN, true, 0.0, true)
tracks_note_bearing(tracks_st, 2.5)
let root = save_tree()
save_section(root, "tracks", 1, tracks_save())
save_section(root, "tracks", 1, tracks_save(tracks_st))
let text = save_encode(root)
tracks_reset()
tracks_reset(base_st, tracks_st)
let n = load_section(save_decode(text), "tracks")
tracks_load(n.data, n.version)
expect_eq(tracks_read_count(), 1)
expect(tracks_has_bearing() and tracks_last_yaw() == 2.5)
tracks_load(base_st, tracks_st, n.data, n.version)
expect_eq(tracks_read_count(tracks_st), 1)
expect(tracks_has_bearing(tracks_st) and tracks_last_yaw(tracks_st) == 2.5)
}
}