From 3a772e7ed6c02f91de57320b1694c7d11e1c7618 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 3 Jan 2018 17:28:57 +0100 Subject: GameUI refactor (part 2/X): Move Game::guitext to GameUI + enhancements on StaticText Other enhancements: * C++ friendlyness for addStaticText() -> move to static StaticText::add() --- src/game.cpp | 60 +++++++----------------------------------------------------- 1 file changed, 7 insertions(+), 53 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index f1ee9f8e2..d31daf32b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1174,16 +1174,6 @@ struct GameRunData { float time_of_day_smooth; }; -struct Jitter { - f32 max, min, avg, counter, max_sample, min_sample, max_fraction; -}; - -struct RunStats { - u32 drawtime; - - Jitter dtime_jitter, busy_time_jitter; -}; - class Game; struct ClientEventHandler @@ -1452,7 +1442,6 @@ private: /* GUI stuff */ - gui::IGUIStaticText *guitext; // First line of debug text gui::IGUIStaticText *guitext2; // Second line of debug text gui::IGUIStaticText *guitext_info; // At the middle of the screen gui::IGUIStaticText *guitext_status; @@ -1998,34 +1987,30 @@ bool Game::createClient(const std::string &playername, bool Game::initGui() { - // First line of debug text - guitext = addStaticText(guienv, - utf8_to_wide(PROJECT_NAME_C).c_str(), - core::rect(0, 0, 0, 0), - false, false, guiroot); + m_game_ui->init(); // Second line of debug text - guitext2 = addStaticText(guienv, + guitext2 = gui::StaticText::add(guienv, L"", core::rect(0, 0, 0, 0), false, false, guiroot); // At the middle of the screen // Object infos are shown in this - guitext_info = addStaticText(guienv, + guitext_info = gui::StaticText::add(guienv, L"", core::rect(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5) + v2s32(100, 200), false, true, guiroot); // Status text (displays info when showing and hiding GUI stuff, etc.) - guitext_status = addStaticText(guienv, + guitext_status = gui::StaticText::add(guienv, L"", core::rect(0, 0, 0, 0), false, false, guiroot); guitext_status->setVisible(false); // Chat text - guitext_chat = addStaticText( + guitext_chat = gui::StaticText::add( guienv, L"", core::rect(0, 0, 0, 0), @@ -2048,7 +2033,7 @@ bool Game::initGui() } // Profiler text (size is updated when text is updated) - guitext_profiler = addStaticText(guienv, + guitext_profiler = gui::StaticText::add(guienv, L"", core::rect(0, 0, 0, 0), false, false, guiroot); @@ -4410,38 +4395,7 @@ void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation & LocalPlayer *player = client->getEnv().getLocalPlayer(); v3f player_position = player->getPosition(); - if (m_game_ui->m_flags.show_debug) { - static float drawtime_avg = 0; - drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05; - u16 fps = 1.0 / stats.dtime_jitter.avg; - - std::ostringstream os(std::ios_base::binary); - os << std::fixed - << PROJECT_NAME_C " " << g_version_hash - << ", FPS: " << fps - << std::setprecision(0) - << ", drawtime: " << drawtime_avg << "ms" - << std::setprecision(1) - << ", dtime jitter: " - << (stats.dtime_jitter.max_fraction * 100.0) << "%" - << std::setprecision(1) - << ", view range: " - << (draw_control->range_all ? "All" : itos(draw_control->wanted_range)) - << std::setprecision(3) - << ", RTT: " << client->getRTT() << "s"; - setStaticText(guitext, utf8_to_wide(os.str()).c_str()); - guitext->setVisible(true); - } else { - guitext->setVisible(false); - } - - if (guitext->isVisible()) { - core::rect rect( - 5, 5, - screensize.X, 5 + g_fontengine->getTextHeight() - ); - guitext->setRelativePosition(rect); - } + m_game_ui->update(stats, client, draw_control); if (m_game_ui->m_flags.show_debug) { std::ostringstream os(std::ios_base::binary); -- cgit v1.2.3