From 1d25d1f7ad35f739e8a64c2bdb44105998aed19b Mon Sep 17 00:00:00 2001 From: hecks <42101236+hecktest@users.noreply.github.com> Date: Sun, 11 Jul 2021 09:50:34 +0200 Subject: Refactor video driver name retrieval (#11413) Co-authored-by: hecktest <> --- src/client/renderingengine.cpp | 29 ++++++++--------------------- src/client/renderingengine.h | 7 +++++-- src/script/lua_api/l_mainmenu.cpp | 7 +++---- 3 files changed, 16 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 558a9dd7a..037ede074 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -105,7 +105,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) u32 i; for (i = 0; i != drivers.size(); i++) { if (!strcasecmp(driverstring.c_str(), - RenderingEngine::getVideoDriverName(drivers[i]))) { + RenderingEngine::getVideoDriverInfo(drivers[i]).name.c_str())) { driverType = drivers[i]; break; } @@ -555,28 +555,15 @@ void RenderingEngine::draw_scene(video::SColor skycolor, bool show_hud, core->draw(skycolor, show_hud, show_minimap, draw_wield_tool, draw_crosshair); } -const char *RenderingEngine::getVideoDriverName(irr::video::E_DRIVER_TYPE type) +const VideoDriverInfo &RenderingEngine::getVideoDriverInfo(irr::video::E_DRIVER_TYPE type) { - static const std::unordered_map driver_ids = { - {irr::video::EDT_NULL, "null"}, - {irr::video::EDT_OPENGL, "opengl"}, - {irr::video::EDT_OGLES1, "ogles1"}, - {irr::video::EDT_OGLES2, "ogles2"}, + static const std::unordered_map driver_info_map = { + {irr::video::EDT_NULL, {"null", "NULL Driver"}}, + {irr::video::EDT_OPENGL, {"opengl", "OpenGL"}}, + {irr::video::EDT_OGLES1, {"ogles1", "OpenGL ES1"}}, + {irr::video::EDT_OGLES2, {"ogles2", "OpenGL ES2"}}, }; - - return driver_ids.at(type).c_str(); -} - -const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type) -{ - static const std::unordered_map driver_names = { - {irr::video::EDT_NULL, "NULL Driver"}, - {irr::video::EDT_OPENGL, "OpenGL"}, - {irr::video::EDT_OGLES1, "OpenGL ES1"}, - {irr::video::EDT_OGLES2, "OpenGL ES2"}, - }; - - return driver_names.at(type).c_str(); + return driver_info_map.at(type); } #ifndef __ANDROID__ diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 5299222e2..6f104bba9 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -29,6 +29,10 @@ with this program; if not, write to the Free Software Foundation, Inc., // include the shadow mapper classes too #include "client/shadows/dynamicshadowsrender.h" +struct VideoDriverInfo { + std::string name; + std::string friendly_name; +}; class ITextureSource; class Camera; @@ -49,8 +53,7 @@ public: video::IVideoDriver *getVideoDriver() { return driver; } - static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type); - static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type); + static const VideoDriverInfo &getVideoDriverInfo(irr::video::E_DRIVER_TYPE type); static float getDisplayDensity(); static v2u32 getDisplaySize(); diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 788557460..ad00de1c4 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -737,13 +737,12 @@ int ModApiMainMenu::l_get_video_drivers(lua_State *L) lua_newtable(L); for (u32 i = 0; i != drivers.size(); i++) { - const char *name = RenderingEngine::getVideoDriverName(drivers[i]); - const char *fname = RenderingEngine::getVideoDriverFriendlyName(drivers[i]); + auto &info = RenderingEngine::getVideoDriverInfo(drivers[i]); lua_newtable(L); - lua_pushstring(L, name); + lua_pushstring(L, info.name.c_str()); lua_setfield(L, -2, "name"); - lua_pushstring(L, fname); + lua_pushstring(L, info.friendly_name.c_str()); lua_setfield(L, -2, "friendly_name"); lua_rawseti(L, -2, i + 1); -- cgit v1.2.3