]> git.lizzy.rs Git - minetest.git/blobdiff - src/game.cpp
Damage flash: Reduce maximum alpha. Avoid fade overload
[minetest.git] / src / game.cpp
index ba77d299ab1f6eeba486b2ee2f631138440ddd48..1e4464cc4fce9133bf100520e74e96071f27da0a 100644 (file)
@@ -605,6 +605,8 @@ class ProfilerGraph
        void draw(s32 x_left, s32 y_bottom, video::IVideoDriver *driver,
                  gui::IGUIFont *font) const
        {
+               // Do *not* use UNORDERED_MAP here as the order needs
+               // to be the same for each call to prevent flickering
                std::map<std::string, Meta> m_meta;
 
                for (std::deque<Piece>::const_iterator k = m_log.begin();
@@ -615,8 +617,7 @@ class ProfilerGraph
                                        i != piece.values.end(); ++i) {
                                const std::string &id = i->first;
                                const float &value = i->second;
-                               std::map<std::string, Meta>::iterator j =
-                                       m_meta.find(id);
+                               std::map<std::string, Meta>::iterator j = m_meta.find(id);
 
                                if (j == m_meta.end()) {
                                        m_meta[id] = Meta(value);
@@ -1273,10 +1274,10 @@ static void updateChat(Client &client, f32 dtime, bool show_debug,
        setStaticText(guitext_chat, recent_chat);
 
        // Update gui element size and position
-       s32 chat_y = 5 + line_height;
+       s32 chat_y = 5;
 
        if (show_debug)
-               chat_y += line_height;
+               chat_y += 2 * line_height;
 
        // first pass to calculate height of text to be set
        s32 width = std::min(g_fontengine->getTextWidth(recent_chat.c_str()) + 10,
@@ -1371,6 +1372,7 @@ void KeyCache::populate()
                        = 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");
@@ -1739,6 +1741,8 @@ class Game {
        bool m_cache_enable_joysticks;
        bool m_cache_enable_particles;
        bool m_cache_enable_fog;
+       bool m_cache_enable_noclip;
+       bool m_cache_enable_free_move;
        f32  m_cache_mouse_sensitivity;
        f32  m_cache_joystick_frustum_sensitivity;
        f32  m_repeat_right_click_time;
@@ -1788,6 +1792,10 @@ Game::Game() :
                &settingChangedCallback, this);
        g_settings->registerChangedCallback("repeat_rightclick_time",
                &settingChangedCallback, this);
+       g_settings->registerChangedCallback("noclip",
+               &settingChangedCallback, this);
+       g_settings->registerChangedCallback("free_move",
+               &settingChangedCallback, this);
 
        readSettings();
 
@@ -1837,6 +1845,10 @@ Game::~Game()
                &settingChangedCallback, this);
        g_settings->deregisterChangedCallback("repeat_rightclick_time",
                &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("noclip",
+               &settingChangedCallback, this);
+       g_settings->deregisterChangedCallback("free_move",
+               &settingChangedCallback, this);
 }
 
 bool Game::startup(bool *kill,
@@ -2205,6 +2217,8 @@ bool Game::createClient(const std::string &playername,
        /* Set window caption
         */
        std::wstring str = utf8_to_wide(PROJECT_NAME_C);
+       str += L" ";
+       str += utf8_to_wide(g_version_hash);
        str += L" [";
        str += driver->getName();
        str += L"]";
@@ -2400,7 +2414,26 @@ bool Game::connectToServer(const std::string &playername,
                        wait_time += dtime;
                        // Only time out if we aren't waiting for the server we started
                        if ((*address != "") && (wait_time > 10)) {
-                               *error_message = "Connection timed out.";
+                               bool sent_old_init = g_settings->getFlag("send_pre_v25_init");
+                               // If no pre v25 init was sent, and no answer was received,
+                               // but the low level connection could be established
+                               // (meaning that we have a peer id), then we probably wanted
+                               // to connect to a legacy server. In this case, tell the user
+                               // to enable the option to be able to connect.
+                               if (!sent_old_init &&
+                                               (client->getProtoVersion() == 0) &&
+                                               client->connectedToServer()) {
+                                       *error_message = "Connection failure: init packet not "
+                                       "recognized by server.\n"
+                                       "Most likely the server uses an old protocol version (<v25).\n"
+                                       "Please ask the server owner to update to 0.4.13 or later.\n"
+                                       "To still connect to the server in the meantime,\n"
+                                       "you can enable the 'send_pre_v25_init' setting by editing minetest.conf,\n"
+                                       "or by enabling the 'Client -> Network -> Support older Servers'\n"
+                                       "entry in the advanced settings menu.";
+                               } else {
+                                       *error_message = "Connection timed out.";
+                               }
                                errorstream << *error_message << std::endl;
                                break;
                        }
@@ -2550,7 +2583,7 @@ inline bool Game::handleCallbacks()
 
        if (g_gamecallback->changevolume_requested) {
                (new GUIVolumeChange(guienv, guiroot, -1,
-                                    &g_menumgr, client))->drop();
+                                    &g_menumgr))->drop();
                g_gamecallback->changevolume_requested = false;
        }
 
@@ -2830,7 +2863,7 @@ void Game::processItemSelection(u16 *new_playeritem)
 
        s32 wheel = input->getMouseWheel();
        u16 max_item = MYMIN(PLAYER_INVENTORY_SIZE - 1,
-                                player->hud_hotbar_itemcount - 1);
+                   player->hud_hotbar_itemcount - 1);
 
        s32 dir = wheel;
 
@@ -3268,6 +3301,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
                isKeyDown(KeyType::JUMP),
                isKeyDown(KeyType::SPECIAL1),
                isKeyDown(KeyType::SNEAK),
+               isKeyDown(KeyType::ZOOM),
                isLeftPressed(),
                isRightPressed(),
                cam.camera_pitch,
@@ -3340,12 +3374,12 @@ void Game::processClientEvents(CameraOrientation *cam, float *damage_flash)
                        //u16 damage = event.player_damage.amount;
                        //infostream<<"Player damage: "<<damage<<std::endl;
 
-                       *damage_flash += 100.0;
-                       *damage_flash += 8.0 * event.player_damage.amount;
+                       *damage_flash += 95.0 + 3.2 * event.player_damage.amount;
+                       *damage_flash = MYMIN(*damage_flash, 127.0);
 
                        player->hurt_tilt_timer = 1.5;
-                       player->hurt_tilt_strength = event.player_damage.amount / 4;
-                       player->hurt_tilt_strength = rangelim(player->hurt_tilt_strength, 1.0, 4.0);
+                       player->hurt_tilt_strength =
+                               rangelim(event.player_damage.amount / 4, 1.0, 4.0);
 
                        MtEvent *e = new SimpleTriggerEvent("PlayerDamage");
                        gamedef->event()->put(e);
@@ -4073,7 +4107,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
        float direct_brightness;
        bool sunlight_seen;
 
-       if (g_settings->getBool("free_move")) {
+       if (m_cache_enable_noclip && m_cache_enable_free_move) {
                direct_brightness = time_brightness;
                sunlight_seen = true;
        } else {
@@ -4144,7 +4178,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
                                runData->fog_range * 1.0,
                                0.01,
                                false, // pixel fog
-                               false // range fog
+                               true // range fog
                );
        } else {
                driver->setFog(
@@ -4251,10 +4285,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
                Damage flash
        */
        if (runData->damage_flash > 0.0) {
-               video::SColor color(std::min(runData->damage_flash, 180.0f),
-                               180,
-                               0,
-                               0);
+               video::SColor color(runData->damage_flash, 180, 0, 0);
                driver->draw2DRectangle(color,
                                        core::rect<s32>(0, 0, screensize.X, screensize.Y),
                                        NULL);
@@ -4296,23 +4327,12 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
 
 inline static const char *yawToDirectionString(int yaw)
 {
-       // NOTE: TODO: This can be done mathematically without the else/else-if
-       // cascade.
-
-       const char *player_direction;
+       static const char *direction[4] = {"North [+Z]", "West [-X]", "South [-Z]", "East [+X]"};
 
        yaw = wrapDegrees_0_360(yaw);
+       yaw = (yaw + 45) % 360 / 90;
 
-       if (yaw >= 45 && yaw < 135)
-               player_direction = "West [-X]";
-       else if (yaw >= 135 && yaw < 225)
-               player_direction = "South [-Z]";
-       else if (yaw >= 225 && yaw < 315)
-               player_direction = "East [+X]";
-       else
-               player_direction = "North [+Z]";
-
-       return player_direction;
+       return direction[yaw];
 }
 
 
@@ -4347,11 +4367,6 @@ void Game::updateGui(float *statustext_time, const RunStats &stats,
                   << ", RTT = " << client->getRTT();
                setStaticText(guitext, utf8_to_wide(os.str()).c_str());
                guitext->setVisible(true);
-       } else if (flags.show_hud || flags.show_chat) {
-               std::ostringstream os(std::ios_base::binary);
-               os << PROJECT_NAME_C " " << g_version_hash;
-               setStaticText(guitext, utf8_to_wide(os.str()).c_str());
-               guitext->setVisible(true);
        } else {
                guitext->setVisible(false);
        }
@@ -4526,6 +4541,9 @@ void Game::readSettings()
        m_cache_joystick_frustum_sensitivity = g_settings->getFloat("joystick_frustum_sensitivity");
        m_repeat_right_click_time            = g_settings->getFloat("repeat_rightclick_time");
 
+       m_cache_enable_noclip                = g_settings->getBool("noclip");
+       m_cache_enable_free_move             = g_settings->getBool("free_move");
+
        m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
 }