Refactor Game class (part 2) (#5422)

* showPauseMenu is now part of game
* remove many flags parameters passed to game functions, use the member.
* rename VolatileRunFlags to GameUIFlags (this will permit to share structure with client and CSM
* updatePointedThing: remove pointer ref, we already have the pointer in rundata
* move some attributes outside of VolatileRunFlags after renaming, to game class
* rename statustext to m_statustext
* make some const variables static
* All those changes permit to reduce a little bit function class cost and will permit to interface CSM with some interesting Game flags
* Expose GameUIFlags to client
* Client now have GameUIFlags parameter and setters for other classes
* Fix minimap show/hide in Lua because we now have access to the real flag
This commit is contained in:
Loïc Blot 2017-03-19 13:18:52 +01:00 committed by GitHub
parent 2e3778ec0c
commit 3c4ac70348
6 changed files with 285 additions and 266 deletions

View File

@ -46,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" #include "serialization.h"
#include "guiscalingfilter.h" #include "guiscalingfilter.h"
#include "script/clientscripting.h" #include "script/clientscripting.h"
#include "game.h"
extern gui::IGUIEnvironment* guienv; extern gui::IGUIEnvironment* guienv;
@ -198,7 +199,8 @@ Client::Client(
IWritableNodeDefManager *nodedef, IWritableNodeDefManager *nodedef,
ISoundManager *sound, ISoundManager *sound,
MtEventManager *event, MtEventManager *event,
bool ipv6 bool ipv6,
GameUIFlags *game_ui_flags
): ):
m_packetcounter_timer(0.0), m_packetcounter_timer(0.0),
m_connection_reinit_timer(0.1), m_connection_reinit_timer(0.1),
@ -250,7 +252,8 @@ Client::Client(
m_state(LC_Created), m_state(LC_Created),
m_localdb(NULL), m_localdb(NULL),
m_script(NULL), m_script(NULL),
m_mod_storage_save_timer(10.0f) m_mod_storage_save_timer(10.0f),
m_game_ui_flags(game_ui_flags)
{ {
// Add local player // Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername)); m_env.setLocalPlayer(new LocalPlayer(this, playername));
@ -1935,6 +1938,36 @@ bool Client::shouldShowMinimap() const
return !m_minimap_disabled_by_server; return !m_minimap_disabled_by_server;
} }
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)
{
m_game_ui_flags->show_minimap = 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
// Under envlock // Under envlock
IItemDefManager* Client::getItemDefManager() IItemDefManager* Client::getItemDefManager()

View File

@ -307,6 +307,7 @@ private:
}; };
class ClientScripting; class ClientScripting;
class GameUIFlags;
class Client : public con::PeerHandler, public InventoryManager, public IGameDef class Client : public con::PeerHandler, public InventoryManager, public IGameDef
{ {
@ -326,7 +327,8 @@ public:
IWritableNodeDefManager *nodedef, IWritableNodeDefManager *nodedef,
ISoundManager *sound, ISoundManager *sound,
MtEventManager *event, MtEventManager *event,
bool ipv6 bool ipv6,
GameUIFlags *game_ui_flags
); );
~Client(); ~Client();
@ -578,6 +580,13 @@ public:
m_client_event_queue.push(event); m_client_event_queue.push(event);
} }
void showGameChat(const bool show = true);
void showGameHud(const bool show = true);
void showMinimap(const bool show = true);
void showProfiler(const bool show = true);
void showGameFog(const bool show = true);
void showGameDebug(const bool show = true);
private: private:
// Virtual methods from con::PeerHandler // Virtual methods from con::PeerHandler
@ -725,6 +734,7 @@ private:
bool m_modding_enabled; bool m_modding_enabled;
UNORDERED_MAP<std::string, ModMetadata *> m_mod_storages; UNORDERED_MAP<std::string, ModMetadata *> m_mod_storages;
float m_mod_storage_save_timer; float m_mod_storage_save_timer;
GameUIFlags *m_game_ui_flags;
DISABLE_CLASS_COPY(Client); DISABLE_CLASS_COPY(Client);
}; };

View File

