2015-06-21 22:34:56 -04: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"
|
|
|
|
#include "jthread/jmutex.h"
|
2015-06-27 12:11:24 -04:00
|
|
|
#include "jthread/jsemaphore.h"
|
2015-06-21 22:34:56 -04:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
enum MinimapMode {
|
|
|
|
MINIMAP_MODE_OFF,
|
|
|
|
MINIMAP_MODE_SURFACEx1,
|
|
|
|
MINIMAP_MODE_SURFACEx2,
|
|
|
|
MINIMAP_MODE_SURFACEx4,
|
|
|
|
MINIMAP_MODE_RADARx1,
|
|
|
|
MINIMAP_MODE_RADARx2,
|
|
|
|
MINIMAP_MODE_RADARx4
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MinimapPixel
|
|
|
|
{
|
|
|
|
u16 id;
|
|
|
|
u16 height;
|
|
|
|
u16 air_count;
|
|
|
|
u16 light;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MinimapMapblock
|
|
|
|
{
|
|
|
|
MinimapPixel data[MAP_BLOCKSIZE * MAP_BLOCKSIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MinimapData
|
|
|
|
{
|
|
|
|
bool radar;
|
|
|
|
MinimapMode mode;
|
|
|
|
v3s16 pos;
|
|
|
|
v3s16 old_pos;
|
|
|
|
u16 scan_height;
|
|
|
|
u16 map_size;
|
|
|
|
MinimapPixel minimap_scan[512 * 512];
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct QueuedMinimapUpdate
|
|
|
|
{
|
|
|
|
v3s16 pos;
|
|
|
|
MinimapMapblock *data;
|
|
|
|
|
|
|
|
QueuedMinimapUpdate();
|
|
|
|
~QueuedMinimapUpdate();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
A thread-safe queue of minimap mapblocks update tasks
|
|
|
|
*/
|
|
|
|
|
|
|
|
class MinimapUpdateQueue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MinimapUpdateQueue();
|
|
|
|
|
|
|
|
~MinimapUpdateQueue();
|
|
|
|
|
2015-06-27 12:11:24 -04:00
|
|
|
bool addBlock(v3s16 pos, MinimapMapblock *data);
|
2015-06-21 22:34:56 -04:00
|
|
|
|
|
|
|
QueuedMinimapUpdate *pop();
|
|
|
|
|
|
|
|
u32 size()
|
|
|
|
{
|
|
|
|
JMutexAutoLock lock(m_mutex);
|
|
|
|
return m_queue.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-06-27 12:11:24 -04:00
|
|
|
std::list<QueuedMinimapUpdate*> m_queue;
|
2015-06-21 22:34:56 -04:00
|
|
|
JMutex m_mutex;
|
|
|
|
};
|
|
|
|
|
2015-06-29 05:06:03 -04:00
|
|
|
class MinimapUpdateThread : public UpdateThread
|
2015-06-21 22:34:56 -04:00
|
|
|
{
|
|
|
|
private:
|
2015-06-27 12:11:24 -04:00
|
|
|
MinimapUpdateQueue m_queue;
|
2015-06-21 22:34:56 -04:00
|
|
|
|
2015-06-29 05:06:03 -04:00
|
|
|
protected:
|
|
|
|
const char *getName()
|
|
|
|
{ return "MinimapUpdateThread"; }
|
|
|
|
virtual void doUpdate();
|
|
|
|
|
2015-06-21 22:34:56 -04:00
|
|
|
public:
|
|
|
|
MinimapUpdateThread(IrrlichtDevice *device, Client *client)
|
|
|
|
{
|
|
|
|
this->device = device;
|
|
|
|
this->client = client;
|
|
|
|
this->driver = device->getVideoDriver();
|
|
|
|
this->tsrc = client->getTextureSource();
|
|
|
|
}
|
2015-06-28 06:17:36 -04:00
|
|
|
~MinimapUpdateThread();
|
2015-06-21 22:34:56 -04:00
|
|
|
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);
|
2015-06-27 12:11:24 -04:00
|
|
|
|
|
|
|
void enqueue_Block(v3s16 pos, MinimapMapblock *data);
|
2015-06-21 22:34:56 -04:00
|
|
|
IrrlichtDevice *device;
|
|
|
|
Client *client;
|
|
|
|
video::IVideoDriver *driver;
|
|
|
|
ITextureSource *tsrc;
|
|
|
|
MinimapData *data;
|
|
|
|
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;
|
2015-06-28 06:17:36 -04:00
|
|
|
u16 m_surface_mode_scan_height;
|
2015-06-21 22:34:56 -04:00
|
|
|
JMutex m_mutex;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Mapper(IrrlichtDevice *device, Client *client);
|
|
|
|
~Mapper();
|
|
|
|
|
|
|
|
void addBlock(v3s16 pos, MinimapMapblock *data);
|
|
|
|
void setPos(v3s16 pos);
|
|
|
|
video::ITexture* getMinimapTexture();
|
|
|
|
v3f getYawVec();
|
|
|
|
MinimapMode getMinimapMode();
|
|
|
|
void setMinimapMode(MinimapMode mode);
|
|
|
|
void toggleMinimapShape();
|
|
|
|
scene::SMeshBuffer *getMinimapMeshBuffer();
|
|
|
|
void drawMinimap();
|
|
|
|
IrrlichtDevice *device;
|
|
|
|
Client *client;
|
|
|
|
video::IVideoDriver *driver;
|
|
|
|
LocalPlayer *player;
|
|
|
|
ITextureSource *tsrc;
|
|
|
|
IShaderSource *shdrsrc;
|
|
|
|
MinimapData *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|