ludic.devlink: an editor's live link into a running dev build (protocol v1, stage 1)
A package on ludic.base alone. DevlinkNet is the transport (a game binds Udp, the test a fake); DevlinkWorld's members are the verbs, each defaulting to "not offered" (err unbound): ping, hello (with Build.schema_hash as 16 hex digits), cam_get / cam_set / cam_release, goto, map_load, time, weather, shot, pause / resume / step. One request a frame, parsed in place from a fixed 8 KB buffer and answered into another; map_load, shot and step answer later by id, one at a time, 5 s at most. Loopback senders only, opened only when enabled() (dev_tools), co-op refuses everything but ping and hello. tests/devlink_test: each answer byte for byte, bad arguments, a stranger dropped, co-op, the late answers and their timeout, a closed build that never opens. Compiles; not run (the Master runs the package tests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dd1e852356
commit
18755d9057
14 changed files with 723 additions and 0 deletions
30
packages/ludic.devlink/system.ludic
Normal file
30
packages/ludic.devlink/system.ludic
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# system.ludic - a frame of the link, first thing in PH_INPUT: a waiting answer sent when it is done, then
|
||||
# at most one request read, answered and sent. A build whose `enabled` says no never opens the socket.
|
||||
export function devlink_system() -> System {
|
||||
let s = system_new("devlink", PH_INPUT)
|
||||
s.tick = fn devlink_tick
|
||||
return s
|
||||
}
|
||||
|
||||
export function devlink_tick(devlink_st: mut DevlinkState, t: Tick) -> void {
|
||||
if not DevlinkWorld.enabled() { return }
|
||||
if devlink_st.dl_h < 0 {
|
||||
if devlink_st.dl_tried { return }
|
||||
devlink_st.dl_tried = true
|
||||
devlink_st.dl_h = DevlinkNet.open(DevlinkWorld.port())
|
||||
if devlink_st.dl_h < 0 { return }
|
||||
}
|
||||
let h = devlink_st.dl_h
|
||||
if devlink_late(devlink_st, t.dt) { DevlinkNet.send(h, devlink_st.dl_pend_ip, devlink_st.dl_pend_port, devlink_st.dl_out, devlink_st.dl_o) }
|
||||
let n = DevlinkNet.recv(h, devlink_st.dl_in, DL_BUF)
|
||||
if n <= 0 { return }
|
||||
devlink_st.dl_ip = DevlinkNet.from_ip(h)
|
||||
devlink_st.dl_port = DevlinkNet.from_port(h)
|
||||
if not DevlinkNet.loopback(devlink_st.dl_ip) { return } # only this machine
|
||||
devlink_st.dl_n = n
|
||||
devlink_handle(devlink_st)
|
||||
if devlink_st.dl_o > 0 { DevlinkNet.send(h, devlink_st.dl_ip, devlink_st.dl_port, devlink_st.dl_out, devlink_st.dl_o) }
|
||||
}
|
||||
|
||||
# whether a request is waiting on a slow answer (a map load, a shot, steps)
|
||||
export function devlink_waiting(devlink_st: DevlinkState) -> bool { return devlink_st.dl_pend != DL_NONE }
|
||||
Loading…
Add table
Add a link
Reference in a new issue