12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- /*
- Copyright (C) 2015 Marien Raat
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #pragma once
- // This class takes one dimensional double array as a heightmap and a
- // double as the water level.
- // It returns a one dimensional array of booleans where true signifies
- // land and false signifies sea.
- // Lakes are not generated by this class
- // Note: The heightmap and the water levelshould be normalized between
- // 0.0 and 1.0 for this class.
- class LandMapGenerator {
- public:
- LandMapGenerator();
- // Sets the water level
- void setWaterLevel(double waterLevel);
- // Returns a pointer to this->landMap
- bool *generateLandMap(
- // The heightmap array to derive the land
- // map from.
- // Normalized between 0.0 and 1.0.
- double *heightmap,
- // The width of the heightmap
- unsigned width,
- // The height of the heightmap
- unsigned height,
- // If the current landMap should be overwritten
- // or a new one should be created
- bool overwriteOldMap);
- // A pointer to an one dimensional boolean array of the
- // same size as the heightmap. true signifies land, while false
- // signifies sea.
- // Will contain valid data if generateLandMap has been called
- bool *landMap;
- private:
- double waterLevel;
- bool firstMap;
- // Writes to the points adjacent to (x, y) if they are part of the
- // sea, when (x, y) is part of the sea.
- // Returns true to signify that it found at least one new part of
- // sea. Returns false if it failed to find a new point of sea.
- bool spreadFrom(
- // x and y coordinates to spread from
- unsigned x,
- unsigned y,
- // The width and height of the belowSeaLevelMap
- // and the landMap
- unsigned width,
- unsigned height,
- // The map that signifies whether a point is below
- // sea level
- bool *belowSeaLevel,
- // The map to write to which points are below sea
- // level.
- bool *landMap);
- };
|