]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/minimap.h
Cpp11 patchset 11: continue working on constructor style migration (#6004)
[dragonfireclient.git] / src / minimap.h
index 220c3add0794585613c8cea9b289205c30be0ee6..04ac27a04984c838f7031f15235ec16c5b400337 100644 (file)
@@ -23,11 +23,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_extrabloated.h"
 #include "client.h"
 #include "voxel.h"
-#include "jthread/jmutex.h"
-#include "jthread/jsemaphore.h"
+#include "threading/semaphore.h"
 #include <map>
 #include <string>
 #include <vector>
+#include "camera.h"
+
+#define MINIMAP_MAX_SX 512
+#define MINIMAP_MAX_SY 512
+
 
 enum MinimapMode {
        MINIMAP_MODE_OFF,
@@ -36,142 +40,126 @@ enum MinimapMode {
        MINIMAP_MODE_SURFACEx4,
        MINIMAP_MODE_RADARx1,
        MINIMAP_MODE_RADARx2,
-       MINIMAP_MODE_RADARx4
+       MINIMAP_MODE_RADARx4,
+       MINIMAP_MODE_COUNT,
+};
+
+enum MinimapShape {
+       MINIMAP_SHAPE_SQUARE,
+       MINIMAP_SHAPE_ROUND,
 };
 
-struct MinimapPixel
-{
-       u16 id;
+struct MinimapModeDef {
+       bool is_radar;
+       u16 scan_height;
+       u16 map_size;
+};
+
+struct MinimapPixel {
+       //! The topmost node that the minimap displays.
+       MapNode n;
        u16 height;
        u16 air_count;
-       u16 light;
 };
 
-struct MinimapMapblock
-{
+struct MinimapMapblock {
+       void getMinimapNodes(VoxelManipulator *vmanip, v3s16 pos);
+
        MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
 };
 
-struct MinimapData
-{
-       bool radar;
+struct MinimapData {
+       bool is_radar;
        MinimapMode mode;
        v3s16 pos;
        v3s16 old_pos;
        u16 scan_height;
        u16 map_size;
-       MinimapPixel minimap_scan[512 * 512];
+       MinimapPixel minimap_scan[MINIMAP_MAX_SX * MINIMAP_MAX_SY];
        bool map_invalidated;
        bool minimap_shape_round;
-       video::IImage *minimap_image;
-       video::IImage *heightmap_image;
-       video::IImage *minimap_mask_round;
-       video::IImage *minimap_mask_square;
-       video::ITexture *texture;
-       video::ITexture *heightmap_texture;
-       video::ITexture *minimap_overlay_round;
-       video::ITexture *minimap_overlay_square;
-       video::ITexture *player_marker;
+       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;
 };
 
-struct QueuedMinimapUpdate
-{
+struct QueuedMinimapUpdate {
        v3s16 pos;
-       MinimapMapblock *data;
-
-       QueuedMinimapUpdate();
-       ~QueuedMinimapUpdate();
+       MinimapMapblock *data = nullptr;
 };
 
-/*
-       A thread-safe queue of minimap mapblocks update tasks
-*/
-
-class MinimapUpdateQueue
-{
+class MinimapUpdateThread : public UpdateThread {
 public:
-       MinimapUpdateQueue();
-
-       ~MinimapUpdateQueue();
+       MinimapUpdateThread() : UpdateThread("Minimap") {}
+       virtual ~MinimapUpdateThread();
 
-       bool addBlock(v3s16 pos, MinimapMapblock *data);
+       void getMap(v3s16 pos, s16 size, s16 height);
+       void enqueueBlock(v3s16 pos, MinimapMapblock *data);
+       bool pushBlockUpdate(v3s16 pos, MinimapMapblock *data);
+       bool popBlockUpdate(QueuedMinimapUpdate *update);
 
-       // blocking!!
-       QueuedMinimapUpdate *pop();
+       MinimapData *data = nullptr;
 
-       u32 size()
-       {
-               JMutexAutoLock lock(m_mutex);
-               return m_queue.size();
-       }
-
-private:
-       std::list<QueuedMinimapUpdate*> m_queue;
-       JMutex m_mutex;
-};
+protected:
+       virtual void doUpdate();
 
-class MinimapUpdateThread : public JThread
-{
 private:
-       JSemaphore m_queue_sem;
-       MinimapUpdateQueue m_queue;
-
-public:
-       MinimapUpdateThread(IrrlichtDevice *device, Client *client)
-       {
-               this->device = device;
-               this->client = client;
-               this->driver = device->getVideoDriver();
-               this->tsrc = client->getTextureSource();
-       }
-       ~MinimapUpdateThread();
-       void getMap (v3s16 pos, s16 size, s16 height, bool radar);
-       MinimapPixel *getMinimapPixel (v3s16 pos, s16 height, s16 &pixel_height);
-       s16 getAirCount (v3s16 pos, s16 height);
-       video::SColor getColorFromId(u16 id);
-
-       void enqueue_Block(v3s16 pos, MinimapMapblock *data);
-
-       IrrlichtDevice *device;
-       Client *client;
-       video::IVideoDriver *driver;
-       ITextureSource *tsrc;
-       void Stop();
-       void *Thread();
-       MinimapData *data;
+       std::mutex m_queue_mutex;
+       std::deque<QueuedMinimapUpdate> m_update_queue;
        std::map<v3s16, MinimapMapblock *> m_blocks_cache;
 };
 
-class Mapper
-{
-private:
-       MinimapUpdateThread *m_minimap_update_thread;
-       video::ITexture *minimap_texture;
-       scene::SMeshBuffer *m_meshbuffer;
-       bool m_enable_shaders;
-       u16 m_surface_mode_scan_height;
-       JMutex m_mutex;
-
+class Minimap {
 public:
-       Mapper(IrrlichtDevice *device, Client *client);
-       ~Mapper();
+       Minimap(IrrlichtDevice *device, Client *client);
+       ~Minimap();
 
        void addBlock(v3s16 pos, MinimapMapblock *data);
-       void setPos(v3s16 pos);
-       video::ITexture* getMinimapTexture();
+
        v3f getYawVec();
-       MinimapMode getMinimapMode();
+
+       void setPos(v3s16 pos);
+       v3s16 getPos() const { return data->pos; }
+       void setAngle(f32 angle);
+       f32 getAngle() const { return m_angle; }
        void setMinimapMode(MinimapMode mode);
+       MinimapMode getMinimapMode() const { return data->mode; }
        void toggleMinimapShape();
+       void setMinimapShape(MinimapShape shape);
+       MinimapShape getMinimapShape();
+
+
+       video::ITexture *getMinimapTexture();
+
+       void blitMinimapPixelsToImageRadar(video::IImage *map_image);
+       void blitMinimapPixelsToImageSurface(video::IImage *map_image,
+               video::IImage *heightmap_image);
+
        scene::SMeshBuffer *getMinimapMeshBuffer();
+
+       void updateActiveMarkers();
        void drawMinimap();
-       IrrlichtDevice *device;
-       Client *client;
+
        video::IVideoDriver *driver;
-       LocalPlayer *player;
-       ITextureSource *tsrc;
-       IShaderSource *shdrsrc;
+       Client* client;
        MinimapData *data;
+
+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;
+       std::mutex m_mutex;
+       std::list<v2f> m_active_markers;
 };
 
 #endif