fix(ludic.jobs): jobs_taken and jobs_shown fill a kept list per group (the map and the journal asked every frame, and the fence caught a list kept)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f4233ba11d
commit
90dd603cee
2 changed files with 17 additions and 5 deletions
|
|
@ -13,21 +13,32 @@ export function jobs_at(jobs_st: JobsState, group: int, vendor: int) -> []int {
|
|||
}
|
||||
|
||||
# every job of a group taken at some point, done ones too
|
||||
export function jobs_taken(jobs_st: JobsState, group: int) -> []int {
|
||||
let out = new []int
|
||||
for i in 0 .. JOB_COUNT { if Jobs[i].group == group and jobs_state(jobs_st, i) != JOBS_OFFERED { push(out, i) } }
|
||||
export function jobs_taken(jobs_st: mut JobsState, group: int) -> []int {
|
||||
let out = jobs_st.jobs__lists[group * 2]
|
||||
List.clear(out)
|
||||
for i in 0 .. JOB_COUNT {
|
||||
@alloc_ok("a kept list, cleared each ask: grows once to the group's jobs")
|
||||
if Jobs[i].group == group and jobs_state(jobs_st, i) != JOBS_OFFERED { push(out, i) }
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
# the first `most` of a group under way
|
||||
export function jobs_shown(jobs_st: JobsState, group: int, most: int) -> []int {
|
||||
let out = new []int
|
||||
export function jobs_shown(jobs_st: mut JobsState, group: int, most: int) -> []int {
|
||||
let out = jobs_st.jobs__lists[group * 2 + 1]
|
||||
List.clear(out)
|
||||
for i in 0 .. JOB_COUNT {
|
||||
if len(out) >= most { break }
|
||||
@alloc_ok("a kept list, cleared each ask: grows once to `most`")
|
||||
if Jobs[i].group == group and jobs_under_way(jobs_st, i) { push(out, i) }
|
||||
}
|
||||
return out
|
||||
}
|
||||
function jobs__lists_new(n: int) -> [][]int {
|
||||
let out = new [][]int
|
||||
for i in 0 .. n { push(out, new []int) }
|
||||
return out
|
||||
}
|
||||
|
||||
# the first under way and not yet met, or -1
|
||||
export function jobs_first_open(jobs_st: JobsState, group: int) -> int {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export state JobsState {
|
|||
jobs__back: []int = jobs__ints(JOB_COUNT, 0) # given up: the first day it may be taken again
|
||||
jobs__primed: bool = false # the first tick after a reset learns the offers quietly
|
||||
jobs__done_n: []int = jobs__ints(JOBS_GROUPS, 0) # handed in, per group
|
||||
jobs__lists: [][]int = jobs__lists_new(2 * JOBS_GROUPS) # jobs_taken's and jobs_shown's answers, per group, filled in place
|
||||
jobs__off: []int = jobs__offsets()
|
||||
jobs__pk: []int = jobs__ints(jobs__slots(), -1) # kind, -1 empty
|
||||
jobs__pp: []int = jobs__ints(jobs__slots(), -1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue