Skip to content
Permalink
Browse files

[CSM] Add minimap API modifiers (#5399)

* Rename Mapper (too generic) to Minimap
* Add lua functions to get/set position, angle, mode for minimap
* Client: rename m_mapper to m_minimap
* Add minimap to core.ui namespace (core.ui.minimap)
* Add various functions to manage minimap (show, hide, toggle_shape)
* Cleanup trivial declaration in client
  • Loading branch information...
nerzhul committed Mar 16, 2017
1 parent eb88e5d commit 40ce538aad9af8f7634c4ba7e9f12246fb23b31c
@@ -47,9 +47,21 @@ core.register_chatcommand("test_node", {
end,
})

local function preview_minimap()
local minimap = core.ui.minimap
minimap:show()
minimap:set_mode(4)
minimap:set_pos({x=5, y=50, z=5})
minimap:toggle_shape()

print("[PREVIEW] Minimap: mode => " .. dump(minimap:get_mode()) ..
" position => " .. dump(minimap:get_pos()) ..
" angle => " .. dump(minimap:get_angle()))
end

core.after(2, function()
print("[PREVIEW] loaded " .. modname .. " mod")
preview_minimap()
modstorage:set_string("current_mod", modname)
print(modstorage:get_string("current_mod"))
end)
@@ -789,9 +789,27 @@ Call these functions only at load time!
* same as fgettext_ne(), but calls core.formspec_escape before returning result
* `show_formspec(formname, formspec)` : returns true on success
* Shows a formspec to the player

### UI
* `minetest.ui.minimap`
* Reference to the minimap object. See `Minimap` class reference for methods.

Class reference
---------------

### `Minimap`
An interface to manipulate minimap on client UI

* `show()`: shows the minimap (if not disabled by server)
* `hide()`: hides the minimap
* `set_pos(pos)`: sets the minimap position on screen
* `get_pos()`: returns the minimap current position
* `set_angle(deg)`: sets the minimap angle in degrees
* `get_angle()`: returns the current minimap angle in degrees
* `set_mode(mode)`: sets the minimap mode (0 to 6)
* `get_mode()`: returns the current minimap mode
* `toggle_shape()`: toggles minimap shape to round or square.

### `Settings`
An interface to read config files in the format of `minetest.conf`.

@@ -224,6 +224,7 @@ Client::Client(
m_device(device),
m_camera(NULL),
m_minimap_disabled_by_server(false),
m_minimap_shown_by_mod(false),
m_server_ser_ver(SER_FMT_VER_INVALID),
m_proto_ver(0),
m_playeritem(0),
@@ -255,7 +256,7 @@ Client::Client(
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));

m_mapper = new Mapper(device, this);
m_minimap = new Minimap(device, this);
m_cache_save_interval = g_settings->getU16("server_map_save_interval");

m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
@@ -386,7 +387,7 @@ Client::~Client()
m_device->getSceneManager()->getMeshCache()->removeMesh(mesh);
}

delete m_mapper;
delete m_minimap;
}

void Client::connect(Address address,
@@ -636,7 +637,7 @@ void Client::step(float dtime)
}

if (do_mapper_update)
m_mapper->addBlock(r.p, minimap_mapblock);
m_minimap->addBlock(r.p, minimap_mapblock);

