Merge branch 'lang/allocs-physics' into lang/foundations
This commit is contained in:
commit
2bed060d13
32 changed files with 175 additions and 70 deletions
21
packages/ludic.wildlife/fact_pool.ludic
Normal file
21
packages/ludic.wildlife/fact_pool.ludic
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# ludic.wildlife/fact_pool.ludic - the facts' records made at the start (WILDFACTS of them) with a free list
|
||||
# of room for all, so a frame holding a new peak of facts makes nothing until that many are held
|
||||
const WL_FACTS: int = 64
|
||||
|
||||
function wl_fpool_new() -> []WildFact {
|
||||
let l = new []WildFact
|
||||
for i in 0 .. WL_FACTS { push(l, new WildFact) }
|
||||
return l
|
||||
}
|
||||
function wl_ffree_new() -> []WildFact {
|
||||
let l = wl_fpool_new()
|
||||
List.clear(l)
|
||||
return l
|
||||
}
|
||||
# past them: a record for the new peak, kept in the pool for good
|
||||
@alloc_ok("a new peak of facts held at once, past the 64 made at the start; kept and reused")
|
||||
function wl_fact_more(wildlife_st: mut WildlifeState) -> WildFact {
|
||||
let f = new WildFact
|
||||
push(wildlife_st.wl_fpool, f)
|
||||
return f
|
||||
}
|
||||
|
|
@ -48,9 +48,7 @@ function wl_fact_record(wildlife_st: mut WildlifeState) -> WildFact {
|
|||
f.diet = 0
|
||||
return f
|
||||
}
|
||||
let f = new WildFact
|
||||
push(wildlife_st.wl_fpool, f)
|
||||
return f
|
||||
return wl_fact_more(wildlife_st)
|
||||
}
|
||||
# how many fact records have ever been made: the peak held at once, not the facts pushed
|
||||
export function wildlife_fact_records(wildlife_st: WildlifeState) -> int { return len(wildlife_st.wl_fpool) }
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ module ludic_wildlife uses ludic_base
|
|||
numbers float
|
||||
import "ludic.base"
|
||||
import "species.ludic"
|
||||
import "fact_pool.ludic"
|
||||
import "animal.ludic"
|
||||
import "places.ludic"
|
||||
import "port.ludic"
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ export property WildSpecies {
|
|||
|
||||
export state WildlifeState {
|
||||
wl_facts: Queue<WildFact> = wl_facts__new()
|
||||
wl_fpool: []WildFact = new []WildFact # every fact record made, reused once no drain holds it
|
||||
wl_ffree: []WildFact = new []WildFact # of those, the ones free at the last look
|
||||
wl_fpool: []WildFact = wl_fpool_new() # every fact record made, reused once no drain holds it
|
||||
wl_ffree: []WildFact = wl_ffree_new() # of those, the ones free at the last look
|
||||
wl_fnext: []int = words(1) # the next of them to hand out
|
||||
wl_own: WildTable = null # a guest's own animals, put away whole while it draws the host's
|
||||
wl_host: WildTable = wl__new() # the table the host's are drawn into: made once, cleared per join
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export property WildTable {
|
|||
nids: IntMap = null
|
||||
}
|
||||
|
||||
@alloc_ok("a table of animals: a load, or a guest taking the host's")
|
||||
function wl__new() -> WildTable {
|
||||
let w = new WildTable
|
||||
let tb: Table<WildAnimal> = table_new(2, 2)
|
||||
|
|
|
|||
|
|
@ -84,13 +84,13 @@ program WildCrowdTest {
|
|||
expect(not wildlife_listed(wildlife_st, a))
|
||||
}
|
||||
|
||||
test "a fact a frame, drained each frame, makes a few records and then reuses them" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
|
||||
test "a fact a frame, drained each frame, makes no record past the ones made at the start" (wildlife_st: mut WildlifeState, wildlife_tests_fake_st: mut WildlifeTestsFakeState) {
|
||||
let a = walker(wildlife_st, wildlife_tests_fake_st)
|
||||
for k in 1 .. 3001 {
|
||||
wildlife_moved(wildlife_st, a, 0.0, -3.0 * float(k), 0.0, -1.2)
|
||||
let fs = q_drain(wildlife_facts(wildlife_st))
|
||||
for i in 0 .. len(fs) { expect_eq(fs[i].what, WILD_PRINT) }
|
||||
}
|
||||
expect(wildlife_fact_records(wildlife_st) <= 4)
|
||||
expect_eq(wildlife_fact_records(wildlife_st), 64)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue