Line data Source code
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 : #ifndef MINIMAP_HEADER
21 : #define MINIMAP_HEADER
22 :
23 : #include "irrlichttypes_extrabloated.h"
24 : #include "client.h"
25 : #include "voxel.h"
26 : #include "jthread/jmutex.h"
27 : #include "jthread/jsemaphore.h"
28 : #include <map>
29 : #include <string>
30 : #include <vector>
31 :
32 : enum MinimapMode {
33 : MINIMAP_MODE_OFF,
34 : MINIMAP_MODE_SURFACEx1,
35 : MINIMAP_MODE_SURFACEx2,
36 : MINIMAP_MODE_SURFACEx4,
37 : MINIMAP_MODE_RADARx1,
38 : MINIMAP_MODE_RADARx2,
39 : MINIMAP_MODE_RADARx4
40 : };
41 :
42 : struct MinimapPixel
43 : {
44 : u16 id;
45 : u16 height;
46 : u16 air_count;
47 : u16 light;
48 : };
49 :
50 : struct MinimapMapblock
51 : {
52 : MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
53 : };
54 :
55 1 : struct MinimapData
56 : {
57 : bool radar;
58 : MinimapMode mode;
59 : v3s16 pos;
60 : v3s16 old_pos;
61 : u16 scan_height;
62 : u16 map_size;
63 : MinimapPixel minimap_scan[512 * 512];
64 : bool map_invalidated;
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;
75 : };
76 :
77 : struct QueuedMinimapUpdate
78 : {
79 : v3s16 pos;
80 : MinimapMapblock *data;
81 :
82 : QueuedMinimapUpdate();
83 : ~QueuedMinimapUpdate();
84 : };
85 :
86 : /*
87 : A thread-safe queue of minimap mapblocks update tasks
88 : */
89 :
90 : class MinimapUpdateQueue
91 : {
92 : public:
93 : MinimapUpdateQueue();
94 :
95 : ~MinimapUpdateQueue();
96 :
97 : bool addBlock(v3s16 pos, MinimapMapblock *data);
98 :
99 : QueuedMinimapUpdate *pop();
100 :
101 3615 : u32 size()
102 : {
103 7230 : JMutexAutoLock lock(m_mutex);
104 7230 : return m_queue.size();
105 : }
106 :
107 : private:
108 : std::list<QueuedMinimapUpdate*> m_queue;
109 : JMutex m_mutex;
110 : };
111 :
112 : class MinimapUpdateThread : public UpdateThread
113 : {
114 : private:
115 : MinimapUpdateQueue m_queue;
116 : std::map<v3s16, MinimapMapblock *> m_blocks_cache;
117 :
118 : protected:
119 1 : const char *getName()
120 1 : { return "MinimapUpdateThread"; }
121 : virtual void doUpdate();
122 :
123 : public:
124 1 : MinimapUpdateThread(IrrlichtDevice *device, Client *client)
125 1 : {
126 1 : this->device = device;
127 1 : this->client = client;
128 1 : this->driver = device->getVideoDriver();
129 1 : this->tsrc = client->getTextureSource();
130 1 : }
131 : ~MinimapUpdateThread();
132 : void getMap (v3s16 pos, s16 size, s16 height, bool radar);
133 : MinimapPixel *getMinimapPixel (v3s16 pos, s16 height, s16 &pixel_height);
134 : s16 getAirCount (v3s16 pos, s16 height);
135 : video::SColor getColorFromId(u16 id);
136 :
137 : void enqueue_Block(v3s16 pos, MinimapMapblock *data);
138 : IrrlichtDevice *device;
139 : Client *client;
140 : video::IVideoDriver *driver;
141 : ITextureSource *tsrc;
142 : MinimapData *data;
143 : };
144 :
145 : class Mapper
146 : {
147 : private:
148 : MinimapUpdateThread *m_minimap_update_thread;
149 : video::ITexture *minimap_texture;
150 : scene::SMeshBuffer *m_meshbuffer;
151 : bool m_enable_shaders;
152 : u16 m_surface_mode_scan_height;
153 : JMutex m_mutex;
154 :
155 : public:
156 : Mapper(IrrlichtDevice *device, Client *client);
157 : ~Mapper();
158 :
159 : void addBlock(v3s16 pos, MinimapMapblock *data);
160 : void setPos(v3s16 pos);
161 : video::ITexture* getMinimapTexture();
162 : v3f getYawVec();
163 : MinimapMode getMinimapMode();
164 : void setMinimapMode(MinimapMode mode);
165 : void toggleMinimapShape();
166 : scene::SMeshBuffer *getMinimapMeshBuffer();
167 : void drawMinimap();
168 : IrrlichtDevice *device;
169 : Client *client;
170 : video::IVideoDriver *driver;
171 : LocalPlayer *player;
172 : ITextureSource *tsrc;
173 : IShaderSource *shdrsrc;
174 : MinimapData *data;
175 : };
176 :
177 : #endif
|