ludic/examples/networking/net_rpc.ludic
Orkuncakilkaya bf36bc8a8f refactor(runtime,packages,examples): named constants, package enums, idiom sweep
- runtime: HEADLESS_FRAME_PATH, STICK_DEADZONE / STICK_LEFT_X/Y, key and
  byte codes as char literals throughout (`k == 'w'`, `fill(rt_map, ' ', …)`)
- ludic.gameplay/stats: drop the duplicate `stat_field` (it answered "atk"
  for every build stat); Stats.base uses stats_field_name
- ludic.shooter: compare aim modes and fire patterns with AimMode.* and
  WeaponPattern.* instead of raw ints; STICK_RIGHT_X/Y
- ludic.npcai: DecisionMade / brain_set_state use AiState.*
- examples/games/menu.ludic uses Font.load / Ui.* with FONT_PATH and
  BACKDROP named; strings.ludic header says what it prints
- whole tree: `x = x + 1` → `x += 1` (single-term right-hand sides only),
  `0 - x` → `-x`, ASCII codes → char literals; every .ludic and every
  ```ludic fence reformatted with the fixed formatter (whitespace only)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 01:12:26 +03:00

29 lines
1.2 KiB
Text

# net_rpc.ludic — N4: remote events / RPCs (NETWORKING-DESIGN §6.4, §13 N4).
#
# An `event` marked @ToServer (client→server) or @ToClients (server→clients) is a
# directional remote event — the event bus with a direction flag, no new concept.
# At an `emit` site the POD payload is serialized as [event id][fields] and
# net_send in its direction; net_pump() drains inbound frames and re-emits each
# into the ordinary @On dispatch on the far side. So `emit Fire(...)` is a remote
# call — it does not run locally; the receiver's pump runs the handler.
#
# Here two Fire RPCs are emitted (dir 5, dir 3). Before net_pump the handler has
# not run (hits still 0); after, both are drained and re-emitted (5 + 3 = 8).
program NetRpc {
property Log { hits: int = 0 }
model Sink { Log }
@ToServer event Fire { dir: int = 0 }
@On(Fire) handler OnFire {
for (Log) in query [Log] { Log.hits += dir }
}
entry {
spawn Sink { Log { hits: 0 } }
emit Fire(dir: 5) # serialized onto the wire (not run locally)
emit Fire(dir: 3)
for (Log) in query [Log] { print(Log.hits) } # 0
net_pump() # drain + re-emit both RPCs
for (Log) in query [Log] { print(Log.hits) } # 8
}
}