39 lines
1.5 KiB
Text
39 lines
1.5 KiB
Text
# 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(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(tracks_st: mut TracksState, kind: int, x: float, z: float, yaw: float, sp: int, legend: bool, maker: int, 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
|
|
}
|
|
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
|
|
t.sp = sp
|
|
t.legend = legend
|
|
t.maker = maker
|
|
t.made = made
|
|
t.read = false
|
|
TracksWorld.placed(kind, i)
|
|
return i
|
|
}
|
|
|
|
export function tracks_leave(tracks_st: mut TracksState, kind: int, x: float, z: float, yaw: float, sp: int, legend: bool, maker: int) -> int {
|
|
return tracks_leave_at(tracks_st, kind, x, z, yaw, sp, legend, maker, tk_now())
|
|
}
|
|
|
|
# the ground forgets every print (a new world)
|
|
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
|
|
}
|
|
tracks_st.tk_chain = -1
|
|
}
|