Fix last performance-type-promotion-in-math-fn problems
authorLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Apr 2018 05:42:40 +0000 (07:42 +0200)
committerLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Apr 2018 05:42:40 +0000 (07:42 +0200)
src/camera.cpp
src/chat.cpp
src/chat.h
src/client.cpp
src/content_cao.cpp
src/content_cao.h
src/fontengine.cpp
src/game.cpp
src/particles.cpp
src/sky.cpp
src/util/numeric.cpp

index cf96f3308f75431c3a5029e17219660240bb083a..ebb1541375720f310bfbbaa13ee94c82ae346a0e 100644 (file)
@@ -291,7 +291,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
        {
                f32 oldy = old_player_position.Y;
                f32 newy = player_position.Y;
-               f32 t = exp(-23*frametime);
+               f32 t = std::exp(-23 * frametime);
                player_position.Y = oldy * t + newy * (1-t);
        }
 
@@ -481,7 +481,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
                if(m_digging_anim > 0.5)
                        frac = 2.0 * (m_digging_anim - 0.5);
                // This value starts from 1 and settles to 0
-               f32 ratiothing = pow((1.0f - tool_reload_ratio), 0.5f);
+               f32 ratiothing = std::pow((1.0f - tool_reload_ratio), 0.5f);
                //f32 ratiothing2 = pow(ratiothing, 0.5f);
                f32 ratiothing2 = (easeCurve(ratiothing*0.5))*2.0;
                wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7f);
index cc0980230ba4e8ed74993959ee5ef8aff6b81bae..c3ed59804c0adbbb4f45a796a2aba1785bf0035b 100644 (file)
@@ -402,7 +402,7 @@ void ChatPrompt::input(const std::wstring &str)
        m_nick_completion_end = 0;
 }
 
