Game refactor [4/X]: keycache is now owned by InputHandler
authorLoic Blot <loic.blot@unix-experience.fr>
Sat, 13 Jan 2018 09:54:18 +0000 (10:54 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 20 Jan 2018 15:38:38 +0000 (16:38 +0100)
* Make InputHandler own the key cache
* Add a helper function InputHandler::cancelPressed to avoid multiple similar calls in game.cpp
* Move RandomInputHandler::step definition into cpp file

build/android/jni/Android.mk
src/client/inputhandler.cpp
src/client/inputhandler.h
src/game.cpp
src/gui/guiFormSpecMenu.cpp
src/gui/guiFormSpecMenu.h
src/gui/profilergraph.cpp
src/gui/profilergraph.h

index 72be8fe2c683e9882aa09a4b09b659f04dd89ca4..dd8aadf99b576b2235f20c7a0b9626190ceec248 100644 (file)
@@ -158,6 +158,7 @@ LOCAL_SRC_FILES := \
                jni/src/gui/guiTable.cpp                  \
                jni/src/guiscalingfilter.cpp              \
                jni/src/gui/guiVolumeChange.cpp           \
+               jni/src/gui/profilergraph.cpp             \
                jni/src/httpfetch.cpp                     \
                jni/src/hud.cpp                           \
                jni/src/imagefilters.cpp                  \
index 3b01f5d93ea520e4bb2837981b28cd4403f39ef2..95d9fef718da716e4626d5686c4bacd1af7f045d 100644 (file)
@@ -29,57 +29,51 @@ void KeyCache::populate_nonchanging()
 
 void KeyCache::populate()
 {
-       key[KeyType::FORWARD]      = getKeySetting("keymap_forward");
-       key[KeyType::BACKWARD]     = getKeySetting("keymap_backward");
-       key[KeyType::LEFT]         = getKeySetting("keymap_left");
-       key[KeyType::RIGHT]        = getKeySetting("keymap_right");
-       key[KeyType::JUMP]         = getKeySetting("keymap_jump");
-       key[KeyType::SPECIAL1]     = getKeySetting("keymap_special1");
-       key[KeyType::SNEAK]        = getKeySetting("keymap_sneak");
-
-       key[KeyType::AUTOFORWARD]  = getKeySetting("keymap_autoforward");
-
-       key[KeyType::DROP]         = getKeySetting("keymap_drop");
-       key[KeyType::INVENTORY]    = getKeySetting("keymap_inventory");
-       key[KeyType::CHAT]         = getKeySetting("keymap_chat");
-       key[KeyType::CMD]          = getKeySetting("keymap_cmd");
-       key[KeyType::CMD_LOCAL]    = getKeySetting("keymap_cmd_local");
-       key[KeyType::CONSOLE]      = getKeySetting("keymap_console");
-       key[KeyType::MINIMAP]      = getKeySetting("keymap_minimap");
-       key[KeyType::FREEMOVE]     = getKeySetting("keymap_freemove");
-       key[KeyType::FASTMOVE]     = getKeySetting("keymap_fastmove");
-       key[KeyType::NOCLIP]       = getKeySetting("keymap_noclip");
-       key[KeyType::HOTBAR_PREV]  = getKeySetting("keymap_hotbar_previous");
-       key[KeyType::HOTBAR_NEXT]  = getKeySetting("keymap_hotbar_next");
-       key[KeyType::MUTE]         = getKeySetting("keymap_mute");
-       key[KeyType::INC_VOLUME]   = getKeySetting("keymap_increase_volume");
-       key[KeyType::DEC_VOLUME]   = getKeySetting("keymap_decrease_volume");
-       key[KeyType::CINEMATIC]    = getKeySetting("keymap_cinematic");
-       key[KeyType::SCREENSHOT]   = getKeySetting("keymap_screenshot");
-       key[KeyType::TOGGLE_HUD]   = getKeySetting("keymap_toggle_hud");
-       key[KeyType::TOGGLE_CHAT]  = getKeySetting("keymap_toggle_chat");
-       key[KeyType::TOGGLE_FORCE_FOG_OFF]
-               = getKeySetting("keymap_toggle_force_fog_off");
-       key[KeyType::TOGGLE_UPDATE_CAMERA]
-               = getKeySetting("keymap_toggle_update_camera");
-       key[KeyType::TOGGLE_DEBUG]
-               = getKeySetting("keymap_toggle_debug");
-       key[KeyType::TOGGLE_PROFILER]
-               = getKeySetting("keymap_toggle_profiler");
-       key[KeyType::CAMERA_MODE]
-               = getKeySetting("keymap_camera_mode");
-       key[KeyType::INCREASE_VIEWING_RANGE]
-               = getKeySetting("keymap_increase_viewing_range_min");
-       key[KeyType::DECREASE_VIEWING_RANGE]
-               = getKeySetting("keymap_decrease_viewing_range_min");
-       key[KeyType::RANGESELECT]
-               = getKeySetting("keymap_rangeselect");
+       key[KeyType::FORWARD] = getKeySetting("keymap_forward");
+       key[KeyType::BACKWARD] = getKeySetting("keymap_backward");
+       key[KeyType::LEFT] = getKeySetting("keymap_left");
+       key[KeyType::RIGHT] = getKeySetting("keymap_right");
+       key[KeyType::JUMP] = getKeySetting("keymap_jump");
+       key[KeyType::SPECIAL1] = getKeySetting("keymap_special1");
+       key[KeyType::SNEAK] = getKeySetting("keymap_sneak");
+
+       key[KeyType::AUTOFORWARD] = getKeySetting("keymap_autoforward");
+
+       key[KeyType::DROP] = getKeySetting("keymap_drop");
+       key[KeyType::INVENTORY] = getKeySetting("keymap_inventory");
+       key[KeyType::CHAT] = getKeySetting("keymap_chat");
+       key[KeyType::CMD] = getKeySetting("keymap_cmd");
+       key[KeyType::CMD_LOCAL] = getKeySetting("keymap_cmd_local");
+       key[KeyType::CONSOLE] = getKeySetting("keymap_console");
+       key[KeyType::MINIMAP] = getKeySetting("keymap_minimap");
+       key[KeyType::FREEMOVE] = getKeySetting("keymap_freemove");
+       key[KeyType::FASTMOVE] = getKeySetting("keymap_fastmove");
+       key[KeyType::NOCLIP] = getKeySetting("keymap_noclip");
+       key[KeyType::HOTBAR_PREV] = getKeySetting("keymap_hotbar_previous");
+       key[KeyType::HOTBAR_NEXT] = getKeySetting("keymap_hotbar_next");
+       key[KeyType::MUTE] = getKeySetting("keymap_mute");
+       key[KeyType::INC_VOLUME] = getKeySetting("keymap_increase_volume");
+       key[KeyType::DEC_VOLUME] = getKeySetting("keymap_decrease_volume");
+       key[KeyType::CINEMATIC] = getKeySetting("keymap_cinematic");
+       key[KeyType::SCREENSHOT] = getKeySetting("keymap_screenshot");
+       key[KeyType::TOGGLE_HUD] = getKeySetting("keymap_toggle_hud");
+       key[KeyType::TOGGLE_CHAT] = getKeySetting("keymap_toggle_chat");
+       key[KeyType::TOGGLE_FORCE_FOG_OFF] = getKeySetting("keymap_toggle_force_fog_off");
+       key[KeyType::TOGGLE_UPDATE_CAMERA] = getKeySetting("keymap_toggle_update_camera");
+       key[KeyType::TOGGLE_DEBUG] = getKeySetting("keymap_toggle_debug");
+       key[KeyType::TOGGLE_PROFILER] = getKeySetting("keymap_toggle_profiler");
+       key[KeyType::CAMERA_MODE] = getKeySetting("keymap_camera_mode");
+       key[KeyType::INCREASE_VIEWING_RANGE] =
+                       getKeySetting("keymap_increase_viewing_range_min");
+       key[KeyType::DECREASE_VIEWING_RANGE] =
+                       getKeySetting("keymap_decrease_viewing_range_min");
+       key[KeyType::RANGESELECT] = getKeySetting("keymap_rangeselect");
        key[KeyType::ZOOM] = getKeySetting("keymap_zoom");
 
        key[KeyType::QUICKTUNE_NEXT] = getKeySetting("keymap_quicktune_next");
        key[KeyType::QUICKTUNE_PREV] = getKeySetting("keymap_quicktune_prev");
-       key[KeyType::QUICKTUNE_INC]  = getKeySetting("keymap_quicktune_inc");
-       key[KeyType::QUICKTUNE_DEC]  = getKeySetting("keymap_quicktune_dec");
+       key[KeyType::QUICKTUNE_INC] = getKeySetting("keymap_quicktune_inc");
+       key[KeyType::QUICKTUNE_DEC] = getKeySetting("keymap_quicktune_dec");
 
        for (int i = 0; i < 23; i++) {
                std::string slot_key_name = "keymap_slot" + std::to_string(i + 1);
@@ -191,3 +185,72 @@ s32 RandomInputHandler::Rand(s32 min, s32 max)
 {
        return (myrand() % (max - min + 1)) + min;
 }
+
+void RandomInputHandler::step(float dtime)
+{
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 40);
+                       keydown.toggle(getKeySetting("keymap_jump"));
+               }
+       }
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 40);
+                       keydown.toggle(getKeySetting("keymap_special1"));
+               }
+       }
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 40);
+                       keydown.toggle(getKeySetting("keymap_forward"));
+               }
+       }
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 40);
+                       keydown.toggle(getKeySetting("keymap_left"));
+               }
+       }
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 20);
+                       mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
+               }
+       }
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 30);
+                       leftdown = !leftdown;
+                       if (leftdown)
+                               leftclicked = true;
+                       if (!leftdown)
+                               leftreleased = true;
+               }
+       }
+       {
+               static float counter1 = 0;
+               counter1 -= dtime;
+               if (counter1 < 0.0) {
+                       counter1 = 0.1 * Rand(1, 15);
+                       rightdown = !rightdown;
+                       if (rightdown)
+                               rightclicked = true;
+                       if (!rightdown)
+                               rightreleased = true;
+               }
+       }
+       mousepos += mousespeed;
+}
index 91c1111345e6964481fbdc20e48cd61cee83af91..9be2a2ed4df1042bedc4492591e4ba48bc83a0b4 100644 (file)
@@ -42,7 +42,8 @@ class InputHandler;
  * (up to 10x faster) key lookup is an asset. Other parts of the codebase
  * (e.g. formspecs) should continue using getKeySetting().
  */
