Skip to content

Commit 8e0b80a

Browse files
committedApr 4, 2018
Fix last performance-type-promotion-in-math-fn problems
1 parent a90d27e commit 8e0b80a

File tree

11 files changed

+59
-42
lines changed

11 files changed

+59
-42
lines changed
 

Diff for: ‎src/camera.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
291291
{
292292
f32 oldy = old_player_position.Y;
293293
f32 newy = player_position.Y;
294-
f32 t = exp(-23*frametime);
294+
f32 t = std::exp(-23 * frametime);
295295
player_position.Y = oldy * t + newy * (1-t);
296296
}
297297

@@ -481,7 +481,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
481481
if(m_digging_anim > 0.5)
482482
frac = 2.0 * (m_digging_anim - 0.5);
483483
// This value starts from 1 and settles to 0
484-
f32 ratiothing = pow((1.0f - tool_reload_ratio), 0.5f);
484+
f32 ratiothing = std::pow((1.0f - tool_reload_ratio), 0.5f);
485485
//f32 ratiothing2 = pow(ratiothing, 0.5f);
486486
f32 ratiothing2 = (easeCurve(ratiothing*0.5))*2.0;
487487
wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7f);

Diff for: ‎src/chat.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void ChatPrompt::input(const std::wstring &str)
402402
m_nick_completion_end = 0;
403403
}
404404