-void ChatPrompt::addToHistory(std::wstring line)
+void ChatPrompt::addToHistory(const std::wstring &line)
 {
        if (!line.empty() &&
                        (m_history.size() == 0 || m_history.back() != line)) {
@@ -426,7 +426,7 @@ void ChatPrompt::clear()
        m_nick_completion_end = 0;
 }
 
-std::wstring ChatPrompt::replace(std::wstring line)
+std::wstring ChatPrompt::replace(const std::wstring &line)
 {
        std::wstring old_line = m_line;
        m_line =  line;
@@ -660,7 +660,7 @@ ChatBackend::ChatBackend():
 {
 }
 
-void ChatBackend::addMessage(std::wstring name, std::wstring text)
+void ChatBackend::addMessage(const std::wstring &name, std::wstring text)
 {
        // Note: A message may consist of multiple lines, for example the MOTD.
        text = translate_string(text);
index 8649704d19131e261749896c6cea72a0cf16cb71..f84ece206c4fc0cb75adc236cf380c6653ae44d9 100644 (file)
@@ -153,7 +153,7 @@ public:
        void input(const std::wstring &str);
 
        // Add a string to the history
-       void addToHistory(std::wstring line);
+       void addToHistory(const std::wstring &line);
 
        // Get current line
        std::wstring getLine() const { return m_line; }
@@ -165,7 +165,7 @@ public:
        void clear();
 
        // Replace the current line with the given text
-       std::wstring replace(std::wstring line);
+       std::wstring replace(const std::wstring &line);
 
        // Select previous command from history
        void historyPrev();
@@ -256,7 +256,7 @@ public:
        ~ChatBackend() = default;
 
        // Add chat message
-       void addMessage(std::wstring name, std::wstring text);
+       void addMessage(const std::wstring &name, std::wstring text);
        // Parse and add unparsed chat message
        void addUnparsedMessage(std::wstring line);
 
index 5356ef151129916e63bedf0a667cbe2e872a073c..87e5e12bca1941f4ef7654ba0a3292f24ba31799 100644 (file)
@@ -523,21 +523,18 @@ void Client::step(float dtime)
                the local inventory (so the player notices the lag problem
                and knows something is wrong).
        */
-       if(m_inventory_from_server)
-       {
-               float interval = 10.0;
-               float count_before = floor(m_inventory_from_server_age / interval);
+       if (m_inventory_from_server) {
+               float interval = 10.0f;
+               float count_before = std::floor(m_inventory_from_server_age / interval);
 
                m_inventory_from_server_age += dtime;
 
-               float count_after = floor(m_inventory_from_server_age / interval);
+               float count_after = std::floor(m_inventory_from_server_age / interval);
 
-               if(count_after != count_before)
-               {
+               if (count_after != count_before) {
                        // Do this every <interval> seconds after TOCLIENT_INVENTORY
                        // Reset the locally changed inventory to the authoritative inventory
-                       LocalPlayer *player = m_env.getLocalPlayer();
-                       player->inventory = *m_inventory_from_server;
+                       m_env.getLocalPlayer()->inventory = *m_inventory_from_server;
                        m_inventory_updated = true;
                }
        }
index 92b0ddfbd001daefaa4958f49b48ff3a882b3f7b..81443c824f6cc52459e45972e12cf439321aefab 100644 (file)
@@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client.h"
 #include "wieldmesh.h"
 #include <algorithm>
+#include <cmath>
 #include "client/renderingengine.h"
 
 class Settings;
@@ -947,25 +948,23 @@ void GenericCAO::updateTexturePos()
                int row = m_tx_basepos.Y;
                int col = m_tx_basepos.X;
 
-               if(m_tx_select_horiz_by_yawpitch)
-               {
-                       if(cam_to_entity.Y > 0.75)
+               if (m_tx_select_horiz_by_yawpitch) {
+                       if (cam_to_entity.Y > 0.75)
                                col += 5;
-                       else if(cam_to_entity.Y < -0.75)
+                       else if (cam_to_entity.Y < -0.75)
                                col += 4;
-                       else{
+                       else {
                                float mob_dir =
                                                atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
                                float dir = mob_dir - m_yaw;
                                dir = wrapDegrees_180(dir);
-                               //infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
-                               if(fabs(wrapDegrees_180(dir - 0)) <= 45.1)
+                               if (std::fabs(wrapDegrees_180(dir - 0)) <= 45.1f)
                                        col += 2;
-                               else if(fabs(wrapDegrees_180(dir - 90)) <= 45.1)
+                               else if(std::fabs(wrapDegrees_180(dir - 90)) <= 45.1f)
                                        col += 3;
-                               else if(fabs(wrapDegrees_180(dir - 180)) <= 45.1)
+                               else if(std::fabs(wrapDegrees_180(dir - 180)) <= 45.1f)
                                        col += 0;
-                               else if(fabs(wrapDegrees_180(dir + 90)) <= 45.1)
+                               else if(std::fabs(wrapDegrees_180(dir + 90)) <= 45.1f)
                                        col += 1;
                                else
                                        col += 4;
@@ -977,12 +976,11 @@ void GenericCAO::updateTexturePos()
 
                float txs = m_tx_size.X;
                float tys = m_tx_size.Y;
-               setBillboardTextureMatrix(m_spritenode,
-                               txs, tys, col, row);
+               setBillboardTextureMatrix(m_spritenode, txs, tys, col, row);
        }
 }
 
-void GenericCAO::updateTextures(std::string mod)
+void GenericCAO::updateTextures(const std::string &mod)
 {
        ITextureSource *tsrc = m_client->tsrc();
 
@@ -1292,7 +1290,7 @@ void GenericCAO::processMessage(const std::string &data)
                m_position = readV3F1000(is);
                m_velocity = readV3F1000(is);
                m_acceleration = readV3F1000(is);
-               if(fabs(m_prop.automatic_rotate) < 0.001)
+               if (std::fabs(m_prop.automatic_rotate) < 0.001f)
                        m_yaw = readF1000(is);
                else
                        readF1000(is);
index 7e946efb7ef8bcb828c1c06fc2280d004744303e..a93df664a2a6f8415ae4d873c324a674b3004720 100644 (file)
@@ -199,7 +199,7 @@ public:
 
        // std::string copy is mandatory as mod can be a class member and there is a swap
        // on those class members
-       void updateTextures(std::string mod);
+       void updateTextures(const std::string &mod);
 
        void updateAnimation();
 
index b40e1ef0f0bd483f36ea62e0e7bd0f251d10189c..dc98fb1e44c376bc533d899dca4c8f1ce5f621a2 100644 (file)
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "fontengine.h"
+#include <cmath>
 #include "client/renderingengine.h"
 #include "config.h"
 #include "porting.h"
@@ -309,10 +310,10 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
        }
 #if USE_FREETYPE
        else {
-               if (! is_yes(m_settings->get("freetype"))) {
+               if (!is_yes(m_settings->get("freetype"))) {
                        return;
                }
-               unsigned int size = floor(RenderingEngine::getDisplayDensity() *
+               u32 size = std::floor(RenderingEngine::getDisplayDensity() *
                                m_settings->getFloat("gui_scaling") * basesize);
                u32 font_shadow       = 0;
                u32 font_shadow_alpha = 0;
@@ -428,7 +429,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
        if (basesize == FONT_SIZE_UNSPECIFIED)
                basesize = DEFAULT_FONT_SIZE;
 
-       unsigned int size = floor(
+       u32 size = std::floor(
                        RenderingEngine::getDisplayDensity() *
                        m_settings->getFloat("gui_scaling") *
                        basesize);
index 9a7f4e6d78f9c1ca1d1acc475a05542bebf616ce..3d11ddbaad81ad170648afae3d290add9d021274 100644 (file)
@@ -3131,9 +3131,9 @@ PointedThing Game::updatePointedThing(
                // Modify final color a bit with time
                u32 timer = porting::getTimeMs() % 5000;
                float timerf = (float) (irr::core::PI * ((timer / 2500.0) - 0.5));
-               float sin_r = 0.08 * sin(timerf);
-               float sin_g = 0.08 * sin(timerf + irr::core::PI * 0.5);
-               float sin_b = 0.08 * sin(timerf + irr::core::PI);
+               float sin_r = 0.08f * std::sin(timerf);
+               float sin_g = 0.08f * std::sin(timerf + irr::core::PI * 0.5f);
+               float sin_b = 0.08f * std::sin(timerf + irr::core::PI);
                c.setRed(core::clamp(core::round32(c.getRed() * (0.8 + sin_r)), 0, 255));
                c.setGreen(core::clamp(core::round32(c.getGreen() * (0.8 + sin_g)), 0, 255));
                c.setBlue(core::clamp(core::round32(c.getBlue() * (0.8 + sin_b)), 0, 255));
index 0a6651ce453624a68c1a02b034cfe735480f3bca..e98068f5355dad1387c526b0b92b8c0ee3a82dde 100644 (file)
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 */
 
 #include "particles.h"
+#include <cmath>
 #include "client.h"
 #include "collision.h"
 #include "client/clientevent.h"
@@ -227,7 +228,8 @@ void Particle::updateVertices()
        for (video::S3DVertex &vertex : m_vertices) {
                if (m_vertical) {
                        v3f ppos = m_player->getPosition()/BS;
-                       vertex.Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
+                       vertex.Pos.rotateXZBy(std::atan2(ppos.Z - m_pos.Z, ppos.X - m_pos.X) /
+                               core::DEGTORAD + 90);
                } else {
                        vertex.Pos.rotateYZBy(m_player->getPitch());
                        vertex.Pos.rotateXZBy(m_player->getYaw());
index 02e882592b9ef35df75467a28b0b86eb2c0f9802..03afc44645cfe04ff2ab2e5bc9ca4d037f1d36f3 100644 (file)
@@ -1,3 +1,22 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+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 "sky.h"
 #include "IVideoDriver.h"
 #include "ISceneManager.h"
@@ -243,7 +262,7 @@ void Sky::render()
                {
                        float mid1 = 0.25;
                        float mid = wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1);
-                       float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
+                       float a_ = 1.0f - std::fabs(wicked_time_of_day - mid) * 35.0f;
                        float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
                        //std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
                        video::SColor c(255, 255, 255, 255);
@@ -539,7 +558,7 @@ void Sky::update(float time_of_day, float time_brightness,
 
        float cloud_color_change_fraction = 0.95;
        if (sunlight_seen) {
-               if (fabs(time_brightness - m_brightness) < 0.2) {
+               if (std::fabs(time_brightness - m_brightness) < 0.2f) {
                        m_brightness = m_brightness * 0.95 + time_brightness * 0.05;
                } else {
                        m_brightness = m_brightness * 0.80 + time_brightness * 0.20;
index f533c275fb1bdf36d45eff4f239cfff19568bc31..ddd4fd6cce527a8d18fb6e017ed4fc5f4f165bb7 100644 (file)
@@ -173,6 +173,6 @@ s16 adjustDist(s16 dist, float zoom_fov)
 
        // new_dist = dist * ((1 - cos(FOV / 2)) / (1-cos(zoomFOV /2))) ^ (1/3)
        // note: FOV is calculated at compilation time
-       return round(dist * std::cbrt((1.0f - std::cos(default_fov)) /
+       return std::round(dist * std::cbrt((1.0f - std::cos(default_fov)) /
                (1.0f - std::cos(zoom_fov / 2.0f))));
 }