Version 1 (modified by trac, 16 years ago) ( diff )

--

This page will cover the implementation of the random map generator. Back to Random Map Generator

Source Structure

The following source files make up RmGen (each .cpp file has an associated .h):

  • stdafx.h: Precompiled header.
  • 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.
  • random.cpp: Random map generator (currently using Boost::Random's Mersenne Twister)
  • point.cpp: 2D point structure with integer coordinates.
  • api.cpp: C++ functions available directly to JavaScripts.
  • 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).
  • 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).
  • output.cpp: Functions for outputting the map to PMP/XML
  • map.cpp: The map class, providing functions to access texture/elevation data, add entities and place areas.
  • entity.cpp: Entity class
  • 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.
  • area.cpp: Area class, which consists of just a numerical ID and a list of points for now.
  • constraint.cpp: Constraint interface, which can either allow or disallow placement on a tile.
  • areaplacer.cpp: AreaPlacer interface, which selects a set of points to place an area on or returns failure given a constraint.
  • areapainter.cpp: AreaPainter interface, which performs an action on a given Area.
  • simplepainters.cpp: Simple area painters (such as TerrainPainter).
  • simpleconstraints.cpp: Simple constraints (such as NullConstraint, simple avoid constraints and AND/OR constraints).
  • smoothelevationpainter.cpp: SmoothElevationPainter class: raises/lowers an area to a specific elevation or by a specific delta, with smoothing around the edges.
  • clumpplacer.cpp: ClumpPlacer class: places a clump with given size, coherence, smoothness and center point.
  • 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).
Note: See TracWiki for help on using the wiki.