GameUI refactor (part 7/7): Finish to include profiler things to GameUI

Other changes:
* Add GameUI clarification comment
* Move force_fog_off & disable_camera_update flags from GameUI to Game, it's not UI related
* Properly init GameUI::Flags
* Move toggleChat toggleHud & toggleProfiler to GameUI
* Add gameui.cpp to LINT whitelist
master
Loic Blot 2018-01-04 23:58:46 +01:00 committed by Loïc Blot
parent 02f82eca0b
commit f40f4143df
4 changed files with 78 additions and 75 deletions

View File

@ -204,8 +204,7 @@ void GameUI::showTranslatedStatusText(const char *str)
delete[] wmsg; delete[] wmsg;
} }
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count, void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
u32 profiler_current_page)
{ {
setStaticText(m_guitext_chat, chat_text); 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 // Don't show chat if disabled or empty or profiler is enabled
m_guitext_chat->setVisible(m_flags.show_chat && 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); std::ostringstream os(std::ios_base::binary);
g_profiler->printPage(os, profiler_current_page, g_profiler->printPage(os, m_profiler_current_page, m_profiler_max_page);
profiler_max_page);
std::wstring text = translate_string(utf8_to_wide(os.str())); std::wstring text = translate_string(utf8_to_wide(os.str()));
setStaticText(m_guitext_profiler, text.c_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<s32>(upper_left, lower_right)); m_guitext_profiler->setRelativePosition(core::rect<s32>(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]; wchar_t buf[255];
const wchar_t* str = wgettext("Profiler shown (page %d of %d)"); const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str, swprintf(buf, sizeof(buf) / sizeof(wchar_t), str,
profiler_current_page, profiler_max_page); m_profiler_current_page, m_profiler_max_page);
delete[] str; delete[] str;
showStatusText(buf); showStatusText(buf);
} else { } else {

View File

@ -29,6 +29,14 @@ using namespace irr;
class Client; class Client;
struct MapDrawControl; struct MapDrawControl;
/*
* This object intend to contain the core UI elements
* It includes:
* - status texts
* - debug texts
* - chat texts
* - hud flags
*/
class GameUI class GameUI
{ {
// Temporary between coding time to move things here // Temporary between coding time to move things here
@ -44,13 +52,11 @@ public:
// Flags that can, or may, change during main game loop // Flags that can, or may, change during main game loop
struct Flags struct Flags
{ {
bool show_chat; bool show_chat = true;
bool show_hud; bool show_hud = true;
bool show_minimap; bool show_minimap = true;
bool force_fog_off; bool show_debug = true;
bool show_debug; bool show_profiler_graph = true;
bool show_profiler_graph;
bool disable_camera_update;
}; };
void init(); void init();
@ -74,15 +80,18 @@ public:
void showTranslatedStatusText(const char *str); void showTranslatedStatusText(const char *str);
inline void clearStatusText() { m_statustext.clear(); } inline void clearStatusText() { m_statustext.clear(); }
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count, void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
u32 profiler_current_page);
void updateProfiler(u32 profiler_current_page, u32 profiler_max_page); void updateProfiler();
void toggleChat();
void toggleHud();
void toggleProfiler();
private: private:
Flags m_flags; 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_guitext2 = nullptr; // Second line of debug text
gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
@ -93,5 +102,8 @@ private:
float m_statustext_time = 0.0f; float m_statustext_time = 0.0f;
gui::IGUIStaticText *m_guitext_chat; // Chat text gui::IGUIStaticText *m_guitext_chat; // Chat text
gui::IGUIStaticText *m_guitext_profiler; // Profiler text gui::IGUIStaticText *m_guitext_profiler; // Profiler text
u8 m_profiler_current_page = 0;
const u8 m_profiler_max_page = 3;
}; };

View File

@ -1065,9 +1065,6 @@ struct GameRunData {
v3f update_draw_list_last_cam_dir; v3f update_draw_list_last_cam_dir;
u32 profiler_current_page;
u32 profiler_max_page; // Number of pages
float time_of_day_smooth; float time_of_day_smooth;
}; };
@ -1158,13 +1155,10 @@ protected:
void toggleCinematic(); void toggleCinematic();
void toggleAutoforward(); void toggleAutoforward();
void toggleChat();
void toggleHud();
void toggleMinimap(bool shift_pressed); void toggleMinimap(bool shift_pressed);
void toggleFog(); void toggleFog();
void toggleDebug(); void toggleDebug();
void toggleUpdateCamera(); void toggleUpdateCamera();
void toggleProfiler();
void increaseViewRange(); void increaseViewRange();
void decreaseViewRange(); void decreaseViewRange();
@ -1256,6 +1250,11 @@ protected:
#endif #endif
private: private:
struct Flags {
bool force_fog_off = false;
bool disable_camera_update = false;
};
void showPauseMenu(); void showPauseMenu();
// ClientEvent handlers // ClientEvent handlers
@ -1315,6 +1314,7 @@ private:
Minimap *mapper = nullptr; Minimap *mapper = nullptr;
GameRunData runData; GameRunData runData;
Flags m_flags;
/* 'cache' /* 'cache'
This class does take ownership/responsibily for cleaning up etc of any of 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)); memset(&runData, 0, sizeof(runData));
runData.time_from_last_punch = 10.0; runData.time_from_last_punch = 10.0;
runData.profiler_max_page = 3;
runData.update_wielded_item_trigger = true; runData.update_wielded_item_trigger = true;
m_game_ui->initFlags(); m_game_ui->initFlags();
@ -1790,7 +1789,7 @@ bool Game::createClient(const std::string &playername,
} }
GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory( 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); shader_src->addShaderConstantSetterFactory(scsf);
// Update cached textures, meshes and materials // Update cached textures, meshes and materials
@ -2201,9 +2200,7 @@ void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
g_profiler->print(infostream); g_profiler->print(infostream);
} }
m_game_ui->updateProfiler(runData.profiler_current_page, m_game_ui->updateProfiler();
runData.profiler_max_page);
g_profiler->clear(); g_profiler->clear();
} }
@ -2377,11 +2374,11 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::SCREENSHOT)) { } else if (wasKeyDown(KeyType::SCREENSHOT)) {
client->makeScreenshot(); client->makeScreenshot();
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) { } else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
toggleHud(); m_game_ui->toggleHud();
} else if (wasKeyDown(KeyType::MINIMAP)) { } else if (wasKeyDown(KeyType::MINIMAP)) {
toggleMinimap(isKeyDown(KeyType::SNEAK)); toggleMinimap(isKeyDown(KeyType::SNEAK));
} else if (wasKeyDown(KeyType::TOGGLE_CHAT)) { } else if (wasKeyDown(KeyType::TOGGLE_CHAT)) {
toggleChat(); m_game_ui->toggleChat();
} else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) { } else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) {
toggleFog(); toggleFog();
} else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) { } else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) {
@ -2389,7 +2386,7 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) { } else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) {
toggleDebug(); toggleDebug();
} else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) { } else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) {
toggleProfiler(); m_game_ui->toggleProfiler();
} else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) { } else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) {
increaseViewRange(); increaseViewRange();
} else if (wasKeyDown(KeyType::DECREASE_VIEWING_RANGE)) { } else if (wasKeyDown(KeyType::DECREASE_VIEWING_RANGE)) {
@ -2615,25 +2612,6 @@ void Game::toggleAutoforward()
m_game_ui->showTranslatedStatusText("Automatic forwards disabled"); 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) void Game::toggleMinimap(bool shift_pressed)
{ {
if (!mapper || !m_game_ui->m_flags.show_hud || !g_settings->getBool("enable_minimap")) 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() void Game::toggleFog()
{ {
m_game_ui->m_flags.force_fog_off = !m_game_ui->m_flags.force_fog_off; m_flags.force_fog_off = !m_flags.force_fog_off;
if (m_game_ui->m_flags.force_fog_off) if (m_flags.force_fog_off)
m_game_ui->showTranslatedStatusText("Fog disabled"); m_game_ui->showTranslatedStatusText("Fog disabled");
else else
m_game_ui->showTranslatedStatusText("Fog enabled"); m_game_ui->showTranslatedStatusText("Fog enabled");
@ -2730,24 +2708,14 @@ void Game::toggleDebug()
void Game::toggleUpdateCamera() void Game::toggleUpdateCamera()
{ {
m_game_ui->m_flags.disable_camera_update = !m_game_ui->m_flags.disable_camera_update; m_flags.disable_camera_update = !m_flags.disable_camera_update;
if (m_game_ui->m_flags.disable_camera_update) if (m_flags.disable_camera_update)
m_game_ui->showTranslatedStatusText("Camera update disabled"); m_game_ui->showTranslatedStatusText("Camera update disabled");
else else
m_game_ui->showTranslatedStatusText("Camera update enabled"); 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() void Game::increaseViewRange()
{ {
s16 range = g_settings->getS16("viewing_range"); 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 if (can_be_and_is_paused) { // This is for a singleplayer server
*dtime = 0; // No time passes *dtime = 0; // No time passes
} else { } else {
if (server != NULL) { if (server) {
//TimeTaker timer("server->step(dtime)");
server->step(*dtime); server->step(*dtime);
} }
//TimeTaker timer("client.step(dtime)");
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 // Display all messages in a static text element
m_game_ui->setChatText(chat_backend->getRecentChat(), 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) 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); 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, client->getEnv().getClientMap().updateCamera(camera_position,
camera_direction, camera_fov, camera_offset); camera_direction, camera_fov, camera_offset);
@ -4033,7 +3999,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
clouds->update(camera_node_position, clouds->update(camera_node_position,
sky->getCloudColor()); sky->getCloudColor());
if (clouds->isCameraInsideCloud() && m_cache_enable_fog && 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 // if inside clouds, and fog enabled, use that as sky
// color(s) // color(s)
video::SColor clouds_dark = clouds->getColor() video::SColor clouds_dark = clouds->getColor()
@ -4058,7 +4024,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
Fog 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( driver->setFog(
sky->getBgColor(), sky->getBgColor(),
video::EFT_FOG_LINEAR, video::EFT_FOG_LINEAR,

View File

@ -21,6 +21,7 @@ src/clientobject.cpp
src/clientobject.h src/clientobject.h
src/client/clientlauncher.cpp src/client/clientlauncher.cpp
src/client/clientlauncher.h src/client/clientlauncher.h
src/client/gameui.cpp
src/client/joystick_controller.cpp src/client/joystick_controller.cpp
src/client/joystick_controller.h src/client/joystick_controller.h
src/client/renderingengine.cpp src/client/renderingengine.cpp