Repository navigation
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
RLK
---
Minimal C99 library for 2D grid-based games and roguelikes.
Build:
make # Build librlk.a
make lint # Static analysis (-Werror): lib + test/ + demo/
make test # Build + run all tests (unit + golden oracle, in test/)
make demo # Demos; the PXL viewer is also built when a pxl
# checkout exists (default sibling ../pxl, see below)
make check # Full validation: lint + test
make dist # Vendoring snapshot: rlk-<commit>.tar.gz
make clean # Remove build artifacts
Note: the Makefiles use BSD make. On Linux, use `bmake` or `pmake`
instead of GNU make.
Configuration:
Main configuration is defined in Makefile.inc.
Copy config.mk.example to config.mk to customize CFLAGS, PXL_DIR or library
paths.
The PXL viewer demo_viewer is built when a pxl checkout is found
(default: the sibling ../pxl; override with an absolute PXL_DIR); without one,
`make demo` builds only the standalone text demos. Backend: PXL_BACKEND = x11
(default) or sdl.
Vendoring:
rlk vendors as-is: flat sources, no generated files, no config header.
bmake dist # -> rlk-<commit>.tar.gz, unpack into vendor/rlk
Build the static lib with bmake (`bmake -C vendor/rlk`, link -lrlk -lm) or
compile the sources directly in your own build system:
cc -std=c99 -Ivendor/rlk -ffp-contract=off -c vendor/rlk/*.c
-ffp-contract=off is the determinism contract (Makefile.inc enforces it
under bmake; pass it yourself otherwise). Keep LICENSE in vendor/rlk and
record the upstream commit (vendor/rlk/VENDORED-AT).
Design:
- Zero allocation: the lib never calls malloc/free; all buffers are
caller-owned (doc/architecture.md, "Memory model").
- Determinism: same seed + same build -> identical world, byte for byte
(build flags enforced in Makefile.inc).
Documentation:
doc/architecture.md # Zones (base / domains / user land), memory model,
# determinism contract, recipes
doc/conventions.md # Naming rules
doc/stats.md # Map quality stats: what each probe measures, golden
# policy, multi-seed report (test/test_tilemap_gen)
Headers:
rlk.h # Umbrella header (includes all of the below)
Base — core:
err.h # Error codes (RLK_OK, RLK_E_INVALID, RLK_E_NOTFOUND)
hash.h # Deterministic 64-bit hashing
fmath.h # Math helpers (clamp, lerp, smoothstep, distances)
noise.h # Noise generation (value, perlin, fbm)
Base — data (POD, caller-owned):
entity.h # Generic entities: fixed-capacity list (push/get/move)
geom.h # Rect (region) + lattice (grid geometry on world)
grid.h # Coarse float grid with bilinear sampling
mask.h # Uint8 mask (weight, density, visibility) + constructors
# + 4-connected flood fill / component labelling (rlk_mask_flood, rlk_mask_components)
poi.h # Points of Interest (anchor, bbox, type, seed)
scatter.h # Stateless jittered-grid scatter (one point per cell)
stats.h # Deterministic map stats (entropy, edge/pair entropy,
# Moran's I, LZSS bits, patches) on caller-owned rasters
tilemap.h # Tile grid over a world rect + tile props + index/line drawing
Domain terrain:
slope.h # Slope from an elevation grid (Horn 3x3)
drain.h # Drainage: fill, D8 flow, accumulation, river SDF
hydro.h # Derived hydrology: slope, Strahler order, speed
Domain nav:
path.h # A* pathfinding (integer costs, lattice window) +
# rlk_path_snap (nearest enterable cell, ring scan)
path_distance.h # Multi-source distance field (flow field, nearest source)
Domain vision:
fov.h # Field of view (recursive shadowcasting)
Domain worldgen — pipeline (wg):
wg.h # Noise-field terrain generation engine
wg_region.h # Voronoi region (macro-area) stage
wg_drain.h # Drain reading stage
wg_hydro.h # Hydro reading stage
wg_relief.h # Standardised elevation stage
wg_rivers.h # River projection stage
wg_poi.h # POI detection stage
Domain worldgen — structure generators:
ca.h # Cellular Automata (caves)
bsp.h # Binary Space Partitioning (dungeons)
Chunked persistent world (on top of the wg pipeline):
world.h # rlk_world_t: macro field query without fine generation,
# on-demand chunks (seam-coherent), tile diffs applied on
# regeneration, save/load (seed + diffs), predicate search
Demos (demo/ is flat like the lib; prefixes mark generic vs demo-only blocks):
demo/demo_viewer.c # PXL viewer: demo_viewer [world|ca|bsp] [seed]
# (world mode: stage probes + river/POI/A* overlays)
demo/demo_world.c # Fantasy map in a terminal: tilemap_gen + ca/bsp per POI,
# scatter points, ASCII render, rlk_stats_* probes
demo/demo_gis.c # GIS raster export .asc/.pgm for external tools (QGIS/GDAL)
demo/tilemap_gen.* gen_* # Fantasy map generator package
demo/src_*.h gis_export.h # Viewer demo sources + GIS export helpers
demo/source.h viewer.h viewer_app.h widget.h font_6x10.h
# Generic PXL viewer harness (header-only)
Tests (test/): unit tests per module + test_tilemap_gen, the golden map-stats
oracle over the demo generator, run by `make test`.
License:
MIT. See LICENSE.