Expand description
The navmesh generator: plans the tiles of a run, fetches them (or reads them from a capture), builds them in parallel and assembles the mesh (spec 2.3, 8.4, 8.5).
§Threads
Three stages run inside one std::thread::scope, joined by bounded channels:
- fetchers (one per connection) claim the next plan index (a hand-back queue first, then a shared counter), fetch the tile and send it to the builders (queue bound 64);
- builders (
threads, default cores - 1, at least 1) build the tiles and send the results to the assembler (queue boundbuilders * 4); - the assembler is the calling thread. It keeps a reorder buffer keyed by plan index and applies
the results strictly in plan order, so the output is byte-identical for any
threadsandconnections(this deliberately differs from the completion order of the original, see the spec’s section 8.4).
The graph is acyclic and the assembler only ever waits for the result channel, which it always
drains into its reorder buffer. So every blocked send is eventually released: the assembler never
waits for a send, the builders therefore never wait for it, and the fetchers wait only for builders.
Each claimed plan index produces exactly one message (a tile, a skipped tile or an error), so the
assembler’s next-expected index is always eventually delivered. A fetcher whose connection died
(a final network error) puts its claimed index back into the hand-back queue and stops; the other
fetchers take it from there, and a fetcher with nothing left to claim waits while another one still has
an index in flight. Only the last fetcher to stop reports what is left (handed-back and unclaimed
indices) as fetch errors (small messages, so it ignores the window below).
The reorder buffer is bounded by a claim window: a fetcher that has claimed index i waits (on a
condition variable) while i >= applied + window before it fetches. The index the assembler waits
for is always below that limit, so its holder never waits and the wait is released as soon as that
tile is applied; a hung connection therefore stalls the run (until the receive timeout) but cannot
make the buffer grow past the window. A failing checkpoint or capture write, and a panic of the
assembler, set the stop flag and wake the waiting fetchers: they stop claiming, the channels close
as the stages finish and the run ends with GenerateReport::stopped set. A panic while building a
tile is caught and makes that tile fail; builders own the receiver of the fetch queue, so if every
builder is gone the fetchers’ sends fail and they return.
Structs§
- Generate
Options - Options of
generate. - Generate
Report - The result of
generate. - Progress
- How far a run has come; passed to the progress callback.
Enums§
- Source
- Where the tile geometry comes from.
Constants§
- MAX_
WORKERS - The most builder threads or connections
generateaccepts; more is an error (each is an operating system thread, and the channels are sized by them).
Functions§
- generate
- Generates a navmesh from
source. - plan_
tiles - The tiles of a run, in the order of spec 8.4.
- probe
- Asks the data server at
hostfor the world params (one attempt, no retry of the request).