forked from Mirrorlandia_minetest/minetest
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
This commit is contained in:
parent
549cfd9db8
commit
0ebaed430a
@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "network/networkpacket.h"
|
#include "network/networkpacket.h"
|
||||||
#include "threading/mutex_auto_lock.h"
|
#include "threading/mutex_auto_lock.h"
|
||||||
#include "client/clientevent.h"
|
#include "client/clientevent.h"
|
||||||
|
#include "client/gameui.h"
|
||||||
#include "client/renderingengine.h"
|
#include "client/renderingengine.h"
|
||||||
#include "client/tile.h"
|
#include "client/tile.h"
|
||||||
#include "util/auth.h"
|
#include "util/auth.h"
|
||||||
@ -74,7 +75,7 @@ Client::Client(
|
|||||||
ISoundManager *sound,
|
ISoundManager *sound,
|
||||||
MtEventManager *event,
|
MtEventManager *event,
|
||||||
bool ipv6,
|
bool ipv6,
|
||||||
GameUIFlags *game_ui_flags
|
GameUI *game_ui
|
||||||
):
|
):
|
||||||
m_tsrc(tsrc),
|
m_tsrc(tsrc),
|
||||||
m_shsrc(shsrc),
|
m_shsrc(shsrc),
|
||||||
@ -96,7 +97,7 @@ Client::Client(
|
|||||||
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
|
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
|
||||||
m_media_downloader(new ClientMediaDownloader()),
|
m_media_downloader(new ClientMediaDownloader()),
|
||||||
m_state(LC_Created),
|
m_state(LC_Created),
|
||||||
m_game_ui_flags(game_ui_flags),
|
m_game_ui(game_ui),
|
||||||
m_modchannel_mgr(new ModChannelMgr())
|
m_modchannel_mgr(new ModChannelMgr())
|
||||||
{
|
{
|
||||||
// Add local player
|
// Add local player
|
||||||
@ -1771,34 +1772,9 @@ void Client::pushToEventQueue(ClientEvent *event)
|
|||||||
m_client_event_queue.push(event);
|
m_client_event_queue.push(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::showGameChat(const bool show)
|
|
||||||
{
|
|
||||||
m_game_ui_flags->show_chat = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::showGameHud(const bool show)
|
|
||||||
{
|
|
||||||
m_game_ui_flags->show_hud = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::showMinimap(const bool show)
|
void Client::showMinimap(const bool show)
|
||||||
{
|
{
|
||||||
m_game_ui_flags->show_minimap = show;
|
m_game_ui->showMinimap(show);
|
||||||
}
|
|
||||||
|
|
||||||
void Client::showProfiler(const bool show)
|
|
||||||
{
|
|
||||||
m_game_ui_flags->show_profiler_graph = show;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::showGameFog(const bool show)
|
|
||||||
{
|
|
||||||
m_game_ui_flags->force_fog_off = !show;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::showGameDebug(const bool show)
|
|
||||||
{
|
|
||||||
m_game_ui_flags->show_debug = show;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IGameDef interface
|
// IGameDef interface
|
||||||
|
12
src/client.h
12
src/client.h
@ -112,7 +112,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class ClientScripting;
|
class ClientScripting;
|
||||||
struct GameUIFlags;
|
class GameUI;
|
||||||
|
|
||||||
class Client : public con::PeerHandler, public InventoryManager, public IGameDef
|
class Client : public con::PeerHandler, public InventoryManager, public IGameDef
|
||||||
{
|
{
|
||||||
@ -133,7 +133,7 @@ public:
|
|||||||
ISoundManager *sound,
|
ISoundManager *sound,
|
||||||
MtEventManager *event,
|
MtEventManager *event,
|
||||||
bool ipv6,
|
bool ipv6,
|
||||||
GameUIFlags *game_ui_flags
|
GameUI *game_ui
|
||||||
);
|
);
|
||||||
|
|
||||||
~Client();
|
~Client();
|
||||||
@ -400,12 +400,7 @@ public:
|
|||||||
|
|
||||||
void pushToEventQueue(ClientEvent *event);
|
void pushToEventQueue(ClientEvent *event);
|
||||||
|
|
||||||
void showGameChat(bool show = true);
|
|
||||||
void showGameHud(bool show = true);
|
|
||||||
void showMinimap(bool show = true);
|
void showMinimap(bool show = true);
|
||||||
void showProfiler(bool show = true);
|
|
||||||
void showGameFog(bool show = true);
|
|
||||||
void showGameDebug(bool show = true);
|
|
||||||
|
|
||||||
const Address getServerAddress();
|
const Address getServerAddress();
|
||||||
|
|
||||||
@ -570,6 +565,8 @@ private:
|
|||||||
// own state
|
// own state
|
||||||
LocalClientState m_state;
|
LocalClientState m_state;
|
||||||
|
|
||||||
|
GameUI *m_game_ui;
|
||||||
|
|
||||||
// Used for saving server map to disk client-side
|
// Used for saving server map to disk client-side
|
||||||
MapDatabase *m_localdb = nullptr;
|
MapDatabase *m_localdb = nullptr;
|
||||||
IntervalLimiter m_localdb_save_interval;
|
IntervalLimiter m_localdb_save_interval;
|
||||||
@ -580,7 +577,6 @@ private:
|
|||||||
std::unordered_map<std::string, ModMetadata *> m_mod_storages;
|
std::unordered_map<std::string, ModMetadata *> m_mod_storages;
|
||||||
float m_mod_storage_save_timer = 10.0f;
|
float m_mod_storage_save_timer = 10.0f;
|
||||||
std::vector<ModSpec> m_mods;
|
std::vector<ModSpec> m_mods;
|
||||||
GameUIFlags *m_game_ui_flags;
|
|
||||||
|
|
||||||
bool m_shutdown = false;
|
bool m_shutdown = false;
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ set(client_SRCS
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/render/stereo.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/render/stereo.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/gameui.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/joystick_controller.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/joystick_controller.cpp
|
||||||
|
35
src/client/gameui.cpp
Normal file
35
src/client/gameui.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||||
|
Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gameui.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
void GameUI::initFlags()
|
||||||
|
{
|
||||||
|
memset(&m_flags, 0, sizeof(GameUI::Flags));
|
||||||
|
m_flags.show_chat = true;
|
||||||
|
m_flags.show_hud = true;
|
||||||
|
m_flags.show_debug = g_settings->getBool("show_debug");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameUI::showMinimap(const bool show)
|
||||||
|
{
|
||||||
|
m_flags.show_minimap = show;
|
||||||
|
}
|
60
src/client/gameui.h
Normal file
60
src/client/gameui.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||||
|
Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "IGUIEnvironment.h"
|
||||||
|
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
|
class GameUI
|
||||||
|
{
|
||||||
|
// Temporary between coding time to move things here
|
||||||
|
friend class Game;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
void initFlags();
|
||||||
|
const Flags &getFlags() const { return m_flags; }
|
||||||
|
|
||||||
|
void showMinimap(const bool show);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Flags m_flags;
|
||||||
|
|
||||||
|
// @TODO future move
|
||||||
|
// gui::IGUIStaticText *m_guitext; // First line of debug text
|
||||||
|
// gui::IGUIStaticText *m_guitext2; // Second line of debug text
|
||||||
|
// gui::IGUIStaticText *m_guitext_info; // At the middle of the screen
|
||||||
|
// gui::IGUIStaticText *m_guitext_status;
|
||||||
|
// gui::IGUIStaticText *m_guitext_chat; // Chat text
|
||||||
|
// gui::IGUIStaticText *m_guitext_profiler; // Profiler text
|
||||||
|
};
|
147
src/game.cpp
147
src/game.cpp
@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "client/clientevent.h"
|
#include "client/clientevent.h"
|
||||||
|
#include "client/gameui.h"
|
||||||
#include "client/inputhandler.h"
|
#include "client/inputhandler.h"
|
||||||
#include "client/tile.h" // For TextureSource
|
#include "client/tile.h" // For TextureSource
|
||||||
#include "client/keys.h"
|
#include "client/keys.h"
|
||||||
@ -965,7 +966,8 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
|
|||||||
while (!chat_log_error_buf.empty()) {
|
while (!chat_log_error_buf.empty()) {
|
||||||
std::wstring error_message = utf8_to_wide(chat_log_error_buf.get());
|
std::wstring error_message = utf8_to_wide(chat_log_error_buf.get());
|
||||||
if (!g_settings->getBool("disable_escape_sequences")) {
|
if (!g_settings->getBool("disable_escape_sequences")) {
|
||||||
error_message = L"\x1b(c@red)" + error_message + L"\x1b(c@white)";
|
error_message = L"\x1b(c@red)";
|
||||||
|
error_message.append(error_message).append(L"\x1b(c@white)");
|
||||||
}
|
}
|
||||||
chat_backend.addMessage(L"", error_message);
|
chat_backend.addMessage(L"", error_message);
|
||||||
}
|
}
|
||||||
@ -1392,41 +1394,41 @@ private:
|
|||||||
|
|
||||||
InputHandler *input;
|
InputHandler *input;
|
||||||
|
|
||||||
Client *client;
|
Client *client = nullptr;
|
||||||
Server *server;
|
Server *server = nullptr;
|
||||||
|
|
||||||
IWritableTextureSource *texture_src;
|
IWritableTextureSource *texture_src = nullptr;
|
||||||
IWritableShaderSource *shader_src;
|
IWritableShaderSource *shader_src = nullptr;
|
||||||
|
|
||||||
// When created, these will be filled with data received from the server
|
// When created, these will be filled with data received from the server
|
||||||
IWritableItemDefManager *itemdef_manager;
|
IWritableItemDefManager *itemdef_manager = nullptr;
|
||||||
IWritableNodeDefManager *nodedef_manager;
|
IWritableNodeDefManager *nodedef_manager = nullptr;
|
||||||
|
|
||||||
GameOnDemandSoundFetcher soundfetcher; // useful when testing
|
GameOnDemandSoundFetcher soundfetcher; // useful when testing
|
||||||
ISoundManager *sound;
|
ISoundManager *sound = nullptr;
|
||||||
bool sound_is_dummy = false;
|
bool sound_is_dummy = false;
|
||||||
SoundMaker *soundmaker;
|
SoundMaker *soundmaker = nullptr;
|
||||||
|
|
||||||
ChatBackend *chat_backend;
|
ChatBackend *chat_backend = nullptr;
|
||||||
|
|
||||||
GUIFormSpecMenu *current_formspec;
|
GUIFormSpecMenu *current_formspec = nullptr;
|
||||||
//default: "". If other than "", empty show_formspec packets will only close the formspec when the formname matches
|
//default: "". If other than "", empty show_formspec packets will only close the formspec when the formname matches
|
||||||
std::string cur_formname;
|
std::string cur_formname;
|
||||||
|
|
||||||
EventManager *eventmgr;
|
EventManager *eventmgr = nullptr;
|
||||||
QuicktuneShortcutter *quicktune;
|
QuicktuneShortcutter *quicktune = nullptr;
|
||||||
|
|
||||||
GUIChatConsole *gui_chat_console; // Free using ->Drop()
|
std::unique_ptr<GameUI> m_game_ui;
|
||||||
MapDrawControl *draw_control;
|
GUIChatConsole *gui_chat_console = nullptr; // Free using ->Drop()
|
||||||
Camera *camera;
|
MapDrawControl *draw_control = nullptr;
|
||||||
Clouds *clouds; // Free using ->Drop()
|
Camera *camera = nullptr;
|
||||||
Sky *sky; // Free using ->Drop()
|
Clouds *clouds = nullptr; // Free using ->Drop()
|
||||||
Inventory *local_inventory;
|
Sky *sky = nullptr; // Free using ->Drop()
|
||||||
Hud *hud;
|
Inventory *local_inventory = nullptr;
|
||||||
Minimap *mapper;
|
Hud *hud = nullptr;
|
||||||
|
Minimap *mapper = nullptr;
|
||||||
|
|
||||||
GameRunData runData;
|
GameRunData runData;
|
||||||
GameUIFlags 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,27 +1498,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Game::Game() :
|
Game::Game() :
|
||||||
client(NULL),
|
m_game_ui(new GameUI())
|
||||||
server(NULL),
|
|
||||||
texture_src(NULL),
|
|
||||||
shader_src(NULL),
|
|
||||||
itemdef_manager(NULL),
|
|
||||||
nodedef_manager(NULL),
|
|
||||||
sound(NULL),
|
|
||||||
soundmaker(NULL),
|
|
||||||
chat_backend(NULL),
|
|
||||||
current_formspec(NULL),
|
|
||||||
cur_formname(""),
|
|
||||||
eventmgr(NULL),
|
|
||||||
quicktune(NULL),
|
|
||||||
gui_chat_console(NULL),
|
|
||||||
draw_control(NULL),
|
|
||||||
camera(NULL),
|
|
||||||
clouds(NULL),
|
|
||||||
sky(NULL),
|
|
||||||
local_inventory(NULL),
|
|
||||||
hud(NULL),
|
|
||||||
mapper(NULL)
|
|
||||||
{
|
{
|
||||||
g_settings->registerChangedCallback("doubletap_jump",
|
g_settings->registerChangedCallback("doubletap_jump",
|
||||||
&settingChangedCallback, this);
|
&settingChangedCallback, this);
|
||||||
@ -1643,10 +1625,8 @@ bool Game::startup(bool *kill,
|
|||||||
runData.profiler_max_page = 3;
|
runData.profiler_max_page = 3;
|
||||||
runData.update_wielded_item_trigger = true;
|
runData.update_wielded_item_trigger = true;
|
||||||
|
|
||||||
memset(&flags, 0, sizeof(flags));
|
m_game_ui->initFlags();
|
||||||
flags.show_chat = true;
|
|
||||||
flags.show_hud = true;
|
|
||||||
flags.show_debug = g_settings->getBool("show_debug");
|
|
||||||
m_invert_mouse = g_settings->getBool("invert_mouse");
|
m_invert_mouse = g_settings->getBool("invert_mouse");
|
||||||
m_first_loop_after_window_activation = true;
|
m_first_loop_after_window_activation = true;
|
||||||
|
|
||||||
@ -1737,12 +1717,13 @@ void Game::run()
|
|||||||
processClientEvents(&cam_view_target);
|
processClientEvents(&cam_view_target);
|
||||||
updateCamera(draw_times.busy_time, dtime);
|
updateCamera(draw_times.busy_time, dtime);
|
||||||
updateSound(dtime);
|
updateSound(dtime);
|
||||||
processPlayerInteraction(dtime, flags.show_hud, flags.show_debug);
|
processPlayerInteraction(dtime, m_game_ui->m_flags.show_hud,
|
||||||
|
m_game_ui->m_flags.show_debug);
|
||||||
updateFrame(&graph, &stats, dtime, cam_view);
|
updateFrame(&graph, &stats, dtime, cam_view);
|
||||||
updateProfilerGraphs(&graph);
|
updateProfilerGraphs(&graph);
|
||||||
|
|
||||||
// Update if minimap has been disabled by the server
|
// Update if minimap has been disabled by the server
|
||||||
flags.show_minimap &= client->shouldShowMinimap();
|
m_game_ui->m_flags.show_minimap &= client->shouldShowMinimap();
|
||||||
|
|
||||||
if (m_does_lost_focus_pause_game && !device->isWindowFocused() && !isMenuActive()) {
|
if (m_does_lost_focus_pause_game && !device->isWindowFocused() && !isMenuActive()) {
|
||||||
showPauseMenu();
|
showPauseMenu();
|
||||||
@ -1935,7 +1916,7 @@ bool Game::createClient(const std::string &playername,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory(
|
GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory(
|
||||||
&flags.force_fog_off, &runData.fog_range, client);
|
&m_game_ui->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
|
||||||
@ -2128,7 +2109,7 @@ bool Game::connectToServer(const std::string &playername,
|
|||||||
client = new Client(playername.c_str(), password, *address,
|
client = new Client(playername.c_str(), password, *address,
|
||||||
*draw_control, texture_src, shader_src,
|
*draw_control, texture_src, shader_src,
|
||||||
itemdef_manager, nodedef_manager, sound, eventmgr,
|
itemdef_manager, nodedef_manager, sound, eventmgr,
|
||||||
connect_address.isIPv6(), &flags);
|
connect_address.isIPv6(), m_game_ui.get());
|
||||||
|
|
||||||
if (!client)
|
if (!client)
|
||||||
return false;
|
return false;
|
||||||
@ -2816,9 +2797,9 @@ void Game::toggleAutoforward()
|
|||||||
|
|
||||||
void Game::toggleChat()
|
void Game::toggleChat()
|
||||||
{
|
{
|
||||||
flags.show_chat = !flags.show_chat;
|
m_game_ui->m_flags.show_chat = !m_game_ui->m_flags.show_chat;
|
||||||
runData.statustext_time = 0;
|
runData.statustext_time = 0;
|
||||||
if (flags.show_chat)
|
if (m_game_ui->m_flags.show_chat)
|
||||||
showStatusTextSimple("Chat shown");
|
showStatusTextSimple("Chat shown");
|
||||||
else
|
else
|
||||||
showStatusTextSimple("Chat hidden");
|
showStatusTextSimple("Chat hidden");
|
||||||
@ -2827,9 +2808,9 @@ void Game::toggleChat()
|
|||||||
|
|
||||||
void Game::toggleHud()
|
void Game::toggleHud()
|
||||||
{
|
{
|
||||||
flags.show_hud = !flags.show_hud;
|
m_game_ui->m_flags.show_hud = !m_game_ui->m_flags.show_hud;
|
||||||
runData.statustext_time = 0;
|
runData.statustext_time = 0;
|
||||||
if (flags.show_hud)
|
if (m_game_ui->m_flags.show_hud)
|
||||||
showStatusTextSimple("HUD shown");
|
showStatusTextSimple("HUD shown");
|
||||||
else
|
else
|
||||||
showStatusTextSimple("HUD hidden");
|
showStatusTextSimple("HUD hidden");
|
||||||
@ -2837,7 +2818,7 @@ void Game::toggleHud()
|
|||||||
|
|
||||||
void Game::toggleMinimap(bool shift_pressed)
|
void Game::toggleMinimap(bool shift_pressed)
|
||||||
{
|
{
|
||||||
if (!mapper || !flags.show_hud || !g_settings->getBool("enable_minimap"))
|
if (!mapper || !m_game_ui->m_flags.show_hud || !g_settings->getBool("enable_minimap"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (shift_pressed) {
|
if (shift_pressed) {
|
||||||
@ -2856,7 +2837,7 @@ void Game::toggleMinimap(bool shift_pressed)
|
|||||||
mode = MINIMAP_MODE_OFF;
|
mode = MINIMAP_MODE_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.show_minimap = true;
|
m_game_ui->m_flags.show_minimap = true;
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case MINIMAP_MODE_SURFACEx1:
|
case MINIMAP_MODE_SURFACEx1:
|
||||||
showStatusTextSimple("Minimap in surface mode, Zoom x1");
|
showStatusTextSimple("Minimap in surface mode, Zoom x1");
|
||||||
@ -2878,7 +2859,7 @@ void Game::toggleMinimap(bool shift_pressed)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mode = MINIMAP_MODE_OFF;
|
mode = MINIMAP_MODE_OFF;
|
||||||
flags.show_minimap = false;
|
m_game_ui->m_flags.show_minimap = false;
|
||||||
if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE)
|
if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE)
|
||||||
showStatusTextSimple("Minimap hidden");
|
showStatusTextSimple("Minimap hidden");
|
||||||
else
|
else
|
||||||
@ -2891,9 +2872,9 @@ void Game::toggleMinimap(bool shift_pressed)
|
|||||||
|
|
||||||
void Game::toggleFog()
|
void Game::toggleFog()
|
||||||
{
|
{
|
||||||
flags.force_fog_off = !flags.force_fog_off;
|
m_game_ui->m_flags.force_fog_off = !m_game_ui->m_flags.force_fog_off;
|
||||||
runData.statustext_time = 0;
|
runData.statustext_time = 0;
|
||||||
if (flags.force_fog_off)
|
if (m_game_ui->m_flags.force_fog_off)
|
||||||
showStatusTextSimple("Fog disabled");
|
showStatusTextSimple("Fog disabled");
|
||||||
else
|
else
|
||||||
showStatusTextSimple("Fog enabled");
|
showStatusTextSimple("Fog enabled");
|
||||||
@ -2906,21 +2887,21 @@ void Game::toggleDebug()
|
|||||||
// 1x toggle: Debug text with chat
|
// 1x toggle: Debug text with chat
|
||||||
// 2x toggle: Debug text with profiler graph
|
// 2x toggle: Debug text with profiler graph
|
||||||
// 3x toggle: Debug text and wireframe
|
// 3x toggle: Debug text and wireframe
|
||||||
if (!flags.show_debug) {
|
if (!m_game_ui->m_flags.show_debug) {
|
||||||
flags.show_debug = true;
|
m_game_ui->m_flags.show_debug = true;
|
||||||
flags.show_profiler_graph = false;
|
m_game_ui->m_flags.show_profiler_graph = false;
|
||||||
draw_control->show_wireframe = false;
|
draw_control->show_wireframe = false;
|
||||||
showStatusTextSimple("Debug info shown");
|
showStatusTextSimple("Debug info shown");
|
||||||
} else if (!flags.show_profiler_graph && !draw_control->show_wireframe) {
|
} else if (!m_game_ui->m_flags.show_profiler_graph && !draw_control->show_wireframe) {
|
||||||
flags.show_profiler_graph = true;
|
m_game_ui->m_flags.show_profiler_graph = true;
|
||||||
showStatusTextSimple("Profiler graph shown");
|
showStatusTextSimple("Profiler graph shown");
|
||||||
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
|
} else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
|
||||||
flags.show_profiler_graph = false;
|
m_game_ui->m_flags.show_profiler_graph = false;
|
||||||
draw_control->show_wireframe = true;
|
draw_control->show_wireframe = true;
|
||||||
showStatusTextSimple("Wireframe shown");
|
showStatusTextSimple("Wireframe shown");
|
||||||
} else {
|
} else {
|
||||||
flags.show_debug = false;
|
m_game_ui->m_flags.show_debug = false;
|
||||||
flags.show_profiler_graph = false;
|
m_game_ui->m_flags.show_profiler_graph = false;
|
||||||
draw_control->show_wireframe = false;
|
draw_control->show_wireframe = false;
|
||||||
if (client->checkPrivilege("debug")) {
|
if (client->checkPrivilege("debug")) {
|
||||||
showStatusTextSimple("Debug info, profiler graph, and wireframe hidden");
|
showStatusTextSimple("Debug info, profiler graph, and wireframe hidden");
|
||||||
@ -2934,9 +2915,9 @@ void Game::toggleDebug()
|
|||||||
|
|
||||||
void Game::toggleUpdateCamera()
|
void Game::toggleUpdateCamera()
|
||||||
{
|
{
|
||||||
flags.disable_camera_update = !flags.disable_camera_update;
|
m_game_ui->m_flags.disable_camera_update = !m_game_ui->m_flags.disable_camera_update;
|
||||||
runData.statustext_time = 0;
|
runData.statustext_time = 0;
|
||||||
if (flags.disable_camera_update)
|
if (m_game_ui->m_flags.disable_camera_update)
|
||||||
showStatusTextSimple("Camera update disabled");
|
showStatusTextSimple("Camera update disabled");
|
||||||
else
|
else
|
||||||
showStatusTextSimple("Camera update enabled");
|
showStatusTextSimple("Camera update enabled");
|
||||||
@ -3529,7 +3510,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 (!flags.disable_camera_update) {
|
if (!m_game_ui->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);
|
||||||
|
|
||||||
@ -4224,7 +4205,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 &&
|
||||||
!flags.force_fog_off) {
|
!m_game_ui->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()
|
||||||
@ -4249,7 +4230,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
Fog
|
Fog
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (m_cache_enable_fog && !flags.force_fog_off) {
|
if (m_cache_enable_fog && !m_game_ui->m_flags.force_fog_off) {
|
||||||
driver->setFog(
|
driver->setFog(
|
||||||
sky->getBgColor(),
|
sky->getBgColor(),
|
||||||
video::EFT_FOG_LINEAR,
|
video::EFT_FOG_LINEAR,
|
||||||
@ -4277,8 +4258,8 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
|
|
||||||
v2u32 screensize = driver->getScreenSize();
|
v2u32 screensize = driver->getScreenSize();
|
||||||
|
|
||||||
updateChat(*client, dtime, flags.show_debug, screensize,
|
updateChat(*client, dtime, m_game_ui->m_flags.show_debug, screensize,
|
||||||
flags.show_chat, runData.profiler_current_page,
|
m_game_ui->m_flags.show_chat, runData.profiler_current_page,
|
||||||
*chat_backend, guitext_chat);
|
*chat_backend, guitext_chat);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4351,7 +4332,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
TimeTaker tt_draw("mainloop: draw");
|
TimeTaker tt_draw("mainloop: draw");
|
||||||
driver->beginScene(true, true, skycolor);
|
driver->beginScene(true, true, skycolor);
|
||||||
|
|
||||||
bool draw_wield_tool = (flags.show_hud &&
|
bool draw_wield_tool = (m_game_ui->m_flags.show_hud &&
|
||||||
(player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
|
(player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
|
||||||
(camera->getCameraMode() == CAMERA_MODE_FIRST));
|
(camera->getCameraMode() == CAMERA_MODE_FIRST));
|
||||||
bool draw_crosshair = (
|
bool draw_crosshair = (
|
||||||
@ -4363,13 +4344,13 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
} catch (SettingNotFoundException) {
|
} catch (SettingNotFoundException) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
RenderingEngine::draw_scene(skycolor, flags.show_hud, flags.show_minimap,
|
RenderingEngine::draw_scene(skycolor, m_game_ui->m_flags.show_hud,
|
||||||
draw_wield_tool, draw_crosshair);
|
m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Profiler graph
|
Profiler graph
|
||||||
*/
|
*/
|
||||||
if (flags.show_profiler_graph)
|
if (m_game_ui->m_flags.show_profiler_graph)
|
||||||
graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont());
|
graph->draw(10, screensize.Y - 10, driver, g_fontengine->getFont());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4397,7 +4378,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
|
|||||||
/*
|
/*
|
||||||
Update minimap pos and rotation
|
Update minimap pos and rotation
|
||||||
*/
|
*/
|
||||||
if (mapper && flags.show_minimap && flags.show_hud) {
|
if (mapper && m_game_ui->m_flags.show_minimap && m_game_ui->m_flags.show_hud) {
|
||||||
mapper->setPos(floatToInt(player->getPosition(), BS));
|
mapper->setPos(floatToInt(player->getPosition(), BS));
|
||||||
mapper->setAngle(player->getYaw());
|
mapper->setAngle(player->getYaw());
|
||||||
}
|
}
|
||||||
@ -4429,7 +4410,7 @@ void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &
|
|||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
v3f player_position = player->getPosition();
|
v3f player_position = player->getPosition();
|
||||||
|
|
||||||
if (flags.show_debug) {
|
if (m_game_ui->m_flags.show_debug) {
|
||||||
static float drawtime_avg = 0;
|
static float drawtime_avg = 0;
|
||||||
drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
|
drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
|
||||||
u16 fps = 1.0 / stats.dtime_jitter.avg;
|
u16 fps = 1.0 / stats.dtime_jitter.avg;
|
||||||
@ -4462,7 +4443,7 @@ void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &
|
|||||||
guitext->setRelativePosition(rect);
|
guitext->setRelativePosition(rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags.show_debug) {
|
if (m_game_ui->m_flags.show_debug) {
|
||||||
std::ostringstream os(std::ios_base::binary);
|
std::ostringstream os(std::ios_base::binary);
|
||||||
os << std::setprecision(1) << std::fixed
|
os << std::setprecision(1) << std::fixed
|
||||||
<< "pos: (" << (player_position.X / BS)
|
<< "pos: (" << (player_position.X / BS)
|
||||||
@ -4498,7 +4479,7 @@ void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &
|
|||||||
}
|
}
|
||||||
|
|
||||||
setStaticText(guitext_info, translate_string(infotext).c_str());
|
setStaticText(guitext_info, translate_string(infotext).c_str());
|
||||||
guitext_info->setVisible(flags.show_hud && g_menumgr.menuCount() == 0);
|
guitext_info->setVisible(m_game_ui->m_flags.show_hud && g_menumgr.menuCount() == 0);
|
||||||
|
|
||||||
float statustext_time_max = 1.5;
|
float statustext_time_max = 1.5;
|
||||||
|
|
||||||
|
12
src/game.h
12
src/game.h
@ -26,18 +26,6 @@ class InputHandler;
|
|||||||
class ChatBackend; /* to avoid having to include chat.h */
|
class ChatBackend; /* to avoid having to include chat.h */
|
||||||
struct SubgameSpec;
|
struct SubgameSpec;
|
||||||
|
|
||||||
// Flags that can, or may, change during main game loop
|
|
||||||
struct GameUIFlags
|
|
||||||
{
|
|
||||||
bool show_chat;
|
|
||||||
bool show_hud;
|
|
||||||
bool show_minimap;
|
|
||||||
bool force_fog_off;
|
|
||||||
bool show_debug;
|
|
||||||
bool show_profiler_graph;
|
|
||||||
bool disable_camera_update;
|
|
||||||
};
|
|
||||||
|
|
||||||
void the_game(bool *kill,
|
void the_game(bool *kill,
|
||||||
bool random_input,
|
bool random_input,
|
||||||
InputHandler *input,
|
InputHandler *input,
|
||||||
|
@ -29,5 +29,6 @@ set (UNITTEST_SRCS
|
|||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
|
|
||||||
set (UNITTEST_CLIENT_SRCS
|
set (UNITTEST_CLIENT_SRCS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/test_gameui.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/test_keycode.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/test_keycode.cpp
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
|
60
src/unittest/test_gameui.cpp
Normal file
60
src/unittest/test_gameui.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
Minetest
|
||||||
|
Copyright (C) 2018 nerzhul, Loic BLOT <loic.blot@unix-experience.fr>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
#include "client/gameui.h"
|
||||||
|
|
||||||
|
class TestGameUI : public TestBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TestGameUI() { TestManager::registerTestModule(this); }
|
||||||
|
const char *getName() { return "TestGameUI"; }
|
||||||
|
|
||||||
|
void runTests(IGameDef *gamedef);
|
||||||
|
|
||||||
|
void testInit();
|
||||||
|
void testFlagSetters();
|
||||||
|
};
|
||||||
|
|
||||||
|
static TestGameUI g_test_instance;
|
||||||
|
|
||||||
|
void TestGameUI::runTests(IGameDef *gamedef)
|
||||||
|
{
|
||||||
|
TEST(testInit);
|
||||||
|
TEST(testFlagSetters);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestGameUI::testInit()
|
||||||
|
{
|
||||||
|
GameUI gui{};
|
||||||
|
gui.initFlags();
|
||||||
|
UASSERT(gui.getFlags().show_chat)
|
||||||
|
UASSERT(gui.getFlags().show_hud)
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestGameUI::testFlagSetters()
|
||||||
|
{
|
||||||
|
GameUI gui;
|
||||||
|
gui.showMinimap(true);
|
||||||
|
UASSERT(gui.getFlags().show_minimap);
|
||||||
|
|
||||||
|
gui.showMinimap(false);
|
||||||
|
UASSERT(!gui.getFlags().show_minimap);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user