wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic 1804 vars into 126 states, 64 into lets; 23498 edits in 460 files Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5ffe50ed02
commit
19fcf60599
459 changed files with 17862 additions and 17603 deletions
|
|
@ -4,26 +4,28 @@ numbers float
|
|||
import "ludic.base"
|
||||
export property Caught { species: int = 0, weight: float = 0.0 }
|
||||
export port FishingWorld { is_water: fn(float, float) -> bool } # its port
|
||||
var dice: Rng = null
|
||||
var casts: int = 0
|
||||
export var caught: Queue<Caught> = null # its facts
|
||||
export function fishing_cast(x: float, z: float) -> bool { # its verb
|
||||
export state ToyFishingState {
|
||||
dice: Rng = null
|
||||
casts: int = 0
|
||||
caught: Queue<Caught> = null # its facts
|
||||
}
|
||||
export function fishing_cast(toy_fishing_st: mut ToyFishingState, x: float, z: float) -> bool { # its verb
|
||||
if not FishingWorld.is_water(x, z) { return false }
|
||||
casts += 1
|
||||
toy_fishing_st.casts += 1
|
||||
return true
|
||||
}
|
||||
function fishing_reset() -> void {
|
||||
casts = 0
|
||||
dice = rng_new(7)
|
||||
caught = queue_new("fishing.caught")
|
||||
function fishing_reset(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState) -> void {
|
||||
toy_fishing_st.casts = 0
|
||||
toy_fishing_st.dice = rng_new(7)
|
||||
toy_fishing_st.caught = queue_new(base_st, "fishing.caught")
|
||||
}
|
||||
function fishing_tick(t: Tick) -> void {
|
||||
while casts > 0 {
|
||||
function fishing_tick(base_st: mut BaseState, toy_fishing_st: mut ToyFishingState, t: Tick) -> void {
|
||||
while toy_fishing_st.casts > 0 {
|
||||
let c = new Caught
|
||||
c.species = rng_between(dice, 0, 2)
|
||||
c.weight = 0.5 + rng_float(dice)
|
||||
q_push(caught, c)
|
||||
casts -= 1
|
||||
c.species = rng_between(toy_fishing_st.dice, 0, 2)
|
||||
c.weight = 0.5 + rng_float(toy_fishing_st.dice)
|
||||
q_push(base_st, toy_fishing_st.caught, c)
|
||||
toy_fishing_st.casts -= 1
|
||||
}
|
||||
}
|
||||
export function fishing_system() -> System {
|
||||
|
|
|
|||
|
|
@ -2,22 +2,24 @@
|
|||
module toy_pack uses ludic_base
|
||||
numbers float
|
||||
import "ludic.base"
|
||||
var counts: []int = null
|
||||
export function pack_add(kind: int, n: int) -> void { counts[kind] = counts[kind] + n }
|
||||
export function pack_count(kind: int) -> int { return counts[kind] }
|
||||
function pack_reset() -> void {
|
||||
counts = new []int
|
||||
for i in 0 .. 3 { push(counts, 0) }
|
||||
export state ToyPackState {
|
||||
counts: []int = null
|
||||
}
|
||||
function pack_save() -> Val {
|
||||
export function pack_add(toy_pack_st: mut ToyPackState, kind: int, n: int) -> void { toy_pack_st.counts[kind] = toy_pack_st.counts[kind] + n }
|
||||
export function pack_count(toy_pack_st: ToyPackState, kind: int) -> int { return toy_pack_st.counts[kind] }
|
||||
function pack_reset(toy_pack_st: mut ToyPackState) -> void {
|
||||
toy_pack_st.counts = new []int
|
||||
for i in 0 .. 3 { push(toy_pack_st.counts, 0) }
|
||||
}
|
||||
function pack_save(toy_pack_st: ToyPackState) -> Val {
|
||||
let v = Value.object()
|
||||
sv_put_ints(v, "counts", counts)
|
||||
sv_put_ints(v, "counts", toy_pack_st.counts)
|
||||
return v
|
||||
}
|
||||
function pack_load(v: Val, version: int) -> void {
|
||||
pack_reset()
|
||||
function pack_load(toy_pack_st: mut ToyPackState, v: Val, version: int) -> void {
|
||||
pack_reset(toy_pack_st)
|
||||
let xs = sv_ints(v, "counts")
|
||||
for i in 0 .. len(xs) { if i < len(counts) { counts[i] = xs[i] } }
|
||||
for i in 0 .. len(xs) { if i < len(toy_pack_st.counts) { toy_pack_st.counts[i] = xs[i] } }
|
||||
}
|
||||
export function pack_system() -> System {
|
||||
let s = system_new("pack", PH_COMMIT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue