~/bend-docscommunity

src/rom.bend source

src/rom.bend on the hub · documented module

import Baseimport ./tab.bend as Timport ./fixed.bend as Fimport ./gfx.bend as Gimport ./render.bend as Vimport ./mem.bend as Mdef lit.go(+pal: T.Vec<U32>, bs: List<&2, U32>, acc: List<&2, U32>) -> List<&2, U32>:  match bs:    case b <> t:      lit.go(pal, t, T.get(U32, pal, b, 0) <> acc)    case []:      List.reverse(&2, U32, acc)def lit(+pal: T.Vec<U32>, bs: List<&2, U32>) -> List<&2, U32>:  lit.go(pal, bs, [])def pal.list.go(n: Nat, +pal: T.Vec<U32>, +i: U32, acc: List<&2, U32>) -> List<&2, U32>:  match n:    case 0n:      List.reverse(&2, U32, acc)    case 1n+p:      pal.list.go(p, pal, (i + 1 : U32), T.get(U32, pal, i, 0) <> acc)def pal.list(n: Nat, +pal: T.Vec<U32>, +i: U32) -> List<&2, U32>:  pal.list.go(n, pal, i, [])def fuzztab() -> List<&2, U32>:  [1, 4294967295, 1, 4294967295, 1, 1, 4294967295, 1, 1, 4294967295, 1, 1, 1, 4294967295, 1, 1, 1, 4294967295, 4294967295, 4294967295, 4294967295, 1, 4294967295, 4294967295, 1, 1, 1, 1, 4294967295, 1, 4294967295, 1, 1, 4294967295, 4294967295, 1, 1, 4294967295, 4294967295, 4294967295, 4294967295, 1, 1, 1, 1, 4294967295, 1, 1, 4294967295, 1]def zlevel(+i: U32, +j: U32) -> U32:  +lv = ((15 - i) * 4 - ((655360 / (j + 1) : U32) >> 12n) / 2 : U32)  (Bool.pick(U32, F.lt(lv, 0), 0, Bool.pick(U32, F.gt(lv, 31), 31, lv)) * 256 : U32)def zrow.go(n: Nat, +i: U32, +j: U32, acc: List<&2, U32>) -> List<&2, U32>:  match n:    case 0n:      List.reverse(&2, U32, acc)    case 1n+p:      zrow.go(p, i, (j + 1 : U32), zlevel(i, j) <> acc)def zrow(n: Nat, +i: U32, +j: U32) -> List<&2, U32>:  zrow.go(n, i, j, [])def zlights(n: Nat, +i: U32) -> List<&2, U32>:  match n:    case 0n:      []    case 1n+p:      List.append(&2, U32, zrow(128n, i, 0), zlights(p, (i + 1 : U32)))def tex.info(+at: U32, +t: G.Tex) -> M.Info:  match t:    case G.Tex{+m, h, xs, ps, bl}:      M.Info{m, h, at, Bool.pick(U32, List.is_empty(&2, U32, ps), 4294967295, (at + (m + 1) * 128 : U32))}def tex.size(+t: G.Tex) -> U32:  match t:    case G.Tex{m, h, xs, +ps, +bl}:      ((m + 1) * 128 + T.len(U32, ps) + T.len(U32, bl) : U32)def infos.go(ts: List<&2, G.Tex>, +at: U32, acc: List<&2, M.Info>) -> List<&2, M.Info>:  match ts:    case +t <> r:      infos.go(r, (at + tex.size(t) : U32), tex.info(at, t) <> acc)    case []:      List.reverse(&2, M.Info, acc)def infos(ts: List<&2, G.Tex>, +at: U32) -> List<&2, M.Info>:  infos.go(ts, at, [])def texs.end(ts: List<&2, G.Tex>, +at: U32) -> U32:  match ts:    case +t <> r:      texs.end(r, (at + tex.size(t) : U32))    case []:      atdef flat.bases.go(fs: List<&2, List<&2, U32>>, +at: U32, acc: List<&2, U32>) -> List<&2, U32>:  match fs:    case f <> r:      flat.bases.go(r, (at + 4096 : U32), at <> acc)    case []:      List.reverse(&2, U32, acc)def flat.bases(fs: List<&2, List<&2, U32>>, +at: U32) -> List<&2, U32>:  flat.bases.go(fs, at, [])def layout(+ts: List<&2, G.Tex>, +fs: List<&2, List<&2, U32>>) -> M.Layout:  +fb = texs.end(ts, M.texbase())  M.Layout{infos(ts, M.texbase()), flat.bases(fs, fb), (fb + 4096 * T.len(List<&2, U32>, fs) : U32)}def rebase.go(xs: List<&2, U32>, +b: U32, acc: List<&2, U32>) -> List<&2, U32>:  match xs:    case +x <> t:      rebase.go(t, b, Bool.pick(U32, U32.is_eq(x, 4294967295), x, (x + b : U32)) <> acc)    case []:      List.reverse(&2, U32, acc)def rebase(xs: List<&2, U32>, +b: U32) -> List<&2, U32>:  rebase.go(xs, b, [])def put.tex(+t: G.Tex, a: Array<U32>, +at: U32) -> Array<U32>:  match t:    case G.Tex{+m, h, xs, +ps, bl}:      +p0 = (at + (m + 1) * 128 : U32)      +b0 = (p0 + T.len(U32, ps) : U32)      M.fill(bl, M.fill(rebase(ps, b0), M.fill(xs, a, at), p0), b0)def put.texs(ts: List<&2, G.Tex>, a: Array<U32>, +at: U32) -> Array<U32>:  match ts:    case +t <> r:      put.texs(r, put.tex(t, a, at), (at + tex.size(t) : U32))    case []:      adef put.flats(fs: List<&2, List<&2, U32>>, a: Array<U32>, +at: U32) -> Array<U32>:  match fs:    case f <> r:      put.flats(r, M.fill(List.take(&2, U32, f, 4096n), a, at), (at + 4096 : U32))    case []:      adef build(+tb: V.Tabs, +pal: T.Vec<U32>, cmaps: List<&2, U32>, ts: List<&2, G.Tex>, +fs: List<&2, List<&2, U32>>, +unused: U32, +flat0: U32) -> Array<U32>:  a0 = Array.new(U32, M.depth(U32.max(unused, (flat0 + 4096 * T.len(List<&2, U32>, fs) : U32))), 0)  a1 = M.fill(List.take(&2, U32, pal.list(256n, pal, 0), 256n), M.fill(List.take(&2, U32, cmaps, 8704n), a0, M.cmap()), M.pal())  a2 = M.fill(fuzztab(), M.fill(zlights(16n, 0), a1, M.zlight()), M.fuzz())  a5 = put.texs(ts, a2, M.texbase())  put.flats(fs, a5, flat0)