refactor(packages): 0.R5 - jobs, session, settings, hints and net make their tables when the state is made, not on the first question (jobs__ensure, session__init and ply_init, sg_init, hn_mute_ensure, net__init gone); their questions read
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
63c30b9ebe
commit
9e4f4edb92
21 changed files with 98 additions and 163 deletions
|
|
@ -34,7 +34,7 @@ down ends the night). The transport says what this machine became (`ses_set_role
|
|||
|
||||
| | |
|
||||
| --- | --- |
|
||||
| `ply_init()`, `ply_join(pid) -> slot`, `ply_leave(p)`, `ply_leave_all()` | the roster (-1: full, or pid 0) |
|
||||
| `ply_join(pid) -> slot`, `ply_leave(p)`, `ply_leave_all()` | the roster (-1: full, or pid 0) |
|
||||
| `ply_report(p, x, y, z, yaw, speed)`, `ply_report_rest(p, rest, sleeping)`, `ply_report_name(p, name)` | what a remote machine said |
|
||||
| `ply_on`, `ply_is_local`, `ply_slot_of(pid)`, `ply_count`, `ply_pid`, `ply_name`, `ply_x/y/z/yaw/speed/rest(p)`, `ply_sleeping(p)` | who and where |
|
||||
| `ply_near(x, z)`, `ply_near_d2`, `ply_near_i()`, `ply_dist(p, x, z)` | the nearest player |
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
# roster.ludic - who is here. Slot 0 is this machine's player and reads the SessionLocal port
|
||||
# live; slots 1.. are remote players, filled by what their machines report.
|
||||
export function ply_init(session_st: mut SessionState) -> void { session__init(session_st) }
|
||||
|
||||
export function ply_on(session_st: SessionState, p: int) -> bool {
|
||||
if p == 0 { return true }
|
||||
|
|
@ -26,7 +25,6 @@ export function ply_count(session_st: SessionState) -> int {
|
|||
# a remote player comes in, standing where this one stands until they say: the first free
|
||||
# slot, or -1 when the party is full
|
||||
export function ply_join(session_st: mut SessionState, pid: int) -> int {
|
||||
session__init(session_st)
|
||||
if pid <= 0 { return -1 } # 0 is this machine's player
|
||||
for p in 1 .. PLY_MAX {
|
||||
if session_st.session__slot[p].on { continue }
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ function session__nameless() -> string { return "" }
|
|||
|
||||
export state SessionState {
|
||||
session__me_sleeping: bool = false
|
||||
session__slot: []PartyMember = null
|
||||
session__slot: []PartyMember = session__slots()
|
||||
session__role: int = 0
|
||||
session__max: int = 4
|
||||
session__open: bool = true
|
||||
|
|
@ -92,10 +92,11 @@ function session__fact(session_st: SessionState, what: int, slot: int, pid: int)
|
|||
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
|
||||
}
|
||||
function session__facts__new() -> Queue<SessionFact> { return queue_new("session.facts") }
|
||||
# the roster's slots, slot 0 this machine's own and on
|
||||
function session__slots() -> []PartyMember {
|
||||
let out = new []PartyMember
|
||||
for i in 0 .. PLY_MAX { push(out, new PartyMember) }
|
||||
out[0].on = true
|
||||
return out
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,12 @@ program SessionTest {
|
|||
|
||||
# a host with n guests, pids 2.., facts drained
|
||||
function party(session_st: mut SessionState, n: int) -> void {
|
||||
ply_init(session_st)
|
||||
ses_set_role(session_st, SES_HOST)
|
||||
for i in 0 .. n { ply_join(session_st, 2 + i) }
|
||||
q_clear(ses_facts(session_st))
|
||||
}
|
||||
|
||||
test "slot 0 is the local player, read live; others join at its feet and leave" (session_st: mut SessionState, session_test_st: mut SessionTestState) {
|
||||
ply_init(session_st)
|
||||
session_test_st.me_x = 5.0
|
||||
expect(ply_on(session_st, 0))
|
||||
expect_near(ply_x(session_st, 0), 5.0, 0.001)
|
||||
|
|
@ -58,14 +56,12 @@ program SessionTest {
|
|||
}
|
||||
|
||||
test "the roster fills at twelve" (session_st: mut SessionState) {
|
||||
ply_init(session_st)
|
||||
for i in 0 .. PLY_MAX - 1 { expect(ply_join(session_st, 10 + i) > 0) }
|
||||
expect_eq(ply_join(session_st, 99), -1)
|
||||
expect_eq(ply_count(session_st), PLY_MAX)
|
||||
}
|
||||
|
||||
test "the nearest player, whoever it is" (session_st: mut SessionState, session_test_st: mut SessionTestState) {
|
||||
ply_init(session_st)
|
||||
session_test_st.me_x = 100.0
|
||||
let p = ply_join(session_st, 2)
|
||||
ply_report(session_st, p, 3.0, 0.0, 4.0, 0.0, 1.0)
|
||||
|
|
@ -75,7 +71,6 @@ program SessionTest {
|
|||
}
|
||||
|
||||
test "roles: alone owns the world, a guest does not, and a change is a fact" (session_st: mut SessionState) {
|
||||
ply_init(session_st)
|
||||
expect(ses_owns_world(session_st))
|
||||
expect(not ses_live(session_st))
|
||||
expect(ses_night_passes(session_st))
|
||||
|
|
@ -115,7 +110,6 @@ program SessionTest {
|
|||
}
|
||||
|
||||
test "a guest's turning in is a fact for the host to hear; alone a bed just sleeps" (session_st: mut SessionState) {
|
||||
ply_init(session_st)
|
||||
expect(not ses_sleep(session_st, true))
|
||||
ses_set_role(session_st, SES_GUEST)
|
||||
q_clear(ses_facts(session_st))
|
||||
|
|
@ -153,7 +147,6 @@ program SessionTest {
|
|||
}
|
||||
|
||||
test "alone it may go; a guest may not, and its vote goes to the host" (session_st: mut SessionState) {
|
||||
ply_init(session_st)
|
||||
expect_eq(ses_may(session_st, 1, 0, "x"), SES_MAY_GO)
|
||||
ses_set_role(session_st, SES_GUEST)
|
||||
expect_eq(ses_may(session_st, 1, 0, "x"), SES_MAY_HOSTS)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue