]> git.lizzy.rs Git - minetest.git/commitdiff
Add minetest.get_player_window_information() (#12367)
authorrubenwardy <rw@rubenwardy.com>
Mon, 27 Feb 2023 22:58:41 +0000 (22:58 +0000)
committerGitHub <noreply@github.com>
Mon, 27 Feb 2023 22:58:41 +0000 (22:58 +0000)
23 files changed:
builtin/mainmenu/tab_about.lua
doc/lua_api.txt
doc/menu_lua_api.txt
games/devtest/mods/testfullscreenfs/init.lua [new file with mode: 0644]
games/devtest/mods/testfullscreenfs/mod.conf [new file with mode: 0644]
src/client/client.cpp
src/client/client.h
src/client/game.cpp
src/client/renderingengine.h
src/clientdynamicinfo.h [new file with mode: 0644]
src/clientiface.h
src/network/clientopcodes.cpp
src/network/networkprotocol.h
src/network/serveropcodes.cpp
src/network/serverpackethandler.cpp
src/script/common/c_converter.cpp
src/script/common/c_converter.h
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_mainmenu.h
src/script/lua_api/l_server.cpp
src/script/lua_api/l_server.h
src/server.cpp
src/server.h

index a84ebce3f69506d8d4ad11d2b8de6eeba53c8d74..609b0cb71aa879eb89aaa430f39410002bfcd168 100644 (file)
@@ -165,7 +165,7 @@ return {
                fs = fs .. "style[label_button2;border=false]" ..
                        "button[0.1,6;5.3,1;label_button2;" ..
                        fgettext("Active renderer:") .. "\n" ..
-                       core.formspec_escape(core.get_screen_info().render_info) .. "]"
+                       core.formspec_escape(core.get_active_renderer()) .. "]"
 
                if PLATFORM == "Android" then
                        fs = fs .. "button[0.5,5.1;4.5,0.8;share_debug;" .. fgettext("Share debug log") .. "]"
index 19e87b368c0a510e8aa36f77083001754a26bb90..a16790eeebaa4d259e3e63bf9231cf15e342c357 100644 (file)
@@ -4972,6 +4972,7 @@ Utilities
           protocol_version = 32,     -- protocol version used by client
           formspec_version = 2,      -- supported formspec version
           lang_code = "fr"           -- Language code used for translation
+
           -- the following keys can be missing if no stats have been collected yet
           min_rtt = 0.01,            -- minimum round trip time
           max_rtt = 0.2,             -- maximum round trip time
@@ -4988,6 +4989,42 @@ Utilities
           --vers_string = "0.4.9-git", -- full version string
           --state = "Active"           -- current client state
       }
+* `minetest.get_player_window_information(player_name)`:
+
+      -- Will only be present if the client sent this information (requires v5.7+)
+      --
+      -- Note that none of these things are constant, they are likely to change during a client
+      -- connection as the player resizes the window and moves it between monitors
+      --
+      -- real_gui_scaling and real_hud_scaling can be used instead of DPI.
+      -- OSes don't necessarily give the physical DPI, as they may allow user configuration.
+      -- real_*_scaling is just OS DPI / 96 but with another level of user configuration.
+      {
+          -- Current size of the in-game render target (pixels).
+          --
+          -- This is usually the window size, but may be smaller in certain situations,
+          -- such as side-by-side mode.
+          size = {
+              x = 1308,
+              y = 577,
+          },
+
+          -- Estimated maximum formspec size before Minetest will start shrinking the
+          -- formspec to fit. For a fullscreen formspec, use a size 10-20% larger than
+          -- this and `padding[-0.01,-0.01]`.
+          max_formspec_size = {
+              x = 20,
+              y = 11.25
+          },
+
+          -- GUI Scaling multiplier
+          -- Equal to the setting `gui_scaling` multiplied by `dpi / 96`
+          real_gui_scaling = 1,
+
+          -- HUD Scaling multiplier
+          -- Equal to the setting `hud_scaling` multiplied by `dpi / 96`
+          real_hud_scaling = 1,
+      }
 
 * `minetest.mkdir(path)`: returns success.
     * Creates a directory specified by `path`, creating parent directories
index ad07ea7328e8c0fcf171c8c14e168d9dfabdc384..e8d7b6e400f02e6920b9af688e41b3f65399906c 100644 (file)
@@ -203,17 +203,42 @@ GUI
         will be added to fieldname value is set to formname itself
   * if `is_file_select` is `true`, a file and not a folder will be selected
   * returns nil or selected file/folder
-* `core.get_screen_info()`
-  * returns
+* `core.get_active_renderer()`: Ex: "OpenGL 4.6".
+* `core.get_window_info()`: Same as server-side `get_player_window_information` API.
+
+      -- Note that none of these things are constant, they are likely to change
+      -- as the player resizes the window and moves it between monitors
+      --
+      -- real_gui_scaling and real_hud_scaling can be used instead of DPI.
+      -- OSes don't necessarily give the physical DPI, as they may allow user configuration.
+      -- real_*_scaling is just OS DPI / 96 but with another level of user configuration.
+      {
+          -- Current size of the in-game render target.
+          --
+          -- This is usually the window size, but may be smaller in certain situations,
+          -- such as side-by-side mode.
+          size = {
+              x = 1308,
+              y = 577,
+          },
+
+          -- Estimated maximum formspec size before Minetest will start shrinking the
+          -- formspec to fit. For a fullscreen formspec, use a size 10-20% larger than
+          -- this and `padding[-0.01,-0.01]`.
+          max_formspec_size = {
+              x = 20,
+              y = 11.25
+          },
+
+          -- GUI Scaling multiplier
+          -- Equal to the setting `gui_scaling` multiplied by `dpi / 96`
+          real_gui_scaling = 1,
+
+          -- HUD Scaling multiplier
+          -- Equal to the setting `hud_scaling` multiplied by `dpi / 96`
+          real_hud_scaling = 1,
+      }
 
-        {
-          density         = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
-          display_width   = <width of display>,
-          display_height  = <height of display>,
-          window_width    = <current window width>,
-          window_height   = <current window height>,
-          render_info     = <active render information>
-        }
 
 
 Content and Packages
diff --git a/games/devtest/mods/testfullscreenfs/init.lua b/games/devtest/mods/testfullscreenfs/init.lua
new file mode 100644 (file)
index 0000000..b9d2061
--- /dev/null
@@ -0,0 +1,29 @@
+local function show_fullscreen_fs(name)
+       local window = minetest.get_player_window_information(name)
+       if not window then
+               return false, "Unable to get window info"
+       end
+
+       print(dump(window))
+
+       local size = { x = window.max_formspec_size.x * 1.1, y = window.max_formspec_size.y * 1.1 }
+       local fs = {
+               "formspec_version[4]",
+               ("size[%f,%f]"):format(size.x, size.y),
+               "padding[-0.01,-0.01]",
+               ("button[%f,%f;1,1;%s;%s]"):format(0, 0, "tl", "TL"),
+               ("button[%f,%f;1,1;%s;%s]"):format(size.x - 1, 0, "tr", "TR"),
+               ("button[%f,%f;1,1;%s;%s]"):format(size.x - 1, size.y - 1, "br", "BR"),
+               ("button[%f,%f;1,1;%s;%s]"):format(0, size.y - 1, "bl", "BL"),
+
+               ("label[%f,%f;%s]"):format(size.x / 2, size.y / 2, "Fullscreen")
+       }
+
+       minetest.show_formspec(name, "testfullscreenfs:fs", table.concat(fs))
+       return true, ("Calculated size of %f, %f"):format(size.x, size.y)
+end
+
+
+minetest.register_chatcommand("testfullscreenfs", {
+       func = show_fullscreen_fs,
+})
diff --git a/games/devtest/mods/testfullscreenfs/mod.conf b/games/devtest/mods/testfullscreenfs/mod.conf
new file mode 100644 (file)
index 0000000..84dc87e
--- /dev/null
@@ -0,0 +1,2 @@
+name = testfullscreenfs
+description = Test mod to use minetest.get_player_window_information()
index 6544dbaf6cd46a685da4ee74442fd0032546bc57..6f2647d503a795acb202f05b983796128ac06f38 100644 (file)
@@ -1415,6 +1415,17 @@ void Client::sendHaveMedia(const std::vector<u32> &tokens)
        Send(&pkt);
 }
 
