landMap.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (C) 2015 Marien Raat
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. // This class takes one dimensional double array as a heightmap and a
  16. // double as the water level.
  17. // It returns a one dimensional array of booleans where true signifies
  18. // land and false signifies sea.
  19. // Lakes are not generated by this class
  20. // Note: The heightmap and the water levelshould be normalized between
  21. // 0.0 and 1.0 for this class.
  22. class LandMapGenerator {
  23. public:
  24. LandMapGenerator();
  25. // Sets the water level
  26. void setWaterLevel(double waterLevel);
  27. // Returns a pointer to this->landMap
  28. bool *generateLandMap(
  29. // The heightmap array to derive the land
  30. // map from.
  31. // Normalized between 0.0 and 1.0.
  32. double *heightmap,
  33. // The width of the heightmap
  34. unsigned width,
  35. // The height of the heightmap
  36. unsigned height,
  37. // If the current landMap should be overwritten
  38. // or a new one should be created
  39. bool overwriteOldMap);
  40. // A pointer to an one dimensional boolean array of the
  41. // same size as the heightmap. true signifies land, while false
  42. // signifies sea.
  43. // Will contain valid data if generateLandMap has been called
  44. bool *landMap;
  45. private:
  46. double waterLevel;
  47. bool firstMap;
  48. // Writes to the points adjacent to (x, y) if they are part of the
  49. // sea, when (x, y) is part of the sea.
  50. // Returns true to signify that it found at least one new part of
  51. // sea. Returns false if it failed to find a new point of sea.
  52. bool spreadFrom(
  53. // x and y coordinates to spread from
  54. unsigned x,
  55. unsigned y,
  56. // The width and height of the belowSeaLevelMap
  57. // and the landMap
  58. unsigned width,
  59. unsigned height,
  60. // The map that signifies whether a point is below
  61. // sea level
  62. bool *belowSeaLevel,
  63. // The map to write to which points are below sea
  64. // level.
  65. bool *landMap);
  66. };