Fix more type promotion mistakes

Someone of these are probably actual bugs and gcc totally doesn't care to warn about them, wtf?
This issue seems to be new with the IrrlichtMt update.
This commit is contained in:
sfan5 2024-02-26 21:54:48 +01:00
parent 9fcd7f2dc0
commit fbec378869
6 changed files with 24 additions and 30 deletions

View File

@ -138,8 +138,8 @@ void Camera::notifyFovChange()
// Returns the fractional part of x // Returns the fractional part of x
inline f32 my_modf(f32 x) inline f32 my_modf(f32 x)
{ {
double dummy; float dummy;
return modf(x, &dummy); return std::modf(x, &dummy);
} }
void Camera::step(f32 dtime) void Camera::step(f32 dtime)
@ -407,10 +407,10 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
f32 bobdir = (m_view_bobbing_anim < 0.5) ? 1.0 : -1.0; f32 bobdir = (m_view_bobbing_anim < 0.5) ? 1.0 : -1.0;
f32 bobknob = 1.2; f32 bobknob = 1.2;
f32 bobtmp = sin(pow(bobfrac, bobknob) * M_PI); f32 bobtmp = std::sin(std::pow(bobfrac, bobknob) * M_PI);
v3f bobvec = v3f( v3f bobvec = v3f(
0.3 * bobdir * sin(bobfrac * M_PI), 0.3 * bobdir * std::sin(bobfrac * M_PI),
-0.28 * bobtmp * bobtmp, -0.28 * bobtmp * bobtmp,
0.); 0.);
@ -531,11 +531,9 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
addArmInertia(yaw); addArmInertia(yaw);
// Position the wielded item // Position the wielded item
//v3f wield_position = v3f(45, -35, 65);
v3f wield_position = v3f(m_wieldmesh_offset.X, m_wieldmesh_offset.Y, 65); v3f wield_position = v3f(m_wieldmesh_offset.X, m_wieldmesh_offset.Y, 65);
//v3f wield_rotation = v3f(-100, 120, -100);
v3f wield_rotation = v3f(-100, 120, -100); v3f wield_rotation = v3f(-100, 120, -100);
wield_position.Y += fabs(m_wield_change_timer)*320 - 40; wield_position.Y += std::abs(m_wield_change_timer)*320 - 40;
if(m_digging_anim < 0.05 || m_digging_anim > 0.5) if(m_digging_anim < 0.05 || m_digging_anim > 0.5)
{ {
f32 frac = 1.0; f32 frac = 1.0;
@ -543,33 +541,29 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
frac = 2.0 * (m_digging_anim - 0.5); frac = 2.0 * (m_digging_anim - 0.5);
// This value starts from 1 and settles to 0 // This value starts from 1 and settles to 0
f32 ratiothing = std::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; f32 ratiothing2 = (easeCurve(ratiothing*0.5))*2.0;
wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7f); wield_position.Y -= frac * 25.0f * std::pow(ratiothing2, 1.7f);
//wield_position.Z += frac * 5.0 * ratiothing2; wield_position.X -= frac * 35.0f * std::pow(ratiothing2, 1.1f);
wield_position.X -= frac * 35.0 * pow(ratiothing2, 1.1f); wield_rotation.Y += frac * 70.0f * std::pow(ratiothing2, 1.4f);
wield_rotation.Y += frac * 70.0 * pow(ratiothing2, 1.4f);
//wield_rotation.X -= frac * 15.0 * pow(ratiothing2, 1.4f);
//wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0f);
} }
if (m_digging_button != -1) if (m_digging_button != -1)
{ {
f32 digfrac = m_digging_anim; f32 digfrac = m_digging_anim;
wield_position.X -= 50 * sin(pow(digfrac, 0.8f) * M_PI); wield_position.X -= 50 * std::sin(std::pow(digfrac, 0.8f) * M_PI);
wield_position.Y += 24 * sin(digfrac * 1.8 * M_PI); wield_position.Y += 24 * std::sin(digfrac * 1.8 * M_PI);
wield_position.Z += 25 * 0.5; wield_position.Z += 25 * 0.5;
// Euler angles are PURE EVIL, so why not use quaternions? // Euler angles are PURE EVIL, so why not use quaternions?
core::quaternion quat_begin(wield_rotation * core::DEGTORAD); core::quaternion quat_begin(wield_rotation * core::DEGTORAD);
core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD); core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD);
core::quaternion quat_slerp; core::quaternion quat_slerp;
quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI)); quat_slerp.slerp(quat_begin, quat_end, std::sin(digfrac * M_PI));
quat_slerp.toEuler(wield_rotation); quat_slerp.toEuler(wield_rotation);
wield_rotation *= core::RADTODEG; wield_rotation *= core::RADTODEG;
} else { } else {
f32 bobfrac = my_modf(m_view_bobbing_anim); f32 bobfrac = my_modf(m_view_bobbing_anim);
wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0; wield_position.X -= std::sin(bobfrac*M_PI*2.0) * 3.0;
wield_position.Y += sin(my_modf(bobfrac*2.0)*M_PI) * 3.0; wield_position.Y += std::sin(my_modf(bobfrac*2.0)*M_PI) * 3.0;
} }
m_wieldnode->setPosition(wield_position); m_wieldnode->setPosition(wield_position);
m_wieldnode->setRotation(wield_rotation); m_wieldnode->setRotation(wield_rotation);
@ -584,8 +578,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
// view bobbing is enabled and free_move is off, // view bobbing is enabled and free_move is off,
// start (or continue) the view bobbing animation. // start (or continue) the view bobbing animation.
const v3f &speed = player->getSpeed(); const v3f &speed = player->getSpeed();
const bool movement_XZ = hypot(speed.X, speed.Z) > BS; const bool movement_XZ = std::hypot(speed.X, speed.Z) > BS;
const bool movement_Y = fabs(speed.Y) > BS; const bool movement_Y = std::abs(speed.Y) > BS;
const bool walking = movement_XZ && player->touching_ground; const bool walking = movement_XZ && player->touching_ground;
const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid; const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid;

