mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add minetest.get_player_window_information() (#12367)
This commit is contained in:
parent
fbbdae93ee
commit
39f4d26177
23 changed files with 345 additions and 35 deletions
|
@ -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 @@ private:
|
|||
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> ¤t_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 ¤t_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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue