1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00
luanti/src/client/minimap.h

184 lines
4.3 KiB
C
Raw Normal View History

// Luanti
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
2015-06-22 04:34:56 +02:00
#pragma once
2015-06-22 04:34:56 +02:00
#include "irrlichttypes.h"
#include "../hud.h"
#include "mapnode.h"
#include "util/thread.h"
#include <map>
#include <string>
#include <vector>
// irr includes
#include <irr_ptr.h>
#include <rect.h>
#include <CMeshBuffer.h>
namespace scene = irr::scene;
namespace video = irr::video;
namespace irr {
namespace video {
class IVideoDriver;
class IImage;
class ITexture;
}
namespace scene {
class ISceneNode;
}
}
class Client;
class NodeDefManager;
class ITextureSource;
class IShaderSource;
class VoxelManipulator;
#define MINIMAP_MAX_SX 512
#define MINIMAP_MAX_SY 512
2015-06-22 04:34:56 +02:00
enum MinimapShape {
MINIMAP_SHAPE_SQUARE,
MINIMAP_SHAPE_ROUND,
};
struct MinimapModeDef {
MinimapType type;
std::string label;
u16 scan_height;
u16 map_size;
std::string texture;
u16 scale;
};
struct MinimapMarker {
MinimapMarker(scene::ISceneNode *parent_node):
parent_node(parent_node)
{
}
scene::ISceneNode *parent_node;
};
struct MinimapPixel {
//! The topmost node that the minimap displays.
MapNode n;
2015-06-22 04:34:56 +02:00
u16 height;
u16 air_count;
};
struct MinimapMapblock {
void getMinimapNodes(VoxelManipulator *vmanip, const v3s16 &pos);
2015-06-22 04:34:56 +02:00
MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
};
struct MinimapData {
MinimapModeDef mode;
2015-06-22 04:34:56 +02:00
v3s16 pos;
v3s16 old_pos;
MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
2015-06-22 04:34:56 +02:00
bool map_invalidated;
bool minimap_shape_round;
video::IImage *minimap_mask_round = nullptr;
video::IImage *minimap_mask_square = nullptr;
video::ITexture *texture = nullptr;
video::ITexture *heightmap_texture = nullptr;
bool textures_initialised = false; // True if the following textures are not nullptrs.
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
};
struct QueuedMinimapUpdate {
2015-06-22 04:34:56 +02:00
v3s16 pos;
MinimapMapblock *data = nullptr;
2015-06-22 04:34:56 +02:00
};
class MinimapUpdateThread : public UpdateThread {
2015-06-22 04:34:56 +02:00
public:
MinimapUpdateThread() : UpdateThread("Minimap") {}
virtual ~MinimapUpdateThread();
2015-06-22 04:34:56 +02:00
2017-02-23 16:04:39 +03:00
void getMap(v3s16 pos, s16 size, s16 height);
void enqueueBlock(v3s16 pos, MinimapMapblock *data);
bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
bool popBlockUpdate(QueuedMinimapUpdate *update);
2015-06-22 04:34:56 +02:00
MinimapData *data = nullptr;
2015-06-22 04:34:56 +02:00
protected:
virtual void doUpdate();
2015-06-22 04:34:56 +02:00
private:
std::mutex m_queue_mutex;
std::deque<QueuedMinimapUpdate> m_update_queue;
std::map<v3s16, MinimapMapblock *> m_blocks_cache;
};
2015-06-22 04:34:56 +02:00
class Minimap {
2015-06-22 04:34:56 +02:00
public:
Minimap(Client *client);
~Minimap();
2015-06-22 04:34:56 +02:00
void addBlock(v3s16 pos, MinimapMapblock *data);
2015-06-22 04:34:56 +02:00
v3f getYawVec();
void setPos(v3s16 pos);
v3s16 getPos() const { return data->pos; }
void setAngle(f32 angle);
f32 getAngle() const { return m_angle; }
2015-06-22 04:34:56 +02:00
void toggleMinimapShape();
void setMinimapShape(MinimapShape shape);
MinimapShape getMinimapShape();
void clearModes() { m_modes.clear(); };
void addMode(MinimapModeDef mode);
void addMode(MinimapType type, u16 size = 0, const std::string &label = "",
const std::string &texture = "", u16 scale = 1);
void setModeIndex(size_t index);
size_t getModeIndex() const { return m_current_mode_index; };
size_t getMaxModeIndex() const { return m_modes.size() - 1; };
void nextMode();
MinimapModeDef getModeDef() const { return data->mode; }
video::IImage *getMinimapMask();
video::ITexture *getMinimapTexture();
void blitMinimapPixelsToImageRadar(video::IImage *map_image);
void blitMinimapPixelsToImageSurface(video::IImage *map_image,
video::IImage *heightmap_image);
irr_ptr<scene::SMeshBuffer> createMinimapMeshBuffer();
2016-02-18 17:17:17 +01:00
MinimapMarker* addMarker(scene::ISceneNode *parent_node);
void removeMarker(MinimapMarker **marker);
2016-02-18 17:17:17 +01:00
void updateActiveMarkers();
void drawMinimap(core::rect<s32> rect);
2015-06-22 04:34:56 +02:00
video::IVideoDriver *driver;
2016-02-18 17:17:17 +01:00
Client* client;
std::unique_ptr<MinimapData> data;
private:
ITextureSource *m_tsrc;
IShaderSource *m_shdrsrc;
const NodeDefManager *m_ndef;
std::unique_ptr<MinimapUpdateThread> m_minimap_update_thread;
irr_ptr<scene::SMeshBuffer> m_meshbuffer;
std::vector<MinimapModeDef> m_modes;
size_t m_current_mode_index;
u16 m_surface_mode_scan_height;
f32 m_angle;
std::mutex m_mutex;
std::list<std::unique_ptr<MinimapMarker>> m_markers;
2016-02-18 17:17:17 +01:00
std::list<v2f> m_active_markers;
2015-06-22 04:34:56 +02:00
};