+void Client::sendUpdateClientInfo(const ClientDynamicInfo& info)
+{
+       NetworkPacket pkt(TOSERVER_UPDATE_CLIENT_INFO, 4*2 + 4 + 4 + 4*2);
+       pkt << (u32)info.render_target_size.X << (u32)info.render_target_size.Y;
+       pkt << info.real_gui_scaling;
+       pkt << info.real_hud_scaling;
+       pkt << (f32)info.max_fs_size.X << (f32)info.max_fs_size.Y;
+
+       Send(&pkt);
+}
+
 void Client::removeNode(v3s16 p)
 {
        std::map<v3s16, MapBlock*> modified_blocks;
index 44a0de719d7ae68b729cb1694db57bbe3edeb36d..5ed5c6e9a28a2f77bd50c3429c0d160810ae4b52 100644 (file)
@@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "network/address.h"
 #include "network/peerhandler.h"
 #include "gameparams.h"
+#include "clientdynamicinfo.h"
 #include <fstream>
 #include "util/numeric.h"
 
@@ -251,6 +252,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
        void sendRespawn();
        void sendReady();
        void sendHaveMedia(const std::vector<u32> &tokens);
+       void sendUpdateClientInfo(const ClientDynamicInfo &info);
 
        ClientEnvironment& getEnv() { return m_env; }
        ITextureSource *tsrc() { return getTextureSource(); }
index cd0e67b42105f42305addfbbd387a15c1ac57e85..c5dc8f6d9d8337f809b2111595c12066d6184145 100644 (file)
@@ -71,6 +71,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "version.h"
 #include "script/scripting_client.h"
 #include "hud.h"
+#include "clientdynamicinfo.h"
 
 #if USE_SOUND
        #include "client/sound_openal.h"
@@ -917,12 +918,16 @@ class Game {
        static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
 
        f32 getSensitivityScaleFactor() const;
+       ClientDynamicInfo getCurrentDynamicInfo() const;
 
        InputHandler *input = nullptr;
 
        Client *client = nullptr;
        Server *server = nullptr;
 
+       ClientDynamicInfo client_display_info{};
+       float dynamic_info_send_timer = 0;
+
        IWritableTextureSource *texture_src = nullptr;
        IWritableShaderSource *shader_src = nullptr;
 
@@ -1187,31 +1192,44 @@ void Game::run()
                        && client->checkPrivilege("fast");
 #endif
 
-       irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screen_w"),
+       v2u32 previous_screen_size(g_settings->getU16("screen_w"),
                g_settings->getU16("screen_h"));
 
        while (m_rendering_engine->run()
                        && !(*kill || g_gamecallback->shutdown_requested
                        || (server && server->isShutdownRequested()))) {
 
-               const irr::core::dimension2d<u32> &current_screen_size =
-                       m_rendering_engine->get_video_driver()->getScreenSize();
+               // Calculate dtime =
+               //    m_rendering_engine->run() from this iteration
+               //  + Sleep time until the wanted FPS are reached
+               draw_times.limit(device, &dtime);
+
+               const auto current_dynamic_info = getCurrentDynamicInfo();
+               if (!current_dynamic_info.equal(client_display_info)) {
+                       client_display_info = current_dynamic_info;
+                       dynamic_info_send_timer = 0.2f;
+               }
+
+               if (dynamic_info_send_timer > 0) {
+                       dynamic_info_send_timer -= dtime;
+                       if (dynamic_info_send_timer <= 0) {
+                               client->sendUpdateClientInfo(current_dynamic_info);
+                       }
+               }
+
+               const auto &current_screen_size = current_dynamic_info.render_target_size;
+
                // Verify if window size has changed and save it if it's the case
                // Ensure evaluating settings->getBool after verifying screensize
                // First condition is cheaper
                if (previous_screen_size != current_screen_size &&
                                current_screen_size != irr::core::dimension2d<u32>(0,0) &&
                                g_settings->getBool("autosave_screensize")) {
-                       g_settings->setU16("screen_w", current_screen_size.Width);
-                       g_settings->setU16("screen_h", current_screen_size.Height);
+                       g_settings->setU16("screen_w", current_screen_size.X);
+                       g_settings->setU16("screen_h", current_screen_size.Y);
                        previous_screen_size = current_screen_size;
                }
 
-               // Calculate dtime =
-               //    m_rendering_engine->run() from this iteration
-               //  + Sleep time until the wanted FPS are reached
-               draw_times.limit(device, &dtime);
-
                // Prepare render data for next iteration
 
                updateStats(&stats, draw_times, dtime);
@@ -2583,6 +2601,19 @@ f32 Game::getSensitivityScaleFactor() const
        return tan(fov_y / 2.0f) * 1.3763818698f;
 }
 
+ClientDynamicInfo Game::getCurrentDynamicInfo() const
+{
+       v2u32 screen_size = RenderingEngine::getWindowSize();
+       f32 density = RenderingEngine::getDisplayDensity();
+       f32 gui_scaling = g_settings->getFloat("gui_scaling") * density;
+       f32 hud_scaling = g_settings->getFloat("hud_scaling") * density;
+
+       return {
+               screen_size, gui_scaling, hud_scaling,
+               ClientDynamicInfo::calculateMaxFSSize(screen_size)
+       };
+}
+
 void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
 {
 #ifdef HAVE_TOUCHSCREENGUI
index b477da0273c2279099054d7435500d22784f6dc5..8332ed9f5af748d88eac25badb97ad1b302b65ca 100644 (file)
@@ -67,6 +67,12 @@ class RenderingEngine
 
        void removeMesh(const scene::IMesh* mesh);
 
+       /**
+        * This takes 3d_mode into account - side-by-side will return a
+        * halved horizontal size.
+        *
+        * @return "window" size
+        */
        static v2u32 getWindowSize()
        {
                sanity_check(s_singleton);
diff --git a/src/clientdynamicinfo.h b/src/clientdynamicinfo.h
new file mode 100644 (file)
index 0000000..ebe5964
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+Minetest
+Copyright (C) 2022-3 rubenwardy <rw@rubenwardy.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.
+*/
+
+#pragma once
+
+#include "irrTypes.h"
+
+
+struct ClientDynamicInfo
+{
+       v2u32 render_target_size;
+       f32 real_gui_scaling;
+       f32 real_hud_scaling;
+       v2f32 max_fs_size;
+
+       bool equal(const ClientDynamicInfo &other) const {
+               return render_target_size == other.render_target_size &&
+                               abs(real_gui_scaling - other.real_gui_scaling) < 0.001f &&
+                               abs(real_hud_scaling - other.real_hud_scaling) < 0.001f;
+       }
+
+       static v2f32 calculateMaxFSSize(v2u32 render_target_size) {
+               f32 factor =
+#ifdef HAVE_TOUCHSCREENGUI
+                               10;
+#else
+                               15;
+#endif
+               f32 ratio = (f32)render_target_size.X / (f32)render_target_size.Y;
+               if (ratio < 1)
+                       return { factor, factor / ratio };
+               else
+                       return { factor * ratio, factor };
+       }
+};
index 3d84944ea448e062268642d36956b082b273aa1c..d867c52fe7328ed68f13f6e1a05e6860e1765a51 100644 (file)
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "network/address.h"
 #include "porting.h"
 #include "threading/mutex_auto_lock.h"
+#include "clientdynamicinfo.h"
 
 #include <list>
 #include <vector>
@@ -350,6 +351,9 @@ class RemoteClient
        void setCachedAddress(const Address &addr) { m_addr = addr; }
        const Address &getAddress() const { return m_addr; }
 
+       void setDynamicInfo(const ClientDynamicInfo &info) { m_dynamic_info = info; }
+       const ClientDynamicInfo &getDynamicInfo() const { return m_dynamic_info; }
+
 private:
        // Version is stored in here after INIT before INIT2
        u8 m_pending_serialization_version = SER_FMT_VER_INVALID;
@@ -360,9 +364,12 @@ class RemoteClient
        // Cached here so retrieval doesn't have to go to connection API
        Address m_addr;
 
-       // Client sent language code
+       // Client-sent language code
        std::string m_lang_code;
 
+       // Client-sent dynamic info
+       ClientDynamicInfo m_dynamic_info{};
+
        /*
                Blocks that have been sent to client.
                - These don't have to be sent again.
index 6a78b4652e072fb030babce62acf3322176e7826..bff3181551724837e03a20c75288a7a8583e4b15 100644 (file)
@@ -223,4 +223,5 @@ const ServerCommandFactory serverCommandFactoryTable[TOSERVER_NUM_MSG_TYPES] =
        { "TOSERVER_FIRST_SRP",          1, true }, // 0x50
        { "TOSERVER_SRP_BYTES_A",        1, true }, // 0x51
        { "TOSERVER_SRP_BYTES_M",        1, true }, // 0x52
+       { "TOSERVER_UPDATE_CLIENT_INFO", 1, true }, // 0x53
 };
index d456f19bf9e4270a618847bd217537c68f51da77..d420101c87d3a3e64636cec077cfc888aaa01e81 100644 (file)
@@ -1062,7 +1062,15 @@ enum ToServerCommand
                std::string bytes_M
        */
 
-       TOSERVER_NUM_MSG_TYPES = 0x53,
+       TOSERVER_UPDATE_CLIENT_INFO = 0x53,
+       /*
+               v2s16 render_target_size
+               f32 gui_scaling
+               f32 hud_scaling
+               v2f32 max_fs_info
+       */
+
+       TOSERVER_NUM_MSG_TYPES = 0x54,
 };
 
 enum AuthMechanism
index cd2ff64fd478b411e98655168a918dcd1bbb1732..1165bb0656142197fb6a3b23507fb44b48484eac 100644 (file)
@@ -107,6 +107,7 @@ const ToServerCommandHandler toServerCommandTable[TOSERVER_NUM_MSG_TYPES] =
        { "TOSERVER_FIRST_SRP",                TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_FirstSrp }, // 0x50
        { "TOSERVER_SRP_BYTES_A",              TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_SrpBytesA }, // 0x51
        { "TOSERVER_SRP_BYTES_M",              TOSERVER_STATE_NOT_CONNECTED, &Server::handleCommand_SrpBytesM }, // 0x52
+       { "TOSERVER_UPDATE_CLIENT_INFO",       TOSERVER_STATE_INGAME, &Server::handleCommand_UpdateClientInfo }, // 0x53
 };
 
 const static ClientCommandFactory null_command_factory = { "TOCLIENT_NULL", 0, false };
index a5ee81a9cbefe3fac1f012b975ae801348f6c92a..89e2e2a1cd8f7bc2a61a4b85df274a7f55a6cbdb 100644 (file)
@@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/pointedthing.h"
 #include "util/serialize.h"
 #include "util/srp.h"
+#include "clientdynamicinfo.h"
 
 void Server::handleCommand_Deprecated(NetworkPacket* pkt)
 {
@@ -1841,3 +1842,18 @@ void Server::handleCommand_HaveMedia(NetworkPacket *pkt)
                }
        }
 }
