wip(0.S2): migrate - a var nothing writes becomes a let; a state is keyed by its module, directory or program, so every program's plan agrees; paths normalized; program states named SceneDemoState / scene_demo_st; the LSP reads state, mut and entry/handler parameters
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3eda72e8c2
commit
5ffe50ed02
463 changed files with 72045 additions and 67421 deletions
|
|
@ -1,97 +1,100 @@
|
|||
# explored.ludic - walking reveals the cells round you; "explored" is the share of the core's LAND
|
||||
# that has been seen, since open water has nothing on it to miss
|
||||
var mm_land_n: int = 0 # land cells in the core, counted once per origin
|
||||
var mm_land_ox: float = 0.0
|
||||
var mm_land_oz: float = 0.0
|
||||
|
||||
# every cell any part of which is within r of (x, z)
|
||||
export function minimap_reveal(minimap_st: mut MinimapState, x: float, z: float, r: float) -> void {
|
||||
mm_grid(minimap_st)
|
||||
let c = minimap_cell(minimap_st, x, z)
|
||||
let reach = int(r / minimap_st.mm_cell_m) + 1
|
||||
let x0 = minimap_grid_x0(minimap_st)
|
||||
let z0 = minimap_grid_z0(minimap_st)
|
||||
let ci = int(Math.floor((x - x0) / minimap_st.mm_cell_m))
|
||||
let cj = int(Math.floor((z - z0) / minimap_st.mm_cell_m))
|
||||
export function minimap_reveal(x: float, z: float, r: float) -> void {
|
||||
mm_grid()
|
||||
let c = minimap_cell(x, z)
|
||||
let reach = int(r / mm_cell_m) + 1
|
||||
let x0 = minimap_grid_x0()
|
||||
let z0 = minimap_grid_z0()
|
||||
let ci = int(Math.floor((x - x0) / mm_cell_m))
|
||||
let cj = int(Math.floor((z - z0) / mm_cell_m))
|
||||
for j in cj - reach .. cj + reach + 1 {
|
||||
for i in ci - reach .. ci + reach + 1 {
|
||||
if i < 0 or j < 0 or i >= minimap_st.mm_cells or j >= minimap_st.mm_cells { continue }
|
||||
let nx = Math.clamp(x, x0 + float(i) * minimap_st.mm_cell_m, x0 + float(i + 1) * minimap_st.mm_cell_m)
|
||||
let nz = Math.clamp(z, z0 + float(j) * minimap_st.mm_cell_m, z0 + float(j + 1) * minimap_st.mm_cell_m)
|
||||
if (nx - x) * (nx - x) + (nz - z) * (nz - z) <= r * r { minimap_reveal_cell(minimap_st, j * minimap_st.mm_cells + i) }
|
||||
if i < 0 or j < 0 or i >= mm_cells or j >= mm_cells { continue }
|
||||
let nx = Math.clamp(x, x0 + float(i) * mm_cell_m, x0 + float(i + 1) * mm_cell_m)
|
||||
let nz = Math.clamp(z, z0 + float(j) * mm_cell_m, z0 + float(j + 1) * mm_cell_m)
|
||||
if (nx - x) * (nx - x) + (nz - z) * (nz - z) <= r * r { minimap_reveal_cell(j * mm_cells + i) }
|
||||
}
|
||||
}
|
||||
if c >= 0 { minimap_reveal_cell(minimap_st, c) }
|
||||
if c >= 0 { minimap_reveal_cell(c) }
|
||||
}
|
||||
|
||||
export function minimap_reveal_cell(minimap_st: mut MinimapState, c: int) -> void {
|
||||
mm_grid(minimap_st)
|
||||
if c < 0 or c >= minimap_st.mm_cells * minimap_st.mm_cells or minimap_st.mm_seen[c] != 0 { return }
|
||||
minimap_st.mm_seen[c] = 1
|
||||
minimap_st.mm_version += 1
|
||||
export function minimap_reveal_cell(c: int) -> void {
|
||||
mm_grid()
|
||||
if c < 0 or c >= mm_cells * mm_cells or mm_seen[c] != 0 { return }
|
||||
mm_seen[c] = 1
|
||||
mm_version += 1
|
||||
}
|
||||
|
||||
export function minimap_seen(minimap_st: MinimapState, c: int) -> bool {
|
||||
if minimap_st.mm_seen == null or c < 0 or c >= minimap_st.mm_cells * minimap_st.mm_cells { return false }
|
||||
return minimap_st.mm_seen[c] != 0
|
||||
export function minimap_seen(c: int) -> bool {
|
||||
if mm_seen == null or c < 0 or c >= mm_cells * mm_cells { return false }
|
||||
return mm_seen[c] != 0
|
||||
}
|
||||
|
||||
export function minimap_seen_at(minimap_st: MinimapState, x: float, z: float) -> bool { return minimap_seen(minimap_st, minimap_cell(minimap_st, x, z)) }
|
||||
export function minimap_seen_at(x: float, z: float) -> bool { return minimap_seen(minimap_cell(x, z)) }
|
||||
|
||||
export function minimap_seen_count(minimap_st: MinimapState) -> int {
|
||||
export function minimap_seen_count() -> int {
|
||||
var n = 0
|
||||
if minimap_st.mm_seen == null { return 0 }
|
||||
for c in 0 .. len(minimap_st.mm_seen) { if minimap_st.mm_seen[c] != 0 { n += 1 } }
|
||||
if mm_seen == null { return 0 }
|
||||
for c in 0 .. len(mm_seen) { if mm_seen[c] != 0 { n += 1 } }
|
||||
return n
|
||||
}
|
||||
|
||||
# goes up whenever what has been seen changes: a picture of the fog is baked again when it does
|
||||
export function minimap_version(minimap_st: MinimapState) -> int { return minimap_st.mm_version }
|
||||
export function minimap_version() -> int { return mm_version }
|
||||
|
||||
export function minimap_explored_pct(minimap_st: mut MinimapState) -> int {
|
||||
mm_land_count(minimap_st)
|
||||
export function minimap_explored_pct() -> int {
|
||||
mm_land_count()
|
||||
var n = 0
|
||||
for j in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n {
|
||||
for i in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n {
|
||||
if minimap_seen(minimap_st, j * minimap_st.mm_cells + i) and mm_land(minimap_st, i, j) { n += 1 }
|
||||
for j in mm_core0 .. mm_core0 + mm_core_n {
|
||||
for i in mm_core0 .. mm_core0 + mm_core_n {
|
||||
if minimap_seen(j * mm_cells + i) and mm_land(i, j) { n += 1 }
|
||||
}
|
||||
}
|
||||
return Math.min(n * 100 / minimap_st.mm_land_n, 100)
|
||||
return Math.min(n * 100 / mm_land_n, 100)
|
||||
}
|
||||
|
||||
function mm_land(minimap_st: MinimapState, i: int, j: int) -> bool { return MinimapWorld.land(minimap_cell_x(minimap_st, i), minimap_cell_z(minimap_st, j)) }
|
||||
function mm_land(i: int, j: int) -> bool { return MinimapWorld.land(minimap_cell_x(i), minimap_cell_z(j)) }
|
||||
|
||||
function mm_land_count(minimap_st: mut MinimapState) -> void {
|
||||
function mm_land_count() -> void {
|
||||
let ox = MinimapWorld.origin_x()
|
||||
let oz = MinimapWorld.origin_z()
|
||||
if minimap_st.mm_land_n > 0 and ox == minimap_st.mm_land_ox and oz == minimap_st.mm_land_oz { return }
|
||||
minimap_st.mm_land_ox = ox
|
||||
minimap_st.mm_land_oz = oz
|
||||
minimap_st.mm_land_n = 0
|
||||
for j in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n {
|
||||
for i in minimap_st.mm_core0 .. minimap_st.mm_core0 + minimap_st.mm_core_n { if mm_land(minimap_st, i, j) { minimap_st.mm_land_n += 1 } }
|
||||
if mm_land_n > 0 and ox == mm_land_ox and oz == mm_land_oz { return }
|
||||
mm_land_ox = ox
|
||||
mm_land_oz = oz
|
||||
mm_land_n = 0
|
||||
for j in mm_core0 .. mm_core0 + mm_core_n {
|
||||
for i in mm_core0 .. mm_core0 + mm_core_n { if mm_land(i, j) { mm_land_n += 1 } }
|
||||
}
|
||||
minimap_st.mm_land_n = Math.max(minimap_st.mm_land_n, 1)
|
||||
mm_land_n = Math.max(mm_land_n, 1)
|
||||
}
|
||||
|
||||
# the ground under the grid is not what it was (a new world): count its land again
|
||||
export function minimap_land_changed(minimap_st: mut MinimapState) -> void { minimap_st.mm_land_n = 0 }
|
||||
export function minimap_land_changed() -> void { mm_land_n = 0 }
|
||||
|
||||
# the grid as one string of 0 / 1, row by row, and back (a shorter string leaves the rest unseen)
|
||||
export function minimap_seen_text(minimap_st: mut MinimapState) -> string {
|
||||
mm_grid(minimap_st)
|
||||
export function minimap_seen_text() -> string {
|
||||
mm_grid()
|
||||
var s = ""
|
||||
for j in 0 .. minimap_st.mm_cells {
|
||||
for j in 0 .. mm_cells {
|
||||
var row = ""
|
||||
for i in 0 .. minimap_st.mm_cells { if minimap_st.mm_seen[j * minimap_st.mm_cells + i] != 0 { row = row + "1" } else { row = row + "0" } }
|
||||
for i in 0 .. mm_cells { if mm_seen[j * mm_cells + i] != 0 { row = row + "1" } else { row = row + "0" } }
|
||||
s = s + row
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
export function minimap_seen_from_text(minimap_st: mut MinimapState, s: string) -> void {
|
||||
mm_grid(minimap_st)
|
||||
export function minimap_seen_from_text(s: string) -> void {
|
||||
mm_grid()
|
||||
let n = len(s)
|
||||
for c in 0 .. minimap_st.mm_cells * minimap_st.mm_cells {
|
||||
minimap_st.mm_seen[c] = 0
|
||||
if c < n and s[c] == 49 { minimap_st.mm_seen[c] = 1 }
|
||||
for c in 0 .. mm_cells * mm_cells {
|
||||
mm_seen[c] = 0
|
||||
if c < n and s[c] == 49 { mm_seen[c] = 1 }
|
||||
}
|
||||
minimap_st.mm_version += 1
|
||||
mm_version += 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue