]> git.lizzy.rs Git - dragonfireclient.git/blob - src/minimap.h
Use C++11 mutexes only (remove compat code) (#5922)
[dragonfireclient.git] / src / minimap.h
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 "threading/semaphore.h"
27 #include <map>
28 #include <string>
29 #include <vector>
30 #include "camera.h"
31
32 #define MINIMAP_MAX_SX 512
33 #define MINIMAP_MAX_SY 512
34
35
36 enum MinimapMode {
37         MINIMAP_MODE_OFF,
38         MINIMAP_MODE_SURFACEx1,
39         MINIMAP_MODE_SURFACEx2,
40         MINIMAP_MODE_SURFACEx4,
41         MINIMAP_MODE_RADARx1,
42         MINIMAP_MODE_RADARx2,
43         MINIMAP_MODE_RADARx4,
44         MINIMAP_MODE_COUNT,
45 };
46
47 enum MinimapShape {
48         MINIMAP_SHAPE_SQUARE,
49         MINIMAP_SHAPE_ROUND,
50 };
51
52 struct MinimapModeDef {
53         bool is_radar;
54         u16 scan_height;
55         u16 map_size;
56 };
57
58 struct MinimapPixel {
59         //! The topmost node that the minimap displays.
60         MapNode n;
61         u16 height;
62         u16 air_count;
63 };
64
65 struct MinimapMapblock {
66         void getMinimapNodes(VoxelManipulator *vmanip, v3s16 pos);
67
68         MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
69 };
70
71 struct MinimapData {
72         bool is_radar;
73         MinimapMode mode;
74         v3s16 pos;
75         v3s16 old_pos;
76         u16 scan_height;
77         u16 map_size;
78         MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
79         bool map_invalidated;
80         bool minimap_shape_round;
81         video::IImage *minimap_image;
82         video::IImage *heightmap_image;
83         video::IImage *minimap_mask_round;
84         video::IImage *minimap_mask_square;
85         video::ITexture *texture;
86         video::ITexture *heightmap_texture;
87         video::ITexture *minimap_overlay_round;
88         video::ITexture *minimap_overlay_square;
89         video::ITexture *player_marker;
90         video::ITexture *object_marker_red;
91 };
92
93 struct QueuedMinimapUpdate {
94         v3s16 pos;
95         MinimapMapblock *data;
96 };
97
98 class MinimapUpdateThread : public UpdateThread {
99 public:
100         MinimapUpdateThread() : UpdateThread("Minimap") {}
101         virtual ~MinimapUpdateThread();
102
103         void getMap(v3s16 pos, s16 size, s16 height);
104         void enqueueBlock(v3s16 pos, MinimapMapblock *data);
105         bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
106         bool popBlockUpdate(QueuedMinimapUpdate *update);
107
108         MinimapData *data;
109
110 protected:
111         virtual void doUpdate();
112
113 private:
114         std::mutex m_queue_mutex;
115         std::deque<QueuedMinimapUpdate> m_update_queue;
116         std::map<v3s16, MinimapMapblock *> m_blocks_cache;
117 };
118
119 class Minimap {
120 public:
121         Minimap(IrrlichtDevice *device, Client *client);
122         ~Minimap();
123
124         void addBlock(v3s16 pos, MinimapMapblock *data);
125
126         v3f getYawVec();
127
128         void setPos(v3s16 pos);
129         v3s16 getPos() const { return data->pos; }
130         void setAngle(f32 angle);
131         f32 getAngle() const { return m_angle; }
132         void setMinimapMode(MinimapMode mode);
133         MinimapMode getMinimapMode() const { return data->mode; }
134         void toggleMinimapShape();
135         void setMinimapShape(MinimapShape shape);
136         MinimapShape getMinimapShape();
137
138
139         video::ITexture *getMinimapTexture();
140
141         void blitMinimapPixelsToImageRadar(video::IImage *map_image);
142         void blitMinimapPixelsToImageSurface(video::IImage *map_image,
143                 video::IImage *heightmap_image);
144
145         scene::SMeshBuffer *getMinimapMeshBuffer();
146
147         void updateActiveMarkers();
148         void drawMinimap();
149
150         video::IVideoDriver *driver;
151         Client* client;
152         MinimapData *data;
153
154 private:
155         ITextureSource *m_tsrc;
156         IShaderSource *m_shdrsrc;
157         INodeDefManager *m_ndef;
158         MinimapUpdateThread *m_minimap_update_thread;
159         scene::SMeshBuffer *m_meshbuffer;
160         bool m_enable_shaders;
161         u16 m_surface_mode_scan_height;
162         f32 m_angle;
163         std::mutex m_mutex;
164         std::list<v2f> m_active_markers;
165 };
166
167 #endif