]> git.lizzy.rs Git - minetest.git/blob - src/minimap.h
Biome API: Make fallback biome stone and water, disable filler
[minetest.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 <map>
24 #include <string>
25 #include <vector>
26 #include "irrlichttypes_extrabloated.h"
27 #include "client.h"
28 #include "voxel.h"
29 #include "jthread/jmutex.h"
30 #include "jthread/jsemaphore.h"
31
32 #define MINIMAP_MAX_SX 512
33 #define MINIMAP_MAX_SY 512
34
35 enum MinimapMode {
36         MINIMAP_MODE_OFF,
37         MINIMAP_MODE_SURFACEx1,
38         MINIMAP_MODE_SURFACEx2,
39         MINIMAP_MODE_SURFACEx4,
40         MINIMAP_MODE_RADARx1,
41         MINIMAP_MODE_RADARx2,
42         MINIMAP_MODE_RADARx4,
43         MINIMAP_MODE_COUNT,
44 };
45
46 struct MinimapModeDef {
47         bool is_radar;
48         u16 scan_height;
49         u16 map_size;
50 };
51
52 struct MinimapPixel {
53         u16 id;
54         u16 height;
55         u16 air_count;
56         u16 light;
57 };
58
59 struct MinimapMapblock {
60         void getMinimapNodes(VoxelManipulator *vmanip, v3s16 pos);
61
62         MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
63 };
64
65 struct MinimapData {
66         bool is_radar;
67         MinimapMode mode;
68         v3s16 pos;
69         v3s16 old_pos;
70         u16 scan_height;
71         u16 map_size;
72         MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
73         bool map_invalidated;
74         bool minimap_shape_round;
75         video::IImage *minimap_image;
76         video::IImage *heightmap_image;
77         video::IImage *minimap_mask_round;
78         video::IImage *minimap_mask_square;
79         video::ITexture *texture;
80         video::ITexture *heightmap_texture;
81         video::ITexture *minimap_overlay_round;
82         video::ITexture *minimap_overlay_square;
83         video::ITexture *player_marker;
84 };
85
86 struct QueuedMinimapUpdate {
87         v3s16 pos;
88         MinimapMapblock *data;
89 };
90
91 class MinimapUpdateThread : public UpdateThread {
92 public:
93         virtual ~MinimapUpdateThread();
94
95         void getMap(v3s16 pos, s16 size, s16 height, bool radar);
96         MinimapPixel *getMinimapPixel(v3s16 pos, s16 height, s16 *pixel_height);
97         s16 getAirCount(v3s16 pos, s16 height);
98         video::SColor getColorFromId(u16 id);
99
100         void enqueueBlock(v3s16 pos, MinimapMapblock *data);
101
102         bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
103         bool popBlockUpdate(QueuedMinimapUpdate *update);
104
105         MinimapData *data;
106
107 protected:
108         const char *getName() { return "MinimapUpdateThread"; }
109         virtual void doUpdate();
110
111 private:
112         JMutex m_queue_mutex;
113         std::deque<QueuedMinimapUpdate> m_update_queue;
114         std::map<v3s16, MinimapMapblock *> m_blocks_cache;
115 };
116
117 class Mapper {
118 public:
119         Mapper(IrrlichtDevice *device, Client *client);
120         ~Mapper();
121
122         void addBlock(v3s16 pos, MinimapMapblock *data);
123
124         v3f getYawVec();
125         MinimapMode getMinimapMode();
126
127         void setPos(v3s16 pos);
128         void setAngle(f32 angle);
129         void setMinimapMode(MinimapMode 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         void drawMinimap();
141
142         video::IVideoDriver *driver;
143         MinimapData *data;
144
145 private:
146         ITextureSource *m_tsrc;
147         IShaderSource *m_shdrsrc;
148         INodeDefManager *m_ndef;
149         MinimapUpdateThread *m_minimap_update_thread;
150         scene::SMeshBuffer *m_meshbuffer;
151         bool m_enable_shaders;
152         u16 m_surface_mode_scan_height;
153         f32 m_angle;
154         JMutex m_mutex;
155 };
156
157 #endif