Package squidpony.squidgrid.mapping
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
Biome mapping is likely to need customization per-game, but some good starting points are
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
WorldMapGenerator.BiomeMapper
static class
WorldMapGenerator.DetailedBiomeMapper
A way to get biome information for the cells on a map when you want an area's biome to be a combination of two main biome types, such as "Grassland" or "TropicalRainforest", with the biomes varying in weight between areas.static class
WorldMapGenerator.EllipticalHammerMap
A concrete implementation ofWorldMapGenerator
that projects the world map onto an ellipse that should be twice as wide as it is tall (although you can stretch it by width and height that don't have that ratio).static class
WorldMapGenerator.EllipticalMap
A concrete implementation ofWorldMapGenerator
that projects the world map onto an ellipse that should be twice as wide as it is tall (although you can stretch it by width and height that don't have that ratio).static class
WorldMapGenerator.HyperellipticalMap
A concrete implementation ofWorldMapGenerator
that projects the world map onto a shape that resembles a mix part-way between an ellipse and a rectangle.static class
WorldMapGenerator.LocalMap
A concrete implementation ofWorldMapGenerator
that does no projection of the map, as if the area were completely flat or small enough that curvature is impossible to see.static class
WorldMapGenerator.LocalMimicMap
An unusual map generator that imitates an existing local map (such as a map of Australia, which it can do by default), without applying any projection or changing heat levels in the polar regions or equator.static class
WorldMapGenerator.MimicMap
An unusual map generator that imitates an existing map (such as a map of Earth, which it can do by default).static class
WorldMapGenerator.RotatingSpaceMap
A concrete implementation ofWorldMapGenerator
that imitates an infinite-distance perspective view of a world, showing only one hemisphere, that should be as wide as it is tall (its outline is a circle).static class
WorldMapGenerator.RoundSideMap
A concrete implementation ofWorldMapGenerator
that projects the world map onto a shape with a flat top and bottom but near-circular sides.static class
WorldMapGenerator.SimpleBiomeMapper
A way to get biome information for the cells on a map when you only need a single value to describe a biome, such as "Grassland" or "TropicalRainforest".static class
WorldMapGenerator.SpaceViewMap
A concrete implementation ofWorldMapGenerator
that imitates an infinite-distance perspective view of a world, showing only one hemisphere, that should be as wide as it is tall (its outline is a circle).static class
WorldMapGenerator.SphereMap
A concrete implementation ofWorldMapGenerator
that distorts the map as it nears the poles, expanding the smaller-diameter latitude lines in extreme north and south regions so they take up the same space as the equator; this counteracts certain artifacts that are common in Simplex noise world maps by using a 4D noise call to generate terrain, using a normal 3D noise call's result as the extra 4th dimension.static class
WorldMapGenerator.TilingMap
A concrete implementation ofWorldMapGenerator
that tiles both east-to-west and north-to-south. -
Field Summary
Fields Modifier and Type Field Description int
cacheA
int
cacheB
protected double
centerLongitude
static double
coastalWaterLower
static double
coastalWaterUpper
static double
deepWaterLower
static double
deepWaterUpper
static FastNoise
DEFAULT_NOISE
A FastNoise that has a higher frequency than that class defaults to, which is useful for maps here.static double
forestLower
static double
forestUpper
static double
grassLower
static double
grassUpper
double[][]
heatData
double
heatModifier
int
height
int[][]
heightCodeData
double[][]
heightData
GreasedRegion
landData
double
landModifier
double
maxHeat
double
maxHeight
double
maxHeightActual
double
maxWet
static double
mediumWaterLower
static double
mediumWaterUpper
double
minHeat
double
minHeight
double
minHeightActual
double
minWet
double[][]
moistureData
GWTRNG
rng
static double
rockLower
static double
rockUpper
static double
sandLower
static double
sandUpper
int
seedA
int
seedB
static double
shallowWaterLower
static double
shallowWaterUpper
static double
snowLower
static double
snowUpper
protected IntVLA
startCacheX
protected IntVLA
startCacheY
int
startX
int
startY
int
usedHeight
int
usedWidth
int
width
int
zoom
protected int
zoomStartX
protected int
zoomStartY
-
Constructor Summary
Constructors Modifier Constructor Description 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 implementsregenerate(int, int, int, int, double, double, int, int)
).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 implementsregenerate(int, int, int, int, double, double, int, int)
).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 implementsregenerate(int, int, int, int, double, double, int, int)
).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. -
Method Summary
Modifier and Type Method Description int
codeHeight(double high)
protected int
decodeX(int coded)
protected int
decodeY(int coded)
void
generate()
Generates a world using a random RNG state and all parameters randomized.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.void
generate(long state)
Generates a world using the specified RNG state as a long.double
getCenterLongitude()
Gets the longitude line the map is centered on, which should usually be between 0 and 2 * PI.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.protected abstract void
regenerate(int startX, int startY, int usedWidth, int usedHeight, double landMod, double heatMod, int stateA, int stateB)
protected static double
removeExcess(double radians)
void
setCenterLongitude(double centerLongitude)
Sets the center longitude line to a longitude measured in radians, from 0 to 2 * PI.int
wrapX(int x, int y)
int
wrapY(int x, int y)
void
zoomIn()
Doubles the resolution of the map and halves the area it covers; the 2D arrays this uses keep their sizes.void
zoomIn(int zoomAmount, int zoomCenterX, int zoomCenterY)
Doubles the resolution of the map and halves the area it covers repeatedly, doublingzoomAmount
times; the 2D arrays this uses keep their sizes.void
zoomOut()
Halves the resolution of the map and doubles the area it covers; the 2D arrays this uses keep their sizes.void
zoomOut(int zoomAmount, int zoomCenterX, int zoomCenterY)
Halves the resolution of the map and doubles the area it covers repeatedly, halvingzoomAmount
times; the 2D arrays this uses keep their sizes.
-
Field Details
-
width
-
height
-
seedA
-
seedB
-
cacheA
-
cacheB
-
rng
-
heightData
-
heatData
-
moistureData
-
landData
-
heightCodeData
-
landModifier
-
heatModifier
-
minHeight
-
maxHeight
-
minHeightActual
-
maxHeightActual
-
minHeat
-
maxHeat
-
minWet
-
maxWet
-
centerLongitude
-
zoom
-
startX
-
startY
-
usedWidth
-
usedHeight
-
startCacheX
-
startCacheY
-
zoomStartX
-
zoomStartY
-
DEFAULT_NOISE
A FastNoise that has a higher frequency than that class defaults to, which is useful for maps here. With the default FastNoise frequency of 1f/32f, the maps this produces are giant blurs.
Even though this is a FastNoise and so technically can be edited, that seems to have issues when there's more than one WorldMapGenerator that uses this field. So you can feel free to use this as a Noise2D or Noise3D when generators need one, but don't change it too much, if at all. -
deepWaterLower
- See Also:
- Constant Field Values
-
deepWaterUpper
- See Also:
- Constant Field Values
-
mediumWaterLower
- See Also:
- Constant Field Values
-
mediumWaterUpper
- See Also:
- Constant Field Values
-
shallowWaterLower
- See Also:
- Constant Field Values
-
shallowWaterUpper
- See Also:
- Constant Field Values
-
coastalWaterLower
- See Also:
- Constant Field Values
-
coastalWaterUpper
- See Also:
- Constant Field Values
-
sandLower
- See Also:
- Constant Field Values
-
sandUpper
- See Also:
- Constant Field Values
-
grassLower
- See Also:
- Constant Field Values
-
grassUpper
- See Also:
- Constant Field Values
-
forestLower
- See Also:
- Constant Field Values
-
forestUpper
- See Also:
- Constant Field Values
-
rockLower
- See Also:
- Constant Field Values
-
rockUpper
- See Also:
- Constant Field Values
-
snowLower
- See Also:
- Constant Field Values
-
snowUpper
- See Also:
- Constant Field Values
-
-
Constructor Details
-
WorldMapGenerator
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 implementsregenerate(int, int, int, int, double, double, int, int)
). Always makes a 256x256 map. If you were usingWorldMapGenerator(long, int, int)
, then this would be the same as passing the parameters0x1337BABE1337D00DL, 256, 256
. -
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 implementsregenerate(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 callgenerate(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 latermapHeight
- the height of the map(s) to generate; cannot be changed later
-
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 implementsregenerate(int, int, int, int, double, double, int, int)
). Takes an initial seed and the width/height of the map. TheinitialSeed
parameter may or may not be used, since you can specify the seed to use when you callgenerate(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 generatemapWidth
- the width of the map(s) to generate; cannot be changed latermapHeight
- the height of the map(s) to generate; cannot be changed later
-
-
Method Details
-
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
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
-
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 callzoomIn(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 asheightData
andmoistureData
will be the same. -
generate
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 callzoomIn(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 asheightData
andmoistureData
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
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 callzoomIn(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 asheightData
andmoistureData
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 negativeheatMod
- 1.125 is Earth-like, less than 1 is cooler, more than 1 is hotter; a random value will be used if this is negativestate
- the state to give this generator's RNG; if the same as the last call, this will reuse data
-
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 usingzoomIn(int, int, int)
or its overload. -
zoomOut
Halves the resolution of the map and doubles the area it covers repeatedly, halvingzoomAmount
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 usingzoomIn(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 edgezoomCenterY
- 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
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
Doubles the resolution of the map and halves the area it covers repeatedly, doublingzoomAmount
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 edgezoomCenterY
- 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
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 andwidth
, and y between 0 andheight
, both exclusive. Automatically wraps the Coord's values usingwrapX(int, int)
andwrapY(int, int)
. -
codeHeight
-
decodeX
-
decodeY
-
wrapX
-
wrapY
-