Painted Metropolis
README.md
splats
The marks paint leaves, on the world and on things that move, within a budget.
A splat is a position, a surface normal, a radius and a pigment. It sits either on the world (x, y, z in world
metres) or on a thing (`target` = the thing's id, x, y, z in the thing's own space, so it travels with a car
or a person). The store keeps at most cfg.splats.max of them (the oldest goes first) and at most
cfg.splats.maxPerTarget on one thing, merges a new mark into a near one of the same pigment instead of
stacking, finds world marks near a point through a grid, ages the marks whose surface says they fade
(cfg.splats.rules[surface].life), and reports what changed since it was last asked so a renderer keeps up
without rescanning.
local Splats = require("~.modules.splats")
local store = Splats.new(cfg.splats)
local id, merged = store:add({ x, y, z, nx, ny, nz, radius = 0.4, pigment = "ochre", surface = "wall" })
store:add({ target = "car12", x = 0.2, y = 1.1, z = 1.9, radius = 0.3, pigment = "white", surface = "glass" })
-- (a second argument `true` adds without merging; spec.life overrides the surface rule's life)
store:near(x, z, 5) -- world splats within 5 m on the ground plane, nearest first
store:on("car12") -- the splats on a thing, oldest first
store:get(id) store:remove(id) store:count()
store:removeNear(x, z, r) -- scrubbed away; returns how many (only where the surface allows scrubbing)
store:removeOn("car12") -- washed; returns how many
store:tick(dt) -- ages fading marks; returns how many went
local delta = store:drain() -- { added = { splat }, changed = { splat }, removed = { id } } since last drain
local data = store:serialise() -- world splats as compact rows (centimetres), oldest first
Splats.restore(cfg.splats, data)
store:serialiseOn("car12") store:restoreOn("car12", rows) -- a thing's marks, to keep with the thing
The interface is documented in the header of init.luau; this file repeats it for the asset browser.