Engine Showcase
README.md
blocks
An endless block world. Chunked procedural terrain that auto-streams around the local player as they move. Each chunk builds one merged mesh per block-type so the engine pipeline can apply per-type materials in a single draw per type.
Exports
M.generate(opts: GenerateOpts?) -> GenerateResult— set lighting and load the chunks around the origin.M.loadChunk(cx: number, cz: number) -> ChunkRecord— build and spawn a single chunk.M.unloadChunk(cx: number, cz: number)— despawn the chunk's entities.M.updateChunks(worldX: number, worldZ: number) -> UpdateResult— reconcile loaded chunks against a player position; loads/unloads as needed.M.getLoadedChunkCount() -> number— chunk count.M.clearAll()— unload everything.M.enableStreaming(target: string)— attach theBlockStreamercomponent totarget, so chunks stream around it. Idempotent.M.config: Config— chunkSize / chunkHeight / viewDistance / waterLevel / treeSpacing / treeMinHeight / treeMaxHeight. Mutate before generate.
Types:
Config = { chunkSize: number, chunkHeight: number, viewDistance: number, waterLevel: number, treeSpacing: number, treeMinHeight: number, treeMaxHeight: number }GenerateOpts = { viewDistance: number?, chunkSize: number?, chunkHeight: number? }ChunkRecord = { root: string, children: { string }, faces: number, cx: number, cz: number }UpdateResult = { loaded: number, unloaded: number, totalChunks: number }GenerateResult = { chunks: number, faces: number }
Usage
local mc = require("showcase.blockWorld.blocks")
mc.generate({ viewDistance = 3 })
-- Per-frame (driven by the auto-attached streamer component):
-- mc.updateChunks(playerX, playerZ)
Notes
- Terrain noise is a sum of sines (WASM-safe; no bit ops, no allocation).
- The streamer component runs at 0.5 s intervals and calls
updateChunksonly when the player crosses into a new chunk — otherwise it's a cheap timer increment. - Each chunk uses a parent + per-block-type child layout so a single setParent groups the chunk for unload. Despawning the root despawns the children as well.
- World coordinates use a left-handed Z (the
-(z + ...)flips rendering) — keep this in mind if you mix in entities outside the module.