← tile_world · version 0.14.3
60 public items, in source order. Generated from the registry index, which re-derives them from the package source at publish time — so a signature here is the one that version actually ships.
pub struct World { chunks: hash<Chunk[cx, cy, z]>, stacks: hash<Stack[x, y, z]>, terrains: hash<TerrainKind[kd]>, objects: hash<ThingKind[kd]>, edges: hash<EdgeKind[kd]>, grounds: hash<Ground[gz]>, changes: integer, marks: hash<Mark[bx, by, bz]>, layer_marks: hash<LayerMark[lz]>, kinds_at: integer }
The world: its chunks, its stacks, the kinds the game declared, and what changed when.
pub fn world() -> World
An empty world: every cell void, no kinds declared, no changes counted.
pub fn changes(w: const World) -> integer
How many changes the world has had (the header's § Changes): remembered, it tells whether anything changed since.
pub fn changed_since(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z0: integer, z1: integer, since: integer) -> boolean
Has anything in cells x0 ..= x1, y0 ..= y1 on layers z0 ..= z1 changed after this world counted since (a changes(w) remembered from the same world)? Answers false at once when w.changes <= since — callers swapping worlds reset since = 0 or check changes(w) < since first. Told by blocks of 8 x 8 cells: a change in a block the box overlaps counts, though it was outside the box. A layer's ground set, or a kind declared, after since changes every cell it reaches: yes.
pub fn terrain_kind(w: World, kind: integer, walk: boolean, opaque: boolean, light: boolean = false, glyph: text = "?")
Declare terrain kind kind (1..15): whether it can be walked on, whether it stops sight and light, whether it gives light (a lava floor, a window), and its glyph in view.
pub fn thing_kind(w: World, thing: integer, height: integer, blocks: boolean, opaque: boolean = false, light: boolean = false, glyph: text = "?")
Declare thing thing: how many height steps it adds to its stack, whether it blocks a cell for walking (passable, shortest_path), whether it stops sight and light, whether it gives light (a torch), and its glyph in view.
pub fn edge_kind(w: World, kind: integer, walk: boolean, opaque: boolean, glyph: text = "|")
Declare edge kind kind (1..255): whether it can be walked across (an open doorway) and whether it stops sight and light (a wall, a closed door; not a fence or a window), and its glyph.
pub fn walkable_kind(w: const World, kind: integer) -> boolean
Can terrain kind kind be walked on: as declared; void and an undeclared kind cannot.
pub fn thing_height(w: const World, thing: integer) -> integer
How many height steps thing thing adds: as declared, 1 for an undeclared thing.
pub fn chunk_of(v: integer) -> integer
floor(v / 32): the chunk a coordinate is in, west and north of the origin included.
pub fn chunk_count(w: const World) -> integer
How many chunks the world holds — the measure of its memory, 2 KB each.
pub fn layers(w: const World) -> vector<integer>
The layers that hold any terrain, lowest first — what saving the world walks.
pub fn chunks(w: const World, z: integer) -> vector<(integer, integer)>
The chunks layer z holds, as (cx, cy), in reading order (row by row, west to east) — each one 32x32 cells from (cx * 32, cy * 32).
pub fn stacks(w: const World) -> vector<(integer, integer, integer)>
Every cell that holds things, as (x, y, z): layer by layer, lowest first, each in reading order.
pub fn set_terrain(w: World, x: integer, y: integer, z: integer, kind: integer, tile: integer = 0)
Set a cell's terrain: a kind (0..15) and, for the picture, a tile number (0..4095). VOID makes the cell void even on a layer with a ground — a pit, a hole; clear unsets it.
pub fn clear(w: World, x: integer, y: integer, z: integer)
Make a cell unset again: it reads as its layer's ground, or as void.
pub fn is_set(w: const World, x: integer, y: integer, z: integer) -> boolean
Was this cell set (to anything, void included), rather than read from the ground?
pub fn set_ground(w: World, z: integer, kind: integer, tile: integer = 0)
Give layer z a ground: every cell of it nobody set reads as terrain kind with picture tile — open land that costs no memory. Kind VOID takes the ground away.
pub fn ground_layers(w: const World) -> vector<integer>
The layers that have a ground, lowest first — with layers, what saving a world walks.
pub fn ground_tile(w: const World, z: integer) -> integer
Layer z's ground tile, 0 when it has none.
pub fn fill(w: World, x0: integer, y0: integer, x1: integer, y1: integer, z: integer, kind: integer, tile: integer = 0)
Set a rectangle of terrain, corners included.
pub fn terrain(w: const World, x: integer, y: integer, z: integer) -> integer
A cell's terrain kind: what it was set to, or its layer's ground when it was not.
pub fn tile(w: const World, x: integer, y: integer, z: integer) -> integer
A cell's tile number, its picture: what it was set to, or its layer's ground tile.
pub fn set_edge(w: World, x: integer, y: integer, z: integer, side: integer, kind: integer)
Put edge kind kind (1..255) on side (NORTH, EAST, SOUTH, WEST) of cell (x, y, z); 0 takes the edge away. The east edge of a cell is its east neighbour's west edge, and the same edge: setting one sets both.
pub fn edge(w: const World, x: integer, y: integer, z: integer, side: integer) -> integer
The edge kind on side of cell (x, y, z), 0 for none.
pub fn crossable(w: const World, x: integer, y: integer, z: integer, dx: integer, dy: integer) -> boolean
Can a walker step from (x, y, z) by (dx, dy) — one of the four directions — across the edge between: no edge, or one declared walkable. Whether the cell it lands on can be stood on is passable's question.
pub fn see_through(w: const World, x: integer, y: integer, z: integer, dx: integer, dy: integer) -> boolean
Do sight and light pass from (x, y, z) by (dx, dy) across the edge between.
pub fn set_rise(w: World, x: integer, y: integer, z: integer, steps: integer)
Give cell (x, y, z) a rise of steps (0..15): its own height, under whatever stands on it. A hillside is cells rising one step at a time, so a walker that steps up one at a time walks up it.
pub fn rise(w: const World, x: integer, y: integer, z: integer) -> integer
A cell's rise in steps, 0 for a flat one.
pub fn set_slant(w: World, x: integer, y: integer, z: integer, toward: integer)
Give cell (x, y, z) a slant: a 45-degree face looking toward (NORTH_EAST, SOUTH_EAST, SOUTH_WEST, NORTH_WEST; 0 takes it away), so the game draws its kind filling only the half away from that corner — a rock face or a wall running at 45 degrees. A picture only: walking, sight, light and standing on it read the cell as its kind, whole. Kept when the terrain changes, like the edges and the rise.
pub fn slant(w: const World, x: integer, y: integer, z: integer) -> integer
Which way cell (x, y, z)'s slant looks, 0 for a whole cell.
pub fn set_ceiling(w: World, x: integer, y: integer, z: integer, steps: integer)
Lower the ceiling over cell (x, y, z) to steps (0..15) below the floor of the layer above: 0, the default, is that floor's underside. A ceiling's slope is its neighbours' differences, as a floor's is its rise's. Kept for a renderer that draws ceilings; no routine here reads it — a cell under the open sky has no ceiling, whatever this holds. Kept when the terrain changes, like the edges, the rise and the slant.
pub fn ceiling(w: const World, x: integer, y: integer, z: integer) -> integer
How many steps the ceiling over cell (x, y, z) hangs below the floor of the layer above, 0 for none.
pub fn block(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z: integer) -> vector<integer>
What each cell of x0 ..= x1, y0 ..= y1 on layer z holds, row by row, two numbers a cell: first its terrain kind (bits 0..3, as terrain reads it), rise (4..7), slant (8..10), ceiling (11..14), and bit 15 when things lie on it; then its north edge (bits 0..7) and west edge (8..15). Two numbers, not one: under #width 32 an integer holds 31 bits. Read once for the box — the cell's chunk and its stack looked up once each — where asking terrain, rise, edge and the rest of each cell asks for its chunk again every time: what a renderer reading a box of cells (a mesh's halo, a tile of faces) wants.
pub fn open_sky(w: const World, x: integer, y: integer, z: integer) -> boolean
Is (x, y, z) under the open sky: nothing set on the layer above it.
pub fn place(w: World, x: integer, y: integer, z: integer, thing: integer)
Put a thing on top of a cell's stack.
pub fn take(w: World, x: integer, y: integer, z: integer) -> integer
Take the top thing off a cell's stack and answer it; 0 when the cell has none. The stack goes when it empties.
pub fn things(w: const World, x: integer, y: integer, z: integer) -> vector<integer>
The things on a cell, bottom first.
pub fn top(w: const World, x: integer, y: integer, z: integer) -> integer
The top thing on a cell, 0 when there is none.
pub fn height(w: const World, x: integer, y: integer, z: integer) -> integer
The height of a cell in steps: its rise and the declared heights of the things on it.
pub fn passable(w: const World, x: integer, y: integer, z: integer) -> boolean
Can a cell be walked into: walkable terrain and nothing on it that blocks.
pub fn opaque(w: const World, x: integer, y: integer, z: integer) -> boolean
Does a cell stop sight and light: opaque terrain, or an opaque thing on it. An undeclared terrain kind (not void) is opaque.
pub fn lit(w: const World, x: integer, y: integer, z: integer, daylight: boolean = true) -> boolean
Does a cell give light: under the open sky (by day: daylight, the default), lit terrain, or a lit thing on it. A void cell gives none.
pub fn shortest_path(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z: integer, limit: integer = 64) -> vector<(integer, integer)>
The shortest walk from (x0, y0) to (x1, y1) on layer z, in steps to the four neighbours over passable cells and crossable edges: the cells passed through, the goal last, the start left out. Empty when the goal cannot be reached within limit steps (or is the start). The goal itself need not be passable, so a path can lead up to a thing to act on.
pub fn line_of_sight(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z: integer) -> boolean
Can (x1, y1) be seen from (x0, y0) on layer z: no opaque cell on the straight line between them (Bresenham's), and no opaque edge it crosses. The two ends themselves do not count, so a wall is seen, and an eye in a doorway sees out.
pub fn shades(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z: integer, lights: const vector<(integer, integer)> = [], start: const vector<integer> = [], daylight: boolean = true) -> vector<integer>
How dark each cell of x0..=x1, y0..=y1 on layer z is, row by row: 0 at a light, one shade darker for each step from the nearest one, up to DARKEST, never black. A light is a lit cell or one of lights (cells the game says give light now: what a figure carries, a torch). A light of lights starts at its shade in start (0, the default, is full; a dimmer light — a torch burning down — reaches less far), the k-th entry for the k-th light. Light spreads over every cell but an opaque one, which is lit but passes no light on unless it is itself a light, and never across an opaque edge. A light up to DARKEST cells outside the rectangle counts. daylight false: the open sky is no light — night, when only what gives light of itself (a lamp, a lit terrain) and lights light the world.
pub fn reach(w: const World, x: integer, y: integer, z: integer, start: integer = 0) -> vector<integer>
The shades one light gives alone, as shades spreads it, over the square of DARKEST cells round it on layer z, row by row (2 * DARKEST + 1 a side, its corner at (x - DARKEST, y - DARKEST)): start at the light, one darker a step, DARKEST where it does not reach. What a GPU lights a torch by, apart from the others (the scene contract's torches): shades with these lights is, cell by cell, the brightest of shades without them and each light's reach, but where a light stands on an opaque cell another light reaches more brightly than it starts — there shades passes that light on, a light's reach does not.
pub fn view(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z: integer, marks: const vector<(integer, integer, text)> = []) -> text
A layer as text, one line per row: each cell's top thing's glyph, or its terrain's, or a space for void. marks puts a glyph of the game's at a cell (a figure): (x, y, glyph).
pub fn region(w: const World, x: integer, y: integer, z: integer, limit: integer) -> vector<(integer, integer)>
The cells of layer z connected to (x, y) that hold the same terrain as it — the same kind and tile, set or read from the ground — four ways, never across an edge between two cells: what a fill paints. Nearest first (breadth first), (x, y) itself first, and at most limit of them, because a layer's ground has no end: a region exactly limit long may go on.
pub fn copy(w: const World, x0: integer, y0: integer, x1: integer, y1: integer, z0: integer, z1: integer) -> World
A stamp: the cells of the box x0..=x1, y0..=y1 on layers z0..=z1, corners included — terrain as set (an unset cell stays unset), rise, slant, ceiling, the north and west edges each cell holds, and the stacks — moved so the corner (x0, y0, z0) is (0, 0, 0). The kinds come along: the stamp is a world of its own, to paste back or keep.
pub fn paste(w: World, from: const World, x: integer, y: integer, z: integer)
Write stamp from (a copy) into w with its (0, 0, 0) at (x, y, z). Each cell the stamp holds anything at replaces the cell there: its terrain when the stamp set it, its rise, slant, ceiling and north and west edges, and its stack (none when the stamp's cell has none). A cell the stamp holds nothing at leaves w as it was.
pub fn stamp_box(s: const World) -> (integer, integer, integer, integer)
The box of a stamp: the cells it set or put things on, over every layer, as (x0, y0, x1, y1), corners included. A cell that only holds an edge, a rise, a slant or a ceiling is not counted: a part's size is its cells'. An empty stamp's box is the single cell (0, 0).
pub fn stamp_size(s: const World, turn: integer) -> (integer, integer)
The size of a stamp's box, (width, height), once turned turn quarters.
pub fn stamp_spot(x0: integer, y0: integer, x1: integer, y1: integer, turn: integer, flip: boolean, x: integer, y: integer) -> (integer, integer)
Where cell (x, y) of a stamp whose box is (x0, y0, x1, y1) lands, counted from the turned box's north-west corner: mirrored east to west first (flip), then turned clockwise turn quarters. For what a game keeps beside its world — a figure on a cell, a lock on a door — to go where its cell goes. A cell outside the box lands outside the turned box, as far.
pub fn turned_side(side: integer, turn: integer, flip: boolean) -> integer
The side (NORTH, EAST, SOUTH, WEST) side becomes: mirrored east to west, then turned clockwise.
pub fn turned_slant(way: integer, turn: integer, flip: boolean) -> integer
The way a slant looks (NORTH_EAST .. NORTH_WEST, 0 for none) once mirrored and turned.
pub fn turned(s: const World, turn: integer, flip: boolean = false) -> World
Stamp s mirrored east to west (flip) and then turned clockwise turn quarters, as a stamp: its box's north-west corner at (0, 0), its layers as they were. Every cell goes where stamp_spot says, with its terrain, rise, ceiling and stack; its slant looks the turned way; its edges are on their turned sides. Turned four times, or mirrored twice, it is the stamp again (moved so its box begins at (0, 0)).
pub fn lay(w: World, from: const World, x: integer, y: integer, z: integer)
Lay stamp from on w with its (0, 0, 0) at (x, y, z): only what the stamp holds is written. - a cell it SET (to anything, void included) replaces the cell there: its terrain, rise, slant and ceiling, and its stack (none when the stamp's cell has none); - a cell it left UNSET leaves w's cell as it is, so the stamp takes the shape of what it is laid on; - an edge it holds is written; an edge it does not hold is left alone, so a stamp adds and changes edges and never removes one; - things on a cell it left unset still replace the stack there. paste is the other rule: there every cell the stamp holds anything at is replaced whole, its edges with it.