]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/minimap.cpp
Make Lint Happy
[dragonfireclient.git] / src / client / minimap.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "minimap.h"
21 #include <cmath>
22 #include "client.h"
23 #include "clientmap.h"
24 #include "settings.h"
25 #include "shader.h"
26 #include "mapblock.h"
27 #include "client/renderingengine.h"
28
29 ////
30 //// MinimapUpdateThread
31 ////
32
33 MinimapUpdateThread::~MinimapUpdateThread()
34 {
35         for (auto &it : m_blocks_cache) {
36                 delete it.second;
37         }
38
39         for (auto &q : m_update_queue) {
40                 delete q.data;
41         }
42 }
43
44 bool MinimapUpdateThread::pushBlockUpdate(v3s16 pos, MinimapMapblock *data)
45 {
46         MutexAutoLock lock(m_queue_mutex);
47
48         // Find if block is already in queue.
49         // If it is, update the data and quit.
50         for (QueuedMinimapUpdate &q : m_update_queue) {
51                 if (q.pos == pos) {
52                         delete q.data;
53                         q.data = data;
54                         return false;
55                 }
56         }
57
58         // Add the block
59         QueuedMinimapUpdate q;
60         q.pos = pos;
61         q.data = data;
62         m_update_queue.push_back(q);
63
64         return true;
65 }
66
67 bool MinimapUpdateThread::popBlockUpdate(QueuedMinimapUpdate *update)
68 {
69         MutexAutoLock lock(m_queue_mutex);
70
71         if (m_update_queue.empty())
72                 return false;
73
74         *update = m_update_queue.front();
75         m_update_queue.pop_front();
76
77         return true;
78 }
79
80 void MinimapUpdateThread::enqueueBlock(v3s16 pos, MinimapMapblock *data)
81 {
82         pushBlockUpdate(pos, data);
83         deferUpdate();
84 }
85
86 void MinimapUpdateThread::doUpdate()
87 {
88         QueuedMinimapUpdate update;
89
90         while (popBlockUpdate(&update)) {
91                 if (update.data) {
92                         // Swap two values in the map using single lookup
93                         std::pair<std::map<v3s16, MinimapMapblock *>::iterator, bool>
94                                         result = m_blocks_cache.insert(std::make_pair(
95                                                         update.pos, update.data));
96                         if (!result.second) {
97                                 delete result.first->second;
98                                 result.first->second = update.data;
99                         }
100                 } else {
101                         std::map<v3s16, MinimapMapblock *>::iterator it;
102                         it = m_blocks_cache.find(update.pos);
103                         if (it != m_blocks_cache.end()) {
104                                 delete it->second;
105                                 m_blocks_cache.erase(it);
106                         }
107                 }
108         }
109
110         if (data->map_invalidated && data->mode != MINIMAP_MODE_OFF) {
111                 getMap(data->pos, data->map_size, data->scan_height);
112                 data->map_invalidated = false;
113         }
114 }
115
116 void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
117 {
118         v3s16 pos_min(pos.X - size / 2, pos.Y - height / 2, pos.Z - size / 2);
119         v3s16 pos_max(pos_min.X + size - 1, pos.Y + height / 2, pos_min.Z + size - 1);
120         v3s16 blockpos_min = getNodeBlockPos(pos_min);
121         v3s16 blockpos_max = getNodeBlockPos(pos_max);
122
123         // clear the map
124         for (int z = 0; z < size; z++)
125                 for (int x = 0; x < size; x++) {
126                         MinimapPixel &mmpixel = data->minimap_scan[x + z * size];
127                         mmpixel.air_count = 0;
128                         mmpixel.height = 0;
129                         mmpixel.n = MapNode(CONTENT_AIR);
130                 }
131
132         // draw the map
133         v3s16 blockpos;
134         for (blockpos.Z = blockpos_min.Z; blockpos.Z <= blockpos_max.Z; ++blockpos.Z)
135                 for (blockpos.Y = blockpos_min.Y; blockpos.Y <= blockpos_max.Y;
136                                 ++blockpos.Y)
137                         for (blockpos.X = blockpos_min.X; blockpos.X <= blockpos_max.X;
138                                         ++blockpos.X) {
139                                 std::map<v3s16, MinimapMapblock *>::const_iterator
140                                                 pblock = m_blocks_cache.find(blockpos);
141                                 if (pblock == m_blocks_cache.end())
142                                         continue;
143                                 const MinimapMapblock &block = *pblock->second;
144
145                                 v3s16 block_node_min(blockpos * MAP_BLOCKSIZE);
146                                 v3s16 block_node_max(block_node_min + MAP_BLOCKSIZE - 1);
147                                 // clip
148                                 v3s16 range_min = componentwise_max(
149                                                 block_node_min, pos_min);
150                                 v3s16 range_max = componentwise_min(
151                                                 block_node_max, pos_max);
152
153                                 v3s16 pos;
154                                 pos.Y = range_min.Y;
155                                 for (pos.Z = range_min.Z; pos.Z <= range_max.Z; ++pos.Z)
156                                         for (pos.X = range_min.X; pos.X <= range_max.X;
157                                                         ++pos.X) {
158                                                 v3s16 inblock_pos = pos - block_node_min;
159                                                 const MinimapPixel &in_pixel =
160                                                                 block.data[inblock_pos.Z * MAP_BLOCKSIZE +
161                                                                                 inblock_pos.X];
162
163                                                 v3s16 inmap_pos = pos - pos_min;
164                                                 MinimapPixel &out_pixel =
165                                                                 data->minimap_scan[inmap_pos.X +
166                                                                                    inmap_pos.Z * size];
167
168                                                 out_pixel.air_count += in_pixel.air_count;
169                                                 if (in_pixel.n.param0 != CONTENT_AIR) {
170                                                         out_pixel.n = in_pixel.n;
171                                                         out_pixel.height =
172                                                                         inmap_pos.Y +
173                                                                         in_pixel.height;
174                                                 }
175                                         }
176                         }
177 }
178
179 ////
180 //// Mapper
181 ////
182
183 Minimap::Minimap(Client *client)
184 {
185         this->client = client;
186         this->driver = RenderingEngine::get_video_driver();
187         this->m_tsrc = client->getTextureSource();
188         this->m_shdrsrc = client->getShaderSource();
189         this->m_ndef = client->getNodeDefManager();
190
191         m_angle = 0.f;
192
193         // Initialize static settings
194         m_enable_shaders = g_settings->getBool("enable_shaders");
195         m_surface_mode_scan_height =
196                         g_settings->getBool("minimap_double_scan_height") ? 256 : 128;
197
198         // Initialize minimap data
199         data = new MinimapData;
200         data->mode = MINIMAP_MODE_OFF;
201         data->is_radar = false;
202         data->map_invalidated = true;
203         data->texture = NULL;
204         data->heightmap_texture = NULL;
205         data->minimap_shape_round = g_settings->getBool("minimap_shape_round");
206
207         // Get round minimap textures
208         data->minimap_mask_round = driver->createImage(
209                         m_tsrc->getTexture("minimap_mask_round.png"),
210                         core::position2d<s32>(0, 0),
211                         core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
212         data->minimap_overlay_round = m_tsrc->getTexture("minimap_overlay_round.png");
213
214         // Get square minimap textures
215         data->minimap_mask_square = driver->createImage(
216                         m_tsrc->getTexture("minimap_mask_square.png"),
217                         core::position2d<s32>(0, 0),
218                         core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
219         data->minimap_overlay_square = m_tsrc->getTexture("minimap_overlay_square.png");
220
221         // Create player marker texture
222         data->player_marker = m_tsrc->getTexture("player_marker.png");
223         // Create object marker texture
224         data->object_marker_red = m_tsrc->getTexture("object_marker_red.png");
225
226         // Create mesh buffer for minimap
227         m_meshbuffer = getMinimapMeshBuffer();
228
229         // Initialize and start thread
230         m_minimap_update_thread = new MinimapUpdateThread();
231         m_minimap_update_thread->data = data;
232         m_minimap_update_thread->start();
233 }
234
235 Minimap::~Minimap()
236 {
237         m_minimap_update_thread->stop();
238         m_minimap_update_thread->wait();
239
240         m_meshbuffer->drop();
241
242         data->minimap_mask_round->drop();
243         data->minimap_mask_square->drop();
244
245         driver->removeTexture(data->texture);
246         driver->removeTexture(data->heightmap_texture);
247         driver->removeTexture(data->minimap_overlay_round);
248         driver->removeTexture(data->minimap_overlay_square);
249         driver->removeTexture(data->object_marker_red);
250
251         delete data;
252         delete m_minimap_update_thread;
253 }
254
255 void Minimap::addBlock(v3s16 pos, MinimapMapblock *data)
256 {
257         m_minimap_update_thread->enqueueBlock(pos, data);
258 }
259
260 void Minimap::toggleMinimapShape()
261 {
262         MutexAutoLock lock(m_mutex);
263
264         data->minimap_shape_round = !data->minimap_shape_round;
265         g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
266         m_minimap_update_thread->deferUpdate();
267 }
268
269 void Minimap::setMinimapShape(MinimapShape shape)
270 {
271         MutexAutoLock lock(m_mutex);
272
273         if (shape == MINIMAP_SHAPE_SQUARE)
274                 data->minimap_shape_round = false;
275         else if (shape == MINIMAP_SHAPE_ROUND)
276                 data->minimap_shape_round = true;
277
278         g_settings->setBool("minimap_shape_round", data->minimap_shape_round);
279         m_minimap_update_thread->deferUpdate();
280 }
281
282 MinimapShape Minimap::getMinimapShape()
283 {
284         if (data->minimap_shape_round) {
285                 return MINIMAP_SHAPE_ROUND;
286         }
287
288         return MINIMAP_SHAPE_SQUARE;
289 }
290
291 void Minimap::setMinimapMode(MinimapMode mode)
292 {
293         static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = {{false, 0, 0},
294                         {false, m_surface_mode_scan_height, 256},
295                         {false, m_surface_mode_scan_height, 128},
296                         {false, m_surface_mode_scan_height, 64}, {true, 32, 128},
297                         {true, 32, 64}, {true, 32, 32}};
298
299         if (mode >= MINIMAP_MODE_COUNT)
300                 return;
301
302         MutexAutoLock lock(m_mutex);
303
304         data->is_radar = modedefs[mode].is_radar;
305         data->scan_height = modedefs[mode].scan_height;
306         data->map_size = modedefs[mode].map_size;
307         data->mode = mode;
308
309         m_minimap_update_thread->deferUpdate();
310 }
311
312 void Minimap::setPos(v3s16 pos)
313 {
314         bool do_update = false;
315
316         {
317                 MutexAutoLock lock(m_mutex);
318
319                 if (pos != data->old_pos) {
320                         data->old_pos = data->pos;
321                         data->pos = pos;
322                         do_update = true;
323                 }
324         }
325
326         if (do_update)
327                 m_minimap_update_thread->deferUpdate();
328 }
329
330 void Minimap::setAngle(f32 angle)
331 {
332         m_angle = angle;
333 }
334
335 void Minimap::blitMinimapPixelsToImageRadar(video::IImage *map_image)
336 {
337         video::SColor c(240, 0, 0, 0);
338         for (s16 x = 0; x < data->map_size; x++)
339                 for (s16 z = 0; z < data->map_size; z++) {
340                         MinimapPixel *mmpixel =
341                                         &data->minimap_scan[x + z * data->map_size];
342
343                         if (mmpixel->air_count > 0)
344                                 c.setGreen(core::clamp(
345                                                 core::round32(32 +
346                                                                 mmpixel->air_count * 8),
347                                                 0, 255));
348                         else
349                                 c.setGreen(0);
350
351                         map_image->setPixel(x, data->map_size - z - 1, c);
352                 }
353 }
354
355 void Minimap::blitMinimapPixelsToImageSurface(
356                 video::IImage *map_image, video::IImage *heightmap_image)
357 {
358         // This variable creation/destruction has a 1% cost on rendering minimap
359         video::SColor tilecolor;
360         for (s16 x = 0; x < data->map_size; x++)
361                 for (s16 z = 0; z < data->map_size; z++) {
362                         MinimapPixel *mmpixel =
363                                         &data->minimap_scan[x + z * data->map_size];
364
365                         const ContentFeatures &f = m_ndef->get(mmpixel->n);
366                         const TileDef *tile = &f.tiledef[0];
367
368                         // Color of the 0th tile (mostly this is the topmost)
369                         if (tile->has_color)
370                                 tilecolor = tile->color;
371                         else
372                                 mmpixel->n.getColor(f, &tilecolor);
373
374                         tilecolor.setRed(tilecolor.getRed() * f.minimap_color.getRed() /
375                                          255);
376                         tilecolor.setGreen(tilecolor.getGreen() *
377                                            f.minimap_color.getGreen() / 255);
378                         tilecolor.setBlue(tilecolor.getBlue() *
379                                           f.minimap_color.getBlue() / 255);
380                         tilecolor.setAlpha(240);
381
382                         map_image->setPixel(x, data->map_size - z - 1, tilecolor);
383
384                         u32 h = mmpixel->height;
385                         heightmap_image->setPixel(x, data->map_size - z - 1,
386                                         video::SColor(255, h, h, h));
387                 }
388 }
389
390 video::ITexture *Minimap::getMinimapTexture()
391 {
392         // update minimap textures when new scan is ready
393         if (data->map_invalidated)
394                 return data->texture;
395
396         // create minimap and heightmap images in memory
397         core::dimension2d<u32> dim(data->map_size, data->map_size);
398         video::IImage *map_image = driver->createImage(video::ECF_A8R8G8B8, dim);
399         video::IImage *heightmap_image = driver->createImage(video::ECF_A8R8G8B8, dim);
400         video::IImage *minimap_image = driver->createImage(video::ECF_A8R8G8B8,
401                         core::dimension2d<u32>(MINIMAP_MAX_SX, MINIMAP_MAX_SY));
402
403         // Blit MinimapPixels to images
404         if (data->is_radar)
405                 blitMinimapPixelsToImageRadar(map_image);
406         else
407                 blitMinimapPixelsToImageSurface(map_image, heightmap_image);
408
409         map_image->copyToScaling(minimap_image);
410         map_image->drop();
411
412         video::IImage *minimap_mask = data->minimap_shape_round
413                                                       ? data->minimap_mask_round
414                                                       : data->minimap_mask_square;
415
416         if (minimap_mask) {
417                 for (s16 y = 0; y < MINIMAP_MAX_SY; y++)
418                         for (s16 x = 0; x < MINIMAP_MAX_SX; x++) {
419                                 const video::SColor &mask_col =
420                                                 minimap_mask->getPixel(x, y);
421                                 if (!mask_col.getAlpha())
422                                         minimap_image->setPixel(
423                                                         x, y, video::SColor(0, 0, 0, 0));
424                         }
425         }
426
427         if (data->texture)
428                 driver->removeTexture(data->texture);
429         if (data->heightmap_texture)
430                 driver->removeTexture(data->heightmap_texture);
431
432         data->texture = driver->addTexture("minimap__", minimap_image);
433         data->heightmap_texture =
434                         driver->addTexture("minimap_heightmap__", heightmap_image);
435         minimap_image->drop();
436         heightmap_image->drop();
437
438         data->map_invalidated = true;
439
440         return data->texture;
441 }
442
443 v3f Minimap::getYawVec()
444 {
445         if (data->minimap_shape_round) {
446                 return v3f(std::cos(m_angle * core::DEGTORAD),
447                                 std::sin(m_angle * core::DEGTORAD), 1.0);
448         }
449
450         return v3f(1.0, 0.0, 1.0);
451 }
452
453 scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
454 {
455         scene::SMeshBuffer *buf = new scene::SMeshBuffer();
456         buf->Vertices.set_used(4);
457         buf->Indices.set_used(6);
458         static const video::SColor c(255, 255, 255, 255);
459
460         buf->Vertices[0] = video::S3DVertex(-1, -1, 0, 0, 0, 1, c, 0, 1);
461         buf->Vertices[1] = video::S3DVertex(-1, 1, 0, 0, 0, 1, c, 0, 0);
462         buf->Vertices[2] = video::S3DVertex(1, 1, 0, 0, 0, 1, c, 1, 0);
463         buf->Vertices[3] = video::S3DVertex(1, -1, 0, 0, 0, 1, c, 1, 1);
464
465         buf->Indices[0] = 0;
466         buf->Indices[1] = 1;
467         buf->Indices[2] = 2;
468         buf->Indices[3] = 2;
469         buf->Indices[4] = 3;
470         buf->Indices[5] = 0;
471
472         return buf;
473 }
474
475 void Minimap::drawMinimap()
476 {
477         video::ITexture *minimap_texture = getMinimapTexture();
478         if (!minimap_texture)
479                 return;
480
481         updateActiveMarkers();
482         v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
483         const u32 size = 0.25 * screensize.Y;
484
485         core::rect<s32> oldViewPort = driver->getViewPort();
486         core::matrix4 oldProjMat = driver->getTransform(video::ETS_PROJECTION);
487         core::matrix4 oldViewMat = driver->getTransform(video::ETS_VIEW);
488
489         driver->setViewPort(core::rect<s32>(
490                         screensize.X - size - 10, 10, screensize.X - 10, size + 10));
491         driver->setTransform(video::ETS_PROJECTION, core::matrix4());
492         driver->setTransform(video::ETS_VIEW, core::matrix4());
493
494         core::matrix4 matrix;
495         matrix.makeIdentity();
496
497         video::SMaterial &material = m_meshbuffer->getMaterial();
498         material.setFlag(video::EMF_TRILINEAR_FILTER, true);
499         material.Lighting = false;
500         material.TextureLayer[0].Texture = minimap_texture;
501         material.TextureLayer[1].Texture = data->heightmap_texture;
502
503         if (m_enable_shaders && !data->is_radar) {
504                 u16 sid = m_shdrsrc->getShader("minimap_shader", 1, 1);
505                 material.MaterialType = m_shdrsrc->getShaderInfo(sid).material;
506         } else {
507                 material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
508         }
509
510         if (data->minimap_shape_round)
511                 matrix.setRotationDegrees(core::vector3df(0, 0, 360 - m_angle));
512
513         // Draw minimap
514         driver->setTransform(video::ETS_WORLD, matrix);
515         driver->setMaterial(material);
516         driver->drawMeshBuffer(m_meshbuffer);
517
518         // Draw overlay
519         video::ITexture *minimap_overlay = data->minimap_shape_round
520                                                            ? data->minimap_overlay_round
521                                                            : data->minimap_overlay_square;
522         material.TextureLayer[0].Texture = minimap_overlay;
523         material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
524         driver->setMaterial(material);
525         driver->drawMeshBuffer(m_meshbuffer);
526
527         // Draw player marker on minimap
528         if (data->minimap_shape_round) {
529                 matrix.setRotationDegrees(core::vector3df(0, 0, 0));
530         } else {
531                 matrix.setRotationDegrees(core::vector3df(0, 0, m_angle));
532         }
533
534         material.TextureLayer[0].Texture = data->player_marker;
535         driver->setTransform(video::ETS_WORLD, matrix);
536         driver->setMaterial(material);
537         driver->drawMeshBuffer(m_meshbuffer);
538
539         // Reset transformations
540         driver->setTransform(video::ETS_VIEW, oldViewMat);
541         driver->setTransform(video::ETS_PROJECTION, oldProjMat);
542         driver->setViewPort(oldViewPort);
543
544         // Draw player markers
545         v2s32 s_pos(screensize.X - size - 10, 10);
546         core::dimension2di imgsize(data->object_marker_red->getOriginalSize());
547         core::rect<s32> img_rect(0, 0, imgsize.Width, imgsize.Height);
548         static const video::SColor col(255, 255, 255, 255);
549         static const video::SColor c[4] = {col, col, col, col};
550         f32 sin_angle = std::sin(m_angle * core::DEGTORAD);
551         f32 cos_angle = std::cos(m_angle * core::DEGTORAD);
552         s32 marker_size2 = 0.025 * (float)size;
553         for (std::list<v2f>::const_iterator i = m_active_markers.begin();
554                         i != m_active_markers.end(); ++i) {
555                 v2f posf = *i;
556                 if (data->minimap_shape_round) {
557                         f32 t1 = posf.X * cos_angle - posf.Y * sin_angle;
558                         f32 t2 = posf.X * sin_angle + posf.Y * cos_angle;
559                         posf.X = t1;
560                         posf.Y = t2;
561                 }
562                 posf.X = (posf.X + 0.5) * (float)size;
563                 posf.Y = (posf.Y + 0.5) * (float)size;
564                 core::rect<s32> dest_rect(s_pos.X + posf.X - marker_size2,
565                                 s_pos.Y + posf.Y - marker_size2,
566                                 s_pos.X + posf.X + marker_size2,
567                                 s_pos.Y + posf.Y + marker_size2);
568                 driver->draw2DImage(data->object_marker_red, dest_rect, img_rect,
569                                 &dest_rect, &c[0], true);
570         }
571 }
572
573 void Minimap::updateActiveMarkers()
574 {
575         video::IImage *minimap_mask = data->minimap_shape_round
576                                                       ? data->minimap_mask_round
577                                                       : data->minimap_mask_square;
578
579         const std::list<Nametag *> &nametags = client->getCamera()->getNametags();
580
581         m_active_markers.clear();
582
583         for (Nametag *nametag : nametags) {
584                 v3s16 pos = floatToInt(
585                                 nametag->parent_node->getAbsolutePosition() +
586                                                 intToFloat(client->getCamera()->getOffset(),
587                                                                 BS),
588                                 BS);
589                 pos -= data->pos - v3s16(data->map_size / 2, data->scan_height / 2,
590                                                    data->map_size / 2);
591                 if (pos.X < 0 || pos.X > data->map_size || pos.Y < 0 ||
592                                 pos.Y > data->scan_height || pos.Z < 0 ||
593                                 pos.Z > data->map_size) {
594                         continue;
595                 }
596                 pos.X = ((float)pos.X / data->map_size) * MINIMAP_MAX_SX;
597                 pos.Z = ((float)pos.Z / data->map_size) * MINIMAP_MAX_SY;
598                 const video::SColor &mask_col = minimap_mask->getPixel(pos.X, pos.Z);
599                 if (!mask_col.getAlpha()) {
600                         continue;
601                 }
602
603                 m_active_markers.emplace_back(
604                                 ((float)pos.X / (float)MINIMAP_MAX_SX) - 0.5,
605                                 (1.0 - (float)pos.Z / (float)MINIMAP_MAX_SY) - 0.5);
606         }
607 }
608
609 ////
610 //// MinimapMapblock
611 ////
612
613 void MinimapMapblock::getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos)
614 {
615
616         for (s16 x = 0; x < MAP_BLOCKSIZE; x++)
617                 for (s16 z = 0; z < MAP_BLOCKSIZE; z++) {
618                         s16 air_count = 0;
619                         bool surface_found = false;
620                         MinimapPixel *mmpixel = &data[z * MAP_BLOCKSIZE + x];
621
622                         for (s16 y = MAP_BLOCKSIZE - 1; y >= 0; y--) {
623                                 v3s16 p(x, y, z);
624                                 MapNode n = vmanip->getNodeNoEx(pos + p);
625                                 if (!surface_found && n.getContent() != CONTENT_AIR) {
626                                         mmpixel->height = y;
627                                         mmpixel->n = n;
628                                         surface_found = true;
629                                 } else if (n.getContent() == CONTENT_AIR) {
630                                         air_count++;
631                                 }
632                         }
633
634                         if (!surface_found)
635                                 mmpixel->n = MapNode(CONTENT_AIR);
636
637                         mmpixel->air_count = air_count;
638                 }
639 }