View File

@ -1806,7 +1806,7 @@ struct TextureUpdateArgs {
void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress) void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress)
{ {
TextureUpdateArgs* targs = (TextureUpdateArgs*) args; TextureUpdateArgs* targs = (TextureUpdateArgs*) args;
u16 cur_percent = ceil(progress / (double) max_progress * 100.); u16 cur_percent = std::ceil(progress / max_progress * 100.f);
// update the loading menu -- if necessary // update the loading menu -- if necessary
bool do_draw = false; bool do_draw = false;

View File

@ -3708,11 +3708,11 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
break; break;
}; };
case NDT_SIGNLIKE: { case NDT_SIGNLIKE: {
rotate90 = abs(pdir.X) < abs(pdir.Z); rotate90 = std::abs(pdir.X) < std::abs(pdir.Z);
break; break;
} }
default: { default: {
rotate90 = abs(pdir.X) > abs(pdir.Z); rotate90 = std::abs(pdir.X) > std::abs(pdir.Z);
break; break;
} }
} }

View File

@ -38,8 +38,8 @@ public:
bool equal(const ClientDynamicInfo &other) const { bool equal(const ClientDynamicInfo &other) const {
return render_target_size == other.render_target_size && return render_target_size == other.render_target_size &&
abs(real_gui_scaling - other.real_gui_scaling) < 0.001f && std::abs(real_gui_scaling - other.real_gui_scaling) < 0.001f &&
abs(real_hud_scaling - other.real_hud_scaling) < 0.001f && std::abs(real_hud_scaling - other.real_hud_scaling) < 0.001f &&
touch_controls == other.touch_controls; touch_controls == other.touch_controls;
} }

View File

@ -46,9 +46,9 @@ T RangedParameter<T>::pickWithin() const
auto p = numericAbsolute(bias) + 1; auto p = numericAbsolute(bias) + 1;
for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); ++i) { for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
if (bias < 0) if (bias < 0)
values[i] = 1.0f - pow(myrand_float(), p); values[i] = 1.0f - std::pow(myrand_float(), p);
else else
values[i] = pow(myrand_float(), p); values[i] = std::pow(myrand_float(), p);
} }
return T::pick(values, min, max); return T::pick(values, min, max);
} }

View File

@ -191,7 +191,7 @@ u32 PlayerControl::getKeysPressed() const
float abs_d; float abs_d;
// (absolute value indicates forward / backward) // (absolute value indicates forward / backward)
abs_d = abs(movement_direction); abs_d = std::abs(movement_direction);
if (abs_d < 3.0f / 8.0f * M_PI) if (abs_d < 3.0f / 8.0f * M_PI)
keypress_bits |= (u32)1; // Forward keypress_bits |= (u32)1; // Forward
if (abs_d > 5.0f / 8.0f * M_PI) if (abs_d > 5.0f / 8.0f * M_PI)
@ -201,7 +201,7 @@ u32 PlayerControl::getKeysPressed() const
abs_d = movement_direction + M_PI_2; abs_d = movement_direction + M_PI_2;
if (abs_d >= M_PI) if (abs_d >= M_PI)
abs_d -= 2 * M_PI; abs_d -= 2 * M_PI;
abs_d = abs(abs_d); abs_d = std::abs(abs_d);
// (value now indicates left / right) // (value now indicates left / right)
if (abs_d < 3.0f / 8.0f * M_PI) if (abs_d < 3.0f / 8.0f * M_PI)
keypress_bits |= (u32)1 << 2; // Left keypress_bits |= (u32)1 << 2; // Left