Skip to content

Commit

Permalink
Fix last performance-type-promotion-in-math-fn problems
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul committed Apr 4, 2018
1 parent a90d27e commit 8e0b80a
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/camera.cpp
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/chat.cpp
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/chat.h
Expand Up @@ -153,7 +153,7 @@ class ChatPrompt
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; }
Expand All @@ -165,7 +165,7 @@ class ChatPrompt
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();
Expand Down Expand Up @@ -256,7 +256,7 @@ class ChatBackend
~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);

Expand Down
15 changes: 6 additions & 9 deletions src/client.cpp
Expand Up @@ -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;
}
}
Expand Down
26 changes: 12 additions & 14 deletions src/content_cao.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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.;

This comment has been minimized.

Copy link
@paramat

paramat Apr 4, 2018

Contributor

std::atan2

This comment has been minimized.

Copy link
@nerzhul

nerzhul Apr 4, 2018

Author Member

maybe reported or not, if you look at my current pr to promote some points are reported, like this :) will fix them with the PR

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;
Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/content_cao.h
Expand Up @@ -199,7 +199,7 @@ class GenericCAO : public ClientActiveObject

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

Expand Down
7 changes: 4 additions & 3 deletions src/fontengine.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/game.cpp
Expand Up @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion src/particles.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down
23 changes: 21 additions & 2 deletions src/sky.cpp
@@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/util/numeric.cpp
Expand Up @@ -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))));
}

0 comments on commit 8e0b80a

Please sign in to comment.