lua api: add register_on_item_activate
[waspsaliva.git] / src / client / minimap.h
blob4a2c462f831a0fb71229a794ee4d4b0266091ed5
1 /*
2 Minetest
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.
20 #pragma once
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>
30 class Client;
31 class ITextureSource;
32 class IShaderSource;
34 #define MINIMAP_MAX_SX 512
35 #define MINIMAP_MAX_SY 512
37 enum MinimapShape {
38 MINIMAP_SHAPE_SQUARE,
39 MINIMAP_SHAPE_ROUND,
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;
51 struct MinimapMarker {
52 MinimapMarker(scene::ISceneNode *parent_node):
53 parent_node(parent_node)
56 scene::ISceneNode *parent_node;
58 struct MinimapPixel {
59 //! The topmost node that the minimap displays.
60 MapNode n;
61 u16 height;
62 u16 air_count;
65 struct MinimapMapblock {
66 void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos);
68 MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
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;
88 struct QueuedMinimapUpdate {
89 v3s16 pos;
90 MinimapMapblock *data = nullptr;
93 class MinimapUpdateThread : public UpdateThread {
94 public:
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;
105 protected:
106 virtual void doUpdate();
108 private:
109 std::mutex m_queue_mutex;
110 std::deque<QueuedMinimapUpdate> m_update_queue;
111 std::map<v3s16, MinimapMapblock *> m_blocks_cache;
114 class Minimap {
115 public:
116 Minimap(Client *client);
117 ~Minimap();
119 void addBlock(v3s16 pos, MinimapMapblock *data);
121 v3f getYawVec();
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; };
139 void nextMode();
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();
156 void drawMinimap();
157 void drawMinimap(core::rect<s32> rect);
159 video::IVideoDriver *driver;
160 Client* client;
161 MinimapData *data;
163 private:
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;
173 f32 m_angle;
174 std::mutex m_mutex;
175 std::list<MinimapMarker*> m_markers;
176 std::list<v2f> m_active_markers;