feat(compiler): the built-in ECS's stores grow - 100 000 entities, where 1024 was the wall
Every per-entity store (@S_ components, @H_ flags, alive, kind, freelist, owners) is a heap block
L_grow doubles from 1024 as L_alloc hands out a slot past it, the new slots zeroed; each site loads
the store's base where it indexes it (ecs_base, its registers %ecsb* so a raw function's t0 labels
cannot collide). Prop.has bounds against @L_cap, Pool.capacity answers it, a mod's registered
stores grow with the rest, every main grows the stores once before anything reads them. A snapshot
records its slot count first and a load grows to it before reading back. The overflow stop of
1c7ce84 is gone with the wall. ludic-dev test 305 passed, selfhost-test 33 passed; 1000 / 5000 /
100000 entities spawn and count.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0c6235e55b
commit
8384ad3215
13 changed files with 27441 additions and 26036 deletions
|
|
@ -46,16 +46,23 @@ function emit_io(fn2: pointer, p: pointer, bytes: pointer) -> void {
|
|||
function emit_snapshot_blocks(fn2: pointer) -> void {
|
||||
g_iok = 0
|
||||
g_off = "0"
|
||||
let me = itoa(MAX_ENT)
|
||||
# the stores grow, so a snapshot says how many slots it holds first; a load grows to it before
|
||||
# reading them back
|
||||
let reading = (fn2 == "fread") or (g_snap_mode == "load")
|
||||
if not reading { emit(" %sncap0 = load i32, ptr @L_cap\n store i32 %sncap0, ptr @L_snapcap\n") }
|
||||
emit_io(fn2, "@L_snapcap", "4")
|
||||
emit(" %sncap = load i32, ptr @L_snapcap\n")
|
||||
if reading { emit(" call void @L_grow(i32 %sncap)\n") }
|
||||
emit(" %sncap64 = sext i32 %sncap to i64\n")
|
||||
emit_io(fn2, "@L_entc", "4")
|
||||
emit_io(fn2, "@L_freen", "4")
|
||||
emit(" %nalive = mul i64 "); emit(me); emit(", 4\n")
|
||||
emit_io(fn2, "@L_alive", "%nalive")
|
||||
emit_io(fn2, "@L_freelist", "%nalive")
|
||||
emit_io(fn2, "@L_kind", "%nalive")
|
||||
emit(" %nalive = mul i64 %sncap64, 4\n")
|
||||
emit_io(fn2, snap_base("L_alive", 0), "%nalive")
|
||||
emit_io(fn2, snap_base("L_freelist", 1), "%nalive")
|
||||
emit_io(fn2, snap_base("L_kind", 2), "%nalive")
|
||||
# N3: an @Owned world snapshots its per-entity owners too, so rollback/replication
|
||||
# round-trips ownership (like @L_kind). Gated, so non-@Owned snapshots are unchanged.
|
||||
if net_has_owned() { emit_io(fn2, "@L_owner_arr", "%nalive") }
|
||||
if net_has_owned() { emit_io(fn2, snap_base("L_owner_arr", 3), "%nalive") }
|
||||
var i = 0
|
||||
while i < len(prog) { if prog[i].kind == N_VAR { emit_io(fn2, `@g_{prog[i].s}`, "4") }; i += 1 }
|
||||
var ci = 0
|
||||
|
|
@ -63,16 +70,25 @@ function emit_snapshot_blocks(fn2: pointer) -> void {
|
|||
while i < len(prog) {
|
||||
if prog[i].kind == N_COMP {
|
||||
let c = prog[i].s
|
||||
let csz1 = `%csz1_{itoa(ci)}`
|
||||
let csz = `%csz{itoa(ci)}`
|
||||
emit(" "); emit(csz); emit(" = ptrtoint ptr getelementptr (%Cmp_"); emit(c); emit(", ptr null, i32 "); emit(me); emit(") to i64\n")
|
||||
emit_io(fn2, `@S_{c}`, csz)
|
||||
emit_io(fn2, `@H_{c}`, me)
|
||||
emit(" "); emit(csz1); emit(" = ptrtoint ptr getelementptr (%Cmp_"); emit(c); emit(", ptr null, i32 1) to i64\n")
|
||||
emit(" "); emit(csz); emit(" = mul i64 %sncap64, "); emit(csz1); emit("\n")
|
||||
emit_io(fn2, snap_base(`S_{c}`, 4 + ci * 2), csz)
|
||||
emit_io(fn2, snap_base(`H_{c}`, 5 + ci * 2), "%sncap64")
|
||||
ci += 1
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
# a store's base, loaded after any grow the snapshot made
|
||||
function snap_base(store: pointer, k: int) -> pointer {
|
||||
let r = `%snb{itoa(k)}`
|
||||
emit(` {r} = load ptr, ptr @{store}\n`)
|
||||
return r
|
||||
}
|
||||
|
||||
function emit_snapshot() -> void {
|
||||
g_snap_mode = "file" # seed (module ptr inits are null)
|
||||
emith("@.sav_path = private unnamed_addr constant [10 x i8] c\"ludic.sav\\00\"\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue