Skip to content

Commit f40f414

Browse files
committedJan 5, 2018
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
1 parent 02f82ec commit f40f414

File tree

4 files changed

+78
-75
lines changed

4 files changed

+78
-75
lines changed
 

‎src/client/gameui.cpp

+34-10
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ void GameUI::showTranslatedStatusText(const char *str)
204204
delete[] wmsg;
205205
}
206206

207-
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
208-
u32 profiler_current_page)
207+
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
209208
{
210209
setStaticText(m_guitext_chat, chat_text);
211210

@@ -228,15 +227,14 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
228227

229228
// Don't show chat if disabled or empty or profiler is enabled
230229
m_guitext_chat->setVisible(m_flags.show_chat &&
231-
recent_chat_count != 0 && profiler_current_page == 0);
230+
recent_chat_count != 0 && m_profiler_current_page == 0);
232231
}
233232

234-
void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page)
233+
void GameUI::updateProfiler()
235234
{
236-
if (profiler_current_page != 0) {
235+
if (m_profiler_current_page != 0) {
237236
std::ostringstream os(std::ios_base::binary);
238-
g_profiler->printPage(os, profiler_current_page,
239-
profiler_max_page);
237+
g_profiler->printPage(os, m_profiler_current_page, m_profiler_max_page);
240238

241239
std::wstring text = translate_string(utf8_to_wide(os.str()));
242240
setStaticText(m_guitext_profiler, text.c_str());
@@ -263,13 +261,39 @@ void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page)
263261
m_guitext_profiler->setRelativePosition(core::rect<s32>(upper_left, lower_right));
264262
}
265263

266-
m_guitext_profiler->setVisible(profiler_current_page != 0);
264+
m_guitext_profiler->setVisible(m_profiler_current_page != 0);
265+
}
266+
267+
void GameUI::toggleChat()
268+
{
269+
m_flags.show_chat = !m_flags.show_chat;
270+
if (m_flags.show_chat)
271+
showTranslatedStatusText("Chat shown");
272+
else
273+
showTranslatedStatusText("Chat hidden");
274+
}
275+
276+
void GameUI::toggleHud()
277+
{
278+
m_flags.show_hud = !m_flags.show_hud;
279+
if (m_flags.show_hud)
280+
showTranslatedStatusText("HUD shown");
281+
else
282+
showTranslatedStatusText("HUD hidden");
283+
}
284+
285+
void GameUI::toggleProfiler()
286+
{
287+
m_profiler_current_page = (m_profiler_current_page + 1) % (m_profiler_max_page + 1);
288+
289+
// FIXME: This updates the profiler with incomplete values
290+
updateProfiler();
267291

268-
if (profiler_current_page != 0) {
292+
if (m_profiler_current_page != 0) {
269293
wchar_t buf[255];
270294
const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
271295
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str,
272-
profiler_current_page, profiler_max_page);
296+
m_profiler_current_page, m_profiler_max_page);
273297
delete[] str;
274298
showStatusText(buf);
275299
} else {

‎src/client/gameui.h

+23-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ using namespace irr;
2929
class Client;
3030
struct MapDrawControl;
3131

32+
/*
33+
* This object intend to contain the core UI elements
34+
* It includes:
35+
* - status texts
36+
* - debug texts
37+
* - chat texts
38+
* - hud flags
39+
*/
3240
class GameUI
3341
{
3442
// Temporary between coding time to move things here
@@ -44,13 +52,11 @@ class GameUI
4452
// Flags that can, or may, change during main game loop
4553
struct Flags
4654
{
47-
bool show_chat;
48-
bool show_hud;
49-
bool show_minimap;
50-
bool force_fog_off;
51-
bool show_debug;
52-
bool show_profiler_graph;
53-
bool disable_camera_update;
55+
bool show_chat = true;
56+
bool show_hud = true;
57+
bool show_minimap = true;
58+
bool show_debug = true;
59+
bool show_profiler_graph = true;
5460
};
5561

5662
void init();
@@ -74,15 +80,18 @@ class GameUI
7480
void showTranslatedStatusText(const char *str);
7581
inline void clearStatusText() { m_statustext.clear(); }
7682

77-
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
78-
u32 profiler_current_page);
83+
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
84+
85+
void updateProfiler();
7986

80-
void updateProfiler(u32 profiler_current_page, u32 profiler_max_page);
87+
void toggleChat();
88+
void toggleHud();
89+
void toggleProfiler();
8190

8291
private:
8392
Flags m_flags;
8493

85-
gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
94+
gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
8695
gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
8796

8897
gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
@@ -93,5 +102,8 @@ class GameUI
93102
float m_statustext_time = 0.0f;
94103

95104
gui::IGUIStaticText *m_guitext_chat; // Chat text
105+
96106
gui::IGUIStaticText *m_guitext_profiler; // Profiler text
107+
u8 m_profiler_current_page = 0;
108+
const u8 m_profiler_max_page = 3;
97109
};

