Skip to content

Commit 0ebaed4

Browse files
committedJan 5, 2018
GameUI refactor (part 1/X): GameUI object creation + GameUIFlags move to GameUI
Game class is too huge and has too specialization on various subjects, like UI, formspecs, client, renderer. Start to move UI related things to GameUI object and cleanup them Other improvements: * updateChat: more performance on error messages by remove string copies * Initialize all game class members in definition instead of constructor (with nullptr instead of NULL) * Drop unused Client::show{GameChat,GameHud,Profiler,GameFog} * Add GameUI unittests
1 parent 549cfd9 commit 0ebaed4

File tree

9 files changed

+229
-131
lines changed

9 files changed

+229
-131
lines changed
 

‎src/client.cpp

+4-28
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2828
#include "network/networkpacket.h"
2929
#include "threading/mutex_auto_lock.h"
3030
#include "client/clientevent.h"
31+
#include "client/gameui.h"
3132
#include "client/renderingengine.h"
3233
#include "client/tile.h"
3334
#include "util/auth.h"
@@ -74,7 +75,7 @@ Client::Client(
7475
ISoundManager *sound,
7576
MtEventManager *event,
7677
bool ipv6,
77-
GameUIFlags *game_ui_flags
78+
GameUI *game_ui
7879
):
7980
m_tsrc(tsrc),
8081
m_shsrc(shsrc),
@@ -96,7 +97,7 @@ Client::Client(
9697
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
9798
m_media_downloader(new ClientMediaDownloader()),
9899
m_state(LC_Created),
99-
m_game_ui_flags(game_ui_flags),
100+
m_game_ui(game_ui),
100101
m_modchannel_mgr(new ModChannelMgr())
101102
{
102103
// Add local player
@@ -1771,34 +1772,9 @@ void Client::pushToEventQueue(ClientEvent *event)
17711772
m_client_event_queue.push(event);
17721773
}
17731774

1774-
void Client::showGameChat(const bool show)
1775-
{
1776-
m_game_ui_flags->show_chat = show;
1777-
}
1778-
1779-
void Client::showGameHud(const bool show)
1780-
{
1781-
m_game_ui_flags->show_hud = show;
1782-
}
1783-
17841775
void Client::showMinimap(const bool show)
17851776
{
1786-
m_game_ui_flags->show_minimap = show;
1787-
}
1788-
1789-
void Client::showProfiler(const bool show)
1790-
{
1791-
m_game_ui_flags->show_profiler_graph = show;
1792-
}
1793-
1794-
void Client::showGameFog(const bool show)
1795-
{
1796-
m_game_ui_flags->force_fog_off = !show;
1797-
}
1798-
1799-
void Client::showGameDebug(const bool show)
1800-
{
1801-
m_game_ui_flags->show_debug = show;
1777+
m_game_ui->showMinimap(show);
18021778
}
18031779

18041780
// IGameDef interface

‎src/client.h

+4-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class PacketCounter
112112
};
113113

114114
class ClientScripting;
115-
struct GameUIFlags;
115+
class GameUI;
116116

117117
class Client : public con::PeerHandler, public InventoryManager, public IGameDef
118118
{
@@ -133,7 +133,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
133133
ISoundManager *sound,
134134
MtEventManager *event,
135135
bool ipv6,
136-
GameUIFlags *game_ui_flags
136+
GameUI *game_ui
137137
);
138138

139139
~Client();
@@ -400,12 +400,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
400400

401401
void pushToEventQueue(ClientEvent *event);
402402

403-
void showGameChat(bool show = true);
404-
void showGameHud(bool show = true);
405403
void showMinimap(bool show = true);
406-
void showProfiler(bool show = true);
407-
void showGameFog(bool show = true);
408-
void showGameDebug(bool show = true);
409404

410405
const Address getServerAddress();
411406

@@ -570,6 +565,8 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
570565
// own state
571566
LocalClientState m_state;
572567

568+
GameUI *m_game_ui;
569+
573570
// Used for saving server map to disk client-side
574571
MapDatabase *m_localdb = nullptr;
575572
IntervalLimiter m_localdb_save_interval;
@@ -580,7 +577,6 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
580577
std::unordered_map<std::string, ModMetadata *> m_mod_storages;
581578
float m_mod_storage_save_timer = 10.0f;
582579
std::vector<ModSpec> m_mods;
583-
GameUIFlags *m_game_ui_flags;
584580

585581
bool m_shutdown = false;
586582

‎src/client/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(client_SRCS
99
${CMAKE_CURRENT_SOURCE_DIR}/render/stereo.cpp
1010
${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
1111
${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
12+
${CMAKE_CURRENT_SOURCE_DIR}/gameui.cpp
1213
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
1314
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
1415
${CMAKE_CURRENT_SOURCE_DIR}/joystick_controller.cpp

‎src/client/gameui.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Lesser General Public License as published by
8+
the Free Software Foundation; either version 2.1 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public License along
17+
with this program; if not, write to the Free Software Foundation, Inc.,
18+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*/
20+
21+
#include "gameui.h"
22+
#include "settings.h"
23+
24+
void GameUI::initFlags()
25+
{
26+
memset(&m_flags, 0, sizeof(GameUI::Flags));
27+
m_flags.show_chat = true;
28+
m_flags.show_hud = true;
29+
m_flags.show_debug = g_settings->getBool("show_debug");
30+
}
31+
32+
void GameUI::showMinimap(const bool show)
33+
{
34+
m_flags.show_minimap = show;
35+
}

‎src/client/gameui.h

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Lesser General Public License as published by
8+
the Free Software Foundation; either version 2.1 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public License along
17+
with this program; if not, write to the Free Software Foundation, Inc.,
18+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*/
20+
21+
#pragma once
22+
23+
#include "IGUIEnvironment.h"
24+
25+
using namespace irr;
26+
27+
class GameUI
28+
{
29+
// Temporary between coding time to move things here
30+
friend class Game;
31+
32+
public:
33+
// Flags that can, or may, change during main game loop
34+
struct Flags
35+
{
36+
bool show_chat;
37+
bool show_hud;
38+
bool show_minimap;
39+
bool force_fog_off;
40+
bool show_debug;
41+
bool show_profiler_graph;
42+
bool disable_camera_update;
43+
};
44+
45+
void initFlags();
46+
const Flags &getFlags() const { return m_flags; }
47+
48+
void showMinimap(const bool show);
49+
50+
private:
51+
Flags m_flags;
52+
53+
// @TODO future move
54+
// gui::IGUIStaticText *m_guitext; // First line of debug text
55+
// gui::IGUIStaticText *m_guitext2; // Second line of debug text
56+
// gui::IGUIStaticText *m_guitext_info; // At the middle of the screen
57+
// gui::IGUIStaticText *m_guitext_status;
58+
// gui::IGUIStaticText *m_guitext_chat; // Chat text
59+
// gui::IGUIStaticText *m_guitext_profiler; // Profiler text
60+
};

0 commit comments

Comments
 (0)
Please sign in to comment.