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
{
51 struct MinimapMarker
{
52 MinimapMarker(scene::ISceneNode
*parent_node
):
53 parent_node(parent_node
)
56 scene::ISceneNode
*parent_node
;
59 //! The topmost node that the minimap displays.
65 struct MinimapMapblock
{
66 void getMinimapNodes(VoxelManipulator
*vmanip
, const v3s16
&pos
);
68 MinimapPixel data
[MAP_BLOCKSIZE
* MAP_BLOCKSIZE
];
75 MinimapPixel minimap_scan
[MINIMAP_MAX_SX
* MINIMAP_MAX_SY
];
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;
88 struct QueuedMinimapUpdate
{
90 MinimapMapblock
*data
= nullptr;
93 class MinimapUpdateThread
: public UpdateThread
{
95 MinimapUpdateThread() : UpdateThread("Minimap") {}
96 virtual ~MinimapUpdateThread();
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
);
103 MinimapData
*data
= nullptr;
106 virtual void doUpdate();
109 std::mutex m_queue_mutex
;
110 std::deque
<QueuedMinimapUpdate
> m_update_queue
;
111 std::map
<v3s16
, MinimapMapblock
*> m_blocks_cache
;
116 Minimap(Client
*client
);
119 void addBlock(v3s16 pos
, MinimapMapblock
*data
);
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();
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);
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; };
141 void setModesFromString(std::string modes_string
);
142 MinimapModeDef
getModeDef() const { return data
->mode
; }
144 video::ITexture
*getMinimapTexture();
146 void blitMinimapPixelsToImageRadar(video::IImage
*map_image
);
147 void blitMinimapPixelsToImageSurface(video::IImage
*map_image
,
148 video::IImage
*heightmap_image
);
150 scene::SMeshBuffer
*getMinimapMeshBuffer();
152 MinimapMarker
* addMarker(scene::ISceneNode
*parent_node
);
153 void removeMarker(MinimapMarker
**marker
);
155 void updateActiveMarkers();
157 void drawMinimap(core::rect
<s32
> rect
);
159 video::IVideoDriver
*driver
;
164 ITextureSource
*m_tsrc
;
165 IShaderSource
*m_shdrsrc
;
166 const NodeDefManager
*m_ndef
;
167 MinimapUpdateThread
*m_minimap_update_thread
= nullptr;
168 scene::SMeshBuffer
*m_meshbuffer
;
169 bool m_enable_shaders
;
170 std::vector
<MinimapModeDef
> m_modes
;
171 size_t m_current_mode_index
;
172 u16 m_surface_mode_scan_height
;
175 std::list
<MinimapMarker
*> m_markers
;
176 std::list
<v2f
> m_active_markers
;