ludic/packages/ludic.session/state.ludic
Orkuncakilkaya 71735b10a2 feat(base): 0.R4 - a queue keeps its own count, so every package verb takes only its own state; ludic migrate state --prune
ludic.base's Queue<T> carries a QueueTag (its name and pending count): queue_new(name), q_push(q, v),
q_drain(q), q_clear(q) take no BaseState, and core_undrained(tags) names the given queues still holding
facts. A reducer on a package's state can now call that package's verbs (wallet_earn(wallet_st, n)).

ludic migrate state --prune (ludicc --migrate-prune) takes out each state parameter a function no
longer uses, nor anything it calls, and the argument that fills it - including an argument for a
parameter the callee has dropped, which is taken out before the call is checked, so a generic's T is
told by the argument that says it. A reducer keeps its state. --dry-run now counts the edits it would
make. Every package was moved with it: 608 base_st parameters and their arguments, 1889 edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 04:19:56 +03:00

101 lines
3.3 KiB
Text

# state.ludic - a roster slot, the local player's port, the roles, and the facts the game drains
export const PLY_MAX: int = 12 # a party: this player and eleven more
export const SES_SOLO: int = 0
export const SES_HOST: int = 1
export const SES_GUEST: int = 2
# what happened: a player in or out (slot, pid), the role changed (role), a vote opened, this
# guest's own vote to send, a vote decided (id, kind, param, passed, text), everyone in for the
# night (the host), this player turned in or got up (yes)
export const SES_JOINED: int = 0
export const SES_LEFT: int = 1
export const SES_ROLE: int = 2
export const SES_VOTE_OPENED: int = 3
export const SES_VOTE_CAST: int = 4
export const SES_VOTE_RESOLVED: int = 5
export const SES_NIGHT: int = 6
export const SES_SLEEP: int = 7
export property SessionFact {
what: int = 0,
slot: int = -1,
pid: int = 0,
role: int = 0,
id: int = 0,
kind: int = 0,
param: int = 0,
yes: bool = false,
text: string = ""
}
# a remote player, as its own machine reported it
property PartyMember {
on: bool = false,
pid: int = 0, # the session's id for them (0 is never a remote player)
name: string = "",
x: float = 0.0,
y: float = 0.0,
z: float = 0.0,
yaw: float = 0.0,
speed: float = 0.0,
rest: float = 1.0, # how much faster their rest runs the clock (1 on their feet)
sleeping: bool = false, # turned in, as their body says
ready: bool = false # turned in, as they told the host (the host's count for the night)
}
# this machine's player, read live
export port SessionLocal {
x: fn() -> float
y: fn() -> float
z: fn() -> float
yaw: fn() -> float = fn session__zero
speed: fn() -> float = fn session__zero
rest: fn() -> float = fn session__one
name: fn() -> string = fn session__nameless
}
function session__zero() -> float { return 0.0 }
function session__one() -> float { return 1.0 }
function session__nameless() -> string { return "" }
export state SessionState {
session__me_sleeping: bool = false
session__slot: []PartyMember = null
session__role: int = 0
session__max: int = 4
session__open: bool = true
session__near_i: int = 0
session__facts: Queue<SessionFact> = null
session__vote_id: int = 0
session__vote_kind: int = 0
session__vote_param: int = 0
session__vote_text: string = ""
session__vote_t: float = 0.0
session__vote_yes: int = 0
session__vote_no: int = 0
session__vote_mine: int = -1 # -1 not voted, 0 no, 1 yes
session__vote_passed: int = -1 # the last vote: -1 none, 0 failed, 1 passed
}
export function ses_facts(session_st: mut SessionState) -> Queue<SessionFact> {
if session_st.session__facts == null { session_st.session__facts = queue_new("session.facts") }
return session_st.session__facts
}
function session__fact(session_st: mut SessionState, what: int, slot: int, pid: int) -> SessionFact {
let f = new SessionFact
f.what = what
f.slot = slot
f.pid = pid
f.role = session_st.session__role
q_push(ses_facts(session_st), f)
return f
}
function session__init(session_st: mut SessionState) -> void {
if session_st.session__slot != null { return }
session_st.session__slot = new []PartyMember
for i in 0 .. PLY_MAX { push(session_st.session__slot, new PartyMember) }
session_st.session__slot[0].on = true
}