Advertisement
Guest User

Untitled

a guest
Feb 18th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. class MapgenTest : public Mapgen {
  2. ManualMapVoxelManipulator *vmanip;
  3. INodeDefManager *ndef;
  4.  
  5. void makeChunk(BlockMakeData *data) {
  6. vmanip = data->vmanip;
  7. ndef = data->nodedef;
  8.  
  9. v3s16 node_min = data->blockpos_min * MAP_BLOCKSIZE;
  10. v3s16 node_max = (data->blockpos_max + v3s16(1,1,1)) * MAP_BLOCKSIZE - v3s16(1,1,1);
  11.  
  12. MapNode n_air(ndef->getId("mapgen_air"));
  13. MapNode n_grass(ndef->getId("mapgen_dirt_with_grass"));
  14.  
  15. for (int z = node_min.Z; z <= node_max.Z; z++) {
  16. for (int y = node_min.Y; y <= node_max.Y; y++) {
  17. for (int x = node_min.X; x <= node_max.X; x++) {
  18. int i = vmanip->m_area.index(x, y, z);
  19. if (y == -4)
  20. vmanip->m_data[i] = n_grass;
  21. else
  22. vmanip->m_data[i] = n_air;
  23. }
  24. }
  25. }
  26.  
  27. updateLighting(node_min, node_max);
  28. }
  29.  
  30. int getGroundLevelAtPoint(v2s16 p) {
  31. return 0;
  32. }
  33.  
  34. void updateLighting(v3s16 nmin, v3s16 nmax) {
  35. enum LightBank banks[2] = {LIGHTBANK_DAY, LIGHTBANK_NIGHT};
  36.  
  37. VoxelArea a(nmin - v3s16(1,0,1) * MAP_BLOCKSIZE,
  38. nmax + v3s16(1,0,1) * MAP_BLOCKSIZE);
  39. bool block_is_underground = false;
  40. bool sunlight = !block_is_underground;
  41.  
  42. for (int i = 0; i < 2; i++) {
  43. enum LightBank bank = banks[i];
  44. core::map<v3s16, bool> light_sources;
  45. core::map<v3s16, u8> unlight_from;
  46.  
  47. voxalgo::clearLightAndCollectSources(*vmanip, a, bank, ndef, light_sources, unlight_from);
  48. voxalgo::propagateSunlight(*vmanip, a, sunlight, light_sources, ndef);
  49. vmanip->unspreadLight(bank, unlight_from, light_sources, ndef);
  50. vmanip->spreadLight(bank, light_sources, ndef);
  51. }
  52. }
  53. };
  54.  
  55. class MapgenTestParams : public MapgenParams {
  56. bool readParams(Settings *settings) {
  57. return true;
  58. }
  59.  
  60. void writeParams(Settings *settings) {
  61. }
  62. };
  63.  
  64. class MapgenTestFactory : public MapgenFactory {
  65. Mapgen *createMapgen(int mgid, MapgenParams *params, EmergeManager *emerge) {
  66. return new MapgenTest();
  67. }
  68.  
  69. MapgenParams *createMapgenParams() {
  70. return new MapgenTestParams();
  71. }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement