Merge branch 'lang/ecs' into lang/foundations
This commit is contained in:
commit
01c2971ce7
2 changed files with 23 additions and 8 deletions
|
|
@ -74,17 +74,20 @@ function mm_land_count(minimap_st: mut MinimapState) -> void {
|
|||
# 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 }
|
||||
|
||||
# the grid as one string of 0 / 1, row by row, and back (a shorter string leaves the rest unseen)
|
||||
@alloc_ok("on a save: the explored grid written out")
|
||||
# the grid as one string of 0 / 1, row by row, and back (a shorter string leaves the rest unseen).
|
||||
# Written into bytes the state keeps (a string a cell before, every save): good until the next save
|
||||
export function minimap_seen_text(minimap_st: mut MinimapState) -> string {
|
||||
mm_grid(minimap_st)
|
||||
var s = ""
|
||||
for j in 0 .. minimap_st.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" } }
|
||||
s = s + row
|
||||
let n = minimap_st.mm_cells * minimap_st.mm_cells
|
||||
if minimap_st.mm_seen_cap < n + 1 { mm_seen_buf_make(minimap_st, n + 1) }
|
||||
let p = minimap_st.mm_seen_buf
|
||||
unsafe {
|
||||
for c in 0 .. n {
|
||||
if minimap_st.mm_seen[c] != 0 { p[c] = 49 } else { p[c] = 48 }
|
||||
}
|
||||
p[n] = 0
|
||||
}
|
||||
return s
|
||||
return p
|
||||
}
|
||||
|
||||
export function minimap_seen_from_text(minimap_st: mut MinimapState, s: string) -> void {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
# grid.ludic - the explored grid: square cells round the origin, and the part of it "explored" is
|
||||
# measured over (a core, so a bigger grid does not change what a share of it means)
|
||||
export state MinimapState {
|
||||
mm_seen_buf: pointer = null # minimap_seen_text's bytes, kept and written again on every save
|
||||
mm_seen_cap: int = 0
|
||||
mm_none: MinimapPin = new MinimapPin # minimap_pin past the end: an empty mark, the same one each time
|
||||
mm_near: []int = new []int # minimap_pins_near's answer, cleared and refilled: a compass asks every frame
|
||||
mm_land_n: int = 0 # land cells in the core, counted once per origin
|
||||
|
|
@ -78,3 +80,13 @@ export function minimap_cell(minimap_st: MinimapState, x: float, z: float) -> in
|
|||
}
|
||||
|
||||
function mm_grid(minimap_st: mut MinimapState) -> void { if minimap_st.mm_seen == null { minimap_config(minimap_st, minimap_st.mm_cells, minimap_st.mm_cell_m) } }
|
||||
|
||||
@alloc_ok("once per grid size: the save's bytes, kept")
|
||||
function mm_seen_buf_make(minimap_st: mut MinimapState, cap: int) -> void {
|
||||
let old = minimap_st.mm_seen_buf
|
||||
unsafe {
|
||||
if old != null { free(old) }
|
||||
minimap_st.mm_seen_buf = bytes(cap)
|
||||
}
|
||||
minimap_st.mm_seen_cap = cap
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue