wip(0.S2): migrate - a var nothing writes becomes a let; a state is keyed by its module, directory or program, so every program's plan agrees; paths normalized; program states named SceneDemoState / scene_demo_st; the LSP reads state, mut and entry/handler parameters
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3eda72e8c2
commit
5ffe50ed02
463 changed files with 72045 additions and 67421 deletions
|
|
@ -3,31 +3,31 @@
|
|||
# highest reliable id taken in order, a message count - then each message: kind, flags, a
|
||||
# reliable id when it is reliable, a 16-bit length, the payload. A reliable message goes again
|
||||
# every quarter second until acknowledged; an unreliable one half a second old is dropped.
|
||||
export function np_flush(net_st: mut NetState, slot: int) -> void {
|
||||
if not net_peer_on(net_st, slot) { return }
|
||||
let p = net_st.net__peers[slot]
|
||||
export function np_flush(slot: int) -> void {
|
||||
if not net_peer_on(slot) { return }
|
||||
let p = net__peers[slot]
|
||||
for pk in 0 .. 8 {
|
||||
if not net__flush_one(net_st, p) { return }
|
||||
if not net__flush_one(p) { return }
|
||||
}
|
||||
}
|
||||
|
||||
function net__flush_one(net_st: mut NetState, p: NetPeer) -> bool {
|
||||
function net__flush_one(p: NetPeer) -> bool {
|
||||
var o = 20
|
||||
var count = 0
|
||||
let keep = new []NetMsg
|
||||
for i in 0 .. len(p.queue) {
|
||||
let m = p.queue[i]
|
||||
if m.rel and m.id <= p.acked { continue } # taken: drop it
|
||||
if not m.rel and net_st.net__time - m.made > 0.5 { continue } # stale
|
||||
if not m.rel and net__time - m.made > 0.5 { continue } # stale
|
||||
var due = true
|
||||
if m.rel and not (m.sent < 0.0) and net_st.net__time - m.sent < 0.25 { due = false }
|
||||
if m.rel and not (m.sent < 0.0) and net__time - m.sent < 0.25 { due = false }
|
||||
var size = 4 + m.len
|
||||
if m.rel { size += 4 }
|
||||
if due and o + size <= NET_MTU and count < 250 {
|
||||
o = net__put_msg(net_st, o, m)
|
||||
o = net__put_msg(o, m)
|
||||
count += 1
|
||||
m.sent = net_st.net__time
|
||||
if net_st.net__kind_out != null and m.kind < 64 { net_st.net__kind_out[m.kind] += size }
|
||||
m.sent = net__time
|
||||
if net__kind_out != null and m.kind < 64 { net__kind_out[m.kind] += size }
|
||||
if m.rel { push(keep, m) } # kept until acknowledged
|
||||
} else {
|
||||
push(keep, m) # not due, or waits for the next packet
|
||||
|
|
@ -35,47 +35,47 @@ function net__flush_one(net_st: mut NetState, p: NetPeer) -> bool {
|
|||
}
|
||||
p.queue = keep
|
||||
if count == 0 and not p.ack_due { return false }
|
||||
nb_put8(net_st.net__out, 0, 'M')
|
||||
nb_put8(net_st.net__out, 1, 'L')
|
||||
nb_put8(net_st.net__out, 2, net__conf(net_st).proto)
|
||||
nb_put8(net_st.net__out, 3, 1)
|
||||
nb_put32(net_st.net__out, 4, net_st.net__token)
|
||||
nb_put32(net_st.net__out, 8, net_st.net__my_pid)
|
||||
nb_put32(net_st.net__out, 12, p.recv_id)
|
||||
nb_put32(net_st.net__out, 16, count)
|
||||
let sent = net__relay_send(net_st, p, o)
|
||||
if sent > 0 { net_st.net__bytes_out += sent + 28 } # with the IP and UDP headers: what the line carries
|
||||
nb_put8(net__out, 0, 'M')
|
||||
nb_put8(net__out, 1, 'L')
|
||||
nb_put8(net__out, 2, net__conf().proto)
|
||||
nb_put8(net__out, 3, 1)
|
||||
nb_put32(net__out, 4, net__token)
|
||||
nb_put32(net__out, 8, net__my_pid)
|
||||
nb_put32(net__out, 12, p.recv_id)
|
||||
nb_put32(net__out, 16, count)
|
||||
let sent = net__relay_send(p, o)
|
||||
if sent > 0 { net__bytes_out += sent + 28 } # with the IP and UDP headers: what the line carries
|
||||
if NetWorld.trace() { net__log(`out {o} bytes to {Udp.ip_text(p.ip)}:{p.port}: {sent}`) }
|
||||
p.ack_due = false
|
||||
return count > 0
|
||||
}
|
||||
|
||||
function net__put_msg(net_st: NetState, at: int, m: NetMsg) -> int {
|
||||
function net__put_msg(at: int, m: NetMsg) -> int {
|
||||
var o = at
|
||||
nb_put8(net_st.net__out, o, m.kind)
|
||||
nb_put8(net_st.net__out, o + 1, 0)
|
||||
if m.rel { nb_put8(net_st.net__out, o + 1, 1) }
|
||||
nb_put8(net__out, o, m.kind)
|
||||
nb_put8(net__out, o + 1, 0)
|
||||
if m.rel { nb_put8(net__out, o + 1, 1) }
|
||||
o += 2
|
||||
if m.rel {
|
||||
nb_put32(net_st.net__out, o, m.id)
|
||||
nb_put32(net__out, o, m.id)
|
||||
o += 4
|
||||
}
|
||||
nb_put8(net_st.net__out, o, m.len & 255)
|
||||
nb_put8(net_st.net__out, o + 1, (m.len >> 8) & 255)
|
||||
nb_put8(net__out, o, m.len & 255)
|
||||
nb_put8(net__out, o + 1, (m.len >> 8) & 255)
|
||||
o += 2
|
||||
nb_copy(net_st.net__out, o, m.data, 0, m.len)
|
||||
nb_copy(net__out, o, m.data, 0, m.len)
|
||||
return o + m.len
|
||||
}
|
||||
|
||||
# the per-kind byte count starts again (a game measuring what a party costs its upload)
|
||||
export function net_kind_out_clear(net_st: mut NetState) -> void {
|
||||
net_st.net__kind_out = words(64)
|
||||
for k in 0 .. 64 { net_st.net__kind_out[k] = 0 }
|
||||
export function net_kind_out_clear() -> void {
|
||||
net__kind_out = words(64)
|
||||
for k in 0 .. 64 { net__kind_out[k] = 0 }
|
||||
}
|
||||
|
||||
export function net_kind_bytes(net_st: NetState, kind: int) -> int {
|
||||
if net_st.net__kind_out == null or kind < 0 or kind >= 64 { return 0 }
|
||||
return net_st.net__kind_out[kind]
|
||||
export function net_kind_bytes(kind: int) -> int {
|
||||
if net__kind_out == null or kind < 0 or kind >= 64 { return 0 }
|
||||
return net__kind_out[kind]
|
||||
}
|
||||
|
||||
export function net_bytes_out(net_st: NetState) -> int { return net_st.net__bytes_out }
|
||||
export function net_bytes_out() -> int { return net__bytes_out }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue