| 1 | This page will cover the implementation of the random map generator. [wiki:Random_Map_Generator Back to Random Map Generator] |
| 2 | |
| 3 | = Source Structure = |
| 4 | |
| 5 | The following source files make up !RmGen (each .cpp file has an associated .h): |
| 6 | * '''stdafx.h''': Precompiled header. |
| 7 | * '''rmgen.cpp''': Program entry point. Sets up !JavaScript engine then executes a file. The rmgen.h header exposes the JS engine objects and some utility functions. |
| 8 | * '''random.cpp''': Random map generator (currently using Boost::Random's Mersenne Twister) |
| 9 | * '''point.cpp''': 2D point structure with integer coordinates. |
| 10 | * '''api.cpp''': C++ functions available directly to !JavaScripts. |
| 11 | * '''objparse.cpp''': Utility functions for converting complex !JavaScript objects to their C++ counterparts (area placers, area painters, constraints, etc are all represented by classes in both JS and C++; this file converts a jsval to various types of C++ objects). |
| 12 | * '''rmlibrary.js''': !JavaScript part of the library; implements the complex objects such as area placers, area painters and constraints, as well as utility functions, and will eventually hold the high-level JS API. (Note: This file is located in binaries/mods/official/data/maps). |
| 13 | * '''output.cpp''': Functions for outputting the map to PMP/XML |
| 14 | * '''map.cpp''': The map class, providing functions to access texture/elevation data, add entities and place areas. |
| 15 | * '''entity.cpp''': Entity class |
| 16 | * '''terrain.cpp''': Terrain painter interface and some implementations (!SimpleTerrain, !RandomTerrain). By terrain here I mean a "logical terrain", which is not just a texture but also objects associated with each tile (for example, forest is a logical terrain). The Terrain interface only requires one method that paints a single tile, so a terrain object can actually paint different tiles with different textures/objects (as long as it does each one independently of the others) - see !RandomTerrain for example. |
| 17 | * '''area.cpp''': Area class, which consists of just a numerical ID and a list of points for now. |
| 18 | * '''constraint.cpp''': Constraint interface, which can either allow or disallow placement on a tile. |
| 19 | * '''areaplacer.cpp''': !AreaPlacer interface, which selects a set of points to place an area on or returns failure given a constraint. |
| 20 | * '''areapainter.cpp''': !AreaPainter interface, which performs an action on a given Area. |
| 21 | * '''simplepainters.cpp''': Simple area painters (such as !TerrainPainter). |
| 22 | * '''simpleconstraints.cpp''': Simple constraints (such as !NullConstraint, simple avoid constraints and AND/OR constraints). |
| 23 | * '''smoothelevationpainter.cpp''': !SmoothElevationPainter class: raises/lowers an area to a specific elevation or by a specific delta, with smoothing around the edges. |
| 24 | * '''clumpplacer.cpp''': !ClumpPlacer class: places a clump with given size, coherence, smoothness and center point. |
| 25 | * '''layeredpainter.cpp''': !LayeredPainter class: paints an area in "layers" of different terrains depending on each point's distance from the edge (for example, a dirt patch can have grass-dirt-50 on the outside and dirt on the inside to blend smoothly on grass terrain). |