Mapgen

Overview
A map generator (hereinafter referred to as "mapgen") object creates new map and responds to queries about map terrain. Each derived Mapgen class must implement the two pure virtual methods in the Mapgen interface, makeChunk and getGroundLevelAtPoint.

Members of a Mapgen object are guaranteed to be valid data used in the latest call of makeChunk by that object.

Access of Mapgen objects are typically not thread-safe.

Pure virtual methods to be implemented
Returns the ground height at the 2d coordinates p.

Given a BlockMakeData structure, update the included ManualMapVoxelManipulator for the range of blocks from blockpos_min up to and also blockpos_max with MapNodes from the included INodeDefManager.

Non-virtual methods
Add liquids that need to be updated to the transforming_liquid queue. Set all nodes' light levels in vm to the specified, uniform light level. Calculate and update the lighting for nodes in vm. Same as calcLighting and may be slightly more accurate, but 22x slower on average.

Members
u64 seed The map seed used for generation. int water_level The node Y position below which water occurs, and MapBlocks are marked as being underground. bool generating Signifies if the Mapgen object is currently in a call to makeChunk. Reading this variable is not thread safe, but this is not problematic since it is intended to be used for informational purposes, such as profilers or output, rather than synchronization. int id The ID and index of that Mapgen in the EmergeManager. ManualMapVoxelManipulator *vm Must be a pointer to a valid ManualMapVoxelManipulator while makeChunk is executed. Set this equal to what is given in BlockMakeData. INodeDefManager *ndef Must be a pointer to a valid INodeDefManager while makeChunk is executed. Set this equal to what is given in BlockMakeData. v3s16 csize Represents the size of the chunk that the Mapgen expects to process on makeChunk. s16 *heightmap An X, Z array of ground level points in the most recently generated chunk. It is csize.X * csize.Z elements large. This member is NULL if the mapgen does not support heightmaps. u8 *biomemap An X, Z array of biome IDs (indices of biomes in the BiomeDefManager) at each horizontal point in the most recently generated chunk. It is csize.X * csize.Z elements large. This member is NULL if the mapgen does not support biomes.

BlockMakeData
A BlockMakeData structure has the following members:

ManualMapVoxelManipulator *vmanip The ManualMapVoxelManipulator where nodes are to be written to. Already contains the current map contents in the contained coordinates. If a node has not previously been written to, it is CONTENT_IGNORE.

u64 seed The 64-bit map seed to be used for randomized events. Not need anymore, as the base MapgenParams object passed to MapgenFactory::createMapgen will contain this as well.

v3s16 blockpos_min v3s16 blockpos_max Respectively, the minimum and maximum (inclusive) block (NOT NODE) coordinates to be generated.

v3s16 blockpos_requested The block coordinate of the actual block requested for generation. Not really necessary.

UniqueQueue transforming_liquid A UniqueQueue of 3d coordinates specifying which nodes are liquid and need a liquid transform applied after generation so they can flow.

INodeDefManager *nodedef A NodeDef that contains the definitions for nodes to be placed to the ManualMapVoxelManipulator.

Boilerplate Mapgen Code
Here is the bare minimum for a (playable) map generator: Then, simply add to EmergeManager::EmergeManager.