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:
Orkun ÇAKILKAYA 2026-09-27 01:29:32 +03:00
parent 63c30b9ebe
commit 9e4f4edb92
21 changed files with 98 additions and 163 deletions

View file

@ -22,7 +22,6 @@ export function nb_copy(dst: []byte, d: int, src: []byte, s: int, n: int) -> voi
# the writer: past the MTU it counts on and keeps nothing, and np_queue cuts the message there
export function nw_begin(net_st: mut NetState) -> void {
net__init(net_st)
net_st.net__wl = 0
}
@ -82,7 +81,6 @@ export function nr_bad(net_st: NetState) -> bool { return net_st.net__rbad }
# a message that came in, made the one nr_* reads
export function net_read(net_st: mut NetState, m: NetMessage) -> void {
net__init(net_st)
nb_copy(net_st.net__rb, 0, m.data, 0, m.len)
net_st.net__rl = m.len
net_st.net__rp = 0
@ -90,8 +88,7 @@ export function net_read(net_st: mut NetState, m: NetMessage) -> void {
}
# the message just written, as if it had come in (a loopback: a test, a host telling itself)
export function net_written(net_st: mut NetState) -> NetMessage {
net__init(net_st)
export function net_written(net_st: NetState) -> NetMessage {
let m = new NetMessage
m.from = net_st.net__my_pid
m.len = min(net_st.net__wl, NET_MTU)

View file

@ -29,7 +29,6 @@ export function net_room_join(net_st: mut NetState, code: string) -> bool {
net_st.net__why = NET_WHY_NO_MATCHMAKER
return false
}
net__init(net_st)
if not net__socket(net_st) { return false }
net_st.net__r_role = 2
net_st.net__room = Text.upper(code)

View file

@ -3,7 +3,6 @@
# open a socket on `port` and take guests; false (net_why) when the port is taken
export function net_host(net_st: mut NetState, port: int, token: int) -> bool {
net__init(net_st)
if net_live(net_st) { return true }
net_st.net__sock = NetSocket.open(port)
if net_st.net__sock <= 0 {
@ -20,7 +19,6 @@ export function net_host(net_st: mut NetState, port: int, token: int) -> bool {
# dial a host at an address; the hello (net_hello_set) goes until a welcome or a refusal
export function net_join(net_st: mut NetState, ip: int, port: int) -> bool {
net__init(net_st)
if net_live(net_st) { return false }
if not net__socket(net_st) { return false }
for i in 0 .. NET_PEERS { np_close(net_st, i) }
@ -42,7 +40,6 @@ function net__socket(net_st: mut NetState) -> bool {
# the message just written is the hello: what a host is asked to let this machine in with
export function net_hello_set(net_st: mut NetState) -> void {
net__init(net_st)
nb_copy(net_st.net__hello_b, 0, net_st.net__wb, 0, net_st.net__wl)
net_st.net__hello_l = net_st.net__wl
if net_st.net__hello_l > NET_MTU - 40 { net_st.net__hello_l = NET_MTU - 40 }
@ -50,7 +47,6 @@ export function net_hello_set(net_st: mut NetState) -> void {
# (again) to that address, with a fresh connection and the hello sent anew
export function net_dial(net_st: mut NetState, ip: int, port: int) -> void {
net__init(net_st)
np_close(net_st, 0)
net_st.net__join_ip = ip
net_st.net__join_port = port
@ -70,7 +66,6 @@ export function net_follow(net_st: mut NetState, ip: int, port: int) -> void {
export function net_stand_alone(net_st: mut NetState) -> void { net_st.net__state = NET_IDLE }
export function net_become_host(net_st: mut NetState, token: int) -> void {
net__init(net_st)
net_st.net__state = NET_HOSTING
net_st.net__my_pid = 1
net_st.net__next_pid = 2

View file

@ -79,17 +79,17 @@ export state NetState {
net__token: int = 0
net__my_pid: int = 0
net__next_pid: int = 2
net__peers: []NetPeer = null
net__in: []byte = null
net__out: []byte = null
net__wb: []byte = null # the message being written
net__peers: []NetPeer = net__peers_new()
net__in: []byte = buffer(NET_MTU + 64)
net__out: []byte = buffer(NET_MTU + 64)
net__wb: []byte = buffer(NET_MTU) # the message being written
net__wl: int = 0
net__rb: []byte = null # the message being read
net__rb: []byte = buffer(NET_MTU) # the message being read
net__rl: int = 0
net__rp: int = 0
net__rbad: bool = false
net__tb: []byte = buffer(NET_MTU) # text read out of a message, through one scratch buffer
net__hello_b: []byte = null # the game's hello, sent again on every dial
net__hello_b: []byte = buffer(NET_MTU) # the game's hello, sent again on every dial
net__hello_l: int = 0
net__hello_t: float = 0.0 # seconds since it went; -1 not yet
net__wait_more: int = 0 # extra seconds a slow host is given (a map switch, a matchmaker)
@ -111,19 +111,15 @@ export function net_inbox(net_st: NetState) -> Queue<NetMessage> {
return net_st.net__inbox
}
function net__init(net_st: mut NetState) -> void {
if net_st.net__peers != null { return }
net_st.net__peers = new []NetPeer
function net__facts__new() -> Queue<NetFact> { return queue_new("net.facts") }
function net__inbox__new() -> Queue<NetMessage> { return queue_new("net.inbox") }
# every peer slot, each with its own queue
function net__peers_new() -> []NetPeer {
let out = new []NetPeer
for i in 0 .. NET_PEERS {
let p = new NetPeer
p.queue = new []NetMsg
push(net_st.net__peers, p)
push(out, p)
}
net_st.net__in = buffer(NET_MTU + 64)
net_st.net__out = buffer(NET_MTU + 64)
net_st.net__wb = buffer(NET_MTU)
net_st.net__rb = buffer(NET_MTU)
net_st.net__hello_b = buffer(NET_MTU)
return out
}
function net__facts__new() -> Queue<NetFact> { return queue_new("net.facts") }
function net__inbox__new() -> Queue<NetMessage> { return queue_new("net.inbox") }