How luanti-org/luanti works
Purpose and entry points
Luanti is a C++ voxel game engine that runs an interactive client, a dedicated server, or local singleplayer; games and mods are Lua content. Process startup and mode selection originate in src/main.cpp, with client launch/game control in src/client/clientlauncher.cpp and authoritative server lifecycle in src/server.cpp. CMake defines the native build graph at CMakeLists.txt and src/CMakeLists.txt.
Core simulation and world model
The engine’s shared domain model represents voxel maps, nodes, entities, players, inventories, crafting, collision, lighting, and serialization. Persistent/in-memory map structures center on src/map.cpp, src/mapblock.cpp, and src/environment.cpp. Server specialization adds world ownership, active objects, player state, rollback, and inventory mutation through src/servermap.cpp, src/serverenvironment.cpp, and src/server/activeobjectmgr.cpp.
Server, generation, and persistence
The server simulates the world, invokes gameplay callbacks, generates/emerges map blocks, and persists data. Emerge/map-generation is separated from runtime map management in src/emerge.cpp, src/mapgen/mapgen.cpp, and generator variants such as src/mapgen/mapgen_v7.cpp. Database adapters provide a replaceable persistence boundary: files, SQLite3, LevelDB, PostgreSQL, and Redis under src/database/database.cpp, src/database/database-sqlite3.cpp, and src/database/database-postgresql.cpp.
Multiplayer protocol boundary
Client and server exchange engine protocol packets over the networking layer. Packet definitions, opcode dispatch, connection handling, and the transport implementation reside in src/network/networkprotocol.cpp, src/network/connection.cpp, and src/network/mtp/impl.cpp; server-side client/session management is src/server/clientiface.cpp. This is the principal trust boundary between remote clients and server-authoritative state.
Client runtime and rendering
The client receives replicated world/media state, maintains client-side environment and map meshes, processes input/UI, and renders through the bundled Irrlicht-derived graphics stack. Core gameplay loop is src/client/game.cpp; world replication/model is src/client/client.cpp and src/client/clientenvironment.cpp; asynchronous mesh construction is src/client/mesh_generator_thread.cpp. Rendering pipeline and effects are organized in src/client/render/pipeline.cpp, src/client/renderingengine.cpp, and GLSL assets such as client/shaders/nodes_shader/opengl_fragment.glsl. The graphics runtime is vendored in irr/, including SDL device support and OpenGL/GLES drivers.
Lua content and scripting boundary
Lua is the extension boundary for games, server mods, client mods, menus, mapgen, and restricted server-sent client-side mods. C++ Lua bindings and context-specific script hosts are in src/script/lua_api/, src/script/scripting_server.cpp, and src/script/scripting_client.cpp. Built-in Lua establishes standard engine behavior and UI: builtin/game/init.lua, builtin/mainmenu/init.lua, and builtin/client/init.lua. Installed game/mod content is discovered and configured via src/content/mods.cpp and src/content/subgames.cpp; games/devtest/ is the bundled engine-validation game.
Platform and external dependencies
Native targets use CMake and run across desktop platforms plus Android. Android wraps the native engine with Java/SDL activities in android/app/src/main/java/net/minetest/minetest/GameActivity.java and Gradle builds. Material dependencies include SDL, OpenGL/OpenGLES, Lua or LuaJIT, OpenAL/Vorbis, curl/HTTP, gettext, and optional database backends; discovery modules are under cmake/Modules/. Docker supports server deployment via Dockerfile.
Main entry points: server.cpp Server lifecycle · main.cpp Process startup · scripting_server.cpp Lua script hosts · servermap.cpp Server world state
Components 21
Native engine
- Process startup · Selects client, dedicated-server, or local-play mode.
src/main.cpp - Shared world model · Maps, blocks, environment, entities, and serialization.
src/map.cpp - Network protocol
src/network/networkprotocol.cpp - Network transport
src/network/mtp/impl.cpp
Authoritative server
- Server lifecycle
src/server.cpp - Server world state · Owns active objects, players, rollback, and inventories.
src/servermap.cpp - Emerge and mapgen
src/emerge.cpp - Map generator
src/mapgen/mapgen.cpp - Persistence adapters · Replaceable file, SQL, LevelDB, PostgreSQL, and Redis storage.
src/database/database.cpp - Server sessions
src/server/clientiface.cpp
Client and graphics
- Client launcher
src/client/clientlauncher.cpp - Client game loop
src/client/game.cpp - Client world replica
src/client/client.cpp - Mesh generation worker
src/client/mesh_generator_thread.cpp - Rendering pipeline · Renders meshes and effects through the Irrlicht-derived runtime.
src/client/render/pipeline.cpp - Irrlicht graphics runtime · SDL device and OpenGL/GLES drivers.
Lua content
- Lua script hosts · Context-specific server and client Lua hosts.
src/script/scripting_server.cpp - Built-in Lua behavior
builtin/game/init.lua - Games and mods · Discovers installed games and mods.
src/content/mods.cpp
Build and platform
- Native build graph
CMakeLists.txt - Android wrapper
android/app/src/main/java/net/minetest/minetest/GameActivity.java
Connections 22
- Process startup → Client launcher: starts client
- Process startup → Server lifecycle: starts server
- Client launcher → Client game loop: launches
- Server lifecycle → Server world state: owns
- Server world state → Shared world model: specializes
- Server lifecycle → Emerge and mapgen: requests blocks
- Emerge and mapgen → Map generator: generates
- Server world state → Persistence adapters: persists world
- Server lifecycle → Server sessions: manages clients
- Server sessions → Network protocol: dispatches packets
- Network protocol → Network transport: uses
- Network transport → Client world replica: replicates state
- Client game loop → Client world replica: updates
- Client world replica → Mesh generation worker: schedules meshes
- Mesh generation worker → Rendering pipeline: provides mesh data
- Rendering pipeline → Irrlicht graphics runtime: draws through
- Server lifecycle → Lua script hosts: invokes callbacks
- Client game loop → Lua script hosts: runs client scripts
- Lua script hosts → Built-in Lua behavior: loads
- Lua script hosts → Games and mods: executes content
- Native build graph → Process startup: builds
- Android wrapper → Process startup: hosts native engine