if (r.ack_block_to_server) {
/*
@@ -1859,23 +1860,17 @@ void Client::afterContentReceived(IrrlichtDevice *device)
delete[] text;
}

float Client::getRTT(void)
float Client::getRTT()
{
return m_con.getPeerStat(PEER_ID_SERVER,con::AVG_RTT);
}

float Client::getCurRate(void)
float Client::getCurRate()
{
return ( m_con.getLocalStat(con::CUR_INC_RATE) +
m_con.getLocalStat(con::CUR_DL_RATE));
}

float Client::getAvgRate(void)
{
return ( m_con.getLocalStat(con::AVG_INC_RATE) +
m_con.getLocalStat(con::AVG_DL_RATE));
}

void Client::makeScreenshot(IrrlichtDevice *device)
{
irr::video::IVideoDriver *driver = device->getVideoDriver();
@@ -1935,6 +1930,15 @@ void Client::makeScreenshot(IrrlichtDevice *device)
raw_image->drop();
}

bool Client::shouldShowMinimap() const
{
if (m_minimap_disabled_by_server) {
return false;
}

return m_minimap_shown_by_mod;
}

// IGameDef interface
// Under envlock
IItemDefManager* Client::getItemDefManager()
@@ -49,7 +49,7 @@ struct MapDrawControl;
class MtEventManager;
struct PointedThing;
class Database;
class Mapper;
class Minimap;
struct MinimapMapblock;
class Camera;
class NetworkPacket;
@@ -522,21 +522,17 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

void afterContentReceived(IrrlichtDevice *device);

float getRTT(void);
float getCurRate(void);
float getAvgRate(void);
float getRTT();
float getCurRate();

Mapper* getMapper ()
{ return m_mapper; }

void setCamera(Camera* camera)
{ m_camera = camera; }
Minimap* getMinimap() { return m_minimap; }
void setCamera(Camera* camera) { m_camera = camera; }

Camera* getCamera ()
{ return m_camera; }

bool isMinimapDisabledByServer()
{ return m_minimap_disabled_by_server; }
bool shouldShowMinimap() const;
void setMinimapShownByMod(bool state) { m_minimap_shown_by_mod = state; }

// IGameDef interface
virtual IItemDefManager* getItemDefManager();
@@ -636,8 +632,9 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
con::Connection m_con;
IrrlichtDevice *m_device;
Camera *m_camera;
Mapper *m_mapper;
Minimap *m_minimap;
bool m_minimap_disabled_by_server;
bool m_minimap_shown_by_mod;
// Server serialization version
u8 m_server_ser_ver;

@@ -474,7 +474,7 @@ void draw_plain(Camera &camera, bool show_hud, Hud &hud,

void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
Mapper &mapper, gui::IGUIEnvironment *guienv,
Minimap &mapper, gui::IGUIEnvironment *guienv,
const v2u32 &screensize, const video::SColor &skycolor,
bool show_hud, bool show_minimap)
{
@@ -32,7 +32,7 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,

void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
Camera &camera, Client &client, LocalPlayer *player,
Hud &hud, Mapper &mapper, gui::IGUIEnvironment *guienv,
Hud &hud, Minimap &mapper, gui::IGUIEnvironment *guienv,
const v2u32 &screensize, const video::SColor &skycolor,
bool show_hud, bool show_minimap);

@@ -715,7 +715,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
m_eye_position_vertex.set(eye_position_array, services);

float minimap_yaw_array[3];
v3f minimap_yaw = m_client->getMapper()->getYawVec();
v3f minimap_yaw = m_client->getMinimap()->getYawVec();
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
minimap_yaw_array[0] = minimap_yaw.X;
minimap_yaw_array[1] = minimap_yaw.Y;
@@ -1473,7 +1473,7 @@ class Game {
Sky *sky; // Free using ->Drop()
Inventory *local_inventory;
Hud *hud;
Mapper *mapper;
Minimap *mapper;

GameRunData runData;
VolatileRunFlags flags;
@@ -1769,7 +1769,7 @@ void Game::run()
updateProfilerGraphs(&graph);

// Update if minimap has been disabled by the server
flags.show_minimap &= !client->isMinimapDisabledByServer();
flags.show_minimap = client->shouldShowMinimap();
}
}

@@ -2029,7 +2029,7 @@ bool Game::createClient(const std::string &playername,
return false;
}

mapper = client->getMapper();
mapper = client->getMinimap();
mapper->setMinimapMode(MINIMAP_MODE_OFF);

return true;
@@ -184,7 +184,7 @@ void MinimapUpdateThread::getMap(v3s16 pos, s16 size, s16 height)
//// Mapper
////

Mapper::Mapper(IrrlichtDevice *device, Client *client)
Minimap::Minimap(IrrlichtDevice *device, Client *client)
{
this->client = client;
this->driver = device->getVideoDriver();
@@ -238,7 +238,7 @@ Mapper::Mapper(IrrlichtDevice *device, Client *client)
m_minimap_update_thread->start();
}

Mapper::~Mapper()
Minimap::~Minimap()
{
m_minimap_update_thread->stop();
m_minimap_update_thread->wait();
@@ -258,17 +258,12 @@ Mapper::~Mapper()
delete m_minimap_update_thread;
}

void Mapper::addBlock(v3s16 pos, MinimapMapblock *data)
void Minimap::addBlock(v3s16 pos, MinimapMapblock *data)
{
m_minimap_update_thread->enqueueBlock(pos, data);
}

MinimapMode Mapper::getMinimapMode()
{
return data->mode;
}

void Mapper::toggleMinimapShape()
void Minimap::toggleMinimapShape()
{
MutexAutoLock lock(m_mutex);

@@ -277,7 +272,7 @@ void Mapper::toggleMinimapShape()
m_minimap_update_thread->deferUpdate();
}

void Mapper::setMinimapMode(MinimapMode mode)
void Minimap::setMinimapMode(MinimapMode mode)
{
static const MinimapModeDef modedefs[MINIMAP_MODE_COUNT] = {
{false, 0, 0},
@@ -302,7 +297,7 @@ void Mapper::setMinimapMode(MinimapMode mode)
m_minimap_update_thread->deferUpdate();
}

void Mapper::setPos(v3s16 pos)
void Minimap::setPos(v3s16 pos)
{
bool do_update = false;

@@ -320,12 +315,12 @@ void Mapper::setPos(v3s16 pos)
m_minimap_update_thread->deferUpdate();
}

void Mapper::setAngle(f32 angle)
void Minimap::setAngle(f32 angle)
{
m_angle = angle;
}

void Mapper::blitMinimapPixelsToImageRadar(video::IImage *map_image)
void Minimap::blitMinimapPixelsToImageRadar(video::IImage *map_image)
{
for (s16 x = 0; x < data->map_size; x++)
for (s16 z = 0; z < data->map_size; z++) {
@@ -339,7 +334,7 @@ void Mapper::blitMinimapPixelsToImageRadar(video::IImage *map_image)
}
}

void Mapper::blitMinimapPixelsToImageSurface(
void Minimap::blitMinimapPixelsToImageSurface(
video::IImage *map_image, video::IImage *heightmap_image)
{
for (s16 x = 0; x < data->map_size; x++)
@@ -368,7 +363,7 @@ void Mapper::blitMinimapPixelsToImageSurface(
}
}

video::ITexture *Mapper::getMinimapTexture()
video::ITexture *Minimap::getMinimapTexture()
{
// update minimap textures when new scan is ready
if (data->map_invalidated)
@@ -418,7 +413,7 @@ video::ITexture *Mapper::getMinimapTexture()
return data->texture;
}

v3f Mapper::getYawVec()
v3f Minimap::getYawVec()
{
if (data->minimap_shape_round) {
return v3f(
@@ -430,7 +425,7 @@ v3f Mapper::getYawVec()
}
}

scene::SMeshBuffer *Mapper::getMinimapMeshBuffer()
scene::SMeshBuffer *Minimap::getMinimapMeshBuffer()
{
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
buf->Vertices.set_used(4);
@@ -452,7 +447,7 @@ scene::SMeshBuffer *Mapper::getMinimapMeshBuffer()
return buf;
}

void Mapper::drawMinimap()
void Minimap::drawMinimap()
{
video::ITexture *minimap_texture = getMinimapTexture();
if (!minimap_texture)
@@ -550,7 +545,7 @@ void Mapper::drawMinimap()
}
}

void Mapper::updateActiveMarkers ()
void Minimap::updateActiveMarkers()
{
video::IImage *minimap_mask = data->minimap_shape_round ?
data->minimap_mask_round : data->minimap_mask_square;
@@ -112,19 +112,21 @@ class MinimapUpdateThread : public UpdateThread {
std::map<v3s16, MinimapMapblock *> m_blocks_cache;
};

class Mapper {
class Minimap {
public:
Mapper(IrrlichtDevice *device, Client *client);
~Mapper();
Minimap(IrrlichtDevice *device, Client *client);
~Minimap();

void addBlock(v3s16 pos, MinimapMapblock *data);

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();


@@ -1140,7 +1140,7 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
if (m_minimap_disabled_by_server && was_minimap_visible) {
// defers a minimap update, therefore only call it if really
// needed, by checking that minimap was visible before
m_mapper->setMinimapMode(MINIMAP_MODE_OFF);
m_minimap->setMinimapMode(MINIMAP_MODE_OFF);
}
}

0 comments on commit 40ce538

Please sign in to comment.
You can’t perform that action at this time.