Class WorldMapGenerator

java.lang.Object
squidpony.squidgrid.mapping.WorldMapGenerator
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
WorldMapGenerator.EllipticalHammerMap, WorldMapGenerator.EllipticalMap, WorldMapGenerator.HyperellipticalMap, WorldMapGenerator.LocalMap, WorldMapGenerator.RotatingSpaceMap, WorldMapGenerator.RoundSideMap, WorldMapGenerator.SpaceViewMap, WorldMapGenerator.SphereMap, WorldMapGenerator.TilingMap

public abstract class WorldMapGenerator
extends Object
implements Serializable
Can be used to generate world maps with a wide variety of data, starting with height, temperature and moisture. From there, you can determine biome information in as much detail as your game needs, with default implementations available; one assigns a single biome to each cell based on heat/moisture, and the other gives a gradient between two biome types for every cell. The maps this produces with WorldMapGenerator.SphereMap are valid for spherical world projections, while the maps from WorldMapGenerator.TilingMap are for toroidal world projections and will wrap from edge to opposite edge seamlessly thanks to a technique from the Accidental Noise Library that involves getting a 2D slice of 4D Simplex noise. Because of how Simplex noise works, this also allows extremely high zoom levels for all types of map as long as certain parameters are within reason. Other world maps produce more conventional shapes, like WorldMapGenerator.SpaceViewMap and WorldMapGenerator.RotatingSpaceMap make a view of a marble-like world from space, and others make more unconventional shapes, like WorldMapGenerator.EllipticalMap or WorldMapGenerator.EllipticalHammerMap, which form a 2:1 ellipse shape that accurately keeps sizes but not relative shapes, WorldMapGenerator.RoundSideMap, which forms a pill-shape, and WorldMapGenerator.HyperellipticalMap, which takes parameters so it can fit any shape between a circle or ellipse and a rectangle (the default is a slightly squared-off ellipse). You can access the height map with the heightData field, the heat map with the heatData field, the moisture map with the moistureData field, and a special map that stores ints representing the codes for various ranges of elevation (0 to 8 inclusive, with 0 the deepest ocean and 8 the highest mountains) with heightCodeData. The last map should be noted as being the simplest way to find what is land and what is water; any height code 4 or greater is land, and any height code 3 or less is water.
Biome mapping is likely to need customization per-game, but some good starting points are WorldMapGenerator.SimpleBiomeMapper, which stores one biome per cell, and WorldMapGenerator.DetailedBiomeMapper, which gives each cell a midway value between two biomes.
See Also:
Serialized Form
  • Field Details

  • Constructor Details

    • WorldMapGenerator

      protected WorldMapGenerator​(WorldMapGenerator other)
      Used to implement most of the copy constructor for subclasses; this cannot copy Noise implementations and leaves that up to the subclass, but will copy all non-static fields defined in WorldMapGenerator from other.
      Parameters:
      other - a WorldMapGenerator (subclass) to copy fields from
    • WorldMapGenerator

      protected WorldMapGenerator()
      Constructs a WorldMapGenerator (this class is abstract, so you should typically call this from a subclass or as part of an anonymous class that implements regenerate(int, int, int, int, double, double, int, int)). Always makes a 256x256 map. If you were using WorldMapGenerator(long, int, int), then this would be the same as passing the parameters 0x1337BABE1337D00DL, 256, 256.
    • WorldMapGenerator

      protected WorldMapGenerator​(int mapWidth, int mapHeight)
      Constructs a WorldMapGenerator (this class is abstract, so you should typically call this from a subclass or as part of an anonymous class that implements regenerate(int, int, int, int, double, double, int, int)). Takes only the width/height of the map. The initial seed is set to the same large long every time, and it's likely that you would set the seed when you call generate(long). The width and height of the map cannot be changed after the fact, but you can zoom in.
      Parameters:
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
    • WorldMapGenerator

      protected WorldMapGenerator​(long initialSeed, int mapWidth, int mapHeight)
      Constructs a WorldMapGenerator (this class is abstract, so you should typically call this from a subclass or as part of an anonymous class that implements regenerate(int, int, int, int, double, double, int, int)). Takes an initial seed and the width/height of the map. The initialSeed parameter may or may not be used, since you can specify the seed to use when you call generate(long). The width and height of the map cannot be changed after the fact, but you can zoom in.
      Parameters:
      initialSeed - the seed for the GWTRNG this uses; this may also be set per-call to generate
      mapWidth - the width of the map(s) to generate; cannot be changed later
      mapHeight - the height of the map(s) to generate; cannot be changed later
  • Method Details

    • getCenterLongitude

      public double getCenterLongitude()
      Gets the longitude line the map is centered on, which should usually be between 0 and 2 * PI.
      Returns:
      the longitude line the map is centered on, in radians from 0 to 2 * PI
    • setCenterLongitude

      public void setCenterLongitude​(double centerLongitude)
      Sets the center longitude line to a longitude measured in radians, from 0 to 2 * PI. Positive arguments will be corrected with modulo, but negative ones may not always act as expected, and are strongly discouraged.
      Parameters:
      centerLongitude - the longitude to center the map projection on, from 0 to 2 * PI (can be any non-negative double).
    • removeExcess

      protected static double removeExcess​(double radians)
    • generate

      public void generate()
      Generates a world using a random RNG state and all parameters randomized. The worlds this produces will always have width and height as specified in the constructor (default 256x256). You can call zoomIn(int, int, int) to double the resolution and center on the specified area, but the width and height of the 2D arrays this changed, such as heightData and moistureData will be the same.
    • generate

      public void generate​(long state)
      Generates a world using the specified RNG state as a long. Other parameters will be randomized, using the same RNG state to start with. The worlds this produces will always have width and height as specified in the constructor (default 256x256). You can call zoomIn(int, int, int) to double the resolution and center on the specified area, but the width and height of the 2D arrays this changed, such as heightData and moistureData will be the same.
      Parameters:
      state - the state to give this generator's RNG; if the same as the last call, this will reuse data
    • generate

      public void generate​(double landMod, double heatMod, long state)
      Generates a world using the specified RNG state as a long, with specific land and heat modifiers that affect the land-water ratio and the average temperature, respectively. The worlds this produces will always have width and height as specified in the constructor (default 256x256). You can call zoomIn(int, int, int) to double the resolution and center on the specified area, but the width and height of the 2D arrays this changed, such as heightData and moistureData will be the same.
      Parameters:
      landMod - 1.0 is Earth-like, less than 1 is more-water, more than 1 is more-land; a random value will be used if this is negative
      heatMod - 1.125 is Earth-like, less than 1 is cooler, more than 1 is hotter; a random value will be used if this is negative
      state - the state to give this generator's RNG; if the same as the last call, this will reuse data
    • zoomOut

      public void zoomOut()
      Halves the resolution of the map and doubles the area it covers; the 2D arrays this uses keep their sizes. This version of zoomOut always zooms out from the center of the currently used area.
      Only has an effect if you have previously zoomed in using zoomIn(int, int, int) or its overload.
    • zoomOut

      public void zoomOut​(int zoomAmount, int zoomCenterX, int zoomCenterY)
      Halves the resolution of the map and doubles the area it covers repeatedly, halving zoomAmount times; the 2D arrays this uses keep their sizes. This version of zoomOut allows you to specify where the zoom should be centered, using the current coordinates (if the map size is 256x256, then coordinates should be between 0 and 255, and will refer to the currently used area and not necessarily the full world size).
      Only has an effect if you have previously zoomed in using zoomIn(int, int, int) or its overload.
      Parameters:
      zoomCenterX - the center X position to zoom out from; if too close to an edge, this will stop moving before it would extend past an edge
      zoomCenterY - the center Y position to zoom out from; if too close to an edge, this will stop moving before it would extend past an edge
    • zoomIn

      public void zoomIn()
      Doubles the resolution of the map and halves the area it covers; the 2D arrays this uses keep their sizes. This version of zoomIn always zooms in to the center of the currently used area.
      Although there is no technical restriction on maximum zoom, zooming in more than 5 times (64x scale or greater) will make the map appear somewhat less realistic due to rounded shapes appearing more bubble-like and less like a normal landscape.
    • zoomIn

      public void zoomIn​(int zoomAmount, int zoomCenterX, int zoomCenterY)
      Doubles the resolution of the map and halves the area it covers repeatedly, doubling zoomAmount times; the 2D arrays this uses keep their sizes. This version of zoomIn allows you to specify where the zoom should be centered, using the current coordinates (if the map size is 256x256, then coordinates should be between 0 and 255, and will refer to the currently used area and not necessarily the full world size).
      Although there is no technical restriction on maximum zoom, zooming in more than 5 times (64x scale or greater) will make the map appear somewhat less realistic due to rounded shapes appearing more bubble-like and less like a normal landscape.
      Parameters:
      zoomCenterX - the center X position to zoom in to; if too close to an edge, this will stop moving before it would extend past an edge
      zoomCenterY - the center Y position to zoom in to; if too close to an edge, this will stop moving before it would extend past an edge
    • regenerate

      protected abstract void regenerate​(int startX, int startY, int usedWidth, int usedHeight, double landMod, double heatMod, int stateA, int stateB)
    • project

      public Coord project​(double latitude, double longitude)
      Given a latitude and longitude in radians (the conventional way of describing points on a globe), this gets the (x,y) Coord on the map projection this generator uses that corresponds to the given lat-lon coordinates. If this generator does not represent a globe (if it is toroidal, for instance) or if there is no "good way" to calculate the projection for a given lat-lon coordinate, this returns null. The default implementation always returns null. If this is a supported operation and the parameters are valid, this returns a Coord with x between 0 and width, and y between 0 and height, both exclusive. Automatically wraps the Coord's values using wrapX(int, int) and wrapY(int, int).
      Parameters:
      latitude - the latitude, from Math.PI * -0.5 to Math.PI * 0.5
      longitude - the longitude, from 0.0 to Math.PI * 2.0
      Returns:
      the point at the given latitude and longitude, as a Coord with x between 0 and width and y between 0 and height, or null if unsupported
    • codeHeight

      public int codeHeight​(double high)
    • decodeX

      protected final int decodeX​(int coded)
    • decodeY

      protected final int decodeY​(int coded)
    • wrapX

      public int wrapX​(int x, int y)
    • wrapY

      public int wrapY​(int x, int y)