-struct KeyCache {
+struct KeyCache
+{
 
        KeyCache()
        {
@@ -210,12 +211,17 @@ private:
 class InputHandler
 {
 public:
-       InputHandler() = default;
+       InputHandler()
+       {
+               keycache.handler = this;
+               keycache.populate();
+       }
 
        virtual ~InputHandler() = default;
 
-       virtual bool isKeyDown(const KeyPress &keyCode) = 0;
-       virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
+       virtual bool isKeyDown(GameKeyType k) = 0;
+       virtual bool wasKeyDown(GameKeyType k) = 0;
+       virtual bool cancelPressed() = 0;
 
        virtual void listenForKey(const KeyPress &keyCode) {}
        virtual void dontListenForKeys() {}
@@ -243,6 +249,7 @@ public:
        virtual void clear() {}
 
        JoystickController joystick;
+       KeyCache keycache;
 };
 /*
        Separated input handler
@@ -255,13 +262,17 @@ public:
        {
                m_receiver->joystick = &joystick;
        }
-       virtual bool isKeyDown(const KeyPress &keyCode)
+       virtual bool isKeyDown(GameKeyType k)
+       {
+               return m_receiver->IsKeyDown(keycache.key[k]) || joystick.isKeyDown(k);
+       }
+       virtual bool wasKeyDown(GameKeyType k)
        {
-               return m_receiver->IsKeyDown(keyCode);
+               return m_receiver->WasKeyDown(keycache.key[k]) || joystick.wasKeyDown(k);
        }
-       virtual bool wasKeyDown(const KeyPress &keyCode)
+       virtual bool cancelPressed()
        {
-               return m_receiver->WasKeyDown(keyCode);
+               return wasKeyDown(KeyType::ESC) || m_receiver->WasKeyDown(CancelKey);
        }
        virtual void listenForKey(const KeyPress &keyCode)
        {
@@ -301,11 +312,13 @@ public:
 
        virtual bool getLeftClicked()
        {
-               return m_receiver->leftclicked || joystick.getWasKeyDown(KeyType::MOUSE_L);
+               return m_receiver->leftclicked ||
+                      joystick.getWasKeyDown(KeyType::MOUSE_L);
        }
        virtual bool getRightClicked()
        {
-               return m_receiver->rightclicked || joystick.getWasKeyDown(KeyType::MOUSE_R);
+               return m_receiver->rightclicked ||
+                      joystick.getWasKeyDown(KeyType::MOUSE_R);
        }
 
        virtual void resetLeftClicked()
@@ -313,18 +326,21 @@ public:
                m_receiver->leftclicked = false;
                joystick.clearWasKeyDown(KeyType::MOUSE_L);
        }
-       virtual void resetRightClicked() {
+       virtual void resetRightClicked()
+       {
                m_receiver->rightclicked = false;
                joystick.clearWasKeyDown(KeyType::MOUSE_R);
        }
 
        virtual bool getLeftReleased()
        {
-               return m_receiver->leftreleased || joystick.wasKeyReleased(KeyType::MOUSE_L);
+               return m_receiver->leftreleased ||
+                      joystick.wasKeyReleased(KeyType::MOUSE_L);
        }
        virtual bool getRightReleased()
        {
-               return m_receiver->rightreleased || joystick.wasKeyReleased(KeyType::MOUSE_R);
+               return m_receiver->rightreleased ||
+                      joystick.wasKeyReleased(KeyType::MOUSE_R);
        }
 
        virtual void resetLeftReleased()
@@ -356,8 +372,9 @@ class RandomInputHandler : public InputHandler
 public:
        RandomInputHandler() = default;
 
-       virtual bool isKeyDown(const KeyPress &keyCode) { return keydown[keyCode]; }
-       virtual bool wasKeyDown(const KeyPress &keyCode) { return false; }
+       virtual bool isKeyDown(GameKeyType k) { return keydown[keycache.key[k]]; }
+       virtual bool wasKeyDown(GameKeyType k) { return false; }
+       virtual bool cancelPressed() { return false; }
        virtual v2s32 getMousePos() { return mousepos; }
        virtual void setMousePos(s32 x, s32 y) { mousepos = v2s32(x, y); }
 
@@ -376,74 +393,7 @@ public:
 
        virtual s32 getMouseWheel() { return 0; }
 
-       virtual void step(float dtime)
-       {
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 40);
-                               keydown.toggle(getKeySetting("keymap_jump"));
-                       }
-               }
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 40);
-                               keydown.toggle(getKeySetting("keymap_special1"));
-                       }
-               }
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 40);
-                               keydown.toggle(getKeySetting("keymap_forward"));
-                       }
-               }
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 40);
-                               keydown.toggle(getKeySetting("keymap_left"));
-                       }
-               }
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 20);
-                               mousespeed = v2s32(Rand(-20, 20), Rand(-15, 20));
-                       }
-               }
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 30);
-                               leftdown = !leftdown;
-                               if (leftdown)
-                                       leftclicked = true;
-                               if (!leftdown)
-                                       leftreleased = true;
-                       }
-               }
-               {
-                       static float counter1 = 0;
-                       counter1 -= dtime;
-                       if (counter1 < 0.0) {
-                               counter1 = 0.1 * Rand(1, 15);
-                               rightdown = !rightdown;
-                               if (rightdown)
-                                       rightclicked = true;
-                               if (!rightdown)
-                                       rightreleased = true;
-                       }
-               }
-               mousepos += mousespeed;
-       }
+       virtual void step(float dtime);
 
        s32 Rand(s32 min, s32 max);
 
index ff348a47bc2e19d70c463925a222a9608e2e3efa..55b2f5204f40d2eff08004848e8b3bc3c93ea1c6 100644 (file)
@@ -757,11 +757,11 @@ protected:
 
        inline bool isKeyDown(GameKeyType k)
        {
-               return input->isKeyDown(keycache.key[k]) || input->joystick.isKeyDown(k);
+               return input->isKeyDown(k);
        }
        inline bool wasKeyDown(GameKeyType k)
        {
-               return input->wasKeyDown(keycache.key[k]) || input->joystick.wasKeyDown(k);
+               return input->wasKeyDown(k);
        }
 
 #ifdef __ANDROID__
@@ -859,8 +859,6 @@ private:
         */
        int crack_animation_length;
 
-       KeyCache keycache;
-
        IntervalLimiter profiler_interval;
 
        /*
@@ -1008,8 +1006,7 @@ bool Game::startup(bool *kill,
        this->chat_backend        = chat_backend;
        this->simple_singleplayer_mode = simple_singleplayer_mode;
 
-       keycache.handler = input;
-       keycache.populate();
+       input->keycache.populate();
 
        driver = device->getVideoDriver();
        smgr = RenderingEngine::get_scene_manager();
@@ -1521,7 +1518,7 @@ bool Game::connectToServer(const std::string &playername,
                                break;
                        }
 
-                       if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
+                       if (input->cancelPressed()) {
                                *connection_aborted = true;
                                infostream << "Connect aborted [Escape]" << std::endl;
                                break;
@@ -1593,7 +1590,7 @@ bool Game::getServerContent(bool *aborted)
                        return false;
                }
 
-               if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
+               if (input->cancelPressed()) {
                        *aborted = true;
                        infostream << "Connect aborted [Escape]" << std::endl;
                        return false;
@@ -1706,7 +1703,7 @@ inline bool Game::handleCallbacks()
        }
 
        if (g_gamecallback->keyconfig_changed) {
-               keycache.populate(); // update the cache with new settings
+               input->keycache.populate(); // update the cache with new settings
                g_gamecallback->keyconfig_changed = false;
        }
 
@@ -1865,7 +1862,7 @@ void Game::processKeyInput()
                toggleAutoforward();
        } else if (wasKeyDown(KeyType::INVENTORY)) {
                openInventory();
-       } else if (wasKeyDown(KeyType::ESC) || input->wasKeyDown(CancelKey)) {
+       } else if (input->cancelPressed()) {
                if (!gui_chat_console->isOpenInhibited()) {
                        showPauseMenu();
                }
@@ -2030,7 +2027,7 @@ void Game::openInventory()
        if (!client->moddingEnabled()
                        || !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
                TextDest *txt_dst = new TextDestPlayerInventory(client);
-               GUIFormSpecMenu::create(&current_formspec, client, &input->joystick, fs_src,
+               GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src,
                        txt_dst);
                cur_formname = "";
                current_formspec->setFormSpec(fs_src->getForm(), inventoryloc);
@@ -2396,10 +2393,10 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
        // distinguish between the two in order to know when to use joysticks.
 
        PlayerControl control(
-               input->isKeyDown(keycache.key[KeyType::FORWARD]),
-               input->isKeyDown(keycache.key[KeyType::BACKWARD]),
-               input->isKeyDown(keycache.key[KeyType::LEFT]),
-               input->isKeyDown(keycache.key[KeyType::RIGHT]),
+               input->isKeyDown(KeyType::FORWARD),
+               input->isKeyDown(KeyType::BACKWARD),
+               input->isKeyDown(KeyType::LEFT),
+               input->isKeyDown(KeyType::RIGHT),
                isKeyDown(KeyType::JUMP),
                isKeyDown(KeyType::SPECIAL1),
                isKeyDown(KeyType::SNEAK),
@@ -2535,7 +2532,7 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
                TextDestPlayerInventory *txt_dst =
                        new TextDestPlayerInventory(client, *(event->show_formspec.formname));
 
-               GUIFormSpecMenu::create(&current_formspec, client, &input->joystick,
+               GUIFormSpecMenu::create(current_formspec, client, &input->joystick,
                        fs_src, txt_dst);
                cur_formname = *(event->show_formspec.formname);
        }
@@ -2549,7 +2546,7 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
        FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec);
        LocalFormspecHandler *txt_dst =
                new LocalFormspecHandler(*event->show_formspec.formname, client);
-       GUIFormSpecMenu::create(&current_formspec, client, &input->joystick, fs_src, txt_dst);
+       GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src, txt_dst);
 
        delete event->show_formspec.formspec;
        delete event->show_formspec.formname;
@@ -3213,7 +3210,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
                                &client->getEnv().getClientMap(), nodepos);
                        TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
 
-                       GUIFormSpecMenu::create(&current_formspec, client, &input->joystick, fs_src,
+                       GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src,
                                txt_dst);
                        cur_formname.clear();
 
@@ -4110,7 +4107,7 @@ void Game::showPauseMenu()
        FormspecFormSource *fs_src = new FormspecFormSource(os.str());
        LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
 
-       GUIFormSpecMenu::create(&current_formspec, client, &input->joystick, fs_src, txt_dst);
+       GUIFormSpecMenu::create(current_formspec, client, &input->joystick, fs_src, txt_dst);
        current_formspec->setFocus("btn_continue");
        current_formspec->doPause = true;
 }
index 4acc4b94a23baa67998a5c33a10eebeb22a50271..89cf19973cc227009eca2ae8b6239553782693a2 100644 (file)
@@ -44,6 +44,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "gettime.h"
 #include "gettext.h"
 #include "scripting_server.h"
+#include "mainmenumanager.h"
 #include "porting.h"
 #include "settings.h"
 #include "client.h"
@@ -131,13 +132,13 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
        delete m_text_dst;
 }
 
-void GUIFormSpecMenu::create(GUIFormSpecMenu **cur_formspec, Client *client,
+void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
        JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest)
 {
-       if (*cur_formspec == 0) {
-               *cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
+       if (cur_formspec == nullptr) {
+               cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
                        client, client->getTextureSource(), fs_src, txt_dest);
-               (*cur_formspec)->doPause = false;
+               cur_formspec->doPause = false;
 
                /*
                        Caution: do not call (*cur_formspec)->drop() here --
@@ -148,8 +149,8 @@ void GUIFormSpecMenu::create(GUIFormSpecMenu **cur_formspec, Client *client,
                */
 
        } else {
-               (*cur_formspec)->setFormSource(fs_src);
-               (*cur_formspec)->setTextDest(txt_dest);
+               cur_formspec->setFormSource(fs_src);
+               cur_formspec->setTextDest(txt_dest);
        }
 }
 
index 9cd98f8068c97f495f96cc6dea5c66008624d228..8b16f24cf52537702808987e27727d6232291798 100644 (file)
@@ -291,7 +291,7 @@ public:
 
        ~GUIFormSpecMenu();
 
-       static void create(GUIFormSpecMenu **cur_formspec, Client *client,
+       static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
                JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest);
 
        void setFormSpec(const std::string &formspec_string,
index 314796106a5fdcdba20b7b428df5e560f4253052..740dfa35c95b05927ad1f502a5d38a19cd01aae6 100644 (file)
@@ -30,7 +30,7 @@ void ProfilerGraph::put(const Profiler::GraphValues &values)
 }
 
 void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
-       gui::IGUIFont *font) const
+               gui::IGUIFont *font) const
 {
        // Do *not* use UNORDERED_MAP here as the order needs
        // to be the same for each call to prevent flickering
@@ -56,15 +56,13 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
        }
 
        // Assign colors
