Include backtrace in error message when LuaErrors occur
[minetest-c55.git] / src / minimap.h
blobdd1397d54c18b4f19102eca204b810f55785c2cc
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 #ifndef MINIMAP_HEADER
21 #define MINIMAP_HEADER
23 #include "irrlichttypes_extrabloated.h"
24 #include "client.h"
25 #include "voxel.h"
26 #include "threading/mutex.h"
27 #include "threading/semaphore.h"
28 #include <map>
29 #include <string>
30 #include <vector>
32 #define MINIMAP_MAX_SX 512
33 #define MINIMAP_MAX_SY 512
36 enum MinimapMode {
37 MINIMAP_MODE_OFF,
38 MINIMAP_MODE_SURFACEx1,
39 MINIMAP_MODE_SURFACEx2,
40 MINIMAP_MODE_SURFACEx4,
41 MINIMAP_MODE_RADARx1,
42 MINIMAP_MODE_RADARx2,
43 MINIMAP_MODE_RADARx4,
44 MINIMAP_MODE_COUNT,
47 struct MinimapModeDef {
48 bool is_radar;
49 u16 scan_height;
50 u16 map_size;
53 struct MinimapPixel {
54 u16 id;
55 u16 height;
56 u16 air_count;
57 u16 light;
60 struct MinimapMapblock {
61 void getMinimapNodes(VoxelManipulator *vmanip, v3s16 pos);
63 MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
66 struct MinimapData {
67 bool is_radar;
68 MinimapMode mode;
69 v3s16 pos;
70 v3s16 old_pos;
71 u16 scan_height;
72 u16 map_size;
73 MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
74 bool map_invalidated;
75 bool minimap_shape_round;
76 video::IImage *minimap_image;
77 video::IImage *heightmap_image;
78 video::IImage *minimap_mask_round;
79 video::IImage *minimap_mask_square;
80 video::ITexture *texture;
81 video::ITexture *heightmap_texture;
82 video::ITexture *minimap_overlay_round;
83 video::ITexture *minimap_overlay_square;
84 video::ITexture *player_marker;
87 struct QueuedMinimapUpdate {
88 v3s16 pos;
89 MinimapMapblock *data;
92 class MinimapUpdateThread : public UpdateThread {
93 public:
94 MinimapUpdateThread() : UpdateThread("Minimap") {}
95 virtual ~MinimapUpdateThread();
97 void getMap(v3s16 pos, s16 size, s16 height, bool radar);
98 MinimapPixel *getMinimapPixel(v3s16 pos, s16 height, s16 *pixel_height);
99 s16 getAirCount(v3s16 pos, s16 height);
100 video::SColor getColorFromId(u16 id);
102 void enqueueBlock(v3s16 pos, MinimapMapblock *data);
104 bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
105 bool popBlockUpdate(QueuedMinimapUpdate *update);
107 MinimapData *data;
109 protected:
110 virtual void doUpdate();
112 private:
113 Mutex m_queue_mutex;
114 std::deque<QueuedMinimapUpdate> m_update_queue;
115 std::map<v3s16, MinimapMapblock *> m_blocks_cache;
118 class Mapper {
119 public:
120 Mapper(IrrlichtDevice *device, Client *client);
121 ~Mapper();
123 void addBlock(v3s16 pos, MinimapMapblock *data);
125 v3f getYawVec();
126 MinimapMode getMinimapMode();
128 void setPos(v3s16 pos);
129 void setAngle(f32 angle);
130 void setMinimapMode(MinimapMode mode);
131 void toggleMinimapShape();
134 video::ITexture *getMinimapTexture();
136 void blitMinimapPixelsToImageRadar(video::IImage *map_image);
137 void blitMinimapPixelsToImageSurface(video::IImage *map_image,
138 video::IImage *heightmap_image);
140 scene::SMeshBuffer *getMinimapMeshBuffer();
141 void drawMinimap();
143 video::IVideoDriver *driver;
144 MinimapData *data;
146 private:
147 ITextureSource *m_tsrc;
148 IShaderSource *m_shdrsrc;
149 INodeDefManager *m_ndef;
150 MinimapUpdateThread *m_minimap_update_thread;
151 scene::SMeshBuffer *m_meshbuffer;
152 bool m_enable_shaders;
153 u16 m_surface_mode_scan_height;
154 f32 m_angle;
155 Mutex m_mutex;
158 #endif