mapgen_singlenode.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "mapgen_singlenode.h"
  17. #include "voxel.h"
  18. #include "mapblock.h"
  19. #include "mapnode.h"
  20. #include "map.h"
  21. #include "nodedef.h"
  22. #include "voxelalgorithms.h"
  23. #include "profiler.h"
  24. #include "emerge.h"
  25. //////////////////////// Mapgen Singlenode parameter read/write
  26. void MapgenSinglenodeParams::readParams(Settings *settings) {
  27. }
  28. void MapgenSinglenodeParams::writeParams(Settings *settings) {
  29. }
  30. ///////////////////////////////////////////////////////////////////////////////
  31. MapgenSinglenode::MapgenSinglenode(int mapgenid, MapgenParams *params) {
  32. flags = params->flags;
  33. }
  34. MapgenSinglenode::~MapgenSinglenode() {
  35. }
  36. //////////////////////// Map generator
  37. void MapgenSinglenode::makeChunk(BlockMakeData *data) {
  38. assert(data->vmanip);
  39. assert(data->nodedef);
  40. assert(data->blockpos_requested.X >= data->blockpos_min.X &&
  41. data->blockpos_requested.Y >= data->blockpos_min.Y &&
  42. data->blockpos_requested.Z >= data->blockpos_min.Z);
  43. assert(data->blockpos_requested.X <= data->blockpos_max.X &&
  44. data->blockpos_requested.Y <= data->blockpos_max.Y &&
  45. data->blockpos_requested.Z <= data->blockpos_max.Z);
  46. this->generating = true;
  47. this->vm = data->vmanip;
  48. this->ndef = data->nodedef;
  49. v3s16 blockpos_min = data->blockpos_min;
  50. v3s16 blockpos_max = data->blockpos_max;
  51. // Area of central chunk
  52. v3s16 node_min = blockpos_min*MAP_BLOCKSIZE;
  53. v3s16 node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1);
  54. content_t c_node = ndef->getId("mapgen_singlenode");
  55. if (c_node == CONTENT_IGNORE)
  56. c_node = CONTENT_AIR;
  57. MapNode n_node(c_node);
  58. for (s16 z = node_min.Z; z <= node_max.Z; z++)
  59. for (s16 y = node_min.Y; y <= node_max.Y; y++) {
  60. u32 i = vm->m_area.index(node_min.X, y, z);
  61. for (s16 x = node_min.X; x <= node_max.X; x++) {
  62. if (vm->m_data[i].getContent() == CONTENT_IGNORE)
  63. vm->m_data[i] = n_node;
  64. i++;
  65. }
  66. }
  67. // Add top and bottom side of water to transforming_liquid queue
  68. updateLiquid(&data->transforming_liquid, node_min, node_max);
  69. // Calculate lighting
  70. if (flags & MG_LIGHT)
  71. calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
  72. node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
  73. this->generating = false;
  74. }
  75. int MapgenSinglenode::getGroundLevelAtPoint(v2s16 p) {
  76. return 0;
  77. }