aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2021-09-19 20:23:35 +0200
committerGitHub <noreply@github.com>2021-09-19 20:23:35 +0200
commite79d6154fc26b2a9bac242f0ac01ec785b5c53b1 (patch)
treeeb4587e1a83696f4e9d08531856a7170d019ae65 /src/client
parent40ea4ddef1fe56dab9a1479302f0b2578b4b0ed5 (diff)
downloadminetest-e79d6154fc26b2a9bac242f0ac01ec785b5c53b1.tar.gz
minetest-e79d6154fc26b2a9bac242f0ac01ec785b5c53b1.tar.bz2
minetest-e79d6154fc26b2a9bac242f0ac01ec785b5c53b1.zip
Fix client-side performance of chat UI (#11612)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/game.cpp20
-rw-r--r--src/client/gameui.cpp18
-rw-r--r--src/client/gameui.h2
3 files changed, 27 insertions, 13 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index a24ded844..6eb09adfa 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -804,7 +804,7 @@ private:
CameraOrientation *cam);
void handleClientEvent_CloudParams(ClientEvent *event, CameraOrientation *cam);
- void updateChat(f32 dtime, const v2u32 &screensize);
+ void updateChat(f32 dtime);
bool nodePlacement(const ItemDefinition &selected_def, const ItemStack &selected_item,
const v3s16 &nodepos, const v3s16 &neighbourpos, const PointedThing &pointed,
@@ -2922,7 +2922,7 @@ void Game::processClientEvents(CameraOrientation *cam)
}
}
-void Game::updateChat(f32 dtime, const v2u32 &screensize)
+void Game::updateChat(f32 dtime)
{
// Get new messages from error log buffer
while (!m_chat_log_buf.empty())
@@ -2938,8 +2938,14 @@ void Game::updateChat(f32 dtime, const v2u32 &screensize)
chat_backend->step(dtime);
// Display all messages in a static text element
- m_game_ui->setChatText(chat_backend->getRecentChat(),
- chat_backend->getRecentBuffer().getLineCount());
+ auto &buf = chat_backend->getRecentBuffer();
+ if (buf.getLinesModified()) {
+ buf.resetLinesModified();
+ m_game_ui->setChatText(chat_backend->getRecentChat(), buf.getLineCount());
+ }
+
+ // Make sure that the size is still correct
+ m_game_ui->updateChatSize();
}
void Game::updateCamera(u32 busy_time, f32 dtime)
@@ -3861,9 +3867,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
Get chat messages from client
*/
- v2u32 screensize = driver->getScreenSize();
-
- updateChat(dtime, screensize);
+ updateChat(dtime);
/*
Inventory
@@ -3957,6 +3961,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
/*
Profiler graph
*/
+ v2u32 screensize = driver->getScreenSize();
+
if (m_game_ui->m_flags.show_profiler_graph)
graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont());
diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp
index 9b77cf6ff..ecb8e0ec4 100644
--- a/src/client/gameui.cpp
+++ b/src/client/gameui.cpp
@@ -227,7 +227,13 @@ void GameUI::showTranslatedStatusText(const char *str)
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
{
+ setStaticText(m_guitext_chat, chat_text);
+ m_recent_chat_count = recent_chat_count;
+}
+
+void GameUI::updateChatSize()
+{
// Update gui element size and position
s32 chat_y = 5;
@@ -238,15 +244,15 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
const v2u32 &window_size = RenderingEngine::getWindowSize();
- core::rect<s32> chat_size(10, chat_y,
- window_size.X - 20, 0);
+ core::rect<s32> chat_size(10, chat_y, window_size.X - 20, 0);
chat_size.LowerRightCorner.Y = std::min((s32)window_size.Y,
- m_guitext_chat->getTextHeight() + chat_y);
+ m_guitext_chat->getTextHeight() + chat_y);
- m_guitext_chat->setRelativePosition(chat_size);
- setStaticText(m_guitext_chat, chat_text);
+ if (chat_size == m_current_chat_size)
+ return;
+ m_current_chat_size = chat_size;
- m_recent_chat_count = recent_chat_count;
+ m_guitext_chat->setRelativePosition(chat_size);
}
void GameUI::updateProfiler()
diff --git a/src/client/gameui.h b/src/client/gameui.h
index cb460b1c3..2eb2488e6 100644
--- a/src/client/gameui.h
+++ b/src/client/gameui.h
@@ -89,6 +89,7 @@ public:
return m_flags.show_chat && m_recent_chat_count != 0 && m_profiler_current_page == 0;
}
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
+ void updateChatSize();
void updateProfiler();
@@ -122,6 +123,7 @@ private:
gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
u32 m_recent_chat_count = 0;
+ core::rect<s32> m_current_chat_size{0, 0, 0, 0};
gui::IGUIStaticText *m_guitext_profiler = nullptr; // Profiler text
u8 m_profiler_current_page = 0;