Skip to content

Commit

Permalink
Fix more type promotion mistakes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sfan5 committed Feb 26, 2024
1 parent 9fcd7f2 commit fbec378
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
36 changes: 15 additions & 21 deletions src/client/camera.cpp
Expand Up @@ -138,8 +138,8 @@ void Camera::notifyFovChange()
// Returns the fractional part of x
inline f32 my_modf(f32 x)
{
double dummy;
return modf(x, &dummy);
float dummy;
return std::modf(x, &dummy);
}

void Camera::step(f32 dtime)
Expand Down Expand Up @@ -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 bobknob = 1.2;
f32 bobtmp = sin(pow(bobfrac, bobknob) * M_PI);
f32 bobtmp = std::sin(std::pow(bobfrac, bobknob) * M_PI);

v3f bobvec = v3f(
0.3 * bobdir * sin(bobfrac * M_PI),
0.3 * bobdir * std::sin(bobfrac * M_PI),
-0.28 * bobtmp * bobtmp,
0.);

Expand Down Expand Up @@ -531,45 +531,39 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
addArmInertia(yaw);

// 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_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)
{
f32 frac = 1.0;
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 = 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);
//wield_position.Z += frac * 5.0 * ratiothing2;
wield_position.X -= frac * 35.0 * pow(ratiothing2, 1.1f);
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);
wield_position.Y -= frac * 25.0f * std::pow(ratiothing2, 1.7f);
wield_position.X -= frac * 35.0f * std::pow(ratiothing2, 1.1f);
wield_rotation.Y += frac * 70.0f * std::pow(ratiothing2, 1.4f);
}
if (m_digging_button != -1)
{
f32 digfrac = m_digging_anim;
wield_position.X -= 50 * sin(pow(digfrac, 0.8f) * M_PI);
wield_position.Y += 24 * sin(digfrac * 1.8 * M_PI);
wield_position.X -= 50 * std::sin(std::pow(digfrac, 0.8f) * M_PI);
wield_position.Y += 24 * std::sin(digfrac * 1.8 * M_PI);
wield_position.Z += 25 * 0.5;

// Euler angles are PURE EVIL, so why not use quaternions?
core::quaternion quat_begin(wield_rotation * core::DEGTORAD);
core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD);
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);
wield_rotation *= core::RADTODEG;
} else {
f32 bobfrac = my_modf(m_view_bobbing_anim);
wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0;
wield_position.Y += sin(my_modf(bobfrac*2.0)*M_PI) * 3.0;
wield_position.X -= std::sin(bobfrac*M_PI*2.0) * 3.0;
wield_position.Y += std::sin(my_modf(bobfrac*2.0)*M_PI) * 3.0;
}
m_wieldnode->setPosition(wield_position);
m_wieldnode->setRotation(wield_rotation);
Expand All @@ -584,8 +578,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
// view bobbing is enabled and free_move is off,
// start (or continue) the view bobbing animation.
const v3f &speed = player->getSpeed();
const bool movement_XZ = hypot(speed.X, speed.Z) > BS;
const bool movement_Y = fabs(speed.Y) > BS;
const bool movement_XZ = std::hypot(speed.X, speed.Z) > BS;
const bool movement_Y = std::abs(speed.Y) > BS;

const bool walking = movement_XZ && player->touching_ground;
const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid;
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.cpp
Expand Up @@ -1806,7 +1806,7 @@ struct TextureUpdateArgs {
void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress)
{
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
bool do_draw = false;
Expand Down
4 changes: 2 additions & 2 deletions src/client/game.cpp
Expand Up @@ -3708,11 +3708,11 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
break;
};
case NDT_SIGNLIKE: {
rotate90 = abs(pdir.X) < abs(pdir.Z);
rotate90 = std::abs(pdir.X) < std::abs(pdir.Z);
break;
}
default: {
rotate90 = abs(pdir.X) > abs(pdir.Z);
rotate90 = std::abs(pdir.X) > std::abs(pdir.Z);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/clientdynamicinfo.h
Expand Up @@ -38,8 +38,8 @@ struct ClientDynamicInfo

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

Expand Down
4 changes: 2 additions & 2 deletions src/particles.cpp
Expand Up @@ -46,9 +46,9 @@ T RangedParameter<T>::pickWithin() const
auto p = numericAbsolute(bias) + 1;
for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); ++i) {
if (bias < 0)
values[i] = 1.0f - pow(myrand_float(), p);
values[i] = 1.0f - std::pow(myrand_float(), p);
else
values[i] = pow(myrand_float(), p);
values[i] = std::pow(myrand_float(), p);
}
return T::pick(values, min, max);
}
Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Expand Up @@ -191,7 +191,7 @@ u32 PlayerControl::getKeysPressed() const
float abs_d;

// (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)
keypress_bits |= (u32)1; // Forward
if (abs_d > 5.0f / 8.0f * M_PI)
Expand All @@ -201,7 +201,7 @@ u32 PlayerControl::getKeysPressed() const
abs_d = movement_direction + M_PI_2;
if (abs_d >= M_PI)
abs_d -= 2 * M_PI;
abs_d = abs(abs_d);
abs_d = std::abs(abs_d);
// (value now indicates left / right)
if (abs_d < 3.0f / 8.0f * M_PI)
keypress_bits |= (u32)1 << 2; // Left
Expand Down

0 comments on commit fbec378

Please sign in to comment.