@ -123,16 +123,15 @@ struct TextDestPlayerInventory : public TextDest {
Client *m_client; Client *m_client;
}; };
struct LocalFormspecHandler : public TextDest { struct LocalFormspecHandler : public TextDest
LocalFormspecHandler(); {
LocalFormspecHandler(std::string formname):
LocalFormspecHandler(std::string formname) :
m_client(0) m_client(0)
{ {
m_formname = formname; m_formname = formname;
} }
LocalFormspecHandler(std::string formname, Client *client) : LocalFormspecHandler(std::string formname, Client *client):
m_client(client) m_client(client)
{ {
m_formname = formname; m_formname = formname;
@ -927,81 +926,6 @@ static inline void create_formspec_menu(GUIFormSpecMenu **cur_formspec,
#define SIZE_TAG "size[11,5.5,true]" // Fixed size on desktop #define SIZE_TAG "size[11,5.5,true]" // Fixed size on desktop
#endif #endif
/******************************************************************************/
static void show_pause_menu(GUIFormSpecMenu **cur_formspec,
Client *client,
IWritableTextureSource *tsrc, IrrlichtDevice *device,
JoystickController *joystick, bool singleplayermode)
{
#ifdef __ANDROID__
std::string control_text = strgettext("Default Controls:\n"
"No menu visible:\n"
"- single tap: button activate\n"
"- double tap: place/use\n"
"- slide finger: look around\n"
"Menu/Inventory visible:\n"
"- double tap (outside):\n"
" -->close\n"
"- touch stack, touch slot:\n"
" --> move stack\n"
"- touch&drag, tap 2nd finger\n"
" --> place single item to slot\n"
);
#else
std::string control_text = strgettext("Default Controls:\n"
"- WASD: move\n"
"- Space: jump/climb\n"
"- Shift: sneak/go down\n"
"- Q: drop item\n"
"- I: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- T: chat\n"
);
#endif
float ypos = singleplayermode ? 0.5 : 0.1;
std::ostringstream os;
os << FORMSPEC_VERSION_STRING << SIZE_TAG
<< "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;"
<< strgettext("Continue") << "]";
if (!singleplayermode) {
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;"
<< strgettext("Change Password") << "]";
}
#ifndef __ANDROID__
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;"
<< strgettext("Sound Volume") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;"
<< strgettext("Change Keys") << "]";
#endif
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;"
<< strgettext("Exit to Menu") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"
<< strgettext("Exit to OS") << "]"
<< "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]"
<< "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n"
<< g_build_info << "\n"
<< "path_user = " << wrap_rows(porting::path_user, 20)
<< "\n;]";
/* Create menu */
/* Note: FormspecFormSource and LocalFormspecHandler *
* are deleted by guiFormSpecMenu */
FormspecFormSource *fs_src = new FormspecFormSource(os.str());
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
create_formspec_menu(cur_formspec, client, device, joystick, fs_src, txt_dst);
std::string con("btn_continue");
(*cur_formspec)->setFocus(con);
(*cur_formspec)->doPause = true;
}
/******************************************************************************/ /******************************************************************************/
static void updateChat(Client &client, f32 dtime, bool show_debug, static void updateChat(Client &client, f32 dtime, bool show_debug,
const v2u32 &screensize, bool show_chat, u32 show_profiler, const v2u32 &screensize, bool show_chat, u32 show_profiler,
@ -1219,28 +1143,10 @@ struct Jitter {
struct RunStats { struct RunStats {
u32 drawtime; u32 drawtime;
u32 beginscenetime;
u32 endscenetime;
Jitter dtime_jitter, busy_time_jitter; Jitter dtime_jitter, busy_time_jitter;
}; };
/* Flags that can, or may, change during main game loop
*/
struct VolatileRunFlags {
bool invert_mouse;
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 first_loop_after_window_activation;
bool camera_offset_changed;
};
/**************************************************************************** /****************************************************************************
THE GAME THE GAME
****************************************************************************/ ****************************************************************************/
@ -1322,29 +1228,24 @@ protected:
void toggleCinematic(); void toggleCinematic();
void toggleAutorun(); void toggleAutorun();
void toggleChat(bool *flag); void toggleChat();
void toggleHud(bool *flag); void toggleHud();
void toggleMinimap(bool *flag, bool show_hud, void toggleMinimap(bool shift_pressed);
bool shift_pressed); void toggleFog();
void toggleFog(bool *flag); void toggleDebug();
void toggleDebug(bool *show_debug, void toggleUpdateCamera();
bool *show_profiler_graph, bool *show_wireframe); void toggleProfiler();
void toggleUpdateCamera(bool *flag);
void toggleProfiler(u32 *profiler_current_page,
u32 profiler_max_page);
void increaseViewRange(); void increaseViewRange();
void decreaseViewRange(); void decreaseViewRange();
void toggleFullViewRange(); void toggleFullViewRange();
void updateCameraDirection(CameraOrientation *cam, VolatileRunFlags *flags, void updateCameraDirection(CameraOrientation *cam, float dtime);
float dtime); void updateCameraOrientation(CameraOrientation *cam, float dtime);
void updateCameraOrientation(CameraOrientation *cam,
const VolatileRunFlags &flags, float dtime);
void updatePlayerControl(const CameraOrientation &cam); void updatePlayerControl(const CameraOrientation &cam);
void step(f32 *dtime); void step(f32 *dtime);
void processClientEvents(CameraOrientation *cam); void processClientEvents(CameraOrientation *cam);
void updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime); void updateCamera(u32 busy_time, f32 dtime);
void updateSound(f32 dtime); void updateSound(f32 dtime);
void processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug); void processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug);
/*! /*!
@ -1362,8 +1263,7 @@ protected:
*/ */
PointedThing updatePointedThing( PointedThing updatePointedThing(
const core::line3d<f32> &shootline, bool liquids_pointable, const core::line3d<f32> &shootline, bool liquids_pointable,
bool look_for_object, const v3s16 &camera_offset, bool look_for_object, const v3s16 &camera_offset);
ClientActiveObject *&selected_object);
void handlePointingAtNothing(const ItemStack &playerItem); void handlePointingAtNothing(const ItemStack &playerItem);
void handlePointingAtNode(const PointedThing &pointed, const ItemDefinition &playeritem_def, void handlePointingAtNode(const PointedThing &pointed, const ItemDefinition &playeritem_def,
const ToolCapabilities &playeritem_toolcap, f32 dtime); const ToolCapabilities &playeritem_toolcap, f32 dtime);
@ -1372,9 +1272,8 @@ protected:
void handleDigging(const PointedThing &pointed, const v3s16 &nodepos, void handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
const ToolCapabilities &playeritem_toolcap, f32 dtime); const ToolCapabilities &playeritem_toolcap, f32 dtime);
void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, void updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
const VolatileRunFlags &flags, const CameraOrientation &cam); const CameraOrientation &cam);
void updateGui(const RunStats &stats, f32 dtime, void updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &cam);
const VolatileRunFlags &flags, const CameraOrientation &cam);
void updateProfilerGraphs(ProfilerGraph *graph); void updateProfilerGraphs(ProfilerGraph *graph);
// Misc // Misc
@ -1426,6 +1325,8 @@ protected:
#endif #endif
private: private:
void showPauseMenu();
InputHandler *input; InputHandler *input;
Client *client; Client *client;
@ -1462,7 +1363,7 @@ private:
Minimap *mapper; Minimap *mapper;
GameRunData runData; GameRunData runData;
VolatileRunFlags flags; 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
@ -1494,7 +1395,7 @@ private:
gui::IGUIStaticText *guitext_profiler; // Profiler text gui::IGUIStaticText *guitext_profiler; // Profiler text
std::wstring infotext; std::wstring infotext;
std::wstring statustext; std::wstring m_statustext;
KeyCache keycache; KeyCache keycache;
@ -1519,6 +1420,10 @@ private:
f32 m_cache_cam_smoothing; f32 m_cache_cam_smoothing;
f32 m_cache_fog_start; f32 m_cache_fog_start;
bool m_invert_mouse;
bool m_first_loop_after_window_activation;
bool m_camera_offset_changed;
#ifdef __ANDROID__ #ifdef __ANDROID__
bool m_cache_hold_aux1; bool m_cache_hold_aux1;
bool m_android_chat_open; bool m_android_chat_open;
@ -1547,7 +1452,10 @@ Game::Game() :
sky(NULL), sky(NULL),
local_inventory(NULL), local_inventory(NULL),
hud(NULL), hud(NULL),
mapper(NULL) mapper(NULL),
m_invert_mouse(false),
m_first_loop_after_window_activation(false),
m_camera_offset_changed(false)
{ {
g_settings->registerChangedCallback("doubletap_jump", g_settings->registerChangedCallback("doubletap_jump",
&settingChangedCallback, this); &settingChangedCallback, this);
@ -1678,8 +1586,8 @@ bool Game::startup(bool *kill,
flags.show_chat = true; flags.show_chat = true;
flags.show_hud = true; flags.show_hud = true;
flags.show_debug = g_settings->getBool("show_debug"); flags.show_debug = g_settings->getBool("show_debug");
flags.invert_mouse = g_settings->getBool("invert_mouse"); m_invert_mouse = g_settings->getBool("invert_mouse");
flags.first_loop_after_window_activation = true; m_first_loop_after_window_activation = true;
if (!init(map_dir, address, port, gamespec)) if (!init(map_dir, address, port, gamespec))
return false; return false;
@ -1738,7 +1646,7 @@ void Game::run()
updateProfilers(stats, draw_times, dtime); updateProfilers(stats, draw_times, dtime);
processUserInput(dtime); processUserInput(dtime);
// Update camera before player movement to avoid camera lag of one frame // Update camera before player movement to avoid camera lag of one frame
updateCameraDirection(&cam_view_target, &flags, dtime); updateCameraDirection(&cam_view_target, dtime);
cam_view.camera_yaw += (cam_view_target.camera_yaw - cam_view.camera_yaw += (cam_view_target.camera_yaw -
cam_view.camera_yaw) * m_cache_cam_smoothing; cam_view.camera_yaw) * m_cache_cam_smoothing;
cam_view.camera_pitch += (cam_view_target.camera_pitch - cam_view.camera_pitch += (cam_view_target.camera_pitch -
@ -1746,10 +1654,10 @@ void Game::run()
updatePlayerControl(cam_view); updatePlayerControl(cam_view);
step(&dtime); step(&dtime);
processClientEvents(&cam_view_target); processClientEvents(&cam_view_target);
updateCamera(&flags, 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, flags.show_hud, flags.show_debug);
updateFrame(&graph, &stats, dtime, flags, 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
@ -2130,7 +2038,7 @@ bool Game::connectToServer(const std::string &playername,
playername.c_str(), password, playername.c_str(), password,
*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()); connect_address.isIPv6(), &flags);
if (!client) if (!client)
return false; return false;
@ -2535,22 +2443,18 @@ void Game::processKeyInput()
openInventory(); openInventory();
} else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) { } else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
if (!gui_chat_console->isOpenInhibited()) { if (!gui_chat_console->isOpenInhibited()) {
show_pause_menu(&current_formspec, client, showPauseMenu();
texture_src, device, &input->joystick,
simple_singleplayer_mode);
} }
} else if (wasKeyDown(KeyType::CHAT)) { } else if (wasKeyDown(KeyType::CHAT)) {
openConsole(0.2, L""); openConsole(0.2, L"");
} else if (wasKeyDown(KeyType::CMD)) { } else if (wasKeyDown(KeyType::CMD)) {
openConsole(0.2, L"/"); openConsole(0.2, L"/");
} else if (wasKeyDown(KeyType::CONSOLE)) { } else if (wasKeyDown(KeyType::CONSOLE)) {
openConsole(core::clamp( openConsole(core::clamp(g_settings->getFloat("console_height"), 0.1f, 1.0f));
g_settings->getFloat("console_height"), 0.1f, 1.0f));
} else if (wasKeyDown(KeyType::FREEMOVE)) { } else if (wasKeyDown(KeyType::FREEMOVE)) {
toggleFreeMove(); toggleFreeMove();
} else if (wasKeyDown(KeyType::JUMP)) { } else if (wasKeyDown(KeyType::JUMP)) {
toggleFreeMoveAlt(); toggleFreeMoveAlt();
runData.reset_jump_timer = true;
} else if (wasKeyDown(KeyType::FASTMOVE)) { } else if (wasKeyDown(KeyType::FASTMOVE)) {
toggleFast(); toggleFast();
} else if (wasKeyDown(KeyType::NOCLIP)) { } else if (wasKeyDown(KeyType::NOCLIP)) {
@ -2560,21 +2464,19 @@ void Game::processKeyInput()
} else if (wasKeyDown(KeyType::SCREENSHOT)) { } else if (wasKeyDown(KeyType::SCREENSHOT)) {
client->makeScreenshot(device); client->makeScreenshot(device);
} else if (wasKeyDown(KeyType::TOGGLE_HUD)) { } else if (wasKeyDown(KeyType::TOGGLE_HUD)) {
toggleHud(&flags.show_hud); toggleHud();
} else if (wasKeyDown(KeyType::MINIMAP)) { } else if (wasKeyDown(KeyType::MINIMAP)) {
toggleMinimap(&flags.show_minimap, flags.show_hud, isKeyDown(KeyType::SNEAK)); toggleMinimap(isKeyDown(KeyType::SNEAK));
} else if (wasKeyDown(KeyType::TOGGLE_CHAT)) { } else if (wasKeyDown(KeyType::TOGGLE_CHAT)) {
toggleChat(&flags.show_chat); toggleChat();
} else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) { } else if (wasKeyDown(KeyType::TOGGLE_FORCE_FOG_OFF)) {
toggleFog(&flags.force_fog_off); toggleFog();
} else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) { } else if (wasKeyDown(KeyType::TOGGLE_UPDATE_CAMERA)) {
toggleUpdateCamera(&flags.disable_camera_update); toggleUpdateCamera();
} else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) { } else if (wasKeyDown(KeyType::TOGGLE_DEBUG)) {
toggleDebug(&flags.show_debug, &flags.show_profiler_graph, toggleDebug();
&draw_control->show_wireframe);
} else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) { } else if (wasKeyDown(KeyType::TOGGLE_PROFILER)) {
toggleProfiler(&runData.profiler_current_page, toggleProfiler();
runData.profiler_max_page);
} 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)) {
@ -2605,7 +2507,7 @@ void Game::processKeyInput()
} }
if (quicktune->hasMessage()) { if (quicktune->hasMessage()) {
statustext = utf8_to_wide(quicktune->getMessage()); m_statustext = utf8_to_wide(quicktune->getMessage());
runData.statustext_time = 0.0f; runData.statustext_time = 0.0f;
} }
} }
@ -2731,9 +2633,9 @@ void Game::toggleFreeMove()
g_settings->set("free_move", bool_to_cstr(free_move)); g_settings->set("free_move", bool_to_cstr(free_move));
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[free_move]; m_statustext = msg[free_move];
if (free_move && !client->checkPrivilege("fly")) if (free_move && !client->checkPrivilege("fly"))
statustext += L" (note: no 'fly' privilege)"; m_statustext += L" (note: no 'fly' privilege)";
} }
@ -2741,6 +2643,8 @@ void Game::toggleFreeMoveAlt()
{ {
if (m_cache_doubletap_jump && runData.jump_timer < 0.2f) if (m_cache_doubletap_jump && runData.jump_timer < 0.2f)
toggleFreeMove(); toggleFreeMove();
runData.reset_jump_timer = true;
} }
@ -2751,12 +2655,12 @@ void Game::toggleFast()
g_settings->set("fast_move", bool_to_cstr(fast_move)); g_settings->set("fast_move", bool_to_cstr(fast_move));
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[fast_move]; m_statustext = msg[fast_move];
bool has_fast_privs = client->checkPrivilege("fast"); bool has_fast_privs = client->checkPrivilege("fast");
if (fast_move && !has_fast_privs) if (fast_move && !has_fast_privs)
statustext += L" (note: no 'fast' privilege)"; m_statustext += L" (note: no 'fast' privilege)";
#ifdef __ANDROID__ #ifdef __ANDROID__
m_cache_hold_aux1 = fast_move && has_fast_privs; m_cache_hold_aux1 = fast_move && has_fast_privs;
@ -2771,10 +2675,10 @@ void Game::toggleNoClip()
g_settings->set("noclip", bool_to_cstr(noclip)); g_settings->set("noclip", bool_to_cstr(noclip));
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[noclip]; m_statustext = msg[noclip];
if (noclip && !client->checkPrivilege("noclip")) if (noclip && !client->checkPrivilege("noclip"))
statustext += L" (note: no 'noclip' privilege)"; m_statustext += L" (note: no 'noclip' privilege)";
} }
void Game::toggleCinematic() void Game::toggleCinematic()
@ -2784,7 +2688,7 @@ void Game::toggleCinematic()
g_settings->set("cinematic", bool_to_cstr(cinematic)); g_settings->set("cinematic", bool_to_cstr(cinematic));
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[cinematic]; m_statustext = msg[cinematic];
} }
// Add WoW-style autorun by toggling continuous forward. // Add WoW-style autorun by toggling continuous forward.
@ -2795,32 +2699,31 @@ void Game::toggleAutorun()
g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled)); g_settings->set("continuous_forward", bool_to_cstr(autorun_enabled));
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[autorun_enabled ? 1 : 0]; m_statustext = msg[autorun_enabled ? 1 : 0];
} }
void Game::toggleChat(bool *flag) void Game::toggleChat()
{ {
static const wchar_t *msg[] = { L"Chat hidden", L"Chat shown" }; static const wchar_t *msg[] = { L"Chat hidden", L"Chat shown" };
*flag = !*flag; flags.show_chat = !flags.show_chat;
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[*flag]; m_statustext = msg[flags.show_chat];
} }
void Game::toggleHud(bool *flag) void Game::toggleHud()
{ {
static const wchar_t *msg[] = { L"HUD hidden", L"HUD shown" }; static const wchar_t *msg[] = { L"HUD hidden", L"HUD shown" };
*flag = !*flag; flags.show_hud = !flags.show_hud;
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[*flag]; m_statustext = msg[flags.show_hud];
} }
void Game::toggleMinimap(bool *flag, void Game::toggleMinimap(bool shift_pressed)
bool show_hud, bool shift_pressed)
{ {
if (!show_hud || !g_settings->getBool("enable_minimap")) if (!flags.show_hud || !g_settings->getBool("enable_minimap"))
return; return;
if (shift_pressed) { if (shift_pressed) {
@ -2836,30 +2739,30 @@ void Game::toggleMinimap(bool *flag,
mode = (MinimapMode)((int)mode + 1); mode = (MinimapMode)((int)mode + 1);
} }
*flag = true; flags.show_minimap = true;
switch (mode) { switch (mode) {
case MINIMAP_MODE_SURFACEx1: case MINIMAP_MODE_SURFACEx1:
statustext = L"Minimap in surface mode, Zoom x1"; m_statustext = L"Minimap in surface mode, Zoom x1";
break; break;
case MINIMAP_MODE_SURFACEx2: case MINIMAP_MODE_SURFACEx2:
statustext = L"Minimap in surface mode, Zoom x2"; m_statustext = L"Minimap in surface mode, Zoom x2";
break; break;
case MINIMAP_MODE_SURFACEx4: case MINIMAP_MODE_SURFACEx4:
statustext = L"Minimap in surface mode, Zoom x4"; m_statustext = L"Minimap in surface mode, Zoom x4";
break; break;
case MINIMAP_MODE_RADARx1: case MINIMAP_MODE_RADARx1:
statustext = L"Minimap in radar mode, Zoom x1"; m_statustext = L"Minimap in radar mode, Zoom x1";
break; break;
case MINIMAP_MODE_RADARx2: case MINIMAP_MODE_RADARx2:
statustext = L"Minimap in radar mode, Zoom x2"; m_statustext = L"Minimap in radar mode, Zoom x2";
break; break;
case MINIMAP_MODE_RADARx4: case MINIMAP_MODE_RADARx4:
statustext = L"Minimap in radar mode, Zoom x4"; m_statustext = L"Minimap in radar mode, Zoom x4";
break; break;
default: default:
mode = MINIMAP_MODE_OFF; mode = MINIMAP_MODE_OFF;
*flag = false; flags.show_minimap = false;
statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ? m_statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ?
L"Minimap hidden" : L"Minimap disabled by server"; L"Minimap hidden" : L"Minimap disabled by server";
} }
@ -2867,76 +2770,77 @@ void Game::toggleMinimap(bool *flag,
mapper->setMinimapMode(mode); mapper->setMinimapMode(mode);
} }
void Game::toggleFog(bool *flag) void Game::toggleFog()
{ {
static const wchar_t *msg[] = { L"Fog enabled", L"Fog disabled" }; static const wchar_t *msg[] = { L"Fog enabled", L"Fog disabled" };
*flag = !*flag; flags.force_fog_off = !flags.force_fog_off;
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[*flag]; m_statustext = msg[flags.force_fog_off];
} }
void Game::toggleDebug(bool *show_debug, bool *show_profiler_graph, bool *show_wireframe) void Game::toggleDebug()
{ {
// Initial / 4x toggle: Chat only // Initial / 4x toggle: Chat only
// 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 (!*show_debug) { if (!flags.show_debug) {
*show_debug = true; flags.show_debug = true;
*show_profiler_graph = false; flags.show_profiler_graph = false;
*show_wireframe = false; draw_control->show_wireframe = false;
statustext = L"Debug info shown"; m_statustext = L"Debug info shown";
} else if (!*show_profiler_graph && !*show_wireframe) { } else if (!flags.show_profiler_graph && !draw_control->show_wireframe) {
*show_profiler_graph = true; flags.show_profiler_graph = true;
statustext = L"Profiler graph shown"; m_statustext = L"Profiler graph shown";
} else if (!*show_wireframe && client->checkPrivilege("debug")) { } else if (!draw_control->show_wireframe && client->checkPrivilege("debug")) {
*show_profiler_graph = false; flags.show_profiler_graph = false;
*show_wireframe = true; draw_control->show_wireframe = true;
statustext = L"Wireframe shown"; m_statustext = L"Wireframe shown";
} else { } else {
*show_debug = false; flags.show_debug = false;
*show_profiler_graph = false; flags.show_profiler_graph = false;
*show_wireframe = false; draw_control->show_wireframe = false;
if (client->checkPrivilege("debug")) { if (client->checkPrivilege("debug")) {
statustext = L"Debug info, profiler graph, and wireframe hidden"; m_statustext = L"Debug info, profiler graph, and wireframe hidden";
} else { } else {
statustext = L"Debug info and profiler graph hidden"; m_statustext = L"Debug info and profiler graph hidden";
} }
} }
runData.statustext_time = 0; runData.statustext_time = 0;
} }
void Game::toggleUpdateCamera(bool *flag) void Game::toggleUpdateCamera()
{ {
static const wchar_t *msg[] = { static const wchar_t *msg[] = {
L"Camera update enabled", L"Camera update enabled",
L"Camera update disabled" L"Camera update disabled"
}; };
*flag = !*flag; flags.disable_camera_update = !flags.disable_camera_update;
runData.statustext_time = 0; runData.statustext_time = 0;
statustext = msg[*flag]; m_statustext = msg[flags.disable_camera_update];
} }
void Game::toggleProfiler(u32 *profiler_current_page, u32 profiler_max_page) void Game::toggleProfiler()
{ {
*profiler_current_page = (*profiler_current_page + 1) % (profiler_max_page + 1); runData.profiler_current_page =
(runData.profiler_current_page + 1) % (runData.profiler_max_page + 1);
// FIXME: This updates the profiler with incomplete values // FIXME: This updates the profiler with incomplete values
update_profiler_gui(guitext_profiler, g_fontengine, *profiler_current_page, update_profiler_gui(guitext_profiler, g_fontengine, runData.profiler_current_page,
profiler_max_page, driver->getScreenSize().Height); runData.profiler_max_page, driver->getScreenSize().Height);
if (*profiler_current_page != 0) { if (runData.profiler_current_page != 0) {
std::wstringstream sstr; std::wstringstream sstr;
sstr << "Profiler shown (page " << *profiler_current_page sstr << "Profiler shown (page " << runData.profiler_current_page
<< " of " << profiler_max_page << ")"; << " of " << runData.profiler_max_page << ")";
statustext = sstr.str(); m_statustext = sstr.str();
} else { } else {
statustext = L"Profiler hidden"; m_statustext = L"Profiler hidden";
} }
runData.statustext_time = 0; runData.statustext_time = 0;
} }
@ -2949,10 +2853,10 @@ void Game::increaseViewRange()
if (range_new > 4000) { if (range_new > 4000) {
range_new = 4000; range_new = 4000;
statustext = utf8_to_wide("Viewing range is at maximum: " m_statustext = utf8_to_wide("Viewing range is at maximum: "
+ itos(range_new)); + itos(range_new));
} else { } else {
statustext = utf8_to_wide("Viewing range changed to " m_statustext = utf8_to_wide("Viewing range changed to "
+ itos(range_new)); + itos(range_new));
} }
g_settings->set("viewing_range", itos(range_new)); g_settings->set("viewing_range", itos(range_new));
@ -2967,10 +2871,10 @@ void Game::decreaseViewRange()
if (range_new < 20) { if (range_new < 20) {
range_new = 20; range_new = 20;
statustext = utf8_to_wide("Viewing range is at minimum: " m_statustext = utf8_to_wide("Viewing range is at minimum: "
+ itos(range_new)); + itos(range_new));
} else { } else {
statustext = utf8_to_wide("Viewing range changed to " m_statustext = utf8_to_wide("Viewing range changed to "
+ itos(range_new)); + itos(range_new));
} }
g_settings->set("viewing_range", itos(range_new)); g_settings->set("viewing_range", itos(range_new));
@ -2987,13 +2891,12 @@ void Game::toggleFullViewRange()
draw_control->range_all = !draw_control->range_all; draw_control->range_all = !draw_control->range_all;
infostream << msg[draw_control->range_all] << std::endl; infostream << msg[draw_control->range_all] << std::endl;
statustext = msg[draw_control->range_all]; m_statustext = msg[draw_control->range_all];
runData.statustext_time = 0; runData.statustext_time = 0;
} }
void Game::updateCameraDirection(CameraOrientation *cam, void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
VolatileRunFlags *flags, float dtime)
{ {
if ((device->isWindowActive() && noMenuActive()) || random_input) { if ((device->isWindowActive() && noMenuActive()) || random_input) {
@ -3005,10 +2908,10 @@ void Game::updateCameraDirection(CameraOrientation *cam,
} }
#endif #endif
if (flags->first_loop_after_window_activation) if (m_first_loop_after_window_activation)
flags->first_loop_after_window_activation = false; m_first_loop_after_window_activation = false;
else else
updateCameraOrientation(cam, *flags, dtime); updateCameraOrientation(cam, dtime);
input->setMousePos((driver->getScreenSize().Width / 2), input->setMousePos((driver->getScreenSize().Width / 2),
(driver->getScreenSize().Height / 2)); (driver->getScreenSize().Height / 2));
@ -3016,18 +2919,17 @@ void Game::updateCameraDirection(CameraOrientation *cam,
#ifndef ANDROID #ifndef ANDROID
// Mac OSX gets upset if this is set every frame // Mac OSX gets upset if this is set every frame
if (device->getCursorControl()->isVisible() == false) if (!device->getCursorControl()->isVisible())
device->getCursorControl()->setVisible(true); device->getCursorControl()->setVisible(true);
#endif #endif
if (!flags->first_loop_after_window_activation) if (!m_first_loop_after_window_activation)
flags->first_loop_after_window_activation = true; m_first_loop_after_window_activation = true;
} }
} }
void Game::updateCameraOrientation(CameraOrientation *cam, void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
const VolatileRunFlags &flags, float dtime)
{ {
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
if (g_touchscreengui) { if (g_touchscreengui) {
@ -3039,8 +2941,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam,
s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2); s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2);
s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2); s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2);
if (flags.invert_mouse if (m_invert_mouse || camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT) {
|| camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT) {
dy = -dy; dy = -dy;
} }
@ -3053,10 +2954,8 @@ void Game::updateCameraOrientation(CameraOrientation *cam,
if (m_cache_enable_joysticks) { if (m_cache_enable_joysticks) {
f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime; f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime;
cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * c;
c; cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c;
cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) *
c;
} }
cam->camera_pitch = rangelim(cam->camera_pitch, -89.5, 89.5); cam->camera_pitch = rangelim(cam->camera_pitch, -89.5, 89.5);
@ -3355,7 +3254,7 @@ void Game::processClientEvents(CameraOrientation *cam)
} }
void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime) void Game::updateCamera(u32 busy_time, f32 dtime)
{ {
LocalPlayer *player = client->getEnv().getLocalPlayer(); LocalPlayer *player = client->getEnv().getLocalPlayer();
@ -3411,13 +3310,13 @@ void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime)
f32 camera_fov = camera->getFovMax(); f32 camera_fov = camera->getFovMax();
v3s16 camera_offset = camera->getOffset(); v3s16 camera_offset = camera->getOffset();
flags->camera_offset_changed = (camera_offset != old_camera_offset); m_camera_offset_changed = (camera_offset != old_camera_offset);
if (!flags->disable_camera_update) { if (!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);
if (flags->camera_offset_changed) { if (m_camera_offset_changed) {
client->updateCameraOffset(camera_offset); client->updateCameraOffset(camera_offset);
client->getEnv().updateCameraOffset(camera_offset); client->getEnv().updateCameraOffset(camera_offset);
@ -3511,9 +3410,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
PointedThing pointed = updatePointedThing(shootline, PointedThing pointed = updatePointedThing(shootline,
playeritem_def.liquids_pointable, playeritem_def.liquids_pointable,
!runData.ldown_for_dig, !runData.ldown_for_dig,
camera_offset, camera_offset);
// output
runData.selected_object);
if (pointed != runData.pointed_old) { if (pointed != runData.pointed_old) {
infostream << "Pointing at " << pointed.dump() << std::endl; infostream << "Pointing at " << pointed.dump() << std::endl;
@ -3604,8 +3501,7 @@ PointedThing Game::updatePointedThing(
const core::line3d<f32> &shootline, const core::line3d<f32> &shootline,
bool liquids_pointable, bool liquids_pointable,
bool look_for_object, bool look_for_object,
const v3s16 &camera_offset, const v3s16 &camera_offset)
ClientActiveObject *&selected_object)
{ {
std::vector<aabb3f> *selectionboxes = hud->getSelectionBoxes(); std::vector<aabb3f> *selectionboxes = hud->getSelectionBoxes();
selectionboxes->clear(); selectionboxes->clear();
@ -3616,21 +3512,21 @@ PointedThing Game::updatePointedThing(
ClientMap &map = client->getEnv().getClientMap(); ClientMap &map = client->getEnv().getClientMap();
INodeDefManager *nodedef=client->getNodeDefManager(); INodeDefManager *nodedef=client->getNodeDefManager();
selected_object = NULL; runData.selected_object = NULL;
PointedThing result=client->getEnv().getPointedThing( PointedThing result=client->getEnv().getPointedThing(
shootline, liquids_pointable, look_for_object); shootline, liquids_pointable, look_for_object);
if (result.type == POINTEDTHING_OBJECT) { if (result.type == POINTEDTHING_OBJECT) {
selected_object = client->getEnv().getActiveObject(result.object_id); runData.selected_object = client->getEnv().getActiveObject(result.object_id);
if (show_entity_selectionbox && selected_object->doShowSelectionBox()) { if (show_entity_selectionbox && runData.selected_object->doShowSelectionBox()) {
aabb3f *selection_box = selected_object->getSelectionBox(); aabb3f *selection_box = runData.selected_object->getSelectionBox();
// Box should exist because object was // Box should exist because object was
// returned in the first place // returned in the first place
assert(selection_box); assert(selection_box);
v3f pos = selected_object->getPosition(); v3f pos = runData.selected_object->getPosition();
selectionboxes->push_back(aabb3f( selectionboxes->push_back(aabb3f(
selection_box->MinEdge, selection_box->MaxEdge)); selection_box->MinEdge, selection_box->MaxEdge));
selectionboxes->push_back( selectionboxes->push_back(
@ -3981,7 +3877,7 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
const VolatileRunFlags &flags, const CameraOrientation &cam) const CameraOrientation &cam)
{ {
LocalPlayer *player = client->getEnv().getLocalPlayer(); LocalPlayer *player = client->getEnv().getLocalPlayer();
@ -4015,13 +3911,11 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
/ 255.0; / 255.0;
} }
float time_of_day = runData.time_of_day;
float time_of_day_smooth = runData.time_of_day_smooth; float time_of_day_smooth = runData.time_of_day_smooth;
float time_of_day = client->getEnv().getTimeOfDayF();
time_of_day = client->getEnv().getTimeOfDayF(); static const float maxsm = 0.05;
static const float todsm = 0.05;
const float maxsm = 0.05;
const float todsm = 0.05;
if (fabs(time_of_day - time_of_day_smooth) > maxsm && if (fabs(time_of_day - time_of_day_smooth) > maxsm &&
fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm && fabs(time_of_day - time_of_day_smooth + 1.0) > maxsm &&
@ -4138,13 +4032,13 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
v3f camera_direction = camera->getDirection(); v3f camera_direction = camera->getDirection();
if (runData.update_draw_list_timer >= 0.2 if (runData.update_draw_list_timer >= 0.2
|| runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2 || runData.update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2
|| flags.camera_offset_changed) { || m_camera_offset_changed) {
runData.update_draw_list_timer = 0; runData.update_draw_list_timer = 0;
client->getEnv().getClientMap().updateDrawList(driver); client->getEnv().getClientMap().updateDrawList(driver);
runData.update_draw_list_last_cam_dir = camera_direction; runData.update_draw_list_last_cam_dir = camera_direction;
} }
updateGui(*stats, dtime, flags, cam); updateGui(*stats, dtime, cam);
/* /*
make sure menu is on top make sure menu is on top
@ -4167,11 +4061,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
video::SColor skycolor = sky->getSkyColor(); video::SColor skycolor = sky->getSkyColor();
TimeTaker tt_draw("mainloop: draw"); TimeTaker tt_draw("mainloop: draw");
{ driver->beginScene(true, true, skycolor);
TimeTaker timer("beginScene");
driver->beginScene(true, true, skycolor);
stats->beginscenetime = timer.stop(true);
}
draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper, draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper,
guienv, screensize, skycolor, flags.show_hud, guienv, screensize, skycolor, flags.show_hud,
@ -4216,11 +4106,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
/* /*
End scene End scene
*/ */
{ driver->endScene();
TimeTaker timer("endScene");
driver->endScene();
stats->endscenetime = timer.stop(true);
}
stats->drawtime = tt_draw.stop(true); stats->drawtime = tt_draw.stop(true);
g_profiler->graphAdd("mainloop_draw", stats->drawtime / 1000.0f); g_profiler->graphAdd("mainloop_draw", stats->drawtime / 1000.0f);
@ -4238,8 +4124,7 @@ inline static const char *yawToDirectionString(int yaw)
} }
void Game::updateGui(const RunStats &stats, f32 dtime, const VolatileRunFlags &flags, void Game::updateGui(const RunStats &stats, f32 dtime, const CameraOrientation &cam)
const CameraOrientation &cam)
{ {
v2u32 screensize = driver->getScreenSize(); v2u32 screensize = driver->getScreenSize();
LocalPlayer *player = client->getEnv().getLocalPlayer(); LocalPlayer *player = client->getEnv().getLocalPlayer();
@ -4319,19 +4204,19 @@ void Game::updateGui(const RunStats &stats, f32 dtime, const VolatileRunFlags &f
float statustext_time_max = 1.5; float statustext_time_max = 1.5;
if (!statustext.empty()) { if (!m_statustext.empty()) {
runData.statustext_time += dtime; runData.statustext_time += dtime;
if (runData.statustext_time >= statustext_time_max) { if (runData.statustext_time >= statustext_time_max) {
statustext = L""; m_statustext = L"";
runData.statustext_time = 0; runData.statustext_time = 0;
} }
} }
setStaticText(guitext_status, statustext.c_str()); setStaticText(guitext_status, m_statustext.c_str());
guitext_status->setVisible(!statustext.empty()); guitext_status->setVisible(!m_statustext.empty());
if (!statustext.empty()) { if (!m_statustext.empty()) {
s32 status_width = guitext_status->getTextWidth(); s32 status_width = guitext_status->getTextWidth();
s32 status_height = guitext_status->getTextHeight(); s32 status_height = guitext_status->getTextHeight();
s32 status_y = screensize.Y - 150; s32 status_y = screensize.Y - 150;
@ -4485,6 +4370,75 @@ void Game::extendedResourceCleanup()
<< " (note: irrlicht doesn't support removing renderers)" << std::endl; << " (note: irrlicht doesn't support removing renderers)" << std::endl;
} }
void Game::showPauseMenu()
{
#ifdef __ANDROID__
static const std::string control_text = strgettext("Default Controls:\n"
"No menu visible:\n"
"- single tap: button activate\n"
"- double tap: place/use\n"
"- slide finger: look around\n"
"Menu/Inventory visible:\n"
"- double tap (outside):\n"
" -->close\n"
"- touch stack, touch slot:\n"
" --> move stack\n"
"- touch&drag, tap 2nd finger\n"
" --> place single item to slot\n"
);
#else
static const std::string control_text = strgettext("Default Controls:\n"
"- WASD: move\n"
"- Space: jump/climb\n"
"- Shift: sneak/go down\n"
"- Q: drop item\n"
"- I: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
"- T: chat\n"
);
#endif
float ypos = simple_singleplayer_mode ? 0.5 : 0.1;
std::ostringstream os;
os << FORMSPEC_VERSION_STRING << SIZE_TAG
<< "button_exit[4," << (ypos++) << ";3,0.5;btn_continue;"
<< strgettext("Continue") << "]";
if (!simple_singleplayer_mode) {
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;"
<< strgettext("Change Password") << "]";
}
#ifndef __ANDROID__
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_sound;"
<< strgettext("Sound Volume") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_key_config;"
<< strgettext("Change Keys") << "]";
#endif
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_menu;"
<< strgettext("Exit to Menu") << "]";
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"
<< strgettext("Exit to OS") << "]"
<< "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]"
<< "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n"
<< g_build_info << "\n"
<< "path_user = " << wrap_rows(porting::path_user, 20)
<< "\n;]";
/* Create menu */
/* Note: FormspecFormSource and LocalFormspecHandler *
* are deleted by guiFormSpecMenu */
FormspecFormSource *fs_src = new FormspecFormSource(os.str());
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
create_formspec_menu(&current_formspec, client, device, &input->joystick, fs_src, txt_dst);
current_formspec->setFocus("btn_continue");
current_formspec->doPause = true;
}
/****************************************************************************/ /****************************************************************************/
/**************************************************************************** /****************************************************************************

View File

@ -143,6 +143,18 @@ public:
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,

View File

@ -335,7 +335,7 @@ public:
void removeChildren(); void removeChildren();
void setInitialFocus(); void setInitialFocus();
void setFocus(std::string &elementname) void setFocus(const std::string &elementname)
{ {
m_focused_element = elementname; m_focused_element = elementname;
} }

View File

@ -118,21 +118,31 @@ int LuaMinimap::l_toggle_shape(lua_State *L)
int LuaMinimap::l_show(lua_State *L) int LuaMinimap::l_show(lua_State *L)
{ {
Client *client = getClient(L);
assert(client);
LuaMinimap *ref = checkobject(L, 1); LuaMinimap *ref = checkobject(L, 1);
Minimap *m = getobject(ref); Minimap *m = getobject(ref);
if (m->getMinimapMode() == MINIMAP_MODE_OFF) if (m->getMinimapMode() == MINIMAP_MODE_OFF)
m->setMinimapMode(MINIMAP_MODE_SURFACEx1); m->setMinimapMode(MINIMAP_MODE_SURFACEx1);
client->showMinimap(true);
return 1; return 1;
} }
int LuaMinimap::l_hide(lua_State *L) int LuaMinimap::l_hide(lua_State *L)
{ {
Client *client = getClient(L);
assert(client);
LuaMinimap *ref = checkobject(L, 1); LuaMinimap *ref = checkobject(L, 1);
Minimap *m = getobject(ref); Minimap *m = getobject(ref);
if (m->getMinimapMode() != MINIMAP_MODE_OFF) if (m->getMinimapMode() != MINIMAP_MODE_OFF)
m->setMinimapMode(MINIMAP_MODE_OFF); m->setMinimapMode(MINIMAP_MODE_OFF);
client->showMinimap(false);
return 1; return 1;
} }