+
+void Server::handleCommand_UpdateClientInfo(NetworkPacket *pkt)
+{
+       ClientDynamicInfo info;
+       *pkt >> info.render_target_size.X;
+       *pkt >> info.render_target_size.Y;
+       *pkt >> info.real_gui_scaling;
+       *pkt >> info.real_hud_scaling;
+       *pkt >> info.max_fs_size.X;
+       *pkt >> info.max_fs_size.Y;
+
+       session_t peer_id = pkt->getPeerId();
+       RemoteClient *client = getClient(peer_id, CS_Invalid);
+       client->setDynamicInfo(info);
+}
index 90b78a0810f0ad6e87037962fb583dd8ef247ecb..22aa1c5d7954fbc8b24c039dc1e41ee4c659a444 100644 (file)
@@ -128,6 +128,15 @@ void push_v2s32(lua_State *L, v2s32 p)
        lua_setfield(L, -2, "y");
 }
 
+void push_v2u32(lua_State *L, v2u32 p)
+{
+       lua_createtable(L, 0, 2);
+       lua_pushinteger(L, p.X);
+       lua_setfield(L, -2, "x");
+       lua_pushinteger(L, p.Y);
+       lua_setfield(L, -2, "y");
+}
+
 v2s32 read_v2s32(lua_State *L, int index)
 {
        v2s32 p;
index f1e4e47ec255b8e3ab48c7e7f622b2d0461a66a2..90358147ae013f60640e34806775ef737da8bf81 100644 (file)
@@ -108,6 +108,7 @@ size_t              read_stringlist     (lua_State *L, int index,
 
 void                push_v2s16          (lua_State *L, v2s16 p);
 void                push_v2s32          (lua_State *L, v2s32 p);
+void                push_v2u32          (lua_State *L, v2u32 p);
 void                push_v3s16          (lua_State *L, v3s16 p);
 void                push_aabb3f         (lua_State *L, aabb3f box);
 void                push_ARGB8          (lua_State *L, video::SColor color);
index e53ec5fedac23df31429f4ef879fdde97e5ea8e5..e19156e22502ec87fb40a350490446a7c3d47dd8 100644 (file)
@@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "network/networkprotocol.h"
 #include "content/mod_configuration.h"
 #include "threading/mutex_auto_lock.h"
+#include "common/c_converter.h"
 
 /******************************************************************************/
 std::string ModApiMainMenu::getTextData(lua_State *L, std::string name)
@@ -922,26 +923,40 @@ int ModApiMainMenu::l_gettext(lua_State *L)
 }
 
 /******************************************************************************/
-int ModApiMainMenu::l_get_screen_info(lua_State *L)
+int ModApiMainMenu::l_get_window_info(lua_State *L)
 {
        lua_newtable(L);
        int top = lua_gettop(L);
-       lua_pushstring(L,"density");
-       lua_pushnumber(L,RenderingEngine::getDisplayDensity());
-       lua_settable(L, top);
 
        const v2u32 &window_size = RenderingEngine::getWindowSize();
-       lua_pushstring(L,"window_width");
-       lua_pushnumber(L, window_size.X);
+       f32 density = RenderingEngine::getDisplayDensity();
+       f32 gui_scaling = g_settings->getFloat("gui_scaling") * density;
+       f32 hud_scaling = g_settings->getFloat("hud_scaling") * density;
+
+       lua_pushstring(L, "size");
+       push_v2u32(L, window_size);
        lua_settable(L, top);
 
-       lua_pushstring(L,"window_height");
-       lua_pushnumber(L, window_size.Y);
+       lua_pushstring(L, "max_formspec_size");
+       push_v2f(L, ClientDynamicInfo::calculateMaxFSSize(window_size));
        lua_settable(L, top);
 
-       lua_pushstring(L, "render_info");
-       lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
+       lua_pushstring(L, "real_gui_scaling");
+       lua_pushnumber(L, gui_scaling);
        lua_settable(L, top);
+
+       lua_pushstring(L, "real_hud_scaling");
+       lua_pushnumber(L, hud_scaling);
+       lua_settable(L, top);
+
+       return 1;
+}
+
+/******************************************************************************/
+
+int ModApiMainMenu::l_get_active_renderer(lua_State *L)
+{
+       lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
        return 1;
 }
 
@@ -1086,7 +1101,8 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
        API_FCT(download_file);
        API_FCT(gettext);
        API_FCT(get_video_drivers);
-       API_FCT(get_screen_info);
+       API_FCT(get_window_info);
+       API_FCT(get_active_renderer);
        API_FCT(get_min_supp_proto);
        API_FCT(get_max_supp_proto);
        API_FCT(open_url);
index a731f77a8ea5b62ecc4c06d4c940148b851db6eb..bb5c93cd599f8e401731fda384bf3b55f84d423f 100644 (file)
@@ -104,7 +104,9 @@ class ModApiMainMenu: public ModApiBase
 
        static int l_set_formspec_prepend(lua_State *L);
 
-       static int l_get_screen_info(lua_State *L);
+       static int l_get_window_info(lua_State *L);
+
+       static int l_get_active_renderer(lua_State *L);
 
        //filesystem
 
index fb2018aacce948177a07a68e4a8e9e45303a9ea6..eff2126536bb2d952e1250c513d736879575b911 100644 (file)
@@ -269,6 +269,44 @@ int ModApiServer::l_get_player_information(lua_State *L)
        return 1;
 }
 
