In my 2D-sideview game, I have certain biomes, each one having a unique sea level, or water height, (depending on the humidity of the biome). The terrain is composed of stacks of blocks, each being a type of land or being water. I want the height map to look something like this:
Terrain height does not always correlate to water height. It does so here for demo purposes.
Each lake must have a constant water height across.
What I've tried: To calculate if there is water in a region, I want to know the minimum water height of all biomes in that region. That will be the lake's water height.
However, I don't know how far the region extends on each side, so I can't find the minimum water height. If the water height was global/constant, I would search in both directions until I found a block above sea level (or a maximum distance was reached), but I don't know the water height, because I can't search for it, because I need the other water heights to search for this water height!
Some ideas that seem inefficient:
- Search for the endpoints of a potential lake at each biome water level, and choose the smallest water level to generate the lake.
- Find the smallest biome level in a max distance on each side, and choose the smallest water level to generate the lake.
Please tell there is a better way!
Edit:
- Terrain stacks (columns) are generated individually, then loaded into memory. When the player reaches a certain distance from the stack, it will get unloaded, and then regenerated again when the player is near. Every time a terrain stack is generated it must be exactly the same.
- For querying stack heights over and over again for calculating whether water should be on a stack, I cache the height and biome of some stacks beyond the loaded stacks in each direction; thus, it is not considered loaded (so entities can't move), but the basic information does not have to be recalculated.
No comments:
Post a Comment