diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 924336165..6f6d2c2a8 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -204,8 +204,7 @@ void GameUI::showTranslatedStatusText(const char *str) delete[] wmsg; } -void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, - u32 profiler_current_page) +void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) { setStaticText(m_guitext_chat, chat_text); @@ -228,15 +227,14 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, // Don't show chat if disabled or empty or profiler is enabled m_guitext_chat->setVisible(m_flags.show_chat && - recent_chat_count != 0 && profiler_current_page == 0); + recent_chat_count != 0 && m_profiler_current_page == 0); } -void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page) +void GameUI::updateProfiler() { - if (profiler_current_page != 0) { + if (m_profiler_current_page != 0) { std::ostringstream os(std::ios_base::binary); - g_profiler->printPage(os, profiler_current_page, - profiler_max_page); + g_profiler->printPage(os, m_profiler_current_page, m_profiler_max_page); std::wstring text = translate_string(utf8_to_wide(os.str())); setStaticText(m_guitext_profiler, text.c_str()); @@ -263,13 +261,39 @@ void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page) m_guitext_profiler->setRelativePosition(core::rect(upper_left, lower_right)); } - m_guitext_profiler->setVisible(profiler_current_page != 0); + m_guitext_profiler->setVisible(m_profiler_current_page != 0); +} - if (profiler_current_page != 0) { +void GameUI::toggleChat() +{ + m_flags.show_chat = !m_flags.show_chat; + if (m_flags.show_chat) + showTranslatedStatusText("Chat shown"); + else + showTranslatedStatusText("Chat hidden"); +} + +void GameUI::toggleHud() +{ + m_flags.show_hud = !m_flags.show_hud; + if (m_flags.show_hud) + showTranslatedStatusText("HUD shown"); + else + showTranslatedStatusText("HUD hidden"); +} + +void GameUI::toggleProfiler() +{ + m_profiler_current_page = (m_profiler_current_page + 1) % (m_profiler_max_page + 1); + + // FIXME: This updates the profiler with incomplete values + updateProfiler(); + + if (m_profiler_current_page != 0) { wchar_t buf[255]; const wchar_t* str = wgettext("Profiler shown (page %d of %d)"); swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, - profiler_current_page, profiler_max_page); + m_profiler_current_page, m_profiler_max_page); delete[] str; showStatusText(buf); } else { diff --git a/src/client/gameui.h b/src/client/gameui.h index b090f5cb0..ebb7842c4 100644 --- a/src/client/gameui.h +++ b/src/client/gameui.h @@ -29,6 +29,14 @@ using namespace irr; class Client; struct MapDrawControl; +/* + * This object intend to contain the core UI elements + * It includes: + * - status texts + * - debug texts + * - chat texts + * - hud flags + */ class GameUI { // Temporary between coding time to move things here @@ -44,13 +52,11 @@ public: // Flags that can, or may, change during main game loop struct Flags { - bool show_chat; - bool show_hud; - bool show_minimap; - bool force_fog_off; - bool show_debug; - bool show_profiler_graph; - bool disable_camera_update; + bool show_chat = true; + bool show_hud = true; + bool show_minimap = true; + bool show_debug = true; + bool show_profiler_graph = true; }; void init(); @@ -74,15 +80,18 @@ public: void showTranslatedStatusText(const char *str); inline void clearStatusText() { m_statustext.clear(); } - void setChatText(const EnrichedString &chat_text, u32 recent_chat_count, - u32 profiler_current_page); + void setChatText(const EnrichedString &chat_text, u32 recent_chat_count); - void updateProfiler(u32 profiler_current_page, u32 profiler_max_page); + void updateProfiler(); + + void toggleChat(); + void toggleHud(); + void toggleProfiler(); private: Flags m_flags; - gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text + gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen @@ -93,5 +102,8 @@ private: float m_statustext_time = 0.0f; gui::IGUIStaticText *m_guitext_chat; // Chat text + gui::IGUIStaticText *m_guitext_profiler; // Profiler text + u8 m_profiler_current_page = 0; + const u8 m_profiler_max_page = 3; }; diff --git a/src/game.cpp b/src/game.cpp index 593fe8439..924ca8c47 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1065,9 +1065,6 @@ struct GameRunData { v3f update_draw_list_last_cam_dir; - u32 profiler_current_page; - u32 profiler_max_page; // Number of pages - float time_of_day_smooth; }; @@ -1158,13 +1155,10 @@ protected: void toggleCinematic(); void toggleAutoforward(); - void toggleChat(); - void toggleHud(); void toggleMinimap(bool shift_pressed); void toggleFog(); void toggleDebug(); void toggleUpdateCamera(); - void toggleProfiler(); void increaseViewRange(); void decreaseViewRange(); @@ -1256,6 +1250,11 @@ protected: #endif private: + struct Flags { + bool force_fog_off = false; + bool disable_camera_update = false; + }; + void showPauseMenu(); // ClientEvent handlers @@ -1315,6 +1314,7 @@ private: Minimap *mapper = nullptr; GameRunData runData; + Flags m_flags; /* 'cache' This class does take ownership/responsibily for cleaning up etc of any of @@ -1496,7 +1496,6 @@ bool Game::startup(bool *kill, memset(&runData, 0, sizeof(runData)); runData.time_from_last_punch = 10.0; - runData.profiler_max_page = 3; runData.update_wielded_item_trigger = true; m_game_ui->initFlags(); @@ -1790,7 +1789,7 @@ bool Game::createClient(const std::string &playername, } GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory( - &m_game_ui->m_flags.force_fog_off, &runData.fog_range, client); + &m_flags.force_fog_off, &runData.fog_range, client); shader_src->addShaderConstantSetterFactory(scsf); // Update cached textures, meshes and materials @@ -2201,9 +2200,7 @@ void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times, g_profiler->print(infostream); } - m_game_ui->updateProfiler(runData.profiler_current_page, - runData.profiler_max_page); - + m_game_ui->updateProfiler(); g_profiler->clear(); } @@ -2377,11 +2374,11 @@ void Game::processKeyInput() } else if (wasKeyDown(KeyType::SCREENSHOT)) { client->makeScreenshot(); } else if (wasKeyDown(KeyType::TOGGLE_HUD)) { - toggleHud(); + m_game_ui->toggleHud(); } else if (wasKeyDown(KeyType::MINIMAP)) { toggleMinimap(isKeyDown(KeyType::SNEAK)); } else if (wasKeyDown(KeyType::TOGGLE_CHAT)) { - toggleChat(); + m_game_ui->toggleChat(); } else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) { toggleFog(); } else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) { @@ -2389,7 +2386,7 @@ void Game::processKeyInput() } else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) { toggleDebug(); } else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) { - toggleProfiler(); + m_game_ui->toggleProfiler(); } else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) { increaseViewRange(); } else if (wasKeyDown(KeyType::DECREASE_VIEWING_RANGE)) { @@ -2615,25 +2612,6 @@ void Game::toggleAutoforward() m_game_ui->showTranslatedStatusText("Automatic forwards disabled"); } -void Game::toggleChat() -{ - m_game_ui->m_flags.show_chat = !m_game_ui->m_flags.show_chat; - if (m_game_ui->m_flags.show_chat) - m_game_ui->showTranslatedStatusText("Chat shown"); - else - m_game_ui->showTranslatedStatusText("Chat hidden"); -} - - -void Game::toggleHud() -{ - m_game_ui->m_flags.show_hud = !m_game_ui->m_flags.show_hud; - if (m_game_ui->m_flags.show_hud) - m_game_ui->showTranslatedStatusText("HUD shown"); - else - m_game_ui->showTranslatedStatusText("HUD hidden"); -} - void Game::toggleMinimap(bool shift_pressed) { if (!mapper || !m_game_ui->m_flags.show_hud || !g_settings->getBool("enable_minimap")) @@ -2689,8 +2667,8 @@ void Game::toggleMinimap(bool shift_pressed) void Game::toggleFog() { - m_game_ui->m_flags.force_fog_off = !m_game_ui->m_flags.force_fog_off; - if (m_game_ui->m_flags.force_fog_off) + m_flags.force_fog_off = !m_flags.force_fog_off; + if (m_flags.force_fog_off) m_game_ui->showTranslatedStatusText("Fog disabled"); else m_game_ui->showTranslatedStatusText("Fog enabled"); @@ -2730,24 +2708,14 @@ void Game::toggleDebug() void Game::toggleUpdateCamera() { - m_game_ui->m_flags.disable_camera_update = !m_game_ui->m_flags.disable_camera_update; - if (m_game_ui->m_flags.disable_camera_update) + m_flags.disable_camera_update = !m_flags.disable_camera_update; + if (m_flags.disable_camera_update) m_game_ui->showTranslatedStatusText("Camera update disabled"); else m_game_ui->showTranslatedStatusText("Camera update enabled"); } -void Game::toggleProfiler() -{ - runData.profiler_current_page = - (runData.profiler_current_page + 1) % (runData.profiler_max_page + 1); - - // FIXME: This updates the profiler with incomplete values - m_game_ui->updateProfiler(runData.profiler_current_page, runData.profiler_max_page); -} - - void Game::increaseViewRange() { s16 range = g_settings->getS16("viewing_range"); @@ -2944,12 +2912,10 @@ inline void Game::step(f32 *dtime) if (can_be_and_is_paused) { // This is for a singleplayer server *dtime = 0; // No time passes } else { - if (server != NULL) { - //TimeTaker timer("server->step(dtime)"); + if (server) { server->step(*dtime); } - //TimeTaker timer("client.step(dtime)"); client->step(*dtime); } } @@ -3276,7 +3242,7 @@ void Game::updateChat(f32 dtime, const v2u32 &screensize) // Display all messages in a static text element m_game_ui->setChatText(chat_backend->getRecentChat(), - chat_backend->getRecentBuffer().getLineCount(), runData.profiler_current_page); + chat_backend->getRecentBuffer().getLineCount()); } void Game::updateCamera(u32 busy_time, f32 dtime) @@ -3336,7 +3302,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime) m_camera_offset_changed = (camera_offset != old_camera_offset); - if (!m_game_ui->m_flags.disable_camera_update) { + if (!m_flags.disable_camera_update) { client->getEnv().getClientMap().updateCamera(camera_position, camera_direction, camera_fov, camera_offset); @@ -4033,7 +3999,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, clouds->update(camera_node_position, sky->getCloudColor()); if (clouds->isCameraInsideCloud() && m_cache_enable_fog && - !m_game_ui->m_flags.force_fog_off) { + !m_flags.force_fog_off) { // if inside clouds, and fog enabled, use that as sky // color(s) video::SColor clouds_dark = clouds->getColor() @@ -4058,7 +4024,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, Fog */ - if (m_cache_enable_fog && !m_game_ui->m_flags.force_fog_off) { + if (m_cache_enable_fog && !m_flags.force_fog_off) { driver->setFog( sky->getBgColor(), video::EFT_FOG_LINEAR, diff --git a/util/travis/clang-format-whitelist.txt b/util/travis/clang-format-whitelist.txt index 3ff4142b6..95a61fc28 100644 --- a/util/travis/clang-format-whitelist.txt +++ b/util/travis/clang-format-whitelist.txt @@ -21,6 +21,7 @@ src/clientobject.cpp src/clientobject.h src/client/clientlauncher.cpp src/client/clientlauncher.h +src/client/gameui.cpp src/client/joystick_controller.cpp src/client/joystick_controller.h src/client/renderingengine.cpp