Fix last performance-type-promotion-in-math-fn problems

master
Loic Blot 2018-04-04 07:42:40 +02:00
parent a90d27e1e2
commit 8e0b80aa36
No known key found for this signature in database
GPG Key ID: EFAA458E8C153987
11 changed files with 59 additions and 42 deletions

View 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);

View 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);

View 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);

View 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;
}
}

View 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);

View 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();

View 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);

View 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));

View 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());

View 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;

View 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))));
}