Skip to content

Commit e25a38e

Browse files
authoredMay 19, 2017
When minimap is disabled in configuration, really disable it (#5771)
* When minimap is disabled in configuration, really disable it
1 parent 1c6d2f5 commit e25a38e

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed
 

‎doc/client_lua_api.md

+1
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ Call these functions only at load time!
800800
### UI
801801
* `minetest.ui.minimap`
802802
* Reference to the minimap object. See [`Minimap`](#minimap) class reference for methods.
803+
* If client disabled minimap (using enable_minimap setting) this reference will be nil.
803804
* `minetest.camera`
804805
* Reference to the camera object. See [`Camera`](#camera) class reference for methods.
805806
* `minetest.show_formspec(formname, formspec)` : returns true on success

‎src/client.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Client::Client(
9393
m_address_name(address_name),
9494
m_device(device),
9595
m_camera(NULL),
96+
m_minimap(NULL),
9697
m_minimap_disabled_by_server(false),
9798
m_server_ser_ver(SER_FMT_VER_INVALID),
9899
m_proto_ver(0),
@@ -127,7 +128,9 @@ Client::Client(
127128
// Add local player
128129
m_env.setLocalPlayer(new LocalPlayer(this, playername));
129130

130-
m_minimap = new Minimap(device, this);
131+
if (g_settings->getBool("enable_minimap")) {
132+
m_minimap = new Minimap(device, this);
133+
}
131134
m_cache_save_interval = g_settings->getU16("server_map_save_interval");
132135

133136
m_modding_enabled = g_settings->getBool("enable_client_modding");
@@ -502,7 +505,7 @@ void Client::step(float dtime)
502505
delete r.mesh;
503506
}
504507

505-
if (do_mapper_update)
508+
if (m_minimap && do_mapper_update)
506509
m_minimap->addBlock(r.p, minimap_mapblock);
507510

508511
if (r.ack_block_to_server) {

‎src/drawscene.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ void draw_plain(Camera &camera, bool show_hud,
509509

510510
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
511511
Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
512-
Minimap &mapper, gui::IGUIEnvironment *guienv,
512+
Minimap *mapper, gui::IGUIEnvironment *guienv,
513513
const v2u32 &screensize, const video::SColor &skycolor,
514514
bool show_hud, bool show_minimap)
515515
{
@@ -584,8 +584,8 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
584584
hud.drawLuaElements(camera.getOffset());
585585
camera.drawNametags();
586586

587-
if (show_minimap)
588-
mapper.drawMinimap();
587+
if (mapper && show_minimap)
588+
mapper->drawMinimap();
589589
}
590590

591591
guienv->drawAll();

‎src/drawscene.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,
3232

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

‎src/game.cpp

+15-11
Original file line numberDiff line numberDiff line change
@@ -715,16 +715,19 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
715715
m_eye_position_pixel.set(eye_position_array, services);
716716
m_eye_position_vertex.set(eye_position_array, services);
717717

718-
float minimap_yaw_array[3];
719-
v3f minimap_yaw = m_client->getMinimap()->getYawVec();
718+
if (m_client->getMinimap()) {
719+
float minimap_yaw_array[3];
720+
v3f minimap_yaw = m_client->getMinimap()->getYawVec();
720721
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
721-
minimap_yaw_array[0] = minimap_yaw.X;
722-
minimap_yaw_array[1] = minimap_yaw.Y;
723-
minimap_yaw_array[2] = minimap_yaw.Z;
722+
minimap_yaw_array[0] = minimap_yaw.X;
723+
minimap_yaw_array[1] = minimap_yaw.Y;
724+
minimap_yaw_array[2] = minimap_yaw.Z;
724725
#else
725-
minimap_yaw.getAs3Values(minimap_yaw_array);
726+
minimap_yaw.getAs3Values(minimap_yaw_array);
726727
#endif
727-
m_minimap_yaw.set(minimap_yaw_array, services);
728+
m_minimap_yaw.set(minimap_yaw_array, services);
729+
730+
}
728731

729732
SamplerLayer_t base_tex = 0,
730733
normal_tex = 1,
@@ -1948,7 +1951,8 @@ bool Game::createClient(const std::string &playername,
19481951
}
19491952

19501953
mapper = client->getMinimap();
1951-
mapper->setMinimapMode(MINIMAP_MODE_OFF);
1954+
if (mapper)
1955+
mapper->setMinimapMode(MINIMAP_MODE_OFF);
19521956

19531957
return true;
19541958
}
@@ -2781,7 +2785,7 @@ void Game::toggleHud()
27812785

27822786
void Game::toggleMinimap(bool shift_pressed)
27832787
{
2784-
if (!flags.show_hud || !g_settings->getBool("enable_minimap"))
2788+
if (!mapper || !flags.show_hud || !g_settings->getBool("enable_minimap"))
27852789
return;
27862790

27872791
if (shift_pressed) {
@@ -4194,7 +4198,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
41944198
TimeTaker tt_draw("mainloop: draw");
41954199
driver->beginScene(true, true, skycolor);
41964200

4197-
draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper,
4201+
draw_scene(driver, smgr, *camera, *client, player, *hud, mapper,
41984202
guienv, screensize, skycolor, flags.show_hud,
41994203
flags.show_minimap);
42004204

@@ -4229,7 +4233,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
42294233
/*
42304234
Update minimap pos and rotation
42314235
*/
4232-
if (flags.show_minimap && flags.show_hud) {
4236+
if (mapper && flags.show_minimap && flags.show_hud) {
42334237
mapper->setPos(floatToInt(player->getPosition(), BS));
42344238
mapper->setAngle(player->getYaw());
42354239
}

‎src/network/clientpackethandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt)
11501150
m_minimap_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
11511151

11521152
// Hide minimap if it has been disabled by the server
1153-
if (m_minimap_disabled_by_server && was_minimap_visible) {
1153+
if (m_minimap && m_minimap_disabled_by_server && was_minimap_visible) {
11541154
// defers a minimap update, therefore only call it if really
11551155
// needed, by checking that minimap was visible before
11561156
m_minimap->setMinimapMode(MINIMAP_MODE_OFF);

‎src/script/scripting_client.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ ClientScripting::ClientScripting(Client *client):
5151
InitializeModApi(L, top);
5252
lua_pop(L, 1);
5353

54-
LuaMinimap::create(L, client->getMinimap());
54+
if (client->getMinimap())
55+
LuaMinimap::create(L, client->getMinimap());
5556

5657
// Push builtin initialization type
5758
lua_pushstring(L, "client");

0 commit comments

Comments
 (0)