From 8e0b80aa369df7d1142053f077df928106c6ce8c Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 4 Apr 2018 07:42:40 +0200 Subject: [PATCH] Fix last performance-type-promotion-in-math-fn problems --- src/camera.cpp | 4 ++-- src/chat.cpp | 6 +++--- src/chat.h | 6 +++--- src/client.cpp | 15 ++++++--------- src/content_cao.cpp | 26 ++++++++++++-------------- src/content_cao.h | 2 +- src/fontengine.cpp | 7 ++++--- src/game.cpp | 6 +++--- src/particles.cpp | 4 +++- src/sky.cpp | 23 +++++++++++++++++++++-- src/util/numeric.cpp | 2 +- 11 files changed, 59 insertions(+), 42 deletions(-) diff --git a/src/camera.cpp b/src/camera.cpp index cf96f3308..ebb154137 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -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); diff --git a/src/chat.cpp b/src/chat.cpp index cc0980230..c3ed59804 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -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); diff --git a/src/chat.h b/src/chat.h index 8649704d1..f84ece206 100644 --- a/src/chat.h +++ b/src/chat.h @@ -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); diff --git a/src/client.cpp b/src/client.cpp index 5356ef151..87e5e12bc 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -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 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; } } diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 92b0ddfbd..81443c824 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "wieldmesh.h" #include +#include #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="< #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); diff --git a/src/game.cpp b/src/game.cpp index 9a7f4e6d7..3d11ddbaa 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -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)); diff --git a/src/particles.cpp b/src/particles.cpp index 0a6651ce4..e98068f53 100644 --- a/src/particles.cpp +++ b/src/particles.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "particles.h" +#include #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()); diff --git a/src/sky.cpp b/src/sky.cpp index 02e882592..03afc4464 100644 --- a/src/sky.cpp +++ b/src/sky.cpp @@ -1,3 +1,22 @@ +/* +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola + +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_="<