landMap.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 = true);
  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 = true);
  51. // A pointer to an one dimensional boolean array of the same size
  52. // as the heightmap. true signifies land, and lakes while false
  53. // signifies sea.
  54. // NOTE: Will only contain valid data if generateLandMap has been
  55. // called
  56. // Lakes are now also on land but are not covered by this map, any
  57. // true value can be land, lake or river.
  58. bool *landMap;
  59. // A pointer to an one dimensional double array of the same size
  60. // as the heightmap. The values show the height of the
  61. // surface. This means that on places which are determined to be
  62. // land the value is the same as the heightmap, but on places
  63. // which arent the value is equal to the waterLevel.
  64. // NOTE: Will only contain valid dat if generateSurfaceHeightMap
  65. // has been called.
  66. double *surfaceHeightmap;
  67. private:
  68. double waterLevel;
  69. bool firstLandMap, firstSurfaceHeightmap;
  70. int previousWidthLandMap, previousHeightLandMap,
  71. previousWidthHeightmap, previousHeightHeightmap;
  72. // Writes to the points adjacent to (x, y) if they are part of the
  73. // sea, when (x, y) is part of the sea.
  74. // Returns true to signify that it found at least one new part of
  75. // sea. Returns false if it failed to find a new point of sea.
  76. bool spreadFrom(
  77. // x and y coordinates to spread from
  78. unsigned x,
  79. unsigned y,
  80. // The width and height of the belowSeaLevelMap and the
  81. // landMap
  82. unsigned width,
  83. unsigned height,
  84. // The map that signifies whether a point is below sea level
  85. bool *belowSeaLevel,
  86. // The map to write to which points are below sea level.
  87. bool *landMap);
  88. };