‎src/game.cpp

+20-54
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,6 @@ struct GameRunData {
10651065

10661066
v3f update_draw_list_last_cam_dir;
10671067

1068-
u32 profiler_current_page;
1069-
u32 profiler_max_page; // Number of pages
1070-
10711068
float time_of_day_smooth;
10721069
};
10731070

@@ -1158,13 +1155,10 @@ class Game {
11581155
void toggleCinematic();
11591156
void toggleAutoforward();
11601157

1161-
void toggleChat();
1162-
void toggleHud();
11631158
void toggleMinimap(bool shift_pressed);
11641159
void toggleFog();
11651160
void toggleDebug();
11661161
void toggleUpdateCamera();
1167-
void toggleProfiler();
11681162

11691163
void increaseViewRange();
11701164
void decreaseViewRange();
@@ -1256,6 +1250,11 @@ class Game {
12561250
#endif
12571251

12581252
private:
1253+
struct Flags {
1254+
bool force_fog_off = false;
1255+
bool disable_camera_update = false;
1256+
};
1257+
12591258
void showPauseMenu();
12601259

12611260
// ClientEvent handlers
@@ -1315,6 +1314,7 @@ class Game {
13151314
Minimap *mapper = nullptr;
13161315

13171316
GameRunData runData;
1317+
Flags m_flags;
13181318

13191319
/* 'cache'
13201320
This class does take ownership/responsibily for cleaning up etc of any of
@@ -1496,7 +1496,6 @@ bool Game::startup(bool *kill,
14961496

14971497
memset(&runData, 0, sizeof(runData));
14981498
runData.time_from_last_punch = 10.0;
1499-
runData.profiler_max_page = 3;
15001499
runData.update_wielded_item_trigger = true;
15011500

15021501
m_game_ui->initFlags();
@@ -1790,7 +1789,7 @@ bool Game::createClient(const std::string &playername,
17901789
}
17911790

17921791
GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory(
1793-
&m_game_ui->m_flags.force_fog_off, &runData.fog_range, client);
1792+
&m_flags.force_fog_off, &runData.fog_range, client);
17941793
shader_src->addShaderConstantSetterFactory(scsf);
17951794

17961795
// Update cached textures, meshes and materials
@@ -2201,9 +2200,7 @@ void Game::updateProfilers(const RunStats &stats, const FpsControl &draw_times,
22012200
g_profiler->print(infostream);
22022201
}
22032202

2204-
m_game_ui->updateProfiler(runData.profiler_current_page,
2205-
runData.profiler_max_page);
2206-
2203+
m_game_ui->updateProfiler();
22072204
g_profiler->clear();
22082205
}
22092206

@@ -2377,19 +2374,19 @@ void Game::processKeyInput()
23772374
} else if (wasKeyDown(KeyType::SCREENSHOT)) {
23782375
client->makeScreenshot();
23792376
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
2380-
toggleHud();
2377+
m_game_ui->toggleHud();
23812378
} else if (wasKeyDown(KeyType::MINIMAP)) {
23822379
toggleMinimap(isKeyDown(KeyType::SNEAK));
23832380
} else if (wasKeyDown(KeyType::TOGGLE_CHAT)) {
2384-
toggleChat();
2381+
m_game_ui->toggleChat();
23852382
} else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) {
23862383
toggleFog();
23872384
} else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) {
23882385
toggleUpdateCamera();
23892386
} else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) {
23902387
toggleDebug();
23912388
} else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) {
2392-
toggleProfiler();
2389+
m_game_ui->toggleProfiler();
23932390
} else if (wasKeyDown(KeyType::INCREASE_VIEWING_RANGE)) {
23942391
increaseViewRange();
23952392
} else if (wasKeyDown(KeyType::DECREASE_VIEWING_RANGE)) {
@@ -2615,25 +2612,6 @@ void Game::toggleAutoforward()
26152612
m_game_ui->showTranslatedStatusText("Automatic forwards disabled");
26162613
}
26172614

2618-
void Game::toggleChat()
2619-
{
2620-
m_game_ui->m_flags.show_chat = !m_game_ui->m_flags.show_chat;
2621-
if (m_game_ui->m_flags.show_chat)
2622-
m_game_ui->showTranslatedStatusText("Chat shown");
2623-
else
2624-
m_game_ui->showTranslatedStatusText("Chat hidden");
2625-
}
2626-
2627-
2628-
void Game::toggleHud()
2629-
{
2630-
m_game_ui->m_flags.show_hud = !m_game_ui->m_flags.show_hud;
2631-
if (m_game_ui->m_flags.show_hud)
2632-
m_game_ui->showTranslatedStatusText("HUD shown");
2633-
else
2634-
m_game_ui->showTranslatedStatusText("HUD hidden");
2635-
}
2636-
26372615
void Game::toggleMinimap(bool shift_pressed)
26382616
{
26392617
if (!mapper || !m_game_ui->m_flags.show_hud || !g_settings->getBool("enable_minimap"))
@@ -2689,8 +2667,8 @@ void Game::toggleMinimap(bool shift_pressed)
26892667

26902668
void Game::toggleFog()
26912669
{
2692-
m_game_ui->m_flags.force_fog_off = !m_game_ui->m_flags.force_fog_off;
2693-
if (m_game_ui->m_flags.force_fog_off)
2670+
m_flags.force_fog_off = !m_flags.force_fog_off;
2671+
if (m_flags.force_fog_off)
26942672
m_game_ui->showTranslatedStatusText("Fog disabled");
26952673
else
26962674
m_game_ui->showTranslatedStatusText("Fog enabled");
@@ -2730,24 +2708,14 @@ void Game::toggleDebug()
27302708

27312709
void Game::toggleUpdateCamera()
27322710
{
2733-
m_game_ui->m_flags.disable_camera_update = !m_game_ui->m_flags.disable_camera_update;
2734-
if (m_game_ui->m_flags.disable_camera_update)
2711+
m_flags.disable_camera_update = !m_flags.disable_camera_update;
2712+
if (m_flags.disable_camera_update)
27352713
m_game_ui->showTranslatedStatusText("Camera update disabled");
27362714
else
27372715
m_game_ui->showTranslatedStatusText("Camera update enabled");
27382716
}
27392717

27402718

2741-
void Game::toggleProfiler()
2742-
{
2743-
runData.profiler_current_page =
2744-
(runData.profiler_current_page + 1) % (runData.profiler_max_page + 1);
2745-
2746-
// FIXME: This updates the profiler with incomplete values
2747-
m_game_ui->updateProfiler(runData.profiler_current_page, runData.profiler_max_page);
2748-
}
2749-
2750-
27512719
void Game::increaseViewRange()
27522720
{
27532721
s16 range = g_settings->getS16("viewing_range");
@@ -2944,12 +2912,10 @@ inline void Game::step(f32 *dtime)
29442912
if (can_be_and_is_paused) { // This is for a singleplayer server
29452913
*dtime = 0; // No time passes
29462914
} else {
2947-
if (server != NULL) {
2948-
//TimeTaker timer("server->step(dtime)");
2915+
if (server) {
29492916
server->step(*dtime);
29502917
}
29512918

2952-
//TimeTaker timer("client.step(dtime)");
29532919
client->step(*dtime);
29542920
}
29552921
}
@@ -3276,7 +3242,7 @@ void Game::updateChat(f32 dtime, const v2u32 &screensize)
32763242

32773243
// Display all messages in a static text element
32783244
m_game_ui->setChatText(chat_backend->getRecentChat(),
3279-
chat_backend->getRecentBuffer().getLineCount(), runData.profiler_current_page);
3245+
chat_backend->getRecentBuffer().getLineCount());
32803246
}
32813247

32823248
void Game::updateCamera(u32 busy_time, f32 dtime)
@@ -3336,7 +3302,7 @@ void Game::updateCamera(u32 busy_time, f32 dtime)
33363302

33373303
m_camera_offset_changed = (camera_offset != old_camera_offset);
33383304

3339-
if (!m_game_ui->m_flags.disable_camera_update) {
3305+
if (!m_flags.disable_camera_update) {
33403306
client->getEnv().getClientMap().updateCamera(camera_position,
33413307
camera_direction, camera_fov, camera_offset);
33423308

@@ -4033,7 +3999,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
40333999
clouds->update(camera_node_position,
40344000
sky->getCloudColor());
40354001
if (clouds->isCameraInsideCloud() && m_cache_enable_fog &&
4036-
!m_game_ui->m_flags.force_fog_off) {
4002+
!m_flags.force_fog_off) {
40374003
// if inside clouds, and fog enabled, use that as sky
40384004
// color(s)
40394005
video::SColor clouds_dark = clouds->getColor()
@@ -4058,7 +4024,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
40584024
Fog
40594025
*/
40604026

4061-
if (m_cache_enable_fog && !m_game_ui->m_flags.force_fog_off) {
4027+
if (m_cache_enable_fog && !m_flags.force_fog_off) {
40624028
driver->setFog(
40634029
sky->getBgColor(),
40644030
video::EFT_FOG_LINEAR,

‎util/travis/clang-format-whitelist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ src/clientobject.cpp
2121
src/clientobject.h
2222
src/client/clientlauncher.cpp
2323
src/client/clientlauncher.h
24+
src/client/gameui.cpp
2425
src/client/joystick_controller.cpp
2526
src/client/joystick_controller.h
2627
src/client/renderingengine.cpp

0 commit comments

Comments
 (0)
Please sign in to comment.