refactor(packages): 0.R5 - a question no longer starts its state - 64 lazy starts ('if st.x == null { st.x = ... }' inside a getter) are the state's defaults, gear__ensure is gone, and ludic migrate state --tighten took mut off 208 package parameters: things_all, thing_find, gear_charge, gear_level, jobs_state and the rest read
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
54f5efb23f
commit
9862ec82e3
102 changed files with 320 additions and 351 deletions
|
|
@ -21,7 +21,7 @@ export function thing_prompt(t: Thing) -> string {
|
|||
}
|
||||
|
||||
# the kind does what using it does; the use is a fact whatever the kind made of it
|
||||
export function thing_use(things_st: mut ThingsState, t: Thing) -> void {
|
||||
export function thing_use(things_st: ThingsState, t: Thing) -> void {
|
||||
if t == null or not thing_kind_ok(t.kind) { return }
|
||||
let k = ThingKinds[t.kind]
|
||||
th_fact(things_st, THING_USED, t)
|
||||
|
|
@ -46,7 +46,7 @@ export function thing_is_personal(t: Thing) -> bool { return thing_kind_ok(t.kin
|
|||
export function thing_is_put_down(t: Thing) -> bool { return ThingsWorld.put_down(t) }
|
||||
|
||||
# every active Thing whose kind ticks, `hours` of the world's clock on
|
||||
export function things_tick(things_st: mut ThingsState, hours: float) -> void {
|
||||
export function things_tick(things_st: ThingsState, hours: float) -> void {
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) {
|
||||
let t = all[i]
|
||||
|
|
@ -58,7 +58,7 @@ export function things_tick(things_st: mut ThingsState, hours: float) -> void {
|
|||
|
||||
# a restock: every Thing the world grew is back, and loses its `used` unless its kind keeps it;
|
||||
# what was put down is left as it is
|
||||
export function things_restock(things_st: mut ThingsState) -> void {
|
||||
export function things_restock(things_st: ThingsState) -> void {
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) {
|
||||
let t = all[i]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
function th_of(t: Thing, kind: int) -> bool { return kind < 0 or t.kind == kind }
|
||||
|
||||
# the first active one of a kind (and of that id, unless id < 0), in the order placed
|
||||
export function thing_find(things_st: mut ThingsState, kind: int, id: int) -> Thing {
|
||||
export function thing_find(things_st: ThingsState, kind: int, id: int) -> Thing {
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) {
|
||||
let t = all[i]
|
||||
|
|
@ -12,14 +12,14 @@ export function thing_find(things_st: mut ThingsState, kind: int, id: int) -> Th
|
|||
return null
|
||||
}
|
||||
|
||||
export function thing_by_uid(things_st: mut ThingsState, uid: int) -> Thing {
|
||||
export function thing_by_uid(things_st: ThingsState, uid: int) -> Thing {
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) { if all[i].uid == uid { return all[i] } }
|
||||
return null
|
||||
}
|
||||
|
||||
# the nearest active one of a kind to (x, z), or null
|
||||
export function thing_nearest(things_st: mut ThingsState, kind: int, x: float, z: float) -> Thing {
|
||||
export function thing_nearest(things_st: ThingsState, kind: int, x: float, z: float) -> Thing {
|
||||
var best: Thing = null
|
||||
var bd = 0.0
|
||||
let all = things_all(things_st)
|
||||
|
|
@ -43,7 +43,7 @@ export function thing_dist2(t: Thing, x: float, z: float) -> float {
|
|||
}
|
||||
|
||||
# every active one within r of (x, z), nearest first
|
||||
export function things_within(things_st: mut ThingsState, x: float, z: float, r: float) -> []Thing {
|
||||
export function things_within(things_st: ThingsState, x: float, z: float, r: float) -> []Thing {
|
||||
let out = new []Thing
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) {
|
||||
|
|
@ -64,7 +64,7 @@ function th_insert(out: []Thing, t: Thing, x: float, z: float) -> void {
|
|||
}
|
||||
|
||||
# every active one of a kind, in the order placed
|
||||
export function things_each(things_st: mut ThingsState, kind: int) -> []Thing {
|
||||
export function things_each(things_st: ThingsState, kind: int) -> []Thing {
|
||||
let out = new []Thing
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) { if all[i].active and th_of(all[i], kind) { push(out, all[i]) } }
|
||||
|
|
@ -72,7 +72,7 @@ export function things_each(things_st: mut ThingsState, kind: int) -> []Thing {
|
|||
}
|
||||
|
||||
# every one of a kind, active or not
|
||||
export function things_each_all(things_st: mut ThingsState, kind: int) -> []Thing {
|
||||
export function things_each_all(things_st: ThingsState, kind: int) -> []Thing {
|
||||
let out = new []Thing
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) { if th_of(all[i], kind) { push(out, all[i]) } }
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
# store.ludic - the Things, and the only verbs that make, remove, move, show and hide one; each
|
||||
# placing and removing is a fact, and the port is told at once so the game can draw it
|
||||
export state ThingsState {
|
||||
th_list: []Thing = null
|
||||
th_list: []Thing = new []Thing
|
||||
th_uid: int = 0
|
||||
th_facts: Queue<ThingFact> = null
|
||||
th_facts: Queue<ThingFact> = th_facts__new()
|
||||
th_marked: int = -1
|
||||
}
|
||||
|
||||
export function things_facts(things_st: mut ThingsState) -> Queue<ThingFact> {
|
||||
if things_st.th_facts == null { things_st.th_facts = queue_new("things.facts") }
|
||||
export function things_facts(things_st: ThingsState) -> Queue<ThingFact> {
|
||||
return things_st.th_facts
|
||||
}
|
||||
|
||||
function th_fact(things_st: mut ThingsState, what: int, t: Thing) -> void {
|
||||
function th_fact(things_st: ThingsState, what: int, t: Thing) -> void {
|
||||
let f = new ThingFact
|
||||
f.what = what
|
||||
f.uid = t.uid
|
||||
|
|
@ -28,12 +27,11 @@ function th_fact(things_st: mut ThingsState, what: int, t: Thing) -> void {
|
|||
export function things_ready(things_st: ThingsState) -> bool { return things_st.th_list != null }
|
||||
|
||||
# every Thing, in the order placed; the list is the package's, never to be pushed to
|
||||
export function things_all(things_st: mut ThingsState) -> []Thing {
|
||||
if things_st.th_list == null { things_st.th_list = new []Thing }
|
||||
export function things_all(things_st: ThingsState) -> []Thing {
|
||||
return things_st.th_list
|
||||
}
|
||||
|
||||
export function things_count(things_st: mut ThingsState) -> int { return len(things_all(things_st)) }
|
||||
export function things_count(things_st: ThingsState) -> int { return len(things_all(things_st)) }
|
||||
|
||||
# a new world: every Thing forgotten, quietly (the game has already dropped its drawings)
|
||||
export function things_clear(things_st: mut ThingsState) -> void { things_st.th_list = new []Thing }
|
||||
|
|
@ -110,3 +108,4 @@ export function thing_set_active(t: Thing, on: bool) -> void {
|
|||
}
|
||||
export function thing_hide(t: Thing) -> void { thing_set_active(t, false) }
|
||||
export function thing_show(t: Thing) -> void { thing_set_active(t, true) }
|
||||
function th_facts__new() -> Queue<ThingFact> { return queue_new("things.facts") }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# system.ludic - the things as a system: its save section carries every active Thing the port
|
||||
# keeps, by its kind's KEY (so the game may reorder its kinds), and a load puts each back
|
||||
export function things_save(things_st: mut ThingsState) -> Val {
|
||||
export function things_save(things_st: ThingsState) -> Val {
|
||||
let l = Value.list()
|
||||
let all = things_all(things_st)
|
||||
for i in 0 .. len(all) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ program ThingsTest {
|
|||
bind ThingsWorld { ground: fn hill, placed: fn on_placed, removed: fn on_removed, shown: fn on_shown, restored: fn on_restored }
|
||||
|
||||
function put(things_st: mut ThingsState, kind: int, x: float, z: float) -> Thing { return thing_spawn(things_st, kind, "m", x, 0.0, z, 0.0, 0) }
|
||||
function facts(things_st: mut ThingsState) -> []ThingFact { return q_drain(things_facts(things_st)) }
|
||||
function facts(things_st: ThingsState) -> []ThingFact { return q_drain(things_facts(things_st)) }
|
||||
|
||||
test "a spawn is drawn, numbered and said" (things_st: mut ThingsState, things_test_st: ThingsTestState) {
|
||||
things_clear(things_st)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue