Engine/Structure

From Minetest Developer Wiki
< Engine
Revision as of 11:56, 19 January 2013 by Celeron55 (talk | contribs)
Jump to navigation Jump to search

The base (NMPR)

Everything is built on a small core, that was the original network multiplayer release of Minetest (call it NMPR). Being around 8000 lines of code, it contains:

  • The map, including simple voxel lighting and rendering code
  • The client + server logic
  • The main loop, invoking the client, the server and the rendering.
  • A bunch of wrappers for OS-dependent things, and utilities.

As the current code still largely bases on the NMPR, it is useful to look at how it works.

More specifically, this refers to the 2010-10-24 16:33:41 version.

Map (the voxels)

-

Network protocol

The high-level network protocol of NMPR is delightfully simple. There are four commands for the server, and three commands for the client. Since this, a lot has been added and changed, but the basic idea stays the same.

Client -> Server

TOSERVER_GETBLOCK v3s16 p Ask the server to send the data of a block
TOSERVER_ADDNODE v3s16 p, MapNode node Inform the server of a placed node
TOSERVER_REMOVENODE v3s16 p, MapNode node Inform the server of a removed node
TOSERVER_PLAYERPOS v3s32 p*100, v3s32 speed*100 Inform the server of the positon of the local player

Server -> Client

TOCLIENT_BLOCKDATA v3s16 p, MapBlock data Send the content of a block (16x16x16 nodes)
TOCLIENT_ADDNODE v3s16 p, MapNode node Add a node
TOCLIENT_REMOVENODE v3s16 p, MapNode node Remove a node
TOCLIENT_PLAYERPOS foreach(player){
u16 player_id, v3s32 p*100, v3s32 speed*100}
Update players on client

Minetest uses it's own reliability layer on top of UDP. It isn't well documented at the moment, and thorough understanding of it isn't that important, so let's skip it as of now.

Rendering

-

Programming style

Minetest is designed in a fairly basic C++ object oriented way: Almost everything is contained within some kind of a class, with inheritance and interfaces being used sparingly in obvious ways.