3 Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
20 #ifndef MINIMAP_HEADER
21 #define MINIMAP_HEADER
23 #include "irrlichttypes_extrabloated.h"
26 #include "jthread/jmutex.h"
27 #include "jthread/jsemaphore.h"
34 MINIMAP_MODE_SURFACEx1,
35 MINIMAP_MODE_SURFACEx2,
36 MINIMAP_MODE_SURFACEx4,
50 struct MinimapMapblock
52 MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
63 MinimapPixel minimap_scan[512 * 512];
65 bool minimap_shape_round;
66 video::IImage *minimap_image;
67 video::IImage *heightmap_image;
68 video::IImage *minimap_mask_round;
69 video::IImage *minimap_mask_square;
70 video::ITexture *texture;
71 video::ITexture *heightmap_texture;
72 video::ITexture *minimap_overlay_round;
73 video::ITexture *minimap_overlay_square;
74 video::ITexture *player_marker;
77 struct QueuedMinimapUpdate
80 MinimapMapblock *data;
82 QueuedMinimapUpdate();
83 ~QueuedMinimapUpdate();
87 A thread-safe queue of minimap mapblocks update tasks
90 class MinimapUpdateQueue
95 ~MinimapUpdateQueue();
97 bool addBlock(v3s16 pos, MinimapMapblock *data);
100 QueuedMinimapUpdate *pop();
104 JMutexAutoLock lock(m_mutex);
105 return m_queue.size();
109 std::list<QueuedMinimapUpdate*> m_queue;
113 class MinimapUpdateThread : public JThread
116 JSemaphore m_queue_sem;
117 MinimapUpdateQueue m_queue;
120 MinimapUpdateThread(IrrlichtDevice *device, Client *client)
122 this->device = device;
123 this->client = client;
124 this->driver = device->getVideoDriver();
125 this->tsrc = client->getTextureSource();
127 void getMap (v3s16 pos, s16 size, s16 height, bool radar);
128 MinimapPixel *getMinimapPixel (v3s16 pos, s16 height, s16 &pixel_height);
129 s16 getAirCount (v3s16 pos, s16 height);
130 video::SColor getColorFromId(u16 id);
132 void enqueue_Block(v3s16 pos, MinimapMapblock *data);
134 IrrlichtDevice *device;
136 video::IVideoDriver *driver;
137 ITextureSource *tsrc;
141 std::map<v3s16, MinimapMapblock *> m_blocks_cache;
147 MinimapUpdateThread *m_minimap_update_thread;
148 video::ITexture *minimap_texture;
149 scene::SMeshBuffer *m_meshbuffer;
150 bool m_enable_shaders;
154 Mapper(IrrlichtDevice *device, Client *client);
157 void addBlock(v3s16 pos, MinimapMapblock *data);
158 void setPos(v3s16 pos);
159 video::ITexture* getMinimapTexture();
161 MinimapMode getMinimapMode();
162 void setMinimapMode(MinimapMode mode);
163 void toggleMinimapShape();
164 scene::SMeshBuffer *getMinimapMeshBuffer();
166 IrrlichtDevice *device;
168 video::IVideoDriver *driver;
170 ITextureSource *tsrc;
171 IShaderSource *shdrsrc;