405-
void ChatPrompt::addToHistory(std::wstring line)
405+
void ChatPrompt::addToHistory(const std::wstring &line)
406406
{
407407
if (!line.empty() &&
408408
(m_history.size() == 0 || m_history.back() != line)) {
@@ -426,7 +426,7 @@ void ChatPrompt::clear()
426426
m_nick_completion_end = 0;
427427
}
428428

429-
std::wstring ChatPrompt::replace(std::wstring line)
429+
std::wstring ChatPrompt::replace(const std::wstring &line)
430430
{
431431
std::wstring old_line = m_line;
432432
m_line = line;
@@ -660,7 +660,7 @@ ChatBackend::ChatBackend():
660660
{
661661
}
662662

663-
void ChatBackend::addMessage(std::wstring name, std::wstring text)
663+
void ChatBackend::addMessage(const std::wstring &name, std::wstring text)
664664
{
665665
// Note: A message may consist of multiple lines, for example the MOTD.
666666
text = translate_string(text);

Diff for: ‎src/chat.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class ChatPrompt
153153
void input(const std::wstring &str);
154154

155155
// Add a string to the history
156-
void addToHistory(std::wstring line);
156+
void addToHistory(const std::wstring &line);
157157

158158
// Get current line
159159
std::wstring getLine() const { return m_line; }
@@ -165,7 +165,7 @@ class ChatPrompt
165165
void clear();
166166

167167
// Replace the current line with the given text
168-
std::wstring replace(std::wstring line);
168+
std::wstring replace(const std::wstring &line);
169169

170170
// Select previous command from history
171171
void historyPrev();
@@ -256,7 +256,7 @@ class ChatBackend
256256
~ChatBackend() = default;
257257

258258
// Add chat message
259-
void addMessage(std::wstring name, std::wstring text);
259+
void addMessage(const std::wstring &name, std::wstring text);
260260
// Parse and add unparsed chat message
261261
void addUnparsedMessage(std::wstring line);
262262

Diff for: ‎src/client.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -523,21 +523,18 @@ void Client::step(float dtime)
523523
the local inventory (so the player notices the lag problem
524524
and knows something is wrong).
525525
*/
526-
if(m_inventory_from_server)
527-
{
528-
float interval = 10.0;
529-
float count_before = floor(m_inventory_from_server_age / interval);
526+
if (m_inventory_from_server) {
527+
float interval = 10.0f;
528+
float count_before = std::floor(m_inventory_from_server_age / interval);
530529

531530
m_inventory_from_server_age += dtime;
532531

533-
float count_after = floor(m_inventory_from_server_age / interval);
532+
float count_after = std::floor(m_inventory_from_server_age / interval);
534533

535-
if(count_after != count_before)
536-
{
534+
if (count_after != count_before) {
537535
// Do this every <interval> seconds after TOCLIENT_INVENTORY
538536
// Reset the locally changed inventory to the authoritative inventory
539-
LocalPlayer *player = m_env.getLocalPlayer();
540-
player->inventory = *m_inventory_from_server;
537+
m_env.getLocalPlayer()->inventory = *m_inventory_from_server;
541538
m_inventory_updated = true;
542539
}
543540
}

Diff for: ‎src/content_cao.cpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
4545
#include "client.h"
4646
#include "wieldmesh.h"
4747
#include <algorithm>
48+
#include <cmath>
4849
#include "client/renderingengine.h"
4950

5051
class Settings;
@@ -947,25 +948,23 @@ void GenericCAO::updateTexturePos()
947948
int row = m_tx_basepos.Y;
948949
int col = m_tx_basepos.X;
949950

950-
if(m_tx_select_horiz_by_yawpitch)
951-
{
952-
if(cam_to_entity.Y > 0.75)
951+
if (m_tx_select_horiz_by_yawpitch) {
952+
if (cam_to_entity.Y > 0.75)
953953
col += 5;
954-
else if(cam_to_entity.Y < -0.75)
954+
else if (cam_to_entity.Y < -0.75)
955955
col += 4;
956-
else{
956+
else {
957957
float mob_dir =
958958
atan2(cam_to_entity.Z, cam_to_entity.X) / M_PI * 180.;
Has conversations. Original line has conversations.
959959
float dir = mob_dir - m_yaw;
960960
dir = wrapDegrees_180(dir);
961-
//infostream<<"id="<<m_id<<" dir="<<dir<<std::endl;
962-
if(fabs(wrapDegrees_180(dir - 0)) <= 45.1)
961+
if (std::fabs(wrapDegrees_180(dir - 0)) <= 45.1f)
963962
col += 2;
964-
else if(fabs(wrapDegrees_180(dir - 90)) <= 45.1)
963+
else if(std::fabs(wrapDegrees_180(dir - 90)) <= 45.1f)
965964
col += 3;
966-
else if(fabs(wrapDegrees_180(dir - 180)) <= 45.1)
965+
else if(std::fabs(wrapDegrees_180(dir - 180)) <= 45.1f)
967966
col += 0;
968-
else if(fabs(wrapDegrees_180(dir + 90)) <= 45.1)
967+
else if(std::fabs(wrapDegrees_180(dir + 90)) <= 45.1f)
969968
col += 1;
970969
else
971970
col += 4;
@@ -977,12 +976,11 @@ void GenericCAO::updateTexturePos()
977976

978977
float txs = m_tx_size.X;
979978
float tys = m_tx_size.Y;
980-
setBillboardTextureMatrix(m_spritenode,
981-
txs, tys, col, row);
979+
setBillboardTextureMatrix(m_spritenode, txs, tys, col, row);
982980
}
983981
}
984982

985-
void GenericCAO::updateTextures(std::string mod)
983+
void GenericCAO::updateTextures(const std::string &mod)
986984
{
987985
ITextureSource *tsrc = m_client->tsrc();
988986

@@ -1292,7 +1290,7 @@ void GenericCAO::processMessage(const std::string &data)
12921290
m_position = readV3F1000(is);
12931291
m_velocity = readV3F1000(is);
12941292
m_acceleration = readV3F1000(is);
1295-
if(fabs(m_prop.automatic_rotate) < 0.001)
1293+
if (std::fabs(m_prop.automatic_rotate) < 0.001f)
12961294
m_yaw = readF1000(is);
12971295
else
12981296
readF1000(is);

Diff for: ‎src/content_cao.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class GenericCAO : public ClientActiveObject
199199

200200
// std::string copy is mandatory as mod can be a class member and there is a swap
201201
// on those class members
202-
void updateTextures(std::string mod);
202+
void updateTextures(const std::string &mod);
203203

204204
void updateAnimation();
205205

Diff for: ‎src/fontengine.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "fontengine.h"
21+
#include <cmath>
2122
#include "client/renderingengine.h"
2223
#include "config.h"
2324
#include "porting.h"
@@ -309,10 +310,10 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
309310
}
310311
#if USE_FREETYPE
311312
else {
312-
if (! is_yes(m_settings->get("freetype"))) {
313+
if (!is_yes(m_settings->get("freetype"))) {
313314
return;
314315
}
315-
unsigned int size = floor(RenderingEngine::getDisplayDensity() *
316+
u32 size = std::floor(RenderingEngine::getDisplayDensity() *
316317
m_settings->getFloat("gui_scaling") * basesize);
317318
u32 font_shadow = 0;
318319
u32 font_shadow_alpha = 0;
@@ -428,7 +429,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
428429
if (basesize == FONT_SIZE_UNSPECIFIED)
429430
basesize = DEFAULT_FONT_SIZE;
430431

431-
unsigned int size = floor(
432+
u32 size = std::floor(
432433
RenderingEngine::getDisplayDensity() *
433434
m_settings->getFloat("gui_scaling") *
434435
basesize);

Diff for: ‎src/game.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3131,9 +3131,9 @@ PointedThing Game::updatePointedThing(
31313131
// Modify final color a bit with time
31323132
u32 timer = porting::getTimeMs() % 5000;
31333133
float timerf = (float) (irr::core::PI * ((timer / 2500.0) - 0.5));
3134-
float sin_r = 0.08 * sin(timerf);
3135-
float sin_g = 0.08 * sin(timerf + irr::core::PI * 0.5);
3136-
float sin_b = 0.08 * sin(timerf + irr::core::PI);
3134+
float sin_r = 0.08f * std::sin(timerf);
3135+
float sin_g = 0.08f * std::sin(timerf + irr::core::PI * 0.5f);
3136+
float sin_b = 0.08f * std::sin(timerf + irr::core::PI);
31373137
c.setRed(core::clamp(core::round32(c.getRed() * (0.8 + sin_r)), 0, 255));
31383138
c.setGreen(core::clamp(core::round32(c.getGreen() * (0.8 + sin_g)), 0, 255));
31393139
c.setBlue(core::clamp(core::round32(c.getBlue() * (0.8 + sin_b)), 0, 255));

Diff for: ‎src/particles.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1818
*/
1919

2020
#include "particles.h"
21+
#include <cmath>
2122
#include "client.h"
2223
#include "collision.h"
2324
#include "client/clientevent.h"
@@ -227,7 +228,8 @@ void Particle::updateVertices()
227228
for (video::S3DVertex &vertex : m_vertices) {
228229
if (m_vertical) {
229230
v3f ppos = m_player->getPosition()/BS;
230-
vertex.Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
231+
vertex.Pos.rotateXZBy(std::atan2(ppos.Z - m_pos.Z, ppos.X - m_pos.X) /
232+
core::DEGTORAD + 90);
231233
} else {
232234
vertex.Pos.rotateYZBy(m_player->getPitch());
233235
vertex.Pos.rotateXZBy(m_player->getYaw());

Diff for: ‎src/sky.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
120
#include "sky.h"
221
#include "IVideoDriver.h"
322
#include "ISceneManager.h"
@@ -243,7 +262,7 @@ void Sky::render()
243262
{
244263
float mid1 = 0.25;
245264
float mid = wicked_time_of_day < 0.5 ? mid1 : (1.0 - mid1);
246-
float a_ = 1.0 - fabs(wicked_time_of_day - mid) * 35.0;
265+
float a_ = 1.0f - std::fabs(wicked_time_of_day - mid) * 35.0f;
247266
float a = easeCurve(MYMAX(0, MYMIN(1, a_)));
248267
//std::cerr<<"a_="<<a_<<" a="<<a<<std::endl;
249268
video::SColor c(255, 255, 255, 255);
@@ -539,7 +558,7 @@ void Sky::update(float time_of_day, float time_brightness,
539558

540559
float cloud_color_change_fraction = 0.95;
541560
if (sunlight_seen) {
542-
if (fabs(time_brightness - m_brightness) < 0.2) {
561+
if (std::fabs(time_brightness - m_brightness) < 0.2f) {
543562
m_brightness = m_brightness * 0.95 + time_brightness * 0.05;
544563
} else {
545564
m_brightness = m_brightness * 0.80 + time_brightness * 0.20;

Diff for: ‎src/util/numeric.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,6 @@ s16 adjustDist(s16 dist, float zoom_fov)
173173

174174
// new_dist = dist * ((1 - cos(FOV / 2)) / (1-cos(zoomFOV /2))) ^ (1/3)
175175
// note: FOV is calculated at compilation time
176-
return round(dist * std::cbrt((1.0f - std::cos(default_fov)) /
176+
return std::round(dist * std::cbrt((1.0f - std::cos(default_fov)) /
177177
(1.0f - std::cos(zoom_fov / 2.0f))));
178178
}

0 commit comments

Comments
 (0)
Please sign in to comment.