+// get_player_window_information(name)
+int ModApiServer::l_get_player_window_information(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+
+       Server *server = getServer(L);
+
+       const char *name = luaL_checkstring(L, 1);
+       RemotePlayer *player = server->getEnv().getPlayer(name);
+       if (!player)
+               return 0;
+
+       auto dynamic = server->getClientDynamicInfo(player->getPeerId());
+
+       if (!dynamic || dynamic->render_target_size == v2u32())
+               return 0;
+
+       lua_newtable(L);
+       int dyn_table = lua_gettop(L);
+
+       lua_pushstring(L, "size");
+       push_v2u32(L, dynamic->render_target_size);
+       lua_settable(L, dyn_table);
+
+       lua_pushstring(L, "max_formspec_size");
+       push_v2f(L, dynamic->max_fs_size);
+       lua_settable(L, dyn_table);
+
+       lua_pushstring(L, "real_gui_scaling");
+       lua_pushnumber(L, dynamic->real_gui_scaling);
+       lua_settable(L, dyn_table);
+
+       lua_pushstring(L, "real_hud_scaling");
+       lua_pushnumber(L, dynamic->real_hud_scaling);
+       lua_settable(L, dyn_table);
+       return 1;
+}
+
 // get_ban_list()
 int ModApiServer::l_get_ban_list(lua_State *L)
 {
@@ -635,6 +673,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
        API_FCT(dynamic_add_media);
 
        API_FCT(get_player_information);
+       API_FCT(get_player_window_information);
        API_FCT(get_player_privs);
        API_FCT(get_player_ip);
        API_FCT(get_ban_list);
index 15d61669e58488fddc1a69f3ca608bf4935453c0..29fea7677106a2432a5c315a308fdfba5bc5a5c0 100644 (file)
@@ -88,6 +88,9 @@ class ModApiServer : public ModApiBase
        // get_player_information(name)
        static int l_get_player_information(lua_State *L);
 
+       // get_player_window_information(name)
+       static int l_get_player_window_information(lua_State *L);
+
        // get_ban_list()
        static int l_get_ban_list(lua_State *L);
 
index 3e0ce3189e32646617ceb3e567485be848c32213..9e2ea8640e456efd38db56cbad934f7354ae5413 100644 (file)
@@ -1303,6 +1303,17 @@ bool Server::getClientInfo(session_t peer_id, ClientInfo &ret)
        return true;
 }
 
