landMap.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 level should be normalized
  21. // between 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 map from.
  30. // Normalized between 0.0 and 1.0.
  31. double *heightmap,
  32. // The width of the heightmap
  33. unsigned width,
  34. // The height of the heightmap
  35. unsigned height,
  36. // If the current landMap should be overwritten or a new one
  37. // should be created
  38. bool overwriteOldMap);
  39. // Returns a pointer to this->surfaceHeightmap
  40. double *generateSurfaceHeightMap(
  41. // The heightmap array to derive the surface height map from.
  42. // Normalized between 0.0 and 1.0.
  43. double *heightmap,
  44. // The width of the heightmap
  45. unsigned width,
  46. // The height of the heightmap
  47. unsigned height,
  48. // If the current surfaceHeightMap and landMap should be
  49. // overwritten or a new one should be created.
  50. bool overwriteOldMap);
  51. // A pointer to an one dimensional boolean array of the
  52. // same size as the heightmap. true signifies land, while false
  53. // signifies sea.
  54. // NOTE: Will contain valid data if generateLandMap has been
  55. // called
  56. bool *landMap;
  57. // A pointer to an one dimensional double array of the same size
  58. // as the heightmap. The values show the height of the
  59. // surface. This means that on places which are determined to be
  60. // land the value is the same as the heightmap, but on places
  61. // which arent the value is equal to the waterLevel.
  62. // NOTE: Will only contain valid dat if generateSurfaceHeightMap
  63. // has been called.
  64. double *surfaceHeightMap;
  65. private:
  66. double waterLevel;
  67. bool firstMap;
  68. // Writes to the points adjacent to (x, y) if they are part of the
  69. // sea, when (x, y) is part of the sea.
  70. // Returns true to signify that it found at least one new part of
  71. // sea. Returns false if it failed to find a new point of sea.
  72. bool spreadFrom(
  73. // x and y coordinates to spread from
  74. unsigned x,
  75. unsigned y,
  76. // The width and height of the belowSeaLevelMap and the
  77. // landMap
  78. unsigned width,
  79. unsigned height,
  80. // The map that signifies whether a point is below sea level
  81. bool *belowSeaLevel,
  82. // The map to write to which points are below sea level.
  83. bool *landMap);
  84. };