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