-       static const video::SColor usable_colors[] = {
-               video::SColor(255, 255, 100, 100),
-               video::SColor(255, 90, 225, 90),
-               video::SColor(255, 100, 100, 255),
-               video::SColor(255, 255, 150, 50),
-               video::SColor(255, 220, 220, 100)
-       };
+       static const video::SColor usable_colors[] = {video::SColor(255, 255, 100, 100),
+                       video::SColor(255, 90, 225, 90),
+                       video::SColor(255, 100, 100, 255),
+                       video::SColor(255, 255, 150, 50),
+                       video::SColor(255, 220, 220, 100)};
        static const u32 usable_colors_count =
-               sizeof(usable_colors) / sizeof(*usable_colors);
+                       sizeof(usable_colors) / sizeof(*usable_colors);
        u32 next_color_i = 0;
 
        for (auto &i : m_meta) {
@@ -82,7 +80,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
        s32 textx2 = textx + 200 - 15;
        s32 meta_i = 0;
 
-       for (const auto &p: m_meta) {
+       for (const auto &p : m_meta) {
                const std::string &id = p.first;
                const Meta &meta = p.second;
                s32 x = x_left;
@@ -99,18 +97,16 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
                char buf[10];
                snprintf(buf, 10, "%.3g", show_max);
                font->draw(utf8_to_wide(buf).c_str(),
-                       core::rect<s32>(textx, y - graphh,
-                               textx2, y - graphh + texth),
-                       meta.color);
+                               core::rect<s32>(textx, y - graphh, textx2,
+                                               y - graphh + texth),
+                               meta.color);
                snprintf(buf, 10, "%.3g", show_min);
                font->draw(utf8_to_wide(buf).c_str(),
-                       core::rect<s32>(textx, y - texth,
-                               textx2, y),
-                       meta.color);
+                               core::rect<s32>(textx, y - texth, textx2, y), meta.color);
                font->draw(utf8_to_wide(id).c_str(),
-                       core::rect<s32>(textx, y - graphh / 2 - texth / 2,
-                               textx2, y - graphh / 2 + texth / 2),
-                       meta.color);
+                               core::rect<s32>(textx, y - graphh / 2 - texth / 2, textx2,
+                                               y - graphh / 2 + texth / 2),
+                               meta.color);
                s32 graph1y = y;
                s32 graph1h = graphh;
                bool relativegraph = (show_min != 0 && show_min != show_max);
