From 40ce538aad9af8f7634c4ba7e9f12246fb23b31c Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 16 Mar 2017 10:34:54 +0100 Subject: [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 --- src/drawscene.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/drawscene.h') diff --git a/src/drawscene.h b/src/drawscene.h index 364fcd499..4965a0889 100644 --- a/src/drawscene.h +++ b/src/drawscene.h @@ -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); -- cgit v1.2.3 From 73de17afa821ccea84a119096b267e05a77db3ff Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sun, 16 Apr 2017 14:44:15 +0200 Subject: Android progressbar fix (#5601) * Fix progressbar for Android Fixes #5599 Fixed #5403 * draw_load_screen: use texturesource this permits to unify texture loading code * scale progress bar * Add gl version check for GL_OES_texture_npot. This fixed the texture on loading screen * Remove two sanity checks pointed by @celeron55 * sfan5 comments + android ratio fixes --- src/client.cpp | 14 ++++++++------ src/client/tile.cpp | 15 ++++++++++++--- src/drawscene.cpp | 28 +++++++++++----------------- src/drawscene.h | 4 ++-- src/game.cpp | 14 +++++++++----- 5 files changed, 42 insertions(+), 33 deletions(-) (limited to 'src/drawscene.h') diff --git a/src/client.cpp b/src/client.cpp index 246525f62..5ca51bd9c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1782,6 +1782,7 @@ typedef struct TextureUpdateArgs { u32 last_time_ms; u16 last_percent; const wchar_t* text_base; + ITextureSource *tsrc; } TextureUpdateArgs; void texture_update_progress(void *args, u32 progress, u32 max_progress) @@ -1803,8 +1804,8 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress) targs->last_time_ms = time_ms; std::basic_stringstream strm; strm << targs->text_base << " " << targs->last_percent << "%..."; - draw_load_screen(strm.str(), targs->device, targs->guienv, 0, - 72 + (u16) ((18. / 100.) * (double) targs->last_percent)); + draw_load_screen(strm.str(), targs->device, targs->guienv, targs->tsrc, 0, + 72 + (u16) ((18. / 100.) * (double) targs->last_percent), true); } } @@ -1824,21 +1825,21 @@ void Client::afterContentReceived(IrrlichtDevice *device) // Rebuild inherited images and recreate textures infostream<<"- Rebuilding images and textures"<rebuildImagesAndTextures(); delete[] text; // Rebuild shaders infostream<<"- Rebuilding shaders"<rebuildShaders(); delete[] text; // Update node aliases infostream<<"- Updating node aliases"<updateAliases(m_itemdef); std::string texture_path = g_settings->get("texture_path"); if (texture_path != "" && fs::IsDir(texture_path)) @@ -1855,6 +1856,7 @@ void Client::afterContentReceived(IrrlichtDevice *device) tu_args.last_time_ms = getTimeMs(); tu_args.last_percent = 0; tu_args.text_base = wgettext("Initializing nodes"); + tu_args.tsrc = m_tsrc; m_nodedef->updateTextures(this, texture_update_progress, &tu_args); delete[] tu_args.text_base; @@ -1871,7 +1873,7 @@ void Client::afterContentReceived(IrrlichtDevice *device) } text = wgettext("Done!"); - draw_load_screen(text, device, guienv, 0, 100); + draw_load_screen(text, device, guienv, m_tsrc, 0, 100); infostream<<"Client::afterContentReceived() done"<name); #ifdef __ANDROID__ img = Align2Npot2(img, driver); - sanity_check(img->getDimension().Height == npot2(img->getDimension().Height)); - sanity_check(img->getDimension().Width == npot2(img->getDimension().Width)); #endif // Create texture from resulting image video::ITexture *t = NULL; @@ -1124,6 +1122,14 @@ video::IImage* TextureSource::generateImage(const std::string &name) * @param driver driver to use for image operations * @return image or copy of image aligned to npot2 */ + +inline u16 get_GL_major_version() +{ + const GLubyte *gl_version = glGetString(GL_VERSION); + std::string gl_ver((const char *)gl_version); + return (u16) (gl_version[0] - '0'); +} + video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver) { @@ -1134,7 +1140,10 @@ video::IImage * Align2Npot2(video::IImage * image, core::dimension2d dim = image->getDimension(); std::string extensions = (char*) glGetString(GL_EXTENSIONS); - if (extensions.find("GL_OES_texture_npot") != std::string::npos) { + + // Only GLES2 is trusted to correctly report npot support + if (get_GL_major_version() > 1 && + extensions.find("GL_OES_texture_npot") != std::string::npos) { return image; } diff --git a/src/drawscene.cpp b/src/drawscene.cpp index 421b96f12..7d2d1d12f 100644 --- a/src/drawscene.cpp +++ b/src/drawscene.cpp @@ -599,7 +599,8 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr, Additionally, a progressbar can be drawn when percent is set between 0 and 100. */ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device, - gui::IGUIEnvironment* guienv, float dtime, int percent, bool clouds ) + gui::IGUIEnvironment* guienv, ITextureSource *tsrc, + float dtime, int percent, bool clouds) { video::IVideoDriver* driver = device->getVideoDriver(); v2u32 screensize = porting::getWindowSize(); @@ -625,27 +626,20 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice* device, // draw progress bar if ((percent >= 0) && (percent <= 100)) { - const std::string &texture_path = g_settings->get("texture_path"); - std::string tp_progress_bar = texture_path + "/progress_bar.png"; - std::string tp_progress_bar_bg = texture_path + "/progress_bar_bg.png"; - - if (!(fs::PathExists(tp_progress_bar) && - fs::PathExists(tp_progress_bar_bg))) { - std::string gamepath = fs::RemoveRelativePathComponents( - porting::path_share + DIR_DELIM + "textures"); - tp_progress_bar = gamepath + "/base/pack/progress_bar.png"; - tp_progress_bar_bg = gamepath + "/base/pack/progress_bar_bg.png"; - } - - video::ITexture *progress_img = - driver->getTexture(tp_progress_bar.c_str()); - video::ITexture *progress_img_bg = - driver->getTexture(tp_progress_bar_bg.c_str()); + video::ITexture *progress_img = tsrc->getTexture("progress_bar.png"); + video::ITexture *progress_img_bg = tsrc->getTexture("progress_bar_bg.png"); if (progress_img && progress_img_bg) { +#ifndef __ANDROID__ const core::dimension2d &img_size = progress_img_bg->getSize(); u32 imgW = rangelim(img_size.Width, 200, 600); u32 imgH = rangelim(img_size.Height, 24, 72); +#else + const core::dimension2d img_size(256, 48); + float imgRatio = (float) img_size.Height / img_size.Width; + u32 imgW = screensize.X / 2.2f; + u32 imgH = floor(imgW * imgRatio); +#endif v2s32 img_pos((screensize.X - imgW) / 2, (screensize.Y - imgH) / 2); draw2DImageFilterScaled( diff --git a/src/drawscene.h b/src/drawscene.h index 4965a0889..4a71b1f4e 100644 --- a/src/drawscene.h +++ b/src/drawscene.h @@ -27,8 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc., void draw_load_screen(const std::wstring &text, IrrlichtDevice *device, - gui::IGUIEnvironment *guienv, float dtime = 0, int percent = 0, - bool clouds = true); + gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime = 0, + int percent = 0, bool clouds = true); void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr, Camera &camera, Client &client, LocalPlayer *player, diff --git a/src/game.cpp b/src/game.cpp index 6ef471c9e..f584a58ef 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1725,9 +1725,10 @@ bool Game::init( u16 port, const SubgameSpec &gamespec) { + texture_src = createTextureSource(device); + showOverlayMessage(wgettext("Loading..."), 0, 0); - texture_src = createTextureSource(device); shader_src = createShaderSource(device); itemdef_manager = createItemDefManager(); @@ -2183,12 +2184,14 @@ bool Game::getServerContent(bool *aborted) if (!client->itemdefReceived()) { const wchar_t *text = wgettext("Item definitions..."); progress = 25; - draw_load_screen(text, device, guienv, dtime, progress); + draw_load_screen(text, device, guienv, texture_src, + dtime, progress); delete[] text; } else if (!client->nodedefReceived()) { const wchar_t *text = wgettext("Node definitions..."); progress = 30; - draw_load_screen(text, device, guienv, dtime, progress); + draw_load_screen(text, device, guienv, texture_src, + dtime, progress); delete[] text; } else { std::stringstream message; @@ -2212,7 +2215,7 @@ bool Game::getServerContent(bool *aborted) progress = 30 + client->mediaReceiveProgress() * 35 + 0.5; draw_load_screen(utf8_to_wide(message.str()), device, - guienv, dtime, progress); + guienv, texture_src, dtime, progress); } } @@ -4357,7 +4360,8 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime) void Game::showOverlayMessage(const wchar_t *msg, float dtime, int percent, bool draw_clouds) { - draw_load_screen(msg, device, guienv, dtime, percent, draw_clouds); + draw_load_screen(msg, device, guienv, texture_src, dtime, percent, + draw_clouds); delete[] msg; } -- cgit v1.2.3 From e25a38e3fbb156ae2bc72cc66aef014ae3963407 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Fri, 19 May 2017 07:25:27 +0200 Subject: When minimap is disabled in configuration, really disable it (#5771) * When minimap is disabled in configuration, really disable it --- doc/client_lua_api.md | 1 + src/client.cpp | 7 +++++-- src/drawscene.cpp | 6 +++--- src/drawscene.h | 2 +- src/game.cpp | 26 +++++++++++++++----------- src/network/clientpackethandler.cpp | 2 +- src/script/scripting_client.cpp | 3 ++- 7 files changed, 28 insertions(+), 19 deletions(-) (limited to 'src/drawscene.h') diff --git a/doc/client_lua_api.md b/doc/client_lua_api.md index 9f59b4671..2c0351a11 100644 --- a/doc/client_lua_api.md +++ b/doc/client_lua_api.md @@ -800,6 +800,7 @@ Call these functions only at load time! ### UI * `minetest.ui.minimap` * Reference to the minimap object. See [`Minimap`](#minimap) class reference for methods. + * If client disabled minimap (using enable_minimap setting) this reference will be nil. * `minetest.camera` * Reference to the camera object. See [`Camera`](#camera) class reference for methods. * `minetest.show_formspec(formname, formspec)` : returns true on success diff --git a/src/client.cpp b/src/client.cpp index 1e17e7c11..6ab4002a5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -93,6 +93,7 @@ Client::Client( m_address_name(address_name), m_device(device), m_camera(NULL), + m_minimap(NULL), m_minimap_disabled_by_server(false), m_server_ser_ver(SER_FMT_VER_INVALID), m_proto_ver(0), @@ -127,7 +128,9 @@ Client::Client( // Add local player m_env.setLocalPlayer(new LocalPlayer(this, playername)); - m_minimap = new Minimap(device, this); + if (g_settings->getBool("enable_minimap")) { + m_minimap = new Minimap(device, this); + } m_cache_save_interval = g_settings->getU16("server_map_save_interval"); m_modding_enabled = g_settings->getBool("enable_client_modding"); @@ -502,7 +505,7 @@ void Client::step(float dtime) delete r.mesh; } - if (do_mapper_update) + if (m_minimap && do_mapper_update) m_minimap->addBlock(r.p, minimap_mapblock); if (r.ack_block_to_server) { diff --git a/src/drawscene.cpp b/src/drawscene.cpp index 7d2d1d12f..59f9b8375 100644 --- a/src/drawscene.cpp +++ b/src/drawscene.cpp @@ -509,7 +509,7 @@ void draw_plain(Camera &camera, bool show_hud, void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr, Camera &camera, Client &client, LocalPlayer *player, Hud &hud, - Minimap &mapper, gui::IGUIEnvironment *guienv, + Minimap *mapper, gui::IGUIEnvironment *guienv, const v2u32 &screensize, const video::SColor &skycolor, bool show_hud, bool show_minimap) { @@ -584,8 +584,8 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr, hud.drawLuaElements(camera.getOffset()); camera.drawNametags(); - if (show_minimap) - mapper.drawMinimap(); + if (mapper && show_minimap) + mapper->drawMinimap(); } guienv->drawAll(); diff --git a/src/drawscene.h b/src/drawscene.h index 4a71b1f4e..99ff1a6bc 100644 --- a/src/drawscene.h +++ b/src/drawscene.h @@ -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, Minimap &mapper, gui::IGUIEnvironment *guienv, + Hud &hud, Minimap *mapper, gui::IGUIEnvironment *guienv, const v2u32 &screensize, const video::SColor &skycolor, bool show_hud, bool show_minimap); diff --git a/src/game.cpp b/src/game.cpp index f079f836b..f967e349c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -715,16 +715,19 @@ public: m_eye_position_pixel.set(eye_position_array, services); m_eye_position_vertex.set(eye_position_array, services); - float minimap_yaw_array[3]; - v3f minimap_yaw = m_client->getMinimap()->getYawVec(); + if (m_client->getMinimap()) { + float minimap_yaw_array[3]; + 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; - minimap_yaw_array[2] = minimap_yaw.Z; + minimap_yaw_array[0] = minimap_yaw.X; + minimap_yaw_array[1] = minimap_yaw.Y; + minimap_yaw_array[2] = minimap_yaw.Z; #else - minimap_yaw.getAs3Values(minimap_yaw_array); + minimap_yaw.getAs3Values(minimap_yaw_array); #endif - m_minimap_yaw.set(minimap_yaw_array, services); + m_minimap_yaw.set(minimap_yaw_array, services); + + } SamplerLayer_t base_tex = 0, normal_tex = 1, @@ -1948,7 +1951,8 @@ bool Game::createClient(const std::string &playername, } mapper = client->getMinimap(); - mapper->setMinimapMode(MINIMAP_MODE_OFF); + if (mapper) + mapper->setMinimapMode(MINIMAP_MODE_OFF); return true; } @@ -2781,7 +2785,7 @@ void Game::toggleHud() void Game::toggleMinimap(bool shift_pressed) { - if (!flags.show_hud || !g_settings->getBool("enable_minimap")) + if (!mapper || !flags.show_hud || !g_settings->getBool("enable_minimap")) return; if (shift_pressed) { @@ -4194,7 +4198,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, TimeTaker tt_draw("mainloop: draw"); driver->beginScene(true, true, skycolor); - draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper, + draw_scene(driver, smgr, *camera, *client, player, *hud, mapper, guienv, screensize, skycolor, flags.show_hud, flags.show_minimap); @@ -4229,7 +4233,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* Update minimap pos and rotation */ - if (flags.show_minimap && flags.show_hud) { + if (mapper && flags.show_minimap && flags.show_hud) { mapper->setPos(floatToInt(player->getPosition(), BS)); mapper->setAngle(player->getYaw()); } diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 0dd09c6d1..59669fe6d 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -1150,7 +1150,7 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt) m_minimap_disabled_by_server = !(player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE); // Hide minimap if it has been disabled by the server - if (m_minimap_disabled_by_server && was_minimap_visible) { + if (m_minimap && 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_minimap->setMinimapMode(MINIMAP_MODE_OFF); diff --git a/src/script/scripting_client.cpp b/src/script/scripting_client.cpp index 24f70b8c1..da289e564 100644 --- a/src/script/scripting_client.cpp +++ b/src/script/scripting_client.cpp @@ -51,7 +51,8 @@ ClientScripting::ClientScripting(Client *client): InitializeModApi(L, top); lua_pop(L, 1); - LuaMinimap::create(L, client->getMinimap()); + if (client->getMinimap()) + LuaMinimap::create(L, client->getMinimap()); // Push builtin initialization type lua_pushstring(L, "client"); -- cgit v1.2.3