]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/minimap.h
Remove obsolete eye_height related workaround
[dragonfireclient.git] / src / client / 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 #pragma once
21
22 #include "../hud.h"
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/thread.h"
25 #include "voxel.h"
26 #include <map>
27 #include <string>
28 #include <vector>
29
30 class Client;
31 class ITextureSource;
32 class IShaderSource;
33
34 #define MINIMAP_MAX_SX 512
35 #define MINIMAP_MAX_SY 512
36
37 enum MinimapShape {
38         MINIMAP_SHAPE_SQUARE,
39         MINIMAP_SHAPE_ROUND,
40 };
41
42 struct MinimapModeDef {
43         MinimapType type;
44         std::string label;
45         u16 scan_height;
46         u16 map_size;
47         std::string texture;
48         u16 scale;
49 };
50
51 struct MinimapMarker {
52         MinimapMarker(scene::ISceneNode *parent_node):
53                 parent_node(parent_node)
54         {
55         }
56         scene::ISceneNode *parent_node;
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, const v3s16 &pos);
67
68         MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
69 };
70
71 struct MinimapData {
72         MinimapModeDef mode;
73         v3s16 pos;
74         v3s16 old_pos;
75         MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
76         bool map_invalidated;
77         bool minimap_shape_round;
78         video::IImage *minimap_mask_round = nullptr;
79         video::IImage *minimap_mask_square = nullptr;
80         video::ITexture *texture = nullptr;
81         video::ITexture *heightmap_texture = nullptr;
82         video::ITexture *minimap_overlay_round = nullptr;
83         video::ITexture *minimap_overlay_square = nullptr;
84         video::ITexture *player_marker = nullptr;
85         video::ITexture *object_marker_red = nullptr;
86 };
87
88 struct QueuedMinimapUpdate {
89         v3s16 pos;
90         MinimapMapblock *data = nullptr;
91 };
92
93 class MinimapUpdateThread : public UpdateThread {
94 public:
95         MinimapUpdateThread() : UpdateThread("Minimap") {}
96         virtual ~MinimapUpdateThread();
97
98         void getMap(v3s16 pos, s16 size, s16 height);
99         void enqueueBlock(v3s16 pos, MinimapMapblock *data);
100         bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
101         bool popBlockUpdate(QueuedMinimapUpdate *update);
102
103         MinimapData *data = nullptr;
104
105 protected:
106         virtual void doUpdate();
107
108 private:
109         std::mutex m_queue_mutex;
110         std::deque<QueuedMinimapUpdate> m_update_queue;
111         std::map<v3s16, MinimapMapblock *> m_blocks_cache;
112 };
113
114 class Minimap {
115 public:
116         Minimap(Client *client);
117         ~Minimap();
118
119         void addBlock(v3s16 pos, MinimapMapblock *data);
120
121         v3f getYawVec();
122
123         void setPos(v3s16 pos);
124         v3s16 getPos() const { return data->pos; }
125         void setAngle(f32 angle);
126         f32 getAngle() const { return m_angle; }
127         void toggleMinimapShape();
128         void setMinimapShape(MinimapShape shape);
129         MinimapShape getMinimapShape();
130
131         void clearModes() { m_modes.clear(); };
132         void addMode(MinimapModeDef mode);
133         void addMode(MinimapType type, u16 size = 0, std::string label = "",
134                         std::string texture = "", u16 scale = 1);
135
136         void setModeIndex(size_t index);
137         size_t getModeIndex() const { return m_current_mode_index; };
138         size_t getMaxModeIndex() const { return m_modes.size() - 1; };
139         void nextMode();
140
141         MinimapModeDef getModeDef() const { return data->mode; }
142
143         video::ITexture *getMinimapTexture();
144
145         void blitMinimapPixelsToImageRadar(video::IImage *map_image);
146         void blitMinimapPixelsToImageSurface(video::IImage *map_image,
147                 video::IImage *heightmap_image);
148
149         scene::SMeshBuffer *getMinimapMeshBuffer();
150
151         MinimapMarker* addMarker(scene::ISceneNode *parent_node);
152         void removeMarker(MinimapMarker **marker);
153
154         void updateActiveMarkers();
155         void drawMinimap();
156         void drawMinimap(core::rect<s32> rect);
157
158         video::IVideoDriver *driver;
159         Client* client;
160         MinimapData *data;
161
162 private:
163         ITextureSource *m_tsrc;
164         IShaderSource *m_shdrsrc;
165         const NodeDefManager *m_ndef;
166         MinimapUpdateThread *m_minimap_update_thread = nullptr;
167         scene::SMeshBuffer *m_meshbuffer;
168         bool m_enable_shaders;
169         std::vector<MinimapModeDef> m_modes;
170         size_t m_current_mode_index;
171         u16 m_surface_mode_scan_height;
172         f32 m_angle;
173         std::mutex m_mutex;
174         std::list<MinimapMarker*> m_markers;
175         std::list<v2f> m_active_markers;
176 };