Advertisement
Doyousketch2

Minetest minimap cross - minimap.cpp:345

Feb 25th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. void Minimap::blitMinimapPixelsToImageRadar(video::IImage *map_image)
  2. {
  3.     int halfmap = data->map_size / 2;
  4.     int reticleSize = data->map_size * 0.3;
  5.     int reticleSize2 = data->map_size - reticleSize;
  6.     int reticleSizeN = data->map_size * 0.8;
  7.     video::SColor c(240, 0, 0, 0);
  8.     for (s16 x = 0; x < data->map_size; x++)
  9.     for (s16 z = 0; z < data->map_size; z++) {
  10.         MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->map_size];
  11.  
  12.         if ((z > reticleSizeN) && (x == halfmap))
  13.             c.setGreen(255);  // North
  14.         else if ((x > reticleSize2) && (z == halfmap))
  15.             c.setGreen(160);  // East
  16.         else if ((z < reticleSize) && (x == halfmap))
  17.             c.setGreen(120);  // South
  18.         else if ((x < reticleSize) && (z == halfmap))
  19.             c.setGreen(160);  // West
  20.         else if ((x == halfmap) && (z == halfmap))
  21.             c.setGreen(0);  // Player dot
  22.         else if (mmpixel->air_count > 0)
  23.             c.setGreen(core::clamp(core::round32(32 + mmpixel->air_count * 8), 0, 255));
  24.         else
  25.             c.setGreen(0);
  26.  
  27.         map_image->setPixel(x, data->map_size - z - 1, c);
  28.     }
  29. }
  30.  
  31. void Minimap::blitMinimapPixelsToImageSurface(
  32.     video::IImage *map_image, video::IImage *heightmap_image)
  33. {
  34.     int halfmap = data->map_size / 2;
  35.     int reticleSize = data->map_size * 0.3;
  36.     int reticleSize2 = data->map_size - reticleSize;
  37.     int reticleSizeN = data->map_size * 0.8;
  38.     // This variable creation/destruction has a 1% cost on rendering minimap
  39.     video::SColor tilecolor;
  40.     for (s16 x = 0; x < data->map_size; x++)
  41.     for (s16 z = 0; z < data->map_size; z++) {
  42.         MinimapPixel *mmpixel = &data->minimap_scan[x + z * data->map_size];
  43.  
  44.         const ContentFeatures &f = m_ndef->get(mmpixel->n);
  45.         const TileDef *tile = &f.tiledef[0];
  46.  
  47.         // Color of the 0th tile (mostly this is the topmost)
  48.         if(tile->has_color)
  49.             tilecolor = tile->color;
  50.         else
  51.             mmpixel->n.getColor(f, &tilecolor);
  52.  
  53.         if ((z > reticleSizeN) && (x == halfmap))
  54.             tilecolor.set(240, 0, 255, 0);  // North
  55.         else if ((x > reticleSize2) && (z == halfmap))
  56.             tilecolor.set(240, 0, 160, 0);  // East
  57.         else if ((z < reticleSize) && (x == halfmap))
  58.             tilecolor.set(240, 0, 120, 0);  // South
  59.         else if ((x < reticleSize) && (z == halfmap))
  60.             tilecolor.set(240, 0, 160, 0);  // West
  61.         else if ((x == halfmap) && (z == halfmap))
  62.             tilecolor.set(240, 0, 255, 0);  // Player dot
  63.         else tilecolor.set(240,
  64.                                 tilecolor.getRed() * f.minimap_color.getRed() / 255,
  65.                                 tilecolor.getGreen() * f.minimap_color.getGreen() / 255,
  66.                                 tilecolor.getBlue() * f.minimap_color.getBlue() / 255 );
  67.  
  68.         map_image->setPixel(x, data->map_size - z - 1, tilecolor);
  69.  
  70.         u32 h = mmpixel->height;
  71.         heightmap_image->setPixel(x,data->map_size - z - 1,
  72.             video::SColor(255, h, h, h));
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement