3 Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
23 #include "irrlichttypes_extrabloated.h"
24 #include "util/thread.h"
34 #define MINIMAP_MAX_SX 512
35 #define MINIMAP_MAX_SY 512
42 struct MinimapModeDef {
52 //! The topmost node that the minimap displays.
58 struct MinimapMapblock {
59 void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos);
61 MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
68 MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
70 bool minimap_shape_round;
71 video::IImage *minimap_mask_round = nullptr;
72 video::IImage *minimap_mask_square = nullptr;
73 video::ITexture *texture = nullptr;
74 video::ITexture *heightmap_texture = nullptr;
75 video::ITexture *minimap_overlay_round = nullptr;
76 video::ITexture *minimap_overlay_square = nullptr;
77 video::ITexture *player_marker = nullptr;
78 video::ITexture *object_marker_red = nullptr;
81 struct QueuedMinimapUpdate {
83 MinimapMapblock *data = nullptr;
86 class MinimapUpdateThread : public UpdateThread {
88 MinimapUpdateThread() : UpdateThread("Minimap") {}
89 virtual ~MinimapUpdateThread();
91 void getMap(v3s16 pos, s16 size, s16 height);
92 void enqueueBlock(v3s16 pos, MinimapMapblock *data);
93 bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
94 bool popBlockUpdate(QueuedMinimapUpdate *update);
96 MinimapData *data = nullptr;
99 virtual void doUpdate();
102 std::mutex m_queue_mutex;
103 std::deque<QueuedMinimapUpdate> m_update_queue;
104 std::map<v3s16, MinimapMapblock *> m_blocks_cache;
109 Minimap(Client *client);
112 void addBlock(v3s16 pos, MinimapMapblock *data);
116 void setPos(v3s16 pos);
117 v3s16 getPos() const { return data->pos; }
118 void setAngle(f32 angle);
119 f32 getAngle() const { return m_angle; }
120 void toggleMinimapShape();
121 void setMinimapShape(MinimapShape shape);
122 MinimapShape getMinimapShape();
124 void clearModes() { m_modes.clear(); };
125 void addMode(MinimapModeDef mode);
126 void addMode(MinimapType type, u16 size = 0, std::string label = "",
127 std::string texture = "", u16 scale = 1);
129 void setModeIndex(size_t index);
130 size_t getModeIndex() const { return m_current_mode_index; };
131 size_t getMaxModeIndex() const { return m_modes.size() - 1; };
134 void setModesFromString(std::string modes_string);
135 MinimapModeDef getModeDef() const { return data->mode; }
137 video::ITexture *getMinimapTexture();
139 void blitMinimapPixelsToImageRadar(video::IImage *map_image);
140 void blitMinimapPixelsToImageSurface(video::IImage *map_image,
141 video::IImage *heightmap_image);
143 scene::SMeshBuffer *getMinimapMeshBuffer();
145 void updateActiveMarkers();
147 void drawMinimap(core::rect<s32> rect);
149 video::IVideoDriver *driver;
154 ITextureSource *m_tsrc;
155 IShaderSource *m_shdrsrc;
156 const NodeDefManager *m_ndef;
157 MinimapUpdateThread *m_minimap_update_thread = nullptr;
158 scene::SMeshBuffer *m_meshbuffer;
159 bool m_enable_shaders;
160 std::vector<MinimapModeDef> m_modes;
161 size_t m_current_mode_index;
162 u16 m_surface_mode_scan_height;
165 std::list<v2f> m_active_markers;