1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #104386 from Repiteo/core/cpp-math

Core: Replace C math headers with C++ equivalents
This commit is contained in:
Thaddeus Crews
2025-04-27 19:21:22 -05:00
101 changed files with 414 additions and 498 deletions

View File

@@ -443,9 +443,9 @@ void JoypadLinux::joypad_vibration_start(Joypad &p_joypad, float p_weak_magnitud
struct ff_effect effect;
effect.type = FF_RUMBLE;
effect.id = -1;
effect.u.rumble.weak_magnitude = floor(p_weak_magnitude * (float)0xffff);
effect.u.rumble.strong_magnitude = floor(p_strong_magnitude * (float)0xffff);
effect.replay.length = floor(p_duration * 1000);
effect.u.rumble.weak_magnitude = std::floor(p_weak_magnitude * (float)0xffff);
effect.u.rumble.strong_magnitude = std::floor(p_strong_magnitude * (float)0xffff);
effect.replay.length = std::floor(p_duration * 1000);
effect.replay.delay = 0;
if (ioctl(p_joypad.fd, EVIOCSFF, &effect) < 0) {

View File

@@ -166,9 +166,9 @@ void TTS_Linux::_speech_event(int p_msg_id, int p_type) {
spd_set_voice_pitch(synth, (message.pitch - 1) * 100);
float rate = 0;
if (message.rate > 1.f) {
rate = log10(MIN(message.rate, 2.5f)) / log10(2.5f) * 100;
rate = std::log10(MIN(message.rate, 2.5f)) / std::log10(2.5f) * 100;
} else if (message.rate < 1.f) {
rate = log10(MAX(message.rate, 0.5f)) / log10(0.5f) * -100;
rate = std::log10(MAX(message.rate, 0.5f)) / std::log10(0.5f) * -100;
}
spd_set_voice_rate(synth, rate);
spd_set_data_mode(synth, SPD_DATA_SSML);

View File

@@ -1830,7 +1830,7 @@ void WaylandThread::_wl_pointer_on_frame(void *data, struct wl_pointer *wl_point
if (test_button == MouseButton::WHEEL_RIGHT || test_button == MouseButton::WHEEL_LEFT) {
// If this is a discrete scroll, specify how many "clicks" it did for this
// pointer frame.
mb->set_factor(fabs(pd.discrete_scroll_vector_120.x / (float)120));
mb->set_factor(std::abs(pd.discrete_scroll_vector_120.x / (float)120));
}
mb->set_button_mask(pd.pressed_button_mask);
@@ -3228,8 +3228,8 @@ void WaylandThread::window_state_update_size(WindowState *p_ws, int p_width, int
// must be scaled with away from zero half-rounding.
Vector2i WaylandThread::scale_vector2i(const Vector2i &p_vector, double p_amount) {
// This snippet is tiny, I know, but this is done a lot.
int x = round(p_vector.x * p_amount);
int y = round(p_vector.y * p_amount);
int x = std::round(p_vector.x * p_amount);
int y = std::round(p_vector.y * p_amount);
return Vector2i(x, y);
}
@@ -4198,8 +4198,8 @@ void WaylandThread::pointer_set_hint(const Point2i &p_hint) {
// discussing about this. I'm not really sure about the maths behind this but,
// oh well, we're setting a cursor hint. ¯\_(ツ)_/¯
// See: https://oftc.irclog.whitequark.org/wayland/2023-08-23#1692756914-1692816818
hint_x = round(p_hint.x / window_state_get_scale_factor(ws));
hint_y = round(p_hint.y / window_state_get_scale_factor(ws));
hint_x = std::round(p_hint.x / window_state_get_scale_factor(ws));
hint_y = std::round(p_hint.y / window_state_get_scale_factor(ws));
}
if (ss) {
@@ -4394,7 +4394,7 @@ void WaylandThread::cursor_shape_set_custom_image(DisplayServer::CursorShape p_c
// Fill the cursor buffer with the image data.
for (unsigned int index = 0; index < (unsigned int)(image_size.width * image_size.height); index++) {
int row_index = floor(index / image_size.width);
int row_index = std::floor(index / image_size.width);
int column_index = (index % int(image_size.width));
cursor.buffer_data[index] = p_image->get_pixel(column_index, row_index).to_argb32();

View File

@@ -3443,7 +3443,7 @@ void DisplayServerX11::cursor_set_custom_image(const Ref<Resource> &p_cursor, Cu
cursor_image->pixels = (XcursorPixel *)memalloc(size);
for (XcursorPixel index = 0; index < image_size; index++) {
int row_index = floor(index / texture_size.width);
int row_index = std::floor(index / texture_size.width);
int column_index = index % int(texture_size.width);
*(cursor_image->pixels + index) = image->get_pixel(column_index, row_index).to_argb32();