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