@@ -120,8 +116,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
                for (const Piece &piece : m_log) {
                        float value = 0;
                        bool value_exists = false;
-                       Profiler::GraphValues::const_iterator k =
-                               piece.values.find(id);
+                       Profiler::GraphValues::const_iterator k = piece.values.find(id);
 
                        if (k != piece.values.end()) {
                                value = k->second;
@@ -149,8 +144,10 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
                                if (lastscaledvalue_exists) {
                                        s32 ivalue1 = lastscaledvalue * graph1h;
                                        s32 ivalue2 = scaledvalue * graph1h;
-                                       driver->draw2DLine(v2s32(x - 1, graph1y - ivalue1),
-                                               v2s32(x, graph1y - ivalue2), meta.color);
+                                       driver->draw2DLine(
+                                                       v2s32(x - 1, graph1y - ivalue1),
+                                                       v2s32(x, graph1y - ivalue2),
+                                                       meta.color);
                                }
 
                                lastscaledvalue = scaledvalue;
@@ -158,7 +155,7 @@ void ProfilerGraph::draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
                        } else {
                                s32 ivalue = scaledvalue * graph1h;
                                driver->draw2DLine(v2s32(x, graph1y),
-                                       v2s32(x, graph1y - ivalue), meta.color);
+                                               v2s32(x, graph1y - ivalue), meta.color);
                        }
 
                        x++;
index 9f2c87853beba842cd8f5f5d94c547f342e793f1..6354ac9ef0d6978d5d5a6b494e55406012007893 100644 (file)
@@ -30,22 +30,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 class ProfilerGraph
 {
 private:
-       struct Piece {
+       struct Piece
+       {
                Piece(Profiler::GraphValues v) : values(std::move(v)) {}
                Profiler::GraphValues values;
        };
-       struct Meta {
+       struct Meta
+       {
                float min;
                float max;
                video::SColor color;
                Meta(float initial = 0,
-                       video::SColor color = video::SColor(255, 255, 255, 255)):
-                       min(initial),
-                       max(initial),
-                       color(color)
-               {}
+                               video::SColor color = video::SColor(255, 255, 255, 255)) :
+                               min(initial),
+                               max(initial), color(color)
+               {
+               }
        };
        std::deque<Piece> m_log;
+
 public:
        u32 m_log_max_size = 200;
 
@@ -54,5 +57,5 @@ public:
        void put(const Profiler::GraphValues &values);
 
        void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
-               gui::IGUIFont *font) const;
+                       gui::IGUIFont *font) const;
 };