2015-06-22 04:34:56 +02:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MINIMAP_HEADER
|
|
|
|
#define MINIMAP_HEADER
|
|
|
|
|
|
|
|
#include "irrlichttypes_extrabloated.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "voxel.h"
|
2015-04-07 12:13:12 +02:00
|
|
|
#include "threading/semaphore.h"
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2016-02-18 17:17:17 +01:00
|
|
|
#include "camera.h"
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
#define MINIMAP_MAX_SX 512
|
|
|
|
#define MINIMAP_MAX_SY 512
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
enum MinimapMode {
|
|
|
|
MINIMAP_MODE_OFF,
|
|
|
|
MINIMAP_MODE_SURFACEx1,
|
|
|
|
MINIMAP_MODE_SURFACEx2,
|
|
|
|
MINIMAP_MODE_SURFACEx4,
|
|
|
|
MINIMAP_MODE_RADARx1,
|
|
|
|
MINIMAP_MODE_RADARx2,
|
2015-07-08 06:45:24 +02:00
|
|
|
MINIMAP_MODE_RADARx4,
|
|
|
|
MINIMAP_MODE_COUNT,
|
2015-06-22 04:34:56 +02:00
|
|
|
};
|
|
|
|
|
2017-04-14 09:04:41 +02:00
|
|
|
enum MinimapShape {
|
|
|
|
MINIMAP_SHAPE_SQUARE,
|
|
|
|
MINIMAP_SHAPE_ROUND,
|
|
|
|
};
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
struct MinimapModeDef {
|
|
|
|
bool is_radar;
|
|
|
|
u16 scan_height;
|
|
|
|
u16 map_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MinimapPixel {
|
2017-01-12 15:46:30 +01:00
|
|
|
//! The topmost node that the minimap displays.
|
|
|
|
MapNode n;
|
2015-06-22 04:34:56 +02:00
|
|
|
u16 height;
|
|
|
|
u16 air_count;
|
|
|
|
};
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
struct MinimapMapblock {
|
2017-07-26 07:35:09 +02:00
|
|
|
void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
|
|
|
|
};
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
struct MinimapData {
|
|
|
|
bool is_radar;
|
2015-06-22 04:34:56 +02:00
|
|
|
MinimapMode mode;
|
|
|
|
v3s16 pos;
|
|
|
|
v3s16 old_pos;
|
|
|
|
u16 scan_height;
|
|
|
|
u16 map_size;
|
2015-07-08 06:45:24 +02:00
|
|
|
MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
|
2015-06-22 04:34:56 +02:00
|
|
|
bool map_invalidated;
|
|
|
|
bool minimap_shape_round;
|
2017-06-18 19:55:15 +02:00
|
|
|
video::IImage *minimap_mask_round = nullptr;
|
|
|
|
video::IImage *minimap_mask_square = nullptr;
|
|
|
|
video::ITexture *texture = nullptr;
|
|
|
|
video::ITexture *heightmap_texture = nullptr;
|
|
|
|
video::ITexture *minimap_overlay_round = nullptr;
|
|
|
|
video::ITexture *minimap_overlay_square = nullptr;
|
|
|
|
video::ITexture *player_marker = nullptr;
|
|
|
|
video::ITexture *object_marker_red = nullptr;
|
2015-06-22 04:34:56 +02:00
|
|
|
};
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
struct QueuedMinimapUpdate {
|
2015-06-22 04:34:56 +02:00
|
|
|
v3s16 pos;
|
2017-06-18 19:55:15 +02:00
|
|
|
MinimapMapblock *data = nullptr;
|
2015-06-22 04:34:56 +02:00
|
|
|
};
|
|
|
|
|
2015-07-08 06:45:24 +02:00
|
|
|
class MinimapUpdateThread : public UpdateThread {
|
2015-06-22 04:34:56 +02:00
|
|
|
public:
|
2015-04-07 12:13:12 +02:00
|
|
|
MinimapUpdateThread() : UpdateThread("Minimap") {}
|
2015-07-08 06:45:24 +02:00
|
|
|
virtual ~MinimapUpdateThread();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2017-02-23 14:04:39 +01:00
|
|
|
void getMap(v3s16 pos, s16 size, s16 height);
|
2015-07-08 06:45:24 +02:00
|
|
|
void enqueueBlock(v3s16 pos, MinimapMapblock *data);
|
|
|
|
bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
|
|
|
|
bool popBlockUpdate(QueuedMinimapUpdate *update);
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2017-06-18 19:55:15 +02:00
|
|
|
MinimapData *data = nullptr;
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2015-06-29 11:06:03 +02:00
|
|
|
protected:
|
2015-07-08 06:45:24 +02:00
|
|
|
virtual void doUpdate();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
|
|
|
private:
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_queue_mutex;
|
2015-07-08 06:45:24 +02:00
|
|
|
std::deque<QueuedMinimapUpdate> m_update_queue;
|
|
|
|
std::map<v3s16, MinimapMapblock *> m_blocks_cache;
|
|
|
|
};
|
2015-06-22 04:34:56 +02:00
|
|
|
|
2017-03-16 10:34:54 +01:00
|
|
|
class Minimap {
|
2015-06-22 04:34:56 +02:00
|
|
|
public:
|
2017-06-26 20:11:17 +02:00
|
|
|
Minimap(Client *client);
|
2017-03-16 10:34:54 +01:00
|
|
|
~Minimap();
|
2015-06-22 04:34:56 +02:00
|
|
|
|
|
|
|
void addBlock(v3s16 pos, MinimapMapblock *data);
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
v3f getYawVec();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
void setPos(v3s16 pos);
|
2017-03-16 10:34:54 +01:00
|
|
|
v3s16 getPos() const { return data->pos; }
|
2015-07-08 06:45:24 +02:00
|
|
|
void setAngle(f32 angle);
|
2017-03-16 10:34:54 +01:00
|
|
|
f32 getAngle() const { return m_angle; }
|
2015-06-22 04:34:56 +02:00
|
|
|
void setMinimapMode(MinimapMode mode);
|
2017-03-16 10:34:54 +01:00
|
|
|
MinimapMode getMinimapMode() const { return data->mode; }
|
2015-06-22 04:34:56 +02:00
|
|
|
void toggleMinimapShape();
|
2017-04-14 09:04:41 +02:00
|
|
|
void setMinimapShape(MinimapShape shape);
|
|
|
|
MinimapShape getMinimapShape();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
video::ITexture *getMinimapTexture();
|
|
|
|
|
|
|
|
void blitMinimapPixelsToImageRadar(video::IImage *map_image);
|
|
|
|
void blitMinimapPixelsToImageSurface(video::IImage *map_image,
|
|
|
|
video::IImage *heightmap_image);
|
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
scene::SMeshBuffer *getMinimapMeshBuffer();
|
2016-02-18 17:17:17 +01:00
|
|
|
|
|
|
|
void updateActiveMarkers();
|
2015-06-22 04:34:56 +02:00
|
|
|
void drawMinimap();
|
2015-07-08 06:45:24 +02:00
|
|
|
|
2015-06-22 04:34:56 +02:00
|
|
|
video::IVideoDriver *driver;
|
2016-02-18 17:17:17 +01:00
|
|
|
Client* client;
|
2015-06-22 04:34:56 +02:00
|
|
|
MinimapData *data;
|
2015-07-08 06:45:24 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
ITextureSource *m_tsrc;
|
|
|
|
IShaderSource *m_shdrsrc;
|
|
|
|
INodeDefManager *m_ndef;
|
|
|
|
MinimapUpdateThread *m_minimap_update_thread;
|
|
|
|
scene::SMeshBuffer *m_meshbuffer;
|
|
|
|
bool m_enable_shaders;
|
|
|
|
u16 m_surface_mode_scan_height;
|
|
|
|
f32 m_angle;
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_mutex;
|
2016-02-18 17:17:17 +01:00
|
|
|
std::list<v2f> m_active_markers;
|
2015-06-22 04:34:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|