+const ClientDynamicInfo *Server::getClientDynamicInfo(session_t peer_id)
+{
+       ClientInterface::AutoLock clientlock(m_clients);
+       RemoteClient *client = m_clients.lockedGetClientNoEx(peer_id, CS_Invalid);
+
+       if (!client)
+               return nullptr;
+
+       return &client->getDynamicInfo();
+}
+
 void Server::handlePeerChanges()
 {
        while(!m_peer_change_queue.empty())
index 168680694affe2a3e418f1f1f273d9182a88606a..9ce3cc24dc8bdab36d7c8ba3a5d337dc76388e8f 100644 (file)
@@ -195,6 +195,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void handleCommand_SrpBytesA(NetworkPacket* pkt);
        void handleCommand_SrpBytesM(NetworkPacket* pkt);
        void handleCommand_HaveMedia(NetworkPacket *pkt);
+       void handleCommand_UpdateClientInfo(NetworkPacket *pkt);
 
        void ProcessData(NetworkPacket *pkt);
 
@@ -341,6 +342,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,
        void DisconnectPeer(session_t peer_id);
        bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval);
        bool getClientInfo(session_t peer_id, ClientInfo &ret);
+       const ClientDynamicInfo *getClientDynamicInfo(session_t peer_id);
 
        void printToConsoleOnly(const std::string &text);