From 7bb8633c4429d71ea9870cecea04bdc6babdaff3 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sat, 26 Sep 2026 22:40:50 +0200 Subject: [PATCH 1/7] fix(core): call the float math functions, so MSVC computes what libstdc++ does --- apps/editor/editor_app.cc | 56 +++---- apps/editor/editor_terrain.cc | 18 +-- apps/editor/editor_ui.cc | 12 +- apps/editor/fly_camera.cc | 6 +- engine/anim/anim_graph.cc | 12 +- engine/anim/body_dynamics.cc | 30 ++-- engine/anim/expression.cc | 6 +- engine/anim/foot_ik.cc | 4 +- engine/anim/locomotion.cc | 16 +- engine/asset/bc_encode.cc | 6 +- engine/asset/gltf_loader.cc | 24 +-- engine/asset/primitives.cc | 30 ++-- engine/asset/procedural_texture.cc | 22 +-- engine/asset/subdivide.cc | 4 +- engine/asset/texture_compress.cc | 8 +- engine/asset/usd_loader.cc | 10 +- engine/audio/aux_synth.cc | 12 +- engine/audio/engine_synth.cc | 18 +-- engine/audio/mixer.cc | 2 +- engine/audio/spatial.h | 4 +- engine/audio/synth_voice.cc | 6 +- engine/audio/thunder_synth.cc | 26 +-- engine/audio/vehicle_audio.cc | 4 +- engine/character/character.cc | 24 +-- engine/character/jetpack.cc | 8 +- engine/combat/damage.cc | 2 +- engine/combat/projectile.cc | 4 +- engine/combat/weapon.cc | 26 +-- engine/core/input_bindings.cc | 10 +- engine/core/math.h | 30 ++-- engine/core/scalar.h | 28 ++++ engine/core/world_clock.cc | 4 +- engine/core/world_clock.h | 2 +- engine/edit/scene_io.cc | 8 +- engine/inventory/world_item.cc | 8 +- engine/locomotion/controller.cc | 8 +- engine/locomotion/estimator.cc | 6 +- engine/locomotion/footstep.cc | 6 +- engine/locomotion/gait.cc | 4 +- engine/locomotion/internal_math.h | 10 +- engine/locomotion/rig.cc | 4 +- engine/locomotion/whole_body.cc | 16 +- engine/nav/agent.cc | 10 +- engine/nav/nav_debug.cc | 2 +- engine/nav/navmesh.cc | 28 ++-- engine/nav/path.cc | 6 +- engine/net/bubble.cc | 18 +-- engine/net/replication.cc | 4 +- engine/net/session.cc | 4 +- engine/physics/aircraft.cc | 22 +-- engine/physics/boat.cc | 20 +-- engine/physics/cloth_collision.cc | 30 ++-- engine/physics/kite.cc | 14 +- engine/physics/physics_world.cc | 88 +++++----- engine/physics/water_waves.h | 6 +- engine/placement/density_program.cc | 2 +- engine/placement/placement.cc | 10 +- engine/placement/placement_math.h | 14 +- engine/placement/world_data.cc | 6 +- engine/render/atmosphere/cloudscape.cc | 40 ++--- .../render/atmosphere/cloudscape_textures.cc | 2 +- engine/render/atmosphere/lightning_envelope.h | 8 +- engine/render/atmosphere/precip_occlusion.cc | 6 +- engine/render/core/dynamic_resolution.cc | 8 +- engine/render/core/renderer.cc | 96 +++++------ engine/render/core/settings_ini.cc | 2 +- engine/render/geometry/gaussian.cc | 10 +- engine/render/geometry/hair_groom.cc | 52 +++--- engine/render/geometry/hair_strands.cc | 8 +- engine/render/geometry/imposters.cc | 6 +- engine/render/geometry/instance_store.cc | 8 +- engine/render/geometry/ocean_fft.cc | 10 +- engine/render/geometry/particle_emitters.cc | 18 +-- engine/render/geometry/procedural_grass.cc | 32 ++-- engine/render/geometry/procedural_grass.h | 6 +- engine/render/geometry/shore_wetting.cc | 4 +- engine/render/geometry/water_field.cc | 6 +- engine/render/gi/ddgi.cc | 14 +- engine/render/gi/light_grid.cc | 6 +- engine/render/gi/local_shadows.cc | 4 +- engine/render/gi/rcgi.cc | 14 +- engine/render/gi/rcgi_interior.h | 2 +- engine/render/gi/rt_instance_cull.cc | 6 +- engine/render/gi/sdf_clipmap.cc | 12 +- engine/render/gi/sdf_scene.cc | 14 +- engine/render/gi/shadow.cc | 14 +- engine/render/gi/shadow_trace.cc | 2 +- engine/render/pipeline/gpu_cull.cc | 2 +- engine/render/pipeline/hair_material.cc | 52 +++--- engine/render/pipeline/human_material.cc | 26 +-- engine/render/pipeline/material_system.cc | 8 +- engine/render/pipeline/meshlet.cc | 14 +- engine/render/pipeline/virtual_geometry.cc | 2 +- engine/render/texturing/virtual_texture.cc | 6 +- engine/render2d/camera2d.h | 2 +- engine/render2d/iso.h | 2 +- engine/render2d/sprite_renderer.cc | 12 +- engine/render2d/tile_map.cc | 6 +- engine/render2d/tile_map.h | 2 +- engine/render2d/types2d.h | 2 +- engine/scene/camera.cc | 10 +- engine/scene/camera_rig.cc | 24 +-- engine/scene/scene_handlers.cc | 6 +- engine/scene/world_streaming.cc | 24 +-- engine/terrain/terrain.cc | 74 ++++----- engine/terrain/terrain_io.cc | 24 +-- engine/weather/weather.cc | 50 +++--- engine/world/world_bake.cc | 8 +- engine/world/world_format.cc | 18 +-- engine/world/world_map.cc | 4 +- engine/world/world_overlay.cc | 8 +- runtime/camera_input.cc | 6 +- runtime/demo_drive.cc | 50 +++--- runtime/demo_grass.cc | 22 +-- runtime/demo_gym.cc | 22 +-- runtime/demo_lookdev.cc | 16 +- runtime/demo_nav.cc | 24 +-- runtime/demo_placement.cc | 10 +- runtime/demo_puppet.cc | 10 +- runtime/demo_scenes.cc | 152 +++++++++--------- runtime/demo_ship.cc | 28 ++-- runtime/demo_shooter.cc | 4 +- runtime/feature_gym/feature_gym.cc | 86 +++++----- runtime/fly_camera.cc | 6 +- runtime/placement_demo_assets.cc | 22 +-- runtime/scene_authoring.cc | 6 +- runtime/scene_validate.cc | 10 +- runtime/viewer.cc | 36 ++--- test/aircraft_test.cc | 24 +-- test/bc_encode_test.cc | 20 +-- test/blend_jiggle_test.cc | 4 +- test/boat_profiles_test.cc | 22 +-- test/boat_test.cc | 24 +-- test/body_dynamics_test.cc | 18 +-- test/camera_rig_test.cc | 2 +- test/camera_test.cc | 6 +- test/character_test.cc | 8 +- test/cloth_collision_test.cc | 4 +- test/cloth_sim_test.cc | 8 +- test/cloud_lighting_test.cc | 10 +- test/combat_test.cc | 2 +- test/decal_bake_test.cc | 6 +- test/edit_test.cc | 8 +- test/expression_test.cc | 8 +- test/fluid_sim_test.cc | 12 +- test/gltf_skin_test.cc | 10 +- test/gltf_texture_transform_test.cc | 2 +- test/hair_bsdf_test.cc | 20 +-- test/hair_sim_test.cc | 6 +- test/handling_test.cc | 36 ++--- test/human_brdf_test.cc | 26 +-- test/input_touch_sdl_test.cc | 2 +- test/input_touch_test.cc | 2 +- test/instance_store_test.cc | 2 +- test/inventory_test.cc | 2 +- test/jetpack_test.cc | 14 +- test/kite_test.cc | 22 +-- test/lens_flare_test.cc | 8 +- test/locomotion_math_test.cc | 20 +-- test/locomotion_test.cc | 32 ++-- test/materialx_test.cc | 14 +- test/morph_test.cc | 6 +- test/nav_test.cc | 4 +- test/net_test.cc | 4 +- test/openpbr_test.cc | 4 +- test/path_motion_test.cc | 4 +- test/path_sampling_test.cc | 24 +-- test/physics_body_test.cc | 14 +- test/placement_gpu_test.cc | 6 +- test/placement_test.cc | 16 +- test/post_sampling_test.cc | 8 +- test/procedural_asset_test.cc | 36 ++--- test/procedural_grass_test.cc | 8 +- test/raytracing_test.cc | 10 +- test/rcgi_interior_test.cc | 2 +- test/recon_atrous_test.cc | 4 +- test/recon_temporal_test.cc | 4 +- test/render2d_test.cc | 4 +- test/scene_authoring_test.cc | 12 +- test/script_test.cc | 14 +- test/settings_ini_test.cc | 2 +- test/terrain_test.cc | 4 +- test/thunder_synth_test.cc | 6 +- test/upscaler_motion_test.cc | 10 +- test/usd_scene_test.cc | 2 +- test/vehicle_audio_test.cc | 24 +-- test/vehicle_integration_test.cc | 24 +-- test/vehicle_test.cc | 18 +-- test/walk_style_test.cc | 8 +- test/weather_test.cc | 12 +- test/world_streaming_test.cc | 8 +- tools/rxdiff.cc | 2 +- 192 files changed, 1435 insertions(+), 1407 deletions(-) diff --git a/apps/editor/editor_app.cc b/apps/editor/editor_app.cc index 2c66b59a..42dcd980 100644 --- a/apps/editor/editor_app.cc +++ b/apps/editor/editor_app.cc @@ -82,7 +82,7 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id, const u32 top_ring = static_cast(lod.vertices.size()); for (u32 i = 0; i <= kSegments; ++i) { const f32 angle = static_cast(i) / kSegments * 6.28318530718f; - const f32 x = ::cos(angle), z = ::sin(angle); + const f32 x = ::cosf(angle), z = ::sinf(angle); lod.vertices.push_back(vertex({x * radius, half_height, z * radius}, {0, 1, 0}, x * 0.5f + 0.5f, z * 0.5f + 0.5f)); @@ -92,7 +92,7 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id, const u32 bottom_ring = static_cast(lod.vertices.size()); for (u32 i = 0; i <= kSegments; ++i) { const f32 angle = static_cast(i) / kSegments * 6.28318530718f; - const f32 x = ::cos(angle), z = ::sin(angle); + const f32 x = ::cosf(angle), z = ::sinf(angle); lod.vertices.push_back(vertex({x * radius, -half_height, z * radius}, {0, -1, 0}, x * 0.5f + 0.5f, z * 0.5f + 0.5f)); @@ -100,7 +100,7 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id, const u32 side_ring = static_cast(lod.vertices.size()); for (u32 i = 0; i <= kSegments; ++i) { const f32 angle = static_cast(i) / kSegments * 6.28318530718f; - const f32 x = ::cos(angle), z = ::sin(angle); + const f32 x = ::cosf(angle), z = ::sinf(angle); lod.vertices.push_back( vertex({x * radius, half_height, z * radius}, {x, 0, z}, static_cast(i) / kSegments, 0)); @@ -125,7 +125,7 @@ asset::Mesh MakeTurntable(f32 radius, f32 half_height, asset::AssetId id, } lod.submeshes.push_back( {0, static_cast(lod.indices.size()), material}); - mesh.bounds_radius = ::sqrt(radius * radius + half_height * half_height); + mesh.bounds_radius = ::sqrtf(radius * radius + half_height * half_height); return mesh; } } // namespace @@ -157,8 +157,8 @@ bool Editor::OnInitialize(app::Services &s) { camera_.set_position({6.0f, 4.5f, 6.0f}); Vec3 d = Normalize(Vec3{0, 1.0f, 0} - camera_.position()); - camera_.set_yaw_pitch(::atan2(d.x, -d.z), - ::asin(rx::Clamp(d.y, -1.0f, 1.0f))); + camera_.set_yaw_pitch(::atan2f(d.x, -d.z), + ::asinf(rx::Clamp(d.y, -1.0f, 1.0f))); // Load a scene or authoring model passed on argv. if (!open_path_.empty()) { @@ -579,7 +579,7 @@ bool Editor::LoadModelDocument(const base::String &path) { .y); } } - if (!::isfinite(floor_y)) + if (!isfinite(floor_y)) floor_y = center.y - radius; constexpr f32 kPlateHalfHeight = 0.055f; const f32 surface_y = @@ -629,8 +629,8 @@ bool Editor::LoadModelDocument(const base::String &path) { camera_.set_position(center + Vec3{radius * 1.4f, radius * 0.75f, radius * 1.8f}); Vec3 direction = Normalize(center - camera_.position()); - camera_.set_yaw_pitch(::atan2(direction.x, -direction.z), - ::asin(rx::Clamp(direction.y, -1.0f, 1.0f))); + camera_.set_yaw_pitch(::atan2f(direction.x, -direction.z), + ::asinf(rx::Clamp(direction.y, -1.0f, 1.0f))); status_message_ = "Imported " + base::String(fs::Filename(path)) + ": " + rx::ToString(imported_scene.meshes.size()) + " meshes, " + rx::ToString(region_count) + " jiggle regions" + @@ -660,7 +660,7 @@ void Editor::UpdateImportedModels(f32 dt) { model.active_walk_style = anim::WalkStyleKind::kMarch; walk_style = march; } else { - const f32 cycle = ::fmod(model.preview_time, 12.0f); + const f32 cycle = ::fmodf(model.preview_time, 12.0f); if (cycle < 5.0f) { model.active_walk_style = anim::WalkStyleKind::kHipSway; walk_style = hip_sway; @@ -737,14 +737,14 @@ void Editor::UpdateImportedModels(f32 dt) { anim::BodyDynamicsFrame frame; if (playing_) { frame.linear_acceleration = { - ::sin(model.preview_time * 2.7f) * 7.0f, - ::sin(model.preview_time * 5.4f) * 5.5f, - ::cos(model.preview_time * 2.1f) * 6.0f, + ::sinf(model.preview_time * 2.7f) * 7.0f, + ::sinf(model.preview_time * 5.4f) * 5.5f, + ::cosf(model.preview_time * 2.1f) * 6.0f, }; frame.angular_acceleration = { - ::sin(model.preview_time * 2.3f) * 2.8f, - ::cos(model.preview_time * 1.7f) * 3.5f, - ::sin(model.preview_time * 3.2f) * 3.0f, + ::sinf(model.preview_time * 2.3f) * 2.8f, + ::cosf(model.preview_time * 1.7f) * 3.5f, + ::sinf(model.preview_time * 3.2f) * 3.0f, }; if (fire_event) { if (event_kind == 0) @@ -917,8 +917,8 @@ void Editor::FocusSelection() { Vec3 eye = center - camera_.forward() * 4.0f; camera_.set_position(eye); Vec3 d = Normalize(center - eye); - camera_.set_yaw_pitch(::atan2(d.x, -d.z), - ::asin(rx::Clamp(d.y, -1.0f, 1.0f))); + camera_.set_yaw_pitch(::atan2f(d.x, -d.z), + ::asinf(rx::Clamp(d.y, -1.0f, 1.0f))); } // Picking. The engine GPU path (DrawItem::pick_id + Renderer::RequestPick / @@ -966,7 +966,7 @@ bool RayTriangle(const Vec3 &o, const Vec3 &d, const Vec3 &a, const Vec3 &b, Vec3 e1 = b - a, e2 = c - a; Vec3 p = Cross(d, e2); f32 det = Dot(e1, p); - if (::fabs(det) < 1e-8f) + if (::fabsf(det) < 1e-8f) return false; f32 inv = 1.0f / det; Vec3 tv = o - a; @@ -1052,7 +1052,7 @@ Vec2 Editor::ProjectToScreen(const Vec3 &world, bool *in_front) const { f32 w = vp.m[3] * world.x + vp.m[7] * world.y + vp.m[11] * world.z + vp.m[15]; if (in_front) *in_front = w > 1e-4f; - if (::fabs(w) < 1e-6f) + if (::fabsf(w) < 1e-6f) w = 1e-6f; f32 ndc_x = x / w, ndc_y = y / w; return {(ndc_x * 0.5f + 0.5f) * window_->width(), @@ -1112,7 +1112,7 @@ void Editor::UpdateGizmo(f32 mx, f32 my, bool lmb_down, bool lmb_edge) { // distance from cursor to the handle tip. The tolerance is authored at // 1x and both operands are pixels, so it scales with the buffer or the // handle gets relatively harder to grab the denser the display. - f32 d = ::hypot(mx - s1.x, my - s1.y); + f32 d = ::hypotf(mx - s1.x, my - s1.y); if (d < 14.0f * window_->pixel_density()) { gizmo_drag_.active = true; gizmo_drag_.axis = a; @@ -1121,7 +1121,7 @@ void Editor::UpdateGizmo(f32 mx, f32 my, bool lmb_down, bool lmb_edge) { gizmo_drag_.grab_mouse_x = mx; gizmo_drag_.grab_mouse_y = my; Vec2 sd{s1.x - s0.x, s1.y - s0.y}; - f32 sl = rx::Max(1.0f, ::hypot(sd.x, sd.y)); + f32 sl = rx::Max(1.0f, ::hypotf(sd.x, sd.y)); gizmo_drag_.axis_screen_dir = {sd.x / sl, sd.y / sl}; gizmo_drag_.world_per_pixel = len / sl; undo_.BeginGroup("Move"); @@ -1585,7 +1585,7 @@ void Editor::RunAutopilot() { scene::Transform *t = world_->Get(find_named("Cube")); RX_INFO("autopilot: undo -> cube z={:.2f} expected 0 -> {}", t ? t->position[2] : -99.f, - (t && ::fabs(t->position[2]) < 1e-3f) ? "PASS" : "FAIL"); + (t && ::fabsf(t->position[2]) < 1e-3f) ? "PASS" : "FAIL"); MarkDirty(); break; } @@ -1594,7 +1594,7 @@ void Editor::RunAutopilot() { scene::Transform *t = world_->Get(find_named("Cube")); RX_INFO("autopilot: redo -> cube z={:.2f} expected 2 -> {}", t ? t->position[2] : -99.f, - (t && ::fabs(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL"); + (t && ::fabsf(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL"); MarkDirty(); break; } @@ -1628,7 +1628,7 @@ void Editor::RunAutopilot() { const f32 height = terrain_.SampleHeight(0, 0).value_or(-99.0f); RX_INFO("autopilot: terrain undo height={:.3f} expected {:.3f} -> {}", height, terrain_before, - ::fabs(height - terrain_before) < 1e-4f ? "PASS" : "FAIL"); + ::fabsf(height - terrain_before) < 1e-4f ? "PASS" : "FAIL"); break; } case 520: { @@ -1636,7 +1636,7 @@ void Editor::RunAutopilot() { const f32 height = terrain_.SampleHeight(0, 0).value_or(-99.0f); RX_INFO("autopilot: terrain redo height={:.3f} expected {:.3f} -> {}", height, terrain_after, - ::fabs(height - terrain_after) < 1e-4f ? "PASS" : "FAIL"); + ::fabsf(height - terrain_after) < 1e-4f ? "PASS" : "FAIL"); break; } case 530: @@ -1661,10 +1661,10 @@ void Editor::RunAutopilot() { scene::Transform *t = e ? world_->Get(e) : nullptr; RX_INFO("autopilot: after load cube z={:.2f} expected 2 -> {}", t ? t->position[2] : -99.f, - (t && ::fabs(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL"); + (t && ::fabsf(t->position[2] - 2.0f) < 1e-3f) ? "PASS" : "FAIL"); const f32 height = terrain_.SampleHeight(0, 0).value_or(-99.0f); const bool sidecar_pass = fs::Exists("scene_saved.rxterrain") && - ::fabs(height - terrain_after) < 2e-3f; + ::fabsf(height - terrain_after) < 2e-3f; RX_INFO("autopilot: terrain sidecar height={:.3f} expected {:.3f} -> {}", height, terrain_after, sidecar_pass ? "PASS" : "FAIL"); break; diff --git a/apps/editor/editor_terrain.cc b/apps/editor/editor_terrain.cc index d568f3d9..68e8fc7d 100644 --- a/apps/editor/editor_terrain.cc +++ b/apps/editor/editor_terrain.cc @@ -121,14 +121,14 @@ void Editor::SetupDefaultTerrain() { const i32 grid_z = tile_z * static_cast(quads) + static_cast(z); const f32 world_x = grid_x * spacing; const f32 world_z = grid_z * spacing; - const f32 broad = 0.46f * ::sin(world_x * 0.22f) * ::cos(world_z * 0.18f); - const f32 detail = 0.17f * ::sin((world_x + world_z) * 0.48f) + - 0.10f * ::cos((world_x - world_z) * 0.61f); - const f32 knoll = 0.30f * ::exp(-(world_x * world_x + world_z * world_z) / 95.0f); + const f32 broad = 0.46f * ::sinf(world_x * 0.22f) * ::cosf(world_z * 0.18f); + const f32 detail = 0.17f * ::sinf((world_x + world_z) * 0.48f) + + 0.10f * ::cosf((world_x - world_z) * 0.61f); + const f32 knoll = 0.30f * ::expf(-(world_x * world_x + world_z * world_z) / 95.0f); const size_t sample = static_cast(z) * side + x; heights[sample] = broad + detail + knoll; - const f32 patch = ::sin(world_x * 0.31f) * ::cos(world_z * 0.27f); + const f32 patch = ::sinf(world_x * 0.31f) * ::cosf(world_z * 0.27f); if (heights[sample] > 0.62f) { weights[sample].rgba = {40, 25, 190, 0}; } else if (heights[sample] < -0.25f) { @@ -235,7 +235,7 @@ base::Pair Editor::ViewportCameraRay(f32 mx, f32 my) const { const f32 height = static_cast(window_->height()); const f32 ndc_x = 2.0f * mx / width - 1.0f; const f32 ndc_y = 1.0f - 2.0f * my / height; - const f32 tan_half_fov = ::tan(1.0472f * 0.5f); + const f32 tan_half_fov = ::tanf(1.0472f * 0.5f); const Vec3 forward = camera_.forward(); const Vec3 right = Normalize(Cross(forward, {0, 1, 0})); const Vec3 up = Cross(right, forward); @@ -425,7 +425,7 @@ void Editor::UpdateModeInteraction(bool lmb_down, bool lmb_edge) { if (terrain_cursor_hit_) { position = terrain_cursor_hit_->position; } else { - const f32 plane_t = ::fabs(direction.y) > 1e-5f ? -origin.y / direction.y : -1.0f; + const f32 plane_t = ::fabsf(direction.y) > 1e-5f ? -origin.y / direction.y : -1.0f; position = plane_t > 0 ? origin + direction * plane_t : origin + direction * 5.0f; } position.y += vertical_offset; @@ -516,8 +516,8 @@ void Editor::AppendInteractionPreview(base::Vector* lines) co Vec3 previous; for (int i = 0; i <= kSegments; ++i) { const f32 angle = static_cast(i) * 6.2831853f / kSegments; - Vec3 point{center.x + ::cos(angle) * radius, center.y + 0.035f, - center.z + ::sin(angle) * radius}; + Vec3 point{center.x + ::cosf(angle) * radius, center.y + 0.035f, + center.z + ::sinf(angle) * radius}; if (editor_mode_ == EditorMode::kTerrain) { if (base::Optional y = terrain_.SampleHeight(point.x, point.z)) point.y = *y + 0.035f; } diff --git a/apps/editor/editor_ui.cc b/apps/editor/editor_ui.cc index f51dd8e3..b12b0561 100644 --- a/apps/editor/editor_ui.cc +++ b/apps/editor/editor_ui.cc @@ -107,13 +107,13 @@ base::String EscapeUguiString(base::StringRef value) { void QuatToEuler(const Quat &q, f32 out_deg[3]) { f32 sinr = 2 * (q.w * q.x + q.y * q.z); f32 cosr = 1 - 2 * (q.x * q.x + q.y * q.y); - f32 x = ::atan2(sinr, cosr); + f32 x = ::atan2f(sinr, cosr); f32 sinp = 2 * (q.w * q.y - q.z * q.x); f32 y = - ::fabs(sinp) >= 1 ? ::copysign(1.5707963f, sinp) : ::asin(sinp); + ::fabsf(sinp) >= 1 ? ::copysignf(1.5707963f, sinp) : ::asinf(sinp); f32 siny = 2 * (q.w * q.z + q.x * q.y); f32 cosy = 1 - 2 * (q.y * q.y + q.z * q.z); - f32 z = ::atan2(siny, cosy); + f32 z = ::atan2f(siny, cosy); const f32 r2d = 57.29578f; out_deg[0] = x * r2d; out_deg[1] = y * r2d; @@ -121,9 +121,9 @@ void QuatToEuler(const Quat &q, f32 out_deg[3]) { } Quat EulerToQuat(const f32 deg[3]) { const f32 d2r = 0.0174533f; - f32 cx = ::cos(deg[0] * d2r * 0.5f), sx = ::sin(deg[0] * d2r * 0.5f); - f32 cy = ::cos(deg[1] * d2r * 0.5f), sy = ::sin(deg[1] * d2r * 0.5f); - f32 cz = ::cos(deg[2] * d2r * 0.5f), sz = ::sin(deg[2] * d2r * 0.5f); + f32 cx = ::cosf(deg[0] * d2r * 0.5f), sx = ::sinf(deg[0] * d2r * 0.5f); + f32 cy = ::cosf(deg[1] * d2r * 0.5f), sy = ::sinf(deg[1] * d2r * 0.5f); + f32 cz = ::cosf(deg[2] * d2r * 0.5f), sz = ::sinf(deg[2] * d2r * 0.5f); return Normalize( Quat{sx * cy * cz - cx * sy * sz, cx * sy * cz + sx * cy * sz, cx * cy * sz - sx * sy * cz, cx * cy * cz + sx * sy * sz}); diff --git a/apps/editor/fly_camera.cc b/apps/editor/fly_camera.cc index 19e6a611..5d602290 100644 --- a/apps/editor/fly_camera.cc +++ b/apps/editor/fly_camera.cc @@ -6,7 +6,7 @@ namespace rx { Vec3 FlyCamera::forward() const { - return {::cos(pitch_) * ::sin(yaw_), ::sin(pitch_), -::cos(pitch_) * ::cos(yaw_)}; + return {::cosf(pitch_) * ::sinf(yaw_), ::sinf(pitch_), -::cosf(pitch_) * ::cosf(yaw_)}; } void FlyCamera::Update(const InputState& input, const ActionState& actions, bool allow_mouse, @@ -17,7 +17,7 @@ void FlyCamera::Update(const InputState& input, const ActionState& actions, bool yaw_ += input.mouse_dx * sensitivity; pitch_ -= input.mouse_dy * sensitivity; if (input.wheel != 0) { - speed *= ::pow(1.2f, input.wheel); + speed *= ::powf(1.2f, input.wheel); speed = rx::Clamp(speed, 0.1f, 200.0f); } } @@ -39,7 +39,7 @@ void FlyCamera::Update(const InputState& input, const ActionState& actions, bool if (actions.down(Action::kCamUp) || actions.down(Action::kJump)) move += Vec3{0, 1, 0}; if (actions.down(Action::kCamDown) || actions.down(Action::kSneak)) move += Vec3{0, -1, 0}; - f32 length = ::sqrt(Dot(move, move)); + f32 length = ::sqrtf(Dot(move, move)); if (length > 0) { f32 boost = actions.down(Action::kSprint) ? 4.0f : 1.0f; position_ += move * (speed * boost * dt / length); diff --git a/engine/anim/anim_graph.cc b/engine/anim/anim_graph.cc index 4b1c25f1..e02b3a01 100644 --- a/engine/anim/anim_graph.cc +++ b/engine/anim/anim_graph.cc @@ -100,7 +100,7 @@ kinema::OwnedClip BakeGait(const kinema::Skeleton& sk, u32 frames, f32 rate, con for (u32 fr = 0; fr < frames; ++fr) { const f32 phase = static_cast(fr) / static_cast(frames - 1); // 0..1, wraps const f32 theta = phase * kTwoPi; - const f32 leg = ::sin(theta); + const f32 leg = ::sinf(theta); for (u32 bone = 0; bone < bones; ++bone) { kinema::Quat rot = sk.bind_rotation[bone]; @@ -108,19 +108,19 @@ kinema::OwnedClip BakeGait(const kinema::Skeleton& sk, u32 frames, f32 rate, con if (is(j.l_thigh)) rot = Compose(rot, x, amp.thigh * leg); else if (is(j.r_thigh)) rot = Compose(rot, x, -amp.thigh * leg); else if (is(j.l_calf)) - rot = Compose(rot, x, -amp.knee * Clamp01(-::sin(theta - 0.6f))); + rot = Compose(rot, x, -amp.knee * Clamp01(-::sinf(theta - 0.6f))); else if (is(j.r_calf)) - rot = Compose(rot, x, -amp.knee * Clamp01(-::sin(theta + kPi - 0.6f))); + rot = Compose(rot, x, -amp.knee * Clamp01(-::sinf(theta + kPi - 0.6f))); else if (is(j.l_arm)) rot = Compose(rot, x, -amp.arm * leg); else if (is(j.r_arm)) rot = Compose(rot, x, amp.arm * leg); - else if (is(j.spine1)) rot = Compose(rot, z, amp.spine * ::cos(theta)); + else if (is(j.spine1)) rot = Compose(rot, z, amp.spine * ::cosf(theta)); else if (is(j.spine)) rot = Compose(rot, x, amp.lean); // constant forward lean b.SetSample(fr, bone, sk.bind_translation[bone], rot, sk.bind_scale[bone]); } if (curve >= 0) { // Two intensity pulses per cycle, peaking at the footfalls. - f32 pL = ::exp(-::pow((phase - 0.25f) * 6.0f, 2.0f)); - f32 pR = ::exp(-::pow((phase - 0.75f) * 6.0f, 2.0f)); + f32 pL = ::expf(-::powf((phase - 0.25f) * 6.0f, 2.0f)); + f32 pR = ::expf(-::powf((phase - 0.75f) * 6.0f, 2.0f)); b.SetCurveSample(fr, static_cast(curve), rx::Max(pL, pR)); } } diff --git a/engine/anim/body_dynamics.cc b/engine/anim/body_dynamics.cc index 4e17517b..a6af919f 100644 --- a/engine/anim/body_dynamics.cc +++ b/engine/anim/body_dynamics.cc @@ -47,26 +47,26 @@ void Spring(f32 *x, f32 *velocity, f32 force, f32 frequency, f32 damping, const f32 z = rx::Max(damping, 0.0f); if (z < 1.0f - 1e-4f) { - const f32 wd = w * ::sqrt(1.0f - z * z); - const f32 e = ::exp(-z * w * dt); - const f32 c = ::cos(wd * dt); - const f32 s = ::sin(wd * dt); + const f32 wd = w * ::sqrtf(1.0f - z * z); + const f32 e = ::expf(-z * w * dt); + const f32 c = ::cosf(wd * dt); + const f32 s = ::sinf(wd * dt); const f32 a = (v + z * w * y) / wd; *x = target + e * (y * c + a * s); *velocity = e * (v * c - ((z * w * v + w * w * y) / wd) * s); } else if (z <= 1.0f + 1e-4f) { - const f32 e = ::exp(-w * dt); + const f32 e = ::expf(-w * dt); const f32 a = v + w * y; *x = target + (y + a * dt) * e; *velocity = (v - w * a * dt) * e; } else { - const f32 root = ::sqrt(z * z - 1.0f); + const f32 root = ::sqrtf(z * z - 1.0f); const f32 r1 = -w * (z - root); const f32 r2 = -w * (z + root); const f32 c1 = (v - r2 * y) / (r1 - r2); const f32 c2 = y - c1; - const f32 e1 = ::exp(r1 * dt); - const f32 e2 = ::exp(r2 * dt); + const f32 e1 = ::expf(r1 * dt); + const f32 e2 = ::expf(r2 * dt); *x = target + c1 * e1 + c2 * e2; *velocity = r1 * c1 * e1 + r2 * c2 * e2; } @@ -80,7 +80,7 @@ void Spring(Vec3 *x, Vec3 *velocity, const Vec3 &force, f32 frequency, } Vec3 ExpSmooth(const Vec3 &previous, const Vec3 &value, f32 halflife, f32 dt) { - const f32 t = 1.0f - ::exp(-0.69314718f * dt / rx::Max(halflife, 1e-4f)); + const f32 t = 1.0f - ::expf(-0.69314718f * dt / rx::Max(halflife, 1e-4f)); return Lerp(previous, value, t); } @@ -91,11 +91,11 @@ Vec3 QuaternionVelocity(Quat previous, Quat current, f32 dt) { if (delta.w < 0) delta = {-delta.x, -delta.y, -delta.z, -delta.w}; const f32 sin_half = - ::sqrt(delta.x * delta.x + delta.y * delta.y + delta.z * delta.z); + ::sqrtf(delta.x * delta.x + delta.y * delta.y + delta.z * delta.z); if (sin_half < 1e-6f || dt <= 0) return {}; const f32 angle = - 2.0f * ::atan2(sin_half, rx::Clamp(delta.w, -1.0f, 1.0f)); + 2.0f * ::atan2f(sin_half, rx::Clamp(delta.w, -1.0f, 1.0f)); return Vec3{delta.x, delta.y, delta.z} * (angle / (sin_half * dt)); } @@ -284,14 +284,14 @@ void BodyDynamics::Update(const asset::Skeleton &skeleton, Resolve(skeleton); } const f32 model_units_per_metre = rx::Max( - ::isfinite(frame.model_units_per_metre) ? frame.model_units_per_metre + isfinite(frame.model_units_per_metre) ? frame.model_units_per_metre : 1.0f, 1e-6f); - if (::fabs(model_units_per_metre - model_units_per_metre_) > 1e-5f) { + if (::fabsf(model_units_per_metre - model_units_per_metre_) > 1e-5f) { Reset(); model_units_per_metre_ = model_units_per_metre; } - if (frame.teleport || !::isfinite(dt) || dt <= 0 || dt > 0.25f) + if (frame.teleport || !isfinite(dt) || dt <= 0 || dt > 0.25f) Reset(); ComputeModelMatrices(skeleton, *pose, &model_); @@ -386,7 +386,7 @@ void BodyDynamics::Update(const asset::Skeleton &skeleton, const f32 impact_from_impulse = Length(frame.linear_impulse) / 2.0f; state.impact = rx::Max( state.impact * - ::exp(-0.69314718f * dt / rx::Max(config.impact_decay, 1e-4f)), + ::expf(-0.69314718f * dt / rx::Max(config.impact_decay, 1e-4f)), rx::Clamp(rx::Max(impact_from_acceleration, impact_from_impulse), 0.0f, 1.0f)); diff --git a/engine/anim/expression.cc b/engine/anim/expression.cc index e5512404..e80f5a66 100644 --- a/engine/anim/expression.cc +++ b/engine/anim/expression.cc @@ -20,7 +20,7 @@ void Damp(f32* x, f32* v, f32 goal, f32 halflife, f32 dt) { const f32 y = (2.0f * 0.69314718f) / rx::Max(halflife, 1e-4f); const f32 j0 = *x - goal; const f32 j1 = *v + j0 * y; - const f32 e = ::exp(-y * dt); + const f32 e = ::expf(-y * dt); *x = goal + (j0 + j1 * dt) * e; *v = (*v - j1 * y * dt) * e; } @@ -37,7 +37,7 @@ f32 ToUnit(u64 value) { return static_cast(value >> 40) * (1.0f / 16777216. // Stateless value noise in [-1, 1]: random knots at integer positions of `s`, // smoothstep between them - smooth drift, never jitter. f32 SmoothNoise(u64 seed, u32 lane, f32 s) { - const f32 floor = ::floor(s); + const f32 floor = ::floorf(s); const i64 knot = static_cast(floor); auto knot_value = [&](i64 k) { u64 state = seed ^ (static_cast(lane) * 0xD6E8FEB86659FD93ull) ^ @@ -273,7 +273,7 @@ void ExpressionController::Update(f32 dt) { f32 out = channel.value; if (life_.enabled && channel.micro >= 0) { // Micro-motion fades as the expression takes the channel over. - const f32 headroom = 1.0f - rx::Min(::abs(channel.value), 1.0f); + const f32 headroom = 1.0f - rx::Min(::fabsf(channel.value), 1.0f); out += life_.micro_amplitude * headroom * SmoothNoise(seed_, static_cast(channel.micro), life_time_ * life_.micro_hz); } diff --git a/engine/anim/foot_ik.cc b/engine/anim/foot_ik.cc index 2d59e971..1a22bb0b 100644 --- a/engine/anim/foot_ik.cc +++ b/engine/anim/foot_ik.cc @@ -96,7 +96,7 @@ void SolveFootIk(const asset::Skeleton& skeleton, const GroundQuery& ground, con if (l_thigh < 1e-4f || l_calf < 1e-4f) continue; Vec3 to_target = p.target - a; - f32 reach = Clamp(Length(to_target), ::fabs(l_thigh - l_calf) + 1e-3f, + f32 reach = Clamp(Length(to_target), ::fabsf(l_thigh - l_calf) + 1e-3f, l_thigh + l_calf - 1e-3f); Vec3 dir = Normalize(to_target); Vec3 effective_target = a + dir * reach; @@ -106,7 +106,7 @@ void SolveFootIk(const asset::Skeleton& skeleton, const GroundQuery& ground, con f32 cos_hip = Clamp((l_thigh * l_thigh + reach * reach - l_calf * l_calf) / (2.0f * l_thigh * reach), -1.0f, 1.0f); - f32 hip_angle = ::acos(cos_hip); + f32 hip_angle = ::acosf(cos_hip); Vec3 plane_n = Cross(dir, forward); if (Length(plane_n) < 1e-4f) plane_n = Cross(dir, up); plane_n = Normalize(plane_n); diff --git a/engine/anim/locomotion.cc b/engine/anim/locomotion.cc index a9a7636f..fd6ee240 100644 --- a/engine/anim/locomotion.cc +++ b/engine/anim/locomotion.cc @@ -112,7 +112,7 @@ f32 AdvancePhase(f32 phase, f32 speed, f32 dt, const WalkStyle &style) { f32 cycles_per_second = speed > 0.01f ? speed / kStride : 0.5f; // idle ticks slowly phase += cycles_per_second * rx::Max(style.cadence_scale, 0.0f) * dt; - phase -= ::floor(phase); + phase -= ::floorf(phase); return phase; } @@ -129,7 +129,7 @@ void Locomotion::Apply(const asset::Skeleton &skeleton, f32 speed, if (!is_biped) { // Quadrupeds/creatures: a slow breathing bob on the spine, no stepping. - f32 breathe = ::sin(theta) * 0.03f; + f32 breathe = ::sinf(theta) * 0.03f; const i32 spine = FindFirst(skeleton, {"NPC Spine [Spn0]", "spine", "spine-1", "chest"}); LayerRotation(pose, spine, {1, 0, 0}, breathe); @@ -156,7 +156,7 @@ void Locomotion::Apply(const asset::Skeleton &skeleton, f32 speed, const i32 right_forearm = FindFirst( skeleton, {"NPC R Forearm [RLar]", "forearm.bend.R", "forearm.R"}); - f32 leg = ::sin(theta); // left leg leads, right is opposite phase + f32 leg = ::sinf(theta); // left leg leads, right is opposite phase f32 thigh_amp = (0.06f + 0.45f * walk + 0.35f * run) * style.stride_scale; f32 knee_amp = (0.10f + 0.7f * walk + 0.6f * run) * style.knee_lift_scale; f32 arm_amp = (0.05f + 0.35f * walk + 0.45f * run) * style.arm_swing_scale; @@ -167,9 +167,9 @@ void Locomotion::Apply(const asset::Skeleton &skeleton, f32 speed, LayerRotation(pose, left_thigh, x, ts * thigh_amp * leg); LayerRotation(pose, right_thigh, x, -ts * thigh_amp * leg); LayerRotation(pose, left_shin, x, - -knee_amp * Clamp01(-::sin(theta - 0.6f))); + -knee_amp * Clamp01(-::sinf(theta - 0.6f))); LayerRotation(pose, right_shin, x, - -knee_amp * Clamp01(-::sin(theta + kPi - 0.6f))); + -knee_amp * Clamp01(-::sinf(theta + kPi - 0.6f))); // Arms counter-swing the legs. f32 as = arm_axis_sign; @@ -185,14 +185,14 @@ void Locomotion::Apply(const asset::Skeleton &skeleton, f32 speed, if (left_shin >= 0) leg_length = rx::Max(Length(skeleton.bones[left_shin].bind_translation), 1.0e-4f); - const f32 sway = ::cos(theta) * walk; - const f32 twist = ::sin(theta) * walk; + const f32 sway = ::cosf(theta) * walk; + const f32 twist = ::sinf(theta) * walk; LayerRotation(pose, hip, {0, 0, 1}, style.hip_roll * sway); LayerRotation(pose, hip, {0, 1, 0}, style.hip_yaw * twist); if (hip >= 0 && hip < static_cast(pose->translation.size())) { pose->translation[hip].x += style.hip_shift * leg_length * sway; pose->translation[hip].y += style.vertical_bob * leg_length * walk * - (0.5f - 0.5f * ::cos(theta * 2.0f)); + (0.5f - 0.5f * ::cosf(theta * 2.0f)); } LayerRotation(pose, spine, {0, 0, 1}, -style.torso_counter_roll * sway); LayerRotation(pose, spine, {0, 1, 0}, -style.torso_counter_yaw * twist); diff --git a/engine/asset/bc_encode.cc b/engine/asset/bc_encode.cc index a8f2f560..fa03dd2c 100644 --- a/engine/asset/bc_encode.cc +++ b/engine/asset/bc_encode.cc @@ -64,7 +64,7 @@ void FitLine(const f32* points, f32* e0, f32* e1) { // Single-colour block: any axis works, the projection collapses anyway. for (int c = 0; c < N; ++c) axis[c] = c == 0 ? 1.0f : 0.0f; } else { - const f32 inv = 1.0f / ::sqrt(len); + const f32 inv = 1.0f / ::sqrtf(len); for (int c = 0; c < N; ++c) axis[c] *= inv; } } @@ -76,7 +76,7 @@ void FitLine(const f32* points, f32* e0, f32* e1) { f32 len = 0; for (int c = 0; c < N; ++c) len += next[c] * next[c]; if (len < 1e-12f) break; - const f32 inv = 1.0f / ::sqrt(len); + const f32 inv = 1.0f / ::sqrtf(len); for (int c = 0; c < N; ++c) axis[c] = next[c] * inv; } @@ -117,7 +117,7 @@ void RefitEndpoints(const f32* points, const f32* weights, f32* e0, f32* e1) { } } const f32 det = aa * bb - ab * ab; - if (::abs(det) < 1e-6f) return; + if (::fabsf(det) < 1e-6f) return; const f32 inv = 1.0f / det; for (int c = 0; c < N; ++c) { e0[c] = rx::Clamp((bb * ax[c] - ab * bx[c]) * inv, 0.0f, 255.0f); diff --git a/engine/asset/gltf_loader.cc b/engine/asset/gltf_loader.cc index 7c61b433..4a69c1a1 100644 --- a/engine/asset/gltf_loader.cc +++ b/engine/asset/gltf_loader.cc @@ -111,7 +111,7 @@ void GenerateTangents(MeshLod *lod, u32 vertex_offset, u32 index_offset) { f32 du1 = v1.uv[0] - v0.uv[0], dv1 = v1.uv[1] - v0.uv[1]; f32 du2 = v2.uv[0] - v0.uv[0], dv2 = v2.uv[1] - v0.uv[1]; f32 det = du1 * dv2 - du2 * dv1; - if (::abs(det) < 1e-12f) + if (::fabsf(det) < 1e-12f) continue; f32 inv = 1.0f / det; Vec3 tangent = (e1 * dv2 + e2 * -dv1) * inv; @@ -127,7 +127,7 @@ void GenerateTangents(MeshLod *lod, u32 vertex_offset, u32 index_offset) { Vec3 t = tangents[i] - n * Dot(n, tangents[i]); if (Dot(t, t) < 1e-12f) { // Degenerate uvs; any frame orthogonal to n will do. - t = ::abs(n.y) < 0.99f ? Cross(n, {0, 1, 0}) : Cross(n, {1, 0, 0}); + t = ::fabsf(n.y) < 0.99f ? Cross(n, {0, 1, 0}) : Cross(n, {1, 0, 0}); } t = Normalize(t); vertex.tangent[0] = t.x; @@ -148,25 +148,25 @@ void QuatFromMatrix(const f32 m[16], const Vec3 &scale, f32 out[4]) { } f32 trace = r[0] + r[4] + r[8]; if (trace > 0) { - f32 s = ::sqrt(trace + 1.0f) * 2; + f32 s = ::sqrtf(trace + 1.0f) * 2; out[3] = 0.25f * s; out[0] = (r[7] - r[5]) / s; out[1] = (r[2] - r[6]) / s; out[2] = (r[3] - r[1]) / s; } else if (r[0] > r[4] && r[0] > r[8]) { - f32 s = ::sqrt(1.0f + r[0] - r[4] - r[8]) * 2; + f32 s = ::sqrtf(1.0f + r[0] - r[4] - r[8]) * 2; out[3] = (r[7] - r[5]) / s; out[0] = 0.25f * s; out[1] = (r[1] + r[3]) / s; out[2] = (r[2] + r[6]) / s; } else if (r[4] > r[8]) { - f32 s = ::sqrt(1.0f + r[4] - r[0] - r[8]) * 2; + f32 s = ::sqrtf(1.0f + r[4] - r[0] - r[8]) * 2; out[3] = (r[2] - r[6]) / s; out[0] = (r[1] + r[3]) / s; out[1] = 0.25f * s; out[2] = (r[5] + r[7]) / s; } else { - f32 s = ::sqrt(1.0f + r[8] - r[0] - r[4]) * 2; + f32 s = ::sqrtf(1.0f + r[8] - r[0] - r[4]) * 2; out[3] = (r[3] - r[1]) / s; out[0] = (r[2] + r[6]) / s; out[1] = (r[5] + r[7]) / s; @@ -240,8 +240,8 @@ void MergeUvTransform(const cgltf_texture_view &view, const char *slot, // uv' = T * R * S * uv, spelt out from the extension's own sample shader. void ApplyUvTransform(const UvTransform &transform, f32 uv[2]) { - const f32 cos_r = ::cos(transform.rotation); - const f32 sin_r = ::sin(transform.rotation); + const f32 cos_r = ::cosf(transform.rotation); + const f32 sin_r = ::sinf(transform.rotation); const f32 u = uv[0] * transform.scale[0]; const f32 v = uv[1] * transform.scale[1]; uv[0] = cos_r * u - sin_r * v + transform.offset[0]; @@ -807,7 +807,7 @@ bool LoadGltfScene(const base::String &path, ImportedScene *out) { f32 dz = vertex.position[2] - mesh.bounds_center[2]; radius_sq = rx::Max(radius_sq, dx * dx + dy * dy + dz * dz); } - mesh.bounds_radius = ::sqrt(radius_sq); + mesh.bounds_radius = ::sqrtf(radius_sq); } } @@ -862,11 +862,11 @@ bool LoadGltfScene(const base::String &path, ImportedScene *out) { f32 world[16]; cgltf_node_transform_world(&node, world); instance.position = {world[12], world[13], world[14]}; - Vec3 scale{::sqrt(world[0] * world[0] + world[1] * world[1] + + Vec3 scale{::sqrtf(world[0] * world[0] + world[1] * world[1] + world[2] * world[2]), - ::sqrt(world[4] * world[4] + world[5] * world[5] + + ::sqrtf(world[4] * world[4] + world[5] * world[5] + world[6] * world[6]), - ::sqrt(world[8] * world[8] + world[9] * world[9] + + ::sqrtf(world[8] * world[8] + world[9] * world[9] + world[10] * world[10])}; instance.scale = (scale.x + scale.y + scale.z) / 3.0f; QuatFromMatrix(world, scale, instance.rotation); diff --git a/engine/asset/primitives.cc b/engine/asset/primitives.cc index 2654ff68..71c3af50 100644 --- a/engine/asset/primitives.cc +++ b/engine/asset/primitives.cc @@ -80,9 +80,9 @@ MeshLod ClusterDecimate(const MeshLod& src, const Vec3& bmin, const Vec3& ext, u base::UnorderedMap seen; for (size_t i = 0; i < src.vertices.size(); ++i) { const Vertex& v = src.vertices[i]; - GridPosition q{{static_cast(::lround((v.position[0] - bmin.x) / quantum)), - static_cast(::lround((v.position[1] - bmin.y) / quantum)), - static_cast(::lround((v.position[2] - bmin.z) / quantum))}}; + GridPosition q{{static_cast(::lroundf((v.position[0] - bmin.x) / quantum)), + static_cast(::lroundf((v.position[1] - bmin.y) / quantum)), + static_cast(::lroundf((v.position[2] - bmin.z) / quantum))}}; u32* id = seen.find(q); if (!id) id = seen.emplace(q, position_count++).first; position_id[i] = *id; @@ -266,7 +266,7 @@ void AddLathe(MeshLod* lod, const base::Vector& rings, u32 segments) for (size_t i = 1; i < rings.size(); ++i) { f32 dr = rings[i].radius - rings[i - 1].radius; f32 dy = rings[i].y - rings[i - 1].y; - travelled += ::sqrt(dr * dr + dy * dy); + travelled += ::sqrtf(dr * dr + dy * dy); v[i] = travelled; } const f32 inv_travelled = travelled > 0.0f ? 1.0f / travelled : 0.0f; @@ -278,7 +278,7 @@ void AddLathe(MeshLod* lod, const base::Vector& rings, u32 segments) for (u32 x = 0; x <= segments; ++x) { f32 u = static_cast(x) / static_cast(segments); f32 theta = u * 6.2831853f; - f32 sin_theta = ::sin(theta), cos_theta = ::cos(theta); + f32 sin_theta = ::sinf(theta), cos_theta = ::cosf(theta); Vertex vertex{}; vertex.position[0] = ring.radius * cos_theta; vertex.position[1] = ring.y; @@ -333,7 +333,7 @@ void AddDisc(MeshLod* lod, f32 radius, f32 y, f32 sign, u32 segments) { push(0.0f, 0.0f, 0.5f, 0.5f); for (u32 x = 0; x <= segments; ++x) { f32 theta = static_cast(x) / static_cast(segments) * 6.2831853f; - f32 cos_theta = ::cos(theta), sin_theta = ::sin(theta); + f32 cos_theta = ::cosf(theta), sin_theta = ::sinf(theta); push(radius * cos_theta, radius * sin_theta, 0.5f + 0.5f * cos_theta, 0.5f + 0.5f * sin_theta); } @@ -494,7 +494,7 @@ Mesh MakeBox(f32 hx, f32 hy, f32 hz, AssetId id) { for (u32 index : {0u, 1u, 2u, 0u, 2u, 3u}) lod.indices.push_back(base + index); } - mesh.bounds_radius = ::sqrt(hx * hx + hy * hy + hz * hz); + mesh.bounds_radius = ::sqrtf(hx * hx + hy * hy + hz * hz); return mesh; } @@ -512,11 +512,11 @@ Mesh MakeSphere(f32 radius, u32 rings, u32 segments, AssetId id) { for (u32 y = 0; y <= rings; ++y) { f32 v = static_cast(y) / static_cast(rings); f32 phi = v * 3.14159265f; // 0..pi, pole to pole - f32 sin_phi = ::sin(phi), cos_phi = ::cos(phi); + f32 sin_phi = ::sinf(phi), cos_phi = ::cosf(phi); for (u32 x = 0; x <= segments; ++x) { f32 u = static_cast(x) / static_cast(segments); f32 theta = u * 6.2831853f; - f32 sin_theta = ::sin(theta), cos_theta = ::cos(theta); + f32 sin_theta = ::sinf(theta), cos_theta = ::cosf(theta); Vec3 n{sin_phi * cos_theta, cos_phi, sin_phi * sin_theta}; Vertex vertex{}; vertex.position[0] = n.x * radius; @@ -569,7 +569,7 @@ Mesh MakePlane(f32 hx, f32 hz, AssetId id) { // Corners run ccw in the xz plane, which is clockwise seen from +Y, so the // winding is reversed to keep the visible face the one the normal points at. for (u32 index : {0u, 3u, 2u, 0u, 2u, 1u}) lod.indices.push_back(index); - return FinishPrimitive(base::move(mesh), ::sqrt(hx * hx + hz * hz)); + return FinishPrimitive(base::move(mesh), ::sqrtf(hx * hx + hz * hz)); } Mesh MakeCylinder(f32 radius, f32 half_height, u32 segments, AssetId id) { @@ -583,7 +583,7 @@ Mesh MakeCylinder(f32 radius, f32 half_height, u32 segments, AssetId id) { AddDisc(&lod, radius, half_height, 1.0f, segments); AddDisc(&lod, radius, -half_height, -1.0f, segments); return FinishPrimitive(base::move(mesh), - ::sqrt(radius * radius + half_height * half_height)); + ::sqrtf(radius * radius + half_height * half_height)); } Mesh MakeCone(f32 radius, f32 half_height, u32 segments, AssetId id) { @@ -599,7 +599,7 @@ Mesh MakeCone(f32 radius, f32 half_height, u32 segments, AssetId id) { AddLathe(&lod, side, segments); AddDisc(&lod, radius, -half_height, -1.0f, segments); return FinishPrimitive(base::move(mesh), - ::sqrt(radius * radius + half_height * half_height)); + ::sqrtf(radius * radius + half_height * half_height)); } Mesh MakeTorus(f32 major_radius, f32 minor_radius, u32 rings, u32 segments, AssetId id) { @@ -612,7 +612,7 @@ Mesh MakeTorus(f32 major_radius, f32 minor_radius, u32 rings, u32 segments, Asse // than wrapping the uv back to 0 across the seam quad. for (u32 i = 0; i <= rings; ++i) { f32 angle = static_cast(i) / static_cast(rings) * 6.2831853f; - f32 cos_angle = ::cos(angle), sin_angle = ::sin(angle); + f32 cos_angle = ::cosf(angle), sin_angle = ::sinf(angle); profile.push_back({major_radius + minor_radius * cos_angle, minor_radius * sin_angle, cos_angle, sin_angle}); } @@ -631,13 +631,13 @@ Mesh MakeCapsule(f32 radius, f32 half_height, u32 rings, u32 segments, AssetId i // them needs no samples of its own. for (u32 i = 0; i <= cap_rings; ++i) { f32 angle = -1.5707963f + static_cast(i) / static_cast(cap_rings) * 1.5707963f; - f32 cos_angle = ::cos(angle), sin_angle = ::sin(angle); + f32 cos_angle = ::cosf(angle), sin_angle = ::sinf(angle); profile.push_back({radius * cos_angle, -half_height + radius * sin_angle, cos_angle, sin_angle}); } for (u32 i = 0; i <= cap_rings; ++i) { f32 angle = static_cast(i) / static_cast(cap_rings) * 1.5707963f; - f32 cos_angle = ::cos(angle), sin_angle = ::sin(angle); + f32 cos_angle = ::cosf(angle), sin_angle = ::sinf(angle); profile.push_back({radius * cos_angle, half_height + radius * sin_angle, cos_angle, sin_angle}); } diff --git a/engine/asset/procedural_texture.cc b/engine/asset/procedural_texture.cc index 59026881..4fb603ba 100644 --- a/engine/asset/procedural_texture.cc +++ b/engine/asset/procedural_texture.cc @@ -10,7 +10,7 @@ namespace rx::asset { namespace { -f32 Fract(f32 x) { return x - ::floor(x); } +f32 Fract(f32 x) { return x - ::floorf(x); } f32 Smoothstep(f32 edge0, f32 edge1, f32 x) { if (edge1 <= edge0) return x < edge0 ? 0.0f : 1.0f; @@ -33,8 +33,8 @@ f32 EdgeDistance(f32 t) { // cell boundary rather than stepped. Both cells reach exactly 0.5 at the // boundary, which is what keeps it continuous (and the checker antialiased). f32 SoftSquare(f32 t) { - f32 cell = ::floor(t); - f32 parity = ::fmod(::abs(cell), 2.0f) >= 1.0f ? 1.0f : 0.0f; + f32 cell = ::floorf(t); + f32 parity = ::fmodf(::fabsf(cell), 2.0f) >= 1.0f ? 1.0f : 0.0f; f32 inside = 0.5f + 0.5f * Smoothstep(0.0f, kEdgeSoftness * 2.0f, EdgeDistance(t)); return parity * inside + (1.0f - parity) * (1.0f - inside); } @@ -52,7 +52,7 @@ u32 HashLattice(i32 x, i32 y, u32 seed) { f32 ValueNoise(f32 x, f32 y, i32 px, i32 py, u32 seed) { if (px < 1) px = 1; if (py < 1) py = 1; - i32 x0 = static_cast(::floor(x)), y0 = static_cast(::floor(y)); + i32 x0 = static_cast(::floorf(x)), y0 = static_cast(::floorf(y)); f32 fx = x - static_cast(x0), fy = y - static_cast(y0); auto wrap = [](i32 v, i32 period) { return ((v % period) + period) % period; }; auto corner = [&](i32 cx, i32 cy) { @@ -69,12 +69,12 @@ f32 ValueNoise(f32 x, f32 y, i32 px, i32 py, u32 seed) { // bound to a slot the GPU samples as sRGB. u8 EncodeSrgb(f32 linear) { f32 v = rx::Clamp(linear, 0.0f, 1.0f); - f32 encoded = v <= 0.0031308f ? v * 12.92f : 1.055f * ::pow(v, 1.0f / 2.4f) - 0.055f; - return static_cast(::lround(encoded * 255.0f)); + f32 encoded = v <= 0.0031308f ? v * 12.92f : 1.055f * ::powf(v, 1.0f / 2.4f) - 0.055f; + return static_cast(::lroundf(encoded * 255.0f)); } u8 EncodeLinear(f32 v) { - return static_cast(::lround(rx::Clamp(v, 0.0f, 1.0f) * 255.0f)); + return static_cast(::lroundf(rx::Clamp(v, 0.0f, 1.0f) * 255.0f)); } Texture BeginTexture(const PatternDesc& desc, bool srgb, AssetId id) { @@ -116,8 +116,8 @@ f32 SamplePattern(const PatternDesc& desc, f32 u, f32 v) { case PatternKind::kBrick: { // scale is bricks across by courses up, and every other course is offset // by half a brick. - f32 course = ::floor(v * sv); - f32 across = u * su + (::fmod(::abs(course), 2.0f) >= 1.0f ? 0.5f : 0.0f); + f32 course = ::floorf(v * sv); + f32 across = u * su + (::fmodf(::fabsf(course), 2.0f) >= 1.0f ? 0.5f : 0.0f); // `line` is a fraction of a COURSE, and the joint has to come out the // same uv width both ways, so the fraction across is rescaled by how much // wider a brick is than a course is tall. A wall 4 bricks across and 20 @@ -132,8 +132,8 @@ f32 SamplePattern(const PatternDesc& desc, f32 u, f32 v) { return rx::Clamp(v, 0.0f, 1.0f); case PatternKind::kNoise: { f32 sum = 0.0f, amplitude = 1.0f, total = 0.0f; - i32 px = rx::Max(1, static_cast(::lround(su))); - i32 py = rx::Max(1, static_cast(::lround(sv))); + i32 px = rx::Max(1, static_cast(::lroundf(su))); + i32 py = rx::Max(1, static_cast(::lroundf(sv))); for (int octave = 0; octave < 4; ++octave) { sum += ValueNoise(u * static_cast(px), v * static_cast(py), px, py, desc.seed + static_cast(octave) * 7919u) * diff --git a/engine/asset/subdivide.cc b/engine/asset/subdivide.cc index d37aaa26..31aad5e0 100644 --- a/engine/asset/subdivide.cc +++ b/engine/asset/subdivide.cc @@ -195,7 +195,7 @@ void RecomputeNormalsTangents(MeshLod& lod) { f32 du1 = v1.uv[0] - v0.uv[0], dv1 = v1.uv[1] - v0.uv[1]; f32 du2 = v2.uv[0] - v0.uv[0], dv2 = v2.uv[1] - v0.uv[1]; f32 det = du1 * dv2 - du2 * dv1; - if (::fabs(det) > 1e-12f) { + if (::fabsf(det) > 1e-12f) { f32 r = 1.0f / det; Vec3 tan = (e1 * dv2 - e2 * dv1) * r; Vec3 bit = (e2 * du1 - e1 * du2) * r; @@ -215,7 +215,7 @@ void RecomputeNormalsTangents(MeshLod& lod) { tan = tan - nrm * Dot(nrm, tan); // Gram-Schmidt if (Dot(tan, tan) < 1e-10f) { // Degenerate uv: pick any axis orthogonal to the normal. - Vec3 axis = ::fabs(nrm.x) < 0.9f ? Vec3{1, 0, 0} : Vec3{0, 1, 0}; + Vec3 axis = ::fabsf(nrm.x) < 0.9f ? Vec3{1, 0, 0} : Vec3{0, 1, 0}; tan = Cross(axis, nrm); } tan = Normalize(tan); diff --git a/engine/asset/texture_compress.cc b/engine/asset/texture_compress.cc index 549ce296..2ea220e9 100644 --- a/engine/asset/texture_compress.cc +++ b/engine/asset/texture_compress.cc @@ -53,7 +53,7 @@ const f32* SrgbToLinearTable() { auto* values = new f32[256]; for (u32 i = 0; i < 256; ++i) { const f32 c = static_cast(i) / 255.0f; - values[i] = c <= 0.04045f ? c / 12.92f : ::pow((c + 0.055f) / 1.055f, 2.4f); + values[i] = c <= 0.04045f ? c / 12.92f : ::powf((c + 0.055f) / 1.055f, 2.4f); } return values; }(); @@ -62,7 +62,7 @@ const f32* SrgbToLinearTable() { u8 LinearToSrgb(f32 v) { v = rx::Clamp(v, 0.0f, 1.0f); - const f32 s = v <= 0.0031308f ? v * 12.92f : 1.055f * ::pow(v, 1.0f / 2.4f) - 0.055f; + const f32 s = v <= 0.0031308f ? v * 12.92f : 1.055f * ::powf(v, 1.0f / 2.4f) - 0.055f; return static_cast(rx::Clamp(s * 255.0f + 0.5f, 0.0f, 255.0f)); } @@ -88,13 +88,13 @@ void Downsample(const u8* src, u32 sw, u32 sh, u8* dst, u32 dw, u32 dh, bool srg const f32 scale_y = static_cast(sh) / static_cast(dh); for (u32 y = 0; y < dh; ++y) { const f32 fy = (static_cast(y) + 0.5f) * scale_y - 0.5f; - const i32 y0 = static_cast(::floor(fy)); + const i32 y0 = static_cast(::floorf(fy)); const f32 wy = fy - static_cast(y0); const u32 ya = static_cast(rx::Clamp(y0, 0, static_cast(sh) - 1)); const u32 yb = static_cast(rx::Clamp(y0 + 1, 0, static_cast(sh) - 1)); for (u32 x = 0; x < dw; ++x) { const f32 fx = (static_cast(x) + 0.5f) * scale_x - 0.5f; - const i32 x0 = static_cast(::floor(fx)); + const i32 x0 = static_cast(::floorf(fx)); const f32 wx = fx - static_cast(x0); const u32 xa = static_cast(rx::Clamp(x0, 0, static_cast(sw) - 1)); const u32 xb = static_cast(rx::Clamp(x0 + 1, 0, static_cast(sw) - 1)); diff --git a/engine/asset/usd_loader.cc b/engine/asset/usd_loader.cc index 65a12022..b1c6a850 100644 --- a/engine/asset/usd_loader.cc +++ b/engine/asset/usd_loader.cc @@ -454,7 +454,7 @@ bool ConvertMesh(const tt::RenderMesh &src, out->bounds_center[2] = (lo.z + hi.z) * 0.5f; const Vec3 extent{hi.x - lo.x, hi.y - lo.y, hi.z - lo.z}; out->bounds_radius = - 0.5f * ::sqrt(extent.x * extent.x + extent.y * extent.y + + 0.5f * ::sqrtf(extent.x * extent.x + extent.y * extent.y + extent.z * extent.z); const auto material_of = [&](int id) -> AssetId { @@ -539,7 +539,7 @@ ImportedScene::Instance MakeInstance(u32 mesh_index, const Mat4 &world) { instance.position = {world.m[12], world.m[13], world.m[14]}; const auto axis_length = [&](int col) { const f32 *c = &world.m[col * 4]; - return ::sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); + return ::sqrtf(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); }; instance.scale = (axis_length(0) + axis_length(1) + axis_length(2)) / 3.0f; const Quat rotation = QuatFromMat4(world); @@ -676,7 +676,7 @@ u32 NormalizeColorSpaceTokens(tinyusdz::PrimSpec &spec) { Vec3 TransformDirectionNormalized(const Mat4 &m, const Vec3 &v) { Vec3 d = TransformDir(m, v); - const f32 len = ::sqrt(d.x * d.x + d.y * d.y + d.z * d.z); + const f32 len = ::sqrtf(d.x * d.x + d.y * d.y + d.z * d.z); if (len > 1e-8f) { d.x /= len; d.y /= len; @@ -731,7 +731,7 @@ bool AverageEnvmapColor(const base::String &path, f32 out_rgb[3]) { // Guard against inf/nan, which show up in the wild in exr-sourced hdr. for (int c = 0; c < 3; ++c) { const f32 v = p[c]; - if (::isfinite(v) && v > 0.0f) sum[c] += weight * v; + if (isfinite(v) && v > 0.0f) sum[c] += weight * v; } weight_total += weight; } @@ -957,7 +957,7 @@ void ConvertCameras(const tt::RenderScene &scene, const Mat4 &stage_to_engine, camera.rotation[2] = rotation.z; camera.rotation[3] = rotation.w; if (src.focalLength > 1e-6f) { - camera.yfov = 2.0f * ::atan(0.5f * src.verticalAperture / src.focalLength); + camera.yfov = 2.0f * ::atanf(0.5f * src.verticalAperture / src.focalLength); } camera.znear = src.znear; camera.zfar = src.zfar; diff --git a/engine/audio/aux_synth.cc b/engine/audio/aux_synth.cc index 9eb1438c..b44691ba 100644 --- a/engine/audio/aux_synth.cc +++ b/engine/audio/aux_synth.cc @@ -55,7 +55,7 @@ void SkidSynth::Render(f32* out, u32 frames, const SynthParams& p) { const f32 bias = rx::Clamp(p.skid_bias, -1.0f, 1.0f); const f32 centre_hz = rx::Clamp((900.0f + speed * 25.0f) * (1.0f + 0.12f * bias), 300.0f, rate_ * 0.4f); - const f32 f = rx::Clamp(2.0f * ::sin(kPi * centre_hz / rate_), 0.0f, 1.0f); + const f32 f = rx::Clamp(2.0f * ::sinf(kPi * centre_hz / rate_), 0.0f, 1.0f); const f32 q = 0.28f; // moderate resonance: a band, not a whistle for (u32 i = 0; i < frames; ++i) { @@ -65,8 +65,8 @@ void SkidSynth::Render(f32* out, u32 frames, const SynthParams& p) { const f32 high = in - svf_low_ - q * svf_band_; svf_band_ += f * high; f32 s = svf_band_ * level; - s = ::tanh(s); - out[i] = ::isfinite(s) ? s : 0.0f; + s = ::tanhf(s); + out[i] = isfinite(s) ? s : 0.0f; } } @@ -93,7 +93,7 @@ void WindSynth::Render(f32* out, u32 frames, const SynthParams& p) { // Cutoff opens with speed: faster air reads brighter, not just louder. const f32 cutoff = rx::Clamp(300.0f + speed * 55.0f, 200.0f, rate_ * 0.45f); - const f32 alpha = rx::Clamp(1.0f - ::exp(-2.0f * kPi * cutoff / rate_), 0.0f, 1.0f); + const f32 alpha = rx::Clamp(1.0f - ::expf(-2.0f * kPi * cutoff / rate_), 0.0f, 1.0f); for (u32 i = 0; i < frames; ++i) { const f32 white = Noise(); @@ -102,8 +102,8 @@ void WindSynth::Render(f32* out, u32 frames, const SynthParams& p) { // rather than a low roar. const f32 band = lp_ - hp_prev_ * 0.02f; hp_prev_ = lp_; - f32 s = ::tanh(band * level); - out[i] = ::isfinite(s) ? s : 0.0f; + f32 s = ::tanhf(band * level); + out[i] = isfinite(s) ? s : 0.0f; } } diff --git a/engine/audio/engine_synth.cc b/engine/audio/engine_synth.cc index 84589093..48203d92 100644 --- a/engine/audio/engine_synth.cc +++ b/engine/audio/engine_synth.cc @@ -14,12 +14,12 @@ constexpr i32 kMaxPartials = 32; // A phase in [0,1) turned into a sine. Wrapping the accumulator (not the angle) // keeps precision bounded no matter how long the engine runs. -f32 SinPhase(f32 phase) { return ::sin(phase * kTwoPi); } +f32 SinPhase(f32 phase) { return ::sinf(phase * kTwoPi); } // Advances a normalised phase by `freq` Hz for one sample and wraps it. f32 Advance(f32 phase, f32 freq, f32 inv_rate) { phase += freq * inv_rate; - phase -= ::floor(phase); + phase -= ::floorf(phase); return phase; } @@ -27,7 +27,7 @@ f32 Advance(f32 phase, f32 freq, f32 inv_rate) { // stable band so a runaway parameter cannot make the filter blow up. f32 LowpassAlpha(f32 cutoff_hz, f32 rate) { const f32 fc = rx::Clamp(cutoff_hz, 20.0f, rate * 0.49f); - return rx::Clamp(1.0f - ::exp(-kTwoPi * fc / rate), 0.0f, 1.0f); + return rx::Clamp(1.0f - ::expf(-kTwoPi * fc / rate), 0.0f, 1.0f); } f32 Smoothstep(f32 edge0, f32 edge1, f32 x) { @@ -176,7 +176,7 @@ void EngineSynth::Render(f32* out, u32 frames, const SynthParams& p) { if (shift_left_ <= 0) return 1.0f; const f32 phase = static_cast(shift_total_ - shift_left_) / static_cast(rx::Max(1, shift_total_)); - const f32 bump = ::sin(kPi * rx::Clamp(phase, 0.0f, 1.0f)); + const f32 bump = ::sinf(kPi * rx::Clamp(phase, 0.0f, 1.0f)); --shift_left_; return shift_sign_ < 0.0f ? (1.0f - 0.55f * bump) : (1.0f + 0.30f * bump); }; @@ -193,7 +193,7 @@ void EngineSynth::Render(f32* out, u32 frames, const SynthParams& p) { const f32 roar_alpha = LowpassAlpha(400.0f + roar_in * 2500.0f, rate); const f32 out_alpha = LowpassAlpha(out_cut_hz, rate); const f32 whine_gain = 0.42f * spool; - const f32 roar_gain = 0.30f * ::pow(roar_in, 1.4f); + const f32 roar_gain = 0.30f * ::powf(roar_in, 1.4f); for (u32 i = 0; i < frames; ++i) { f32 tone = SinPhase(whine_phase_); // A couple of harmonics of the whine, dropped if they alias. @@ -204,8 +204,8 @@ void EngineSynth::Render(f32* out, u32 frames, const SynthParams& p) { const f32 roar = 0.5f * roar_lp_ + 0.5f * (Noise() * 0.4f); f32 s = tone * whine_gain + roar * roar_gain; out_lp_ += out_alpha * (s - out_lp_); - s = ::tanh(out_lp_) * muffle_gain * flare_gain(); - out[i] = ::isfinite(s) ? s : 0.0f; + s = ::tanhf(out_lp_) * muffle_gain * flare_gain(); + out[i] = isfinite(s) ? s : 0.0f; whine_phase_ = Advance(whine_phase_, whine_hz, inv_rate); } return; @@ -291,8 +291,8 @@ void EngineSynth::Render(f32* out, u32 frames, const SynthParams& p) { // The muffle duck and the gear-shift flare ride on the limited output so both // stay bounded and click-free. out_lp_ += out_alpha * (s - out_lp_); - f32 y = ::tanh(out_lp_ * 1.3f) * muffle_gain * flare_gain(); - out[i] = ::isfinite(y) ? y : 0.0f; + f32 y = ::tanhf(out_lp_ * 1.3f) * muffle_gain * flare_gain(); + out[i] = isfinite(y) ? y : 0.0f; base_phase_ = Advance(base_phase_, base_freq, inv_rate); burble_phase_ = Advance(burble_phase_, burble_hz, inv_rate); diff --git a/engine/audio/mixer.cc b/engine/audio/mixer.cc index 96e1c0a4..626858ec 100644 --- a/engine/audio/mixer.cc +++ b/engine/audio/mixer.cc @@ -255,7 +255,7 @@ void Mixer::MixInto(float* out, u32 frames) { const f32 m = master_; for (u32 i = 0; i < frames * 2; ++i) { f32 s = out[i] * m; - if (s > 1.0f || s < -1.0f) s = ::tanh(s); + if (s > 1.0f || s < -1.0f) s = ::tanhf(s); out[i] = s; } } diff --git a/engine/audio/spatial.h b/engine/audio/spatial.h index adf49430..3a921009 100644 --- a/engine/audio/spatial.h +++ b/engine/audio/spatial.h @@ -68,8 +68,8 @@ inline StereoGains PanForSource(const Listener& listener, const Vec3& source, // Map pan [-1,1] -> angle [0, pi/2] and take cos/sin for equal-power gains. const f32 angle = (pan * 0.5f + 0.5f) * 1.57079633f; - f32 l = ::cos(angle); - f32 r = ::sin(angle); + f32 l = ::cosf(angle); + f32 r = ::sinf(angle); l = min_bleed + (1.0f - min_bleed) * l; r = min_bleed + (1.0f - min_bleed) * r; return {l * gain, r * gain}; diff --git a/engine/audio/synth_voice.cc b/engine/audio/synth_voice.cc index c2b4cefc..362f346d 100644 --- a/engine/audio/synth_voice.cc +++ b/engine/audio/synth_voice.cc @@ -20,12 +20,12 @@ constexpr u32 kSmoothChunk = 32; f32 ChunkAlpha(f32 tau_seconds, u32 rate) { if (tau_seconds <= 0.0f || rate == 0) return 1.0f; const f32 dt = static_cast(kSmoothChunk) / static_cast(rate); - return rx::Clamp(1.0f - ::exp(-dt / tau_seconds), 0.0f, 1.0f); + return rx::Clamp(1.0f - ::expf(-dt / tau_seconds), 0.0f, 1.0f); } // Replaces a non-finite telemetry value with zero so a stray NaN upstream can // never poison the smoother (a NaN would stick forever through the one-pole). -f32 Sane(f32 v) { return ::isfinite(v) ? v : 0.0f; } +f32 Sane(f32 v) { return isfinite(v) ? v : 0.0f; } } // namespace @@ -39,7 +39,7 @@ void ParamMailbox::Publish(const SynthParams& p) { clean.muffle = rx::Clamp(Sane(p.muffle), 0.0f, 1.0f); // thrust keeps its <0 "derive from rpm" sentinel; only a real request is // clamped into 0..1 (a NaN degrades to the sentinel, i.e. old behaviour). - clean.thrust = ::isfinite(p.thrust) ? (p.thrust < 0.0f ? -1.0f : rx::Clamp(p.thrust, 0.0f, 1.0f)) + clean.thrust = isfinite(p.thrust) ? (p.thrust < 0.0f ? -1.0f : rx::Clamp(p.thrust, 0.0f, 1.0f)) : -1.0f; clean.gear_shift = rx::Clamp(Sane(p.gear_shift), -1.0f, 1.0f); clean.skid_bias = rx::Clamp(Sane(p.skid_bias), -1.0f, 1.0f); diff --git a/engine/audio/thunder_synth.cc b/engine/audio/thunder_synth.cc index ff8188ec..ac086fa5 100644 --- a/engine/audio/thunder_synth.cc +++ b/engine/audio/thunder_synth.cc @@ -20,24 +20,24 @@ class ThunderDecoder final : public Decoder { // Air absorption: the crack is high-frequency and dies within ~1 km; the // rumble survives but its brightness closes down with range. - crack_gain_ = 1.6f * energy_ * ::exp(-dist / 900.0f); + crack_gain_ = 1.6f * energy_ * ::expf(-dist / 900.0f); f32 muffle = rx::Min(dist / 3000.0f, 1.0f); f32 cutoff_hz = rx::Min(2600.0f - 2250.0f * muffle, rate_f_ * 0.45f); - body_lp_k_ = rx::Clamp(1.0f - ::exp(-2.0f * 3.14159265f * cutoff_hz / rate_f_), + body_lp_k_ = rx::Clamp(1.0f - ::expf(-2.0f * 3.14159265f * cutoff_hz / rate_f_), 0.0f, 1.0f); f32 crack_hz = rx::Min(1800.0f, rate_f_ * 0.2f); - svf_f_ = 2.0f * ::sin(3.14159265f * crack_hz / rate_f_); + svf_f_ = 2.0f * ::sinf(3.14159265f * crack_hz / rate_f_); // Convert the old 48 kHz per-sample coefficients into rate-independent // time constants. Preserve the brown-noise variance at the reference rate. - brown_decay_ = ::exp(::log(0.998f) * (48000.0f / rate_f_)); + brown_decay_ = ::expf(::logf(0.998f) * (48000.0f / rate_f_)); brown_gain_ = 0.03f * - ::sqrt((1.0f - brown_decay_ * brown_decay_) / + ::sqrtf((1.0f - brown_decay_ * brown_decay_) / (1.0f - 0.998f * 0.998f)); - wobble_k_ = 1.0f - ::exp(-7.20054f / rate_f_); - bump_decay_step_ = ::exp(-1.6f / rate_f_); - global_decay_step_ = ::exp(-1.0f / ((2.2f + 2.0f * energy_) * rate_f_)); - crack_decay_step_ = ::exp(-26.0f / rate_f_); + wobble_k_ = 1.0f - ::expf(-7.20054f / rate_f_); + bump_decay_step_ = ::expf(-1.6f / rate_f_); + global_decay_step_ = ::expf(-1.0f / ((2.2f + 2.0f * energy_) * rate_f_)); + crack_decay_step_ = ::expf(-26.0f / rate_f_); seconds_ = 5.0f + 4.0f * energy_; total_frames_ = static_cast(seconds_ * rate_f_); @@ -88,7 +88,7 @@ class ThunderDecoder final : public Decoder { f32 dt_b = t - bump_t_[b]; if (dt_b > 0.0f) { if (bump_decay_[b] == 0.0f) - bump_decay_[b] = ::exp(-dt_b * 1.6f); + bump_decay_[b] = ::expf(-dt_b * 1.6f); else bump_decay_[b] *= bump_decay_step_; env += bump_w_[b] * dt_b * bump_decay_[b] * 4.349251f; @@ -107,7 +107,7 @@ class ThunderDecoder final : public Decoder { f32 tail = rx::Clamp(remaining / 0.4f, 0.0f, 1.0f); tail = tail * tail * (3.0f - 2.0f * tail); f32 s = (crack + body) * tail; - out[i] = s / (1.0f + ::fabs(s)) * 0.95f; // asymptote inside full scale + out[i] = s / (1.0f + ::fabsf(s)) * 0.95f; // asymptote inside full scale } frame_ += n; return n; @@ -156,8 +156,8 @@ class ThunderDecoder final : public Decoder { base::UniquePointer MakeThunder(u32 output_rate, u32 seed, f32 energy, f32 distance_m) { - if (output_rate == 0 || output_rate > 768000u || !::isfinite(energy) || - !::isfinite(distance_m)) + if (output_rate == 0 || output_rate > 768000u || !isfinite(energy) || + !isfinite(distance_m)) return nullptr; return base::MakeUnique(output_rate, seed, energy, distance_m); diff --git a/engine/audio/vehicle_audio.cc b/engine/audio/vehicle_audio.cc index e5ce30e4..3839d818 100644 --- a/engine/audio/vehicle_audio.cc +++ b/engine/audio/vehicle_audio.cc @@ -70,7 +70,7 @@ VehicleAudio::~VehicleAudio() { Stop(); } void VehicleAudio::SetLayerGain(Layer& layer, f32 gain) { if (!layer.voice) return; - if (::abs(gain - layer.sent_gain) < kGainEpsilon) return; + if (::fabsf(gain - layer.sent_gain) < kGainEpsilon) return; mixer_->SetVoiceGain(layer.voice, gain); layer.sent_gain = gain; } @@ -122,7 +122,7 @@ void VehicleAudio::Update(const VehicleAudioState& state) { SynthParams params; params.rpm = state.rpm; params.load = state.load; - params.throttle = ::fabs(state.throttle); // signed input (astern); use its magnitude + params.throttle = ::fabsf(state.throttle); // signed input (astern); use its magnitude params.speed_mps = state.speed_mps; params.slip = slip; params.muffle = state.submerged ? 1.0f : 0.0f; // synth-side dark/duck (smoothed) diff --git a/engine/character/character.cc b/engine/character/character.cc index 05d5f081..f33d1f02 100644 --- a/engine/character/character.cc +++ b/engine/character/character.cc @@ -13,7 +13,7 @@ namespace { constexpr f32 kTwoPi = 6.28318530717958647692f; -f32 WrapAngle(f32 a) { return ::remainder(a, kTwoPi); } +f32 WrapAngle(f32 a) { return ::remainderf(a, kTwoPi); } // Heading quaternion: yaw about -Y so a character's forward (-Z at yaw 0) agrees // with scene::CameraOrbit's yaw and the camera it drives. @@ -21,7 +21,7 @@ Quat HeadingQuat(f32 yaw) { return QuatFromAxisAngle({0, -1, 0}, yaw); } f32 MoveTowardScalar(f32 current, f32 target, f32 max_delta) { const f32 d = target - current; - if (::abs(d) <= max_delta) return target; + if (::fabsf(d) <= max_delta) return target; return current + (d > 0 ? max_delta : -max_delta); } @@ -29,7 +29,7 @@ f32 MoveTowardScalar(f32 current, f32 target, f32 max_delta) { // `half_life` seconds. Converges without overshoot; half_life <= 0 snaps. f32 ExpApproach(f32 current, f32 target, f32 half_life, f32 dt) { if (half_life <= 0.0f) return target; - const f32 t = 1.0f - ::exp2(-dt / half_life); + const f32 t = 1.0f - ::exp2f(-dt / half_life); return current + (target - current) * t; } @@ -37,13 +37,13 @@ f32 ExpApproach(f32 current, f32 target, f32 half_life, f32 dt) { f32 ExpApproachAngle(f32 current, f32 target, f32 half_life, f32 dt) { const f32 diff = WrapAngle(target - current); if (half_life <= 0.0f) return WrapAngle(current + diff); - const f32 t = 1.0f - ::exp2(-dt / half_life); + const f32 t = 1.0f - ::exp2f(-dt / half_life); return WrapAngle(current + diff * t); } // Heading yaw for a horizontal world direction, inverse of HeadingQuat's forward // (forward at yaw 0 is -Z, yaw increases toward +X): forward = (sin y, 0, -cos y). -f32 YawFromDir(const Vec3& d) { return ::atan2(d.x, -d.z); } +f32 YawFromDir(const Vec3& d) { return ::atan2f(d.x, -d.z); } Vec3 MoveTowardVec(const Vec3& current, const Vec3& target, f32 max_delta) { const Vec3 d = target - current; @@ -88,7 +88,7 @@ void RemoveIfPresent(ecs::World& world, ecs::Entity e) { } // namespace void StepCharacters(ecs::World& world, physics::PhysicsWorld& physics, f32 dt) { - if (!::isfinite(dt) || dt <= 0) return; + if (!isfinite(dt) || dt <= 0) return; world.Each( @@ -150,8 +150,8 @@ void StepCharacters(ecs::World& world, physics::PhysicsWorld& physics, f32 dt) { const f32 half_height = CylinderHalf(height, radius); const f32 new_total_half = half_height + radius; - const bool dims_changed = ::abs(new_total_half - old_total_half) > 1e-4f || - ::abs(radius - body.radius) > 1e-4f; + const bool dims_changed = ::fabsf(new_total_half - old_total_half) > 1e-4f || + ::fabsf(radius - body.radius) > 1e-4f; if (dims_changed && have_center) { const Vec3 new_center = feet + up * new_total_half; physics.SetCharacterPosition(body.id, new_center); @@ -185,7 +185,7 @@ void StepCharacters(ecs::World& world, physics::PhysicsWorld& physics, f32 dt) { state.facing_yaw = state.yaw; // locked, raw } else if (throttle > 1e-3f) { const f32 target_yaw = YawFromDir(dir); - const f32 gap = ::abs(WrapAngle(target_yaw - state.facing_yaw)); + const f32 gap = ::fabsf(WrapAngle(target_yaw - state.facing_yaw)); // Sticky pivot: a reversal past pivot_angle latches the faster rate and // holds it through the bulk of the turn (released near completion), so a // 180 spins on the spot instead of arcing then stalling. @@ -236,7 +236,7 @@ void StepCharacters(ecs::World& world, physics::PhysicsWorld& physics, f32 dt) { f32 vy = state.integration_velocity.y; if (grounded_prev && vy < 0) vy = 0; if (jump_wanted && coyote_ok) { - vy = ::sqrt(2.0f * rx::Max(settings.gravity, 0.0f) * + vy = ::sqrtf(2.0f * rx::Max(settings.gravity, 0.0f) * rx::Max(settings.jump_height, 0.0f)); state.jump_buffer_timer = 0; state.jump_consumed = true; @@ -251,7 +251,7 @@ void StepCharacters(ecs::World& world, physics::PhysicsWorld& physics, f32 dt) { // out-thrust weight to lift off) and the ground clamp below still stops // any downward component, so this never bypasses fall/land handling. const Vec3& ext = intent.external_acceleration; - if (::isfinite(ext.x) && ::isfinite(ext.y) && ::isfinite(ext.z)) + if (isfinite(ext.x) && isfinite(ext.y) && isfinite(ext.z)) velocity += ext * dt; // Drive the controller @@ -311,7 +311,7 @@ void StepCharacters(ecs::World& world, physics::PhysicsWorld& physics, f32 dt) { state.landing_dip = rx::Max(state.landing_dip, dip); } state.landing_dip = shape.landing_dip_half_life > 0.0f - ? state.landing_dip * ::exp2(-dt / shape.landing_dip_half_life) + ? state.landing_dip * ::exp2f(-dt / shape.landing_dip_half_life) : 0.0f; state.anchor_eye_y = state.eye_base_y - state.landing_dip; state.view_initialized = true; diff --git a/engine/character/jetpack.cc b/engine/character/jetpack.cc index 378813df..e4184146 100644 --- a/engine/character/jetpack.cc +++ b/engine/character/jetpack.cc @@ -18,7 +18,7 @@ constexpr f32 kLn10 = 2.302585093f; } // namespace void StepJetpacks(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt <= 0.0f) return; + if (!isfinite(dt) || dt <= 0.0f) return; world.Each( @@ -31,7 +31,7 @@ void StepJetpacks(ecs::World& world, f32 dt) { const bool want = in.enabled && in.thrust && st.fuel > 0.0f; const f32 demand = want ? 1.0f : 0.0f; const f32 tau = d.spool_time > 1e-4f ? d.spool_time / kLn10 : 0.0f; - const f32 a = tau > 0.0f ? 1.0f - ::exp(-dt / tau) : 1.0f; + const f32 a = tau > 0.0f ? 1.0f - ::expf(-dt / tau) : 1.0f; st.thrust = Clamp01(st.thrust + (demand - st.thrust) * a); // fuel: drain by actual thrust; refuel grounded + idle only @@ -52,13 +52,13 @@ void StepJetpacks(ecs::World& world, f32 dt) { const f32 g = rx::Max(move.gravity, 0.0f); Vec3 accel{0.0f, st.thrust * d.thrust_to_weight * g, 0.0f}; const Vec3 mh{intent.move.x, 0.0f, intent.move.z}; - const f32 mlen = ::sqrt(mh.x * mh.x + mh.z * mh.z); + const f32 mlen = ::sqrtf(mh.x * mh.x + mh.z * mh.z); if (mlen > 1e-4f) { const f32 s = (st.thrust * d.lateral_accel) / mlen; accel.x += mh.x * s; accel.z += mh.z * s; } - if (::isfinite(accel.x) && ::isfinite(accel.y) && ::isfinite(accel.z)) + if (isfinite(accel.x) && isfinite(accel.y) && isfinite(accel.z)) intent.external_acceleration += accel; // compose (StepCharacters clears it) }); } diff --git a/engine/combat/damage.cc b/engine/combat/damage.cc index f8a72fc1..2b43504e 100644 --- a/engine/combat/damage.cc +++ b/engine/combat/damage.cc @@ -130,7 +130,7 @@ f32 Heal(ecs::World& world, ecs::Entity entity, f32 amount) { } void StepHealth(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt <= 0) return; + if (!isfinite(dt) || dt <= 0) return; world.Each([dt](ecs::Entity, Health& health) { if (health.dead) return; health.time_since_damage += dt; diff --git a/engine/combat/projectile.cc b/engine/combat/projectile.cc index de730804..136d8d9f 100644 --- a/engine/combat/projectile.cc +++ b/engine/combat/projectile.cc @@ -60,7 +60,7 @@ ecs::Entity SpawnProjectile(ecs::World& world, const Projectile& desc) { void StepProjectiles(ecs::World& world, physics::PhysicsWorld& physics, const HitRegistry& registry, CombatEvents& events, f32 dt) { - if (!::isfinite(dt) || dt <= 0) return; + if (!isfinite(dt) || dt <= 0) return; base::Vector spent; base::Vector blasts; @@ -73,7 +73,7 @@ void StepProjectiles(ecs::World& world, physics::PhysicsWorld& physics, if (round.drag > 0) { // drag is per metre travelled, so the decay over a step depends on how // far the round actually gets: fast rounds bleed speed faster. - velocity = velocity * ::exp(-round.drag * Length(velocity) * dt); + velocity = velocity * ::expf(-round.drag * Length(velocity) * dt); } const Vec3 from = round.position; diff --git a/engine/combat/weapon.cc b/engine/combat/weapon.cc index 05900326..63cb4bcf 100644 --- a/engine/combat/weapon.cc +++ b/engine/combat/weapon.cc @@ -37,7 +37,7 @@ f32 RandomSigned(u32& state) { return RandomUnit(state) * 2.0f - 1.0f; } f32 MoveTowardScalar(f32 current, f32 target, f32 max_delta) { const f32 d = target - current; - if (::abs(d) <= max_delta) return target; + if (::fabsf(d) <= max_delta) return target; return current + (d > 0 ? max_delta : -max_delta); } @@ -45,11 +45,11 @@ f32 MoveTowardScalar(f32 current, f32 target, f32 max_delta) { // of the remaining gap closed over `dt` for a given half-life. f32 ApproachFraction(f32 half_life, f32 dt) { if (half_life <= 0) return 1.0f; - return 1.0f - ::exp2(-dt / half_life); + return 1.0f - ::exp2f(-dt / half_life); } void Basis(const Vec3& forward, Vec3* right, Vec3* up) { - const Vec3 reference = ::abs(forward.y) > 0.99f ? Vec3{1, 0, 0} : Vec3{0, 1, 0}; + const Vec3 reference = ::fabsf(forward.y) > 0.99f ? Vec3{1, 0, 0} : Vec3{0, 1, 0}; *right = Normalize(Cross(forward, reference)); *up = Cross(*right, forward); } @@ -60,17 +60,17 @@ void Basis(const Vec3& forward, Vec3* right, Vec3* up) { Vec3 ConeDirection(const Vec3& forward, f32 spread, u32& rng) { if (spread <= 0) return forward; const f32 angle = RandomUnit(rng) * kTwoPi; - const f32 radius = ::sqrt(RandomUnit(rng)) * ::tan(spread); + const f32 radius = ::sqrtf(RandomUnit(rng)) * ::tanf(spread); Vec3 right; Vec3 up; Basis(forward, &right, &up); - return Normalize(forward + right * (::cos(angle) * radius) + - up * (::sin(angle) * radius)); + return Normalize(forward + right * (::cosf(angle) * radius) + + up * (::sinf(angle) * radius)); } Vec3 SafeDirection(const Vec3& v) { const f32 length = Length(v); - if (!::isfinite(length) || length < 1e-6f) return {0, 0, -1}; + if (!isfinite(length) || length < 1e-6f) return {0, 0, -1}; return v * (1.0f / length); } @@ -270,7 +270,7 @@ f32 AimFovScale(const Loadout& loadout, const WeaponCatalog& catalog) { void StepWeapons(ecs::World& world, physics::PhysicsWorld& physics, const WeaponCatalog& catalog, const HitRegistry& registry, CombatEvents& events, f32 dt) { - if (!::isfinite(dt) || dt <= 0) return; + if (!isfinite(dt) || dt <= 0) return; // Projectile entities are created after the walk: spawning inside World::Each // is a structural change that can skip or revisit rows. @@ -472,7 +472,7 @@ void StepWeapons(ecs::World& world, physics::PhysicsWorld& physics, const Weapon } void StepViewRecoil(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt <= 0) return; + if (!isfinite(dt) || dt <= 0) return; world.Each([dt](ecs::Entity, ViewRecoil& recoil) { recoil.time_since_shot += dt; f32 pitch = 0; @@ -506,7 +506,7 @@ void StepViewRecoil(ecs::World& world, f32 dt) { } void StepViewmodels(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt <= 0) return; + if (!isfinite(dt) || dt <= 0) return; world.Each([&](ecs::Entity entity, Viewmodel& viewmodel, WeaponIntent& intent) { // Sway trails the look RATE, so a flick throws the weapon and holding still @@ -527,7 +527,7 @@ void StepViewmodels(ecs::World& world, f32 dt) { viewmodel.bob_weight += (bob_target - viewmodel.bob_weight) * ApproachFraction(viewmodel.bob_half_life, dt); viewmodel.bob_phase = - ::fmod(viewmodel.bob_phase + viewmodel.bob_rate * speed_ratio * dt, kTwoPi); + ::fmodf(viewmodel.bob_phase + viewmodel.bob_rate * speed_ratio * dt, kTwoPi); viewmodel.punch -= viewmodel.punch * ApproachFraction(viewmodel.punch_half_life, dt); @@ -543,8 +543,8 @@ void StepViewmodels(ecs::World& world, f32 dt) { const f32 bob = viewmodel.bob_amplitude * viewmodel.bob_weight * hip; Vec3 target; - target.x = sway_x * hip + ::sin(viewmodel.bob_phase) * bob; - target.y = sway_y * hip + ::sin(viewmodel.bob_phase * 2.0f) * bob * 0.5f; + target.x = sway_x * hip + ::sinf(viewmodel.bob_phase) * bob; + target.y = sway_y * hip + ::sinf(viewmodel.bob_phase * 2.0f) * bob * 0.5f; target.z = -viewmodel.punch; target += viewmodel.ads_offset * ads; diff --git a/engine/core/input_bindings.cc b/engine/core/input_bindings.cc index 95533296..7e142bb7 100644 --- a/engine/core/input_bindings.cc +++ b/engine/core/input_bindings.cc @@ -285,7 +285,7 @@ bool InputMap::SourceHeld(const Binding& b, const InputState& kbm, const Gamepad f32 thr = trigger ? trigger_threshold : stick_deadzone; if (b.axis_dir > 0) return v > thr; if (b.axis_dir < 0) return v < -thr; - return ::fabs(v) > thr; + return ::fabsf(v) > thr; } case SourceKind::kNone: return false; @@ -309,11 +309,11 @@ f32 InputMap::AxisValue(const Binding& b, const GamepadState& pad) const { b.code >= static_cast(GamepadAxis::kCount)) return 0; f32 v = pad.axes[b.code]; - if (::fabs(v) < stick_deadzone) return 0; + if (::fabsf(v) < stick_deadzone) return 0; // Rescale so the value ramps from 0 at the deadzone edge to 1 at full throw. - f32 s = (::fabs(v) - stick_deadzone) / (1.0f - stick_deadzone); + f32 s = (::fabsf(v) - stick_deadzone) / (1.0f - stick_deadzone); s = rx::Clamp(s, 0.0f, 1.0f); - return ::copysign(s, v); + return ::copysignf(s, v); } void InputMap::Resolve(const InputState& kbm, const GamepadState& pad, const TouchState& touch, @@ -364,7 +364,7 @@ void InputMap::Resolve(const InputState& kbm, const GamepadState& pad, const Tou bool trigger = x == static_cast(GamepadAxis::kLeftTrigger) || x == static_cast(GamepadAxis::kRightTrigger); f32 thr = trigger ? trigger_threshold : stick_deadzone; - if (::fabs(pad.axes[x]) > thr) pad_active = true; + if (::fabsf(pad.axes[x]) > thr) pad_active = true; } } // A finger landing wins over a stale pointer position: on a handheld the diff --git a/engine/core/math.h b/engine/core/math.h index 41c2b4d3..22a20893 100644 --- a/engine/core/math.h +++ b/engine/core/math.h @@ -49,11 +49,11 @@ inline Vec3 Cross(const Vec3& a, const Vec3& b) { } inline Vec3 Normalize(const Vec3& v) { - f32 length = ::sqrt(Dot(v, v)); + f32 length = ::sqrtf(Dot(v, v)); return length > 0 ? Vec3{v.x / length, v.y / length, v.z / length} : v; } -inline f32 Length(const Vec3& v) { return ::sqrt(Dot(v, v)); } +inline f32 Length(const Vec3& v) { return ::sqrtf(Dot(v, v)); } inline Vec3 Lerp(const Vec3& a, const Vec3& b, f32 t) { return a + (b - a) * t; } @@ -71,7 +71,7 @@ inline Quat operator*(const Quat& a, const Quat& b) { } inline Quat Normalize(const Quat& q) { - f32 len = ::sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); + f32 len = ::sqrtf(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w); if (len <= 0) return {0, 0, 0, 1}; f32 inv = 1.0f / len; return {q.x * inv, q.y * inv, q.z * inv, q.w * inv}; @@ -79,8 +79,8 @@ inline Quat Normalize(const Quat& q) { inline Quat QuatFromAxisAngle(const Vec3& axis, f32 radians) { Vec3 n = Normalize(axis); - f32 s = ::sin(radians * 0.5f); - return {n.x * s, n.y * s, n.z * s, ::cos(radians * 0.5f)}; + f32 s = ::sinf(radians * 0.5f); + return {n.x * s, n.y * s, n.z * s, ::cosf(radians * 0.5f)}; } inline Quat Conjugate(const Quat& q) { return {-q.x, -q.y, -q.z, q.w}; } @@ -118,10 +118,10 @@ inline Quat Slerp(const Quat& a, Quat b, f32 t) { return Normalize(Quat{a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t}); } - f32 theta = ::acos(cos_theta); - f32 sin_theta = ::sin(theta); - f32 wa = ::sin((1 - t) * theta) / sin_theta; - f32 wb = ::sin(t * theta) / sin_theta; + f32 theta = ::acosf(cos_theta); + f32 sin_theta = ::sinf(theta); + f32 wa = ::sinf((1 - t) * theta) / sin_theta; + f32 wb = ::sinf(t * theta) / sin_theta; return {wa * a.x + wb * b.x, wa * a.y + wb * b.y, wa * a.z + wb * b.z, wa * a.w + wb * b.w}; } @@ -259,25 +259,25 @@ inline Quat QuatFromMat4(const Mat4& m) { f32 trace = r00 + r11 + r22; Quat q; if (trace > 0) { - f32 s = 0.5f / ::sqrt(trace + 1.0f); + f32 s = 0.5f / ::sqrtf(trace + 1.0f); q.w = 0.25f / s; q.x = (r21 - r12) * s; q.y = (r02 - r20) * s; q.z = (r10 - r01) * s; } else if (r00 > r11 && r00 > r22) { - f32 s = 2.0f * ::sqrt(1.0f + r00 - r11 - r22); + f32 s = 2.0f * ::sqrtf(1.0f + r00 - r11 - r22); q.w = (r21 - r12) / s; q.x = 0.25f * s; q.y = (r01 + r10) / s; q.z = (r02 + r20) / s; } else if (r11 > r22) { - f32 s = 2.0f * ::sqrt(1.0f + r11 - r00 - r22); + f32 s = 2.0f * ::sqrtf(1.0f + r11 - r00 - r22); q.w = (r02 - r20) / s; q.x = (r01 + r10) / s; q.y = 0.25f * s; q.z = (r12 + r21) / s; } else { - f32 s = 2.0f * ::sqrt(1.0f + r22 - r00 - r11); + f32 s = 2.0f * ::sqrtf(1.0f + r22 - r00 - r11); q.w = (r10 - r01) / s; q.x = (r02 + r20) / s; q.y = (r12 + r21) / s; @@ -306,7 +306,7 @@ inline Mat4 LookAt(const Vec3& eye, const Vec3& target, const Vec3& up) { // whole range, which matters for large open-world exteriors. Y is flipped for // vulkan clip space. inline Mat4 PerspectiveReversedZ(f32 fov_y_radians, f32 aspect, f32 near_plane) { - f32 g = 1.0f / ::tan(fov_y_radians * 0.5f); + f32 g = 1.0f / ::tanf(fov_y_radians * 0.5f); Mat4 r; r.m[0] = g / aspect; r.m[5] = -g; @@ -320,7 +320,7 @@ inline Mat4 PerspectiveReversedZ(f32 fov_y_radians, f32 aspect, f32 near_plane) // and sampled with the same matrix, so it stays self-consistent without // matching the camera's reversed-infinite clip space. inline Mat4 PerspectiveShadow(f32 fov_y_radians, f32 aspect, f32 near_plane, f32 far_plane) { - f32 g = 1.0f / ::tan(fov_y_radians * 0.5f); + f32 g = 1.0f / ::tanf(fov_y_radians * 0.5f); Mat4 r; r.m[0] = g / aspect; r.m[5] = g; diff --git a/engine/core/scalar.h b/engine/core/scalar.h index 0f5e0123..d50743de 100644 --- a/engine/core/scalar.h +++ b/engine/core/scalar.h @@ -1,6 +1,8 @@ #ifndef RX_CORE_SCALAR_H_ #define RX_CORE_SCALAR_H_ +#include + #include namespace rx { @@ -63,6 +65,32 @@ constexpr T Lerp(T a, T b, T t) { return (t > 1) == (b > a) ? (b < x ? x : b) : (x < b ? x : b); } +// Three-argument std::hypot, step for step as libstdc++ computes it (scale by +// the largest magnitude, then sum the squares). C has no three-argument hypot, +// so without this MSVC finds nothing to call. Instantiated for float or double. +template +T Hypot(T x, T y, T z) { + static_assert(sizeof(T) == sizeof(float) || sizeof(T) == sizeof(double), + "Hypot is for float or double"); + if constexpr (sizeof(T) == sizeof(float)) { + x = ::fabsf(x); + y = ::fabsf(y); + z = ::fabsf(z); + } else { + x = ::fabs(x); + y = ::fabs(y); + z = ::fabs(z); + } + if (T a = x < y ? y < z ? z : y : x < z ? z : x) { + const T sum = (x / a) * (x / a) + (y / a) * (y / a) + (z / a) * (z / a); + if constexpr (sizeof(T) == sizeof(float)) + return a * ::sqrtf(sum); + else + return a * ::sqrt(sum); + } + return {}; +} + // std::bit_cast, on the builtin every supported compiler has. template constexpr To BitCast(const From& from) { diff --git a/engine/core/world_clock.cc b/engine/core/world_clock.cc index 33c0e904..87f5296c 100644 --- a/engine/core/world_clock.cc +++ b/engine/core/world_clock.cc @@ -24,8 +24,8 @@ SkyLighting ComputeSkyLighting(f32 hour) { // 18 -> pi (sunset, due west). A small constant south lean (the -0.25 z) keeps // shadows off the world axes for a more natural look. const f32 a = (hour - 6.0f) / 12.0f * kPi; - const f32 ca = ::cos(a); - const f32 elev = ::sin(a); // sun elevation: > 0 day, < 0 night + const f32 ca = ::cosf(a); + const f32 elev = ::sinf(a); // sun elevation: > 0 day, < 0 night // Daylight weight, with a soft twilight band as the sun crosses the horizon. const f32 day = Smoothstep(-0.12f, 0.12f, elev); diff --git a/engine/core/world_clock.h b/engine/core/world_clock.h index f1db6458..1a488715 100644 --- a/engine/core/world_clock.h +++ b/engine/core/world_clock.h @@ -66,7 +66,7 @@ class WorldClock { private: static f32 Wrap24(f32 h) { - h = ::fmod(h, 24.0f); + h = ::fmodf(h, 24.0f); return h < 0 ? h + 24.0f : h; } base::Atomic game_days_{0.0}; diff --git a/engine/edit/scene_io.cc b/engine/edit/scene_io.cc index d310d52d..a2da2ba3 100644 --- a/engine/edit/scene_io.cc +++ b/engine/edit/scene_io.cc @@ -97,7 +97,7 @@ const char* ReadFloat(const base::String& token, f32* out) { char* end = nullptr; const f32 v = ::strtof(token.c_str(), &end); if (end == token.c_str() || *end != '\0') return "is not a number"; - if (!::isfinite(v)) return "is not finite"; + if (!isfinite(v)) return "is not finite"; *out = v; return nullptr; } @@ -152,8 +152,8 @@ base::String QuatProblem(const base::Vector& v) { // (0.7 0 0 0.7 is only 1% short) and well inside a visible mis-scale. Same // tolerance as --validate's non_unit_rotation, so the two agree on what is // merely rounded and what is wrong. - const f32 length = ::sqrt(length_sq); - if (::abs(length - 1.0f) > 0.05f) + const f32 length = ::sqrtf(length_sq); + if (::fabsf(length - 1.0f) > 0.05f) return rx::StrFormat("length {} scales the mesh by that on top of Transform.scale", length); return {}; } @@ -238,7 +238,7 @@ bool SaveScene(ecs::World& world, const base::String& file_path, base::String* e PropValue value; if (!GetProp(world, e, *comp, prop, &value)) continue; for (u32 lane = 0; lane < lanes; ++lane) { - if (::isfinite(value.f[lane])) continue; + if (isfinite(value.f[lane])) continue; if (error) *error = rx::StrFormat("{}.{} on entity {} is {}; the scene format has no literal for " "it, so nothing was written", diff --git a/engine/inventory/world_item.cc b/engine/inventory/world_item.cc index 7f872276..092a5558 100644 --- a/engine/inventory/world_item.cc +++ b/engine/inventory/world_item.cc @@ -107,8 +107,8 @@ void ReserveWorldItemId(u64 seen_id) { } WorldItemStore::CellKey WorldItemStore::CellOf(const Vec3& p) const { - return CellKey{i32(::floor(p.x / cell_size_)), i32(::floor(p.y / cell_size_)), - i32(::floor(p.z / cell_size_))}; + return CellKey{i32(::floorf(p.x / cell_size_)), i32(::floorf(p.y / cell_size_)), + i32(::floorf(p.z / cell_size_))}; } void WorldItemStore::Insert(const WorldItemRecord& record) { @@ -120,7 +120,7 @@ void WorldItemStore::Insert(const WorldItemRecord& record) { base::Vector WorldItemStore::TakeNear(const Vec3& center, f32 radius) { base::Vector out; - const i32 span = i32(::ceil(radius / cell_size_)); + const i32 span = i32(::ceilf(radius / cell_size_)); const CellKey c = CellOf(center); for (i32 z = c.z - span; z <= c.z + span; ++z) { for (i32 y = c.y - span; y <= c.y + span; ++y) { @@ -216,7 +216,7 @@ void SyncWorldItems(ecs::World& world, physics::PhysicsWorld& physics) { // between the two unit quaternions (|dot| handles the double-cover sign). const f32 rdot = t.rotation[0] * rot[0] + t.rotation[1] * rot[1] + t.rotation[2] * rot[2] + t.rotation[3] * rot[3]; - const f32 ang_delta = 1.0f - ::fabs(rdot); + const f32 ang_delta = 1.0f - ::fabsf(rdot); t.position[0] = pos.x; t.position[1] = pos.y; diff --git a/engine/locomotion/controller.cc b/engine/locomotion/controller.cc index c1b22e11..0939237a 100644 --- a/engine/locomotion/controller.cc +++ b/engine/locomotion/controller.cc @@ -30,7 +30,7 @@ namespace { // Angle (rad) between two directions, both assumed roughly unit-length. f32 AngleBetween(const Vec3& a, const Vec3& b) { - return ::acos(Clampf(Dot(a, b), -1.0f, 1.0f)); + return ::acosf(Clampf(Dot(a, b), -1.0f, 1.0f)); } } // namespace @@ -69,7 +69,7 @@ void LocomotionController::ApplyJointDrive(RigJoint j, f32 torque) { // SetJointDrive walks Jolt constraint settings, so re-issue it only when the // effective torque budget moved > 1%. const f32 ref = applied_torque_[idx] > 1e-3f ? applied_torque_[idx] : 1.0f; - if (::fabs(torque - applied_torque_[idx]) > 0.01f * ref) { + if (::fabsf(torque - applied_torque_[idx]) > 0.01f * ref) { rig_.SetJointDrive(*physics_, j, params_.joint_frequency, params_.joint_damping, torque); applied_torque_[idx] = torque; } @@ -175,7 +175,7 @@ void LocomotionController::Tick(const LocomotionIntent& intent, const PhysicalMo if (FiniteV(requested_facing) && Length(requested_facing) > 1e-4f) { requested_facing = Normalize(requested_facing); const f32 turn_error = - ::atan2(Cross(controlled_facing_, requested_facing).y, + ::atan2f(Cross(controlled_facing_, requested_facing).y, Clampf(Dot(controlled_facing_, requested_facing), -1.0f, 1.0f)); const f32 turn_rate = FiniteScalar(params_.max_turn_rate) ? rx::Max(params_.max_turn_rate, 0.0f) : 0.0f; @@ -222,7 +222,7 @@ void LocomotionController::Tick(const LocomotionIntent& intent, const PhysicalMo // a lead of ~desired_velocity/omega ahead of the support (that IS forward // locomotion, not a fall); subtracting that lead keeps `margin` near zero while // walking and only grows on genuine, uncommanded imbalance. - const f32 omega = ::sqrt(m.gravity / com_height); + const f32 omega = ::sqrtf(m.gravity / com_height); const Vec3 expected_lead = Planar(resolved_intent.desired_velocity) * (1.0f / omega); const f32 margin = PlanarLength(Planar(cp) - Planar(contacts_.support_center) - expected_lead); diff --git a/engine/locomotion/estimator.cc b/engine/locomotion/estimator.cc index 7c444ea2..0907344e 100644 --- a/engine/locomotion/estimator.cc +++ b/engine/locomotion/estimator.cc @@ -130,11 +130,11 @@ void StateEstimator::Measure(const physics::PhysicsWorld& physics, const BipedRi bool finite = FiniteV(out->root_position) && FiniteQ(out->root_rotation) && FiniteV(out->root_linear_velocity) && FiniteV(out->root_angular_velocity) && FiniteV(out->com_position) && FiniteV(out->com_velocity) && - FiniteV(out->ground_normal) && ::isfinite(out->estimated_body_height); + FiniteV(out->ground_normal) && isfinite(out->estimated_body_height); for (u32 f = 0; f < kFootCount; ++f) { const FootMeasurement& fm = out->foot[f]; finite = finite && FiniteV(fm.position) && FiniteV(fm.velocity) && FiniteV(fm.contact_normal) && - ::isfinite(fm.contact_impulse) && ::isfinite(fm.slip_speed); + isfinite(fm.contact_impulse) && isfinite(fm.slip_speed); } if (ok && finite) { @@ -167,7 +167,7 @@ void ContactEstimator::Update(const CharacterMeasurements& m, f32 dt) { if (!fm.in_contact) { raw = FootPhase::kSwinging; } else if (fm.slip_speed >= 0.6f || fm.contact_normal.y <= 0.6f || - ::abs(fm.velocity.y) >= 0.35f) { + ::fabsf(fm.velocity.y) >= 0.35f) { raw = FootPhase::kSliding; } else { raw = FootPhase::kSupporting; diff --git a/engine/locomotion/footstep.cc b/engine/locomotion/footstep.cc index 1d53d8d9..b50afe83 100644 --- a/engine/locomotion/footstep.cc +++ b/engine/locomotion/footstep.cc @@ -31,7 +31,7 @@ Vec3 ResolveFacing(const LocomotionIntent& intent, const Quat& root_rotation) { // rolls the ankle past its limit). Quat FootOrientation(const Vec3& normal, const Vec3& facing) { Vec3 n = Length(normal) > 1e-5f ? Normalize(normal) : kUp; - const f32 angle = ::acos(Clampf(n.y, -1, 1)); + const f32 angle = ::acosf(Clampf(n.y, -1, 1)); Quat tilt{0, 0, 0, 1}; if (angle > 1e-4f) { Vec3 axis = Cross(kUp, n); @@ -46,7 +46,7 @@ Quat FootOrientation(const Vec3& normal, const Vec3& facing) { Vec3 CapturePoint(const Vec3& com_position, const Vec3& com_velocity, f32 gravity, f32 com_height) { const f32 h = com_height < 0.1f ? 0.1f : com_height; - const f32 omega = ::sqrt((gravity > 0 ? gravity : 9.81f) / h); + const f32 omega = ::sqrtf((gravity > 0 ? gravity : 9.81f) / h); if (!(omega > 0)) return com_position; return com_position + com_velocity * (1.0f / omega); } @@ -72,7 +72,7 @@ void FootstepPlanner::Update(const CharacterMeasurements& m, const ContactEstima (void)dt; // the planner is memoryless per tick beyond the lift-off latch const Vec3 facing = ResolveFacing(intent, m.root_rotation); const Vec3 right = Normalize(Cross(facing, kUp)); // character right (+X at yaw 0) - const f32 cos_slope = ::cos(params.max_ground_slope); + const f32 cos_slope = ::cosf(params.max_ground_slope); for (u32 foot = 0; foot < kFootCount; ++foot) { FootPlan& p = plan_[foot]; diff --git a/engine/locomotion/gait.cc b/engine/locomotion/gait.cc index 1345b4a8..bb6de17b 100644 --- a/engine/locomotion/gait.cc +++ b/engine/locomotion/gait.cc @@ -18,8 +18,8 @@ constexpr f32 kSpeedRatioTau = 0.15f; } // namespace f32 Wrap01(f32 x) { - if (!::isfinite(x)) return 0; - x -= ::floor(x); + if (!isfinite(x)) return 0; + x -= ::floorf(x); if (x < 0) x += 1; // guard tiny-negative rounding if (x >= 1) x -= 1; // guard rounding up to exactly 1 return x; diff --git a/engine/locomotion/internal_math.h b/engine/locomotion/internal_math.h index 199deece..7d86b1f7 100644 --- a/engine/locomotion/internal_math.h +++ b/engine/locomotion/internal_math.h @@ -16,12 +16,12 @@ namespace rx::locomotion::internal { // Finiteness predicates. -inline bool FiniteScalar(f32 x) { return ::isfinite(x); } +inline bool FiniteScalar(f32 x) { return isfinite(x); } inline bool FiniteV(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } inline bool FiniteQ(const Quat& q) { - return ::isfinite(q.x) && ::isfinite(q.y) && ::isfinite(q.z) && ::isfinite(q.w); + return isfinite(q.x) && isfinite(q.y) && isfinite(q.z) && isfinite(q.w); } // Clamp a scalar to [lo, hi]. @@ -34,7 +34,7 @@ inline f32 Lerpf(f32 a, f32 b, f32 t) { return a + (b - a) * t; } inline Vec3 Planar(const Vec3& v) { return {v.x, 0.0f, v.z}; } // Planar (x,z) magnitude of a world vector, ignoring the vertical component. -inline f32 PlanarLength(const Vec3& v) { return ::sqrt(v.x * v.x + v.z * v.z); } +inline f32 PlanarLength(const Vec3& v) { return ::sqrtf(v.x * v.x + v.z * v.z); } // Clamp a vector's length to `max_len` (no-op below it; safe for the zero vec). inline Vec3 ClampLength(const Vec3& v, f32 max_len) { @@ -47,7 +47,7 @@ inline Vec3 ClampLength(const Vec3& v, f32 max_len) { // 0 for dt <= 0 or tau <= 0 (holds the current value); -> 1 for large dt. inline f32 SmoothingAlpha(f32 dt, f32 tau) { if (!(dt > 0) || !(tau > 0)) return 0; - return 1.0f - ::exp(-dt / tau); + return 1.0f - ::expf(-dt / tau); } } // namespace rx::locomotion::internal diff --git a/engine/locomotion/rig.cc b/engine/locomotion/rig.cc index 6c486af4..d6d26d3f 100644 --- a/engine/locomotion/rig.cc +++ b/engine/locomotion/rig.cc @@ -208,8 +208,8 @@ bool BipedRig::Build(physics::PhysicsWorld& physics, const ControllerParameters& // Yaw about -Y, matching rx::character::HeadingQuat(yaw) = // QuatFromAxisAngle({0, -1, 0}, yaw) = {0, -sin(yaw/2), 0, cos(yaw/2)}. - const f32 hy = ::sin(yaw * 0.5f); - const f32 hcw = ::cos(yaw * 0.5f); + const f32 hy = ::sinf(yaw * 0.5f); + const f32 hcw = ::cosf(yaw * 0.5f); const Quat yawq{0, -hy, 0, hcw}; const f32 rot[4] = {0, -hy, 0, hcw}; auto world = [&](const Vec3& local) { return feet_position + Rotate(yawq, local); }; diff --git a/engine/locomotion/whole_body.cc b/engine/locomotion/whole_body.cc index 91beb913..651f7307 100644 --- a/engine/locomotion/whole_body.cc +++ b/engine/locomotion/whole_body.cc @@ -20,7 +20,7 @@ constexpr f32 kPi = 3.14159265358979f; Quat ClampCone(Quat q, f32 max_angle) { q = Normalize(q); if (q.w < 0.0f) q = {-q.x, -q.y, -q.z, -q.w}; // pick the shortest hemisphere - f32 angle = 2.0f * ::acos(Clampf(q.w, -1.0f, 1.0f)); + f32 angle = 2.0f * ::acosf(Clampf(q.w, -1.0f, 1.0f)); if (angle <= max_angle) return q; Vec3 axis{q.x, q.y, q.z}; if (Length(axis) < 1e-6f) return {0, 0, 0, 1}; @@ -72,7 +72,7 @@ LegIkResult SolveLegIk(const Vec3& hip_to_sole, const Vec3& sole_normal_parent, const f32 u = upper_length; const f32 l = lower_length; const f32 eps = 1e-4f; - const f32 d_min = ::fabs(u - l) + eps; + const f32 d_min = ::fabsf(u - l) + eps; const f32 d_max = u + l - eps; f32 d = raw; @@ -91,7 +91,7 @@ LegIkResult SolveLegIk(const Vec3& hip_to_sole, const Vec3& sole_normal_parent, // folded (d = |u-l|) -> pi. Never negative. f32 cos_knee = (u * u + l * l - d * d) / (2.0f * u * l); cos_knee = Clampf(cos_knee, -1.0f, 1.0f); - r.knee_flexion = kPi - ::acos(cos_knee); + r.knee_flexion = kPi - ::acosf(cos_knee); if (r.knee_flexion < 0.0f) r.knee_flexion = 0.0f; // Triangle angle at the hip between the thigh (bind -Y) and the hip->ankle @@ -104,7 +104,7 @@ LegIkResult SolveLegIk(const Vec3& hip_to_sole, const Vec3& sole_normal_parent, // where V0 is the bent chain's ankle in the pre-hip frame. f32 cos_alpha = (u * u + d * d - l * l) / (2.0f * u * d); cos_alpha = Clampf(cos_alpha, -1.0f, 1.0f); - const f32 alpha = ::acos(cos_alpha); + const f32 alpha = ::acosf(cos_alpha); r.hip = QuatBetween(down_y, a_hat) * QuatFromAxisAngle(knee_axis, -alpha); // Ankle: after hip+knee, rotate the foot's bind normal (+Y) onto n. Solve in @@ -200,7 +200,7 @@ void BuildWholeBodyTargets(const CharacterMeasurements& m, const ContactEstimate solved_forward = Normalize(solved_forward); desired_forward = Normalize(desired_forward); const f32 yaw_error = - ::atan2(Cross(solved_forward, desired_forward).y, + ::atan2f(Cross(solved_forward, desired_forward).y, Clampf(Dot(solved_forward, desired_forward), -1.0f, 1.0f)); ankle = ClampCone(ankle * QuatFromAxisAngle(up_y, yaw_error), 0.5f); } @@ -229,8 +229,8 @@ void BuildWholeBodyTargets(const CharacterMeasurements& m, const ContactEstimate // 5. Arms: gait-phase counter-swing (arm opposes the same-side leg) const f32 speed_ratio = Clampf(gait.speed_ratio, 0.0f, 4.0f); - const f32 swing_l = 0.45f * speed_ratio * ::cos(2.0f * kPi * GaitClock::FootPhase(gait, 1)); - const f32 swing_r = 0.45f * speed_ratio * ::cos(2.0f * kPi * GaitClock::FootPhase(gait, 0)); + const f32 swing_l = 0.45f * speed_ratio * ::cosf(2.0f * kPi * GaitClock::FootPhase(gait, 1)); + const f32 swing_r = 0.45f * speed_ratio * ::cosf(2.0f * kPi * GaitClock::FootPhase(gait, 0)); const f32 elbow_flex = 0.25f + 0.25f * speed_ratio; out->joint_target[static_cast(RigJoint::kShoulderL)] = QuatFromAxisAngle({1, 0, 0}, swing_l); out->joint_target[static_cast(RigJoint::kShoulderR)] = QuatFromAxisAngle({1, 0, 0}, swing_r); @@ -275,7 +275,7 @@ void BuildWholeBodyTargets(const CharacterMeasurements& m, const ContactEstimate const Vec3 up_target = Rotate(q_d, up_y); const Vec3 cross = Cross(up_world, up_target); const f32 sin_a = Length(cross); - const f32 angle = ::acos(Clampf(Dot(up_world, up_target), -1.0f, 1.0f)); + const f32 angle = ::acosf(Clampf(Dot(up_world, up_target), -1.0f, 1.0f)); const Vec3 axis = sin_a > 1e-6f ? cross * (1.0f / sin_a) : Vec3{0, 0, 0}; assist_torque = axis * (params.torso_orientation_gain * angle) - m.root_angular_velocity * params.torso_angular_damping; diff --git a/engine/nav/agent.cc b/engine/nav/agent.cc index 428efca5..664d92dc 100644 --- a/engine/nav/agent.cc +++ b/engine/nav/agent.cc @@ -15,7 +15,7 @@ Vec3 ReadPosition(const scene::Transform& t) { f32 PlanarDist(const Vec3& a, const Vec3& b) { const f32 dx = a.x - b.x; const f32 dz = a.z - b.z; - return ::sqrt(dx * dx + dz * dz); + return ::sqrtf(dx * dx + dz * dz); } // Face the move direction: yaw-only quaternion around +Y. The engine is @@ -23,11 +23,11 @@ f32 PlanarDist(const Vec3& a, const Vec3& b) { void FaceVelocity(scene::Transform& t, const Vec3& velocity) { const f32 planar = velocity.x * velocity.x + velocity.z * velocity.z; if (planar < 1e-6f) return; - const f32 yaw = ::atan2(velocity.x, velocity.z); + const f32 yaw = ::atan2f(velocity.x, velocity.z); t.rotation[0] = 0; - t.rotation[1] = ::sin(yaw * 0.5f); + t.rotation[1] = ::sinf(yaw * 0.5f); t.rotation[2] = 0; - t.rotation[3] = ::cos(yaw * 0.5f); + t.rotation[3] = ::cosf(yaw * 0.5f); } } // namespace @@ -95,7 +95,7 @@ void UpdateAgents(ecs::World& world, NavMesh& mesh, const AgentUpdateConfig& con } agent.corner = corner; const Vec3 to_corner{corner.x - pos.x, 0, corner.z - pos.z}; - const f32 dist = ::sqrt(Dot(to_corner, to_corner)); + const f32 dist = ::sqrtf(Dot(to_corner, to_corner)); if (dist < 1e-4f) { agent.status = AgentStatus::kMoving; return; diff --git a/engine/nav/nav_debug.cc b/engine/nav/nav_debug.cc index a63ed438..b4055357 100644 --- a/engine/nav/nav_debug.cc +++ b/engine/nav/nav_debug.cc @@ -26,7 +26,7 @@ u32 AreaColor(AreaId area) { return kAreaColors[area & 7]; } void AppendNavMeshLines(const NavMesh& mesh, const Vec3& center, f32 radius, base::Vector* out) { const f32 cs = mesh.config().cell_size; - const i32 r = static_cast(::ceil(radius / cs)); + const i32 r = static_cast(::ceilf(radius / cs)); const CellRef mid = mesh.CellAt(center); // Line endpoints take the interpolated surface height so edges hug slopes // instead of burying their downhill half in the ground. diff --git a/engine/nav/navmesh.cc b/engine/nav/navmesh.cc index 9229bebe..1c2f0fa3 100644 --- a/engine/nav/navmesh.cc +++ b/engine/nav/navmesh.cc @@ -45,10 +45,10 @@ bool NavMesh::BuildTile(i32 tx, i32 tz, SampleFn& sample) { u32 NavMesh::EnsureBubble(const Vec3& center, f32 radius, SampleFn& sample, u32 max_tiles) { const f32 tile_m = config_.cell_size * static_cast(config_.tile_cells); - const i32 t0x = static_cast(::floor((center.x - radius) / tile_m)); - const i32 t1x = static_cast(::floor((center.x + radius) / tile_m)); - const i32 t0z = static_cast(::floor((center.z - radius) / tile_m)); - const i32 t1z = static_cast(::floor((center.z + radius) / tile_m)); + const i32 t0x = static_cast(::floorf((center.x - radius) / tile_m)); + const i32 t1x = static_cast(::floorf((center.x + radius) / tile_m)); + const i32 t0z = static_cast(::floorf((center.z - radius) / tile_m)); + const i32 t1z = static_cast(::floorf((center.z + radius) / tile_m)); // Missing tiles, then nearest-first so the ground under the agents exists // before the bubble rim does. @@ -96,10 +96,10 @@ u32 NavMesh::RemoveTilesBeyond(const Vec3& center, f32 radius) { void NavMesh::PaintDisc(const Vec3& center, f32 radius, AreaId area) { if (area >= kMaxAreas) return; const f32 cs = config_.cell_size; - const i32 c0x = static_cast(::floor((center.x - radius) / cs)); - const i32 c1x = static_cast(::floor((center.x + radius) / cs)); - const i32 c0z = static_cast(::floor((center.z - radius) / cs)); - const i32 c1z = static_cast(::floor((center.z + radius) / cs)); + const i32 c0x = static_cast(::floorf((center.x - radius) / cs)); + const i32 c1x = static_cast(::floorf((center.x + radius) / cs)); + const i32 c0z = static_cast(::floorf((center.z - radius) / cs)); + const i32 c1z = static_cast(::floorf((center.z + radius) / cs)); const i32 n = static_cast(config_.tile_cells); u64 last_tile = ~0ull; Tile* tile = nullptr; @@ -173,7 +173,7 @@ u32 NavMesh::TileVersionByKey(u64 key) const { CellRef NavMesh::CellAt(const Vec3& pos) const { const f32 cs = config_.cell_size; - return {static_cast(::floor(pos.x / cs)), static_cast(::floor(pos.z / cs))}; + return {static_cast(::floorf(pos.x / cs)), static_cast(::floorf(pos.z / cs))}; } Vec3 NavMesh::CellCenter(CellRef cell) const { @@ -201,8 +201,8 @@ bool NavMesh::HeightAt(f32 x, f32 z, f32* out_height) const { // Sample space where integer coordinates sit on cell centers. const f32 sx = x / cs - 0.5f; const f32 sz = z / cs - 0.5f; - const i32 x0 = static_cast(::floor(sx)); - const i32 z0 = static_cast(::floor(sz)); + const i32 x0 = static_cast(::floorf(sx)); + const i32 z0 = static_cast(::floorf(sz)); const f32 fx = sx - static_cast(x0); const f32 fz = sz - static_cast(z0); f32 h[4]; @@ -225,13 +225,13 @@ bool NavMesh::Reachable(CellRef from, CellRef to) const { const Tile* ta = TileOf(from, &ia); const Tile* tb = TileOf(to, &ib); if (!ta || !tb || ta->area[ia] == kAreaNone || tb->area[ib] == kAreaNone) return false; - return ::fabs(ta->height[ia] - tb->height[ib]) <= config_.max_step; + return ::fabsf(ta->height[ia] - tb->height[ib]) <= config_.max_step; } CellRef NavMesh::ClampToWalkable(const Vec3& pos, f32 max_radius) const { const CellRef at = CellAt(pos); if (Walkable(at)) return at; - const i32 rings = static_cast(::ceil(max_radius / config_.cell_size)); + const i32 rings = static_cast(::ceilf(max_radius / config_.cell_size)); // Ring scan outward; within a ring prefer the cell nearest to pos. for (i32 r = 1; r <= rings; ++r) { CellRef best; @@ -282,7 +282,7 @@ NavRaycast NavMesh::Raycast(const Vec3& from, const Vec3& to) const { // Amanatides & Woo traversal over the cell grid. const f32 dx = to.x - from.x; const f32 dz = to.z - from.z; - const f32 len = ::sqrt(dx * dx + dz * dz); + const f32 len = ::sqrtf(dx * dx + dz * dz); const i32 step_x = dx > 0 ? 1 : -1; const i32 step_z = dz > 0 ? 1 : -1; const f32 inv_dx = dx != 0 ? 1.0f / dx : 0; diff --git a/engine/nav/path.cc b/engine/nav/path.cc index 267ec1e8..80d0d168 100644 --- a/engine/nav/path.cc +++ b/engine/nav/path.cc @@ -23,12 +23,12 @@ f32 TriArea2(const Vec3& a, const Vec3& b, const Vec3& c) { f32 PlanarDist(const Vec3& a, const Vec3& b) { const f32 dx = a.x - b.x; const f32 dz = a.z - b.z; - return ::sqrt(dx * dx + dz * dz); + return ::sqrtf(dx * dx + dz * dz); } f32 Octile(CellRef a, CellRef b, f32 cell_size) { - const f32 dx = ::fabs(static_cast(a.x - b.x)); - const f32 dz = ::fabs(static_cast(a.z - b.z)); + const f32 dx = ::fabsf(static_cast(a.x - b.x)); + const f32 dz = ::fabsf(static_cast(a.z - b.z)); const f32 lo = rx::Min(dx, dz); const f32 hi = rx::Max(dx, dz); return (hi + 0.41421356f * lo) * cell_size; diff --git a/engine/net/bubble.cc b/engine/net/bubble.cc index a74632c6..134945a4 100644 --- a/engine/net/bubble.cc +++ b/engine/net/bubble.cc @@ -85,11 +85,11 @@ void InterestMap::Update(ecs::World& world, u64 tick) { scratch_grid_.clear(); for (u32 bi = 0; bi < scratch_bubbles_.size(); ++bi) { const BubbleRef& b = scratch_bubbles_[bi]; - const f32 exit = ::sqrt(b.exit_sq); - const i32 min_x = static_cast(::floor((b.center[0] - exit) * inv_cell)); - const i32 max_x = static_cast(::floor((b.center[0] + exit) * inv_cell)); - const i32 min_z = static_cast(::floor((b.center[2] - exit) * inv_cell)); - const i32 max_z = static_cast(::floor((b.center[2] + exit) * inv_cell)); + const f32 exit = ::sqrtf(b.exit_sq); + const i32 min_x = static_cast(::floorf((b.center[0] - exit) * inv_cell)); + const i32 max_x = static_cast(::floorf((b.center[0] + exit) * inv_cell)); + const i32 min_z = static_cast(::floorf((b.center[2] - exit) * inv_cell)); + const i32 max_z = static_cast(::floorf((b.center[2] + exit) * inv_cell)); for (i32 cx = min_x; cx <= max_x; ++cx) { for (i32 cz = min_z; cz <= max_z; ++cz) { const u64 key = CellKey(cx, cz); @@ -133,8 +133,8 @@ void InterestMap::Update(ecs::World& world, u64 tick) { seen_ids.insert(id.value, u8{1}); candidates.clear(); - const i32 cx = static_cast(::floor(t.position[0] * inv_cell)); - const i32 cz = static_cast(::floor(t.position[2] * inv_cell)); + const i32 cx = static_cast(::floorf(t.position[0] * inv_cell)); + const i32 cz = static_cast(::floorf(t.position[2] * inv_cell)); const base::Vector* bucket = scratch_grid_.find(CellKey(cx, cz)); u32 avatar_peer = kNoPeer; if (bucket) { @@ -240,8 +240,8 @@ void InterestMap::RemovePeer(u32 peer) { u32 PeerColor(u32 peer) { // Golden-angle hue walk: well-spread, stable, no table. - const f32 hue = ::fmod(static_cast(peer) * 137.50776f, 360.0f) / 60.0f; - const f32 x = 1.0f - ::fabs(::fmod(hue, 2.0f) - 1.0f); + const f32 hue = ::fmodf(static_cast(peer) * 137.50776f, 360.0f) / 60.0f; + const f32 x = 1.0f - ::fabsf(::fmodf(hue, 2.0f) - 1.0f); f32 r = 0, g = 0, b = 0; switch (static_cast(hue)) { case 0: r = 1; g = x; break; diff --git a/engine/net/replication.cc b/engine/net/replication.cc index 7144adc8..59384097 100644 --- a/engine/net/replication.cc +++ b/engine/net/replication.cc @@ -29,7 +29,7 @@ f32 SegmentPlanarSpeed(const InterpolatedTransform& interp) { if (interp.duration <= 0) return 0; const f32 dx = interp.to.position[0] - interp.from.position[0]; const f32 dz = interp.to.position[2] - interp.from.position[2]; - return ::sqrt(dx * dx + dz * dz) / interp.duration; + return ::sqrtf(dx * dx + dz * dz) / interp.duration; } // Lerps position and scale, nlerps the quaternion along the shorter arc. @@ -49,7 +49,7 @@ void Blend(const scene::Transform& a, const scene::Transform& b, f32 alpha, q[i] = a.rotation[i] + (sign * b.rotation[i] - a.rotation[i]) * alpha; length_sq += q[i] * q[i]; } - const f32 inv_length = length_sq > 0 ? 1.0f / ::sqrt(length_sq) : 0; + const f32 inv_length = length_sq > 0 ? 1.0f / ::sqrtf(length_sq) : 0; for (int i = 0; i < 4; ++i) out->rotation[i] = q[i] * inv_length; } diff --git a/engine/net/session.cc b/engine/net/session.cc index 37df0112..dc3282b2 100644 --- a/engine/net/session.cc +++ b/engine/net/session.cc @@ -29,9 +29,9 @@ void DefaultSimulatePlayer(ecs::World& world, ecs::Entity player, t->position[2] += ClampAxis(input.move_z) * kDefaultPlayerSpeed * dt; const f32 half_yaw = input.yaw * 0.5f; t->rotation[0] = 0; - t->rotation[1] = ::sin(half_yaw); + t->rotation[1] = ::sinf(half_yaw); t->rotation[2] = 0; - t->rotation[3] = ::cos(half_yaw); + t->rotation[3] = ::cosf(half_yaw); } } // namespace diff --git a/engine/physics/aircraft.cc b/engine/physics/aircraft.cc index 35261c28..69f1feb5 100644 --- a/engine/physics/aircraft.cc +++ b/engine/physics/aircraft.cc @@ -29,8 +29,8 @@ f32 SmoothStep(f32 edge0, f32 edge1, f32 x) { // `alpha`. A logistic centred on the stall angle blends the attached linear // lift curve into a flat-plate curve; `half_width` (rad) sets how abruptly. f32 StallBlend(f32 alpha, f32 stall_alpha, f32 half_width) { - f32 x = (::fabs(alpha) - stall_alpha) / rx::Max(half_width, 1e-3f); - return 1.0f / (1.0f + ::exp(-4.0f * x)); + f32 x = (::fabsf(alpha) - stall_alpha) / rx::Max(half_width, 1e-3f); + return 1.0f / (1.0f + ::expf(-4.0f * x)); } } // namespace @@ -143,7 +143,7 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { // Filter flap deflection toward the quantized command (mechanical lag). { const u32 steps = rx::Max(1u, desc_.flap_steps); - const f32 quantized = ::round(Clampf(input.flaps, 0.0f, 1.0f) * steps) / steps; + const f32 quantized = ::roundf(Clampf(input.flaps, 0.0f, 1.0f) * steps) / steps; const f32 rate = 0.5f; // full travel in ~2 s flaps_ += Clampf(quantized - flaps_, -rate * dt, rate * dt); } @@ -155,8 +155,8 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { const f32 f_com = Dot(vair_com, fwd); const f32 u_com = Dot(vair_com, up); const f32 s_com = Dot(vair_com, right); - const f32 alpha_com = ::atan2(-u_com, f_com); - const f32 beta_com = ::atan2(s_com, rx::Max(::fabs(f_com), 1e-3f)); + const f32 alpha_com = ::atan2f(-u_com, f_com); + const f32 beta_com = ::atan2f(s_com, rx::Max(::fabsf(f_com), 1e-3f)); // wing halves: strip theory at each half's aerodynamic centre // Each half is evaluated at its OWN point velocity (GetPointVelocity), so @@ -181,13 +181,13 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { } const f32 fc = Dot(v, fwd); const f32 uc = Dot(v, up); - const f32 alpha = ::atan2(-uc, fc); + const f32 alpha = ::atan2f(-uc, fc); // Attached linear curve (with flap + aileron camber) blended into a // flat-plate curve past the stall; drag rises with the flat-plate term. const f32 cl_attached = desc_.wing_cl_alpha * (alpha - desc_.wing_zero_lift_alpha_rad) + flap_cl + cl_bias; - const f32 cl_flat = ::sin(2.0f * alpha); // 2 sin a cos a, flat plate + const f32 cl_flat = ::sinf(2.0f * alpha); // 2 sin a cos a, flat plate const f32 blend = StallBlend(alpha, desc_.wing_stall_alpha_rad, desc_.post_stall_decay); const f32 cl = (1.0f - blend) * cl_attached + blend * cl_flat; *stalled = blend > 0.5f; @@ -195,7 +195,7 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { // Induced drag from this half's lift; parasitic drag is applied once at the // CoM below. Post-stall separation adds a flat-plate drag bump. const f32 cd_induced = cl_attached * cl_attached / (kPi * aspect_ratio * desc_.oswald_efficiency); - const f32 cd = (1.0f - blend) * cd_induced + blend * (0.15f + 2.0f * ::sin(alpha) * ::sin(alpha)); + const f32 cd = (1.0f - blend) * cd_induced + blend * (0.15f + 2.0f * ::sinf(alpha) * ::sinf(alpha)); const f32 qh = 0.5f * kAirDensity * vlen * vlen; const f32 lift = qh * half_area * cl; @@ -226,7 +226,7 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { // fuselage side drag (sideslip): damps lateral sliding through the air { const f32 vside = Dot(vair_com, right); - const f32 fside = -0.5f * kAirDensity * ::fabs(vside) * vside * desc_.fuselage_side_cd * + const f32 fside = -0.5f * kAirDensity * ::fabsf(vside) * vside * desc_.fuselage_side_cd * desc_.fuselage_side_area_m2; world_.AddForce(body_, right * (fside * aero_fade)); } @@ -244,7 +244,7 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { if (vlen > 1e-3f) { const f32 fc = Dot(v, fwd); const f32 uc = Dot(v, up); - const f32 alpha_t = ::atan2(-uc, fc); + const f32 alpha_t = ::atan2f(-uc, fc); const f32 cl_t = desc_.tail_cl_alpha * alpha_t - desc_.elevator_authority * input.pitch; const f32 qt = 0.5f * kAirDensity * vlen * vlen; const f32 lift = qt * desc_.tail_area_m2 * cl_t; @@ -264,7 +264,7 @@ void Aircraft::Update(const AircraftInput& input, f32 dt) { if (vlen > 1e-3f) { const f32 fc = Dot(v, fwd); const f32 sc = Dot(v, right); - const f32 beta_f = ::atan2(sc, rx::Max(::fabs(fc), 1e-3f)); + const f32 beta_f = ::atan2f(sc, rx::Max(::fabsf(fc), 1e-3f)); // Side force opposes sideslip (weathervane) and responds to rudder. +yaw // input yaws the nose right (toward body -X): with +Z fwd / +Y up / +X // left, a nose-right yaw is a NEGATIVE rotation about +Y, which the fin diff --git a/engine/physics/boat.cc b/engine/physics/boat.cc index 36a4f804..3f80f4c2 100644 --- a/engine/physics/boat.cc +++ b/engine/physics/boat.cc @@ -23,15 +23,15 @@ f32 SmoothStep(f32 edge0, f32 edge1, f32 x) { // Yaw quaternion about +Y (x,y,z,w), for spawn orientation. Quat YawQuat(f32 yaw_radians) { - return {0.0f, ::sin(yaw_radians * 0.5f), 0.0f, ::cos(yaw_radians * 0.5f)}; + return {0.0f, ::sinf(yaw_radians * 0.5f), 0.0f, ::cosf(yaw_radians * 0.5f)}; } // v * |v|: signed quadratic term (drag ~ v^2 but keeps the sign of v). -f32 SignedSquare(f32 v) { return v * ::fabs(v); } +f32 SignedSquare(f32 v) { return v * ::fabsf(v); } // Guards a force/torque against NaN/Inf before it reaches the solver. bool Finite(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } } // namespace @@ -108,8 +108,8 @@ void Boat::Update(const BoatInput& input, f32 dt) { // engine spool: rpm chases the throttle target with a first-order lag const f32 target_rpm = - desc_.idle_rpm + ::fabs(throttle) * (desc_.max_rpm - desc_.idle_rpm); - const f32 spool = desc_.spool_time > 0 ? (1.0f - ::exp(-dt / desc_.spool_time)) : 1.0f; + desc_.idle_rpm + ::fabsf(throttle) * (desc_.max_rpm - desc_.idle_rpm); + const f32 spool = desc_.spool_time > 0 ? (1.0f - ::expf(-dt / desc_.spool_time)) : 1.0f; rpm_ += (target_rpm - rpm_) * spool; const f32 rpm_span = rx::Max(desc_.max_rpm - desc_.idle_rpm, 1.0f); const f32 thrust_frac = Clamp((rpm_ - desc_.idle_rpm) / rpm_span, 0.0f, 1.0f); @@ -184,10 +184,10 @@ void Boat::Update(const BoatInput& input, f32 dt) { const f32 v_fwd = Dot(vrel, forward); const f32 v_lat = Dot(vrel, right); const f32 v_vert = Dot(vel, up); - const f32 speed = ::sqrt(vel.x * vel.x + vel.z * vel.z); + const f32 speed = ::sqrtf(vel.x * vel.x + vel.z * vel.z); // Planing fraction from forward speed; drives bow lift + drag drop. - const f32 planing = SmoothStep(desc_.hull_speed, desc_.plane_full_speed, ::fabs(v_fwd)); + const f32 planing = SmoothStep(desc_.hull_speed, desc_.plane_full_speed, ::fabsf(v_fwd)); // Longitudinal: fore drag < aft drag; wetted-scaled; dropped by planing when // moving ahead. Lateral: strong keel drag so the hull carves rather than @@ -231,7 +231,7 @@ void Boat::Update(const BoatInput& input, f32 dt) { // Authority scales with the water speed over the rudder (|v_fwd|^2) plus the // propeller wash (proportional to thrust), so the boat still answers the helm // on the wash at a standstill. Only the wash term needs the prop submerged. - const f32 wash = (prop_submerged ? desc_.rudder_wash_gain * ::fabs(thrust_mag) : 0.0f); + const f32 wash = (prop_submerged ? desc_.rudder_wash_gain * ::fabsf(thrust_mag) : 0.0f); const f32 rudder_mag = steer * (desc_.rudder_speed_gain * v_fwd * v_fwd + wash); if (rudder_mag != 0.0f) { const Vec3 rudder_pt = pos + Rotate(q, desc_.rudder_offset); @@ -247,13 +247,13 @@ void Boat::Update(const BoatInput& input, f32 dt) { // little as it shoves it downwind. Conservative coefficient (see wind_drag). if (desc_.wind_drag > 0.0f && exposed > 0.0f) { const Vec3 vrel_wind = world_.wind() - vel; // air velocity relative to hull - const f32 wind_speed = ::sqrt(Dot(vrel_wind, vrel_wind)); + const f32 wind_speed = ::sqrtf(Dot(vrel_wind, vrel_wind)); if (wind_speed > 1e-3f) { const Vec3 wdir = vrel_wind * (1.0f / wind_speed); const f32 side_area = (2.0f * he.z) * (2.0f * he.y); // beam-on profile const f32 front_area = (2.0f * he.x) * (2.0f * he.y); // head-on profile const f32 area = - ::fabs(Dot(wdir, right)) * side_area + ::fabs(Dot(wdir, forward)) * front_area; + ::fabsf(Dot(wdir, right)) * side_area + ::fabsf(Dot(wdir, forward)) * front_area; const f32 mag = 0.5f * kAirDensity * desc_.wind_drag * area * exposed * wind_speed * wind_speed; const Vec3 wind_force = wdir * mag; diff --git a/engine/physics/cloth_collision.cc b/engine/physics/cloth_collision.cc index a87b62c8..b3050dbc 100644 --- a/engine/physics/cloth_collision.cc +++ b/engine/physics/cloth_collision.cc @@ -44,7 +44,7 @@ bool SameFace(const FaceKey& a, const FaceKey& b) { } bool IsFinite(const Vec3& p) { - return ::isfinite(p.x) && ::isfinite(p.y) && ::isfinite(p.z); + return isfinite(p.x) && isfinite(p.y) && isfinite(p.z); } f64 TriangleAreaTwice(const Vec3& a, const Vec3& b, const Vec3& c) { @@ -205,14 +205,14 @@ f64 Dot64(const Vec3& a, const Vec3& b) { u32 FindCubicRoots(f64 c0, f64 c1, f64 c2, f64 c3, f32 roots[4]) { const f64 scale = - ::abs(c0) + ::abs(c1) + ::abs(c2) + ::abs(c3) + 1.0; + ::fabs(c0) + ::fabs(c1) + ::fabs(c2) + ::fabs(c3) + 1.0; const f64 epsilon = scale * 1.0e-10; f64 points[4] = {0, 1, 0, 0}; u32 point_count = 2; const f64 da = 3 * c3; const f64 db = 2 * c2; const f64 dc = c1; - if (::abs(da) > epsilon) { + if (::fabs(da) > epsilon) { const f64 discriminant = db * db - 4 * da * dc; if (discriminant >= 0) { const f64 root = ::sqrt(discriminant); @@ -221,7 +221,7 @@ u32 FindCubicRoots(f64 c0, f64 c1, f64 c2, f64 c3, f32 roots[4]) { if (t0 > 0 && t0 < 1 && point_count < 4) points[point_count++] = t0; if (t1 > 0 && t1 < 1 && point_count < 4) points[point_count++] = t1; } - } else if (::abs(db) > epsilon) { + } else if (::fabs(db) > epsilon) { const f64 t = -dc / db; if (t > 0 && t < 1 && point_count < 4) points[point_count++] = t; } @@ -235,12 +235,12 @@ u32 FindCubicRoots(f64 c0, f64 c1, f64 c2, f64 c3, f32 roots[4]) { if (root < -epsilon || root > 1 + epsilon) return; const f32 value = static_cast(rx::Clamp(root, 0.0, 1.0)); if (root_count < 4 && (root_count == 0 || - ::abs(value - roots[root_count - 1]) > 1.0e-5f)) { + ::fabsf(value - roots[root_count - 1]) > 1.0e-5f)) { roots[root_count++] = value; } }; for (u32 i = 0; i < point_count; ++i) { - if (::abs(evaluate(points[i])) <= epsilon) add_root(points[i]); + if (::fabs(evaluate(points[i])) <= epsilon) add_root(points[i]); if (i + 1 == point_count) continue; f64 low = points[i], high = points[i + 1]; f64 low_value = evaluate(low); @@ -608,7 +608,7 @@ bool BuildClothTopology(const Vec3* positions, u32 vertex_count, } const f64 area_twice = TriangleAreaTwice(positions[a], positions[b], positions[c]); - if (!::isfinite(area_twice) || area_twice < kMinAreaTwice || + if (!isfinite(area_twice) || area_twice < kMinAreaTwice || area_twice > FLT_MAX) { return false; } @@ -619,7 +619,7 @@ bool BuildClothTopology(const Vec3* positions, u32 vertex_count, faces.push_back(MakeFaceKey(a, b, c)); const f64 volume = SignedVolumeContribution(positions[a], positions[b], positions[c]); - if (!::isfinite(volume)) return false; + if (!isfinite(volume)) return false; signed_volume += volume; neighbors.push_back({a, b}); neighbors.push_back({a, c}); @@ -662,7 +662,7 @@ bool BuildClothTopology(const Vec3* positions, u32 vertex_count, const f64 dy = static_cast(b.y) - a.y; const f64 dz = static_cast(b.z) - a.z; const f64 length = ::sqrt(dx * dx + dy * dy + dz * dz); - if (!::isfinite(length)) return false; + if (!isfinite(length)) return false; edge_length += length; ++edge_count; i = end; @@ -787,10 +787,10 @@ bool BuildClothTopology(const Vec3* positions, u32 vertex_count, result.neighbor_offsets[vertex_count] = static_cast(result.neighbors.size()); const f64 average_edge_length = edge_count > 0 ? edge_length / edge_count : 0; - if (!::isfinite(average_edge_length) || + if (!isfinite(average_edge_length) || average_edge_length > FLT_MAX || - !::isfinite(signed_volume) || - ::abs(signed_volume) > FLT_MAX) { + !isfinite(signed_volume) || + ::fabs(signed_volume) > FLT_MAX) { return false; } result.average_edge_length = static_cast(average_edge_length); @@ -820,7 +820,7 @@ u32 SolveClothSelfCollision(const ClothTopology& topology, scratch->predicted.resize(positions.size()); for (size_t i = 0; i < positions.size(); ++i) { if (!IsFinite(positions[i]) || !IsFinite((*velocities)[i]) || - !::isfinite(inverse_masses[i]) || inverse_masses[i] < 0) { + !isfinite(inverse_masses[i]) || inverse_masses[i] < 0) { return 0; } scratch->predicted[i] = positions[i] + (*velocities)[i] * dt; @@ -881,7 +881,7 @@ u32 SolveClothSelfCollision(const ClothTopology& topology, Vec3 correction = contact.normal * ((config.distance - separation) * relaxation / denominator); const f32 correction_length = Length(correction); - if (!IsFinite(correction) || !::isfinite(correction_length)) return; + if (!IsFinite(correction) || !isfinite(correction_length)) return; if (correction_length > max_correction) { correction = correction * (max_correction / correction_length); } @@ -952,7 +952,7 @@ u32 SolveClothSelfCollision(const ClothTopology& topology, Vec3 correction = contact.normal * ((config.distance - separation) * relaxation / denominator); const f32 correction_length = Length(correction); - if (!IsFinite(correction) || !::isfinite(correction_length)) return; + if (!IsFinite(correction) || !isfinite(correction_length)) return; if (correction_length > max_correction) { correction = correction * (max_correction / correction_length); } diff --git a/engine/physics/kite.cc b/engine/physics/kite.cc index a75543ab..3ec60815 100644 --- a/engine/physics/kite.cc +++ b/engine/physics/kite.cc @@ -14,12 +14,12 @@ f32 Clamp(f32 v, f32 lo, f32 hi) { return v < lo ? lo : (v > hi ? hi : v); } // Yaw quaternion about +Y (x,y,z,w), for spawn orientation. Quat YawQuat(f32 yaw_radians) { - return {0.0f, ::sin(yaw_radians * 0.5f), 0.0f, ::cos(yaw_radians * 0.5f)}; + return {0.0f, ::sinf(yaw_radians * 0.5f), 0.0f, ::cosf(yaw_radians * 0.5f)}; } // Guards a force/torque against NaN/Inf before it reaches the solver. bool Finite(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } } // namespace @@ -90,7 +90,7 @@ void Kite::Update(const KiteInput& input, f32 dt) { Vec3 ambient = world_.wind(); if (desc_.gust_amplitude_mps > 0.0f) { // Two-octave sinusoid: a cheap, bounded, deterministic gust. Along gust_dir. - const f32 g = 0.6f * ::sin(gust_time_ * 0.7f) + 0.4f * ::sin(gust_time_ * 2.3f + 1.7f); + const f32 g = 0.6f * ::sinf(gust_time_ * 0.7f) + 0.4f * ::sinf(gust_time_ * 2.3f + 1.7f); ambient += Normalize(desc_.gust_dir) * (desc_.gust_amplitude_mps * g); } @@ -117,7 +117,7 @@ void Kite::Update(const KiteInput& input, f32 dt) { const Vec3 f_aero = f_normal + f_tan; if (Finite(f_aero)) world_.AddForceAtPoint(body_, f_aero, ac_world); // Angle of attack (sail incidence to the wind): sin(alpha) = (w.n)/|w|. - const f32 alpha = ::asin(Clamp(wn / speed, -1.0f, 1.0f)); + const f32 alpha = ::asinf(Clamp(wn / speed, -1.0f, 1.0f)); alpha_deg = alpha * kRadToDeg; // attitude trim: align the belly normal to a belly-UP target @@ -135,7 +135,7 @@ void Kite::Update(const KiteInput& input, f32 dt) { wind_ref_primed_ = true; } else { constexpr f32 kAttTau = 0.35f; // s, attitude-target smoothing time constant - wind_ref_ += (w - wind_ref_) * (1.0f - ::exp(-dt / kAttTau)); + wind_ref_ += (w - wind_ref_) * (1.0f - ::expf(-dt / kAttTau)); } const f32 ref_speed = Length(wind_ref_); if (desc_.attitude_stiffness > 0.0f && ref_speed > desc_.min_airspeed_mps) { @@ -147,8 +147,8 @@ void Kite::Update(const KiteInput& input, f32 dt) { // target stays well-defined (no divide-by-zero, no snap). up_perp = upl > 1e-3f ? up_perp * (1.0f / upl) : Normalize(sail_normal - w_hat * Dot(sail_normal, w_hat)); - const f32 st = ::sin(desc_.trim_alpha_rad); - const f32 ct = ::cos(desc_.trim_alpha_rad); + const f32 st = ::sinf(desc_.trim_alpha_rad); + const f32 ct = ::cosf(desc_.trim_alpha_rad); const Vec3 n_target = w_hat * st + up_perp * ct; const f32 q_dyn = q_area * speed * speed; // 0.5 rho A |w|^2 const Vec3 align_torque = Cross(sail_normal, n_target) * (desc_.attitude_stiffness * q_dyn); diff --git a/engine/physics/physics_world.cc b/engine/physics/physics_world.cc index 64e6dec2..0d36a774 100644 --- a/engine/physics/physics_world.cc +++ b/engine/physics/physics_world.cc @@ -147,12 +147,12 @@ JPH::Mat44 ToJolt(const Mat4& m) { } bool IsFinite(const Vec3& value) { - return ::isfinite(value.x) && ::isfinite(value.y) && ::isfinite(value.z); + return isfinite(value.x) && isfinite(value.y) && isfinite(value.z); } bool IsFinite(const Mat4& value) { for (f32 element : value.m) { - if (!::isfinite(element)) return false; + if (!isfinite(element)) return false; } return true; } @@ -281,7 +281,7 @@ void ApplyTorqueCurve(JPH::VehicleEngineSettings& engine, const Point (&curve)[N // `fade_speed` (m/s), then held. fraction >= 1 or fade_speed <= 0 = no fade. f32 SteerFadeScale(f32 fraction, f32 fade_speed, f32 speed) { if (fade_speed <= 0.0f || fraction >= 1.0f) return 1.0f; - const f32 t = rx::Clamp(::fabs(speed) / fade_speed, 0.0f, 1.0f); + const f32 t = rx::Clamp(::fabsf(speed) / fade_speed, 0.0f, 1.0f); return 1.0f - (1.0f - fraction) * t; } @@ -496,7 +496,7 @@ struct PhysicsWorld::Impl { settings.mCombinedRestitution); f32 impulse = 0; for (f32 point_impulse : estimate.mContactImpulse) impulse += point_impulse; - impulse = ::abs(impulse); + impulse = ::fabsf(impulse); base::LockGuard guard(mutex); if (watch1) { @@ -772,9 +772,9 @@ void PhysicsWorld::Update(f32 dt) { const JPH::Vec3 cloth_velocity = (a.mVelocity + b.mVelocity + c.mVelocity) / 3.0f; const f32 normal_speed = (local_wind - cloth_velocity).Dot(normal); const JPH::Vec3 force = normal * (0.25f * kAirDensity * entry.aerodynamic_drag * - area_twice * normal_speed * ::abs(normal_speed)); - if (!::isfinite(force.GetX()) || !::isfinite(force.GetY()) || - !::isfinite(force.GetZ())) { + area_twice * normal_speed * ::fabsf(normal_speed)); + if (!isfinite(force.GetX()) || !isfinite(force.GetY()) || + !isfinite(force.GetZ())) { continue; } for (JPH::SoftBodyVertex* vertex : {&a, &b, &c}) { @@ -783,12 +783,12 @@ void PhysicsWorld::Update(f32 dt) { // Explicit quadratic drag must not overshoot the air velocity in // one face contribution or it can oscillate and hit the speed cap. const f32 max_delta = - rx::Min(entry.max_linear_velocity * 0.25f, ::abs(normal_speed)); - if (delta_sq > max_delta * max_delta) delta *= max_delta / ::sqrt(delta_sq); + rx::Min(entry.max_linear_velocity * 0.25f, ::fabsf(normal_speed)); + if (delta_sq > max_delta * max_delta) delta *= max_delta / ::sqrtf(delta_sq); vertex->mVelocity += delta; const f32 speed_sq = vertex->mVelocity.LengthSq(); if (speed_sq > entry.max_linear_velocity * entry.max_linear_velocity) { - vertex->mVelocity *= entry.max_linear_velocity / ::sqrt(speed_sq); + vertex->mVelocity *= entry.max_linear_velocity / ::sqrtf(speed_sq); } } } @@ -1266,7 +1266,7 @@ void PhysicsWorld::SetJointMotorTarget(JointId joint, const f32 target_quat[4]) if (entry.hinge) { auto* hinge = static_cast(entry.constraint.GetPtr()); // Twist angle about the hinge axis (constraint-space X) of the target. - f32 angle = 2.0f * ::atan2(q.GetX(), q.GetW()); + f32 angle = 2.0f * ::atan2f(q.GetX(), q.GetW()); hinge->SetTargetAngle(angle); } else { auto* st = static_cast(entry.constraint.GetPtr()); @@ -1957,7 +1957,7 @@ VehicleId PhysicsWorld::CreateMotorcycle(const MotorcycleDesc& desc, const Vec3& front->mPosition = JPH::Vec3(0, attach_y, desc.front_z); front->mMaxSteerAngle = desc.max_steer_angle; // Caster: the fork rakes back, and the steering axis follows the fork. - front->mSuspensionDirection = JPH::Vec3(0, -1, ::tan(desc.caster_angle)).Normalized(); + front->mSuspensionDirection = JPH::Vec3(0, -1, ::tanf(desc.caster_angle)).Normalized(); front->mSteeringAxis = -front->mSuspensionDirection; front->mRadius = desc.wheel_radius; front->mWidth = desc.wheel_width; @@ -2178,7 +2178,7 @@ f32 PhysicsWorld::TractionControlThrottle(u32 vehicle_index, f32 forward) { JPH::BodyInterface& bodies = impl_->system->GetBodyInterface(); const JPH::Vec3 velocity = bodies.GetLinearVelocity(entry.body); const JPH::Vec3 fwd_axis = bodies.GetRotation(entry.body) * JPH::Vec3::sAxisZ(); - if (::fabs(velocity.Dot(fwd_axis)) > 5.0f) { + if (::fabsf(velocity.Dot(fwd_axis)) > 5.0f) { f32 max_slip = 0; for (u32 i = 0; i < entry.wheel_count; ++i) { const auto* wheel = static_cast(entry.constraint->GetWheel(i)); @@ -2280,7 +2280,7 @@ bool PhysicsWorld::GetVehicleState(VehicleId id, VehicleState* out) const { // ~0 to the wheels even though the engine still revs. GetTorque is linear in // its input, so load == delivered/max at this rpm. const f32 clutch = trans.GetClutchFriction(); - const f32 applied = ::fabs(controller->GetForwardInput()) * clutch; + const f32 applied = ::fabsf(controller->GetForwardInput()) * clutch; const f32 max_torque_at_rpm = engine.GetTorque(1.0f); out->engine_torque = engine.GetTorque(applied); out->engine_load = @@ -2573,22 +2573,22 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) !IsFinite(transform)) { return 0; } - if (!::isfinite(desc.areal_density) || desc.areal_density <= 0 || - !::isfinite(desc.warp_compliance) || desc.warp_compliance < 0 || - !::isfinite(desc.weft_compliance) || desc.weft_compliance < 0 || - !::isfinite(desc.shear_compliance) || desc.shear_compliance < 0 || - !::isfinite(desc.bend_compliance) || desc.bend_compliance < 0 || - !::isfinite(desc.max_stretch) || desc.max_stretch < 1 || - !::isfinite(desc.collision_radius) || desc.collision_radius < 0 || - !::isfinite(desc.self_collision_distance) || desc.self_collision_distance < 0 || - !::isfinite(desc.self_collision_relaxation) || desc.self_collision_relaxation < 0 || + if (!isfinite(desc.areal_density) || desc.areal_density <= 0 || + !isfinite(desc.warp_compliance) || desc.warp_compliance < 0 || + !isfinite(desc.weft_compliance) || desc.weft_compliance < 0 || + !isfinite(desc.shear_compliance) || desc.shear_compliance < 0 || + !isfinite(desc.bend_compliance) || desc.bend_compliance < 0 || + !isfinite(desc.max_stretch) || desc.max_stretch < 1 || + !isfinite(desc.collision_radius) || desc.collision_radius < 0 || + !isfinite(desc.self_collision_distance) || desc.self_collision_distance < 0 || + !isfinite(desc.self_collision_relaxation) || desc.self_collision_relaxation < 0 || desc.self_collision_relaxation > 1 || - !::isfinite(desc.aerodynamic_drag) || desc.aerodynamic_drag < 0 || - !::isfinite(desc.damping) || desc.damping < 0 || - !::isfinite(desc.gravity_factor) || !::isfinite(desc.friction) || desc.friction < 0 || - !::isfinite(desc.restitution) || desc.restitution < 0 || - !::isfinite(desc.pressure) || desc.pressure < 0 || - !::isfinite(desc.max_linear_velocity) || desc.max_linear_velocity <= 0 || + !isfinite(desc.aerodynamic_drag) || desc.aerodynamic_drag < 0 || + !isfinite(desc.damping) || desc.damping < 0 || + !isfinite(desc.gravity_factor) || !isfinite(desc.friction) || desc.friction < 0 || + !isfinite(desc.restitution) || desc.restitution < 0 || + !isfinite(desc.pressure) || desc.pressure < 0 || + !isfinite(desc.max_linear_velocity) || desc.max_linear_velocity <= 0 || desc.iterations > 64 || desc.self_collision_iterations > 8 || (desc.self_collision_distance > 0 && desc.self_collision_iterations == 0)) { RX_WARN("cloth rejected: invalid material or collision parameters"); @@ -2614,7 +2614,7 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) return 0; } const bool pressure_capable = topology.closed && topology.component_count == 1 && - ::isfinite(topology.signed_volume) && + isfinite(topology.signed_volume) && topology.signed_volume > 1.0e-9f; if (desc.pressure > 0 && !pressure_capable) { RX_WARN("cloth rejected: pressure requires one closed, outward-wound volume"); @@ -2622,7 +2622,7 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) } if (desc.uvs) { for (u32 i = 0; i < desc.vertex_count * 2; ++i) { - if (!::isfinite(desc.uvs[i])) { + if (!isfinite(desc.uvs[i])) { RX_WARN("cloth rejected: non-finite material UV"); return 0; } @@ -2659,8 +2659,8 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) for (u32 i = 0; i < desc.skin_constraint_count; ++i) { const ClothSkinConstraint& skin = desc.skin_constraints[i]; if (skin.vertex >= desc.vertex_count || skinned[skin.vertex] || pin_mask[skin.vertex] || - !::isfinite(skin.max_distance) || skin.max_distance < 0 || - !::isfinite(skin.backstop_distance) || !::isfinite(skin.backstop_radius) || + !isfinite(skin.max_distance) || skin.max_distance < 0 || + !isfinite(skin.backstop_distance) || !isfinite(skin.backstop_radius) || skin.backstop_radius < 0) { RX_WARN("cloth rejected: invalid skin constraint"); return 0; @@ -2668,7 +2668,7 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) u32 weight_count = 0; for (const ClothSkinWeight& weight : skin.weights) { if (weight.weight == 0) continue; - if (!::isfinite(weight.weight) || weight.weight < 0 || weight.joint >= desc.joint_count || + if (!isfinite(weight.weight) || weight.weight < 0 || weight.joint >= desc.joint_count || weight_count >= JPH::SoftBodySharedSettings::Skinned::cMaxSkinWeights) { RX_WARN("cloth rejected: invalid skin weight"); return 0; @@ -2707,7 +2707,7 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) inverse_masses.resize(desc.vertex_count); if (desc.inverse_masses) { for (u32 i = 0; i < desc.vertex_count; ++i) { - if (!::isfinite(desc.inverse_masses[i]) || desc.inverse_masses[i] < 0) { + if (!isfinite(desc.inverse_masses[i]) || desc.inverse_masses[i] < 0) { RX_WARN("cloth rejected: inverse masses must be finite and non-negative"); return 0; } @@ -2723,15 +2723,15 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) const u32 c = topology.indices[i + 2]; const f64 triangle_mass = static_cast(topology.triangle_areas[i / 3]) * desc.areal_density; - if (!::isfinite(triangle_mass)) return 0; + if (!isfinite(triangle_mass)) return 0; masses[a] += triangle_mass / 3.0; masses[b] += triangle_mass / 3.0; masses[c] += triangle_mass / 3.0; } for (u32 i = 0; i < desc.vertex_count; ++i) { const f64 inverse_mass = 1.0 / masses[i]; - if (masses[i] <= 1.0e-8 || !::isfinite(masses[i]) || - !::isfinite(inverse_mass) || inverse_mass > FLT_MAX) { + if (masses[i] <= 1.0e-8 || !isfinite(masses[i]) || + !isfinite(inverse_mass) || inverse_mass > FLT_MAX) { RX_WARN("cloth rejected: every vertex must belong to a non-degenerate face"); return 0; } @@ -2806,9 +2806,9 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) topology.edges[low * 2 + 1] == b; }; for (JPH::SoftBodySharedSettings::Edge& edge : shared->mEdgeConstraints) { - const f32 du = ::abs(desc.uvs[edge.mVertex[1] * 2 + 0] - + const f32 du = ::fabsf(desc.uvs[edge.mVertex[1] * 2 + 0] - desc.uvs[edge.mVertex[0] * 2 + 0]); - const f32 dv = ::abs(desc.uvs[edge.mVertex[1] * 2 + 1] - + const f32 dv = ::fabsf(desc.uvs[edge.mVertex[1] * 2 + 1] - desc.uvs[edge.mVertex[0] * 2 + 1]); const bool warp = du > 2.0f * dv; const bool weft = dv > 2.0f * du; @@ -2911,7 +2911,7 @@ ClothId PhysicsWorld::CreateCloth(const ClothDesc& desc, const Mat4& transform) bool PhysicsWorld::SetClothTransform(ClothId id, const Mat4& transform, f32 dt) { if (!impl_ || id == 0 || id > impl_->cloth.size() || !IsFinite(transform) || - !::isfinite(dt) || dt < 0) { + !isfinite(dt) || dt < 0) { return false; } Impl::ClothEntry& entry = impl_->cloth[id - 1]; @@ -2925,7 +2925,7 @@ bool PhysicsWorld::SetClothTransform(ClothId id, const Mat4& transform, f32 dt) } bool PhysicsWorld::SetClothPinTargets(ClothId id, const Vec3* targets, u32 target_count, f32 dt) { - if (!impl_ || id == 0 || id > impl_->cloth.size() || !::isfinite(dt) || dt < 0) return false; + if (!impl_ || id == 0 || id > impl_->cloth.size() || !isfinite(dt) || dt < 0) return false; Impl::ClothEntry& entry = impl_->cloth[id - 1]; if (!entry.alive || target_count != entry.pinned.size() || (target_count > 0 && !targets)) { return false; @@ -2972,7 +2972,7 @@ bool PhysicsWorld::SetClothJointTransforms(ClothId id, const Mat4* world_joints, if (!IsFinite(world_joints[i])) return false; if (!changed) { for (u32 element = 0; element < 16; ++element) { - if (::abs(world_joints[i].m[element] - entry.last_joint_transforms[i].m[element]) > + if (::fabsf(world_joints[i].m[element] - entry.last_joint_transforms[i].m[element]) > 1.0e-7f) { changed = true; break; @@ -3013,7 +3013,7 @@ void PhysicsWorld::SetClothWind(ClothId id, const Vec3& velocity) { } void PhysicsWorld::SetClothPressure(ClothId id, f32 pressure) { - if (!impl_ || id == 0 || id > impl_->cloth.size() || !::isfinite(pressure) || pressure < 0) { + if (!impl_ || id == 0 || id > impl_->cloth.size() || !isfinite(pressure) || pressure < 0) { return; } Impl::ClothEntry& entry = impl_->cloth[id - 1]; diff --git a/engine/physics/water_waves.h b/engine/physics/water_waves.h index 4eff5878..c24aca79 100644 --- a/engine/physics/water_waves.h +++ b/engine/physics/water_waves.h @@ -53,10 +53,10 @@ inline f32 GerstnerWaveHeight(f32 x, f32 z, f32 t, Vec3* flow = nullptr, f32 flow_x = 0.0f, flow_z = 0.0f, vy = 0.0f; for (const GerstnerWaveParam& g : kGerstnerWaves) { const f32 k = kWaterTau / g.wavelength; - const f32 w = ::sqrt(kGravity * k); // deep-water dispersion + const f32 w = ::sqrtf(kGravity * k); // deep-water dispersion const f32 phase = k * (g.dir_x * x + g.dir_z * z) + w * t; - const f32 s = ::sin(phase); - const f32 c = ::cos(phase); + const f32 s = ::sinf(phase); + const f32 c = ::cosf(phase); height += g.amplitude * s; // Horizontal displacement amplitude q*amp = chop / (4k); its time // derivative (orbital velocity) is -dir * q*amp * w * sin(phase). diff --git a/engine/placement/density_program.cc b/engine/placement/density_program.cc index 49826ad7..314863ac 100644 --- a/engine/placement/density_program.cc +++ b/engine/placement/density_program.cc @@ -75,7 +75,7 @@ f32 EvalDensityProgram(base::Span ops, const WorldData& world, break; } case DensityOpCode::kPow: - push(::pow(rx::Max(pop(), 0.0f), op.a)); + push(::powf(rx::Max(pop(), 0.0f), op.a)); break; } } diff --git a/engine/placement/placement.cc b/engine/placement/placement.cc index 4c16e8ff..03c21225 100644 --- a/engine/placement/placement.cc +++ b/engine/placement/placement.cc @@ -75,7 +75,7 @@ void PlacementSystem::Update(const Vec3& viewer) { f32 cz = (static_cast(tile.key.z) + 0.5f) * stack.tile_size; f32 dx = viewer.x - cx; f32 dz = viewer.z - cz; - bool outside = ::sqrt(dx * dx + dz * dz) > stack.stream_radius; + bool outside = ::sqrtf(dx * dx + dz * dz) > stack.stream_radius; if (tile.state == 2 && (outside || tile.stale)) evicted_.push_back(tile.key); } @@ -84,8 +84,8 @@ void PlacementSystem::Update(const Vec3& viewer) { for (u32 s = 0; s < stacks_.size() && budget > 0; ++s) { const PlacementStack& stack = stacks_[s]; i32 r = static_cast(config_.radius_tiles); - i32 center_x = static_cast(::floor(viewer.x / stack.tile_size)); - i32 center_z = static_cast(::floor(viewer.z / stack.tile_size)); + i32 center_x = static_cast(::floorf(viewer.x / stack.tile_size)); + i32 center_z = static_cast(::floorf(viewer.z / stack.tile_size)); for (i32 dz = -r; dz <= r && budget > 0; ++dz) { for (i32 dx = -r; dx <= r && budget > 0; ++dx) { TileKey key{s, center_x + dx, center_z + dz}; @@ -93,7 +93,7 @@ void PlacementSystem::Update(const Vec3& viewer) { f32 cz = (static_cast(key.z) + 0.5f) * stack.tile_size; f32 ddx = viewer.x - cx; f32 ddz = viewer.z - cz; - if (::sqrt(ddx * ddx + ddz * ddz) > stack.stream_radius) continue; + if (::sqrtf(ddx * ddx + ddz * ddz) > stack.stream_radius) continue; if (Find(key)) continue; pending_.push_back(key); --budget; @@ -224,7 +224,7 @@ void PlacementSystem::EmitTileCpu(const TileKey& key, base::VectorSample(height_map_, world_x, world_z + h) - world_->Sample(height_map_, world_x, world_z - h); Vec3 normal{-dhx, 2.0f * h, -dhz}; - f32 nlen = ::sqrt(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z); + f32 nlen = ::sqrtf(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z); point.normal = {normal.x / nlen, normal.y / nlen, normal.z / nlen}; u32 seed = InstanceSeed(config_.seed, key.x, key.z, i, layer_index); diff --git a/engine/placement/placement_math.h b/engine/placement/placement_math.h index 832ede8e..d9ae3f13 100644 --- a/engine/placement/placement_math.h +++ b/engine/placement/placement_math.h @@ -46,8 +46,8 @@ inline f32 ValueNoise(f32 x, f32 z, f32 feature_size, u32 seed) { if (feature_size <= 0.0f) return 0.5f; f32 fx = x / feature_size; f32 fz = z / feature_size; - f32 ix = ::floor(fx); - f32 iz = ::floor(fz); + f32 ix = ::floorf(fx); + f32 iz = ::floorf(fz); f32 tx = Smoothstep01(fx - ix); f32 tz = Smoothstep01(fz - iz); i32 cx = static_cast(ix); @@ -78,19 +78,19 @@ inline Mat4 BuildPlacementTransform(const OrientedPoint& point, f32 yaw, f32 sca Vec3 up{0.0f, 1.0f, 0.0f}; Vec3 axis{up.x + (point.normal.x - up.x) * tilt, up.y + (point.normal.y - up.y) * tilt, up.z + (point.normal.z - up.z) * tilt}; - f32 len = ::sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); + f32 len = ::sqrtf(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); if (len < 1e-5f) { axis = up; } else { axis = {axis.x / len, axis.y / len, axis.z / len}; } // Orthonormal basis around `axis`, yawed by `yaw`. - f32 c = ::cos(yaw); - f32 s = ::sin(yaw); - Vec3 ref = ::fabs(axis.y) < 0.99f ? Vec3{0.0f, 1.0f, 0.0f} : Vec3{1.0f, 0.0f, 0.0f}; + f32 c = ::cosf(yaw); + f32 s = ::sinf(yaw); + Vec3 ref = ::fabsf(axis.y) < 0.99f ? Vec3{0.0f, 1.0f, 0.0f} : Vec3{1.0f, 0.0f, 0.0f}; Vec3 tangent{ref.y * axis.z - ref.z * axis.y, ref.z * axis.x - ref.x * axis.z, ref.x * axis.y - ref.y * axis.x}; - f32 tlen = ::sqrt(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z); + f32 tlen = ::sqrtf(tangent.x * tangent.x + tangent.y * tangent.y + tangent.z * tangent.z); tangent = {tangent.x / tlen, tangent.y / tlen, tangent.z / tlen}; // tangent x axis, so [x=tangent, y=axis, z=bitangent] is right-handed // (instance groups reject mirrored transforms). diff --git a/engine/placement/world_data.cc b/engine/placement/world_data.cc index f1476834..f7391b42 100644 --- a/engine/placement/world_data.cc +++ b/engine/placement/world_data.cc @@ -38,8 +38,8 @@ f32 WorldData::Sample(u32 map, f32 world_x, f32 world_z) const { f32 step = meters_per_texel(); f32 u = (world_x - origin_x_) / step - 0.5f; f32 v = (world_z - origin_z_) / step - 0.5f; - f32 fu = ::floor(u); - f32 fv = ::floor(v); + f32 fu = ::floorf(u); + f32 fv = ::floorf(v); f32 tu = u - fu; f32 tv = v - fv; i32 max_texel = static_cast(resolution_) - 1; @@ -67,7 +67,7 @@ void WorldData::PaintDisc(u32 map, f32 center_x, f32 center_z, f32 radius, f32 v for (i32 x = x0; x <= x1; ++x) { f32 wx = origin_x_ + (static_cast(x) + 0.5f) * step; f32 wz = origin_z_ + (static_cast(z) + 0.5f) * step; - f32 d = ::sqrt((wx - center_x) * (wx - center_x) + (wz - center_z) * (wz - center_z)); + f32 d = ::sqrtf((wx - center_x) * (wx - center_x) + (wz - center_z) * (wz - center_z)); if (d >= radius) continue; f32 strength = rx::Min(1.0f, (radius - d) / (radius * 0.25f + 1e-5f)); f32& texel = At(map, static_cast(x), static_cast(z)); diff --git a/engine/render/atmosphere/cloudscape.cc b/engine/render/atmosphere/cloudscape.cc index dfb87a46..b9017565 100644 --- a/engine/render/atmosphere/cloudscape.cc +++ b/engine/render/atmosphere/cloudscape.cc @@ -92,9 +92,9 @@ bool SameMapState(const CloudscapeMapState &a, const CloudscapeMapState &b) { bool MapStateDiscontinuous(const CloudscapeMapState &a, const CloudscapeMapState &b) { - return a.seed != b.seed || ::abs(a.coverage - b.coverage) > 0.25f || - ::abs(a.cloud_type - b.cloud_type) > 0.25f || - ::abs(a.precipitation - b.precipitation) > 0.25f; + return a.seed != b.seed || ::fabsf(a.coverage - b.coverage) > 0.25f || + ::fabsf(a.cloud_type - b.cloud_type) > 0.25f || + ::fabsf(a.precipitation - b.precipitation) > 0.25f; } bool DensityFieldDiscontinuous(const CloudscapeControls &previous, @@ -118,21 +118,21 @@ bool DensityFieldDiscontinuous(const CloudscapeControls &previous, return true; } if (!endpoint_relabel && - ::abs(current.map_blend - previous.map_blend) > 0.25f) + ::fabsf(current.map_blend - previous.map_blend) > 0.25f) return true; const f32 thickness = rx::Max(previous.top - previous.bottom, 1.0f); const Vec2 map_delta = current.map_offset - previous.map_offset; - const f32 wind_alignment = ::cos(current.wind_yaw - previous.wind_yaw); - return ::abs(current.bottom - previous.bottom) > rx::Max(250.0f, thickness * 0.15f) || - ::abs(current.top - previous.top) > rx::Max(500.0f, thickness * 0.15f) || - ::abs(current.density - previous.density) > 0.25f || - ::abs(current.anvil - previous.anvil) > 0.25f || - ::abs(current.darkness - previous.darkness) > 0.25f || + const f32 wind_alignment = ::cosf(current.wind_yaw - previous.wind_yaw); + return ::fabsf(current.bottom - previous.bottom) > rx::Max(250.0f, thickness * 0.15f) || + ::fabsf(current.top - previous.top) > rx::Max(500.0f, thickness * 0.15f) || + ::fabsf(current.density - previous.density) > 0.25f || + ::fabsf(current.anvil - previous.anvil) > 0.25f || + ::fabsf(current.darkness - previous.darkness) > 0.25f || map_delta.x * map_delta.x + map_delta.y * map_delta.y > 250000.0f || wind_alignment < 0.94f || - ::abs(current.vertical_skew - previous.vertical_skew) > 250.0f || - ::abs(current.turbulence - previous.turbulence) > 0.25f; + ::fabsf(current.vertical_skew - previous.vertical_skew) > 250.0f || + ::fabsf(current.turbulence - previous.turbulence) > 0.25f; } } // namespace @@ -308,8 +308,8 @@ ResourceHandle Cloudscape::AddHazeToGraph(RenderGraph &graph, push.sun_color[2] = frame.sun_color.z; push.sun_color[3] = frame.flash; const CloudscapeControls &c = frame.controls; - push.wind[0] = ::cos(c.wind_yaw); - push.wind[1] = ::sin(c.wind_yaw); + push.wind[0] = ::cosf(c.wind_yaw); + push.wind[1] = ::sinf(c.wind_yaw); push.wind[2] = c.vertical_skew; push.wind[3] = c.darkness; push.fog[0] = c.fog_density; @@ -389,8 +389,8 @@ void Cloudscape::AddShadowToGraph(RenderGraph &graph, ResourceHandle sun_shadow, push.sun_dir[2] = sun.z; push.near_plane = 0.1f; const CloudscapeControls &c = frame.controls; - push.wind[0] = ::cos(c.wind_yaw); - push.wind[1] = ::sin(c.wind_yaw); + push.wind[0] = ::cosf(c.wind_yaw); + push.wind[1] = ::sinf(c.wind_yaw); push.wind[2] = c.wind_speed; push.wind[3] = c.vertical_skew; push.shape[0] = c.bottom; @@ -494,10 +494,10 @@ ResourceHandle Cloudscape::AddToGraph(RenderGraph &graph, ResourceHandle color, Vec3 current_sun = Normalize(frame.sun_direction); bool lighting_cut = has_last_frame_ && (Dot(current_sun, last_sun_direction_) < 0.98f || - ::abs(frame.sun_intensity - last_sun_intensity_) > 0.5f || + ::fabsf(frame.sun_intensity - last_sun_intensity_) > 0.5f || Dot(frame.sun_color - last_sun_color_, frame.sun_color - last_sun_color_) > 0.04f || - ::abs(frame.ambient - last_ambient_) > 0.1f); + ::fabsf(frame.ambient - last_ambient_) > 0.1f); bool history = history_valid_ && contiguous && !frame.reset_history && !camera_cut && !density_cut && !lighting_cut; MarchPush march_push{}; @@ -517,8 +517,8 @@ ResourceHandle Cloudscape::AddToGraph(RenderGraph &graph, ResourceHandle color, march_push.sun_color[2] = frame.sun_color.z; march_push.sun_color[3] = frame.ambient; const CloudscapeControls &c = frame.controls; - march_push.wind[0] = ::cos(c.wind_yaw); - march_push.wind[1] = ::sin(c.wind_yaw); + march_push.wind[0] = ::cosf(c.wind_yaw); + march_push.wind[1] = ::sinf(c.wind_yaw); march_push.wind[2] = c.wind_speed; march_push.wind[3] = c.vertical_skew; march_push.shape[0] = c.bottom; diff --git a/engine/render/atmosphere/cloudscape_textures.cc b/engine/render/atmosphere/cloudscape_textures.cc index 32d09a99..a04f138e 100644 --- a/engine/render/atmosphere/cloudscape_textures.cc +++ b/engine/render/atmosphere/cloudscape_textures.cc @@ -33,7 +33,7 @@ bool StateEqual(const CloudscapeMapState& a, const CloudscapeMapState& b) { f32 QuantizeBlend(f32 blend) { constexpr f32 kSteps = 64.0f; - return ::round(rx::Clamp(blend, 0.0f, 1.0f) * kSteps) / kSteps; + return ::roundf(rx::Clamp(blend, 0.0f, 1.0f) * kSteps) / kSteps; } } // namespace diff --git a/engine/render/atmosphere/lightning_envelope.h b/engine/render/atmosphere/lightning_envelope.h index ce726b54..e43b44e5 100644 --- a/engine/render/atmosphere/lightning_envelope.h +++ b/engine/render/atmosphere/lightning_envelope.h @@ -14,7 +14,7 @@ inline constexpr f32 kLightningStrikeDuration = 0.45f; // Kept header-only so gameplay/weather code can schedule matching flashes // without linking the GPU renderer implementation. inline f32 LightningEnvelope(f32 age, u32 seed) { - if (!::isfinite(age) || age < 0.0f || age >= kLightningStrikeDuration) + if (!isfinite(age) || age < 0.0f || age >= kLightningStrikeDuration) return 0.0f; auto pcg_hash = [](u32 v) { v = v * 747796405u + 2891336453u; @@ -31,14 +31,14 @@ inline f32 LightningEnvelope(f32 age, u32 seed) { f32 hz = static_cast(c) * kInv; f32 hw = static_cast(d) * kInv; - f32 envelope = ::exp(-age * 26.0f); + f32 envelope = ::expf(-age * 26.0f); f32 t1 = 0.10f + 0.08f * hx; if (age > t1) - envelope += (0.5f + 0.4f * hy) * ::exp(-(age - t1) * 30.0f); + envelope += (0.5f + 0.4f * hy) * ::expf(-(age - t1) * 30.0f); if (hz > 0.35f) { f32 t2 = 0.22f + 0.10f * hw; if (age > t2) - envelope += (0.35f + 0.30f * hx) * ::exp(-(age - t2) * 30.0f); + envelope += (0.35f + 0.30f * hx) * ::expf(-(age - t2) * 30.0f); } return envelope * rx::Clamp((kLightningStrikeDuration - age) * 20.0f, 0.0f, 1.0f); diff --git a/engine/render/atmosphere/precip_occlusion.cc b/engine/render/atmosphere/precip_occlusion.cc index 1843df80..a7c080f9 100644 --- a/engine/render/atmosphere/precip_occlusion.cc +++ b/engine/render/atmosphere/precip_occlusion.cc @@ -42,9 +42,9 @@ void PrecipOcclusion::BeginFrame(const Vec3& eye, u32 frame_index) { // Quantize the anchor to the coarse cell: the projection window only ever // moves in whole cells (which are whole texels), so map content never // shimmers under camera motion; between cells the map is simply reused. - f32 ax = ::floor(eye.x / kAnchorCell + 0.5f) * kAnchorCell; - f32 ay = ::floor(eye.y / kAnchorCell + 0.5f) * kAnchorCell; - f32 az = ::floor(eye.z / kAnchorCell + 0.5f) * kAnchorCell; + f32 ax = ::floorf(eye.x / kAnchorCell + 0.5f) * kAnchorCell; + f32 ay = ::floorf(eye.y / kAnchorCell + 0.5f) * kAnchorCell; + f32 az = ::floorf(eye.z / kAnchorCell + 0.5f) * kAnchorCell; if (ax != center_[0] || ay != center_[1] || az != center_[2]) dirty_ = true; // Cheap steady-state refresh so doors/moving cover eventually update. if (frame_index % kRefreshFrames == 0) dirty_ = true; diff --git a/engine/render/core/dynamic_resolution.cc b/engine/render/core/dynamic_resolution.cc index 4123b192..d525de64 100644 --- a/engine/render/core/dynamic_resolution.cc +++ b/engine/render/core/dynamic_resolution.cc @@ -26,8 +26,8 @@ bool DynamicResolution::Update(f32 gpu_ms) { if (++over_ < kDownFrames) return false; // Cost is ~quadratic in the per-axis scale: jump to the step predicted to // land just under the target instead of walking down one step per cycle. - f32 fit = scale_ * ::sqrt(target * 0.95f / ema_ms_); - f32 next = ::floor(fit / kStep) * kStep; + f32 fit = scale_ * ::sqrtf(target * 0.95f / ema_ms_); + f32 next = ::floorf(fit / kStep) * kStep; return Apply(rx::Clamp(next, min_scale, scale_ - kStep)); } @@ -47,8 +47,8 @@ bool DynamicResolution::Update(f32 gpu_ms) { } bool DynamicResolution::Apply(f32 next) { - next = ::round(next / kStep) * kStep; // stay on the grid, no float drift - if (::abs(next - scale_) < 1e-4f) { + next = ::roundf(next / kStep) * kStep; // stay on the grid, no float drift + if (::fabsf(next - scale_) < 1e-4f) { over_ = under_ = 0; return false; } diff --git a/engine/render/core/renderer.cc b/engine/render/core/renderer.cc index 9f441a75..37db514f 100644 --- a/engine/render/core/renderer.cc +++ b/engine/render/core/renderer.cc @@ -277,28 +277,28 @@ bool HasUniformScale(base::Span transforms) { for (const Mat4 &transform : transforms) { const f32 *m = transform.m; for (u32 i = 0; i < 16; ++i) - if (!::isfinite(m[i])) + if (!isfinite(m[i])) return false; - if (::abs(m[3]) > 1e-5f || ::abs(m[7]) > 1e-5f || - ::abs(m[11]) > 1e-5f || ::abs(m[15] - 1.0f) > 1e-5f) + if (::fabsf(m[3]) > 1e-5f || ::fabsf(m[7]) > 1e-5f || + ::fabsf(m[11]) > 1e-5f || ::fabsf(m[15] - 1.0f) > 1e-5f) return false; - const f32 sx = ::sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); - const f32 sy = ::sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); - const f32 sz = ::sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); + const f32 sx = ::sqrtf(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + const f32 sy = ::sqrtf(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); + const f32 sz = ::sqrtf(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); const f32 tolerance = rx::Max({sx, sy, sz}) * 1e-4f; - if (sx <= 1e-6f || ::abs(sx - sy) > tolerance || - ::abs(sx - sz) > tolerance) + if (sx <= 1e-6f || ::fabsf(sx - sy) > tolerance || + ::fabsf(sx - sz) > tolerance) return false; const f32 orthogonal_tolerance = sx * sx * 1e-4f; const f32 determinant = m[0] * (m[5] * m[10] - m[6] * m[9]) - m[4] * (m[1] * m[10] - m[2] * m[9]) + m[8] * (m[1] * m[6] - m[2] * m[5]); if (determinant <= 0 || - ::abs(m[0] * m[4] + m[1] * m[5] + m[2] * m[6]) > + ::fabsf(m[0] * m[4] + m[1] * m[5] + m[2] * m[6]) > orthogonal_tolerance || - ::abs(m[0] * m[8] + m[1] * m[9] + m[2] * m[10]) > + ::fabsf(m[0] * m[8] + m[1] * m[9] + m[2] * m[10]) > orthogonal_tolerance || - ::abs(m[4] * m[8] + m[5] * m[9] + m[6] * m[10]) > + ::fabsf(m[4] * m[8] + m[5] * m[9] + m[6] * m[10]) > orthogonal_tolerance) return false; } @@ -307,7 +307,7 @@ bool HasUniformScale(base::Span transforms) { f32 InstanceGroupDistance(const InstanceStore::Group &group, const Vec3 &eye) { const Vec3 delta = eye - group.bounds_center; - return rx::Max(::sqrt(Dot(delta, delta)) - group.bounds_radius, 0.0f) / + return rx::Max(::sqrtf(Dot(delta, delta)) - group.bounds_radius, 0.0f) / group.lod_scale; } @@ -330,7 +330,7 @@ void ExtractFrustumPlanes(const Mat4 &vp, f32 out[5][4]) { }; for (int i = 0; i < 5; ++i) { f32 len = - ::sqrt(p[i][0] * p[i][0] + p[i][1] * p[i][1] + p[i][2] * p[i][2]); + ::sqrtf(p[i][0] * p[i][0] + p[i][1] * p[i][1] + p[i][2] * p[i][2]); if (len < 1e-8f) len = 1.0f; for (int c = 0; c < 4; ++c) @@ -393,7 +393,7 @@ f32 MaskedSubmeshOpacity(const base::Vector &verts, c.position[2] - a.position[2]}; f32 cx = e1[1] * e2[2] - e1[2] * e2[1], cy = e1[2] * e2[0] - e1[0] * e2[2], cz = e1[0] * e2[1] - e1[1] * e2[0]; - f32 area = 0.5f * ::sqrt(cx * cx + cy * cy + cz * cz); + f32 area = 0.5f * ::sqrtf(cx * cx + cy * cy + cz * cz); weighted += static_cast(mean_a) * area; area_sum += area; } @@ -1056,7 +1056,7 @@ bool Renderer::InitializeCommon(const RendererDesc &desc, Window *window, if (const char *sd = SunDir.get()) { Vec3 d{}; if (::sscanf(sd, "%f,%f,%f", &d.x, &d.y, &d.z) == 3) { - f32 len = ::sqrt(d.x * d.x + d.y * d.y + d.z * d.z); + f32 len = ::sqrtf(d.x * d.x + d.y * d.y + d.z * d.z); if (len > 1e-4f) settings_.sun_direction = {d.x / len, d.y / len, d.z / len}; } @@ -2230,7 +2230,7 @@ bool Renderer::UploadMesh(const asset::Mesh &mesh, u64 id_salt) { all_verts, all_indices, submesh, material_system_->material_base_alpha(submesh.material)) : 1.0f; - const f32 s = ::sqrt(rx::Clamp(opacity, 0.02f, 1.0f)); + const f32 s = ::sqrtf(rx::Clamp(opacity, 0.02f, 1.0f)); const u32 base_index = static_cast(approx_indices.size()); for (u32 e = 0; e + 3 <= submesh.index_count; e += 3) { const u32 idx[3] = {all_indices[submesh.index_offset + e], @@ -4077,9 +4077,9 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, Vec3 wc{m[0] * c[0] + m[4] * c[1] + m[8] * c[2] + m[12], m[1] * c[0] + m[5] * c[1] + m[9] * c[2] + m[13], m[2] * c[0] + m[6] * c[1] + m[10] * c[2] + m[14]}; - f32 sx = ::sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); - f32 sy = ::sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); - f32 sz = ::sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); + f32 sx = ::sqrtf(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + f32 sy = ::sqrtf(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); + f32 sz = ::sqrtf(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); f32 radius = mesh->bounds_radius * rx::Max(sx, rx::Max(sy, sz)); if (radius > 0.0f && SphereOutsideFrustum(touch_planes, wc, radius)) continue; @@ -4112,7 +4112,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, // FSR-style phase count grows with the scale factor squared. f32 scale = static_cast(output_width_) / static_cast(render_width_); - sample_count = static_cast(::ceil(8.0f * scale * scale)); + sample_count = static_cast(::ceilf(8.0f * scale * scale)); } JitterSequence::Sample(frame_index_, sample_count, &jitter_x, &jitter_y); } @@ -4341,7 +4341,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, if (settings_.skin_dynamics) { constexpr f32 kTwoPi = 6.28318530718f; f32 phase = static_cast(time_seconds_) * settings_.skin_heart_rate * kTwoPi; - globals.skin_dynamics[0] = ::fmod(phase, kTwoPi); + globals.skin_dynamics[0] = ::fmodf(phase, kTwoPi); globals.skin_dynamics[1] = rx::Clamp(settings_.skin_perfusion, -0.5f, 0.5f); globals.skin_dynamics[2] = settings_.skin_pulse_amplitude; globals.skin_dynamics[3] = settings_.skin_tension_gain; @@ -4358,9 +4358,9 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, { // Froxel slicing: exponential view-z between the near plane and 500 m. constexpr f32 kNear = 0.1f, kFar = 500.0f; - f32 scale = static_cast(kClusterSlices) / ::log2(kFar / kNear); + f32 scale = static_cast(kClusterSlices) / ::log2f(kFar / kNear); globals.cluster_params[0] = scale; - globals.cluster_params[1] = -::log2(kNear) * scale; + globals.cluster_params[1] = -::log2f(kNear) * scale; globals.cluster_params[2] = static_cast(render_width_) / static_cast(kClusterTilesX); globals.cluster_params[3] = @@ -4646,7 +4646,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, const f32 wy = mm[1] * c.x + mm[5] * c.y + mm[9] * c.z + mm[13]; const f32 wz = mm[2] * c.x + mm[6] * c.y + mm[10] * c.z + mm[14]; const f32 dx = wx - eye.x, dy = wy - eye.y, dz = wz - eye.z; - return ::sqrt(dx * dx + dy * dy + dz * dz); + return ::sqrtf(dx * dx + dy * dy + dz * dz); }; // Resolves the RT LOD for one instance: LOD0 inside the near radius (raster // and rays agree there, avoiding the self-intersection disparity the AC @@ -4988,7 +4988,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, rf.sun_intensity = settings_.sun_intensity; rf.sun_color = settings_.sun_color; rf.sun_radius = settings_.sun_angular_radius; - rf.pixel_spread = 2.0f * ::tan(view.camera.fov_y * 0.5f) / + rf.pixel_spread = 2.0f * ::tanf(view.camera.fov_y * 0.5f) / static_cast(render_height_); rf.spp = settings_.path_trace_spp; rf.frame_index = frame_index_; @@ -5050,7 +5050,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, denoised_path = true; pt.spp = settings_.path_trace_spp; // Ray-cone spread for texture lod: vertical fov radians per pixel. - pt.pixel_spread = 2.0f * ::tan(view.camera.fov_y * 0.5f) / + pt.pixel_spread = 2.0f * ::tanf(view.camera.fov_y * 0.5f) / static_cast(render_height_); PathTracer::GbufferTargets t; auto guide = [&](const char *name, Format format) { @@ -5207,10 +5207,10 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, mesh->bounds_center[1], mesh->bounds_center[2]}); const f32 *m = item.transform.m; - f32 sx = ::sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); - f32 sy = ::sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); + f32 sx = ::sqrtf(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + f32 sy = ::sqrtf(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); f32 sz = - ::sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); + ::sqrtf(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); f32 wr = mesh->bounds_radius * rx::Max(sx, rx::Max(sy, sz)); Vec3 d{wc.x - face.light_pos.x, wc.y - face.light_pos.y, @@ -5358,7 +5358,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, mesh->bounds_center[1], mesh->bounds_center[2]}); Vec3 d = view.camera.eye - wc; - lod = SelectLod(*mesh, ::sqrt(d.x * d.x + d.y * d.y + d.z * d.z)); + lod = SelectLod(*mesh, ::sqrtf(d.x * d.x + d.y * d.y + d.z * d.z)); } const base::Vector &lod_subs = lod == 0 ? mesh->submeshes : mesh->lods[lod - 1].submeshes; @@ -5422,7 +5422,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, // width clamp. m[5] is negative under the reversed-Z Y-flip projection. grass_frame.pixel_scale = proj.m[5] != 0.0f - ? 2.0f / (::fabs(proj.m[5]) * static_cast(render_height_)) + ? 2.0f / (::fabsf(proj.m[5]) * static_cast(render_height_)) : 0.0f; grass_active = procedural_grass_.Prepare( *view.grass_domain, @@ -5481,15 +5481,15 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, // Cpu frustum skip: a conservative world radius (bounds scaled by the // largest transform axis) lets off-screen instances cost no dispatch. const f32 *m = item.transform.m; - f32 sx = ::sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); - f32 sy = ::sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); - f32 sz = ::sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); + f32 sx = ::sqrtf(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + f32 sy = ::sqrtf(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); + f32 sz = ::sqrtf(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); f32 ms_radius = mesh->bounds_radius * rx::Max(sx, rx::Max(sy, sz)); if (ms_radius > 0.0f && SphereOutsideFrustum(ms_planes, ms_wc, ms_radius)) continue; u32 ms_lod = - SelectLod(*mesh, ::sqrt(ms_d.x * ms_d.x + ms_d.y * ms_d.y + + SelectLod(*mesh, ::sqrtf(ms_d.x * ms_d.x + ms_d.y * ms_d.y + ms_d.z * ms_d.z)); const base::Vector &ms_subs = ms_lod == 0 ? mesh->submeshes : mesh->lods[ms_lod - 1].submeshes; @@ -5972,9 +5972,9 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, p.top = 4200.0f; // Same drift velocity as clouds.cs, so the shadows track the // deck. - p.wind = ::cos(settings_.weather.wind_yaw) * + p.wind = ::cosf(settings_.weather.wind_yaw) * settings_.weather.wind_speed; - p.wind_z = ::sin(settings_.weather.wind_yaw) * + p.wind_z = ::sinf(settings_.weather.wind_yaw) * settings_.weather.wind_speed; p.strength = 0.75f; ctx.cmd->BindPipeline(cloud_shadow_pipeline_); @@ -6153,10 +6153,10 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, p.near_plane = 0.1f; constexpr f32 kNear = 0.1f, kFar = 500.0f; p.slice_scale = - static_cast(kClusterSlices) / ::log2(kFar / kNear); - p.slice_bias = -::log2(kNear) * p.slice_scale; + static_cast(kClusterSlices) / ::log2f(kFar / kNear); + p.slice_bias = -::log2f(kNear) * p.slice_scale; p.light_count = light_count; - p.tan_half_fov_y = ::tan(view.camera.fov_y * 0.5f); + p.tan_half_fov_y = ::tanf(view.camera.fov_y * 0.5f); p.aspect = static_cast(render_width_) / static_cast(render_height_); p.decal_count = decal_count; @@ -6593,7 +6593,7 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, // Pixels per meter at view depth 1. The projection bakes the vulkan // y-flip into m[5], so it is negative - take the magnitude. p.proj_scale = - ::abs(proj.m[5]) * 0.5f * static_cast(render_height_); + ::fabsf(proj.m[5]) * 0.5f * static_cast(render_height_); p.max_radius = 24.0f; p.strength = ::getenv("RX_SSS_DEBUG") ? -1.0f : 1.0f; // <0 = mask debug view @@ -6803,9 +6803,9 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, cf.sun_color = settings_.sun_color; cf.coverage = settings_.cloud_coverage; cf.wind_x = - ::cos(settings_.weather.wind_yaw) * settings_.weather.wind_speed; + ::cosf(settings_.weather.wind_yaw) * settings_.weather.wind_speed; cf.wind_z = - ::sin(settings_.weather.wind_yaw) * settings_.weather.wind_speed; + ::sinf(settings_.weather.wind_yaw) * settings_.weather.wind_speed; lit = clouds_.AddToGraph(graph_, lit, depth_export, {render_width_, render_height_}, cf); } @@ -6979,9 +6979,9 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, vf.snow = settings_.weather.snow; // Wind yaw is the direction the wind blows toward; decompose to xz. vf.wind[0] = - ::cos(settings_.weather.wind_yaw) * settings_.weather.wind_speed; + ::cosf(settings_.weather.wind_yaw) * settings_.weather.wind_speed; vf.wind[1] = - ::sin(settings_.weather.wind_yaw) * settings_.weather.wind_speed; + ::sinf(settings_.weather.wind_yaw) * settings_.weather.wind_speed; vf.gustiness = settings_.weather.gustiness; vf.lightning = settings_.weather.lightning; vf.jitter[0] = globals.jitter[0]; @@ -7138,9 +7138,9 @@ void Renderer::BuildFrameGraph(FrameResources &frame, u32 image_index, // Screen pixels per world unit at distance 1 (|proj.m5| carries the // vulkan y-flip, hence the fabs). vf.proj_scale = - ::fabs(proj.m[5]) * static_cast(render_height_) * 0.5f; - vf.proj_m00 = ::fabs(proj.m[0]); - vf.proj_m11 = ::fabs(proj.m[5]); + ::fabsf(proj.m[5]) * static_cast(render_height_) * 0.5f; + vf.proj_m00 = ::fabsf(proj.m[0]); + vf.proj_m11 = ::fabsf(proj.m[5]); vf.error_pixels = VgeoError.get() > 0.0f ? VgeoError.get() : 1.0f; // Reversed-z infinite far: proj m[14] is the near plane distance. vf.near_plane = proj.m[14] > 0.0f ? proj.m[14] : 0.1f; diff --git a/engine/render/core/settings_ini.cc b/engine/render/core/settings_ini.cc index fe0637d8..1db73330 100644 --- a/engine/render/core/settings_ini.cc +++ b/engine/render/core/settings_ini.cc @@ -274,7 +274,7 @@ int ApplyIni(base::StringRef text, RenderSettings& s) { }; auto as_f32 = [](const base::String& v, f32& out) { f32 parsed = 0.0f; - if (!ParseWholeF32(v, &parsed) || !::isfinite(parsed)) return false; + if (!ParseWholeF32(v, &parsed) || !isfinite(parsed)) return false; out = parsed; return true; }; diff --git a/engine/render/geometry/gaussian.cc b/engine/render/geometry/gaussian.cc index 9a3cf8c7..0417a9da 100644 --- a/engine/render/geometry/gaussian.cc +++ b/engine/render/geometry/gaussian.cc @@ -36,7 +36,7 @@ u32 PlyTypeSize(const base::String& t) { return 0; } -f32 Sigmoid(f32 x) { return 1.0f / (1.0f + ::exp(-x)); } +f32 Sigmoid(f32 x) { return 1.0f / (1.0f + ::expf(-x)); } } // namespace @@ -273,9 +273,9 @@ bool LoadGaussianPly(const base::String& path, base::Vector* o g.position[2] = at(iz); if (iop >= 0) g.opacity = Sigmoid(at(iop)); if (is0 >= 0 && is1 >= 0 && is2 >= 0) { - g.scale[0] = ::exp(at(is0)); - g.scale[1] = ::exp(at(is1)); - g.scale[2] = ::exp(at(is2)); + g.scale[0] = ::expf(at(is0)); + g.scale[1] = ::expf(at(is1)); + g.scale[2] = ::expf(at(is2)); } if (if0 >= 0 && if1 >= 0 && if2 >= 0) { g.color[0] = rx::Clamp(0.5f + kC0 * at(if0), 0.0f, 1.0f); @@ -284,7 +284,7 @@ bool LoadGaussianPly(const base::String& path, base::Vector* o } if (ir0 >= 0 && ir1 >= 0 && ir2 >= 0 && ir3 >= 0) { f32 w = at(ir0), x = at(ir1), y = at(ir2), z = at(ir3); // inria stores wxyz - f32 len = ::sqrt(w * w + x * x + y * y + z * z); + f32 len = ::sqrtf(w * w + x * x + y * y + z * z); if (len < 1e-8f) len = 1.0f; g.rotation[0] = x / len; g.rotation[1] = y / len; diff --git a/engine/render/geometry/hair_groom.cc b/engine/render/geometry/hair_groom.cc index 3c6bf557..cc657465 100644 --- a/engine/render/geometry/hair_groom.cc +++ b/engine/render/geometry/hair_groom.cc @@ -119,7 +119,7 @@ bool DecodeDiffuse(const asset::Texture& t, u32 target_max, DecodedTex* out) { out->rgba.resize(static_cast(w) * h * 4); auto to_lin = [&](u8 c) { f32 x = c / 255.0f; - return t.is_srgb ? ::pow(x, 2.2f) : x; + return t.is_srgb ? ::powf(x, 2.2f) : x; }; if (t.format == asset::TextureFormat::kRgba8) { if (offset + static_cast(w) * h * 4 > t.data.size()) return false; @@ -187,9 +187,9 @@ struct Texel { // Bilinear tap, returns linear rgb + coverage alpha. Texel SampleTex(const DecodedTex& t, f32 u, f32 v) { - auto wrap = [](f32 x) { return x - ::floor(x); }; + auto wrap = [](f32 x) { return x - ::floorf(x); }; f32 fx = wrap(u) * t.w - 0.5f, fy = wrap(v) * t.h - 0.5f; - i32 x0 = static_cast(::floor(fx)), y0 = static_cast(::floor(fy)); + i32 x0 = static_cast(::floorf(fx)), y0 = static_cast(::floorf(fy)); f32 tx = fx - x0, ty = fy - y0; auto at = [&](i32 x, i32 y) { x = ((x % (i32)t.w) + t.w) % t.w; @@ -254,7 +254,7 @@ Vec3 ChainStep(const Comp& comp, const base::Vector& verts, f32 target_a, f32 dc = AcrossOf(comp, gv) - c; Vec3 dw = gv.p - prev; f32 e = da * da * inv_ha + dc * dc * inv_hc + Dot(dw, dw) * inv_hw; - f32 w = ::exp(-e); + f32 w = ::expf(-e); acc = acc + gv.p * w; wsum += w; } @@ -272,7 +272,7 @@ Vec3 RootAt(const Comp& comp, const base::Vector& verts, f32 c) { f32 wsum = 0; for (u32 vi : comp.root_verts) { f32 dc = AcrossOf(comp, verts[vi]) - c; - f32 w = ::exp(-dc * dc * inv); + f32 w = ::expf(-dc * dc * inv); acc = acc + verts[vi].p * w; wsum += w; } @@ -360,7 +360,7 @@ bool BuildHairGroom(const asset::Mesh& mesh, const GroomParams& params, GroomDat } f32 det = suu * svv - suv * suv; Vec3 dpu, dpv; // world metres per unit u / v - if (::fabs(det) > 1e-12f) { + if (::fabsf(det) > 1e-12f) { dpu = (sup * svv - svp * suv) * (1.0f / det); dpv = (svp * suu - sup * suv) * (1.0f / det); } else { @@ -412,9 +412,9 @@ bool BuildHairGroom(const asset::Mesh& mesh, const GroomParams& params, GroomDat else { comp.a_root = amax; comp.a_tip = amin; } // Root-edge verts: the scalp-side band. Strands are seeded only here so they // start at the scalp and trace the full card length, never mid-card. - f32 root_band = 0.14f * ::fabs(comp.a_tip - comp.a_root) + 1e-6f; + f32 root_band = 0.14f * ::fabsf(comp.a_tip - comp.a_root) + 1e-6f; for (u32 vi : comp.verts) { - if (::fabs(AlongOf(comp, verts[vi]) - comp.a_root) <= root_band) { + if (::fabsf(AlongOf(comp, verts[vi]) - comp.a_root) <= root_band) { comp.root_verts.push_back(vi); } } @@ -490,14 +490,14 @@ bool BuildHairGroom(const asset::Mesh& mesh, const GroomParams& params, GroomDat } Vec3 color = (have_tex && a_acc > 1e-3f) ? col_acc * (1.0f / a_acc) : Vec3{1, 1, 1}; - f32 ha = 0.8f * ::fabs(comp.a_tip - comp.a_root) / (P - 1) + 1e-4f; - f32 hc = 0.06f * ::fabs(comp.c_max - comp.c_min) + 1e-4f; + f32 ha = 0.8f * ::fabsf(comp.a_tip - comp.a_root) / (P - 1) + 1e-4f; + f32 hc = 0.06f * ::fabsf(comp.c_max - comp.c_min) + 1e-4f; // Per-strand flyaway: a fixed random bend that grows toward the tip, applied // to the stored point only (not the chain anchor) so neighbouring strands from // the same card fan apart into individual locks instead of a flat card-slab. f32 fang = randf() * 6.2831853f; f32 fh = randf(); - Vec3 fdir{::cos(fang), -0.15f - 0.3f * fh, ::sin(fang)}; // outward + slight droop + Vec3 fdir{::cosf(fang), -0.15f - 0.3f * fh, ::sinf(fang)}; // outward + slight droop // A few strands only (fh near 1) get a real flyaway; most stay tidy so the // silhouette reads as groomed hair, not frizz. Curl already separates strands. f32 famp = rx::Clamp(comp.hw * 0.3f, 0.002f, 0.008f) * (fh > 0.7f ? fh : 0.15f * fh) * @@ -507,9 +507,9 @@ bool BuildHairGroom(const asset::Mesh& mesh, const GroomParams& params, GroomDat const f32 kLockWorld = 0.010f; f32 lock_c = comp.world_per_c > 1e-6f ? kLockWorld / comp.world_per_c : (comp.c_max - comp.c_min); lock_c = rx::Min(rx::Max(lock_c, 1e-6f), comp.c_max - comp.c_min + 1e-6f); - f32 lock_center = comp.c_min + (::floor((c_seed - comp.c_min) / lock_c) + 0.5f) * lock_c; + f32 lock_center = comp.c_min + (::floorf((c_seed - comp.c_min) / lock_c) + 0.5f) * lock_c; f32 an = rx::Clamp((c_seed - lock_center) / (0.5f * lock_c), -1.0f, 1.0f); - f32 profile = ::sqrt(rx::Max(0.0f, 1.0f - an * an)); + f32 profile = ::sqrtf(rx::Max(0.0f, 1.0f - an * an)); f32 bulge = 0.5f * lock_c * comp.world_per_c * (profile * 0.9f + (randf() - 0.4f) * 0.4f); // Per-strand curl: a two-frequency wave (in-plane + out-of-plane) unique to // each strand, growing toward the tip, so coplanar strands of one flat card @@ -542,10 +542,10 @@ bool BuildHairGroom(const asset::Mesh& mesh, const GroomParams& params, GroomDat // tip; the very first point stays pinned on the scalp (k==0 above). f32 wv = camp * (0.2f + 0.8f * tt); Vec3 curl = - comp.normal * ((::sin(cfreq * tt + cph1) + 0.4f * ::sin(cfreq * 2.7f * tt + cph3)) * wv) + + comp.normal * ((::sinf(cfreq * tt + cph1) + 0.4f * ::sinf(cfreq * 2.7f * tt + cph3)) * wv) + comp.across_dir * - ((::sin(cfreq * 0.7f * tt + cph2) + 0.4f * ::sin(cfreq * 2.3f * tt + cph4)) * wv * 0.6f); - pos = chain_prev + comp.normal * (bulge * ramp) + curl + fdir * (famp * ::pow(tt, 1.4f)); + ((::sinf(cfreq * 0.7f * tt + cph2) + 0.4f * ::sinf(cfreq * 2.3f * tt + cph4)) * wv * 0.6f); + pos = chain_prev + comp.normal * (bulge * ramp) + curl + fdir * (famp * ::powf(tt, 1.4f)); } pts[(static_cast(emitted) * P + k) * 3 + 0] = pos.x; pts[(static_cast(emitted) * P + k) * 3 + 1] = pos.y; @@ -580,7 +580,7 @@ bool BuildHairGroom(const asset::Mesh& mesh, const GroomParams& params, GroomDat f32 head_r = 0; for (u32 i = 0; i < emitted; ++i) { Vec3 rp{roots[i * 3], roots[i * 3 + 1], roots[i * 3 + 2]}; - f32 horiz = ::sqrt((rp.x - scalp.x) * (rp.x - scalp.x) + (rp.z - scalp.z) * (rp.z - scalp.z)); + f32 horiz = ::sqrtf((rp.x - scalp.x) * (rp.x - scalp.x) + (rp.z - scalp.z) * (rp.z - scalp.z)); head_r = rx::Max(head_r, horiz); } if (params.recenter) { @@ -631,9 +631,9 @@ bool BuildTestGroom(TestGroomStyle style, u32 guide_count, u32 seed, GroomData* auto cap_normal = [&](u32 s, u32 count) { f32 t = (static_cast(s) + 0.5f) / count; f32 y = 0.35f + 0.6f * t; - f32 r = ::sqrt(rx::Max(0.0f, 1.0f - y * y)); + f32 r = ::sqrtf(rx::Max(0.0f, 1.0f - y * y)); f32 a = 2.399963f * static_cast(s); - return Vec3{r * ::cos(a), y, r * ::sin(a)}; + return Vec3{r * ::cosf(a), y, r * ::sinf(a)}; }; out->points.reserve(static_cast(guide_count) * P * 3); @@ -655,7 +655,7 @@ bool BuildTestGroom(TestGroomStyle style, u32 guide_count, u32 seed, GroomData* for (u32 k = 0; k < P; ++k) { if (k > 0) { f32 t = static_cast(k) / (P - 1); - Vec3 dir = Normalize(Lerp(nrm, {0, -1, 0}, ::pow(t, 0.7f))); + Vec3 dir = Normalize(Lerp(nrm, {0, -1, 0}, ::powf(t, 0.7f))); p = p + dir * segment; length_sum += Length(p - prev); prev = p; @@ -685,8 +685,8 @@ bool BuildTestGroom(TestGroomStyle style, u32 guide_count, u32 seed, GroomData* for (u32 k = 0; k < P; ++k) { f32 t = static_cast(k) / (P - 1); f32 w = 18.849556f * t + phase; // three full crossings down the braid - centers[b * P + k] = nape + Vec3{amp * ::sin(w), -len * t, - -0.02f * t - 0.5f * amp * ::cos(2.0f * w)}; + centers[b * P + k] = nape + Vec3{amp * ::sinf(w), -len * t, + -0.02f * t - 0.5f * amp * ::cosf(2.0f * w)}; } } for (u32 b = 0; b < 3; ++b) { @@ -694,8 +694,8 @@ bool BuildTestGroom(TestGroomStyle style, u32 guide_count, u32 seed, GroomData* u32 s = b * per_bundle + i; // Per-strand offset within the bundle, tapering to the tip. f32 ang = randf() * 6.2831853f; - f32 rad = 0.004f * ::sqrt(randf()); - Vec3 off{rad * ::cos(ang), 0, rad * ::sin(ang)}; + f32 rad = 0.004f * ::sqrtf(randf()); + Vec3 off{rad * ::cosf(ang), 0, rad * ::sinf(ang)}; Vec3 root = Normalize(centers[b * P] + off * 2.0f) * head_r; push_root(root); Vec3 prev{}; @@ -752,8 +752,8 @@ bool BuildTestGroom(TestGroomStyle style, u32 guide_count, u32 seed, GroomData* Vec3 root = nrm * head_r; // Small spread at the tie so the tail keeps volume. f32 ang = randf() * 6.2831853f; - f32 rad = 0.006f * ::sqrt(randf()); - Vec3 tie_off{rad * ::cos(ang), 0, rad * ::sin(ang)}; + f32 rad = 0.006f * ::sqrtf(randf()); + Vec3 tie_off{rad * ::cosf(ang), 0, rad * ::sinf(ang)}; f32 tail_len = 0.30f + 0.05f * randf(); push_root(root); Vec3 prev{}; diff --git a/engine/render/geometry/hair_strands.cc b/engine/render/geometry/hair_strands.cc index 7ef2f211..7b1aaf0e 100644 --- a/engine/render/geometry/hair_strands.cc +++ b/engine/render/geometry/hair_strands.cc @@ -451,9 +451,9 @@ void HairStrands::SeedCap(Device& device, const Vec3& head_center, f32 head_radi for (u32 s = 0; s < strand_count; ++s) { f32 t = (static_cast(s) + 0.5f) / strand_count; f32 y = 0.45f + 0.55f * t; - f32 r = ::sqrt(rx::Max(0.0f, 1.0f - y * y)); + f32 r = ::sqrtf(rx::Max(0.0f, 1.0f - y * y)); f32 a = golden * static_cast(s); - Vec3 nrm{r * ::cos(a), y, r * ::sin(a)}; + Vec3 nrm{r * ::cosf(a), y, r * ::sinf(a)}; Vec3 root = nrm * head_radius; // local: scalp at origin for (u32 i = 0; i < kPointsPerStrand; ++i) { Vec3 p = root + nrm * (segment * static_cast(i)); @@ -526,13 +526,13 @@ void HairStrands::AddTransmittanceToGraph(RenderGraph& graph, const Frame& frame const Vec3 centre{(lo.x + hi.x) * 0.5f, (lo.y + hi.y) * 0.5f, (lo.z + hi.z) * 0.5f}; const Vec3 extent_v{hi.x - lo.x, hi.y - lo.y, hi.z - lo.z}; const f32 radius = - 0.5f * ::sqrt(extent_v.x * extent_v.x + extent_v.y * extent_v.y + + 0.5f * ::sqrtf(extent_v.x * extent_v.x + extent_v.y * extent_v.y + extent_v.z * extent_v.z) + 0.02f; const Vec3 dir = Normalize(frame.sun_direction); const Vec3 eye{centre.x - dir.x * (radius * 2.0f), centre.y - dir.y * (radius * 2.0f), centre.z - dir.z * (radius * 2.0f)}; - const Vec3 up_ref = ::abs(dir.y) > 0.99f ? Vec3{0, 0, 1} : Vec3{0, 1, 0}; + const Vec3 up_ref = ::fabsf(dir.y) > 0.99f ? Vec3{0, 0, 1} : Vec3{0, 1, 0}; const f32 depth_range = radius * 4.0f; const Mat4 light_vp = Orthographic(-radius, radius, -radius, radius, 0.0f, depth_range) * LookAt(eye, centre, up_ref); diff --git a/engine/render/geometry/imposters.cc b/engine/render/geometry/imposters.cc index 40e52efd..5c4dfd38 100644 --- a/engine/render/geometry/imposters.cc +++ b/engine/render/geometry/imposters.cc @@ -50,7 +50,7 @@ Vec3 HemiOctDecode(f32 u, f32 v) { Vec3 d; d.x = (ex - ey) * 0.5f; d.z = (ex + ey) * 0.5f; - d.y = 1.0f - ::abs(d.x) - ::abs(d.z); + d.y = 1.0f - ::fabsf(d.x) - ::fabsf(d.z); return Normalize(d); } @@ -163,7 +163,7 @@ u32 ImposterPass::Bake(Device& device, const asset::Mesh& mesh, } Vec3 center = (lo + hi) * 0.5f; Vec3 ext = (hi - lo) * 0.5f; - const f32 radius = ::sqrt(ext.x * ext.x + ext.y * ext.y + ext.z * ext.z); + const f32 radius = ::sqrtf(ext.x * ext.x + ext.y * ext.y + ext.z * ext.z); if (first) { albedo_atlas_ = device.CreateImage2D( @@ -219,7 +219,7 @@ u32 ImposterPass::Bake(Device& device, const asset::Mesh& mesh, for (u32 j = 0; j < kGrid; ++j) { for (u32 i = 0; i < kGrid; ++i) { Vec3 dir = HemiOctDecode((i + 0.5f) / kGrid, (j + 0.5f) / kGrid); - Vec3 up = ::abs(dir.y) > 0.98f ? Vec3{0, 0, 1} : Vec3{0, 1, 0}; + Vec3 up = ::fabsf(dir.y) > 0.98f ? Vec3{0, 0, 1} : Vec3{0, 1, 0}; Mat4 view = LookAt(center + dir * (radius * 2.0f), center, up); Mat4 proj = Orthographic(-radius, radius, -radius, radius, 0.1f, radius * 4.0f); const f32 x = static_cast(tile_x + i * kCell); diff --git a/engine/render/geometry/instance_store.cc b/engine/render/geometry/instance_store.cc index 7dd6de2c..41b01c82 100644 --- a/engine/render/geometry/instance_store.cc +++ b/engine/render/geometry/instance_store.cc @@ -14,9 +14,9 @@ namespace { f32 MaxScale(const Mat4 &transform) { const f32 *m = transform.m; - const f32 sx = ::sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); - const f32 sy = ::sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); - const f32 sz = ::sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); + const f32 sx = ::sqrtf(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + const f32 sy = ::sqrtf(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); + const f32 sz = ::sqrtf(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); return rx::Max(sx, rx::Max(sy, sz)); } @@ -55,7 +55,7 @@ void InstanceStore::ComputeBounds(Group &group, const f32 mesh_center[3], f32 me const Vec3 center = TransformPoint(transform, {mesh_center[0], mesh_center[1], mesh_center[2]}); const Vec3 delta = center - group.bounds_center; group.bounds_radius = rx::Max( - group.bounds_radius, ::sqrt(Dot(delta, delta)) + mesh_radius * MaxScale(transform)); + group.bounds_radius, ::sqrtf(Dot(delta, delta)) + mesh_radius * MaxScale(transform)); } } diff --git a/engine/render/geometry/ocean_fft.cc b/engine/render/geometry/ocean_fft.cc index a621f541..e9696652 100644 --- a/engine/render/geometry/ocean_fft.cc +++ b/engine/render/geometry/ocean_fft.cc @@ -125,13 +125,13 @@ f32 Phillips(f32 kx, f32 kz, f32 wind_speed, f32 wind_x, f32 wind_z) { if (k2 < 1e-8f) return 0.0f; const f32 g = 9.81f; f32 l = wind_speed * wind_speed / g; // largest wave from this wind - f32 k = ::sqrt(k2); + f32 k = ::sqrtf(k2); f32 kdw = (kx * wind_x + kz * wind_z) / k; constexpr f32 kAmplitude = 0.6f; - f32 p = kAmplitude * ::exp(-1.0f / (k2 * l * l)) / (k2 * k2) * (kdw * kdw); + f32 p = kAmplitude * ::expf(-1.0f / (k2 * l * l)) / (k2 * k2) * (kdw * kdw); if (kdw < 0.0f) p *= 0.25f; // damp waves running against the wind const f32 small_cut = 0.35f; // meters - p *= ::exp(-k2 * small_cut * small_cut); + p *= ::expf(-k2 * small_cut * small_cut); return p; } @@ -201,8 +201,8 @@ bool OceanFft::Initialize(Device& device) { f32 m = static_cast(y) - kSize * 0.5f; f32 kx = 2.0f * 3.14159265f * n / kPatchSize; f32 kz = 2.0f * 3.14159265f * m / kPatchSize; - f32 ph = ::sqrt(Phillips(kx, kz, wind_speed, wind_x, wind_z)); - f32 phm = ::sqrt(Phillips(-kx, -kz, wind_speed, wind_x, wind_z)); + f32 ph = ::sqrtf(Phillips(kx, kz, wind_speed, wind_x, wind_z)); + f32 phm = ::sqrtf(Phillips(-kx, -kz, wind_speed, wind_x, wind_z)); size_t o = (static_cast(y) * kSize + x) * 4; h0[o + 0] = gauss(rng) * inv_sqrt2 * ph; h0[o + 1] = gauss(rng) * inv_sqrt2 * ph; diff --git a/engine/render/geometry/particle_emitters.cc b/engine/render/geometry/particle_emitters.cc index 67dd7981..f7c4fc0e 100644 --- a/engine/render/geometry/particle_emitters.cc +++ b/engine/render/geometry/particle_emitters.cc @@ -32,14 +32,14 @@ f32 SafeLerpT(f32 t, f32 a, f32 b) { return b - a > 1e-5f ? rx::Clamp((t - a) / // Random direction in a cone of half angle `spread` around `axis`. Vec3 ConeDirection(const Vec3& axis, f32 spread, u32& rng) { if (spread <= 1e-3f) return axis; - Vec3 ref = ::abs(axis.y) < 0.95f ? Vec3{0, 1, 0} : Vec3{1, 0, 0}; + Vec3 ref = ::fabsf(axis.y) < 0.95f ? Vec3{0, 1, 0} : Vec3{1, 0, 0}; Vec3 t = Normalize(Cross(ref, axis)); Vec3 b = Cross(axis, t); f32 angle = spread * RandUnit(rng); f32 azimuth = 6.2831853f * RandUnit(rng); - f32 s = ::sin(angle); - return Normalize(axis * ::cos(angle) + t * (s * ::cos(azimuth)) + - b * (s * ::sin(azimuth))); + f32 s = ::sinf(angle); + return Normalize(axis * ::cosf(angle) + t * (s * ::cosf(azimuth)) + + b * (s * ::sinf(azimuth))); } } // namespace @@ -78,11 +78,11 @@ void ParticleEmitterSim::AddInstance(u64 mesh_key, Vec3 ex = TransformDir(transform, {emitter.extent[0], 0, 0}); Vec3 ey = TransformDir(transform, {0, emitter.extent[1], 0}); Vec3 ez = TransformDir(transform, {0, 0, emitter.extent[2]}); - fresh.extent = {::abs(ex.x) + ::abs(ey.x) + ::abs(ez.x), - ::abs(ex.y) + ::abs(ey.y) + ::abs(ez.y), - ::abs(ex.z) + ::abs(ey.z) + ::abs(ez.z)}; + fresh.extent = {::fabsf(ex.x) + ::fabsf(ey.x) + ::fabsf(ez.x), + ::fabsf(ex.y) + ::fabsf(ey.y) + ::fabsf(ez.y), + ::fabsf(ex.z) + ::fabsf(ey.z) + ::fabsf(ez.z)}; // Uniform scale of the instance transform, for the scalar quantities. - f32 scale = ::sqrt(LengthSq(TransformDir(transform, {1, 0, 0}))); + f32 scale = ::sqrtf(LengthSq(TransformDir(transform, {1, 0, 0}))); fresh.spread = emitter.spread; fresh.speed_variation = emitter.speed_variation * scale; fresh.rate = emitter.rate; @@ -128,7 +128,7 @@ void ParticleEmitterSim::Step(Pool& pool) { } pool.spawn_accumulator = rx::Min(pool.spawn_accumulator + pool.rate * dt_, 8.0f); - f32 speed = ::sqrt(LengthSq(pool.velocity)); + f32 speed = ::sqrtf(LengthSq(pool.velocity)); Vec3 axis = speed > 1e-4f ? pool.velocity * (1.0f / speed) : Vec3{0, 1, 0}; while (pool.spawn_accumulator >= 1.0f && pool.particles.size() < pool.max_particles) { pool.spawn_accumulator -= 1.0f; diff --git a/engine/render/geometry/procedural_grass.cc b/engine/render/geometry/procedural_grass.cc index e966406c..54adf2b5 100644 --- a/engine/render/geometry/procedural_grass.cc +++ b/engine/render/geometry/procedural_grass.cc @@ -110,7 +110,7 @@ bool BuildCandidateRing(const Vec3& camera, bool AllFinite(const f32* values, u32 count) { for (u32 i = 0; i < count; ++i) { - if (!::isfinite(values[i])) + if (!isfinite(values[i])) return false; } return true; @@ -433,13 +433,13 @@ bool ProceduralGrass::Prepare(const GrassDomain& domain, const bool valid_field = domain.samples && domain.sample_width >= 2 && domain.sample_height >= 2 && domain.sample_width <= kMaxFieldDimension && - domain.sample_height <= kMaxFieldDimension && ::isfinite(domain.origin_x) && - ::isfinite(domain.origin_z) && ::isfinite(domain.extent_x) && - ::isfinite(domain.extent_z) && domain.extent_x > 0.0f && domain.extent_z > 0.0f; + domain.sample_height <= kMaxFieldDimension && isfinite(domain.origin_x) && + isfinite(domain.origin_z) && isfinite(domain.extent_x) && + isfinite(domain.extent_z) && domain.extent_x > 0.0f && domain.extent_z > 0.0f; if (type_count == 0 || !domain.types || (!valid_field && surface_count == 0)) return false; - if (!::isfinite(frame.camera_pos.x) || !::isfinite(frame.camera_pos.y) || - !::isfinite(frame.camera_pos.z)) + if (!isfinite(frame.camera_pos.x) || !isfinite(frame.camera_pos.y) || + !isfinite(frame.camera_pos.z)) return false; if (!AllFinite(frame.view_proj.m, 16) || !AllFinite(frame.prev_view_proj.m, 16)) return false; @@ -459,7 +459,7 @@ bool ProceduralGrass::Prepare(const GrassDomain& domain, for (const f32* values : {type.base_color, type.tip_color, type.dimensions, type.shape, type.material}) { for (u32 value = 0; value < 4; ++value) { - if (!::isfinite(values[value])) + if (!isfinite(values[value])) return false; } } @@ -621,8 +621,8 @@ bool ProceduralGrass::Prepare(const GrassDomain& domain, auto* gpu_surfaces = static_cast(slot.surfaces.mapped); for (u32 i = 0; i < surface_count; ++i) { const GrassSurfaceTriangle& src = domain.surfaces[i]; - if (!::isfinite(src.density) || src.density <= 0.0f || - !::isfinite(src.growth) || src.growth <= 0.0f) + if (!isfinite(src.density) || src.density <= 0.0f || + !isfinite(src.growth) || src.growth <= 0.0f) continue; u32 count = GrassSurfaceCandidateCount(src, settings.candidate_spacing); const u32 remaining = max_surface_candidates - surface_candidates; @@ -669,9 +669,9 @@ bool ProceduralGrass::Prepare(const GrassDomain& domain, const f32 bend_extent = settings.stream_radius * 2.0f; const f32 bend_texel = bend_extent / static_cast(kBendResolution); const f32 bend_origin_x = - ::floor((frame.camera_pos.x - bend_extent * 0.5f) / bend_texel) * bend_texel; + ::floorf((frame.camera_pos.x - bend_extent * 0.5f) / bend_texel) * bend_texel; const f32 bend_origin_z = - ::floor((frame.camera_pos.z - bend_extent * 0.5f) / bend_texel) * bend_texel; + ::floorf((frame.camera_pos.z - bend_extent * 0.5f) / bend_texel) * bend_texel; const bool fields_overlap = preserve_bend_history && bend_origin_x < bend_origin_[0] + bend_extent_ && bend_origin_x + bend_extent > bend_origin_[0] && @@ -686,15 +686,15 @@ bool ProceduralGrass::Prepare(const GrassDomain& domain, f32 bend_max_strength = fields_overlap ? bend_max_strength_ : 0.0f; if (settings.bend_recovery_time > 0.0f) { bend_max_strength *= - ::exp2(-recovery_elapsed / settings.bend_recovery_time); + ::exp2f(-recovery_elapsed / settings.bend_recovery_time); } - const f32 bend_height_origin = ::floor(frame.camera_pos.y / 64.0f) * 64.0f; + const f32 bend_height_origin = ::floorf(frame.camera_pos.y / 64.0f) * 64.0f; for (u32 i = 0; i < interaction_count; ++i) { const GrassInteraction& interaction = interactions[i]; if (!AllFinite(interaction.position_radius, 4) || !AllFinite(interaction.direction_strength, 4) || interaction.position_radius[3] <= 0.0f || - ::fabs(interaction.direction_strength[3]) <= 1e-4f) + ::fabsf(interaction.direction_strength[3]) <= 1e-4f) continue; const f32 closest_x = rx::Clamp(interaction.position_radius[0], bend_origin_x, bend_origin_x + bend_extent); @@ -707,10 +707,10 @@ bool ProceduralGrass::Prepare(const GrassDomain& domain, if (dx * dx + dz * dz > effective_radius * effective_radius) continue; const f32 strength = - rx::Min(::fabs(interaction.direction_strength[3]), 2.0f); + rx::Min(::fabsf(interaction.direction_strength[3]), 2.0f); const f32 relative_height = interaction.position_radius[1] - bend_height_origin; const f32 radius = effective_radius; - if (::fabs(relative_height) * strength > 60000.0f || + if (::fabsf(relative_height) * strength > 60000.0f || radius * strength > 60000.0f) continue; bend_max_strength = rx::Max(bend_max_strength, strength); diff --git a/engine/render/geometry/procedural_grass.h b/engine/render/geometry/procedural_grass.h index 00aa1c90..9f5db4c4 100644 --- a/engine/render/geometry/procedural_grass.h +++ b/engine/render/geometry/procedural_grass.h @@ -84,7 +84,7 @@ struct GrassGenerationSettings { inline GrassGenerationSettings SanitizeGrassSettings(GrassGenerationSettings settings) { const GrassGenerationSettings defaults; auto finite_or = [](f32 value, f32 fallback) { - return ::isfinite(value) ? value : fallback; + return isfinite(value) ? value : fallback; }; settings.candidate_spacing = finite_or(settings.candidate_spacing, defaults.candidate_spacing); @@ -144,8 +144,8 @@ inline u32 GrassSurfaceCandidateCount(const GrassSurfaceTriangle& triangle, const Vec3 c{triangle.p2[0], triangle.p2[1], triangle.p2[2]}; const f32 area = 0.5f * Length(Cross(b - a, c - a)); const f32 spacing = rx::Clamp( - ::isfinite(candidate_spacing) ? candidate_spacing : 0.42f, 0.08f, 8.0f); - if (!::isfinite(area) || area <= 1e-6f) + isfinite(candidate_spacing) ? candidate_spacing : 0.42f, 0.08f, 8.0f); + if (!isfinite(area) || area <= 1e-6f) return 0; const f64 candidates = ::ceil(static_cast(area) / (static_cast(spacing) * spacing)); diff --git a/engine/render/geometry/shore_wetting.cc b/engine/render/geometry/shore_wetting.cc index 96474cc0..9e0b14f0 100644 --- a/engine/render/geometry/shore_wetting.cc +++ b/engine/render/geometry/shore_wetting.cc @@ -86,8 +86,8 @@ void ShoreWetting::BeginFrame(const Vec3& camera_eye) { // Snap the origin to the texel grid so the field does not shimmer as the // camera slides; the min corner sits half an extent behind the eye. const f32 texel = kExtent / static_cast(kResolution); - origin_[0] = ::floor((camera_eye.x - kExtent * 0.5f) / texel) * texel; - origin_[1] = ::floor((camera_eye.z - kExtent * 0.5f) / texel) * texel; + origin_[0] = ::floorf((camera_eye.x - kExtent * 0.5f) / texel) * texel; + origin_[1] = ::floorf((camera_eye.z - kExtent * 0.5f) / texel) * texel; if (!have_prev_) { prev_origin_[0] = origin_[0]; prev_origin_[1] = origin_[1]; diff --git a/engine/render/geometry/water_field.cc b/engine/render/geometry/water_field.cc index 4795345d..03025131 100644 --- a/engine/render/geometry/water_field.cc +++ b/engine/render/geometry/water_field.cc @@ -175,8 +175,8 @@ void WaterField::AddToGraph(RenderGraph& graph, const UpdateParams& params, prev_origin[r][0] = origin_[r][0]; prev_origin[r][1] = origin_[r][1]; texel_world[r] = 2.0f * kRingHalfExtent[r] / static_cast(kSize); - origin_[r][0] = ::round(params.camera_pos.x / texel_world[r]) * texel_world[r]; - origin_[r][1] = ::round(params.camera_pos.z / texel_world[r]) * texel_world[r]; + origin_[r][0] = ::roundf(params.camera_pos.x / texel_world[r]) * texel_world[r]; + origin_[r][1] = ::roundf(params.camera_pos.z / texel_world[r]) * texel_world[r]; if (!centered_) { // first frame: no history, resample lands out of bounds prev_origin[r][0] = origin_[r][0] + 1e6f; prev_origin[r][1] = origin_[r][1] + 1e6f; @@ -231,7 +231,7 @@ void WaterField::AddToGraph(RenderGraph& graph, const UpdateParams& params, ctx.cmd->MemoryBarrier(BarrierScope::kComputeWrite, BarrierScope::kComputeRead); ctx.cmd->BindPipeline(pipeline_); - f32 inv = kDriftSpeed / ::sqrt(kDriftDirX * kDriftDirX + kDriftDirZ * kDriftDirZ); + f32 inv = kDriftSpeed / ::sqrtf(kDriftDirX * kDriftDirX + kDriftDirZ * kDriftDirZ); f32 drift_x = kDriftDirX * inv; f32 drift_z = kDriftDirZ * inv; // Depth for slot 4: the real prepass depth when available, else the ring diff --git a/engine/render/gi/ddgi.cc b/engine/render/gi/ddgi.cc index 709241c0..6f027ac5 100644 --- a/engine/render/gi/ddgi.cc +++ b/engine/render/gi/ddgi.cc @@ -60,12 +60,12 @@ void FrameRotation(u32 frame_index, f32 out_rows[12]) { f32 u3 = static_cast(hash(frame_index + 2) & 0xffffff) / 16777215.0f; f32 angle = u1 * 6.2831853f; f32 z = u2 * 2.0f - 1.0f; - f32 r = ::sqrt(rx::Max(0.0f, 1.0f - z * z)); + f32 r = ::sqrtf(rx::Max(0.0f, 1.0f - z * z)); f32 phi = u3 * 6.2831853f; - Vec3 axis{r * ::cos(phi), r * ::sin(phi), z}; + Vec3 axis{r * ::cosf(phi), r * ::sinf(phi), z}; - f32 c = ::cos(angle); - f32 s = ::sin(angle); + f32 c = ::cosf(angle); + f32 s = ::sinf(angle); f32 t = 1.0f - c; f32 rows[12] = { t * axis.x * axis.x + c, t * axis.x * axis.y - s * axis.z, @@ -176,9 +176,9 @@ void DdgiSystem::AddToGraph(RenderGraph& graph, RayTracingContext& raytracing, u // every probe represents, so history resets and re-converges. f32 spacing = settings_.probe_spacing; Vec3 extent{(kProbesX - 1) * spacing, (kProbesY - 1) * spacing, (kProbesZ - 1) * spacing}; - Vec3 origin{::floor((camera.x - extent.x * 0.5f) / spacing) * spacing, - ::floor((camera.y - extent.y * 0.5f) / spacing) * spacing, - ::floor((camera.z - extent.z * 0.5f) / spacing) * spacing}; + Vec3 origin{::floorf((camera.x - extent.x * 0.5f) / spacing) * spacing, + ::floorf((camera.y - extent.y * 0.5f) / spacing) * spacing, + ::floorf((camera.z - extent.z * 0.5f) / spacing) * spacing}; bool snapped = origin.x != origin_.x || origin.y != origin_.y || origin.z != origin_.z; origin_ = origin; bool reset = !history_valid_ || snapped; diff --git a/engine/render/gi/light_grid.cc b/engine/render/gi/light_grid.cc index a6d1ac6d..26e1a9ad 100644 --- a/engine/render/gi/light_grid.cc +++ b/engine/render/gi/light_grid.cc @@ -56,9 +56,9 @@ void LightGrid::AddToGraph(RenderGraph& graph, const GpuBuffer& lights, u32 ligh for (u32 c = 0; c < kCascades; ++c) { f32 extent = kCascade0Extent * static_cast(1u << c); f32 cell_size = extent / static_cast(kCells); - Vec3 origin{::floor((camera.x - extent * 0.5f) / cell_size) * cell_size, - ::floor((camera.y - extent * 0.5f) / cell_size) * cell_size, - ::floor((camera.z - extent * 0.5f) / cell_size) * cell_size}; + Vec3 origin{::floorf((camera.x - extent * 0.5f) / cell_size) * cell_size, + ::floorf((camera.y - extent * 0.5f) / cell_size) * cell_size, + ::floorf((camera.z - extent * 0.5f) / cell_size) * cell_size}; params.cascade[c][0] = origin.x; params.cascade[c][1] = origin.y; params.cascade[c][2] = origin.z; diff --git a/engine/render/gi/local_shadows.cc b/engine/render/gi/local_shadows.cc index c0b66357..ad86b5d8 100644 --- a/engine/render/gi/local_shadows.cc +++ b/engine/render/gi/local_shadows.cc @@ -96,9 +96,9 @@ void LocalShadows::Assign(PointLight* lights, u32 count, const Vec3& camera, u32 if (type == 1) { // spot: one face down the cone, slightly overscanned Vec3 dir = Normalize(Vec3{light.direction_type[0], light.direction_type[1], light.direction_type[2]}); - Vec3 up = ::abs(dir.y) < 0.99f ? Vec3{0, 1, 0} : Vec3{1, 0, 0}; + Vec3 up = ::fabsf(dir.y) < 0.99f ? Vec3{0, 1, 0} : Vec3{1, 0, 0}; view = LookAt(pos, pos + dir, up); - f32 outer = ::acos(rx::Clamp(light.params[1], -1.0f, 1.0f)); + f32 outer = ::acosf(rx::Clamp(light.params[1], -1.0f, 1.0f)); fov = rx::Clamp(2.2f * outer, 0.2f, 2.9f); } else { // point: 95-degree cube faces so the sampling inset stays valid view = LookAt(pos, pos + kFaceDirs[f], kFaceUps[f]); diff --git a/engine/render/gi/rcgi.cc b/engine/render/gi/rcgi.cc index caef0d82..d3313088 100644 --- a/engine/render/gi/rcgi.cc +++ b/engine/render/gi/rcgi.cc @@ -103,10 +103,10 @@ void FrameRotation(u32 frame_index, f32 out_rows[12]) { f32 u3 = static_cast(hash(frame_index + 2) & 0xffffff) / 16777215.0f; f32 angle = u1 * 6.2831853f; f32 z = u2 * 2.0f - 1.0f; - f32 r = ::sqrt(rx::Max(0.0f, 1.0f - z * z)); + f32 r = ::sqrtf(rx::Max(0.0f, 1.0f - z * z)); f32 phi = u3 * 6.2831853f; - Vec3 axis{r * ::cos(phi), r * ::sin(phi), z}; - f32 c = ::cos(angle), s = ::sin(angle), t = 1.0f - c; + Vec3 axis{r * ::cosf(phi), r * ::sinf(phi), z}; + f32 c = ::cosf(angle), s = ::sinf(angle), t = 1.0f - c; f32 rows[12] = { t * axis.x * axis.x + c, t * axis.x * axis.y - s * axis.z, t * axis.x * axis.z + s * axis.y, 0, @@ -134,9 +134,9 @@ base::UniquePointer RcgiSystem::Create(Device& device, TextureView s Vec3 RcgiSystem::SnapOrigin(const Vec3& camera, u32 cascade) const { f32 spacing = kBaseSpacing * static_cast(1u << cascade); f32 half = (kProbesPerAxis - 1) * spacing * 0.5f; - return Vec3{::floor((camera.x - half) / spacing) * spacing, - ::floor((camera.y - half) / spacing) * spacing, - ::floor((camera.z - half) / spacing) * spacing}; + return Vec3{::floorf((camera.x - half) / spacing) * spacing, + ::floorf((camera.y - half) / spacing) * spacing, + ::floorf((camera.z - half) / spacing) * spacing}; } bool RcgiSystem::CreateResources() { @@ -501,7 +501,7 @@ void RcgiSystem::AddToGraph(RenderGraph& graph, RayTracingContext* raytracing, u bool async, const SdfClipmap* sdf) { // A camera teleport (bigger than cascade 0's extent) invalidates the whole // world cache; zero it before this frame's inserts. - f32 jump = ::sqrt((camera.x - last_camera_.x) * (camera.x - last_camera_.x) + + f32 jump = ::sqrtf((camera.x - last_camera_.x) * (camera.x - last_camera_.x) + (camera.y - last_camera_.y) * (camera.y - last_camera_.y) + (camera.z - last_camera_.z) * (camera.z - last_camera_.z)); if (history_valid_ && jump > kBaseSpacing * kProbesPerAxis) { diff --git a/engine/render/gi/rcgi_interior.h b/engine/render/gi/rcgi_interior.h index 140c3a4e..eb442eca 100644 --- a/engine/render/gi/rcgi_interior.h +++ b/engine/render/gi/rcgi_interior.h @@ -54,7 +54,7 @@ inline u32 RcgiPackOffset(const Vec3& frac) { auto lane = [](f32 f) -> u32 { f32 n = f / kRcgiRelocMaxOffset; n = n < -1.0f ? -1.0f : (n > 1.0f ? 1.0f : n); - i32 q = static_cast(::lround(n * 511.0f)) + 512; // [1, 1023] around 512 + i32 q = static_cast(::lroundf(n * 511.0f)) + 512; // [1, 1023] around 512 if (q < 0) q = 0; if (q > 1023) q = 1023; return static_cast(q); diff --git a/engine/render/gi/rt_instance_cull.cc b/engine/render/gi/rt_instance_cull.cc index 7f40f0b3..b1e5a666 100644 --- a/engine/render/gi/rt_instance_cull.cc +++ b/engine/render/gi/rt_instance_cull.cc @@ -17,11 +17,11 @@ f32 MaxScale(const Mat4& t) { for (u32 i = 0; i < 3; ++i) { f32 row = 0.0f; for (u32 j = 0; j < 3; ++j) - row += ::abs(m[4 * i] * m[4 * j] + m[4 * i + 1] * m[4 * j + 1] + + row += ::fabsf(m[4 * i] * m[4 * j] + m[4 * i + 1] * m[4 * j + 1] + m[4 * i + 2] * m[4 * j + 2]); bound = rx::Max(bound, row); } - return ::sqrt(bound); + return ::sqrtf(bound); } } // namespace @@ -35,7 +35,7 @@ bool RtInstanceCuller::DrawVisible(const Mat4& transform, const Vec3& mesh_cente bool RtInstanceCuller::Cull(const Vec3& c, f32 radius) const { if (radius <= 0.0f) return false; // unknown bounds (radius 0): never cull const f32 dx = c.x - eye_.x, dy = c.y - eye_.y, dz = c.z - eye_.z; - const f32 dist = ::sqrt(dx * dx + dy * dy + dz * dz); + const f32 dist = ::sqrtf(dx * dx + dy * dy + dz * dz); if (dist <= start_distance_) return false; // near field is always kept // Angular radius ~= radius / dist; drop when it is below the threshold. return radius < angle_threshold_ * dist; diff --git a/engine/render/gi/sdf_clipmap.cc b/engine/render/gi/sdf_clipmap.cc index 6e37e44f..3186f5c0 100644 --- a/engine/render/gi/sdf_clipmap.cc +++ b/engine/render/gi/sdf_clipmap.cc @@ -180,9 +180,9 @@ Vec3 SdfClipmap::SnapOrigin(const Vec3& camera, u32 clip) const { // backstop covers that window. const f32 snap = voxel * 8.0f; f32 half = extent * 0.5f; - return Vec3{::floor((camera.x - half) / snap) * snap, - ::floor((camera.y - half) / snap) * snap, - ::floor((camera.z - half) / snap) * snap}; + return Vec3{::floorf((camera.x - half) / snap) * snap, + ::floorf((camera.y - half) / snap) * snap, + ::floorf((camera.z - half) / snap) * snap}; } void SdfClipmap::WriteGlobals(u32 frame_index, const Vec3& camera) { @@ -313,9 +313,9 @@ void SdfClipmap::AddComposeToGraph(RenderGraph& graph, const SdfScene& scene, // trace never overshoots. (The max axis would be correct only for a // non-overshooting bound.) const f32* m = inst.transform.m; - f32 sx = ::sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); - f32 sy = ::sqrt(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); - f32 sz = ::sqrt(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); + f32 sx = ::sqrtf(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + f32 sy = ::sqrtf(m[4] * m[4] + m[5] * m[5] + m[6] * m[6]); + f32 sz = ::sqrtf(m[8] * m[8] + m[9] * m[9] + m[10] * m[10]); f32 min_scale = rx::Min(sx, rx::Min(sy, sz)); ComposePush pp{}; diff --git a/engine/render/gi/sdf_scene.cc b/engine/render/gi/sdf_scene.cc index 2ed91e65..a10cdd40 100644 --- a/engine/render/gi/sdf_scene.cc +++ b/engine/render/gi/sdf_scene.cc @@ -55,7 +55,7 @@ bool AxisRayCross(const Vec3& p, u32 axis, const Tri& t, f32& s) { Vec3 e1 = t.b - t.a, e2 = t.c - t.a; Vec3 pv = Cross(dir, e2); f32 det = Dot(e1, pv); - if (::fabs(det) < 1e-12f) return false; + if (::fabsf(det) < 1e-12f) return false; f32 inv = 1.0f / det; Vec3 tv = p - t.a; f32 u = Dot(tv, pv) * inv; @@ -77,7 +77,7 @@ struct Grid { int Index(int x, int y, int z) const { return (z * n[1] + y) * n[0] + x; } int ClampCell(f32 v, int axis) const { - int c = static_cast(::floor((v - (&origin.x)[axis]) / cell)); + int c = static_cast(::floorf((v - (&origin.x)[axis]) / cell)); return rx::Clamp(c, 0, n[axis] - 1); } }; @@ -87,7 +87,7 @@ void BuildGrid(Grid& g, const base::Vector& tris, const Vec3& box_min, cons g.origin = box_min; g.cell = cell; for (int a = 0; a < 3; ++a) - g.n[a] = rx::Max(1, static_cast(::ceil((&box_ext.x)[a] / cell))); + g.n[a] = rx::Max(1, static_cast(::ceilf((&box_ext.x)[a] / cell))); const int cells = g.n[0] * g.n[1] * g.n[2]; base::Vector counts; counts.resize(static_cast(cells) + 1, 0u); @@ -95,8 +95,8 @@ void BuildGrid(Grid& g, const base::Vector& tris, const Vec3& box_min, cons for (int a = 0; a < 3; ++a) { f32 mn = rx::Min({(&t.a.x)[a], (&t.b.x)[a], (&t.c.x)[a]}); f32 mx = rx::Max({(&t.a.x)[a], (&t.b.x)[a], (&t.c.x)[a]}); - lo[a] = rx::Clamp(static_cast(::floor((mn - (&box_min.x)[a]) / cell)), 0, g.n[a] - 1); - hi[a] = rx::Clamp(static_cast(::floor((mx - (&box_min.x)[a]) / cell)), 0, g.n[a] - 1); + lo[a] = rx::Clamp(static_cast(::floorf((mn - (&box_min.x)[a]) / cell)), 0, g.n[a] - 1); + hi[a] = rx::Clamp(static_cast(::floorf((mx - (&box_min.x)[a]) / cell)), 0, g.n[a] - 1); } }; for (const Tri& t : tris) { @@ -220,7 +220,7 @@ bool SdfScene::RegisterMesh(u64 mesh_key, const MeshInput& input) { u32 res[3]; auto compute_res = [&]() { for (int a = 0; a < 3; ++a) { - u32 interior = static_cast(::ceil((&ext.x)[a] / voxel)); + u32 interior = static_cast(::ceilf((&ext.x)[a] / voxel)); res[a] = rx::Clamp(interior + 2u * kPad, 16u, 64u); } }; @@ -288,7 +288,7 @@ bool SdfScene::RegisterMesh(u64 mesh_key, const MeshInput& input) { } } } - f32 dist = ::sqrt(best_sq); + f32 dist = ::sqrtf(best_sq); // Sign: 3-axis ray parity. An axis-aligned ray stays in one cell row, // so we only test that row; a hit counts once (cell-ownership dedup). diff --git a/engine/render/gi/shadow.cc b/engine/render/gi/shadow.cc index 15b74a0b..9e65de12 100644 --- a/engine/render/gi/shadow.cc +++ b/engine/render/gi/shadow.cc @@ -137,7 +137,7 @@ void ShadowPass::Update(const Vec3& eye, const Vec3& forward, const Vec3& right, const u32 count = settings_.cascade_count; const f32 near_plane = 0.1f; const f32 far_plane = settings_.distance; - const f32 tan_half = ::tan(fov_y * 0.5f); + const f32 tan_half = ::tanf(fov_y * 0.5f); const f32 lambda = 0.7f; // log/uniform split blend const f32 back_pad = 80.0f; // caster range behind the slice, toward the sun @@ -145,13 +145,13 @@ void ShadowPass::Update(const Vec3& eye, const Vec3& forward, const Vec3& right, splits[0] = near_plane; for (u32 i = 1; i <= count; ++i) { f32 p = static_cast(i) / static_cast(count); - f32 log_split = near_plane * ::pow(far_plane / near_plane, p); + f32 log_split = near_plane * ::powf(far_plane / near_plane, p); f32 uniform_split = near_plane + (far_plane - near_plane) * p; splits[i] = lambda * log_split + (1.0f - lambda) * uniform_split; } Vec3 light_dir = Normalize(sun_direction); // travel direction = look direction - Vec3 up_ref = ::abs(light_dir.y) > 0.99f ? Vec3{0, 0, 1} : Vec3{0, 1, 0}; + Vec3 up_ref = ::fabsf(light_dir.y) > 0.99f ? Vec3{0, 0, 1} : Vec3{0, 1, 0}; current_ = CascadeData{}; for (u32 i = 0; i < count; ++i) { @@ -172,9 +172,9 @@ void ShadowPass::Update(const Vec3& eye, const Vec3& forward, const Vec3& right, f32 radius = 0.0f; for (const Vec3& p : corners) { Vec3 v = {p.x - center.x, p.y - center.y, p.z - center.z}; - radius = rx::Max(radius, ::sqrt(v.x * v.x + v.y * v.y + v.z * v.z)); + radius = rx::Max(radius, ::sqrtf(v.x * v.x + v.y * v.y + v.z * v.z)); } - radius = ::ceil(radius * 16.0f) / 16.0f; // quantize so it stops pulsing + radius = ::ceilf(radius * 16.0f) / 16.0f; // quantize so it stops pulsing Vec3 light_eye = {center.x - light_dir.x * (radius + back_pad), center.y - light_dir.y * (radius + back_pad), @@ -190,8 +190,8 @@ void ShadowPass::Update(const Vec3& eye, const Vec3& forward, const Vec3& right, f32 half_res = settings_.resolution * 0.5f; f32 sx = origin_ndc.x * half_res; f32 sy = origin_ndc.y * half_res; - f32 dx = (::round(sx) - sx) / half_res; - f32 dy = (::round(sy) - sy) / half_res; + f32 dx = (::roundf(sx) - sx) / half_res; + f32 dy = (::roundf(sy) - sy) / half_res; light_vp.m[12] += dx; light_vp.m[13] += dy; diff --git a/engine/render/gi/shadow_trace.cc b/engine/render/gi/shadow_trace.cc index 38515af7..0dc15290 100644 --- a/engine/render/gi/shadow_trace.cc +++ b/engine/render/gi/shadow_trace.cc @@ -77,7 +77,7 @@ ResourceHandle ShadowTracePass::AddToGraph(RenderGraph& graph, RayTracingContext push.near_plane = near_plane; push.inv_size[0] = 1.0f / static_cast(extent_.width); push.inv_size[1] = 1.0f / static_cast(extent_.height); - push.tan_angular_radius = ::tan(angular_radius > 0.0f ? angular_radius : 0.0045f); + push.tan_angular_radius = ::tanf(angular_radius > 0.0f ? angular_radius : 0.0045f); push.max_distance = 1000.0f; push.jitter[0] = jitter_x; push.jitter[1] = jitter_y; diff --git a/engine/render/pipeline/gpu_cull.cc b/engine/render/pipeline/gpu_cull.cc index 3c9b3723..20f3511e 100644 --- a/engine/render/pipeline/gpu_cull.cc +++ b/engine/render/pipeline/gpu_cull.cc @@ -48,7 +48,7 @@ void ExtractPlanes(const Mat4& vp, f32 out[5][4]) { {row(2, 0), row(2, 1), row(2, 2), row(2, 3)}, // near: clip.z >= 0 }; for (int i = 0; i < 5; ++i) { - f32 len = ::sqrt(p[i][0] * p[i][0] + p[i][1] * p[i][1] + p[i][2] * p[i][2]); + f32 len = ::sqrtf(p[i][0] * p[i][0] + p[i][1] * p[i][1] + p[i][2] * p[i][2]); if (len < 1e-8f) len = 1.0f; for (int c = 0; c < 4; ++c) out[i][c] = p[i][c] / len; } diff --git a/engine/render/pipeline/hair_material.cc b/engine/render/pipeline/hair_material.cc index 860e1799..87fe7ca6 100644 --- a/engine/render/pipeline/hair_material.cc +++ b/engine/render/pipeline/hair_material.cc @@ -16,8 +16,8 @@ constexpr f32 kSqrtPiOver8 = 0.626657069f; constexpr int kPMax = 3; f32 Sqr(f32 x) { return x * x; } -f32 SafeSqrt(f32 x) { return ::sqrt(rx::Max(x, 0.0f)); } -f32 SafeAsin(f32 x) { return ::asin(rx::Clamp(x, -1.0f, 1.0f)); } +f32 SafeSqrt(f32 x) { return ::sqrtf(rx::Max(x, 0.0f)); } +f32 SafeAsin(f32 x) { return ::asinf(rx::Clamp(x, -1.0f, 1.0f)); } f32 I0(f32 x) { f32 val = 0.0f; @@ -35,18 +35,18 @@ f32 I0(f32 x) { f32 LogI0(f32 x) { if (x > 12.0f) { - return x + 0.5f * (-::log(2.0f * kPi) + ::log(1.0f / x) + 1.0f / (8.0f * x)); + return x + 0.5f * (-::logf(2.0f * kPi) + ::logf(1.0f / x) + 1.0f / (8.0f * x)); } - return ::log(I0(x)); + return ::logf(I0(x)); } f32 Mp(f32 cos_theta_i, f32 cos_theta_o, f32 sin_theta_i, f32 sin_theta_o, f32 v) { f32 a = cos_theta_i * cos_theta_o / v; f32 b = sin_theta_i * sin_theta_o / v; if (v <= 0.1f) { - return ::exp(LogI0(a) - b - 1.0f / v + 0.6931472f + ::log(1.0f / (2.0f * v))); + return ::expf(LogI0(a) - b - 1.0f / v + 0.6931472f + ::logf(1.0f / (2.0f * v))); } - return (::exp(-b) * I0(a)) / (::sinh(1.0f / v) * 2.0f * v); + return (::expf(-b) * I0(a)) / (::sinhf(1.0f / v) * 2.0f * v); } f32 FresnelDielectric(f32 cos_theta_i, f32 eta) { @@ -57,19 +57,19 @@ f32 FresnelDielectric(f32 cos_theta_i, f32 eta) { } f32 sin2_t = (1.0f - cos_theta_i * cos_theta_i) / (eta * eta); if (sin2_t >= 1.0f) return 1.0f; - f32 cos_t = ::sqrt(1.0f - sin2_t); + f32 cos_t = ::sqrtf(1.0f - sin2_t); f32 rp = (eta * cos_theta_i - cos_t) / (eta * cos_theta_i + cos_t); f32 rs = (cos_theta_i - eta * cos_t) / (cos_theta_i + eta * cos_t); return 0.5f * (rp * rp + rs * rs); } f32 Logistic(f32 x, f32 s) { - x = ::abs(x); - f32 e = ::exp(-x / s); + x = ::fabsf(x); + f32 e = ::expf(-x / s); return e / (s * Sqr(1.0f + e)); } -f32 LogisticCdf(f32 x, f32 s) { return 1.0f / (1.0f + ::exp(-x / s)); } +f32 LogisticCdf(f32 x, f32 s) { return 1.0f / (1.0f + ::expf(-x / s)); } f32 TrimmedLogistic(f32 x, f32 s) { f32 norm = LogisticCdf(kPi, s) - LogisticCdf(-kPi, s); @@ -82,13 +82,13 @@ f32 PhiLobe(int p, f32 gamma_o, f32 gamma_t) { f32 Np(f32 phi, int p, f32 s, f32 gamma_o, f32 gamma_t) { f32 dphi = phi - PhiLobe(p, gamma_o, gamma_t); - dphi = dphi - 2.0f * kPi * ::floor((dphi + kPi) / (2.0f * kPi)); + dphi = dphi - 2.0f * kPi * ::floorf((dphi + kPi) / (2.0f * kPi)); return TrimmedLogistic(dphi, s); } void LobeVariance(f32 beta_m, f32 v[kPMax + 1]) { f32 b = rx::Clamp(beta_m, 0.02f, 1.0f); - f32 v0 = Sqr(0.726f * b + 0.812f * b * b + 3.7f * ::pow(b, 20.0f)); + f32 v0 = Sqr(0.726f * b + 0.812f * b * b + 3.7f * ::powf(b, 20.0f)); v[0] = v0; v[1] = 0.25f * v0; v[2] = 4.0f * v0; @@ -97,7 +97,7 @@ void LobeVariance(f32 beta_m, f32 v[kPMax + 1]) { f32 AzimuthalScale(f32 beta_n) { f32 b = rx::Clamp(beta_n, 0.02f, 1.0f); - return kSqrtPiOver8 * (0.265f * b + 1.194f * b * b + 5.372f * ::pow(b, 22.0f)); + return kSqrtPiOver8 * (0.265f * b + 1.194f * b * b + 5.372f * ::powf(b, 22.0f)); } void AverageAttenuation(const HairSurfaceParameters& p, f32 cos_theta_d, f32 a_f[3], @@ -105,7 +105,7 @@ void AverageAttenuation(const HairSurfaceParameters& p, f32 cos_theta_d, f32 a_f f32 f = FresnelDielectric(rx::Max(cos_theta_d, 1e-3f), p.eta); f32 spread = rx::Clamp(p.beta_n, 0.0f, 1.0f); for (int c = 0; c < 3; ++c) { - f32 T = ::exp(-p.sigma_a[c] * 2.0f); + f32 T = ::expf(-p.sigma_a[c] * 2.0f); f32 tt = Sqr(1.0f - f) * T; f32 trt = tt * T * f; a_f[c] = rx::Clamp(tt * (1.0f - 0.5f * spread) + trt * 0.15f, 0.0f, 1.0f); @@ -128,7 +128,7 @@ void HairSigmaFromColorPathTraced(const f32 color[3], f32 beta_n, f32 out_sigma[ const f32 denom = 5.969f - 0.215f * b + 2.532f * b * b - 10.73f * b * b * b + 5.574f * b * b * b * b + 0.245f * b * b * b * b * b; for (int c = 0; c < 3; ++c) { - const f32 t = ::log(rx::Clamp(color[c], 1e-4f, 1.0f)) / rx::Max(denom, 1e-4f); + const f32 t = ::logf(rx::Clamp(color[c], 1e-4f, 1.0f)) / rx::Max(denom, 1e-4f); out_sigma[c] = t * t; } } @@ -136,7 +136,7 @@ void HairSigmaFromColorPathTraced(const f32 color[3], f32 beta_n, f32 out_sigma[ void HairSigmaFromColor(const f32 color[3], f32 reference_depth, f32 out_sigma[3]) { const f32 denom = 2.17f + 2.02f * rx::Max(reference_depth, 0.0f); for (int c = 0; c < 3; ++c) { - out_sigma[c] = -::log(rx::Clamp(color[c], 1e-4f, 1.0f)) / rx::Max(denom, 1e-3f); + out_sigma[c] = -::logf(rx::Clamp(color[c], 1e-4f, 1.0f)) / rx::Max(denom, 1e-3f); } } @@ -250,11 +250,11 @@ void HairEvaluateCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 const f32 sin_theta_o = rx::Clamp(wo[0], -1.0f, 1.0f); const f32 cos_theta_o = SafeSqrt(1.0f - sin_theta_o * sin_theta_o); - const f32 phi_o = ::atan2(wo[2], wo[1]); + const f32 phi_o = ::atan2f(wo[2], wo[1]); const f32 sin_theta_i = rx::Clamp(wi[0], -1.0f, 1.0f); const f32 cos_theta_i = SafeSqrt(1.0f - sin_theta_i * sin_theta_i); - const f32 phi_i = ::atan2(wi[2], wi[1]); + const f32 phi_i = ::atan2f(wi[2], wi[1]); const f32 sin_theta_t = sin_theta_o / p.eta; const f32 cos_theta_t = SafeSqrt(1.0f - sin_theta_t * sin_theta_t); @@ -267,7 +267,7 @@ void HairEvaluateCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 f32 T[3]; for (int c = 0; c < 3; ++c) { - T[c] = ::exp(-p.sigma_a[c] * (2.0f * cos_gamma_t / rx::Max(cos_theta_t, 1e-5f))); + T[c] = ::expf(-p.sigma_a[c] * (2.0f * cos_gamma_t / rx::Max(cos_theta_t, 1e-5f))); } const f32 cos_gamma_o = SafeSqrt(1.0f - h * h); @@ -284,7 +284,7 @@ void HairEvaluateCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 LobeVariance(p.beta_m, v); const f32 s = AzimuthalScale(p.beta_n); - const f32 sin_a = ::sin(p.alpha); + const f32 sin_a = ::sinf(p.alpha); const f32 cos_a = SafeSqrt(1.0f - sin_a * sin_a); const f32 sin2a = 2.0f * sin_a * cos_a; const f32 cos2a = cos_a * cos_a - sin_a * sin_a; @@ -304,7 +304,7 @@ void HairEvaluateCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 sto = sin_theta_o * cos4a + cos_theta_o * sin4a; cto = cos_theta_o * cos4a - sin_theta_o * sin4a; } - cto = ::abs(cto); + cto = ::fabsf(cto); const f32 m = Mp(cos_theta_i, cto, sin_theta_i, sto, v[lobe]); const f32 n = Np(phi, lobe, s, gamma_o, gamma_t); for (int c = 0; c < 3; ++c) out_rgb[c] += m * ap[lobe][c] * n; @@ -323,7 +323,7 @@ void HairShadeCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 wi[ f32 strand_count, f32 out_rgb[3]) { const f32 cos_theta_i = SafeSqrt(1.0f - wi[0] * wi[0]); const f32 cos_theta_d = - ::cos(0.5f * (SafeAsin(wi[0]) - SafeAsin(wo[0]))); + ::cosf(0.5f * (SafeAsin(wi[0]) - SafeAsin(wo[0]))); if (!p.dual_scattering) { HairEvaluateCpu(p, wo, wi, h, out_rgb); @@ -332,9 +332,9 @@ void HairShadeCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 wi[ } f32 a_f[3], a_b[3]; - AverageAttenuation(p, ::abs(cos_theta_d), a_f, a_b); + AverageAttenuation(p, ::fabsf(cos_theta_d), a_f, a_b); const f32 n = rx::Max(strand_count, 0.0f) * rx::Max(p.density, 0.0f); - const f32 spread = ::sqrt(n) * 0.4f * (0.2f + rx::Clamp(p.beta_m, 0.0f, 1.0f)); + const f32 spread = ::sqrtf(n) * 0.4f * (0.2f + rx::Clamp(p.beta_m, 0.0f, 1.0f)); f32 direct[3]; HairEvaluateCpu(p, wo, wi, h, direct); @@ -345,9 +345,9 @@ void HairShadeCpu(const HairSurfaceParameters& p, const f32 wo[3], const f32 wi[ f32 scattered[3]; HairEvaluateCpu(blunt, wo, wi, 0.0f, scattered); - const f32 density_term = 1.0f - ::exp(-0.35f * n); + const f32 density_term = 1.0f - ::expf(-0.35f * n); for (int c = 0; c < 3; ++c) { - const f32 forward = ::exp(::log(rx::Max(a_f[c], 1e-6f)) * n); + const f32 forward = ::expf(::logf(rx::Max(a_f[c], 1e-6f)) * n); const f32 back = a_b[c] * density_term * rx::Max(p.scatter_scale, 0.0f); out_rgb[c] = (direct[c] * forward + scattered[c] * forward * back) * cos_theta_i; } diff --git a/engine/render/pipeline/human_material.cc b/engine/render/pipeline/human_material.cc index 94b5e7c9..62855678 100644 --- a/engine/render/pipeline/human_material.cc +++ b/engine/render/pipeline/human_material.cc @@ -19,7 +19,7 @@ V3 Load(const f32 v[3]) { return {v[0], v[1], v[2]}; } f32 Dot(V3 a, V3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } V3 Add(V3 a, V3 b) { return {a.x + b.x, a.y + b.y, a.z + b.z}; } V3 Norm(V3 a) { - f32 len = ::sqrt(rx::Max(Dot(a, a), 1e-20f)); + f32 len = ::sqrtf(rx::Max(Dot(a, a), 1e-20f)); return {a.x / len, a.y / len, a.z / len}; } f32 Sat(f32 x) { return x < 0.0f ? 0.0f : (x > 1.0f ? 1.0f : x); } @@ -31,8 +31,8 @@ f32 D_GGX(f32 ndh, f32 a) { } f32 V_Smith(f32 ndv, f32 ndl, f32 a) { f32 a2 = a * a; - f32 gv = ndl * ::sqrt(ndv * ndv * (1.0f - a2) + a2); - f32 gl = ndv * ::sqrt(ndl * ndl * (1.0f - a2) + a2); + f32 gv = ndl * ::sqrtf(ndv * ndv * (1.0f - a2) + a2); + f32 gl = ndv * ::sqrtf(ndl * ndl * (1.0f - a2) + a2); return 0.5f / rx::Max(gv + gl, 1e-5f); } @@ -365,14 +365,14 @@ HumanBrdfSample HumanEvaluateCpu(const HumanSurfaceParameters& p, const f32 base if (cos_d > 0.0f) { V3 hd = Norm(Add(l, v)); f32 ldh = Sat(Dot(l, hd)); - f32 gv = ::pow(Sat(1.0f - ndv_d), rx::Max(p.diffuse_fresnel_falloff, 1e-2f)); - f32 gl = ::pow(Sat(1.0f - Sat(ndl_d)), + f32 gv = ::powf(Sat(1.0f - ndv_d), rx::Max(p.diffuse_fresnel_falloff, 1e-2f)); + f32 gl = ::powf(Sat(1.0f - Sat(ndl_d)), rx::Max(p.diffuse_fresnel_tangent_falloff, 1e-2f)); f32 fresnel = (1.0f + p.diffuse_fresnel_peak * gv) * (1.0f + p.diffuse_fresnel_peak * gl); f32 fd90 = p.retroreflection_peak * ldh * ldh; - f32 rv = 1.0f + fd90 * ::pow(Sat(1.0f - ndv_d), + f32 rv = 1.0f + fd90 * ::powf(Sat(1.0f - ndv_d), rx::Max(p.retroreflection_tangent_falloff, 1e-2f)); - f32 rl = 1.0f + fd90 * ::pow(Sat(1.0f - Sat(ndl_d)), + f32 rl = 1.0f + fd90 * ::powf(Sat(1.0f - Sat(ndl_d)), rx::Max(p.retroreflection_falloff, 1e-2f)); f32 shaping = rx::Max(fresnel * rv * rl, 0.0f); for (int c = 0; c < 3; ++c) out.diffuse[c] = base_color[c] * (1.0f / kPi) * shaping * cos_d; @@ -389,8 +389,8 @@ HumanBrdfSample HumanEvaluateCpu(const HumanSurfaceParameters& p, const f32 base f32 rough = roughness; solid_angle *= Sat(p.light_shape_response); if (solid_angle > 0.0f) { - f32 widen = Sat(::sqrt(solid_angle / kPi) * 0.5f); - rough = Sat(::sqrt(roughness * roughness + widen * widen)); + f32 widen = Sat(::sqrtf(solid_angle / kPi) * 0.5f); + rough = Sat(::sqrtf(roughness * roughness + widen * widen)); } f32 a1 = rx::Max(rough * rough, 1e-5f); f32 core = D_GGX(ndh, a1) * V_Smith(ndv, ndl, a1); @@ -402,14 +402,14 @@ HumanBrdfSample HumanEvaluateCpu(const HumanSurfaceParameters& p, const f32 base f32 w = Sat(p.secondary_specular_weight); lobe = core + (tail - core) * w; } - f32 fpow = ::pow(Sat(1.0f - vdh), rx::Max(p.specular_fresnel_falloff, 1e-2f)); + f32 fpow = ::powf(Sat(1.0f - vdh), rx::Max(p.specular_fresnel_falloff, 1e-2f)); for (int c = 0; c < 3; ++c) { f32 f = f0[c] + (1.0f - f0[c]) * fpow; out.specular[c] = lobe * f * ndl; } if (p.corneal_wetness > 0.0f) { f32 wa = rx::Max(0.02f * 0.02f, 1e-5f); - f32 wf = (0.02f + 0.98f * ::pow(Sat(1.0f - vdh), 5.0f)) * Sat(p.corneal_wetness); + f32 wf = (0.02f + 0.98f * ::powf(Sat(1.0f - vdh), 5.0f)) * Sat(p.corneal_wetness); f32 wet = D_GGX(ndh, wa) * V_Smith(ndv, ndl, wa) * ndl; for (int c = 0; c < 3; ++c) { out.specular[c] = out.specular[c] * (1.0f - wf) + wet * wf; @@ -421,7 +421,7 @@ HumanBrdfSample HumanEvaluateCpu(const HumanSurfaceParameters& p, const f32 base if (p.transmission > 0.0f && ndl_d < 0.35f) { f32 optical = rx::Max(p.extinction_scale * thickness / rx::Max(p.mean_free_path * p.subsurface_scale, 1e-4f), 0.0f); - f32 attenuation = ::exp(-optical); + f32 attenuation = ::expf(-optical); f32 back = Sat(Dot(v, {-l.x, -l.y, -l.z})); f32 lobe = back * back * Sat(0.35f - ndl_d) / 0.35f; for (int c = 0; c < 3; ++c) { @@ -463,7 +463,7 @@ HumanBrdfSample StockBrdfCpu(const f32 base_color[3], f32 roughness, const f32 f f32 vdh = Sat(Dot(v, h)); f32 a = rx::Max(roughness * roughness, 1e-5f); f32 lobe = D_GGX(ndh, a) * V_Smith(ndv, ndl, a); - f32 fpow = ::pow(Sat(1.0f - vdh), 5.0f); + f32 fpow = ::powf(Sat(1.0f - vdh), 5.0f); for (int c = 0; c < 3; ++c) { out.diffuse[c] = base_color[c] * (1.0f / kPi) * ndl; f32 f = f0[c] + (1.0f - f0[c]) * fpow; diff --git a/engine/render/pipeline/material_system.cc b/engine/render/pipeline/material_system.cc index a3e3e9e9..6a9019cd 100644 --- a/engine/render/pipeline/material_system.cc +++ b/engine/render/pipeline/material_system.cc @@ -41,7 +41,7 @@ SkinCoeffs ComputeSkinCoeffs(const asset::Material::SkinParams& p) { // Kulla-Conty 2017: invert the multiple-scattering albedo so the authored // colour is what's seen. Per channel; s is the surface-albedo scale factor. const f32 s = 4.09712f + 4.20863f * col - - ::sqrt(rx::Max(0.0f, 9.59217f + 41.6808f * col + + ::sqrtf(rx::Max(0.0f, 9.59217f + 41.6808f * col + 17.7126f * col * col)); const f32 s2 = s * s; const f32 alpha = rx::Clamp((1.0f - s2) / (1.0f - c.g * s2), 0.0f, 0.999f); @@ -1223,11 +1223,11 @@ MaterialSystem::MaterialColor MaterialSystem::material_color(u64 material_hash) f32 MaterialSystem::AlphaCoverage::Sample(f32 u, f32 v) const { if (alpha.empty() || width == 0 || height == 0) return mean; - u -= ::floor(u); // wrap into [0,1) - v -= ::floor(v); + u -= ::floorf(u); // wrap into [0,1) + v -= ::floorf(v); f32 fx = u * static_cast(width) - 0.5f; f32 fy = v * static_cast(height) - 0.5f; - i32 x0 = static_cast(::floor(fx)), y0 = static_cast(::floor(fy)); + i32 x0 = static_cast(::floorf(fx)), y0 = static_cast(::floorf(fy)); f32 tx = fx - static_cast(x0), ty = fy - static_cast(y0); auto at = [&](i32 x, i32 y) -> f32 { x = ((x % static_cast(width)) + static_cast(width)) % static_cast(width); diff --git a/engine/render/pipeline/meshlet.cc b/engine/render/pipeline/meshlet.cc index 80c528a4..76a44ada 100644 --- a/engine/render/pipeline/meshlet.cc +++ b/engine/render/pipeline/meshlet.cc @@ -70,7 +70,7 @@ MeshletGeometry BuildImpl(const asset::Vertex* verts, u32 vertex_count, const u3 f32 radius = 0.0f; for (u32 i = 0; i < local_count; ++i) { Vec3 d = P(local_global[i]) - center; - radius = rx::Max(radius, ::sqrt(d.x * d.x + d.y * d.y + d.z * d.z)); + radius = rx::Max(radius, ::sqrtf(d.x * d.x + d.y * d.y + d.z * d.z)); } m.center_radius[0] = center.x; m.center_radius[1] = center.y; @@ -84,10 +84,10 @@ MeshletGeometry BuildImpl(const asset::Vertex* verts, u32 vertex_count, const u3 u32 packed = out.triangles[t]; Vec3 n = Cross(P(local_global[(packed >> 8) & 0xff]) - P(local_global[packed & 0xff]), P(local_global[(packed >> 16) & 0xff]) - P(local_global[packed & 0xff])); - f32 len = ::sqrt(n.x * n.x + n.y * n.y + n.z * n.z); + f32 len = ::sqrtf(n.x * n.x + n.y * n.y + n.z * n.z); if (len > 1e-8f) axis = axis + n * (1.0f / len); } - f32 alen = ::sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); + f32 alen = ::sqrtf(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); if (alen > 1e-6f) { axis = axis * (1.0f / alen); f32 min_c = 1.0f; @@ -95,13 +95,13 @@ MeshletGeometry BuildImpl(const asset::Vertex* verts, u32 vertex_count, const u3 u32 packed = out.triangles[t]; Vec3 n = Cross(P(local_global[(packed >> 8) & 0xff]) - P(local_global[packed & 0xff]), P(local_global[(packed >> 16) & 0xff]) - P(local_global[packed & 0xff])); - f32 len = ::sqrt(n.x * n.x + n.y * n.y + n.z * n.z); + f32 len = ::sqrtf(n.x * n.x + n.y * n.y + n.z * n.z); if (len > 1e-8f) min_c = rx::Min(min_c, (n.x * axis.x + n.y * axis.y + n.z * axis.z) / len); } m.cone[0] = axis.x; m.cone[1] = axis.y; m.cone[2] = axis.z; - m.cone[3] = min_c > 0.0f ? ::sqrt(1.0f - min_c * min_c) : 2.0f; // 2 = never cull + m.cone[3] = min_c > 0.0f ? ::sqrtf(1.0f - min_c * min_c) : 2.0f; // 2 = never cull } else { m.cone[3] = 2.0f; // degenerate, never cone-cull } @@ -155,13 +155,13 @@ MeshletGeometry BuildImpl(const asset::Vertex* verts, u32 vertex_count, const u3 // This triangle's unit normal, to keep the meshlet's normal cone tight. Vec3 pa = P(g[0]); Vec3 n = Cross(P(g[1]) - pa, P(g[2]) - pa); - f32 nlen = ::sqrt(n.x * n.x + n.y * n.y + n.z * n.z); + f32 nlen = ::sqrtf(n.x * n.x + n.y * n.y + n.z * n.z); if (nlen > 1e-8f) n = n * (1.0f / nlen); // Bound the cone half-angle (~45deg from the running mean) so backface cone // culling stays effective; finalize early when a triangle would widen it. bool cone_break = false; if (cone_split && local_count > 0) { - f32 slen = ::sqrt(cone_sum.x * cone_sum.x + cone_sum.y * cone_sum.y + cone_sum.z * cone_sum.z); + f32 slen = ::sqrtf(cone_sum.x * cone_sum.x + cone_sum.y * cone_sum.y + cone_sum.z * cone_sum.z); if (slen > 1e-6f && (n.x * cone_sum.x + n.y * cone_sum.y + n.z * cone_sum.z) / slen < 0.85f) { cone_break = true; } diff --git a/engine/render/pipeline/virtual_geometry.cc b/engine/render/pipeline/virtual_geometry.cc index 7b9b2e01..9293ccd4 100644 --- a/engine/render/pipeline/virtual_geometry.cc +++ b/engine/render/pipeline/virtual_geometry.cc @@ -493,7 +493,7 @@ void VirtualGeometryPass::Upload(Device& device, const asset::Mesh& mesh) { const WorkCluster& c = current[ci]; Vec3 d = Vec3{c.self_sphere[0], c.self_sphere[1], c.self_sphere[2]} - center; radius = rx::Max(radius, - ::sqrt(d.x * d.x + d.y * d.y + d.z * d.z) + c.self_sphere[3]); + ::sqrtf(d.x * d.x + d.y * d.y + d.z * d.z) + c.self_sphere[3]); } f32 group_sphere[4] = {center.x, center.y, center.z, radius}; diff --git a/engine/render/texturing/virtual_texture.cc b/engine/render/texturing/virtual_texture.cc index a1bfa16f..5ff1f25b 100644 --- a/engine/render/texturing/virtual_texture.cc +++ b/engine/render/texturing/virtual_texture.cc @@ -141,15 +141,15 @@ void VirtualTexture::GeneratePage(const PageKey& key, base::Vector* pixels) f32 u = vx / virtual_size, v = vy / virtual_size; // Base: two-tone checker drifting through hue across the space. - f32 checker = (static_cast(::floor(vx / 64.0f)) ^ - static_cast(::floor(vy / 64.0f))) & 1 + f32 checker = (static_cast(::floorf(vx / 64.0f)) ^ + static_cast(::floorf(vy / 64.0f))) & 1 ? 0.55f : 0.45f; f32 r = checker * (0.6f + 0.4f * u); f32 g = checker * (0.6f + 0.4f * v); f32 b = checker * (0.6f + 0.4f * (1.0f - u)); // Coarse grid lines every 1024 virtual texels. - f32 gx = ::fmod(vx, 1024.0f), gy = ::fmod(vy, 1024.0f); + f32 gx = ::fmodf(vx, 1024.0f), gy = ::fmodf(vy, 1024.0f); if (gx < 3.0f * scale || gy < 3.0f * scale) { r = g = b = 0.05f; } diff --git a/engine/render2d/camera2d.h b/engine/render2d/camera2d.h index 11ef0181..5cb29893 100644 --- a/engine/render2d/camera2d.h +++ b/engine/render2d/camera2d.h @@ -30,7 +30,7 @@ class Camera2D { void MoveBy(Vec2 delta) { center_ += delta; } // Pixels per world unit. Clamped positive so the mapping stays invertible. void SetZoom(f32 zoom) { - zoom_ = ::isfinite(zoom) && zoom > 1e-3f ? zoom : 1e-3f; + zoom_ = isfinite(zoom) && zoom > 1e-3f ? zoom : 1e-3f; } Vec2 center() const { return center_; } diff --git a/engine/render2d/iso.h b/engine/render2d/iso.h index 4422b60d..ef47e3d2 100644 --- a/engine/render2d/iso.h +++ b/engine/render2d/iso.h @@ -49,7 +49,7 @@ struct IsoGrid { // Nearest integer cell for a world point (floor of the fractional map). Vec2i WorldToCell(Vec2 world) const { Vec2 f = WorldToCellF(world); - return {static_cast(::floor(f.x)), static_cast(::floor(f.y))}; + return {static_cast(::floorf(f.x)), static_cast(::floorf(f.y))}; } // Painter's-order sort key: cells with a larger (col+row) are nearer the diff --git a/engine/render2d/sprite_renderer.cc b/engine/render2d/sprite_renderer.cc index 7adfa8da..07b8d7dc 100644 --- a/engine/render2d/sprite_renderer.cc +++ b/engine/render2d/sprite_renderer.cc @@ -222,7 +222,7 @@ void SpriteRenderer::DrawSprite(const SpriteParams& s) { q.texture = (s.texture != 0 && s.texture < textures_.size() && textures_[s.texture].valid) ? s.texture : kWhiteTexture; - q.sort_key = ::isfinite(s.sort_key) ? s.sort_key : 0.0f; + q.sort_key = isfinite(s.sort_key) ? s.sort_key : 0.0f; queue_.push_back(q); } @@ -238,17 +238,17 @@ void SpriteRenderer::DrawQuad(Vec2 pos, Vec2 size, Color color, f32 sort_key) { void SpriteRenderer::DrawTileMap(TextureId tileset_texture, const TileMap& map, const Camera2D& camera) { - if (!(map.tile_size > 0.0f) || !::isfinite(map.tile_size)) return; + if (!(map.tile_size > 0.0f) || !isfinite(map.tile_size)) return; Rect view = camera.VisibleRect(); for (const TileLayer& layer : map.layers) { // Parallax shifts a distant layer so it scrolls slower than the camera. Vec2 offset = camera.center() * (1.0f - layer.parallax); // Visible tile range in this layer's own space (undo the parallax offset). f32 x0 = view.x - offset.x, y0 = view.y - offset.y; - i32 tx0 = static_cast(::floor(x0 / map.tile_size)) - 1; - i32 ty0 = static_cast(::floor(y0 / map.tile_size)) - 1; - i32 tx1 = static_cast(::floor((x0 + view.w) / map.tile_size)) + 1; - i32 ty1 = static_cast(::floor((y0 + view.h) / map.tile_size)) + 1; + i32 tx0 = static_cast(::floorf(x0 / map.tile_size)) - 1; + i32 ty0 = static_cast(::floorf(y0 / map.tile_size)) - 1; + i32 tx1 = static_cast(::floorf((x0 + view.w) / map.tile_size)) + 1; + i32 ty1 = static_cast(::floorf((y0 + view.h) / map.tile_size)) + 1; tx0 = rx::Max(tx0, 0); ty0 = rx::Max(ty0, 0); tx1 = rx::Min(tx1, static_cast(layer.width) - 1); diff --git a/engine/render2d/tile_map.cc b/engine/render2d/tile_map.cc index 1014357b..396e7176 100644 --- a/engine/render2d/tile_map.cc +++ b/engine/render2d/tile_map.cc @@ -8,8 +8,8 @@ namespace rx::render2d { namespace { bool TryWorldToTile(f32 tile_size, Vec2 world, Vec2i* tile) { - if (!(tile_size > 0.0f) || !::isfinite(tile_size) || - !::isfinite(world.x) || !::isfinite(world.y)) { + if (!(tile_size > 0.0f) || !isfinite(tile_size) || + !isfinite(world.x) || !isfinite(world.y)) { return false; } const f64 x = ::floor(static_cast(world.x) / tile_size); @@ -56,7 +56,7 @@ bool TileMap::IsSolidWorld(Vec2 world) const { } Rect TileMap::WorldBounds() const { - if (!(tile_size > 0.0f) || !::isfinite(tile_size)) return {}; + if (!(tile_size > 0.0f) || !isfinite(tile_size)) return {}; u32 max_w = 0, max_h = 0; for (const TileLayer& layer : layers) { max_w = layer.width > max_w ? layer.width : max_w; diff --git a/engine/render2d/tile_map.h b/engine/render2d/tile_map.h index 1854b27e..e4b7241f 100644 --- a/engine/render2d/tile_map.h +++ b/engine/render2d/tile_map.h @@ -74,7 +74,7 @@ class RX_RENDER2D_EXPORT TileMap { Vec2i WorldToTile(Vec2 world) const; // Top-left world corner of tile (tx, ty). Vec2 TileToWorld(i32 tx, i32 ty) const { - if (!(tile_size > 0.0f) || !::isfinite(tile_size)) return {}; + if (!(tile_size > 0.0f) || !isfinite(tile_size)) return {}; return {static_cast(tx) * tile_size, static_cast(ty) * tile_size}; } diff --git a/engine/render2d/types2d.h b/engine/render2d/types2d.h index df981aff..fd51b010 100644 --- a/engine/render2d/types2d.h +++ b/engine/render2d/types2d.h @@ -25,7 +25,7 @@ struct Vec2 { }; inline f32 Dot(Vec2 a, Vec2 b) { return a.x * b.x + a.y * b.y; } -inline f32 Length(Vec2 v) { return ::sqrt(Dot(v, v)); } +inline f32 Length(Vec2 v) { return ::sqrtf(Dot(v, v)); } inline Vec2 Lerp(Vec2 a, Vec2 b, f32 t) { return a + (b - a) * t; } inline Vec2 Normalize(Vec2 v) { f32 l = Length(v); diff --git a/engine/scene/camera.cc b/engine/scene/camera.cc index 4f32545d..289c20ae 100644 --- a/engine/scene/camera.cc +++ b/engine/scene/camera.cc @@ -46,7 +46,7 @@ void BeginTransition(CameraOutput& output, CameraStack& stack, ecs::Entity mode, const bool compatible_projection = output.view.lens.projection == camera_mode.view.lens.projection; - if (!::isfinite(spec.duration) || spec.duration <= 0 || !had_output || + if (!isfinite(spec.duration) || spec.duration <= 0 || !had_output || !compatible_projection) { CutToMode(output, stack, mode, camera_mode); return; @@ -201,9 +201,9 @@ CameraView InterpolateCameraView(const CameraView& source, const CameraView& des view.lens = destination.lens; if (destination.lens.projection == CameraProjection::kPerspective) { - const f32 source_scale = ::tan(source.lens.fov_y * 0.5f); - const f32 destination_scale = ::tan(destination.lens.fov_y * 0.5f); - view.lens.fov_y = 2.0f * ::atan(rx::Lerp(source_scale, destination_scale, t)); + const f32 source_scale = ::tanf(source.lens.fov_y * 0.5f); + const f32 destination_scale = ::tanf(destination.lens.fov_y * 0.5f); + view.lens.fov_y = 2.0f * ::atanf(rx::Lerp(source_scale, destination_scale, t)); } else { view.lens.ortho_height = rx::Lerp(source.lens.ortho_height, destination.lens.ortho_height, t); view.lens.ortho_near = rx::Lerp(source.lens.ortho_near, destination.lens.ortho_near, t); @@ -213,7 +213,7 @@ CameraView InterpolateCameraView(const CameraView& source, const CameraView& des } void ResolveCameraStacks(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt < 0) dt = 0; + if (!isfinite(dt) || dt < 0) dt = 0; world.Each([&](ecs::Entity, CameraStack& stack, CameraOutput& output) { if (!PruneInvalidModes(world, stack, output)) return; diff --git a/engine/scene/camera_rig.cc b/engine/scene/camera_rig.cc index a9acb280..766edb4f 100644 --- a/engine/scene/camera_rig.cc +++ b/engine/scene/camera_rig.cc @@ -14,14 +14,14 @@ constexpr f32 kTwoPi = 2.0f * kPi; f32 BlendForHalfLife(f32 half_life, f32 dt) { if (half_life <= 0) return 1.0f; - return 1.0f - ::exp2(-dt / half_life); + return 1.0f - ::exp2f(-dt / half_life); } f32 MoveAngle(f32 current, f32 target, f32 amount) { - return current + ::remainder(target - current, kTwoPi) * amount; + return current + ::remainderf(target - current, kTwoPi) * amount; } -f32 YawFromDirection(const Vec3& direction) { return ::atan2(direction.x, -direction.z); } +f32 YawFromDirection(const Vec3& direction) { return ::atan2f(direction.x, -direction.z); } Quat OrbitRotation(f32 yaw, f32 pitch) { return Normalize(QuatFromAxisAngle({0, -1, 0}, yaw) * QuatFromAxisAngle({1, 0, 0}, pitch)); @@ -35,9 +35,9 @@ Quat LookRotation(const Vec3& direction, const Vec3& up_reference, const Quat& f if (Length(right) <= 1e-5f) right = Cross(forward, Rotate(fallback, Vec3{0, 1, 0})); if (Length(right) <= 1e-5f) { const Vec3 axis = - ::abs(forward.x) <= ::abs(forward.y) && ::abs(forward.x) <= ::abs(forward.z) + ::fabsf(forward.x) <= ::fabsf(forward.y) && ::fabsf(forward.x) <= ::fabsf(forward.z) ? Vec3{1, 0, 0} - : (::abs(forward.y) <= ::abs(forward.z) ? Vec3{0, 1, 0} : Vec3{0, 0, 1}); + : (::fabsf(forward.y) <= ::fabsf(forward.z) ? Vec3{0, 1, 0} : Vec3{0, 0, 1}); right = Cross(forward, axis); } right = Normalize(right); @@ -99,9 +99,9 @@ CameraLens DampLens(const CameraLens& current, const CameraLens& target, f32 amo CameraLens lens = target; if (target.projection == CameraProjection::kPerspective) { - const f32 current_scale = ::tan(current.fov_y * 0.5f); - const f32 target_scale = ::tan(target.fov_y * 0.5f); - lens.fov_y = 2.0f * ::atan(rx::Lerp(current_scale, target_scale, amount)); + const f32 current_scale = ::tanf(current.fov_y * 0.5f); + const f32 target_scale = ::tanf(target.fov_y * 0.5f); + lens.fov_y = 2.0f * ::atanf(rx::Lerp(current_scale, target_scale, amount)); } else { lens.ortho_height = rx::Lerp(current.ortho_height, target.ortho_height, amount); lens.ortho_near = rx::Lerp(current.ortho_near, target.ortho_near, amount); @@ -113,7 +113,7 @@ CameraLens DampLens(const CameraLens& current, const CameraLens& target, f32 amo } // namespace void BuildCameraRigs(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt < 0) dt = 0; + if (!isfinite(dt) || dt < 0) dt = 0; world.Each([&](ecs::Entity entity, CameraRigPose& pose, CameraAnchor& anchor, CameraMode& mode) { @@ -165,7 +165,7 @@ void BuildCameraRigs(ecs::World& world, f32 dt) { const Quat anchor_rotation = Normalize(anchor.orientation); if (CameraRecenter* recenter = world.Get(entity)) { - const bool manual = ::abs(yaw_delta) > 1e-6f || ::abs(pitch_delta) > 1e-6f; + const bool manual = ::fabsf(yaw_delta) > 1e-6f || ::fabsf(pitch_delta) > 1e-6f; if (manual) { recenter->idle_time = 0; } else { @@ -237,7 +237,7 @@ void BuildCameraRigs(ecs::World& world, f32 dt) { } void PrepareCameraRigConstraints(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt < 0) dt = 0; + if (!isfinite(dt) || dt < 0) dt = 0; world.Each( [&](ecs::Entity entity, CameraRigPose& pose, CameraAnchor&, CameraMode&) { @@ -265,7 +265,7 @@ void PrepareCameraRigConstraints(ecs::World& world, f32 dt) { } void ResolveCameraRigs(ecs::World& world, f32 dt) { - if (!::isfinite(dt) || dt < 0) dt = 0; + if (!isfinite(dt) || dt < 0) dt = 0; world.Each([&](ecs::Entity entity, CameraRigPose& pose, CameraAnchor& anchor, CameraMode& mode) { diff --git a/engine/scene/scene_handlers.cc b/engine/scene/scene_handlers.cc index 11a70026..5d6c04bd 100644 --- a/engine/scene/scene_handlers.cc +++ b/engine/scene/scene_handlers.cc @@ -64,7 +64,7 @@ bool InverseTransformPoint(const Mat4& m, Vec3 point, Vec3* result) { const f64 c1xc2y = c1z * c2x - c1x * c2z; const f64 c1xc2z = c1x * c2y - c1y * c2x; const f64 det = c0x * c1xc2x + c0y * c1xc2y + c0z * c1xc2z; - if (det == 0 || !::isfinite(det)) return false; + if (det == 0 || !isfinite(det)) return false; const f64 dx = static_cast(point.x) - m.m[12]; const f64 dy = static_cast(point.y) - m.m[13]; @@ -78,9 +78,9 @@ bool InverseTransformPoint(const Mat4& m, Vec3 point, Vec3* result) { dy * (c0z * c1x - c0x * c1z) + dz * (c0x * c1y - c0y * c1x)) / det; - if (!::isfinite(x) || !::isfinite(y) || !::isfinite(z)) return false; + if (!isfinite(x) || !isfinite(y) || !isfinite(z)) return false; const Vec3 local{static_cast(x), static_cast(y), static_cast(z)}; - if (!::isfinite(local.x) || !::isfinite(local.y) || !::isfinite(local.z)) + if (!isfinite(local.x) || !isfinite(local.y) || !isfinite(local.z)) return false; *result = local; return true; diff --git a/engine/scene/world_streaming.cc b/engine/scene/world_streaming.cc index 32a1306c..d333f1e8 100644 --- a/engine/scene/world_streaming.cc +++ b/engine/scene/world_streaming.cc @@ -14,10 +14,10 @@ namespace { constexpr f32 kDistanceQuantization = 1024.0f; bool IsFinite(const Vec3& value) { - return ::isfinite(value.x) && ::isfinite(value.y) && ::isfinite(value.z); + return isfinite(value.x) && isfinite(value.y) && isfinite(value.z); } -f32 NonNegative(f32 value) { return ::isfinite(value) && value > 0 ? value : 0; } +f32 NonNegative(f32 value) { return isfinite(value) && value > 0 ? value : 0; } u8 SanitizeAxes(u8 axes) { axes &= kWorldStreamXYZ; @@ -27,8 +27,8 @@ u8 SanitizeAxes(u8 axes) { WorldStreamObservation SanitizeObservation(WorldStreamObservation observer) { observer.axes = SanitizeAxes(observer.axes); auto sanitize_axis = [&](u8 axis, f32* position, f32* velocity) { - if ((observer.axes & axis) == 0 && !::isfinite(*position)) *position = 0; - if (!::isfinite(*velocity)) *velocity = 0; + if ((observer.axes & axis) == 0 && !isfinite(*position)) *position = 0; + if (!isfinite(*velocity)) *velocity = 0; }; sanitize_axis(kWorldStreamX, &observer.position.x, &observer.velocity.x); sanitize_axis(kWorldStreamY, &observer.position.y, &observer.velocity.y); @@ -42,9 +42,9 @@ WorldStreamObservation SanitizeObservation(WorldStreamObservation observer) { } bool HasFiniteActivePosition(const WorldStreamObservation& observer) { - return ((observer.axes & kWorldStreamX) == 0 || ::isfinite(observer.position.x)) && - ((observer.axes & kWorldStreamY) == 0 || ::isfinite(observer.position.y)) && - ((observer.axes & kWorldStreamZ) == 0 || ::isfinite(observer.position.z)); + return ((observer.axes & kWorldStreamX) == 0 || isfinite(observer.position.x)) && + ((observer.axes & kWorldStreamY) == 0 || isfinite(observer.position.y)) && + ((observer.axes & kWorldStreamZ) == 0 || isfinite(observer.position.z)); } bool SanitizeRegion(const WorldStreamRegion& source, WorldStreamRegion* result) { @@ -60,7 +60,7 @@ bool SanitizeRegion(const WorldStreamRegion& source, WorldStreamRegion* result) } f32 SafeDistance(double distance) { - if (!::isfinite(distance) || distance > FLT_MAX) { + if (!isfinite(distance) || distance > FLT_MAX) { return INFINITY; } return static_cast(rx::Max(0.0, distance)); @@ -82,7 +82,7 @@ Vec3 PredictedPosition(const WorldStreamObservation& observer) { ? static_cast(observer.velocity.z) * observer.prediction_seconds : 0.0, }; - const double length = ::hypot(offset[0], offset[1], offset[2]); + const double length = rx::Hypot(offset[0], offset[1], offset[2]); if (length <= 0) return observer.position; const double scale = rx::Min(1.0, static_cast(observer.maximum_prediction_distance) / length); @@ -130,7 +130,7 @@ double PointSegmentDistance(double point_x, double point_y, double point_z, Vec3 length_sq, 0.0, 1.0); } - return ::hypot(relative[0] - segment[0] * t, relative[1] - segment[1] * t, + return rx::Hypot(relative[0] - segment[0] * t, relative[1] - segment[1] * t, relative[2] - segment[2] * t); } @@ -156,9 +156,9 @@ f32 SweptBoundsDistance(const Vec3& start, const Vec3& end, const WorldStreamReg (axes & kWorldStreamZ) ? (static_cast(region.maximum.z) - region.minimum.z) * 0.5 : 0.0, }; - const double radius = ::hypot(extent[0], extent[1], extent[2]); + const double radius = rx::Hypot(extent[0], extent[1], extent[2]); const double distance = PointSegmentDistance(center[0], center[1], center[2], start, end, axes); - if (!::isfinite(distance) || !::isfinite(radius)) { + if (!isfinite(distance) || !isfinite(radius)) { return PointBoundsDistance(start, region, axes); } return SafeDistance(rx::Max(0.0, distance - radius)); diff --git a/engine/terrain/terrain.cc b/engine/terrain/terrain.cc index 0e0f94c3..f37798f5 100644 --- a/engine/terrain/terrain.cc +++ b/engine/terrain/terrain.cc @@ -16,8 +16,8 @@ namespace rx::terrain { namespace { bool IsFinite(Vec3 value) { - return ::isfinite(value.x) && ::isfinite(value.y) && - ::isfinite(value.z); + return isfinite(value.x) && isfinite(value.y) && + isfinite(value.z); } bool CheckedSampleCount(u32 quads, size_t *count) { @@ -106,7 +106,7 @@ TerrainWeights PaintWeights(TerrainWeights old, u32 target, f32 amount, amount = rx::Clamp(amount, 0.0f, 1.0f); const u32 old_target = old.rgba[target]; const u32 new_target = static_cast(rx::Clamp( - ::lround(old_target + (255.0f - old_target) * amount), 0l, 255l)); + ::lroundf(old_target + (255.0f - old_target) * amount), 0l, 255l)); const u32 old_others = 255 - old_target; const u32 new_others = 255 - new_target; @@ -198,7 +198,7 @@ bool RayBounds(Vec3 origin, Vec3 direction, const f32 minima[3] = {bounds.minimum.x, bounds.minimum.y, bounds.minimum.z}; const f32 maxima[3] = {bounds.maximum.x, bounds.maximum.y, bounds.maximum.z}; for (u32 axis = 0; axis < 3; ++axis) { - if (::abs(directions[axis]) < 1e-12f) { + if (::fabsf(directions[axis]) < 1e-12f) { if (origins[axis] < minima[axis] || origins[axis] > maxima[axis]) return false; continue; @@ -224,19 +224,19 @@ bool RayTriangle(Vec3 origin, Vec3 direction, Vec3 a, Vec3 b, Vec3 c, const Vec3 edge_b = c - a; const Vec3 p = Cross(direction, edge_b); const f32 determinant = Dot(edge_a, p); - if (!::isfinite(determinant) || ::abs(determinant) < 1e-8f) + if (!isfinite(determinant) || ::fabsf(determinant) < 1e-8f) return false; const f32 inverse = 1.0f / determinant; const Vec3 relative = origin - a; const f32 u = Dot(relative, p) * inverse; - if (!::isfinite(u) || u < 0 || u > 1) + if (!isfinite(u) || u < 0 || u > 1) return false; const Vec3 q = Cross(relative, edge_a); const f32 v = Dot(direction, q) * inverse; - if (!::isfinite(v) || v < 0 || u + v > 1) + if (!isfinite(v) || v < 0 || u + v > 1) return false; const f32 hit = Dot(edge_b, q) * inverse; - if (!::isfinite(hit) || hit < 0 || hit > maximum_distance) + if (!isfinite(hit) || hit < 0 || hit > maximum_distance) return false; *distance = hit; *normal = Normalize(Cross(edge_a, edge_b)); @@ -252,14 +252,14 @@ Terrain::Terrain() : Terrain(TerrainDesc{}) {} Terrain::Terrain(TerrainDesc desc) : desc_(base::move(desc)) { if (desc_.tile_quads == 0) desc_.tile_quads = 32; - if (!::isfinite(desc_.sample_spacing) || desc_.sample_spacing <= 0) { + if (!isfinite(desc_.sample_spacing) || desc_.sample_spacing <= 0) { desc_.sample_spacing = 1.0f; } - if (!::isfinite(desc_.origin.x)) + if (!isfinite(desc_.origin.x)) desc_.origin.x = 0; - if (!::isfinite(desc_.origin.y)) + if (!isfinite(desc_.origin.y)) desc_.origin.y = 0; - if (!::isfinite(desc_.origin.z)) + if (!isfinite(desc_.origin.z)) desc_.origin.z = 0; if (desc_.layers.empty()) desc_.layers.push_back(TerrainLayer{"Layer 0"}); @@ -308,11 +308,11 @@ bool Terrain::AddOrReplaceTile(TerrainTileKey key, base::Span heights if (!CheckedSampleCount(desc_.tile_quads, &sample_count) || heights.size() != sample_count || (!weights.empty() && weights.size() != sample_count) || - !::isfinite(desc_.tile_quads * desc_.sample_spacing)) { + !isfinite(desc_.tile_quads * desc_.sample_spacing)) { return false; } for (f32 height : heights) { - if (!::isfinite(height)) + if (!isfinite(height)) return false; } @@ -327,7 +327,7 @@ bool Terrain::AddOrReplaceTile(TerrainTileKey key, base::Span heights } } RecalculateBounds(&replacement); - if (!::isfinite(replacement.maximum_height - replacement.minimum_height)) + if (!isfinite(replacement.maximum_height - replacement.minimum_height)) return false; auto insertion = @@ -448,7 +448,7 @@ base::Optional Terrain::GridHeight(i64 grid_x, i64 grid_z) const { } base::Optional Terrain::SampleHeight(f32 world_x, f32 world_z) const { - if (!::isfinite(world_x) || !::isfinite(world_z) || tiles_.empty()) + if (!isfinite(world_x) || !isfinite(world_z) || tiles_.empty()) return base::nullopt; const double grid_x = (static_cast(world_x) - desc_.origin.x) / desc_.sample_spacing; @@ -474,8 +474,8 @@ base::Optional Terrain::SampleHeight(f32 world_x, f32 world_z) const { constexpr double kBoundaryEpsilon = 1e-6; const i64 candidate_x[2] = {base_x, base_x - 1}; const i64 candidate_z[2] = {base_z, base_z - 1}; - const u32 count_x = ::abs(edge_x) <= kBoundaryEpsilon ? 2 : 1; - const u32 count_z = ::abs(edge_z) <= kBoundaryEpsilon ? 2 : 1; + const u32 count_x = ::fabs(edge_x) <= kBoundaryEpsilon ? 2 : 1; + const u32 count_z = ::fabs(edge_z) <= kBoundaryEpsilon ? 2 : 1; const u32 side = desc_.tile_quads + 1; for (u32 cz = 0; cz < count_z; ++cz) { @@ -515,8 +515,8 @@ base::Optional Terrain::SampleHeight(f32 world_x, f32 world_z) const { : d + (1.0f - fraction_x) * (c - d) + (1.0f - fraction_z) * (b - d); const double world_height = static_cast(desc_.origin.y) + height; - if (!::isfinite(world_height) || - ::abs(world_height) > FLT_MAX) { + if (!isfinite(world_height) || + ::fabs(world_height) > FLT_MAX) { return base::nullopt; } return static_cast(world_height); @@ -557,7 +557,7 @@ Terrain::TileRegion(TerrainTileKey key, u32 channels, i32 priority) const { const double values[] = {minimum_x, minimum_y, minimum_z, maximum_x, maximum_y, maximum_z}; for (double value : values) { - if (!::isfinite(value) || value < -maximum_float || + if (!isfinite(value) || value < -maximum_float || value > maximum_float) { return base::nullopt; } @@ -579,7 +579,7 @@ void Terrain::GatherStreamRegions( if (!regions) return; regions->clear(); - if ((query.channels & channels) == 0 || !::isfinite(query.radius) || + if ((query.channels & channels) == 0 || !isfinite(query.radius) || query.radius < 0) return; u8 axes = query.axes & scene::kWorldStreamXYZ; @@ -587,7 +587,7 @@ void Terrain::GatherStreamRegions( axes = scene::kWorldStreamXYZ; auto valid_axis = [&](u8 axis, f32 origin, f32 predicted) { return (axes & axis) == 0 || - (::isfinite(origin) && ::isfinite(predicted)); + (isfinite(origin) && isfinite(predicted)); }; if (!valid_axis(scene::kWorldStreamX, query.origin.x, query.predicted.x) || !valid_axis(scene::kWorldStreamY, query.origin.y, query.predicted.y) || @@ -629,7 +629,7 @@ Terrain::BuildTileMesh(TerrainTileKey key, asset::AssetId material) const { const u32 quads = desc_.tile_quads; const u32 side = quads + 1; const f32 width = static_cast(quads) * desc_.sample_spacing; - if (!::isfinite(width)) + if (!isfinite(width)) return base::nullopt; asset::Mesh mesh; @@ -696,7 +696,7 @@ Terrain::BuildTileMesh(TerrainTileKey key, asset::AssetId material) const { (tile->maximum_height - tile->minimum_height) * 0.5f; mesh.bounds_center[2] = width * 0.5f; const f32 half_height = (tile->maximum_height - tile->minimum_height) * 0.5f; - mesh.bounds_radius = ::hypot(width * 0.5f, width * 0.5f, half_height); + mesh.bounds_radius = rx::Hypot(width * 0.5f, width * 0.5f, half_height); return mesh; } @@ -706,8 +706,8 @@ base::Optional Terrain::Raycast(Vec3 origin, Vec3 direction, ::isnan(maximum_distance) || maximum_distance < 0) { return base::nullopt; } - const double length = ::hypot(direction.x, direction.y, direction.z); - if (!::isfinite(length) || length <= 0) + const double length = rx::Hypot(direction.x, direction.y, direction.z); + if (!isfinite(length) || length <= 0) return base::nullopt; direction = {static_cast(static_cast(direction.x) / length), static_cast(static_cast(direction.y) / length), @@ -733,8 +733,8 @@ base::Optional Terrain::Raycast(Vec3 origin, Vec3 direction, minimum_x + width, maximum_y, minimum_z + width}; bool valid_bounds = true; for (double value : values) { - if (!::isfinite(value) || - ::abs(value) > FLT_MAX) { + if (!isfinite(value) || + ::fabs(value) > FLT_MAX) { valid_bounds = false; break; } @@ -786,12 +786,12 @@ base::Optional Terrain::Raycast(Vec3 origin, Vec3 direction, TerrainChange Terrain::ApplyBrush(const TerrainBrush &brush) { TerrainChange change; change.terrain = desc_.id; - if (!::isfinite(brush.center_x) || !::isfinite(brush.center_z) || - !::isfinite(brush.radius) || brush.radius <= 0 || - !::isfinite(brush.strength) || brush.strength <= 0 || - !::isfinite(brush.falloff) || brush.falloff < 0 || + if (!isfinite(brush.center_x) || !isfinite(brush.center_z) || + !isfinite(brush.radius) || brush.radius <= 0 || + !isfinite(brush.strength) || brush.strength <= 0 || + !isfinite(brush.falloff) || brush.falloff < 0 || (brush.mode == TerrainBrushMode::kFlatten && - !::isfinite(brush.flatten_target)) || + !isfinite(brush.flatten_target)) || (brush.mode == TerrainBrushMode::kPaintLayer && brush.layer >= ActiveLayerCount(desc_))) { return change; @@ -826,7 +826,7 @@ TerrainChange Terrain::ApplyBrush(const TerrainBrush &brush) { continue; const f32 radial = rx::Max(0.0f, 1.0f - distance / brush.radius); const f32 influence = - brush.falloff == 0 ? 1.0f : ::pow(radial, brush.falloff); + brush.falloff == 0 ? 1.0f : ::powf(radial, brush.falloff); if (influence <= 0) continue; @@ -872,7 +872,7 @@ TerrainChange Terrain::ApplyBrush(const TerrainBrush &brush) { ActiveLayerCount(desc_)); break; } - if (!::isfinite(new_value.height) || new_value == old_value) + if (!isfinite(new_value.height) || new_value == old_value) continue; change.samples.push_back({tile.key, index, old_value, new_value}); } @@ -973,7 +973,7 @@ bool Terrain::SetChangeState(const TerrainChange &change, bool use_new) { use_new ? sample.new_value : sample.old_value; const TerrainSampleState &expected = use_new ? sample.old_value : sample.new_value; - if (!::isfinite(wanted.height) || + if (!isfinite(wanted.height) || !IsNormalized(wanted.weights, layer_count) || tile->heights[sample.sample] != expected.height || tile->weights[sample.sample] != expected.weights) { diff --git a/engine/terrain/terrain_io.cc b/engine/terrain/terrain_io.cc index 312510b3..b3c4ddc1 100644 --- a/engine/terrain/terrain_io.cc +++ b/engine/terrain/terrain_io.cc @@ -91,15 +91,15 @@ bool GetSampleCount(u32 quads, u32 *count) { bool ValidateTerrain(const Terrain &terrain, u32 *sample_count, base::String *error) { const TerrainDesc &desc = terrain.desc(); - if (!desc.id || !::isfinite(desc.origin.x) || !::isfinite(desc.origin.y) || - !::isfinite(desc.origin.z) || !::isfinite(desc.sample_spacing) || + if (!desc.id || !isfinite(desc.origin.x) || !isfinite(desc.origin.y) || + !isfinite(desc.origin.z) || !isfinite(desc.sample_spacing) || desc.sample_spacing <= 0 || !GetSampleCount(desc.tile_quads, sample_count)) { SetError(error, "terrain has invalid dimensions or non-finite metadata"); return false; } const f32 tile_width = desc.tile_quads * desc.sample_spacing; - if (!::isfinite(tile_width)) { + if (!isfinite(tile_width)) { SetError(error, "terrain tile width is not finite"); return false; } @@ -132,7 +132,7 @@ bool ValidateTerrain(const Terrain &terrain, u32 *sample_count, previous = tile.key; has_previous = true; for (u32 i = 0; i < *sample_count; ++i) { - if (!::isfinite(tile.heights[i]) || + if (!isfinite(tile.heights[i]) || !IsNormalized(tile.weights[i], static_cast(desc.layers.size()))) { SetError(error, "terrain tile contains invalid height or weight data"); @@ -281,7 +281,7 @@ bool SaveTerrain(const Terrain &terrain, const base::String &file_path, } const f32 minimum = *minimum_it; const f32 range = *maximum_it - minimum; - if (!::isfinite(range)) { + if (!isfinite(range)) { SetError(error, "terrain tile height range is not finite"); return false; } @@ -384,12 +384,12 @@ bool LoadTerrain(const base::String &file_path, Terrain *terrain, return false; } u32 sample_count = 0; - if (!desc.id || !::isfinite(desc.origin.x) || - !::isfinite(desc.origin.y) || - !::isfinite(desc.origin.z) || !::isfinite(desc.sample_spacing) || + if (!desc.id || !isfinite(desc.origin.x) || + !isfinite(desc.origin.y) || + !isfinite(desc.origin.z) || !isfinite(desc.sample_spacing) || desc.sample_spacing <= 0 || !GetSampleCount(desc.tile_quads, &sample_count) || - !::isfinite(desc.tile_quads * desc.sample_spacing) || + !isfinite(desc.tile_quads * desc.sample_spacing) || layer_count == 0 || layer_count > kMaximumLayers || tile_count > kMaximumTiles || static_cast(tile_count) * sample_count > kMaximumTotalSamples) { @@ -432,8 +432,8 @@ bool LoadTerrain(const base::String &file_path, Terrain *terrain, SetError(error, "terrain tile header is truncated"); return false; } - if ((has_previous && !KeyLess(previous, key)) || !::isfinite(minimum) || - !::isfinite(range) || range < 0 || !::isfinite(minimum + range) || + if ((has_previous && !KeyLess(previous, key)) || !isfinite(minimum) || + !isfinite(range) || range < 0 || !isfinite(minimum + range) || stored_samples != sample_count || stored_weight_bytes != sample_count * 4 || reader.remaining() < static_cast(sample_count) * 6) { @@ -451,7 +451,7 @@ bool LoadTerrain(const base::String &file_path, Terrain *terrain, return false; } height = minimum + range * (static_cast(quantized) / 65535.0f); - if (!::isfinite(height)) { + if (!isfinite(height)) { SetError(error, "terrain height data is not finite"); return false; } diff --git a/engine/weather/weather.cc b/engine/weather/weather.cc index ac1c1edb..3438ac27 100644 --- a/engine/weather/weather.cc +++ b/engine/weather/weather.cc @@ -39,12 +39,12 @@ constexpr f32 kStrikeMinRange = 100.0f; constexpr f32 kStrikeMaxRange = 300.0f; f32 Clamp01(f32 v) { - if (!::isfinite(v)) return 0.0f; + if (!isfinite(v)) return 0.0f; return v < 0.0f ? 0.0f : (v > 1.0f ? 1.0f : v); } f32 Lerpf(f32 a, f32 b, f32 t) { return a + (b - a) * t; } f32 LerpAngle(f32 a, f32 b, f32 t) { - f32 delta = ::fmod(b - a + kPi, kTwoPi); + f32 delta = ::fmodf(b - a + kPi, kTwoPi); if (delta < 0.0f) delta += kTwoPi; return a + (delta - kPi) * t; @@ -88,7 +88,7 @@ WeatherSystem::WeatherSystem(u32 rng_seed) : rng_(rng_seed ? rng_seed : 1u) {} u32 WeatherSystem::AddState(const WeatherState &state) { WeatherState clean = state; auto finite_or = [](f32 value, f32 fallback) { - return ::isfinite(value) ? value : fallback; + return isfinite(value) ? value : fallback; }; clean.coverage = Clamp01(clean.coverage); clean.cloud_type = Clamp01(clean.cloud_type); @@ -101,7 +101,7 @@ u32 WeatherSystem::AddState(const WeatherState &state) { clean.top_altitude = rx::Clamp(finite_or(clean.top_altitude, clean.base_altitude + 1.0f), clean.base_altitude + 1.0f, 200000.0f); - clean.wind_yaw = ::remainder(finite_or(clean.wind_yaw, 0.0f), kTwoPi); + clean.wind_yaw = ::remainderf(finite_or(clean.wind_yaw, 0.0f), kTwoPi); clean.wind_speed = rx::Clamp(finite_or(clean.wind_speed, 0.0f), 0.0f, 200.0f); clean.vertical_skew = rx::Clamp(finite_or(clean.vertical_skew, 0.0f), -100000.0f, 100000.0f); @@ -129,13 +129,13 @@ u32 WeatherSystem::AddState(const WeatherState &state) { u32 WeatherSystem::AddRegion(const WeatherRegion ®ion) { WeatherRegion clean = region; - if (!::isfinite(clean.min_xz.x) || !::isfinite(clean.min_xz.y) || - !::isfinite(clean.max_xz.x) || !::isfinite(clean.max_xz.y)) { + if (!isfinite(clean.min_xz.x) || !isfinite(clean.min_xz.y) || + !isfinite(clean.max_xz.x) || !isfinite(clean.max_xz.y)) { clean.min_xz = {}; clean.max_xz = {}; } for (f32 &weight : clean.weights) { - weight = ::isfinite(weight) ? rx::Clamp(weight, 0.0f, 1000000.0f) + weight = isfinite(weight) ? rx::Clamp(weight, 0.0f, 1000000.0f) : 0.0f; } regions_.push_back(base::move(clean)); @@ -152,7 +152,7 @@ void WeatherSystem::ForceState(u32 state_index, f32 transition_seconds) { if (state_index >= states_.size()) { state_index = static_cast(states_.size() - 1); } - if (!::isfinite(transition_seconds)) + if (!isfinite(transition_seconds)) transition_seconds = 0.0f; forced_ = true; started_ = true; // a forced state suppresses the first-frame region auto-pick @@ -243,10 +243,10 @@ u32 WeatherSystem::PickNext(const Vec3 &player_pos, f32 time_of_day01) { // Day phase in [0,1]: 0 at midnight (fully night), 1 at noon (fully day), // smoothly through dawn/dusk. Biases each candidate's weight toward its // day_weight or night_weight. - f32 dayness = 0.5f - 0.5f * ::cos(kTwoPi * time_of_day01); + f32 dayness = 0.5f - 0.5f * ::cosf(kTwoPi * time_of_day01); auto effective_weight = [&](u32 idx, f32 base) -> f32 { - if (!::isfinite(base) || base <= 0.0f) + if (!isfinite(base) || base <= 0.0f) return 0.0f; const WeatherState &s = states_[idx]; f32 mult = Lerpf(s.night_weight, s.day_weight, dayness); @@ -414,8 +414,8 @@ void WeatherSystem::IntegrateTornado(f32 dt, const Vec3 &player_pos, f32 out = 1.0f - Smoothstep((tornado_age_ - tornado_dur_ + 9.0f) / 9.0f); cloudscape_.tornado_strength = ramp * out; f32 speed = cloudscape_.wind_speed * 0.55f; - f32 wob = ::sin(tornado_age_ * 0.31f) * 0.6f; - Vec2 dir{::cos(cloudscape_.wind_yaw), ::sin(cloudscape_.wind_yaw)}; + f32 wob = ::sinf(tornado_age_ * 0.31f) * 0.6f; + Vec2 dir{::cosf(cloudscape_.wind_yaw), ::sinf(cloudscape_.wind_yaw)}; tornado_pos_.x += (dir.x - dir.y * wob) * speed * dt; tornado_pos_.y += (dir.y + dir.x * wob) * speed * dt; cloudscape_.tornado_pos = tornado_pos_; @@ -425,7 +425,7 @@ void WeatherSystem::IntegrateTornado(f32 dt, const Vec3 &player_pos, f32 u = NextF32(); if (u < 1e-4f) u = 1e-4f; - tornado_timer_ = -kTornadoMeanInterval * ::log(u); + tornado_timer_ = -kTornadoMeanInterval * ::logf(u); } return; } @@ -437,7 +437,7 @@ void WeatherSystem::IntegrateTornado(f32 dt, const Vec3 &player_pos, if (tornado_timer_ > 0.0f) return; // Touch down upwind of the player so the track carries the funnel past. - Vec2 dir{::cos(cloudscape_.wind_yaw), ::sin(cloudscape_.wind_yaw)}; + Vec2 dir{::cosf(cloudscape_.wind_yaw), ::sinf(cloudscape_.wind_yaw)}; f32 upwind = RandomRange(400.0f, 1100.0f); f32 crosswind = RandomRange(-350.0f, 350.0f); tornado_pos_ = Vec2{player_pos.x - dir.x * upwind - dir.y * crosswind, @@ -483,11 +483,11 @@ bool WeatherSystem::IntegrateLightning(f32 dt, const Vec3 &player_pos, base::Swap(min_r, max_r); f32 ang = RandomRange(0.0f, kTwoPi); f32 range = RandomRange(min_r, max_r); - f32 sx = player_pos.x + ::cos(ang) * range; - f32 sz = player_pos.z + ::sin(ang) * range; + f32 sx = player_pos.x + ::cosf(ang) * range; + f32 sz = player_pos.z + ::sinf(ang) * range; f32 strike_ground = ground_(sx, sz); weather_.strike_pos = - Vec3{sx, ::isfinite(strike_ground) ? strike_ground : 0.0f, sz}; + Vec3{sx, isfinite(strike_ground) ? strike_ground : 0.0f, sz}; weather_.strike_seed = NextU32(); weather_.strike_energy = RandomRange(0.6f, 1.0f); weather_.strike_age = 0.0f; @@ -495,7 +495,7 @@ bool WeatherSystem::IntegrateLightning(f32 dt, const Vec3 &player_pos, f32 u = NextF32(); if (u < 1e-4f) u = 1e-4f; - strike_timer_ = -kStrikeMeanInterval * ::log(u); + strike_timer_ = -kStrikeMeanInterval * ::logf(u); } } @@ -508,7 +508,7 @@ bool WeatherSystem::IntegrateLightning(f32 dt, const Vec3 &player_pos, if (weather_.strike_age >= 0.0f) { f32 dx = weather_.strike_pos.x - player_pos.x; f32 dz = weather_.strike_pos.z - player_pos.z; - f32 dist = ::sqrt(dx * dx + dz * dz); + f32 dist = ::sqrtf(dx * dx + dz * dz); f32 near_w = 600.0f / (600.0f + dist); f32 falloff = 0.08f + 0.92f * near_w * near_w; weather_.lightning = render::LightningEnvelope( @@ -523,12 +523,12 @@ bool WeatherSystem::IntegrateLightning(f32 dt, const Vec3 &player_pos, void WeatherSystem::Update(f32 dt, const Vec3 &player_pos, f32 time_of_day01) { if (states_.empty()) return; // no states: leave the default outputs untouched - if (!::isfinite(dt) || dt < 0.0f) + if (!isfinite(dt) || dt < 0.0f) return; - if (!::isfinite(player_pos.x) || !::isfinite(player_pos.y) || - !::isfinite(player_pos.z)) + if (!isfinite(player_pos.x) || !isfinite(player_pos.y) || + !isfinite(player_pos.z)) return; - if (!::isfinite(time_of_day01)) + if (!isfinite(time_of_day01)) time_of_day01 = 0.0f; dt = rx::Min(dt, 60.0f); @@ -593,7 +593,7 @@ void WeatherSystem::Update(f32 dt, const Vec3 &player_pos, f32 time_of_day01) { if (slice > 0.0f) { f32 yaw = cloudscape_.wind_yaw; f32 speed = cloudscape_.wind_speed; - map_offset_ += Vec2{::cos(yaw), ::sin(yaw)} * (speed * slice); + map_offset_ += Vec2{::cosf(yaw), ::sinf(yaw)} * (speed * slice); cloudscape_.map_offset = map_offset_; IntegrateSurface(slice, weather_.precipitation, weather_.snow); @@ -610,7 +610,7 @@ void WeatherSystem::Update(f32 dt, const Vec3 &player_pos, f32 time_of_day01) { IntegrateTornado(slice, player_pos, cloudscape_.anvil); } f32 local_ground = ground_(player_pos.x, player_pos.z); - cloudscape_.fog_ground = ::isfinite(local_ground) ? local_ground : 0.0f; + cloudscape_.fog_ground = isfinite(local_ground) ? local_ground : 0.0f; remaining -= slice; first_slice = false; diff --git a/engine/world/world_bake.cc b/engine/world/world_bake.cc index 56cd3a32..88a3a84c 100644 --- a/engine/world/world_bake.cc +++ b/engine/world/world_bake.cc @@ -83,11 +83,11 @@ f32 CellOrigin(i64 coord, f32 size) { return static_cast(static_cast(transform.position[axis]) / cell_size; - if (!(::abs(quotient) < static_cast(kMaximumCellCoord))) return false; + if (!(::fabs(quotient) < static_cast(kMaximumCellCoord))) return false; } return true; } @@ -211,7 +211,7 @@ BakeVerdict ClassifyForBake(ecs::World& world, ecs::Entity entity, verdict.refusal = "has a Parent, which is an ecs handle no baked cell can carry"; return verdict; } - const f32 cell_size = options.cell_size > 0 && ::isfinite(options.cell_size) + const f32 cell_size = options.cell_size > 0 && isfinite(options.cell_size) ? options.cell_size : 64.0f; if (!InLattice(*transform, cell_size)) { @@ -255,7 +255,7 @@ bool BakeWorld(const base::String& scene_path, const WorldBakeOptions& input_opt *result = WorldBakeResult{}; WorldBakeOptions options = input_options; - if (!(options.cell_size > 0) || !::isfinite(options.cell_size)) { + if (!(options.cell_size > 0) || !isfinite(options.cell_size)) { SetError(error, "cell size must be a positive, finite number"); return false; } diff --git a/engine/world/world_format.cc b/engine/world/world_format.cc index ad56bc12..ccba6beb 100644 --- a/engine/world/world_format.cc +++ b/engine/world/world_format.cc @@ -200,7 +200,7 @@ bool StringTableTerminated(const base::Vector& table) { } bool IsFinite(const Vec3& value) { - return ::isfinite(value.x) && ::isfinite(value.y) && ::isfinite(value.z); + return isfinite(value.x) && isfinite(value.y) && isfinite(value.z); } bool ValidDomain(u8 value) { return value < kDomainCount; } @@ -377,7 +377,7 @@ bool WorldIndexWriter::Encode(base::Vector* out, base::String* error) const // same things here is what keeps the cook from succeeding on an archive its // own loader will not open: a bake that fails at the end of a cook is a bad // afternoon, one that fails at the start of a play session is a bug report. - if (!::isfinite(cell_size_) || cell_size_ < 0) { + if (!isfinite(cell_size_) || cell_size_ < 0) { SetError(error, "world index: grid cell size is not a finite, non-negative number"); return false; } @@ -555,7 +555,7 @@ bool DecodeWorldIndex(base::Span bytes, WorldIndexData* out, base::Str // is not a finite, non-negative number is a corrupt header, and substituting // zero for it would read as that legitimate answer. Both fields are inside // the checksum, so reaching here with either wrong means a wrong cook. - if (!::isfinite(cell_size) || cell_size < 0) { + if (!isfinite(cell_size) || cell_size < 0) { SetError(error, "world index: grid cell size is not a finite, non-negative number"); return false; } @@ -767,9 +767,9 @@ bool CellPayloadWriter::Encode(base::Vector* out, base::String* error) const } // A transform nothing can draw, refused where it was produced rather than // on the machine that tries to load the cell. - if (!IsFinite(instance.position) || !::isfinite(instance.rotation.x) || - !::isfinite(instance.rotation.y) || !::isfinite(instance.rotation.z) || - !::isfinite(instance.rotation.w) || !::isfinite(instance.scale)) { + if (!IsFinite(instance.position) || !isfinite(instance.rotation.x) || + !isfinite(instance.rotation.y) || !isfinite(instance.rotation.z) || + !isfinite(instance.rotation.w) || !isfinite(instance.scale)) { SetError(error, "cell payload: instance " + rx::ToString(instance.stable_id) + " has a non-finite transform"); return false; @@ -1085,9 +1085,9 @@ bool DecodeCellPayload(base::Span bytes, WorldCellPayload* out, base:: rx::ToString(record.prototype)); return false; } - if (!IsFinite(record.position) || !::isfinite(record.rotation.x) || - !::isfinite(record.rotation.y) || !::isfinite(record.rotation.z) || - !::isfinite(record.rotation.w) || !::isfinite(record.scale)) { + if (!IsFinite(record.position) || !isfinite(record.rotation.x) || + !isfinite(record.rotation.y) || !isfinite(record.rotation.z) || + !isfinite(record.rotation.w) || !isfinite(record.scale)) { SetError(error, "cell payload: instance " + rx::ToString(i) + " has a non-finite transform"); return false; diff --git a/engine/world/world_map.cc b/engine/world/world_map.cc index 239bf0d2..15acefe1 100644 --- a/engine/world/world_map.cc +++ b/engine/world/world_map.cc @@ -142,7 +142,7 @@ void WorldMap::GatherRegions(const scene::WorldStreamObservation& observer, Doma } WorldStreamPolicy DefaultWorldStreamPolicy(f32 scale) { - const f32 unit = ::isfinite(scale) && scale > 0 ? scale : 1.0f; + const f32 unit = isfinite(scale) && scale > 0 ? scale : 1.0f; WorldStreamPolicy policy; auto set = [&](Domain domain, f32 load, f32 retain, f32 full, u32 rows_per_commit) { DomainStreamPolicy& target = policy[domain]; @@ -193,7 +193,7 @@ bool InNearTierBand(const DomainStreamPolicy& policy, f32 distance, bool current const f32 margin = policy.tier_hysteresis > 1.0f ? policy.tier_hysteresis : 1.0f; const f32 threshold = currently_near ? policy.full_tier_distance * margin : policy.full_tier_distance; - return ::isfinite(distance) && distance <= threshold; + return isfinite(distance) && distance <= threshold; } Tier ResolveTier(const WorldIndexData& index, const WorldCellRecord& cell, Domain domain, diff --git a/engine/world/world_overlay.cc b/engine/world/world_overlay.cc index 6f1b47ee..84736029 100644 --- a/engine/world/world_overlay.cc +++ b/engine/world/world_overlay.cc @@ -90,10 +90,10 @@ class Cursor { }; bool Finite(const OverlayMove& move) { - return ::isfinite(move.position.x) && ::isfinite(move.position.y) && - ::isfinite(move.position.z) && ::isfinite(move.rotation.x) && - ::isfinite(move.rotation.y) && ::isfinite(move.rotation.z) && - ::isfinite(move.rotation.w) && ::isfinite(move.scale); + return isfinite(move.position.x) && isfinite(move.position.y) && + isfinite(move.position.z) && isfinite(move.rotation.x) && + isfinite(move.rotation.y) && isfinite(move.rotation.z) && + isfinite(move.rotation.w) && isfinite(move.scale); } } // namespace diff --git a/runtime/camera_input.cc b/runtime/camera_input.cc index 1e8ef52f..c9b7f18a 100644 --- a/runtime/camera_input.cc +++ b/runtime/camera_input.cc @@ -54,8 +54,8 @@ void Viewer::UpdateCamera(f32 frame_delta) { void Viewer::LookCameraAt(const Vec3& eye, const Vec3& center) { camera_.set_position(eye); Vec3 d = Normalize(center - eye); - camera_.set_yaw_pitch(::atan2(d.x, -d.z), - ::asin(rx::Clamp(d.y, -1.0f, 1.0f))); // forward() convention + camera_.set_yaw_pitch(::atan2f(d.x, -d.z), + ::asinf(rx::Clamp(d.y, -1.0f, 1.0f))); // forward() convention } void Viewer::DriveCamera(f32 dt) { @@ -152,7 +152,7 @@ void Viewer::DriveCamera(f32 dt) { } else if (cam_orbit_) { f32 a = cam_time_ * 0.4f; // radians/sec Vec3 center{0.0f, 1.0f, 0.0f}; - LookCameraAt({center.x + ::cos(a) * 6.0f, 2.4f, center.z + ::sin(a) * 6.0f}, center); + LookCameraAt({center.x + ::cosf(a) * 6.0f, 2.4f, center.z + ::sinf(a) * 6.0f}, center); } else if (!cam_replay_.empty()) { // Linear interpolation between the bracketing keys for the current time. const CamKey* lo = &cam_replay_[0]; diff --git a/runtime/demo_drive.cc b/runtime/demo_drive.cc index b55fc4d0..d8ff6906 100644 --- a/runtime/demo_drive.cc +++ b/runtime/demo_drive.cc @@ -154,31 +154,31 @@ u8 RegionAt(f32 x, f32 z) { // Runway: a long asphalt strip on the -X side. if (x >= -74.0f && x <= -50.0f && z >= -152.0f && z <= 152.0f) return kAsphalt; // Road loop centred on the origin (a square ring band). - const f32 m = rx::Max(::fabs(x), ::fabs(z)); + const f32 m = rx::Max(::fabsf(x), ::fabsf(z)); if (m >= 40.0f && m <= 57.0f) { - if (x >= 40.0f && x <= 57.0f && ::fabs(z) <= 9.0f) return kIce; // ice on the east straight + if (x >= 40.0f && x <= 57.0f && ::fabsf(z) <= 9.0f) return kIce; // ice on the east straight return kAsphalt; } // Dirt field just inside the loop's north-west. if (x >= -46.0f && x <= -12.0f && z >= 40.0f && z <= 84.0f) return kDirt; // Sand beach ringing the lake. - const f32 ld = ::sqrt((x - kLakeCx) * (x - kLakeCx) + (z - kLakeCz) * (z - kLakeCz)); + const f32 ld = ::sqrtf((x - kLakeCx) * (x - kLakeCx) + (z - kLakeCz) * (z - kLakeCz)); if (ld >= 66.0f && ld <= 92.0f) return kSand; return kGrass; } f32 HeightAt(f32 x, f32 z) { - f32 h = 1.8f * ::sin(x * 0.017f) * ::cos(z * 0.019f) + - 1.1f * ::sin((x + z) * 0.011f + 0.6f); + f32 h = 1.8f * ::sinf(x * 0.017f) * ::cosf(z * 0.019f) + + 1.1f * ::sinf((x + z) * 0.011f + 0.6f); // Lake basin: dip below the water surface toward the centre. - const f32 ld = ::sqrt((x - kLakeCx) * (x - kLakeCx) + (z - kLakeCz) * (z - kLakeCz)); + const f32 ld = ::sqrtf((x - kLakeCx) * (x - kLakeCx) + (z - kLakeCz) * (z - kLakeCz)); if (ld < 104.0f) { const f32 t = SmoothStep((104.0f - ld) / (104.0f - 40.0f)); h = h + (-6.0f - h) * t; } // Flatten the road loop and the runway so the wheeled vehicles roll on level // ground and the plane has a real runway. - const f32 m = rx::Max(::fabs(x), ::fabs(z)); + const f32 m = rx::Max(::fabsf(x), ::fabsf(z)); const f32 road_w = Feather(m, 40.0f, 57.0f, 3.0f); h = h + (0.0f - h) * road_w; const f32 rw = Feather(x, -74.0f, -50.0f, 3.0f) * Feather(z, -152.0f, 152.0f, 4.0f); @@ -273,7 +273,7 @@ asset::Mesh FinishMesh(MeshBuild& mb, const char* id, asset::AssetId material) { lod.submeshes.push_back({0, static_cast(mb.i.size()), material}); f32 r = 0; for (const asset::Vertex& vert : mb.v) - r = rx::Max(r, ::sqrt(vert.position[0] * vert.position[0] + + r = rx::Max(r, ::sqrtf(vert.position[0] * vert.position[0] + vert.position[1] * vert.position[1] + vert.position[2] * vert.position[2])); mesh.bounds_radius = r; @@ -540,7 +540,7 @@ void DriveDemo::BuildWater() { // the car's tires never read the dry world as submerged. ctx_.physics->set_water_height([](const Vec3& p, f32* height, Vec3* flow) { const f32 d = - ::sqrt((p.x - kLakeCx) * (p.x - kLakeCx) + (p.z - kLakeCz) * (p.z - kLakeCz)); + ::sqrtf((p.x - kLakeCx) * (p.x - kLakeCx) + (p.z - kLakeCz) * (p.z - kLakeCz)); if (d > kLakeWaterRadius) return false; *height = kLakeY; if (flow) *flow = {}; @@ -561,13 +561,13 @@ void DriveDemo::BuildWheelMesh() { const f32 a = t * 2.0f * kPi; for (int k = 0; k < 2; ++k) { asset::Vertex v{}; - v.position[0] = ::cos(a); + v.position[0] = ::cosf(a); v.position[1] = k ? 0.5f : -0.5f; - v.position[2] = ::sin(a); - v.normal[0] = ::cos(a); - v.normal[2] = ::sin(a); - v.tangent[0] = -::sin(a); - v.tangent[2] = ::cos(a); + v.position[2] = ::sinf(a); + v.normal[0] = ::cosf(a); + v.normal[2] = ::sinf(a); + v.tangent[0] = -::sinf(a); + v.tangent[2] = ::cosf(a); v.tangent[3] = 1; v.uv[0] = t * 4.0f; v.uv[1] = k ? 1.0f : 0.0f; @@ -601,8 +601,8 @@ void DriveDemo::BuildBoatHull() { const f32 ws = width_scale(z); for (u32 pj = 0; pj <= kPr; ++pj) { const f32 th = kPi * static_cast(pj) / kPr; - const f32 x = -kHB * ws * ::cos(th); - const f32 y = kDeck - (kDeck - kKeel) * ::pow(::sin(th), 0.62f); + const f32 x = -kHB * ws * ::cosf(th); + const f32 y = kDeck - (kDeck - kKeel) * ::powf(::sinf(th), 0.62f); hb.Add({x, y, z}, static_cast(pj) / kPr, z / 4.0f); } } @@ -899,7 +899,7 @@ void DriveDemo::SetCarProfile(u32 index) { f32 rot[4]; if (ctx_.physics->GetVehicleTransform(car_, &pos, rot)) { const Vec3 fwd = Rotate(Quat{rot[0], rot[1], rot[2], rot[3]}, Vec3{0, 0, 1}); - yaw = ::atan2(fwd.x, fwd.z); + yaw = ::atan2f(fwd.x, fwd.z); } ctx_.physics->RemoveVehicle(car_); } @@ -926,7 +926,7 @@ void DriveDemo::SetBoatProfile(u32 index) { const physics::BoatState& s = boat_->state(); const Vec3 fwd = Rotate(s.rotation, Vec3{0, 0, 1}); pos = {s.position.x, boat_spawn_.y, s.position.z}; - yaw = ::atan2(fwd.x, fwd.z); + yaw = ::atan2f(fwd.x, fwd.z); ctx_.physics->RemoveBody(boat_->body()); // Boat has no dtor cleanup } boat_ = base::MakeUnique(*ctx_.physics, boat_desc_, pos, yaw); @@ -1070,14 +1070,14 @@ void DriveDemo::Update(f32 dt, const InputState& input, const ActionState& actio if (ctx_.physics->GetVehicleState(car_, &vs)) { st.rpm = vs.rpm; st.load = vs.engine_load; - st.speed_mps = ::fabs(vs.forward_speed); + st.speed_mps = ::fabsf(vs.forward_speed); st.gear = vs.gear; st.is_shifting = vs.is_shifting; st.wheel_count = vs.wheel_count; for (u32 i = 0; i < vs.wheel_count && i < 4; ++i) st.wheel_slip[i] = vs.wheels[i].longitudinal_slip; } - st.throttle = ::fabs(car_throttle_); + st.throttle = ::fabsf(car_throttle_); st.slip = CarMaxSlip(); st.position = p; car_audio_->Update(st); @@ -1148,7 +1148,7 @@ void DriveDemo::UpdateChaseCamera(f32 dt, const InputState& input, const ActionS cam_target_ = desired_target; cam_init_ = true; } else { - const f32 a = 1.0f - ::exp(-dt / 0.2f); + const f32 a = 1.0f - ::expf(-dt / 0.2f); cam_eye_ = Lerp(cam_eye_, desired_eye, a); cam_target_ = Lerp(cam_target_, desired_target, a); } @@ -1163,7 +1163,7 @@ void DriveDemo::UpdateChaseCamera(f32 dt, const InputState& input, const ActionS cam_target_ = desired_target; cam_init_ = true; } else { - const f32 a = 1.0f - ::exp(-dt / 0.14f); + const f32 a = 1.0f - ::expf(-dt / 0.14f); cam_eye_ = Lerp(cam_eye_, desired_eye, a); cam_target_ = Lerp(cam_target_, desired_target, a); } @@ -1314,7 +1314,7 @@ void DriveDemo::DrawPanel() { static_cast(car_desc_.mass)); physics::PhysicsWorld::VehicleState vs; if (ctx_.physics->GetVehicleState(car_, &vs)) { - const f32 kmh = ::fabs(vs.forward_speed) * 3.6f; + const f32 kmh = ::fabsf(vs.forward_speed) * 3.6f; const char* gear = vs.gear < 0 ? "R" : (vs.gear == 0 ? "N" : nullptr); if (gear) ImGui::Text("speed %.0f km/h gear %s rpm %.0f", kmh, gear, vs.rpm); @@ -1360,7 +1360,7 @@ void DriveDemo::DrawPanel() { ImGui::Text("altitude %.1f m line %.1f m", ks.altitude_m, ks.line_length_m); ImGui::Text("tension %.0f N %s", ks.tension_n, ks.taut ? "taut" : "slack"); ImGui::Text("airspeed %.1f m/s alpha %.0f deg", ks.airspeed_mps, ks.alpha_deg); - ImGui::Text("wind %.1f m/s", ::sqrt(w.x * w.x + w.y * w.y + w.z * w.z)); + ImGui::Text("wind %.1f m/s", ::sqrtf(w.x * w.x + w.y * w.y + w.z * w.z)); ImGui::TextDisabled("A/D steer W/S reel out/in"); } } diff --git a/runtime/demo_grass.cc b/runtime/demo_grass.cc index 946e0077..0ddad172 100644 --- a/runtime/demo_grass.cc +++ b/runtime/demo_grass.cc @@ -38,10 +38,10 @@ f32 SmoothStep(f32 a, f32 b, f32 value) { } // namespace f32 GrassDemo::TerrainHeight(f32 x, f32 z) const { - f32 broad = ::sin(x * 0.025f) * 4.8f + ::cos(z * 0.031f) * 3.6f; - f32 crossing = ::sin((x + z) * 0.019f + 0.8f) * 3.1f; - f32 detail = ::sin(x * 0.071f - z * 0.049f) * 0.75f + - ::cos(x * 0.043f + z * 0.063f) * 0.55f; + f32 broad = ::sinf(x * 0.025f) * 4.8f + ::cosf(z * 0.031f) * 3.6f; + f32 crossing = ::sinf((x + z) * 0.019f + 0.8f) * 3.1f; + f32 detail = ::sinf(x * 0.071f - z * 0.049f) * 0.75f + + ::cosf(x * 0.043f + z * 0.063f) * 0.55f; return broad + crossing + detail; } @@ -120,10 +120,10 @@ void GrassDemo::BuildField() { const f32 world_z = kOrigin + static_cast(z) * kStep; render::GrassFieldSample& sample = samples_[z * kResolution + x]; sample.height = TerrainHeight(world_x, world_z); - const f32 patch = 0.5f + 0.25f * ::sin(world_x * 0.057f + world_z * 0.031f) + - 0.20f * ::cos(world_x * 0.021f - world_z * 0.069f); - const f32 path_center = ::sin(world_x * 0.035f) * 7.0f - 4.0f; - const f32 path_distance = ::fabs(world_z - path_center); + const f32 patch = 0.5f + 0.25f * ::sinf(world_x * 0.057f + world_z * 0.031f) + + 0.20f * ::cosf(world_x * 0.021f - world_z * 0.069f); + const f32 path_center = ::sinf(world_x * 0.035f) * 7.0f - 4.0f; + const f32 path_distance = ::fabsf(world_z - path_center); // Wide enough to survive the coarser kilometre-scale field texels. const f32 path_mask = SmoothStep(3.0f, 14.0f, path_distance); sample.density = rx::Clamp((0.90f + patch * 0.14f) * path_mask, 0.0f, 1.0f); @@ -343,11 +343,11 @@ void GrassDemo::Create() { void GrassDemo::Update(f32 dt) { time_ += dt; - const f32 x = ::sin(time_ * 0.34f) * 12.0f - 3.0f; - const f32 z = ::cos(time_ * 0.27f) * 7.0f + 4.0f; + const f32 x = ::sinf(time_ * 0.34f) * 12.0f - 3.0f; + const f32 z = ::cosf(time_ * 0.27f) * 7.0f + 4.0f; const f32 y = TerrainHeight(x, z) + 0.62f; interaction_position_ = {x, y, z}; - interaction_direction_ = {::cos(time_ * 0.34f), 0.0f, -::sin(time_ * 0.27f)}; + interaction_direction_ = {::cosf(time_ * 0.34f), 0.0f, -::sinf(time_ * 0.27f)}; if (scene::Transform* transform = ctx_.world->Get(interaction_marker_)) { transform->position[0] = x; diff --git a/runtime/demo_gym.cc b/runtime/demo_gym.cc index 2712ea97..15e45dfb 100644 --- a/runtime/demo_gym.cc +++ b/runtime/demo_gym.cc @@ -65,7 +65,7 @@ asset::Texture MakeChecker(asset::AssetId id, u32 res, u32 cells, Rgb a, Rgb b, c = Rgb{0xE0, 0x82, 0x28}; const f32 fx = static_cast(x % cell_px) / static_cast(cell_px); const f32 fy = static_cast(y % cell_px) / static_cast(cell_px); - if (fx + ::fabs(fy - 0.5f) < 0.55f && fx > 0.15f) c = Rgb{0x18, 0x18, 0x18}; + if (fx + ::fabsf(fy - 0.5f) < 0.55f && fx > 0.15f) c = Rgb{0x18, 0x18, 0x18}; } u8* p = &tex.data[(y * res + x) * 4]; p[0] = c.r; @@ -123,9 +123,9 @@ void PushVert(MeshBuilder& b, const Vec3& p, const Vec3& n, const Vec3& tan, f32 void AddBox(MeshBuilder& b, const Vec3& c, const Vec3& h, f32 uv_scale) { for (const Face& f : kFaces) { const u32 base = static_cast(b.lod().vertices.size()); - const f32 hu = ::fabs(Dot(f.u, h)); - const f32 hv = ::fabs(Dot(f.v, h)); - const Vec3 fc = c + f.n * ::fabs(Dot(f.n, h)); + const f32 hu = ::fabsf(Dot(f.u, h)); + const f32 hv = ::fabsf(Dot(f.v, h)); + const Vec3 fc = c + f.n * ::fabsf(Dot(f.n, h)); const Vec3 corners[4] = { fc - f.u * hu - f.v * hv, fc + f.u * hu - f.v * hv, @@ -142,9 +142,9 @@ void AddBox(MeshBuilder& b, const Vec3& c, const Vec3& h, f32 uv_scale) { void AddRotatedBox(MeshBuilder& b, const Vec3& c, const Vec3& h, const Quat& q, f32 uv_scale) { for (const Face& f : kFaces) { const u32 base = static_cast(b.lod().vertices.size()); - const f32 hu = ::fabs(Dot(f.u, h)); - const f32 hv = ::fabs(Dot(f.v, h)); - const Vec3 fc_local = f.n * ::fabs(Dot(f.n, h)); + const f32 hu = ::fabsf(Dot(f.u, h)); + const f32 hv = ::fabsf(Dot(f.v, h)); + const Vec3 fc_local = f.n * ::fabsf(Dot(f.n, h)); const Vec3 local[4] = { fc_local - f.u * hu - f.v * hv, fc_local + f.u * hu - f.v * hv, @@ -196,7 +196,7 @@ asset::Mesh MakeUnitCylinder(asset::AssetId id, u32 segments) { for (u32 i = 0; i <= segments; ++i) { const f32 t = static_cast(i) / segments; const f32 a = t * 2.0f * kPi; - const Vec3 n{::cos(a), 0, ::sin(a)}; + const Vec3 n{::cosf(a), 0, ::sinf(a)}; for (int k = 0; k < 2; ++k) { asset::Vertex v{}; v.position[0] = n.x; @@ -416,7 +416,7 @@ void GymDemo::BuildContent() { const f32 ang = deg * kPi / 180.0f; const f32 run = 3.0f, w = 1.4f, thick = 0.15f; const Quat q = QuatFromAxisAngle({1, 0, 0}, -ang); // tilt up toward -Z - const Vec3 center{x, ::sin(ang) * run * 0.5f + 0.05f, z - ::cos(ang) * run * 0.5f}; + const Vec3 center{x, ::sinf(ang) * run * 0.5f + 0.05f, z - ::cosf(ang) * run * 0.5f}; AddRotatedBox(st, center, {w * 0.5f, thick * 0.5f, run * 0.5f}, q, 1.0f); physics::ShapeDesc box; box.kind = physics::ShapeDesc::Kind::kBox; @@ -789,7 +789,7 @@ void GymDemo::Update(f32 dt, const InputState& input, const ActionState& actions // Moving platform: ping-pong along X, driven kinematically so a standing body // could ride it (character platform-riding is not yet folded into the module). platform_time_ += fixed; - const f32 offset = ::sin(platform_time_ * 0.6f) * platform_span_; + const f32 offset = ::sinf(platform_time_ * 0.6f) * platform_span_; const Vec3 target{platform_center_.x + offset, platform_center_.y, platform_center_.z}; const f32 identity_rot[4] = {0, 0, 0, 1}; if (platform_body_) phys.MoveBodyKinematic(platform_body_, target, identity_rot, fixed); @@ -915,7 +915,7 @@ void GymDemo::DrawPanel() { const bool tp = vm && vm->kind == character::CharacterViewKind::kThirdPerson; ImGui::Text("view: %s stance: %s %s", tp ? "third-person" : "first-person", stance, state->grounded ? "grounded" : "airborne"); - const f32 speed = ::sqrt(state->velocity.x * state->velocity.x + + const f32 speed = ::sqrtf(state->velocity.x * state->velocity.x + state->velocity.z * state->velocity.z); ImGui::Text("speed: %.2f m/s eye: %.2f m crouch: %.0f%%", speed, state->eye_height, state->crouch_blend * 100.0f); diff --git a/runtime/demo_lookdev.cc b/runtime/demo_lookdev.cc index da0bd2c2..156194a3 100644 --- a/runtime/demo_lookdev.cc +++ b/runtime/demo_lookdev.cc @@ -209,11 +209,11 @@ asset::Texture MakeSweatNormal(u32 size) { const f32 radius = cell * (0.18f + 0.22f * (static_cast((h >> 24) & 255u) / 255.0f)); const f32 dx = static_cast(px) - (static_cast(gx) + jx) * cell; const f32 dy = static_cast(py) - (static_cast(gy) + jy) * cell; - const f32 d = ::sqrt(dx * dx + dy * dy); + const f32 d = ::sqrtf(dx * dx + dy * dy); if (d >= radius || radius <= 0.0f) continue; // Hemispherical bead: the slope grows toward the rim. const f32 t = d / radius; - const f32 slope = t / ::sqrt(rx::Max(1.0f - t * t, 1e-3f)); + const f32 slope = t / ::sqrtf(rx::Max(1.0f - t * t, 1e-3f)); const f32 k = rx::Min(slope, 3.0f) / 3.0f; if (d > 1e-4f) { nx += (dx / d) * k; @@ -222,7 +222,7 @@ asset::Texture MakeSweatNormal(u32 size) { } } Vec3 n{nx, ny, 1.0f}; - const f32 len = ::sqrt(n.x * n.x + n.y * n.y + 1.0f); + const f32 len = ::sqrtf(n.x * n.x + n.y * n.y + 1.0f); const size_t o = (static_cast(py) * size + px) * 4; texture.data[o + 0] = static_cast(rx::Clamp((n.x / len) * 0.5f + 0.5f, 0.0f, 1.0f) * 255.0f); texture.data[o + 1] = static_cast(rx::Clamp((n.y / len) * 0.5f + 0.5f, 0.0f, 1.0f) * 255.0f); @@ -517,7 +517,7 @@ void LookdevDemo::Impl::LoadSubject() { r2 = rx::Max(r2, d.x * d.x + d.y * d.y + d.z * d.z); } } - subject_radius = rx::Max(::sqrt(r2), 1e-3f); + subject_radius = rx::Max(::sqrtf(r2), 1e-3f); } else { subject_center = {(lo.x + hi.x) * 0.5f, (lo.y + hi.y) * 0.5f, (lo.z + hi.z) * 0.5f}; subject_radius = 0.5f * rx::Max({extent.x, extent.y, extent.z}); @@ -597,9 +597,9 @@ render::CameraPose LookdevDemo::Impl::ResolveCamera() const { const f32 distance = stop.distance * scale; render::CameraPose pose; pose.target = subject_center; - pose.eye = {subject_center.x + ::sin(yaw) * ::cos(pitch) * distance, - subject_center.y - ::sin(pitch) * distance, - subject_center.z - ::cos(yaw) * ::cos(pitch) * distance}; + pose.eye = {subject_center.x + ::sinf(yaw) * ::cosf(pitch) * distance, + subject_center.y - ::sinf(pitch) * distance, + subject_center.z - ::cosf(yaw) * ::cosf(pitch) * distance}; pose.fov_y = stop.fov_degrees * kDeg; return pose; } @@ -1033,7 +1033,7 @@ void LookdevDemo::Impl::DrawPanel() { const f32 head_px = ImGui::GetIO().DisplaySize.y * 2.0f * subject_radius / rx::Max(kCameraStops[camera_index].distance * (subject_radius / 0.115f) * - ::tan(kCameraStops[camera_index].fov_degrees * kDeg * 0.5f) * + ::tanf(kCameraStops[camera_index].fov_degrees * kDeg * 0.5f) * 2.0f, 1e-4f); ImGui::Text("subject height: %.0f px -> tier %d suggested", head_px, diff --git a/runtime/demo_nav.cc b/runtime/demo_nav.cc index 4c408e9a..812e3234 100644 --- a/runtime/demo_nav.cc +++ b/runtime/demo_nav.cc @@ -39,7 +39,7 @@ struct Mesa { }; constexpr Mesa kMesas[] = {{18, 74, 7.0f, 5.0f}, {76, 14, 8.0f, 6.0f}}; -f32 RiverCenter(f32 x) { return 48.0f + 7.0f * ::sin(x * 0.07f); } +f32 RiverCenter(f32 x) { return 48.0f + 7.0f * ::sinf(x * 0.07f); } constexpr f32 kRiverHalfWidth = 3.2f; f32 Smoothstep(f32 t) { @@ -69,20 +69,20 @@ NavDemo::NavDemo(EngineContext& ctx) NavDemo::Ground NavDemo::SampleGround(f32 x, f32 z) const { Ground g; // Rolling hills, three octaves. - g.height = 2.2f * ::sin(x * 0.06f) * ::cos(z * 0.05f) + - 1.1f * ::sin(x * 0.13f + 1.7f) * ::sin(z * 0.11f + 0.6f) + - 0.4f * ::sin(x * 0.31f) * ::cos(z * 0.29f); + g.height = 2.2f * ::sinf(x * 0.06f) * ::cosf(z * 0.05f) + + 1.1f * ::sinf(x * 0.13f + 1.7f) * ::sinf(z * 0.11f + 0.6f) + + 0.4f * ::sinf(x * 0.31f) * ::cosf(z * 0.29f); // Mesas: flat tops, steep unwalkable flanks (the slope check below). for (const Mesa& mesa : kMesas) { const f32 dx = x - mesa.x; const f32 dz = z - mesa.z; - const f32 d = ::sqrt(dx * dx + dz * dz); + const f32 d = ::sqrtf(dx * dx + dz * dz); g.height += mesa.height * Smoothstep((mesa.radius - d) / 3.0f); } // The river carves a bed below the banks. - const f32 river_d = ::fabs(z - RiverCenter(x)); + const f32 river_d = ::fabsf(z - RiverCenter(x)); if (river_d < kRiverHalfWidth + 1.5f) { const f32 t = Smoothstep((kRiverHalfWidth + 1.5f - river_d) / (kRiverHalfWidth + 1.5f)); g.height -= 2.0f * t; @@ -137,8 +137,8 @@ void NavDemo::BuildTerrainMesh() { v.tangent[3] = 1; v.uv[0] = x / 8.0f; v.uv[1] = z / 8.0f; - const f32 slope = ::sqrt(hx * hx + hz * hz) / 0.8f; - u32 tone = PackColor(0.13f + 0.04f * ::sin(x * 0.9f) * ::sin(z * 0.77f), 0.34f, + const f32 slope = ::sqrtf(hx * hx + hz * hz) / 0.8f; + u32 tone = PackColor(0.13f + 0.04f * ::sinf(x * 0.9f) * ::sinf(z * 0.77f), 0.34f, 0.10f); // grass, gently mottled if (g.area == kAreaRock) tone = PackColor(0.32f, 0.30f, 0.27f); if (g.area == kAreaWater) tone = PackColor(0.10f, 0.16f, 0.30f); @@ -234,15 +234,15 @@ void NavDemo::BuildTerrainMesh() { for (int i = 0; i < 9; ++i) { const f32 angle = RandRange(rng, 0, 6.2831f); const f32 r = RandRange(rng, 0.3f, field.radius - 0.5f); - const f32 x = field.x + ::cos(angle) * r; - const f32 z = field.z + ::sin(angle) * r; + const f32 x = field.x + ::cosf(angle) * r; + const f32 z = field.z + ::sinf(angle) * r; ecs::Entity rock = ctx_.world->Create(); scene::Transform t; t.position[0] = x; t.position[1] = SampleGround(x, z).height + 0.05f; t.position[2] = z; - t.rotation[1] = ::sin(angle * 0.5f); - t.rotation[3] = ::cos(angle * 0.5f); + t.rotation[1] = ::sinf(angle * 0.5f); + t.rotation[3] = ::cosf(angle * 0.5f); t.scale = RandRange(rng, 0.35f, 0.9f); ctx_.world->Add(rock, t); ctx_.world->Add(rock, scene::Renderable{boulder.id}); diff --git a/runtime/demo_placement.cc b/runtime/demo_placement.cc index d2f44427..4fc3f97d 100644 --- a/runtime/demo_placement.cc +++ b/runtime/demo_placement.cc @@ -24,7 +24,7 @@ constexpr u32 kWorldResolution = 512; constexpr u32 kTerrainGrid = 384; // The road winds north-south through the world. -f32 RoadCenter(f32 z) { return 90.0f * ::sin(z * 0.004f) + 30.0f * ::sin(z * 0.011f); } +f32 RoadCenter(f32 z) { return 90.0f * ::sinf(z * 0.004f) + 30.0f * ::sinf(z * 0.011f); } constexpr f32 kRoadHalfWidth = 4.5f; // The lake basin carved into the height field. @@ -66,12 +66,12 @@ f32 PlacementDemo::TerrainHeight(f32 x, f32 z) const { // Rolling hills with a broad ridge, softened toward the road and carved // into a basin around the lake. f32 height = 10.0f * Fbm(x, z, 420.0f, 101u, 4) + 3.0f * Fbm(x, z, 90.0f, 202u, 3); - f32 road_dist = ::fabs(x - RoadCenter(z)); + f32 road_dist = ::fabsf(x - RoadCenter(z)); f32 road_blend = rx::Min(road_dist / 22.0f, 1.0f); road_blend = road_blend * road_blend * (3.0f - 2.0f * road_blend); f32 dx = x - kLakeX; f32 dz = z - kLakeZ; - f32 lake_dist = ::sqrt(dx * dx + dz * dz); + f32 lake_dist = ::sqrtf(dx * dx + dz * dz); f32 basin = rx::Min(lake_dist / kLakeRadius, 1.0f); basin = basin * basin * (3.0f - 2.0f * basin); height = height * (0.35f + 0.65f * road_blend); // road hugs gentler ground @@ -97,7 +97,7 @@ void PlacementDemo::BuildWorldData() { return t * t * (3.0f - 2.0f * t); }); world_.Generate(map_road_, [](f32 x, f32 z) { - f32 d = ::fabs(x - RoadCenter(z)); + f32 d = ::fabsf(x - RoadCenter(z)); return rx::Clamp(1.0f - (d - kRoadHalfWidth) / 4.0f, 0.0f, 1.0f); }); world_.Generate(map_water_, [this](f32 x, f32 z) { @@ -262,7 +262,7 @@ void PlacementDemo::BuildTerrainMesh() { const f32 dhz = world_.Sample(map_height_, x, z + h) - world_.Sample(map_height_, x, z - h); const f32 inv = - 1.0f / ::sqrt(dhx * dhx + dhz * dhz + 4.0f * h * h); + 1.0f / ::sqrtf(dhx * dhx + dhz * dhz + 4.0f * h * h); v.normal[0] = -dhx * inv; v.normal[1] = 2.0f * h * inv; v.normal[2] = -dhz * inv; diff --git a/runtime/demo_puppet.cc b/runtime/demo_puppet.cc index a0f4fb6a..54c38ada 100644 --- a/runtime/demo_puppet.cc +++ b/runtime/demo_puppet.cc @@ -61,7 +61,7 @@ void PushRing(base::Vector& out, const Vec3& p, f32 r, u32 rg Vec3 prev{p.x + r, p.y, p.z}; for (u32 i = 1; i <= segs; ++i) { const f32 a = 6.2831853f * static_cast(i) / static_cast(segs); - Vec3 cur{p.x + ::cos(a) * r, p.y, p.z + ::sin(a) * r}; + Vec3 cur{p.x + ::cosf(a) * r, p.y, p.z + ::sinf(a) * r}; PushLine(out, prev, cur, rgba); prev = cur; } @@ -71,7 +71,7 @@ void PushRing(base::Vector& out, const Vec3& p, f32 r, u32 rg void PushArrow(base::Vector& out, const Vec3& from, const Vec3& dir, u32 rgba) { const Vec3 tip{from.x + dir.x, from.y + dir.y, from.z + dir.z}; PushLine(out, from, tip, rgba); - const f32 len = ::sqrt(dir.x * dir.x + dir.z * dir.z); + const f32 len = ::sqrtf(dir.x * dir.x + dir.z * dir.z); if (len < 1e-3f) return; const Vec3 back{-dir.x / len, 0, -dir.z / len}; const Vec3 side{back.z, 0, -back.x}; // perpendicular in the ground plane @@ -126,7 +126,7 @@ void PuppetDemo::BuildArena() { // A shallow ~15 deg ramp off to the +X/+Z corner (scenery + a slope to probe). const f32 ramp_deg = 15.0f * 3.14159265f / 180.0f; - const f32 rh = ::sin(ramp_deg * 0.5f), rw = ::cos(ramp_deg * 0.5f); + const f32 rh = ::sinf(ramp_deg * 0.5f), rw = ::cosf(ramp_deg * 0.5f); const f32 ramp_rot[4] = {rh, 0, 0, rw}; // tilt about +X solid({3.0f, 0.35f, 3.0f}, 1.6f, 0.08f, 2.0f, ramp_rot, 0x45483f); @@ -244,7 +244,7 @@ locomotion::LocomotionIntent PuppetDemo::ScriptedIntent() const { // Turn gradually from -Z toward -X over 3 s (an abrupt heading snap while // walking tips this slow ragdoll over); velocity follows the heading. const f32 phi = rx::Min((t - 11.0f) / 3.0f, 1.0f) * 1.5707963f; - const Vec3 dir{-::sin(phi), 0, -::cos(phi)}; + const Vec3 dir{-::sinf(phi), 0, -::cosf(phi)}; intent.desired_facing = dir; intent.desired_velocity = {dir.x * kSpeed, 0, dir.z * kSpeed}; } else { @@ -269,7 +269,7 @@ void PuppetDemo::Step(f32 dt) { pending_small_push_ = pending_big_push_ = false; rng_ = rng_ * 1664525u + 1013904223u; const f32 a = 6.2831853f * (static_cast((rng_ >> 8) & 0xffff) / 65535.0f); - const Vec3 impulse{::cos(a) * mag, 0, ::sin(a) * mag}; + const Vec3 impulse{::cosf(a) * mag, 0, ::sinf(a) * mag}; ctx_.physics->ApplyImpulse(controller_.rig().body[static_cast(BodyPart::kTorso)], impulse); RX_INFO("puppet demo: push {} kg*m/s", mag); } diff --git a/runtime/demo_scenes.cc b/runtime/demo_scenes.cc index 26c85272..37064b8d 100644 --- a/runtime/demo_scenes.cc +++ b/runtime/demo_scenes.cc @@ -169,8 +169,8 @@ void DemoScenes::CreateBubbleDemoScene() { world.Each( [dt](ecs::Entity, BubbleAgent& agent, scene::Transform& t) { agent.time += dt; - t.position[0] = ::sin(agent.time * agent.rate_x) * agent.extent; - t.position[2] = ::cos(agent.time * agent.rate_z) * agent.extent; + t.position[0] = ::sinf(agent.time * agent.rate_x) * agent.extent; + t.position[2] = ::cosf(agent.time * agent.rate_z) * agent.extent; }); }); @@ -289,7 +289,7 @@ void DemoScenes::EmitToView(f32 dt, render::FrameView& view) { renderer_.settings().sun_intensity = rx::Min(renderer_.settings().sun_intensity, 1.3f); const render::WeatherSettings &weather = renderer_.settings().weather; weather_map_offset_ += - Vec2{::cos(weather.wind_yaw), ::sin(weather.wind_yaw)} * (weather.wind_speed * dt); + Vec2{::cosf(weather.wind_yaw), ::sinf(weather.wind_yaw)} * (weather.wind_speed * dt); renderer_.settings().cloudscape_controls.map_offset = weather_map_offset_; } if (storm_enabled_) UpdateStorm(dt); @@ -326,8 +326,8 @@ void DemoScenes::EmitToView(f32 dt, render::FrameView& view) { // path traces real shadows from it). fire_time_ += dt; f32 t = fire_time_; - f32 flicker = 0.82f + 0.12f * ::sin(t * 11.7f) + 0.06f * ::sin(t * 23.3f + 1.7f) + - 0.05f * ::sin(t * 5.1f + 0.6f); + f32 flicker = 0.82f + 0.12f * ::sinf(t * 11.7f) + 0.06f * ::sinf(t * 23.3f + 1.7f) + + 0.05f * ::sinf(t * 5.1f + 0.6f); render::PointLight l; l.pos_radius[0] = gpu_particle_emitter_.x; l.pos_radius[1] = gpu_particle_emitter_.y + 0.55f; @@ -355,17 +355,17 @@ void DemoScenes::EmitToView(f32 dt, render::FrameView& view) { // and lags as the head bobs. if (!hair_sims_.empty()) { hair_time_ += dt; - Vec3 wind = Vec3{0.5f, 0.0f, 0.25f} * (0.6f + 0.4f * ::sin(hair_time_ * 2.1f)) + - Vec3{0.0f, 0.15f * ::sin(hair_time_ * 3.7f), 0.0f}; + Vec3 wind = Vec3{0.5f, 0.0f, 0.25f} * (0.6f + 0.4f * ::sinf(hair_time_ * 2.1f)) + + Vec3{0.0f, 0.15f * ::sinf(hair_time_ * 3.7f), 0.0f}; for (physics::StrandGroomId sim : hair_sims_) physics_.SetStrandGroomWind(sim, wind); if (hair_orbit_strands_ != 0) { f32 a = hair_time_ * 0.9f; // Mostly a head turn (rotation keeps the head under the hair) plus a // small bob, so the hair sways without exposing the scalp. - Vec3 pos{hair_orbit_center_.x + 0.03f * ::sin(a), - hair_orbit_center_.y + 0.02f * ::sin(a * 1.7f), hair_orbit_center_.z}; + Vec3 pos{hair_orbit_center_.x + 0.03f * ::sinf(a), + hair_orbit_center_.y + 0.02f * ::sinf(a * 1.7f), hair_orbit_center_.z}; Mat4 m = - MakeTranslation(pos) * MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.8f * ::sin(a))); + MakeTranslation(pos) * MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.8f * ::sinf(a))); physics_.SetStrandGroomTransform(hair_orbit_strands_, m, dt); renderer_.SetHairGroomTransform(hair_orbit_groom_, m); } @@ -402,8 +402,8 @@ void DemoScenes::EmitWaterDisturbances(f32 dt, render::FrameView& view) { f32 surface_vy = 0.0f; f32 surface = physics::GerstnerWaveHeight(pos.x, pos.z, water_time_, nullptr, &surface_vy); - f32 horiz = ::sqrt(vel.x * vel.x + vel.z * vel.z); - f32 vert = ::fabs(vel.y); + f32 horiz = ::sqrtf(vel.x * vel.x + vel.z * vel.z); + f32 vert = ::fabsf(vel.y); f32 motion = horiz + vert; render::WaterDisturbance d; d.position = {pos.x, 0.0f, pos.z}; @@ -426,7 +426,7 @@ void DemoScenes::EmitWaterDisturbances(f32 dt, render::FrameView& view) { const f32 rel_vy = vel.y - surface_vy; const f32 kSlamSpeed = 2.5f; // m/s of downward closing speed const f32 kWaterlineBand = 1.4f; // cube half-height + margin - if (rel_vy < -kSlamSpeed && ::fabs(pos.y - surface) < kWaterlineBand && + if (rel_vy < -kSlamSpeed && ::fabsf(pos.y - surface) < kWaterlineBand && water_cube_slam_cd_[i] <= 0.0f) { water_cube_slam_cd_[i] = 0.6f; f32 slam = rx::Min(-rel_vy, 12.0f); @@ -463,8 +463,8 @@ void DemoScenes::SpawnSplashSpray(const Vec3& pos, f32 surface, f32 strength) { p.position = {pos.x + (rnd() - 0.5f) * 1.6f, surface + 0.1f, pos.z + (rnd() - 0.5f) * 1.6f}; f32 ang = rnd() * 6.2831853f; f32 spread = 0.6f + rnd() * (0.5f + 0.15f * strength); - p.velocity = {::cos(ang) * spread, 2.0f + rnd() * (1.0f + 0.25f * strength), - ::sin(ang) * spread}; + p.velocity = {::cosf(ang) * spread, 2.0f + rnd() * (1.0f + 0.25f * strength), + ::sinf(ang) * spread}; p.max_life = 0.5f + rnd() * 0.4f; p.life = p.max_life; p.size = 0.03f + rnd() * 0.03f; @@ -498,7 +498,7 @@ f32 FluidDemoBed(f32 x, f32 z) { // Lower basin is the datum (~0). Everything is built up from here. // Domain-edge rim: the outer ~12 m rises to ~2.5 m on every side so the flood // can't visibly spill out of the 128 m domain. - f32 edge = rx::Max(::fabs(x), ::fabs(z)); + f32 edge = rx::Max(::fabsf(x), ::fabsf(z)); f32 h = 2.5f * SmoothStep(52.0f, 64.0f, edge); // Upper reservoir plateau (~6 m), gated to the central x band so it walls the @@ -507,12 +507,12 @@ f32 FluidDemoBed(f32 x, f32 z) { // channel throat stays above the 5.2 m fill level; a longer ramp (the first // cut used -12..-24) leaves a ~4 m shoulder the reservoir quietly drains // around, dam or no dam. - f32 plateau_x = 1.0f - SmoothStep(22.0f, 32.0f, ::fabs(x)); + f32 plateau_x = 1.0f - SmoothStep(22.0f, 32.0f, ::fabsf(x)); f32 plateau = 6.0f * SmoothStep(-13.0f, -19.0f, z) * plateau_x; // Carve the reservoir bowl into the plateau: floor ~3.5 m, centred (0,-40), // radius ~18 m (a smooth radial depression). - f32 rb = ::sqrt(x * x + (z + 40.0f) * (z + 40.0f)); + f32 rb = ::sqrtf(x * x + (z + 40.0f) * (z + 40.0f)); f32 bowl = 2.5f * (1.0f - SmoothStep(6.0f, 18.0f, rb)); h = rx::Max(h, plateau - bowl); @@ -520,7 +520,7 @@ f32 FluidDemoBed(f32 x, f32 z) { // floor descends 3.5 m -> 0.5 m as z runs -24 -> -12, min-blended through the // plateau lip (1 m feather in x, ramps in/out over ~1 m in z). f32 channel_floor = 3.5f - 3.0f * SmoothStep(-24.0f, -12.0f, z); - f32 cmask = (1.0f - SmoothStep(5.0f, 6.0f, ::fabs(x))) * + f32 cmask = (1.0f - SmoothStep(5.0f, 6.0f, ::fabsf(x))) * SmoothStep(-25.0f, -24.0f, z) * (1.0f - SmoothStep(-13.0f, -12.0f, z)); h -= rx::Max(0.0f, h - channel_floor) * cmask; @@ -528,7 +528,7 @@ f32 FluidDemoBed(f32 x, f32 z) { // flank runs ~30+ m downhill into the lower basin (slope ~15 deg), so the vent // near its top feeds a flow that runs, slows and solidifies before pooling. f32 hx = x - 35.0f, hz = z + 30.0f; - f32 hill = 8.0f * ::exp(-(hx * hx + hz * hz) / (2.0f * 12.0f * 12.0f)); + f32 hill = 8.0f * ::expf(-(hx * hx + hz * hz) / (2.0f * 12.0f * 12.0f)); h = rx::Max(h, hill); return h; @@ -624,7 +624,7 @@ void DemoScenes::CreateWaterDemoScene() { for (int i = 0; i < 6; ++i) { ecs::Entity block = world_.Create(); f32 angle = static_cast(i) * 1.047f; - Vec3 position{::cos(angle) * 6.0f, 2.0f + (i % 3), ::sin(angle) * 6.0f}; + Vec3 position{::cosf(angle) * 6.0f, 2.0f + (i % 3), ::sinf(angle) * 6.0f}; world_.Add(block, scene::Transform{.position = {position.x, position.y, position.z}}); world_.Add(block, scene::Renderable{cube.id}); // Density 450 kg/m^3 against the 1.2x buoyancy factor settles the cubes at @@ -687,7 +687,7 @@ void DemoScenes::CreateWaterDemoScene() { for (u32 gx = 0; gx <= kIslandGrid; ++gx) { f32 lx = -kRadius + 2.0f * kRadius * static_cast(gx) / kIslandGrid; f32 lz = -kRadius + 2.0f * kRadius * static_cast(gy) / kIslandGrid; - f32 g = ::exp(-(lx * lx + lz * lz) / (2.0f * kSigma * kSigma)); + f32 g = ::expf(-(lx * lx + lz * lz) / (2.0f * kSigma * kSigma)); f32 slope = kPeak * 2.0f * g / (kSigma * kSigma); // -dh/dr factor Vec3 n = Normalize(Vec3{slope * lx, 1.0f, slope * lz}); asset::Vertex v{}; @@ -759,7 +759,7 @@ void DemoScenes::RebuildFluidBed() { // The wall's flat top must run past the notch shoulders (bed ~5.2-5.9 m // at |x| 5.5-6.5): the startup slosh piles water ~1 m above the rest // level and spills over anything lower than ~6.5 m there. - f32 dmx = 1.0f - SmoothStep(7.0f, 8.5f, ::fabs(x)); + f32 dmx = 1.0f - SmoothStep(7.0f, 8.5f, ::fabsf(x)); f32 dmz = SmoothStep(-18.5f, -17.5f, z) * (1.0f - SmoothStep(-14.5f, -13.5f, z)); h = rx::Max(h, 8.5f * dmx * dmz); } @@ -794,8 +794,8 @@ void DemoScenes::CreateFluidDemoScene() { f32 z = fluid_domain_.origin[1] + (static_cast(j) + 0.5f) * l; for (u32 i = 0; i < res; ++i) { f32 x = fluid_domain_.origin[0] + (static_cast(i) + 0.5f) * l; - f32 rb = ::sqrt(x * x + (z + 40.0f) * (z + 40.0f)); - bool in_reservoir = rb < 19.0f || (::fabs(x) < 6.0f && z < -18.0f && z > -25.0f); + f32 rb = ::sqrtf(x * x + (z + 40.0f) * (z + 40.0f)); + bool in_reservoir = rb < 19.0f || (::fabsf(x) < 6.0f && z < -18.0f && z > -25.0f); if (!in_reservoir) continue; f32 depth = 5.2f - FluidDemoBed(x, z); if (depth > 0.0f) fluid_initial_water_[static_cast(j) * res + i] = depth; @@ -959,7 +959,7 @@ void DemoScenes::EmitFluid(f32 dt, render::FrameView& view) { render::FluidSource lava; lava.position = {35.0f, 0.0f, -30.0f}; lava.radius = 2.5f; - lava.rate = 0.35f * (1.0f + 0.3f * ::sin(fluid_time_ * 0.7f)); + lava.rate = 0.35f * (1.0f + 0.3f * ::sinf(fluid_time_ * 0.7f)); lava.fluid = 1; lava.temperature = 1250.0f; view.fluid_sources.push_back(lava); @@ -1095,7 +1095,7 @@ void DemoScenes::UpdateParticles(f32 dt, render::FrameView& view) { p.position = particle_emitter_; f32 ang = rnd() * 6.2831853f; f32 spread = rnd() * 0.65f; - p.velocity = {::cos(ang) * spread, 2.8f + rnd() * 1.4f, ::sin(ang) * spread}; + p.velocity = {::cosf(ang) * spread, 2.8f + rnd() * 1.4f, ::sinf(ang) * spread}; p.max_life = 0.8f + rnd() * 0.6f; p.life = p.max_life; p.size = 0.02f + rnd() * 0.02f; @@ -1163,9 +1163,9 @@ void DemoScenes::CreateGaussianDemoScene() { for (u32 i = 0; i < kCount; ++i) { f32 t = (static_cast(i) + 0.5f) / static_cast(kCount); f32 y = 1.0f - 2.0f * t; - f32 r = ::sqrt(rx::Max(0.0f, 1.0f - y * y)); + f32 r = ::sqrtf(rx::Max(0.0f, 1.0f - y * y)); f32 phi = static_cast(i) * golden; - Vec3 dir{::cos(phi) * r, y, ::sin(phi) * r}; + Vec3 dir{::cosf(phi) * r, y, ::sinf(phi) * r}; render::GaussianInstance g; g.position[0] = dir.x * radius; g.position[1] = dir.y * radius + 1.8f; @@ -1385,7 +1385,7 @@ void DemoScenes::CreateImposterDemoScene() { auto push_vertex = [&](f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, u32 color) { asset::Vertex v{}; v.position[0] = x; v.position[1] = y; v.position[2] = z; - f32 len = ::sqrt(nx * nx + ny * ny + nz * nz); + f32 len = ::sqrtf(nx * nx + ny * ny + nz * nz); v.normal[0] = nx / len; v.normal[1] = ny / len; v.normal[2] = nz / len; v.tangent[3] = 1.0f; v.color = color; @@ -1403,9 +1403,9 @@ void DemoScenes::CreateImposterDemoScene() { const f32 tw = 0.14f, th = 1.1f; for (int s = 0; s < 4; ++s) { f32 a0 = s * 1.5708f, a1 = a0 + 1.5708f; - f32 x0 = ::cos(a0) * tw, z0 = ::sin(a0) * tw; - f32 x1 = ::cos(a1) * tw, z1 = ::sin(a1) * tw; - f32 nx = ::cos(a0 + 0.7854f), nz = ::sin(a0 + 0.7854f); + f32 x0 = ::cosf(a0) * tw, z0 = ::sinf(a0) * tw; + f32 x1 = ::cosf(a1) * tw, z1 = ::sinf(a1) * tw; + f32 nx = ::cosf(a0 + 0.7854f), nz = ::sinf(a0 + 0.7854f); u32 v0 = push_vertex(x0, 0.0f, z0, nx, 0, nz, kBrown); u32 v1 = push_vertex(x1, 0.0f, z1, nx, 0, nz, kBrown); u32 v2 = push_vertex(x1, th, z1, nx, 0, nz, kBrown); @@ -1419,13 +1419,13 @@ void DemoScenes::CreateImposterDemoScene() { const int kSegs = 10; for (int s = 0; s < kSegs; ++s) { f32 a0 = s * 6.2831853f / kSegs, a1 = (s + 1) * 6.2831853f / kSegs; - f32 x0 = ::cos(a0) * radius, z0 = ::sin(a0) * radius; - f32 x1 = ::cos(a1) * radius, z1 = ::sin(a1) * radius; + f32 x0 = ::cosf(a0) * radius, z0 = ::sinf(a0) * radius; + f32 x1 = ::cosf(a1) * radius, z1 = ::sinf(a1) * radius; f32 am = (a0 + a1) * 0.5f; u32 color = (s & 1) ? kGreen : kGreenDark; u32 v0 = push_vertex(x0, base, z0, x0, radius * 0.6f, z0, color); u32 v1 = push_vertex(x1, base, z1, x1, radius * 0.6f, z1, color); - u32 v2 = push_vertex(0.0f, tip, 0.0f, ::cos(am), 0.8f, ::sin(am), color); + u32 v2 = push_vertex(0.0f, tip, 0.0f, ::cosf(am), 0.8f, ::sinf(am), color); lod.indices.push_back(v0); lod.indices.push_back(v2); lod.indices.push_back(v1); @@ -1466,9 +1466,9 @@ void DemoScenes::CreateImposterDemoScene() { f32 ang = next_rand() * 6.2831853f; f32 dist = 22.0f + next_rand() * 170.0f; render::ImposterPass::Instance inst; - inst.position[0] = ::cos(ang) * dist; + inst.position[0] = ::cosf(ang) * dist; inst.position[1] = 0.0f; - inst.position[2] = ::sin(ang) * dist; + inst.position[2] = ::sinf(ang) * dist; inst.scale = 0.8f + next_rand() * 0.7f; inst.mesh = baked == render::ImposterPass::kNoMesh ? 0 : baked; instances.push_back(inst); @@ -1477,8 +1477,8 @@ void DemoScenes::CreateImposterDemoScene() { f32 ang = next_rand() * 6.2831853f; f32 dist = 6.0f + next_rand() * 12.0f; ecs::Entity t = world_.Create(); - world_.Add(t, scene::Transform{.position = {::cos(ang) * dist, 0.0f, - ::sin(ang) * dist}}); + world_.Add(t, scene::Transform{.position = {::cosf(ang) * dist, 0.0f, + ::sinf(ang) * dist}}); world_.Add(t, scene::Renderable{tree.id}); } if (baked != render::ImposterPass::kNoMesh) renderer_.SetImposterInstances(instances); @@ -1908,9 +1908,9 @@ void DemoScenes::CreateVirtualGeometryDemoScene() { asset::MeshLod& lod = terrain.lods[0]; lod.vertices.reserve(static_cast(kGrid + 1) * (kGrid + 1)); auto analytic = [](f32 x, f32 z) { - return 3.0f * ::sin(x * 0.05f) * ::cos(z * 0.045f) + - 0.8f * ::sin(x * 0.31f + 1.7f) * ::sin(z * 0.27f) + - 0.15f * ::sin(x * 1.7f) * ::cos(z * 1.9f); + return 3.0f * ::sinf(x * 0.05f) * ::cosf(z * 0.045f) + + 0.8f * ::sinf(x * 0.31f + 1.7f) * ::sinf(z * 0.27f) + + 0.15f * ::sinf(x * 1.7f) * ::cosf(z * 1.9f); }; const u32 hm_n = kGrid + 1; auto height = [&](f32 wx, f32 wz, u32 xi, u32 zi) { @@ -1931,7 +1931,7 @@ void DemoScenes::CreateVirtualGeometryDemoScene() { f32 hx = height(wx + e, wz, x1, z) - height(wx - e, wz, x0, z); f32 hz = height(wx, wz + e, x, z1) - height(wx, wz - e, x, z0); f32 nx = -hx / (2.0f * e), nz = -hz / (2.0f * e); - f32 len = ::sqrt(nx * nx + 1.0f + nz * nz); + f32 len = ::sqrtf(nx * nx + 1.0f + nz * nz); v.normal[0] = nx / len; v.normal[1] = 1.0f / len; v.normal[2] = nz / len; @@ -2062,8 +2062,8 @@ void DemoScenes::CreateBrickDemoScene() { // Two-course running bond with rounded mortar channels. f32 row = v * 8.0f; f32 col = u * 4.0f + (static_cast(row) % 2 ? 0.5f : 0.0f); - f32 fy = row - ::floor(row); - f32 fx = col - ::floor(col); + f32 fy = row - ::floorf(row); + f32 fx = col - ::floorf(col); auto channel = [](f32 t, f32 w) { f32 d = rx::Min(t, 1.0f - t) / w; // distance to the mortar line return rx::Min(d, 1.0f); @@ -2100,7 +2100,7 @@ void DemoScenes::CreateBrickDemoScene() { f32 hx = brick_height(u + e, v) - brick_height(u - e, v); f32 hy = brick_height(u, v + e) - brick_height(u, v - e); f32 nx = -hx * 6.0f, ny = -hy * 6.0f, nz = 1.0f; - f32 len = ::sqrt(nx * nx + ny * ny + nz * nz); + f32 len = ::sqrtf(nx * nx + ny * ny + nz * nz); normal.data[o] = static_cast((nx / len * 0.5f + 0.5f) * 255.0f); normal.data[o + 1] = static_cast((ny / len * 0.5f + 0.5f) * 255.0f); normal.data[o + 2] = static_cast((nz / len * 0.5f + 0.5f) * 255.0f); @@ -2175,10 +2175,10 @@ void DemoScenes::CreateBrickDemoScene() { auto blob = [](f32 u, f32 v, u32 seed_base, int arms) { // Irregular radial blob: radius modulated by a few sine lobes. f32 du = u - 0.5f, dv = v - 0.5f; - f32 r = ::sqrt(du * du + dv * dv) * 2.2f; - f32 ang = ::atan2(dv, du); - f32 rim = 0.75f + 0.18f * ::sin(ang * arms + seed_base) + - 0.12f * ::sin(ang * (arms * 2 + 1) + seed_base * 1.7f); + f32 r = ::sqrtf(du * du + dv * dv) * 2.2f; + f32 ang = ::atan2f(dv, du); + f32 rim = 0.75f + 0.18f * ::sinf(ang * arms + seed_base) + + 0.12f * ::sinf(ang * (arms * 2 + 1) + seed_base * 1.7f); return rx::Max(0.0f, 1.0f - r / rim); }; for (u32 y = 0; y < atlas.height; ++y) { @@ -2196,7 +2196,7 @@ void DemoScenes::CreateBrickDemoScene() { } else { // moss f32 u = (x - 256 + 0.5f) / 256.0f; f32 m = blob(u, v, 11, 9); - f32 grain = 0.7f + 0.3f * blob(::fmod(u * 5.0f, 1.0f), ::fmod(v * 5.0f, 1.0f), 5, 5); + f32 grain = 0.7f + 0.3f * blob(::fmodf(u * 5.0f, 1.0f), ::fmodf(v * 5.0f, 1.0f), 5, 5); f32 a = m > 0.05f ? rx::Min(1.0f, m * 1.6f) * grain : 0.0f; atlas.data[o] = static_cast(40 + 25 * m); atlas.data[o + 1] = static_cast(85 + 60 * m * grain); @@ -2217,7 +2217,7 @@ void DemoScenes::CreateBrickDemoScene() { channels.data.resize(static_cast(channels.width) * channels.height * 4); auto moss_height = [&](f32 u, f32 v) { f32 m = blob(u, v, 11, 9); - f32 grain = 0.7f + 0.3f * blob(::fmod(u * 5.0f, 1.0f), ::fmod(v * 5.0f, 1.0f), 5, 5); + f32 grain = 0.7f + 0.3f * blob(::fmodf(u * 5.0f, 1.0f), ::fmodf(v * 5.0f, 1.0f), 5, 5); return m * grain; }; for (u32 y = 0; y < channels.height; ++y) { @@ -2231,7 +2231,7 @@ void DemoScenes::CreateBrickDemoScene() { nx = (moss_height(u - e, v) - moss_height(u + e, v)) * 3.0f; ny = (moss_height(u, v - e) - moss_height(u, v + e)) * 3.0f; } - f32 nz = ::sqrt(rx::Max(1.0f - nx * nx - ny * ny, 0.05f)); + f32 nz = ::sqrtf(rx::Max(1.0f - nx * nx - ny * ny, 0.05f)); channels.data[o] = static_cast((nx * 0.5f + 0.5f) * 255.0f); channels.data[o + 1] = static_cast((ny * 0.5f + 0.5f) * 255.0f); channels.data[o + 2] = static_cast((nz * 0.5f + 0.5f) * 255.0f); @@ -2306,9 +2306,9 @@ void DemoScenes::CreateSilhouettePomDemoScene() { // Grid of rounded domes; deep flat gaps between them give the limb something // to carve. Round-shouldered so the normal map stays smooth. f32 cu = u * kTilesU, cv = v * kTilesV; - f32 fu = cu - ::floor(cu) - 0.5f; - f32 fv = cv - ::floor(cv) - 0.5f; - f32 d = ::sqrt(fu * fu + fv * fv) * 2.0f; // 0 centre .. ~1.4 corner + f32 fu = cu - ::floorf(cu) - 0.5f; + f32 fv = cv - ::floorf(cv) - 0.5f; + f32 d = ::sqrtf(fu * fu + fv * fv) * 2.0f; // 0 centre .. ~1.4 corner f32 h = rx::Max(0.0f, 1.0f - d / 0.82f); return h * h * (3.0f - 2.0f * h); // smoothstep dome }; @@ -2333,7 +2333,7 @@ void DemoScenes::CreateSilhouettePomDemoScene() { f32 hx = stud_height(u + e, v) - stud_height(u - e, v); f32 hy = stud_height(u, v + e) - stud_height(u, v - e); f32 nx = -hx * 6.0f, ny = -hy * 6.0f, nz = 1.0f; - f32 len = ::sqrt(nx * nx + ny * ny + nz * nz); + f32 len = ::sqrtf(nx * nx + ny * ny + nz * nz); normal.data[o] = static_cast((nx / len * 0.5f + 0.5f) * 255.0f); normal.data[o + 1] = static_cast((ny / len * 0.5f + 0.5f) * 255.0f); normal.data[o + 2] = static_cast((nz / len * 0.5f + 0.5f) * 255.0f); @@ -2555,8 +2555,8 @@ void DemoScenes::CreateFireDemoScene() { f32 a = static_cast(i) * 1.2566f; Quat q = QuatFromAxisAngle({0, 1, 0}, a); ecs::Entity e = world_.Create(); - world_.Add(e, scene::Transform{.position = {::cos(a) * 0.28f, 0.10f + 0.02f * i, - ::sin(a) * 0.28f}, + world_.Add(e, scene::Transform{.position = {::cosf(a) * 0.28f, 0.10f + 0.02f * i, + ::sinf(a) * 0.28f}, .rotation = {q.x, q.y, q.z, q.w}}); world_.Add(e, scene::Renderable{log.id}); } @@ -2893,11 +2893,11 @@ void DemoScenes::CreatePointLightDemoScene() { spot.color_intensity[0] = 1.0f; spot.color_intensity[1] = 0.95f; spot.color_intensity[2] = 0.8f; spot.color_intensity[3] = 20.0f; f32 dir[3] = {0.35f, -0.85f, -0.4f}; - f32 len = ::sqrt(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]); + f32 len = ::sqrtf(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]); spot.direction_type[0] = dir[0]/len; spot.direction_type[1] = dir[1]/len; spot.direction_type[2] = dir[2]/len; spot.direction_type[3] = 1.0f; // spot - spot.params[0] = ::cos(0.28f); // inner ~16 deg - spot.params[1] = ::cos(0.45f); // outer ~26 deg + spot.params[0] = ::cosf(0.28f); // inner ~16 deg + spot.params[1] = ::cosf(0.45f); // outer ~26 deg demo_lights_.push_back(spot); render::PointLight ball; @@ -3318,9 +3318,9 @@ void DemoScenes::CreateSwampDemoScene() { // Small-angle lean as a quaternion straight from the half-angles: the // snags list drunkenly instead of standing surveyor-straight. f32 hx = tilt_x * 0.5f, hz = tilt_z * 0.5f; - t.rotation[0] = ::sin(hx); - t.rotation[2] = ::sin(hz); - t.rotation[3] = ::cos(hx) * ::cos(hz); + t.rotation[0] = ::sinf(hx); + t.rotation[2] = ::sinf(hz); + t.rotation[3] = ::cosf(hx) * ::cosf(hz); world_.Add(e, t); world_.Add(e, scene::Renderable{mesh.id}); }; @@ -3347,7 +3347,7 @@ void DemoScenes::CreateSwampDemoScene() { for (int i = 0; i < 26; ++i) { f32 x = (next01() - 0.5f) * 140.0f; f32 z = (next01() - 0.5f) * 140.0f; - if (::fabs(x) < 4.0f && ::fabs(z) < 4.0f) continue; // keep the spawn clear + if (::fabsf(x) < 4.0f && ::fabsf(z) < 4.0f) continue; // keep the spawn clear f32 h = next01() < 0.3f ? 3.0f + next01() * 3.0f : 8.0f + next01() * 9.0f; f32 w = 0.25f + next01() * 0.35f; f32 tx = (next01() - 0.5f) * 0.16f; @@ -3416,9 +3416,9 @@ void DemoScenes::EmitSky(f32 dt) { Vec3 cam = camera_.position(); f32 dx = cc.tornado_pos.x - cam.x; f32 dz = cc.tornado_pos.y - cam.z; - f32 flat = ::sqrt(dx * dx + dz * dz); + f32 flat = ::sqrtf(dx * dx + dz * dz); // forward() is (sin yaw, sin pitch, -cos yaw): aim a third up the funnel. - camera_.set_yaw_pitch(::atan2(dx, -dz), ::atan2(300.0f - cam.y, flat)); + camera_.set_yaw_pitch(::atan2f(dx, -dz), ::atan2f(300.0f - cam.y, flat)); } if (cc.tornado_strength > 0.05f && !sky_tornado_seen_) { sky_tornado_seen_ = true; @@ -3444,7 +3444,7 @@ void DemoScenes::EmitSky(f32 dt) { Vec3 cam = camera_.position(); f32 dx = w.strike_pos.x - cam.x, dy = w.strike_pos.y + 400.0f - cam.y; f32 dz = w.strike_pos.z - cam.z; - f32 dist = ::sqrt(dx * dx + dy * dy + dz * dz); + f32 dist = ::sqrtf(dx * dx + dy * dy + dz * dz); sky_thunder_.push_back({dist / 343.0f, w.strike_pos, w.strike_seed, w.strike_energy, dist}); } for (u32 i = 0; i < sky_thunder_.size();) { @@ -3485,7 +3485,7 @@ void DemoScenes::UpdateStorm(f32 dt) { // Peak ~0.35: the global consumers multiply hard (sun +9x, ambient +0.5 // at flash 1.0) and would white the staged overcast frame out above that. w.lightning = rx::Min( - 1.0f, w.strike_energy * (0.22f * ::exp(-w.strike_age * 9.0f) + 0.35f * env)); + 1.0f, w.strike_energy * (0.22f * ::expf(-w.strike_age * 9.0f) + 0.35f * env)); if (w.strike_age > 1.2f) { // envelope + afterglow both spent w.strike_age = -1.0f; w.lightning = 0.0f; @@ -3504,7 +3504,7 @@ void DemoScenes::UpdateStorm(f32 dt) { if (test_dist > 0.0f) { // Deterministic: directly in front of the camera at the given distance. Vec3 fwd = camera_.forward(); - f32 len = ::sqrt(fwd.x * fwd.x + fwd.z * fwd.z); + f32 len = ::sqrtf(fwd.x * fwd.x + fwd.z * fwd.z); Vec3 dir = len > 1e-4f ? Vec3{fwd.x / len, 0.0f, fwd.z / len} : Vec3{0, 0, -1}; Vec3 eye = camera_.position(); w.strike_pos = {eye.x + dir.x * test_dist, 0.0f, eye.z + dir.z * test_dist}; @@ -3515,7 +3515,7 @@ void DemoScenes::UpdateStorm(f32 dt) { f32 az = hash01(w.strike_seed * 3u + 1u) * 6.2831853f; f32 dist = 300.0f + 600.0f * hash01(w.strike_seed * 3u + 2u); Vec3 eye = camera_.position(); - w.strike_pos = {eye.x + ::cos(az) * dist, 0.0f, eye.z + ::sin(az) * dist}; + w.strike_pos = {eye.x + ::cosf(az) * dist, 0.0f, eye.z + ::sinf(az) * dist}; w.strike_energy = 0.65f + 0.35f * hash01(w.strike_seed * 3u + 3u); storm_next_strike_ = storm_time_ + 6.0f + 3.0f * hash01(w.strike_seed * 7u + 5u); } @@ -3782,8 +3782,8 @@ void DemoScenes::CreateDemoScene() { scheduler_.AddSystem(ecs::Stage::kSim, "demo_spin", [](ecs::World& world, f32 dt) { world.Each([dt](ecs::Entity, Spin& spin, scene::Transform& t) { spin.angle += spin.speed * dt; - t.rotation[1] = ::sin(spin.angle * 0.5f); - t.rotation[3] = ::cos(spin.angle * 0.5f); + t.rotation[1] = ::sinf(spin.angle * 0.5f); + t.rotation[3] = ::cosf(spin.angle * 0.5f); }); }); RX_INFO("no scene given, spinning a cube instead"); @@ -3884,7 +3884,7 @@ void DemoScenes::EmitLocomotion(f32 dt, render::FrameView& view) { if (ctx_.actions) { f32 mx = ctx_.actions->axis(Axis::kMoveX); f32 my = ctx_.actions->axis(Axis::kMoveY); - f32 mag = ::sqrt(mx * mx + my * my); + f32 mag = ::sqrtf(mx * mx + my * my); if (mag > 0.05f) { speed = rx::Min(mag, 1.0f) * 4.5f; // full stick -> run input_driven = true; diff --git a/runtime/demo_ship.cc b/runtime/demo_ship.cc index 24f2e1b6..fbcb5504 100644 --- a/runtime/demo_ship.cc +++ b/runtime/demo_ship.cc @@ -98,7 +98,7 @@ void AddCylinder(MeshBuild& mb, const Vec3& a, const Vec3& b, f32 r0, f32 r1, u3 f32 r = ring == 0 ? r0 : r1; for (u32 s = 0; s < seg; ++s) { f32 t = 2.0f * kPi * static_cast(s) / seg; - Vec3 local{::cos(t) * r, 0, ::sin(t) * r}; + Vec3 local{::cosf(t) * r, 0, ::sinf(t) * r}; mb.Add(center + Rotate(q, local), static_cast(s) / seg, static_cast(ring), color); } } @@ -131,7 +131,7 @@ asset::Mesh Finish(MeshBuild& mb, const char* id, const asset::Material& mat) { // Bounds from the local extent (a loose sphere is enough for cull). f32 r = 0; for (const asset::Vertex& vert : mb.v) { - r = rx::Max(r, ::sqrt(vert.position[0] * vert.position[0] + + r = rx::Max(r, ::sqrtf(vert.position[0] * vert.position[0] + vert.position[1] * vert.position[1] + vert.position[2] * vert.position[2])); } @@ -326,8 +326,8 @@ void ShipDemo::BuildFlagship() { f32 deck = sheer(z); for (u32 pj = 0; pj <= kProfile; ++pj) { f32 th = kPi * static_cast(pj) / kProfile; // 0 = starboard rail .. pi = port rail - f32 x = -kBeam * ws * ::cos(th); - f32 y = deck - (deck - kKeelY) * ::pow(::sin(th), 0.62f); + f32 x = -kBeam * ws * ::cosf(th); + f32 y = deck - (deck - kKeelY) * ::powf(::sinf(th), 0.62f); hb.Add({x, y, z}, static_cast(pj) / kProfile, z / 8.0f); } } @@ -414,7 +414,7 @@ void ShipDemo::BuildFlagship() { f32 x = (a - 0.5f) * 2.0f * s.halfw; f32 y = s.top - b * height; // Bulge downwind (+Z), max at centre, fuller toward the foot. - f32 bulge = ::sin(kPi * a) * (0.25f + 0.75f * b) * billow; + f32 bulge = ::sinf(kPi * a) * (0.25f + 0.75f * b) * billow; Vec3 p = Vec3{x, y, s.z} + kWindDir * bulge; // uv.y drives the mesh.vs cloth-sway weight (0 = pinned head). Cap the // free-edge weight below 1 so the strong default wind flutters the foot @@ -559,7 +559,7 @@ void ShipDemo::UpdateSailsAndRopes(f32 dt, render::FrameView& view) { // frame; the ship barely yaws so the constant approximation is fine. const f32 h2 = dt * dt; Vec3 gravity{0, -9.8f, 0}; - f32 gust = 0.6f + 0.4f * ::sin(time_ * 2.3f); + f32 gust = 0.6f + 0.4f * ::sinf(time_ * 2.3f); Vec3 wind = Rotate(QuatBetween(Rotate(hull_rot_, {0, 0, 1}), {0, 0, 1}), kWindDir) * (4.5f * gust); MeshBuild rm; @@ -712,7 +712,7 @@ void ShipDemo::UpdateParticles(f32 dt, render::FrameView& view) { sp.pos = d.position; f32 ang = Rand() * 2.0f * kPi; f32 spread = Rand() * 2.2f; - sp.vel = {::cos(ang) * spread, 3.5f + Rand() * 3.5f, ::sin(ang) * spread}; + sp.vel = {::cosf(ang) * spread, 3.5f + Rand() * 3.5f, ::sinf(ang) * spread}; sp.color = {0.9f, 1.0f, 1.1f}; sp.max_life = sp.life = 0.6f + Rand() * 0.5f; sp.size = 0.14f + Rand() * 0.14f; @@ -759,7 +759,7 @@ void ShipDemo::UpdateParticles(f32 dt, render::FrameView& view) { // Hull-waterline wake: bow/stern/side impulses scaled by cruise speed, the same // WaterDisturbance path the water-demo cubes use, so the field draws the trail. void ShipDemo::EmitWake(render::FrameView& view) { - f32 speed = ::sqrt(hull_vel_.x * hull_vel_.x + hull_vel_.z * hull_vel_.z); + f32 speed = ::sqrtf(hull_vel_.x * hull_vel_.x + hull_vel_.z * hull_vel_.z); const Vec3 local_pts[5] = {{0, 0, kHalfLen * 0.9f}, // bow {0, 0, -kHalfLen * 0.9f}, // stern {kBeam, 0, 0}, // port beam @@ -781,18 +781,18 @@ void ShipDemo::EmitWake(render::FrameView& view) { void ShipDemo::FollowCamera() { // Unattended framing: a 3/4 stern chase unless the player is steering. if (ctx_.actions) { - f32 mag = ::fabs(ctx_.actions->axis(Axis::kLookX)) + - ::fabs(ctx_.actions->axis(Axis::kLookY)) + - ::fabs(ctx_.actions->axis(Axis::kMoveX)) + - ::fabs(ctx_.actions->axis(Axis::kMoveY)); + f32 mag = ::fabsf(ctx_.actions->axis(Axis::kLookX)) + + ::fabsf(ctx_.actions->axis(Axis::kLookY)) + + ::fabsf(ctx_.actions->axis(Axis::kMoveX)) + + ::fabsf(ctx_.actions->axis(Axis::kMoveY)); if (mag > 0.05f) return; // hand control to the fly camera } Vec3 offset = Rotate(hull_rot_, Vec3{-13.0f, 8.5f, -14.0f}); Vec3 cam = hull_pos_ + offset; Vec3 target = hull_pos_ + Vec3{0, 4.0f, 2.0f}; Vec3 dir = Normalize(target - cam); - f32 yaw = ::atan2(dir.x, -dir.z); - f32 pitch = ::asin(rx::Clamp(dir.y, -1.0f, 1.0f)); + f32 yaw = ::atan2f(dir.x, -dir.z); + f32 pitch = ::asinf(rx::Clamp(dir.y, -1.0f, 1.0f)); camera_.set_position(cam); camera_.set_yaw_pitch(yaw, pitch); } diff --git a/runtime/demo_shooter.cc b/runtime/demo_shooter.cc index f43b8e3e..41e4166d 100644 --- a/runtime/demo_shooter.cc +++ b/runtime/demo_shooter.cc @@ -470,7 +470,7 @@ void ShooterDemo::StepTargets(f32 dt) { target.strafe_phase += dt * 0.7f; Vec3 position = target.home; if (target.strafe_span > 0) { - position.x += ::sin(target.strafe_phase) * target.strafe_span; + position.x += ::sinf(target.strafe_phase) * target.strafe_span; } // A downed target drops through the floor and pops back up on respawn, // which also takes its hitboxes out of the line of fire. @@ -788,7 +788,7 @@ void ShooterDemo::DrawHud() { if (def && weapon && cam_fov_ > 0) { const f32 spread = combat::EffectiveSpread(*def, *weapon, *intent); const f32 pixels = rx::Clamp( - ::tan(spread) / ::tan(cam_fov_ * 0.5f) * size.y * 0.5f, 3.0f, size.y * 0.45f); + ::tanf(spread) / ::tanf(cam_fov_ * 0.5f) * size.y * 0.5f, 3.0f, size.y * 0.45f); const u32 color = IM_COL32(235, 240, 245, 210); const f32 arm = rx::Max(4.0f, pixels * 0.35f); draw->AddLine({middle.x - pixels - arm, middle.y}, {middle.x - pixels, middle.y}, color, 1.6f); diff --git a/runtime/feature_gym/feature_gym.cc b/runtime/feature_gym/feature_gym.cc index 9b075400..0af484a6 100644 --- a/runtime/feature_gym/feature_gym.cc +++ b/runtime/feature_gym/feature_gym.cc @@ -504,8 +504,8 @@ asset::Mesh MakeTree(asset::AssetId id, asset::AssetId material) { for (int side = 0; side < 10; ++side) { const f32 a0 = side * 2.0f * kPi / 10.0f; const f32 a1 = (side + 1) * 2.0f * kPi / 10.0f; - triangle({::cos(a0) * radius, base, ::sin(a0) * radius}, {0, tip, 0}, - {::cos(a1) * radius, base, ::sin(a1) * radius}, + triangle({::cosf(a0) * radius, base, ::sinf(a0) * radius}, {0, tip, 0}, + {::cosf(a1) * radius, base, ::sinf(a1) * radius}, side & 1 ? 0xff245a27 : 0xff377a31); } } @@ -950,7 +950,7 @@ void FeatureGym::Impl::Create() { ctx.camera->set_position({0, 50, 56}); const Vec3 direction = Normalize(Vec3{0, 0, -14} - ctx.camera->position()); - ctx.camera->set_yaw_pitch(::atan2(direction.x, -direction.z), ::asin(direction.y)); + ctx.camera->set_yaw_pitch(::atan2f(direction.x, -direction.z), ::asinf(direction.y)); ctx.camera->speed = 15.0f; RX_INFO( "feature gym: nine self-contained districts ready; use RX_SHOWCASE=1 " @@ -1251,8 +1251,8 @@ void FeatureGym::Impl::CreateLighting() { spot.direction_type[1] = spot_direction.y; spot.direction_type[2] = spot_direction.z; spot.direction_type[3] = 1; - spot.params[0] = ::cos(0.28f); - spot.params[1] = ::cos(0.48f); + spot.params[0] = ::cosf(0.28f); + spot.params[1] = ::cosf(0.48f); lights.push_back(spot); render::PointLight sphere; @@ -1340,7 +1340,7 @@ void FeatureGym::Impl::CreateGeometry() { const f32 pz = (static_cast(z) / kGrid - 0.5f) * kVirtualGeometrySize; asset::Vertex vertex{}; vertex.position[0] = px; - vertex.position[1] = ::sin(px * 1.4f) * ::cos(pz * 1.2f) * 0.6f; + vertex.position[1] = ::sinf(px * 1.4f) * ::cosf(pz * 1.2f) * 0.6f; vertex.position[2] = pz; vertex.normal[1] = 1; terrain_lod.vertices.push_back(vertex); @@ -1385,7 +1385,7 @@ void FeatureGym::Impl::CreateGeometry() { const Vec3 position = c + Vec3{-10.0f + column * 2.2f, 0.45f, -1.0f - row * 2.1f}; prop_transforms.push_back(MakeTranslation(position) * MakeScale(scale)); prop_updated_transforms.push_back( - MakeTranslation(position + Vec3{0, 0.35f + 0.12f * ::sin(column * 0.7f), -0.45f}) * + MakeTranslation(position + Vec3{0, 0.35f + 0.12f * ::sinf(column * 0.7f), -0.45f}) * MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.18f * (row + column))) * MakeScale(scale)); } } @@ -1405,9 +1405,9 @@ void FeatureGym::Impl::CreateGeometry() { const f32 angle = i * 2.39996323f; const f32 radius = 10.0f + (i % 9) * 0.65f; render::ImposterPass::Instance instance; - instance.position[0] = c.x + ::cos(angle) * radius; + instance.position[0] = c.x + ::cosf(angle) * radius; instance.position[1] = 0.1f; - instance.position[2] = c.z + ::sin(angle) * radius; + instance.position[2] = c.z + ::sinf(angle) * radius; instance.scale = 0.65f + (i % 5) * 0.08f; instance.mesh = baked; imposters.push_back(instance); @@ -1478,7 +1478,7 @@ void FeatureGym::Impl::CreateWater() { const f32 local_x = -kIslandRadius + 2.0f * kIslandRadius * static_cast(x) / kIslandGrid; const f32 local_z = -kIslandRadius + 2.0f * kIslandRadius * static_cast(z) / kIslandGrid; const f32 gaussian = - ::exp(-(local_x * local_x + local_z * local_z) / (2.0f * kIslandSigma * kIslandSigma)); + ::expf(-(local_x * local_x + local_z * local_z) / (2.0f * kIslandSigma * kIslandSigma)); const f32 slope = kIslandPeak * 2.0f * gaussian / (kIslandSigma * kIslandSigma); const Vec3 island_normal = Normalize(Vec3{slope * local_x, 1, slope * local_z}); asset::Vertex vertex{}; @@ -1511,7 +1511,7 @@ void FeatureGym::Impl::CreateWater() { Spawn(island.id, island_center); physics.set_water_height([this, c](const Vec3& p, f32* out, Vec3* flow) { - if (::abs(p.x - c.x) > 14 || ::abs(p.z - c.z) > 14) return false; + if (::fabsf(p.x - c.x) > 14 || ::fabsf(p.z - c.z) > 14) return false; Vec3 orbital_flow{}; *out = water_height + physics::GerstnerWaveHeight(p.x, p.z, sim_time, &orbital_flow); if (flow) *flow = orbital_flow; @@ -1590,9 +1590,9 @@ void FeatureGym::Impl::CreateEffects() { for (u32 i = 0; i < kSplatCount; ++i) { const f32 t = (i + 0.5f) / kSplatCount; const f32 y = 1.0f - 2.0f * t; - const f32 radius = ::sqrt(rx::Max(0.0f, 1.0f - y * y)); + const f32 radius = ::sqrtf(rx::Max(0.0f, 1.0f - y * y)); const f32 angle = i * 2.39996323f; - const Vec3 direction{::cos(angle) * radius, y, ::sin(angle) * radius}; + const Vec3 direction{::cosf(angle) * radius, y, ::sinf(angle) * radius}; render::GaussianInstance splat; splat.position[0] = c.x + 5.2f + direction.x * 1.6f; splat.position[1] = 2.0f + direction.y * 1.6f; @@ -1773,7 +1773,7 @@ void FeatureGym::Impl::CreatePhysics() { base::Array heights{}; for (u32 z = 0; z < kHeightSamples; ++z) for (u32 x = 0; x < kHeightSamples; ++x) - heights[z * kHeightSamples + x] = 0.25f * ::sin(x * 0.7f) * ::cos(z * 0.55f); + heights[z * kHeightSamples + x] = 0.25f * ::sinf(x * 0.7f) * ::cosf(z * 0.55f); physics.AddHeightField(c + Vec3{-11, 0, -10}, heights.data(), kHeightSamples, 8.0f); CreateCloth(); } @@ -1918,8 +1918,8 @@ void FeatureGym::Impl::CreateDrivingCircuit() { for (u32 i = 0; i < kOvalSegments; ++i) { const f32 a0 = (static_cast(i) / kOvalSegments) * 2.0f * kPi; const f32 a1 = (static_cast(i + 1) / kOvalSegments) * 2.0f * kPi; - lines.push_back({c + Vec3{rx * ::cos(a0), 0.09f, rz * ::sin(a0)}, - c + Vec3{rx * ::cos(a1), 0.09f, rz * ::sin(a1)}, color}); + lines.push_back({c + Vec3{rx * ::cosf(a0), 0.09f, rz * ::sinf(a0)}, + c + Vec3{rx * ::cosf(a1), 0.09f, rz * ::sinf(a1)}, color}); } }; oval(circuit_rx, circuit_rz, 0xf4f4f5ff); @@ -1934,7 +1934,7 @@ void FeatureGym::Impl::CreateDrivingCircuit() { for (u32 i = 0; i < kCones; ++i) { const f32 a = (static_cast(i) / kCones) * 2.0f * kPi; Spawn(cone, - c + Vec3{(circuit_rx + 1.3f) * ::cos(a), 0.36f, (circuit_rz + 1.3f) * ::sin(a)}); + c + Vec3{(circuit_rx + 1.3f) * ::cosf(a), 0.36f, (circuit_rz + 1.3f) * ::sinf(a)}); } // The circuit car reuses the chassis + wheel meshes uploaded in @@ -2011,7 +2011,7 @@ void FeatureGym::Impl::CreateAnimation() { target.name_hash = asset::MakeAssetId(target.name).hash; target.position_deltas.reserve(morph.lods[0].vertices.size() * 3); for (const asset::Vertex& vertex : morph.lods[0].vertices) { - const f32 wave = 0.26f * ::sin(vertex.position[1] * 6.0f); + const f32 wave = 0.26f * ::sinf(vertex.position[1] * 6.0f); target.position_deltas.push_back(vertex.normal[0] * wave); target.position_deltas.push_back(vertex.normal[1] * wave); target.position_deltas.push_back(vertex.normal[2] * wave); @@ -2171,7 +2171,7 @@ void FeatureGym::Impl::AddSimulation() { [this](ecs::Entity, GymMotion& motion, scene::Transform& transform) { const f32 angle = sim_time * motion.speed + motion.phase; transform.position[0] = motion.origin.x; - transform.position[1] = motion.origin.y + ::sin(angle * 1.7f) * motion.amplitude; + transform.position[1] = motion.origin.y + ::sinf(angle * 1.7f) * motion.amplitude; transform.position[2] = motion.origin.z; const Quat rotation = QuatFromAxisAngle(motion.axis, angle); transform.rotation[0] = rotation.x; @@ -2184,25 +2184,25 @@ void FeatureGym::Impl::AddSimulation() { [dt](ecs::Entity, BubbleAgent& agent, scene::Transform& transform) { agent.time += dt; transform.position[0] = - agent.center.x + ::sin(agent.time * agent.rate_x) * agent.extent; + agent.center.x + ::sinf(agent.time * agent.rate_x) * agent.extent; transform.position[1] = agent.center.y; transform.position[2] = - agent.center.z + ::cos(agent.time * agent.rate_z) * agent.extent; + agent.center.z + ::cosf(agent.time * agent.rate_z) * agent.extent; }); if (strand_sim) { const f32 angle = sim_time * 0.85f; const Vec3 position = - strand_center + Vec3{0.08f * ::sin(angle), 0.10f * ::sin(angle * 1.7f), 0}; + strand_center + Vec3{0.08f * ::sinf(angle), 0.10f * ::sinf(angle * 1.7f), 0}; strand_transform = MakeTranslation(position) * - MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.7f * ::sin(angle))); + MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.7f * ::sinf(angle))); physics.SetStrandGroomTransform(strand_sim, strand_transform, dt); physics.SetStrandGroomWind(strand_sim, - {0.8f + 0.45f * ::sin(sim_time * 2.1f), 0.12f, -0.35f}); + {0.8f + 0.45f * ::sinf(sim_time * 2.1f), 0.12f, -0.35f}); } const f32 identity[4] = {0, 0, 0, 1}; if (platform_body) { - const Vec3 target = platform_origin + Vec3{::sin(sim_time * 0.7f) * 3.5f, 0, 0}; + const Vec3 target = platform_origin + Vec3{::sinf(sim_time * 0.7f) * 3.5f, 0, 0}; physics.MoveBodyKinematic(platform_body, target, identity, dt); if (scene::Transform* transform = sim_world.Get(platform_entity)) { transform->position[0] = target.x; @@ -2221,7 +2221,7 @@ void FeatureGym::Impl::AddSimulation() { if (transform->position[0] < physics_x - 9.0f) character_direction = 1; } const int cycle = static_cast(sim_time / 5.0f); - const bool jump = cycle != jump_cycle && ::fmod(sim_time, 5.0f) < dt * 1.5f; + const bool jump = cycle != jump_cycle && ::fmodf(sim_time, 5.0f) < dt * 1.5f; if (jump) jump_cycle = cycle; physics.MoveCharacter(character, {character_direction * 2.0f, 0, 0}, jump, dt, &position, &grounded); @@ -2237,7 +2237,7 @@ void FeatureGym::Impl::AddSimulation() { if (active == Area::kPhysics) { const bool accelerating = physics_active_time < 1.0f; physics.DriveVehicle(car, accelerating ? 0.10f : 0.0f, - ::sin(physics_active_time * 0.35f) * 0.35f, + ::sinf(physics_active_time * 0.35f) * 0.35f, accelerating ? 0.0f : 0.65f, 0.0f); } else { physics.DriveVehicle(car, 0, 0, 1, 0); @@ -2247,7 +2247,7 @@ void FeatureGym::Impl::AddSimulation() { if (active == Area::kPhysics) { const bool accelerating = physics_active_time < 1.0f; physics.DriveVehicle(bike, accelerating ? 0.08f : 0.0f, - ::sin(physics_active_time * 0.42f) * 0.22f, + ::sinf(physics_active_time * 0.42f) * 0.22f, accelerating ? 0.0f : 0.55f, 0.0f); } else { physics.DriveVehicle(bike, 0, 0, 1, 0); @@ -2257,13 +2257,13 @@ void FeatureGym::Impl::AddSimulation() { if (active_mode == TourMode::kVehicleCircuit) { circuit_time += dt; const f32 theta = circuit_time * 0.6f + 0.42f; - const Vec3 target = circuit_center + Vec3{circuit_rx * ::cos(theta), 0, - circuit_rz * ::sin(theta)}; + const Vec3 target = circuit_center + Vec3{circuit_rx * ::cosf(theta), 0, + circuit_rz * ::sinf(theta)}; Vec3 pos; f32 rot[4]; if (physics.GetVehicleTransform(circuit_car, &pos, rot)) { const Vec3 fwd = Rotate(Quat{rot[0], rot[1], rot[2], rot[3]}, Vec3{0, 0, 1}); - f32 err = ::atan2(target.x - pos.x, target.z - pos.z) - ::atan2(fwd.x, fwd.z); + f32 err = ::atan2f(target.x - pos.x, target.z - pos.z) - ::atan2f(fwd.x, fwd.z); while (err > kPi) err -= 2.0f * kPi; while (err < -kPi) err += 2.0f * kPi; // +Z forward, right = -X, so steer (positive = right) chases the @@ -2301,8 +2301,8 @@ void FeatureGym::Impl::AddSimulation() { const physics::BoatState& s = boat->state(); const f32 theta = boat_time * 0.5f + 0.6f; Vec3 target = boat_circuit_center + - Vec3{boat_circuit_radius * ::cos(theta), 0, - boat_circuit_radius * ::sin(theta)}; + Vec3{boat_circuit_radius * ::cosf(theta), 0, + boat_circuit_radius * ::sinf(theta)}; // Safety backstop: a heavy hull turns wide, so if it // drifts past the ring steer straight for the lake // centre. This bounds the path inside the water region @@ -2314,14 +2314,14 @@ void FeatureGym::Impl::AddSimulation() { (boat_circuit_radius + 1.0f) * (boat_circuit_radius + 1.0f); if (outside) target = boat_circuit_center; const Vec3 fwd = Rotate(s.rotation, Vec3{0, 0, 1}); - f32 err = ::atan2(target.x - s.position.x, target.z - s.position.z) - - ::atan2(fwd.x, fwd.z); + f32 err = ::atan2f(target.x - s.position.x, target.z - s.position.z) - + ::atan2f(fwd.x, fwd.z); while (err > kPi) err -= 2.0f * kPi; while (err < -kPi) err += 2.0f * kPi; // Ease off the throttle when steering hard or recovering // so the hull stays slow enough to answer the helm. input.steer = rx::Clamp(-err * 2.2f, -1.0f, 1.0f); - input.throttle = (outside || ::abs(err) > 1.0f) ? 0.12f : 0.22f; + input.throttle = (outside || ::fabsf(err) > 1.0f) ? 0.12f : 0.22f; } else { boat_cruise_active = false; boat_time = 0; @@ -2354,7 +2354,7 @@ void FeatureGym::Impl::AddSimulation() { plane_time += dt; const physics::AircraftState& s = aircraft->state(); const Vec3 fwd = Rotate(s.rotation, Vec3{0, 0, 1}); - f32 herr = (kPi * 0.5f) - ::atan2(fwd.x, fwd.z); + f32 herr = (kPi * 0.5f) - ::atan2f(fwd.x, fwd.z); while (herr > kPi) herr -= 2.0f * kPi; while (herr < -kPi) herr += 2.0f * kPi; // Hold heading +X with a gentle bank + rudder, hold the cruise altitude @@ -2441,7 +2441,7 @@ void FeatureGym::Impl::EmitAnimation(f32 dt, render::FrameView& view) { if (!graph.valid()) return; const f32 animation_dt = rx::Min(dt, 0.05f); biped_time += animation_dt; - const f32 phase = ::fmod(biped_time, 8.0f); + const f32 phase = ::fmodf(biped_time, 8.0f); const f32 speed = phase < 1.0f ? 0.0f : phase < 3.0f ? 1.6f : 3.8f; rig.SetSpeed(speed); Vec3 root = rig.Update(animation_dt, &pose, [&](const anim::RigPlayer::Event& event) { @@ -2513,7 +2513,7 @@ void FeatureGym::Impl::EmitAnimation(f32 dt, render::FrameView& view) { if (splat_timer > 0.8f) { splat_timer = 0; const f32 angle = static_cast(splat_index) * 2.39996f; // golden angle - const Vec3 dir{::cos(angle), 0.0f, ::sin(angle)}; + const Vec3 dir{::cosf(angle), 0.0f, ::sinf(angle)}; const f32 height = 0.55f + 0.28f * static_cast(splat_index % 4); render::DecalStamp splat; splat.receiver = biped_decal_receiver; @@ -2536,7 +2536,7 @@ void FeatureGym::Impl::EmitAnimation(f32 dt, render::FrameView& view) { morph.prev_transform = morph_previous; morph.morph_offset = static_cast(view.morph_weights.size()); morph.morph_count = 1; - view.morph_weights.push_back({0, ::sin(render_time * 1.7f) * 0.5f + 0.5f}); + view.morph_weights.push_back({0, ::sinf(render_time * 1.7f) * 0.5f + 0.5f}); view.draws.push_back(morph); morph_previous = morph_transform; } @@ -2741,11 +2741,11 @@ void FeatureGym::Impl::EmitSkewedNormals(render::FrameView& view) { void FeatureGym::Impl::EmitCameraExhibit(f32 dt, render::FrameView& view) { if (active_mode != TourMode::kEcsCameraStackRig || !camera_activation) return; if (scene::CameraOrbit* orbit = world.Get(camera_rig_mode)) - orbit->yaw = 0.22f * ::sin(active_mode_elapsed * 0.7f); + orbit->yaw = 0.22f * ::sinf(active_mode_elapsed * 0.7f); if (scene::CameraAnchor* anchor = world.Get(camera_rig_mode)) { const Vec3 c = Info(Area::kPost).center; - anchor->position = c + Vec3{::sin(active_mode_elapsed * 0.6f) * 1.2f, 0.4f, 0}; - anchor->velocity = {::cos(active_mode_elapsed * 0.6f) * 0.72f, 0, 0}; + anchor->position = c + Vec3{::sinf(active_mode_elapsed * 0.6f) * 1.2f, 0.4f, 0}; + anchor->velocity = {::cosf(active_mode_elapsed * 0.6f) * 0.72f, 0, 0}; } scene::BuildCameraRigs(world, dt); scene::PrepareCameraRigConstraints(world, dt); diff --git a/runtime/fly_camera.cc b/runtime/fly_camera.cc index 19e6a611..5d602290 100644 --- a/runtime/fly_camera.cc +++ b/runtime/fly_camera.cc @@ -6,7 +6,7 @@ namespace rx { Vec3 FlyCamera::forward() const { - return {::cos(pitch_) * ::sin(yaw_), ::sin(pitch_), -::cos(pitch_) * ::cos(yaw_)}; + return {::cosf(pitch_) * ::sinf(yaw_), ::sinf(pitch_), -::cosf(pitch_) * ::cosf(yaw_)}; } void FlyCamera::Update(const InputState& input, const ActionState& actions, bool allow_mouse, @@ -17,7 +17,7 @@ void FlyCamera::Update(const InputState& input, const ActionState& actions, bool yaw_ += input.mouse_dx * sensitivity; pitch_ -= input.mouse_dy * sensitivity; if (input.wheel != 0) { - speed *= ::pow(1.2f, input.wheel); + speed *= ::powf(1.2f, input.wheel); speed = rx::Clamp(speed, 0.1f, 200.0f); } } @@ -39,7 +39,7 @@ void FlyCamera::Update(const InputState& input, const ActionState& actions, bool if (actions.down(Action::kCamUp) || actions.down(Action::kJump)) move += Vec3{0, 1, 0}; if (actions.down(Action::kCamDown) || actions.down(Action::kSneak)) move += Vec3{0, -1, 0}; - f32 length = ::sqrt(Dot(move, move)); + f32 length = ::sqrtf(Dot(move, move)); if (length > 0) { f32 boost = actions.down(Action::kSprint) ? 4.0f : 1.0f; position_ += move * (speed * boost * dt / length); diff --git a/runtime/placement_demo_assets.cc b/runtime/placement_demo_assets.cc index 8fa0eff5..e8b461ae 100644 --- a/runtime/placement_demo_assets.cc +++ b/runtime/placement_demo_assets.cc @@ -42,7 +42,7 @@ u32 PushVertex(asset::MeshLod* lod, const Vec3& p, const Vec3& n) { v.normal[2] = n.z; // A stable tangent roughly perpendicular to the normal keeps the tangent // frame finite for normal-mapped materials; exact orientation is unimportant. - Vec3 t = ::abs(n.y) < 0.99f ? Normalize(Cross(Vec3{0, 1, 0}, n)) : Vec3{1, 0, 0}; + Vec3 t = ::fabsf(n.y) < 0.99f ? Normalize(Cross(Vec3{0, 1, 0}, n)) : Vec3{1, 0, 0}; v.tangent[0] = t.x; v.tangent[1] = t.y; v.tangent[2] = t.z; @@ -56,7 +56,7 @@ u32 PushVertex(asset::MeshLod* lod, const Vec3& p, const Vec3& n) { // An orthonormal basis (t, b) spanning the plane perpendicular to axis `d`. void Basis(const Vec3& d, Vec3* t, Vec3* b) { - Vec3 up = ::abs(d.y) < 0.99f ? Vec3{0, 1, 0} : Vec3{1, 0, 0}; + Vec3 up = ::fabsf(d.y) < 0.99f ? Vec3{0, 1, 0} : Vec3{1, 0, 0}; *t = Normalize(Cross(up, d)); *b = Cross(d, *t); } @@ -72,7 +72,7 @@ void AddTube(asset::MeshLod* lod, const Vec3& p0, f32 r0, const Vec3& p1, f32 r1 u32 base = static_cast(lod->vertices.size()); for (u32 k = 0; k < sides; ++k) { f32 a = kTau * static_cast(k) / static_cast(sides); - Vec3 radial = t * ::cos(a) + b * ::sin(a); + Vec3 radial = t * ::cosf(a) + b * ::sinf(a); PushVertex(lod, p0 + radial * r0, radial); PushVertex(lod, p1 + radial * r1, radial); } @@ -93,8 +93,8 @@ void AddCone(asset::MeshLod* lod, const Vec3& base_center, f32 radius, f32 heigh for (u32 k = 0; k < sides; ++k) { f32 a0 = kTau * static_cast(k) / static_cast(sides); f32 a1 = kTau * static_cast(k + 1) / static_cast(sides); - Vec3 p0 = base_center + Vec3{::cos(a0) * radius, 0, ::sin(a0) * radius}; - Vec3 p1 = base_center + Vec3{::cos(a1) * radius, 0, ::sin(a1) * radius}; + Vec3 p0 = base_center + Vec3{::cosf(a0) * radius, 0, ::sinf(a0) * radius}; + Vec3 p1 = base_center + Vec3{::cosf(a1) * radius, 0, ::sinf(a1) * radius}; Vec3 n = Normalize(Cross(p1 - p0, apex - p0)); u32 i0 = PushVertex(lod, p0, n); u32 i1 = PushVertex(lod, p1, n); @@ -113,10 +113,10 @@ void AddEllipsoid(asset::MeshLod* lod, const Vec3& center, const Vec3& scale, u3 u32 base = static_cast(lod->vertices.size()); for (u32 y = 0; y <= rings; ++y) { f32 phi = kPi * static_cast(y) / static_cast(rings); - f32 sp = ::sin(phi), cp = ::cos(phi); + f32 sp = ::sinf(phi), cp = ::cosf(phi); for (u32 x = 0; x <= segments; ++x) { f32 theta = kTau * static_cast(x) / static_cast(segments); - Vec3 u{sp * ::cos(theta), cp, sp * ::sin(theta)}; + Vec3 u{sp * ::cosf(theta), cp, sp * ::sinf(theta)}; Vec3 p{center.x + u.x * scale.x, center.y + u.y * scale.y, center.z + u.z * scale.z}; // Ellipsoid surface normal: unit-sphere normal divided by the scale. Vec3 n = Normalize(Vec3{u.x / scale.x, u.y / scale.y, u.z / scale.z}); @@ -335,10 +335,10 @@ asset::Mesh MakeRock(f32 radius, u32 seed, u64 material, asset::AssetId id) { for (u32 y = 0; y <= rings; ++y) { f32 phi = kPi * static_cast(y) / static_cast(rings); - f32 sp = ::sin(phi), cp = ::cos(phi); + f32 sp = ::sinf(phi), cp = ::cosf(phi); for (u32 x = 0; x <= segments; ++x) { f32 theta = kTau * static_cast(x) / static_cast(segments); - Vec3 u{sp * ::cos(theta), cp, sp * ::sin(theta)}; + Vec3 u{sp * ::cosf(theta), cp, sp * ::sinf(theta)}; f32 lump; if (y == 0) { lump = pole_top; @@ -383,7 +383,7 @@ asset::Mesh MakeGrassTuft(f32 height, u64 material, asset::AssetId id) { for (u32 i = 0; i < kBlades; ++i) { // Deterministic per-blade angle, height and lean. f32 angle = kTau * (static_cast(i) / kBlades) + Hash11(i * 31u + 1u) * 0.4f; - Vec3 dir{::cos(angle), 0, ::sin(angle)}; + Vec3 dir{::cosf(angle), 0, ::sinf(angle)}; Vec3 base{Hash11(i * 7u + 3u) * width * 0.3f, 0, Hash11(i * 13u + 5u) * width * 0.3f}; f32 h = height * (0.7f + 0.3f * Hash01(i * 17u + 9u)); Vec3 lean{Hash11(i * 23u + 2u) * height * 0.25f, 0, Hash11(i * 29u + 4u) * height * 0.25f}; @@ -412,7 +412,7 @@ asset::Mesh MakeDeadTree(f32 height, u64 material, asset::AssetId id) { f32 f = static_cast(b) / kBranches; f32 y = height * (0.5f + 0.32f * f); f32 angle = kTau * f + Hash11(static_cast(b) * 41u + 7u) * 0.5f; - Vec3 dir = Normalize(Vec3{::cos(angle), 0.8f, ::sin(angle)}); + Vec3 dir = Normalize(Vec3{::cosf(angle), 0.8f, ::sinf(angle)}); f32 len = height * (0.28f - 0.06f * f); Vec3 root{0, y, 0}; f32 r = trunk_r * (0.55f - 0.12f * f); diff --git a/runtime/scene_authoring.cc b/runtime/scene_authoring.cc index 3701c76d..f58d2789 100644 --- a/runtime/scene_authoring.cc +++ b/runtime/scene_authoring.cc @@ -863,9 +863,9 @@ bool ApplySceneEnvironment(ecs::World& world, render::RenderSettings* settings) // its negation. Azimuth turns +z toward +x, matching what a yaw of 90 does // to an entity, so "the sun is where that building is facing" is the same // number in both components. - const f32 horizontal = ::cos(elevation); - const Vec3 to_sun{horizontal * ::sin(azimuth), ::sin(elevation), - horizontal * ::cos(azimuth)}; + const f32 horizontal = ::cosf(elevation); + const Vec3 to_sun{horizontal * ::sinf(azimuth), ::sinf(elevation), + horizontal * ::cosf(azimuth)}; settings->sun_direction = {-to_sun.x, -to_sun.y, -to_sun.z}; settings->sun_color = {sun.color[0], sun.color[1], sun.color[2]}; settings->sun_intensity = sun.intensity; diff --git a/runtime/scene_validate.cc b/runtime/scene_validate.cc index 5b894157..e52b7785 100644 --- a/runtime/scene_validate.cc +++ b/runtime/scene_validate.cc @@ -245,7 +245,7 @@ void CheckNumberLiterals(ecs::World& world, const Source& source, Report& report // strtof, not strtod: 1e40 is a perfectly good double and an inf f32, and // it is the f32 the loader keeps. const f32 value = ::strtof(token.c_str(), &end); - if (end != token.c_str() && *end == '\0' && ::isfinite(value)) continue; + if (end != token.c_str() && *end == '\0' && isfinite(value)) continue; const bool number = end != token.c_str() && *end == '\0'; report.ErrorAt(entity, assign.line, number ? "non_finite" : "unparsed_number", rx::StrFormat("{}.{} = {}: '{}' {}; a strict load refuses the file and a " @@ -269,7 +269,7 @@ bool ReadLanes(const base::String& raw, u32 lanes, f32* out) { if (!in.Next(&token)) return true; // the legal short form; the rest stay 0 char* end = nullptr; const f32 value = ::strtof(token.c_str(), &end); - if (end == token.c_str() || *end != '\0' || !::isfinite(value)) return false; + if (end == token.c_str() || *end != '\0' || !isfinite(value)) return false; out[lane] = value; } return true; @@ -337,7 +337,7 @@ void CheckDiscardedTransform(ecs::World& world, const Source& source, bool grids if (!ReadLanes(assign.raw, lanes, authored)) continue; bool differs = false; for (u32 lane = 0; lane < lanes; ++lane) { - differs = differs || ::abs(authored[lane] - solved[lane]) > kDiscardedEpsilon; + differs = differs || ::fabsf(authored[lane] - solved[lane]) > kDiscardedEpsilon; } if (!differs) continue; @@ -369,12 +369,12 @@ void CheckTransform(ecs::World& world, ecs::Entity entity, Report& report) { report.Error(entity, "degenerate_rotation", "Transform.rotation is the zero quaternion; the mesh collapses to a point " "(identity is 0 0 0 1)"); - } else if (::abs(::sqrt(length_sq) - 1.0f) > 0.05f) { + } else if (::fabsf(::sqrtf(length_sq) - 1.0f) > 0.05f) { // 5% is far outside anything hand-rounding a unit quaternion produces // (0.7 0 0 0.7 is only 1% short) and well inside a visible mis-scale. report.Warn(entity, "non_unit_rotation", rx::StrFormat("Transform.rotation has length {}, so it scales the mesh by that " - "on top of Transform.scale", ::sqrt(length_sq))); + "on top of Transform.scale", ::sqrtf(length_sq))); } } diff --git a/runtime/viewer.cc b/runtime/viewer.cc index eb9a2528..7123fa78 100644 --- a/runtime/viewer.cc +++ b/runtime/viewer.cc @@ -606,8 +606,8 @@ void Viewer::StampTattoos(const asset::ImportedScene& scene, // One draw carries one layer tile, so every tattoo has to live in the zone // the first anchor picked; a later anchor on another zone would bake // outside the tile and shade nothing. - const i32 anchor_tile_u = static_cast(::floor(nearest->uv[0])); - const i32 anchor_tile_v = static_cast(::floor(nearest->uv[1])); + const i32 anchor_tile_u = static_cast(::floorf(nearest->uv[0])); + const i32 anchor_tile_v = static_cast(::floorf(nearest->uv[1])); if (!tile_chosen) { tile_u = anchor_tile_u; tile_v = anchor_tile_v; @@ -625,7 +625,7 @@ void Viewer::StampTattoos(const asset::ImportedScene& scene, const Vec3 normal = Normalize(TransformDir( to_world, {nearest->normal[0], nearest->normal[1], nearest->normal[2]})); Vec3 up{0, 1, 0}; - if (::abs(Dot(up, normal)) > 0.9f) up = {0, 0, 1}; + if (::fabsf(Dot(up, normal)) > 0.9f) up = {0, 0, 1}; render::DecalStamp tattoo; tattoo.receiver = receiver; const f32 world_size = f[3] * placement_scale; @@ -678,16 +678,16 @@ void Viewer::ApplySceneLighting(const asset::ImportedScene& scene) { u32 punctual = 0, dropped = 0, distant_count = 0, dome_count = 0; for (const asset::ImportedScene::Light& light : scene.lights) { - const f32 gain = light.intensity * ::exp2(light.exposure); + const f32 gain = light.intensity * ::exp2f(light.exposure); if (light.kind == Kind::kDistant) { // Brightest distant light wins: a rig may carry a fill as well as a key. ++distant_count; - if (!sun || gain > sun->intensity * ::exp2(sun->exposure)) sun = &light; + if (!sun || gain > sun->intensity * ::exp2f(sun->exposure)) sun = &light; continue; } if (light.kind == Kind::kDome) { ++dome_count; - if (!dome || gain > dome->intensity * ::exp2(dome->exposure)) dome = &light; + if (!dome || gain > dome->intensity * ::exp2f(dome->exposure)) dome = &light; continue; } render::PointLight pl; @@ -709,7 +709,7 @@ void Viewer::ApplySceneLighting(const asset::ImportedScene& scene) { } // Influence radius from an inverse-square falloff down to a ~1/255 cutoff, // clamped so a bright practical does not light the entire stage. - pl.pos_radius[3] = rx::Min(30.0f, rx::Max(1.0f, ::sqrt(intensity * 255.0f))); + pl.pos_radius[3] = rx::Min(30.0f, rx::Max(1.0f, ::sqrtf(intensity * 255.0f))); pl.color_intensity[0] = light.color[0]; pl.color_intensity[1] = light.color[1]; pl.color_intensity[2] = light.color[2]; @@ -738,8 +738,8 @@ void Viewer::ApplySceneLighting(const asset::ImportedScene& scene) { pl.direction_type[3] = 1.0f; const f32 outer = light.cone_angle * 3.14159265358979f / 180.0f; const f32 inner = outer * (1.0f - rx::Clamp(light.cone_softness, 0.0f, 1.0f)); - pl.params[0] = ::cos(inner); - pl.params[1] = ::cos(outer); + pl.params[0] = ::cosf(inner); + pl.params[1] = ::cosf(outer); } scene_lights_.push_back(pl); ++punctual; @@ -764,7 +764,7 @@ void Viewer::ApplySceneLighting(const asset::ImportedScene& scene) { s.sun_direction = sun->direction; s.sun_color = {sun->color[0], sun->color[1], sun->color[2]}; s.sun_intensity = - sun->intensity * ::exp2(sun->exposure) * UsdSunScale.get(); + sun->intensity * ::exp2f(sun->exposure) * UsdSunScale.get(); ctx_.scene_owns_sun = true; drive_sun_from_clock_ = false; } @@ -779,7 +779,7 @@ void Viewer::ApplySceneLighting(const asset::ImportedScene& scene) { if (f32* pixels = stbi_loadf(dome->texture.c_str(), &w, &h, &channels, 4)) { const Vec3 tint{dome->color[0], dome->color[1], dome->color[2]}; const f32 gain = - dome->intensity * ::exp2(dome->exposure) * UsdDomeScale.get(); + dome->intensity * ::exp2f(dome->exposure) * UsdDomeScale.get(); dome_ibl = renderer_->SetEnvironmentMap(pixels, static_cast(w), static_cast(h), tint, gain, UsdDomeRotation.get()); @@ -827,7 +827,7 @@ void Viewer::ApplySceneLighting(const asset::ImportedScene& scene) { s.clouds = false; s.aerial_perspective = 0.0f; const f32 dome_gain = - dome ? dome->intensity * ::exp2(dome->exposure) * UsdDomeScale.get() + dome ? dome->intensity * ::exp2f(dome->exposure) * UsdDomeScale.get() : 0.05f; // The dome's tint multiplies its environment map, so the fill colour is // both together - the tint alone is not the colour of the sky. @@ -918,8 +918,8 @@ void Viewer::ApplySceneCamera(const asset::ImportedScene& scene) { camera.rotation[2], camera.rotation[3]); const Vec3 forward = TransformDir(basis, {0.0f, 0.0f, -1.0f}); camera_.set_position(camera.position); - camera_.set_yaw_pitch(::atan2(forward.x, -forward.z), - ::asin(rx::Clamp(forward.y, -1.0f, 1.0f))); + camera_.set_yaw_pitch(::atan2f(forward.x, -forward.z), + ::asinf(rx::Clamp(forward.y, -1.0f, 1.0f))); camera_.speed = 4.0f; // Framing is the lens as much as the pose: a 18mm wide-angle stage camera // shows a different scene through the engine's default 60 degrees. @@ -934,7 +934,7 @@ void Viewer::DriveSunFromClock() { // frame for sub-degree motion. if (!drive_sun_from_clock_ || ctx_.scene_owns_sun) return; const f32 hour = clock_->hour(); - if (last_sky_hour_ >= -100.0f && ::abs(hour - last_sky_hour_) < 0.02f) return; + if (last_sky_hour_ >= -100.0f && ::fabsf(hour - last_sky_hour_) < 0.02f) return; last_sky_hour_ = hour; const SkyLighting sky = ComputeSkyLighting(hour); auto& s = renderer_->settings(); @@ -1036,7 +1036,7 @@ void Viewer::EmitMorphedInstances(f32 frame_delta, render::FrameView& view) { // RX_MORPH_WEIGHTS: weights were fixed at load; skip track/sweep. } else if (!instance.animation.times.empty()) { f32 time = instance.animation.duration > 0 - ? ::fmod(morph_time_, instance.animation.duration) + ? ::fmodf(morph_time_, instance.animation.duration) : 0.0f; anim::SampleMorphWeights(instance.animation, time, &instance.weights); } else if (!instance.expression_map.empty()) { @@ -1051,8 +1051,8 @@ void Viewer::EmitMorphedInstances(f32 frame_delta, render::FrameView& view) { base::Fill(instance.weights.begin(), instance.weights.end(), 0.0f); const f32 period = 1.2f; // seconds per target u32 index = static_cast(morph_time_ / period) % instance.weights.size(); - f32 phase = ::fmod(morph_time_, period) / period; - instance.weights[index] = ::sin(phase * 3.14159265f); + f32 phase = ::fmodf(morph_time_, period) / period; + instance.weights[index] = ::sinf(phase * 3.14159265f); } render::DrawItem draw; draw.mesh = instance.mesh; diff --git a/test/aircraft_test.cc b/test/aircraft_test.cc index 70b3052a..f1d7d7a4 100644 --- a/test/aircraft_test.cc +++ b/test/aircraft_test.cc @@ -41,14 +41,14 @@ void AddRunway(PhysicsWorld& world) { } bool IsFinite(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } bool StateFinite(const AircraftState& s) { - return ::isfinite(s.airspeed_mps) && ::isfinite(s.vertical_speed_mps) && - ::isfinite(s.alpha_deg) && ::isfinite(s.beta_deg) && ::isfinite(s.rpm) && - ::isfinite(s.engine_load) && IsFinite(s.position) && ::isfinite(s.rotation.x) && - ::isfinite(s.rotation.y) && ::isfinite(s.rotation.z) && ::isfinite(s.rotation.w); + return isfinite(s.airspeed_mps) && isfinite(s.vertical_speed_mps) && + isfinite(s.alpha_deg) && isfinite(s.beta_deg) && isfinite(s.rpm) && + isfinite(s.engine_load) && IsFinite(s.position) && isfinite(s.rotation.x) && + isfinite(s.rotation.y) && isfinite(s.rotation.z) && isfinite(s.rotation.w); } // Spawns a plane a little high and lets the suspension settle under zero input. @@ -65,7 +65,7 @@ Aircraft* SpawnSettled(PhysicsWorld& world, const AircraftDesc& desc, Aircraft* // Heading (yaw) of the plane in radians about +Y, from its forward axis. f32 Heading(const Aircraft& a) { Vec3 fwd = Rotate(a.state().rotation, Vec3{0, 0, 1}); - return ::atan2(fwd.x, fwd.z); + return ::atan2f(fwd.x, fwd.z); } // Wrap a heading delta into (-pi, pi] so a signed turn reads correctly even if @@ -105,7 +105,7 @@ int main() { s.gear_compression[0], s.gear_compression[1], s.gear_compression[2]); if (!s.on_ground) return Fail("(a) not resting on the gear"); if (s.position.y < 0.5f) return Fail("(a) sank through the runway"); - if (::fabs(s.vertical_speed_mps) > 0.2f || s.airspeed_mps > 0.3f) + if (::fabsf(s.vertical_speed_mps) > 0.2f || s.airspeed_mps > 0.3f) return Fail("(a) not settled/stationary"); a->~Aircraft(); } @@ -374,9 +374,9 @@ int main() { for (int i = 0; i < 60 * 180; ++i) { AircraftInput in; in.throttle = (i / 30) % 2 ? 1.0f : 0.0f; - in.pitch = ::sin(i * 0.05f); - in.roll = ::sin(i * 0.11f); - in.yaw = ::cos(i * 0.07f); + in.pitch = ::sinf(i * 0.05f); + in.roll = ::sinf(i * 0.11f); + in.yaw = ::cosf(i * 0.07f); in.flaps = (i / 120) % 2 ? 1.0f : 0.0f; in.brakes = (i % 90) < 10 ? 1.0f : 0.0f; a->Update(in, kDt); @@ -465,9 +465,9 @@ int main() { if (fly(12.0f, &cross_dx, &cross_yaw)) return 1; ::fprintf(stderr, "(ii) calm dx=%.1f yaw=%.2f | crosswind dx=%.1f yaw=%.2f deg\n", calm_dx, calm_yaw * 57.2958f, cross_dx, cross_yaw * 57.2958f); - if (::fabs(cross_yaw) < 0.15f) + if (::fabsf(cross_yaw) < 0.15f) return Fail("(ii) crosswind did not weathervane the nose"); - if (::fabs(cross_yaw) <= ::fabs(calm_yaw) + 0.1f) + if (::fabsf(cross_yaw) <= ::fabsf(calm_yaw) + 0.1f) return Fail("(ii) crosswind weathervane not distinct from calm"); } diff --git a/test/bc_encode_test.cc b/test/bc_encode_test.cc index 1efbcbf9..7a67aabf 100644 --- a/test/bc_encode_test.cc +++ b/test/bc_encode_test.cc @@ -207,10 +207,10 @@ base::Vector MakeAlbedo(u32 size) { const f32 v = static_cast(y) / static_cast(size); const f32 grain = static_cast(Rand(state) % 32) - 16.0f; u8* p = image.data() + (static_cast(y) * size + x) * 4; - p[0] = static_cast(::fmin(255.0f, ::fmax(0.0f, 180.0f * u + 40.0f + grain))); - p[1] = static_cast(::fmin(255.0f, ::fmax(0.0f, 140.0f * v + 60.0f + grain))); + p[0] = static_cast(::fminf(255.0f, ::fmaxf(0.0f, 180.0f * u + 40.0f + grain))); + p[1] = static_cast(::fminf(255.0f, ::fmaxf(0.0f, 140.0f * v + 60.0f + grain))); p[2] = static_cast( - ::fmin(255.0f, ::fmax(0.0f, 90.0f * (u + v) * 0.5f + 30.0f + grain))); + ::fminf(255.0f, ::fmaxf(0.0f, 90.0f * (u + v) * 0.5f + 30.0f + grain))); p[3] = 255; } } @@ -229,9 +229,9 @@ base::Vector MakeNormalMap(u32 size) { // angle. Roughly the spatial frequency a 1k tiling material carries. const f32 u = static_cast(x) * 0.09f; const f32 v = static_cast(y) * 0.07f; - f32 n[3] = {-(0.55f * ::cos(u) + 0.2f * ::cos(u * 3.1f + v)), - -(0.55f * ::sin(v) + 0.2f * ::sin(u * 2.3f)), 1.0f}; - const f32 len = ::sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); + f32 n[3] = {-(0.55f * ::cosf(u) + 0.2f * ::cosf(u * 3.1f + v)), + -(0.55f * ::sinf(v) + 0.2f * ::sinf(u * 2.3f)), 1.0f}; + const f32 len = ::sqrtf(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); u8* p = image.data() + (static_cast(y) * size + x) * 4; for (u32 c = 0; c < 3; ++c) { p[c] = static_cast((n[c] / len) * 127.5f + 127.5f); @@ -307,16 +307,16 @@ void TestBc5Normal() { auto decode = [](const u8* p, f32* n) { n[0] = static_cast(p[0]) / 127.5f - 1.0f; n[1] = static_cast(p[1]) / 127.5f - 1.0f; - n[2] = ::sqrt(::fmax(0.0f, 1.0f - n[0] * n[0] - n[1] * n[1])); - const f32 len = ::sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); + n[2] = ::sqrtf(::fmaxf(0.0f, 1.0f - n[0] * n[0] - n[1] * n[1])); + const f32 len = ::sqrtf(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); for (u32 c = 0; c < 3; ++c) n[c] /= len; }; f32 a[3]; f32 b[3]; decode(source.data() + t * 4, a); decode(decoded.data() + t * 4, b); - const f32 dot = ::fmin(1.0f, ::fmax(-1.0f, a[0] * b[0] + a[1] * b[1] + a[2] * b[2])); - const f64 degrees = ::acos(dot) * 57.2957795; + const f32 dot = ::fminf(1.0f, ::fmaxf(-1.0f, a[0] * b[0] + a[1] * b[1] + a[2] * b[2])); + const f64 degrees = ::acosf(dot) * 57.2957795; worst_degrees = ::fmax(worst_degrees, degrees); mean_degrees += degrees; ++samples; diff --git a/test/blend_jiggle_test.cc b/test/blend_jiggle_test.cc index 9afceb27..c6421280 100644 --- a/test/blend_jiggle_test.cc +++ b/test/blend_jiggle_test.cc @@ -24,12 +24,12 @@ bool Check(bool condition, const char *message) { f32 MatrixDifference(const Mat4 &a, const Mat4 &b) { f32 difference = 0; for (u32 i = 0; i < 16; ++i) - difference = rx::Max(difference, ::fabs(a.m[i] - b.m[i])); + difference = rx::Max(difference, ::fabsf(a.m[i] - b.m[i])); return difference; } f32 RotationDifference(const Quat &a, const Quat &b) { - const f32 dot = ::fabs(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); + const f32 dot = ::fabsf(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); return 1.0f - rx::Min(dot, 1.0f); } diff --git a/test/boat_profiles_test.cc b/test/boat_profiles_test.cc index b0343f75..fbd26996 100644 --- a/test/boat_profiles_test.cc +++ b/test/boat_profiles_test.cc @@ -61,7 +61,7 @@ BoatState Run(PhysicsWorld& world, Boat& boat, const BoatInput& in, int steps) { f32 Heading(const BoatState& s) { const Vec3 fwd = Rotate(s.rotation, Vec3{0, 0, 1}); - return ::atan2(fwd.x, fwd.z); + return ::atan2f(fwd.x, fwd.z); } f32 Uprightness(const BoatState& s) { @@ -146,7 +146,7 @@ int main() { const int n = 60 * 5; for (int k = 0; k < n; ++k) { Step(w, *b, in); - sum += ::fabs(b->state().forward_speed); + sum += ::fabsf(b->state().forward_speed); } return static_cast(sum / n); }; @@ -222,7 +222,7 @@ int main() { BoatInput t = go; t.steer = 1.0f; const BoatState s = Run(w, *b, t, 60 * 5); - return ::fabs(Heading(s) - h0) / 5.0f; // rad/s + return ::fabsf(Heading(s) - h0) / 5.0f; // rad/s }; ::fprintf(stderr, "(d) turn rate (rad/s), full helm:\n"); for (int i = 0; i < 5; ++i) { @@ -247,7 +247,7 @@ int main() { base::UniquePointer b; make(w, Profile(profile), cargo, 5.0f, b); const Vec3 p = b->state().position; - const f32 rot[4] = {0.0f, 0.0f, ::sin(heel * 0.5f), ::cos(heel * 0.5f)}; + const f32 rot[4] = {0.0f, 0.0f, ::sinf(heel * 0.5f), ::cosf(heel * 0.5f)}; w.SetBodyPosition(b->body(), p, rot); b->Update({}, kDt); // refresh telemetry from the heeled pose return Uprightness(Run(w, *b, {}, static_cast(secs * 60.0f))); @@ -260,7 +260,7 @@ int main() { base::UniquePointer b; make(w, Profile(profile), cargo, 5.0f, b); const Vec3 p = b->state().position; - const f32 rot[4] = {0.0f, 0.0f, ::sin(heel * 0.5f), ::cos(heel * 0.5f)}; + const f32 rot[4] = {0.0f, 0.0f, ::sinf(heel * 0.5f), ::cosf(heel * 0.5f)}; w.SetBodyPosition(b->body(), p, rot); b->Update({}, kDt); const int limit = static_cast(timeout * 60.0f); @@ -318,8 +318,8 @@ int main() { Boat boat(w, d, Vec3{0, 0.8f, 0}, 0.0f); BoatInput in; for (int k = 0; k < 60 * 60; ++k) { - in.throttle = ::sin(t * 0.7f); - in.steer = ::sin(t * 0.3f); + in.throttle = ::sinf(t * 0.7f); + in.steer = ::sinf(t * 0.3f); // Load transfer partway: ramp cargo up past the rated limit and back. if (k == 60 * 20) boat.SetCargo(d.max_cargo_kg); if (k == 60 * 30) boat.SetCargo(d.max_cargo_kg * 1.25f); @@ -328,10 +328,10 @@ int main() { boat.Update(in, kDt); w.Update(kDt); const BoatState s = boat.state(); - if (!::isfinite(s.position.x) || !::isfinite(s.position.y) || - !::isfinite(s.position.z) || !::isfinite(s.rpm) || - !::isfinite(s.forward_speed) || !::isfinite(s.rotation.w) || - !::isfinite(s.draft_m) || !::isfinite(s.freeboard_m)) { + if (!isfinite(s.position.x) || !isfinite(s.position.y) || + !isfinite(s.position.z) || !isfinite(s.rpm) || + !isfinite(s.forward_speed) || !isfinite(s.rotation.w) || + !isfinite(s.draft_m) || !isfinite(s.freeboard_m)) { return Fail("(g) NaN/Inf in boat state on chop"); } } diff --git a/test/boat_test.cc b/test/boat_test.cc index 270f0c3f..af1fb860 100644 --- a/test/boat_test.cc +++ b/test/boat_test.cc @@ -53,7 +53,7 @@ BoatState Run(PhysicsWorld& world, Boat& boat, const BoatInput& in, int steps) { // Heading angle (radians) of the hull forward axis in the XZ plane. f32 Heading(const BoatState& s) { const Vec3 fwd = Rotate(s.rotation, Vec3{0, 0, 1}); - return ::atan2(fwd.x, fwd.z); + return ::atan2f(fwd.x, fwd.z); } // World up projected onto the hull's up axis: 1 = upright, 0 = on its side. @@ -94,7 +94,7 @@ int main() { const Vec3 p0 = s0.position; Run(world, boat, {}, 60 * 3); const Vec3 p1 = boat.state().position; - const f32 drift = ::sqrt((p1.x - p0.x) * (p1.x - p0.x) + (p1.z - p0.z) * (p1.z - p0.z)); + const f32 drift = ::sqrtf((p1.x - p0.x) * (p1.x - p0.x) + (p1.z - p0.z) * (p1.z - p0.z)); ::fprintf(stderr, "(a) idle drift=%.4f m\n", drift); if (drift > 0.15f) return Fail("(a) idle boat drifted"); } @@ -114,7 +114,7 @@ int main() { s.position.z, s.position.x, Uprightness(s)); if (s.forward_speed < 4.0f) return Fail("(b) boat did not accelerate to several m/s"); if (s.position.z < 10.0f) return Fail("(b) boat did not travel forward (+Z)"); - if (::fabs(s.position.x) > 3.0f) return Fail("(b) boat veered sideways under straight throttle"); + if (::fabsf(s.position.x) > 3.0f) return Fail("(b) boat veered sideways under straight throttle"); } // (c) Sustained steer while moving yaws the boat. @@ -133,7 +133,7 @@ int main() { turn.throttle = 1.0f; turn.steer = 1.0f; const BoatState s = Run(world, boat, turn, 60 * 5); - const f32 dh = ::fabs(Heading(s) - h0); + const f32 dh = ::fabsf(Heading(s) - h0); ::fprintf(stderr, "(c) heading change=%.3f rad\n", dh); if (dh < 0.2f) return Fail("(c) sustained steer did not yaw the boat"); } @@ -209,7 +209,7 @@ int main() { Boat boat(world, desc, Vec3{0, 0.4f, 0}, 0.0f); // Knock it down: roll ~80 deg about the forward (+Z) axis, then let go. const f32 heel = 1.4f; - const f32 rot[4] = {0.0f, 0.0f, ::sin(heel * 0.5f), ::cos(heel * 0.5f)}; + const f32 rot[4] = {0.0f, 0.0f, ::sinf(heel * 0.5f), ::cosf(heel * 0.5f)}; world.SetBodyPosition(boat.body(), Vec3{0, 0.4f, 0}, rot); Step(world, boat, {}); // refresh telemetry from the knocked-down pose const f32 before = Uprightness(boat.state()); @@ -233,7 +233,7 @@ int main() { const f32 footprint = (2.0f * desc.hull_half_extent.x) * (2.0f * desc.hull_half_extent.z); const f32 predicted = desc.mass / (1000.0f * footprint); ::fprintf(stderr, "(h) draft=%.3f predicted=%.3f\n", draft, predicted); - if (::fabs(draft - predicted) > 0.06f) { + if (::fabsf(draft - predicted) > 0.06f) { return Fail("(h) draft does not match single-model displacement (double buoyancy?)"); } } @@ -255,14 +255,14 @@ int main() { BoatInput in; for (int i = 0; i < 60 * 60; ++i) { // Wander the helm so thrust, planing and rudder all exercise on the chop. - in.throttle = ::sin(t * 0.7f); - in.steer = ::sin(t * 0.3f); + in.throttle = ::sinf(t * 0.7f); + in.steer = ::sinf(t * 0.3f); t += kDt; Step(world, boat, in); const BoatState s = boat.state(); - if (!::isfinite(s.position.x) || !::isfinite(s.position.y) || - !::isfinite(s.position.z) || !::isfinite(s.rpm) || - !::isfinite(s.forward_speed) || !::isfinite(s.rotation.w)) { + if (!isfinite(s.position.x) || !isfinite(s.position.y) || + !isfinite(s.position.z) || !isfinite(s.rpm) || + !isfinite(s.forward_speed) || !isfinite(s.rotation.w)) { return Fail("(i) NaN/Inf in boat state on chop"); } } @@ -294,7 +294,7 @@ int main() { ::fprintf(stderr, "(j) calm dx=%.2f up=%.4f | beam wind(25 m/s) dx=%.2f up=%.4f\n", calm_dx, calm_up, wind_dx, wind_up); if (wind_dx < 1.5f) return Fail("(j) beam wind did not push the boat downwind"); - if (wind_dx <= ::fabs(calm_dx) + 1.0f) return Fail("(j) wind drift not distinct from calm"); + if (wind_dx <= ::fabsf(calm_dx) + 1.0f) return Fail("(j) wind drift not distinct from calm"); } // (k) Lifecycle: destroying a Boat removes its hull body and clears the diff --git a/test/body_dynamics_test.cc b/test/body_dynamics_test.cc index 2801212c..cc8bf115 100644 --- a/test/body_dynamics_test.cc +++ b/test/body_dynamics_test.cc @@ -21,7 +21,7 @@ void Check(bool condition, const char *message) { } void Near(f32 actual, f32 expected, f32 tolerance, const char *message) { - if (::fabs(actual - expected) <= tolerance) + if (::fabsf(actual - expected) <= tolerance) return; ::fprintf( stderr, @@ -70,7 +70,7 @@ BodyRegionSample Simulate(f32 step, f32 seconds, BodyDynamics dynamics; dynamics.AddRegion(TestRegion()); dynamics.Update(skeleton, frame, step, &pose); // initialize - const u32 count = static_cast(::ceil(seconds / step)); + const u32 count = static_cast(::ceilf(seconds / step)); for (u32 i = 0; i < count; ++i) { pose.ResetToBind(skeleton); dynamics.Update(skeleton, frame, rx::Min(step, seconds - i * step), &pose); @@ -82,7 +82,7 @@ void TestGravityAndInertia() { BodyDynamicsFrame gravity; const BodyRegionSample sag = Simulate(1.0f / 120.0f, 2.0f, gravity); const f32 expected = - -9.81f / ::pow(2.0f * 3.14159265358979323846f * 2.0f, 2.0f); + -9.81f / ::powf(2.0f * 3.14159265358979323846f * 2.0f, 2.0f); Near(sag.translation.y, expected, 0.0005f, "settled sag follows the spring's physical equilibrium"); @@ -130,9 +130,9 @@ void TestLimitsAndTeleport() { pose.ResetToBind(skeleton); dynamics.Update(skeleton, frame, 1.0f / 60.0f, &pose); BodyRegionSample sample = dynamics.sample(0); - Check(::fabs(sample.translation.x) <= 0.010001f && - ::fabs(sample.translation.y) <= 0.020001f && - ::fabs(sample.translation.z) <= 0.030001f, + Check(::fabsf(sample.translation.x) <= 0.010001f && + ::fabsf(sample.translation.y) <= 0.020001f && + ::fabsf(sample.translation.z) <= 0.030001f, "per-axis anatomical limits hold under extreme impulses"); frame = {}; @@ -148,7 +148,7 @@ void TestLimitsAndTeleport() { frame.linear_impulse = {0, -1, 0}; pose.ResetToBind(skeleton); dynamics.Update(skeleton, frame, 1.0f / 60.0f, &pose); - Check(::fabs(dynamics.sample(0).translation.y) > 0, + Check(::fabsf(dynamics.sample(0).translation.y) > 0, "region resumes simulation on the frame after a teleport"); } @@ -169,7 +169,7 @@ void TestPoseAndMorphOutput() { BodyDynamicsFrame frame; base::Vector weights; dynamics.Update(skeleton, frame, 1.0f / 60.0f, &pose, &weights); - Check(weights.size() == 1 && ::fabs(weights[0].weight - 0.15f) < 1e-6f, + Check(weights.size() == 1 && ::fabsf(weights[0].weight - 0.15f) < 1e-6f, "morph bias is emitted on the rest/initialization frame"); frame.linear_impulse = {0, -1, 0}; pose.ResetToBind(skeleton); @@ -241,7 +241,7 @@ void TestModelUnitScale() { const BodyRegionSample result = dynamics.sample(0); Check(result.active, "changing the source-unit scale keeps the region active"); - Check(::fabs(result.translation.y) > 0, + Check(::fabsf(result.translation.y) > 0, "source-unit scaled simulation responds to a physical impulse"); Near((pose.translation[2].y - skeleton.bones[2].bind_translation.y) / 100.0f, result.translation.y, 1e-6f, diff --git a/test/camera_rig_test.cc b/test/camera_rig_test.cc index 5b9cc430..e0da2677 100644 --- a/test/camera_rig_test.cc +++ b/test/camera_rig_test.cc @@ -25,7 +25,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-4f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "camera_rig_test: FAIL: %s (got %.6f, expected %.6f)\n", message, actual, expected); ++failures; diff --git a/test/camera_test.cc b/test/camera_test.cc index e2a82ef5..9d6d25fe 100644 --- a/test/camera_test.cc +++ b/test/camera_test.cc @@ -30,7 +30,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-4f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "camera_test: FAIL: %s (got %.6f, expected %.6f)\n", message, actual, expected); ++failures; @@ -223,8 +223,8 @@ void TestLensAndOrientationInterpolation() { CameraView half = InterpolateCameraView(source, destination, 0.5f); const f32 expected_fov = - 2.0f * ::atan(rx::Lerp(::tan(source.lens.fov_y * 0.5f), - ::tan(destination.lens.fov_y * 0.5f), 0.5f)); + 2.0f * ::atanf(rx::Lerp(::tanf(source.lens.fov_y * 0.5f), + ::tanf(destination.lens.fov_y * 0.5f), 0.5f)); Near(half.lens.fov_y, expected_fov, "field of view blends in focal scale"); Near(rx::Length(CameraForward(half)), 1.0f, "slerped orientation remains normalized"); diff --git a/test/character_test.cc b/test/character_test.cc index bd10bc2b..7e03d567 100644 --- a/test/character_test.cc +++ b/test/character_test.cc @@ -28,7 +28,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-2f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "character_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; @@ -84,7 +84,7 @@ struct Scene { }; f32 HorizontalSpeed(const CharacterState& s) { - return ::sqrt(s.velocity.x * s.velocity.x + s.velocity.z * s.velocity.z); + return ::sqrtf(s.velocity.x * s.velocity.x + s.velocity.z * s.velocity.z); } void TestGaitSpeeds() { @@ -331,7 +331,7 @@ void TestTurnSmoothingConverges() { // Movement direction with heading yaw ~1.0 rad. const f32 theta = 1.0f; - s.intent().move = {::sin(theta), 0, -::cos(theta)}; + s.intent().move = {::sinf(theta), 0, -::cosf(theta)}; s.intent().gait = CharacterGait::kRun; f32 prev = s.state().facing_yaw; @@ -364,7 +364,7 @@ void TestQuickPivotIsFaster() { move->pivot_angle = pivot_angle; s.Settle(); const f32 theta = 2.6f; // ~149 deg from the +? forward: a near reversal - s.intent().move = {::sin(theta), 0, -::cos(theta)}; + s.intent().move = {::sinf(theta), 0, -::cosf(theta)}; s.intent().gait = CharacterGait::kRun; for (int i = 0; i < steps; ++i) { StepCharacters(s.world, s.physics, kDt); diff --git a/test/cloth_collision_test.cc b/test/cloth_collision_test.cc index ecdd514d..20ff3433 100644 --- a/test/cloth_collision_test.cc +++ b/test/cloth_collision_test.cc @@ -23,8 +23,8 @@ physics::detail::ClothTopology ManualTopology(u32 vertex_count) { bool Finite(const base::Vector& values) { for (const Vec3& value : values) { - if (!::isfinite(value.x) || !::isfinite(value.y) || - !::isfinite(value.z)) { + if (!isfinite(value.x) || !isfinite(value.y) || + !isfinite(value.z)) { return false; } } diff --git a/test/cloth_sim_test.cc b/test/cloth_sim_test.cc index 620db206..c74da8b9 100644 --- a/test/cloth_sim_test.cc +++ b/test/cloth_sim_test.cc @@ -23,7 +23,7 @@ int Fail(const char* what) { } bool IsFinite(const Vec3& p) { - return ::isfinite(p.x) && ::isfinite(p.y) && ::isfinite(p.z); + return isfinite(p.x) && isfinite(p.y) && isfinite(p.z); } struct Mesh { @@ -74,7 +74,7 @@ Mesh MakeSkirt(u32 segments, u32 rings) { const f32 angle = 6.28318530718f * static_cast(segment) / static_cast(segments); mesh.positions.push_back( - {radius * ::cos(angle), -0.7f * t, radius * ::sin(angle)}); + {radius * ::cosf(angle), -0.7f * t, radius * ::sinf(angle)}); } } for (u32 ring = 0; ring + 1 < rings; ++ring) { @@ -234,7 +234,7 @@ int TestSkirt(physics::PhysicsWorld& world) { for (u32 ring = 1; ring < kRings; ++ring) { for (u32 segment = 0; segment < kSegments; ++segment) { const Vec3 p = positions[ring * kSegments + segment] - Vec3{1.4f, 0, 0}; - if (::sqrt(p.x * p.x + p.z * p.z) < 0.27f) { + if (::sqrtf(p.x * p.x + p.z * p.z) < 0.27f) { return Fail("skirt penetrated character capsule"); } } @@ -403,7 +403,7 @@ int TestSelfCollision(physics::PhysicsWorld& world) { lower += positions[i].z; upper += positions[i + 3].z; } - if (::abs(upper - lower) / 3.0f < 0.025f) { + if (::fabsf(upper - lower) / 3.0f < 0.025f) { return Fail("self-collision did not separate overlapping panels"); } world.RemoveCloth(cloth); diff --git a/test/cloud_lighting_test.cc b/test/cloud_lighting_test.cc index b992da17..d2e47659 100644 --- a/test/cloud_lighting_test.cc +++ b/test/cloud_lighting_test.cc @@ -15,7 +15,7 @@ namespace { f32 Half(u16 bits) { if ((bits & 0x7c00u) == 0x7c00u) return INFINITY; const int exponent = (bits >> 10) & 31; - return ::ldexp(float((bits & 1023) + (exponent ? 1024 : 0)), + return ::ldexpf(float((bits & 1023) + (exponent ? 1024 : 0)), exponent ? exponent - 25 : -24) * ((bits & 0x8000) ? -1.f : 1.f); } } // namespace @@ -113,7 +113,7 @@ int main() { const u32 i = p * 4 + c; const f32 opacity_a = 1 - (light_a[i] - dark_a[i]); const f32 opacity_b = 1 - (light_b[i] - dark_b[i]); - if (!::isfinite(opacity_a) || !::isfinite(opacity_b)) { + if (!isfinite(opacity_a) || !isfinite(opacity_b)) { error = INFINITY; continue; } @@ -121,20 +121,20 @@ int main() { const f32 source_a = dark_a[i] / opacity_a; const f32 source_b = dark_b[i] / opacity_b; min_source = rx::Min(min_source, double(rx::Min(source_a, source_b))); - error = rx::Max(error, double(::abs(source_a - source_b) / + error = rx::Max(error, double(::fabsf(source_a - source_b) / rx::Max(source_b, 1e-6f))); ++compared; } } check(compared > count && error < .025, "Cloud source independent of density", error); - check(::isfinite(min_source) && min_source > .1, "Cloud ambient illumination preserved", min_source); + check(isfinite(min_source) && min_source > .1, "Cloud ambient illumination preserved", min_source); ::printf("extent=%ux%u, compared=%u channels\n", extent.width, extent.height, compared); auto expect = [&](const base::Vector& pixels, f32 value, const char* name) { double difference = 0; for (u32 p = 0; p < count; ++p) for (u32 c = 0; c < 3; ++c) { f32 sample = pixels[p * 4 + c]; - difference = ::isfinite(sample) ? rx::Max(difference, double(::abs(sample - value))) : INFINITY; + difference = isfinite(sample) ? rx::Max(difference, double(::fabsf(sample - value))) : INFINITY; } check(difference < .001, name, difference); }; diff --git a/test/combat_test.cc b/test/combat_test.cc index a91d1f54..ced75497 100644 --- a/test/combat_test.cc +++ b/test/combat_test.cc @@ -26,7 +26,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-3f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "combat_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; diff --git a/test/decal_bake_test.cc b/test/decal_bake_test.cc index 7cc1e220..3e291c57 100644 --- a/test/decal_bake_test.cc +++ b/test/decal_bake_test.cc @@ -42,7 +42,7 @@ Vec3 ToDecalSpace(const Decal& d, const Vec3& world) { d.row2[0] * world.x + d.row2[1] * world.y + d.row2[2] * world.z + d.row2[3]}; } -bool Near(f32 a, f32 b) { return ::fabs(a - b) < 1e-4f; } +bool Near(f32 a, f32 b) { return ::fabsf(a - b) < 1e-4f; } // A unit quad in the XZ plane, uv0 covering the full 0..1 chart. World x maps to // u and world z to v, so a projector at the origin lands in the middle of the @@ -109,12 +109,12 @@ int main() { "the projector centre is the origin of decal space"); // Half the FULL width along a plane axis is the box edge. const Vec3 edge = ToDecalSpace(d, {2, 3, 5}); - Check(Near(::fabs(edge.x) + ::fabs(edge.y), 1.0f) && Near(edge.z, 0), + Check(Near(::fabsf(edge.x) + ::fabsf(edge.y), 1.0f) && Near(edge.z, 0), "a point at half the width sits on the box edge"); const Vec3 above = ToDecalSpace(d, {2, 3.5f, 4}); Check(Near(above.z, 1.0f), "the box depth runs along the surface normal"); const Vec3 outside = ToDecalSpace(d, {5, 3, 4}); - Check(::fabs(outside.x) > 1.0f, "a point past the box falls outside"); + Check(::fabsf(outside.x) > 1.0f, "a point past the box falls outside"); } DeviceDesc desc; diff --git a/test/edit_test.cc b/test/edit_test.cc index a9557de2..01ef963e 100644 --- a/test/edit_test.cc +++ b/test/edit_test.cc @@ -38,7 +38,7 @@ int failures = 0; } \ } while (0) -#define CHECK_NEAR(a, b, eps) CHECK(::abs((a) - (b)) <= (eps)) +#define CHECK_NEAR(a, b, eps) CHECK(::fabsf((a) - (b)) <= (eps)) // A component exercising every PropType. struct TestAll { @@ -182,7 +182,7 @@ bool DeepEqual(ecs::World& wa, ecs::Entity a, ecs::World& wb, ecs::Entity b) { if (va.b != vb.b) return false; } else { for (int k = 0; k < 4; ++k) - if (::abs(va.f[k] - vb.f[k]) > 1e-5f) return false; + if (::fabsf(va.f[k] - vb.f[k]) > 1e-5f) return false; } } } @@ -373,13 +373,13 @@ void TestNumberLiterals() { CHECK(error.find("not finite") != base::String::npos); lenient(&t); CHECK_NEAR(t.position[1], 0.f, 1e-6f); - CHECK(::isfinite(t.position[1])); + CHECK(isfinite(t.position[1])); write(base::String("Transform.scale = ") + literal + "\n"); error = strict_error(); CHECK(error.find("not finite") != base::String::npos); lenient(&t); - CHECK(::isfinite(t.scale)); + CHECK(isfinite(t.scale)); } // A trailing suffix is not a number either, in the scalar path where strtof diff --git a/test/expression_test.cc b/test/expression_test.cc index 62b71e9e..c5a0825a 100644 --- a/test/expression_test.cc +++ b/test/expression_test.cc @@ -54,20 +54,20 @@ int TestTransition() { controller.Update(dt); const f32 weight = controller.Weight(smile); const f32 v = (weight - previous) / dt; - if (i > 0) max_jump = rx::Max(max_jump, ::abs(v - velocity)); + if (i > 0) max_jump = rx::Max(max_jump, ::fabsf(v - velocity)); previous = weight; velocity = v; } ::printf("expression_test: max velocity jump %g /s per step\n", max_jump); if (max_jump > 1.5f) return Fail("velocity discontinuity across a retarget"); - if (::abs(controller.Weight(smile) - 0.75f) > 1e-3f) { + if (::fabsf(controller.Weight(smile) - 0.75f) > 1e-3f) { return Fail("smile did not converge to its pose weight"); } - if (::abs(velocity) > 1e-2f) return Fail("velocity did not settle"); + if (::fabsf(velocity) > 1e-2f) return Fail("velocity did not settle"); controller.SetExpression("neutral"); for (int i = 0; i < 2 * 240; ++i) controller.Update(dt); - if (::abs(controller.Weight(smile)) > 1e-3f) return Fail("neutral did not release"); + if (::fabsf(controller.Weight(smile)) > 1e-3f) return Fail("neutral did not release"); return 0; } diff --git a/test/fluid_sim_test.cc b/test/fluid_sim_test.cc index 46222661..8ed927b7 100644 --- a/test/fluid_sim_test.cc +++ b/test/fluid_sim_test.cc @@ -146,7 +146,7 @@ int main() { f32 v = 0; for (u32 i = 0; i < kRes * kRes; ++i) v += s0[i * 4 + 0]; ::printf("fluid_sim_test: uploaded water volume %.3f (cpu %.3f)\n", v, initial_volume); - if (::fabs(v - initial_volume) > 0.01f * initial_volume) + if (::fabsf(v - initial_volume) > 0.01f * initial_volume) return Fail("uploaded water volume does not match the CPU fill"); } @@ -162,12 +162,12 @@ int main() { const f32 dl = s1[i * 4 + 1]; const f32 T = s1[i * 4 + 2]; const f32 C = s1[i * 4 + 3]; - if (!::isfinite(dw) || !::isfinite(dl) || !::isfinite(T) || !::isfinite(C)) + if (!isfinite(dw) || !isfinite(dl) || !isfinite(T) || !isfinite(C)) return Fail("non-finite value in state"); if (dw < -1e-4f || dl < -1e-4f || C < -1e-4f) return Fail("negative depth/crust in state"); vol1 += dw; } - const f32 drift = ::fabs(vol1 - initial_volume) / rx::Max(initial_volume, 1e-6f); + const f32 drift = ::fabsf(vol1 - initial_volume) / rx::Max(initial_volume, 1e-6f); ::printf("fluid_sim_test: initial volume %.3f, after settle %.3f (drift %.3f%%)\n", initial_volume, vol1, drift * 100.0f); if (drift > 0.01f) return Fail("water volume not conserved within 1%"); @@ -194,13 +194,13 @@ int main() { wet = 0; for (u32 i = 0; i < kRes * kRes; ++i) { const f32 dw = s2[i * 4 + 0]; - if (!::isfinite(dw)) return Fail("non-finite depth after flood"); + if (!isfinite(dw)) return Fail("non-finite depth after flood"); if (dw < -1e-4f) return Fail("negative depth after flood"); vol2 += dw; if (dw > 0.5f) { // core pond; shoreline partial cells sit below the plane const f32 surface = bed_open[i] + dw; - mn = ::fmin(mn, surface); - mx = ::fmax(mx, surface); + mn = ::fminf(mn, surface); + mx = ::fmaxf(mx, surface); ++wet; } } diff --git a/test/gltf_skin_test.cc b/test/gltf_skin_test.cc index d8b2a8ac..44e281d2 100644 --- a/test/gltf_skin_test.cc +++ b/test/gltf_skin_test.cc @@ -54,11 +54,11 @@ void Check(bool condition, const char *message) { bool IdentityTransform(const asset::ImportedScene::Instance &instance) { return Length(instance.position) < 1e-7f && - ::fabs(instance.rotation[0]) < 1e-7f && - ::fabs(instance.rotation[1]) < 1e-7f && - ::fabs(instance.rotation[2]) < 1e-7f && - ::fabs(instance.rotation[3] - 1.0f) < 1e-7f && - ::fabs(instance.scale - 1.0f) < 1e-7f; + ::fabsf(instance.rotation[0]) < 1e-7f && + ::fabsf(instance.rotation[1]) < 1e-7f && + ::fabsf(instance.rotation[2]) < 1e-7f && + ::fabsf(instance.rotation[3] - 1.0f) < 1e-7f && + ::fabsf(instance.scale - 1.0f) < 1e-7f; } } // namespace diff --git a/test/gltf_texture_transform_test.cc b/test/gltf_texture_transform_test.cc index b9cf557c..6c0d42e1 100644 --- a/test/gltf_texture_transform_test.cc +++ b/test/gltf_texture_transform_test.cc @@ -76,7 +76,7 @@ bool UvIs(const asset::Mesh &mesh, u32 vertex, f32 u, f32 v) { if (mesh.lods.empty() || mesh.lods[0].vertices.size() <= vertex) return false; const asset::Vertex &out = mesh.lods[0].vertices[vertex]; - return ::fabs(out.uv[0] - u) < 1e-5f && ::fabs(out.uv[1] - v) < 1e-5f; + return ::fabsf(out.uv[0] - u) < 1e-5f && ::fabsf(out.uv[1] - v) < 1e-5f; } } // namespace diff --git a/test/hair_bsdf_test.cc b/test/hair_bsdf_test.cc index 03994cdc..5557b661 100644 --- a/test/hair_bsdf_test.cc +++ b/test/hair_bsdf_test.cc @@ -35,9 +35,9 @@ constexpr float kPi = 3.14159265358979323846f; // A direction in the strand frame: theta is the longitudinal angle off the // normal plane, phi the azimuth around the fibre. void Dir(float theta, float phi, rx::f32 out[3]) { - out[0] = ::sin(theta); - out[1] = ::cos(theta) * ::cos(phi); - out[2] = ::cos(theta) * ::sin(phi); + out[0] = ::sinf(theta); + out[1] = ::cosf(theta) * ::cosf(phi); + out[2] = ::cosf(theta) * ::sinf(phi); } float Luma(const rx::f32 rgb[3]) { @@ -107,7 +107,7 @@ int main() { best_phi = phi; } } - worst = rx::Max(worst, ::abs(best_phi - (-2.0f * ::asin(h)))); + worst = rx::Max(worst, ::fabsf(best_phi - (-2.0f * ::asinf(h)))); } Check(worst < 0.01f, "the surface lobe peaks where the cylinder geometry says it should"); if (worst >= 0.01f) ::fprintf(stderr, " worst azimuthal peak error: %.4f rad\n", worst); @@ -120,7 +120,7 @@ int main() { rx::f32 centre[3], edge[3]; HairEvaluateCpu(brown, wo, wi, 0.0f, centre); HairEvaluateCpu(brown, wo, wi, 0.85f, edge); - Check(::abs(Luma(centre) - Luma(edge)) > 0.01f * rx::Max(Luma(centre), Luma(edge)), + Check(::fabsf(Luma(centre) - Luma(edge)) > 0.01f * rx::Max(Luma(centre), Luma(edge)), "the response varies across the fibre's width"); } @@ -151,7 +151,7 @@ int main() { for (int c = 0; c < 3; ++c) { const float m = rx::Max(a[c], b[c]); if (m < 0.05f * peak) continue; - worst = rx::Max(worst, ::abs(a[c] - b[c]) / m); + worst = rx::Max(worst, ::fabsf(a[c] - b[c]) / m); } } Check(worst < 0.75f, @@ -263,7 +263,7 @@ int main() { rx::f32 wi[3], rgb[3]; Dir(theta, phi, wi); HairShadeCpu(q, w_out, wi, 0.0f, depth, rgb); - total += static_cast(rgb[1]) * ::cos(theta); + total += static_cast(rgb[1]) * ::cosf(theta); } } } @@ -274,7 +274,7 @@ int main() { float worst = 0.0f; for (const float depth : {3.0f, 6.0f, 10.0f}) { for (const float target : {0.85f, 0.65f, 0.45f, 0.28f, 0.15f, 0.07f}) { - worst = rx::Max(worst, ::abs(shaded_albedo(target, depth) - target)); + worst = rx::Max(worst, ::fabsf(shaded_albedo(target, depth) - target)); } } Check(worst < 0.02f, @@ -366,7 +366,7 @@ int main() { }; const float flat_peak = peak_theta(flat, 1); const float tilted_peak = peak_theta(tilted, 1); - Check(::abs(tilted_peak - flat_peak) > 0.01f, + Check(::fabsf(tilted_peak - flat_peak) > 0.01f, "the cuticle tilt shifts the highlight off the specular direction"); } @@ -408,7 +408,7 @@ int main() { rx::f32 shallow[3], deep[3]; HairShadeCpu(distant, wo, wi, 0.0f, 1.0f, shallow); HairShadeCpu(distant, wo, wi, 0.0f, 40.0f, deep); - Check(::abs(shallow[0] - deep[0]) < 1e-6f && ::abs(shallow[2] - deep[2]) < 1e-6f, + Check(::fabsf(shallow[0] - deep[0]) < 1e-6f && ::fabsf(shallow[2] - deep[2]) < 1e-6f, "with multiple scattering off, fibre depth changes nothing"); rx::f32 lit_hero[3]; diff --git a/test/hair_sim_test.cc b/test/hair_sim_test.cc index e0e1ed38..80ee83c6 100644 --- a/test/hair_sim_test.cc +++ b/test/hair_sim_test.cc @@ -68,7 +68,7 @@ int CheckGroom(physics::PhysicsWorld& world, Groom& g, const Mat4& transform, return Fail("GetStrandGroomPositions"); } for (u32 i = 0; i < count; ++i) { - if (!::isfinite(g.positions[i])) { + if (!isfinite(g.positions[i])) { ::fprintf(stderr, " groom %s\n", name); return Fail("non-finite node position"); } @@ -173,8 +173,8 @@ int main() { Mat4 moving = rest_transform; for (int i = 1; i <= 240; ++i) { f32 a = static_cast(i) * dt * 3.0f; - moving = MakeTranslation({0.05f * ::sin(a), 1.6f + 0.03f * ::sin(a * 1.7f), 0}) * - MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.8f * ::sin(a))); + moving = MakeTranslation({0.05f * ::sinf(a), 1.6f + 0.03f * ::sinf(a * 1.7f), 0}) * + MakeFromQuat(QuatFromAxisAngle({0, 1, 0}, 0.8f * ::sinf(a))); world.SetStrandGroomTransform(braid.sim, moving, dt); world.SetStrandGroomTransform(ponytail.sim, moving, dt); world.Update(dt); diff --git a/test/handling_test.cc b/test/handling_test.cc index ead9fbbb..33e292a1 100644 --- a/test/handling_test.cc +++ b/test/handling_test.cc @@ -65,12 +65,12 @@ VehicleId SpawnSettled(PhysicsWorld& world, const Desc& d) { f32 Heading(const f32 q[4]) { const Vec3 f = Rotate(Quat{q[0], q[1], q[2], q[3]}, Vec3{0, 0, 1}); - return ::atan2(f.x, f.z); + return ::atan2f(f.x, f.z); } f32 RollAngle(const f32 q[4]) { const Vec3 right = Rotate(Quat{q[0], q[1], q[2], q[3]}, Vec3{1, 0, 0}); - return ::asin(rx::Clamp(right.y, -1.0f, 1.0f)); + return ::asinf(rx::Clamp(right.y, -1.0f, 1.0f)); } f32 WrapPi(f32 a) { @@ -115,10 +115,10 @@ f32 BrakeDistance(const Desc& d, f32 entry) { world.DriveVehicle(id, 0.0f, 0.0f, 1.0f, 0.0f); world.Update(kDt); world.GetVehicleTransform(id, &last, rot); - if (::fabs(world.VehicleForwardSpeed(id)) < 0.5f) break; + if (::fabsf(world.VehicleForwardSpeed(id)) < 0.5f) break; } const f32 dx = last.x - start.x, dz = last.z - start.z; - return ::sqrt(dx * dx + dz * dz); + return ::sqrtf(dx * dx + dz * dz); } struct SteerResult { @@ -152,11 +152,11 @@ SteerResult StepSteer(const Desc& d, f32 entry) { world.DriveVehicle(id, 0.35f, 0.30f, 0.0f, 0.0f); world.Update(kDt); world.GetVehicleTransform(id, &pos, rot); - r.peak_roll_deg = rx::Max(r.peak_roll_deg, ::fabs(RollAngle(rot)) * 57.2958f); - min_speed = rx::Min(min_speed, ::fabs(world.VehicleForwardSpeed(id))); + r.peak_roll_deg = rx::Max(r.peak_roll_deg, ::fabsf(RollAngle(rot)) * 57.2958f); + min_speed = rx::Min(min_speed, ::fabsf(world.VehicleForwardSpeed(id))); } world.GetVehicleTransform(id, &pos, rot); - r.heading_change_deg = ::fabs(WrapPi(Heading(rot) - start_heading)) * 57.2958f; + r.heading_change_deg = ::fabsf(WrapPi(Heading(rot) - start_heading)) * 57.2958f; r.speed_lost_mps = entry_speed - min_speed; return r; } @@ -189,8 +189,8 @@ SlipResult CornerSlip(const Desc& d) { if (i < 40) continue; // let the corner develop PhysicsWorld::VehicleState st; if (!world.GetVehicleState(id, &st)) continue; - const f32 f = 0.5f * (::fabs(st.wheels[0].lateral_slip) + ::fabs(st.wheels[1].lateral_slip)); - const f32 rr = 0.5f * (::fabs(st.wheels[2].lateral_slip) + ::fabs(st.wheels[3].lateral_slip)); + const f32 f = 0.5f * (::fabsf(st.wheels[0].lateral_slip) + ::fabsf(st.wheels[1].lateral_slip)); + const f32 rr = 0.5f * (::fabsf(st.wheels[2].lateral_slip) + ::fabsf(st.wheels[3].lateral_slip)); r.front = rx::Max(r.front, f); r.rear = rx::Max(r.rear, rr); } @@ -222,15 +222,15 @@ f32 LateralAccel(const Desc& d, f32 target) { world.Update(kDt); world.GetVehicleTransform(id, &pos, rot); const f32 h = Heading(rot); - const f32 yaw_rate = ::fabs(WrapPi(h - prev_heading)) / kDt; + const f32 yaw_rate = ::fabsf(WrapPi(h - prev_heading)) / kDt; prev_heading = h; if (i < 8) continue; // skip the initial transient - peak = rx::Max(peak, ::fabs(world.VehicleForwardSpeed(id)) * yaw_rate); + peak = rx::Max(peak, ::fabsf(world.VehicleForwardSpeed(id)) * yaw_rate); } return peak; } -bool Finite(const Vec3& v) { return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); } +bool Finite(const Vec3& v) { return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } } // namespace @@ -379,7 +379,7 @@ int main() { Vec3 pos{}; f32 rot[4]; world.GetVehicleTransform(id, &pos, rot); - const f32 rest_speed = ::fabs(world.VehicleForwardSpeed(id)); + const f32 rest_speed = ::fabsf(world.VehicleForwardSpeed(id)); Check(Finite(pos), "(g) profile position went non-finite"); Check(rest_speed < 0.5f, "(g) profile did not settle at rest"); // Drive full throttle 2 s; must move and stay finite. @@ -388,7 +388,7 @@ int main() { world.Update(kDt); } world.GetVehicleTransform(id, &pos, rot); - Check(Finite(pos) && ::isfinite(world.VehicleForwardSpeed(id)), + Check(Finite(pos) && isfinite(world.VehicleForwardSpeed(id)), "(g) profile went non-finite under throttle"); Check(world.VehicleForwardSpeed(id) > 1.0f, "(g) profile did not accelerate"); ::fprintf(stderr, "(g) %s: rest_speed=%.3f moved_to=%.1f m/s (finite)\n", it.name, @@ -416,9 +416,9 @@ int main() { world.DriveVehicle(id, 0.0f, 0.0f, 1.0f, 0.0f); world.Update(kDt); world.GetVehicleTransform(id, &b, r); - if (::fabs(world.VehicleForwardSpeed(id)) < 0.5f) break; + if (::fabsf(world.VehicleForwardSpeed(id)) < 0.5f) break; } - ice = ::sqrt((b.x - a.x) * (b.x - a.x) + (b.z - a.z) * (b.z - a.z)); + ice = ::sqrtf((b.x - a.x) * (b.x - a.x) + (b.z - a.z) * (b.z - a.z)); } { PhysicsWorld world; @@ -439,9 +439,9 @@ int main() { world.DriveVehicle(id, 0.0f, 0.0f, 1.0f, 0.0f); world.Update(kDt); world.GetVehicleTransform(id, &b, r); - if (::fabs(world.VehicleForwardSpeed(id)) < 0.5f) break; + if (::fabsf(world.VehicleForwardSpeed(id)) < 0.5f) break; } - wet = ::sqrt((b.x - a.x) * (b.x - a.x) + (b.z - a.z) * (b.z - a.z)); + wet = ::sqrtf((b.x - a.x) * (b.x - a.x) + (b.z - a.z) * (b.z - a.z)); } ::fprintf(stderr, "(g) sports 80-0: dry=%.1fm ice=%.1fm wet=%.1fm\n", dry, ice, wet); Check(ice > dry * 2.0f, "(g) ice not much longer than asphalt"); diff --git a/test/human_brdf_test.cc b/test/human_brdf_test.cc index 267c5fb9..37ae0c73 100644 --- a/test/human_brdf_test.cc +++ b/test/human_brdf_test.cc @@ -37,12 +37,12 @@ struct V3 { }; V3 Norm(V3 v) { - rx::f32 l = ::sqrt(v.x * v.x + v.y * v.y + v.z * v.z); + rx::f32 l = ::sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); return {v.x / l, v.y / l, v.z / l}; } V3 Spherical(rx::f32 theta, rx::f32 phi) { - return {::sin(theta) * ::cos(phi), ::cos(theta), ::sin(theta) * ::sin(phi)}; + return {::sinf(theta) * ::cosf(phi), ::cosf(theta), ::sinf(theta) * ::sinf(phi)}; } rx::f32 Sum(const rx::f32 v[3]) { return v[0] + v[1] + v[2]; } @@ -80,8 +80,8 @@ int main() { HumanEvaluateCpu(neutral, base, roughness, f0, n, n, n, v, l, 0.4f, 0.0f); const HumanBrdfSample s = StockBrdfCpu(base, roughness, f0, n, v, l); for (int c = 0; c < 3; ++c) { - worst = rx::Max(worst, ::abs(h.diffuse[c] - s.diffuse[c])); - worst = rx::Max(worst, ::abs(h.specular[c] - s.specular[c])); + worst = rx::Max(worst, ::fabsf(h.diffuse[c] - s.diffuse[c])); + worst = rx::Max(worst, ::fabsf(h.specular[c] - s.specular[c])); } Check(Sum(h.transmission) == 0.0f, "neutral transmission is exactly zero"); } @@ -105,7 +105,7 @@ int main() { HumanEvaluateCpu(p, base, 0.4f, f0, n, n, n, v_side, l_graze, 0.0f, 0.0f); Check(Sum(lifted.diffuse) > Sum(zero.diffuse), "diffuse Fresnel lifts the grazing diffuse"); - Check(::abs(Sum(lifted.specular) - Sum(zero.specular)) < 1e-7f, + Check(::fabsf(Sum(lifted.specular) - Sum(zero.specular)) < 1e-7f, "diffuse Fresnel does not touch the specular lobe"); p = HumanNeutral(); @@ -113,7 +113,7 @@ int main() { const HumanBrdfSample retro = HumanEvaluateCpu(p, base, 0.4f, f0, n, n, n, v_side, l_graze, 0.0f, 0.0f); Check(Sum(retro.diffuse) > Sum(zero.diffuse), "retroreflection lifts the back-scatter"); - Check(::abs(Sum(retro.specular) - Sum(zero.specular)) < 1e-7f, + Check(::fabsf(Sum(retro.specular) - Sum(zero.specular)) < 1e-7f, "retroreflection does not touch the specular lobe"); p = HumanNeutral(); @@ -122,7 +122,7 @@ int main() { HumanEvaluateCpu(p, base, 0.4f, f0, n, n, n, v_side, l_graze, 0.0f, 0.0f); Check(Sum(fres.specular) > Sum(zero.specular), "a lower specular Fresnel exponent raises grazing reflectance"); - Check(::abs(Sum(fres.diffuse) - Sum(zero.diffuse)) < 1e-7f, + Check(::fabsf(Sum(fres.diffuse) - Sum(zero.diffuse)) < 1e-7f, "the specular Fresnel exponent does not touch the diffuse lobe"); } @@ -147,7 +147,7 @@ int main() { const rx::f32 l[3] = {ll.x, ll.y, ll.z}; const HumanBrdfSample s = HumanEvaluateCpu(p, base, 0.5f, f0, n, n, n, v_side, l, 0.0f, 0.0f); - total += static_cast(s.diffuse[0]) * ::sin(theta); + total += static_cast(s.diffuse[0]) * ::sinf(theta); } return total * (kPi / steps) * 2.0 * kPi; }; @@ -180,7 +180,7 @@ int main() { HumanEvaluateCpu(single, base, 0.3f, f0, n, n, n, v_side, l_45, 0.0f, 0.0f); const HumanBrdfSample b = HumanEvaluateCpu(dual, base, 0.3f, f0, n, n, n, v_side, l_45, 0.0f, 0.0f); - Check(::abs(Sum(a.diffuse) - Sum(b.diffuse)) < 1e-7f, + Check(::fabsf(Sum(a.diffuse) - Sum(b.diffuse)) < 1e-7f, "the second specular lobe does not touch the diffuse lobe"); // Integrated over the hemisphere the two lobes must carry the same energy; @@ -197,7 +197,7 @@ int main() { const rx::f32 l[3] = {ll.x, ll.y, ll.z}; const HumanBrdfSample s = HumanEvaluateCpu(p, base, 0.3f, f0, n, n, n, v_side, l, 0.0f, 0.0f); - total += static_cast(s.specular[0]) * ::sin(theta); + total += static_cast(s.specular[0]) * ::sinf(theta); } } return total; @@ -229,9 +229,9 @@ int main() { HumanEvaluateCpu(p, base, 0.25f, f0, n, n, n, v_side, l_45, 0.0f, 0.0f); const HumanBrdfSample split = HumanEvaluateCpu(p, base, 0.25f, f0, n, n, ns, v_side, l_45, 0.0f, 0.0f); - Check(::abs(Sum(shared_n.diffuse) - Sum(split.diffuse)) < 1e-7f, + Check(::fabsf(Sum(shared_n.diffuse) - Sum(split.diffuse)) < 1e-7f, "a specular-only normal leaves the diffuse lobe alone"); - Check(::abs(Sum(shared_n.specular) - Sum(split.specular)) > 1e-6f, + Check(::fabsf(Sum(shared_n.specular) - Sum(split.specular)) > 1e-6f, "a specular-only normal moves the highlight"); } @@ -380,7 +380,7 @@ int main() { // Neutral has nothing to soften, so the multiplier must be exactly 1 - // otherwise turning the model on re-shades every area-lit surface. const HumanSurfaceParameters neutral = HumanNeutral(); - Check(::abs(HumanTerminatorMultiplierCpu(neutral, n, n, rep_grazing) - 1.0f) < 1e-6f, + Check(::fabsf(HumanTerminatorMultiplierCpu(neutral, n, n, rep_grazing) - 1.0f) < 1e-6f, "the neutral set leaves area-light diffuse untouched"); } diff --git a/test/input_touch_sdl_test.cc b/test/input_touch_sdl_test.cc index 4a7a830e..89bedd23 100644 --- a/test/input_touch_sdl_test.cc +++ b/test/input_touch_sdl_test.cc @@ -30,7 +30,7 @@ void Check(const char* what, bool ok) { } bool Near(rx::f32 a, rx::f32 b, rx::f32 eps = 1.0f) { - return ::fabs(a - b) < eps; // a pixel of slack: normalized -> pixel rounds + return ::fabsf(a - b) < eps; // a pixel of slack: normalized -> pixel rounds } constexpr SDL_TouchID kTouch = 1; diff --git a/test/input_touch_test.cc b/test/input_touch_test.cc index d8068550..944b38e6 100644 --- a/test/input_touch_test.cc +++ b/test/input_touch_test.cc @@ -25,7 +25,7 @@ void Check(const char* what, bool ok) { } bool Near(rx::f32 a, rx::f32 b) { - return ::fabs(a - b) < 1e-4f; + return ::fabsf(a - b) < 1e-4f; } using rx::TouchState; diff --git a/test/instance_store_test.cc b/test/instance_store_test.cc index 6b9a839e..0cb82d6f 100644 --- a/test/instance_store_test.cc +++ b/test/instance_store_test.cc @@ -82,7 +82,7 @@ class TestDevice final : public Device { size_t data_uploads_ = 0; }; -bool Near(f32 a, f32 b) { return ::abs(a - b) < 1e-5f; } +bool Near(f32 a, f32 b) { return ::fabsf(a - b) < 1e-5f; } f32 TranslationX(const GpuBuffer& buffer, size_t index = 0) { return static_cast(buffer.mapped)[index].m[12]; diff --git a/test/inventory_test.cc b/test/inventory_test.cc index 59bdd803..505361ef 100644 --- a/test/inventory_test.cc +++ b/test/inventory_test.cc @@ -274,7 +274,7 @@ void TestHibernateWakeAndWorldSave() { CHECK(wi.body != 0); }); CHECK(woken.index != 0xffffffff); - CHECK(::abs(world.Get(woken)->position[1] - rest_y) < 0.01f); + CHECK(::fabsf(world.Get(woken)->position[1] - rest_y) < 0.01f); // Load the saved blob (item was hibernated at save time) into a fresh world: // it restores as a dormant store record with the same persistent id. diff --git a/test/jetpack_test.cc b/test/jetpack_test.cc index f29b86e4..c1f12fcb 100644 --- a/test/jetpack_test.cc +++ b/test/jetpack_test.cc @@ -88,7 +88,7 @@ struct Scene { } }; -f32 HSpeed(const Vec3& v) { return ::sqrt(v.x * v.x + v.z * v.z); } +f32 HSpeed(const Vec3& v) { return ::sqrtf(v.x * v.x + v.z * v.z); } } // namespace @@ -245,13 +245,13 @@ int main() { s.Step(20); for (int i = 0; i < 60 * 20; ++i) { const f32 t = i * kDt; - s.jin().enabled = ::sin(t * 3.1f) > 0.0f; - s.jin().thrust = ::sin(t * 7.3f) > 0.0f; - s.intent().move = {::sin(t * 2.0f), 0, ::cos(t * 1.3f)}; - if (::sin(t * 5.0f) > 0.9f) s.intent().jump = true; + s.jin().enabled = ::sinf(t * 3.1f) > 0.0f; + s.jin().thrust = ::sinf(t * 7.3f) > 0.0f; + s.intent().move = {::sinf(t * 2.0f), 0, ::cosf(t * 1.3f)}; + if (::sinf(t * 5.0f) > 0.9f) s.intent().jump = true; s.Step(1); - if (!::isfinite(s.feet_y()) || !::isfinite(s.jst().fuel) || - !::isfinite(s.state().velocity.y)) + if (!isfinite(s.feet_y()) || !isfinite(s.jst().fuel) || + !isfinite(s.state().velocity.y)) return Fail("(f) NaN under random input"); } ::fprintf(stderr, "(f) random 20 s: finite, fuel=%.2f y=%.2f\n", s.jst().fuel, s.feet_y()); diff --git a/test/kite_test.cc b/test/kite_test.cc index 1bd2d1cd..620866c9 100644 --- a/test/kite_test.cc +++ b/test/kite_test.cc @@ -96,7 +96,7 @@ int main() { for (int i = 0; i < 60 * 30; ++i) { Step(world, kite, {}); const f32 a = kite.state().altitude_m; - if (!::isfinite(a)) return Fail("(a) NaN altitude"); + if (!isfinite(a)) return Fail("(a) NaN altitude"); lo = rx::Min(lo, a); hi = rx::Max(hi, a); } @@ -141,7 +141,7 @@ int main() { const f32 left = steered_x(-1.0f); const f32 right = steered_x(+1.0f); ::fprintf(stderr, "(c) steer dX left=%.2f m right=%.2f m\n", left, right); - if (::fabs(left) < 0.5f || ::fabs(right) < 0.5f) + if (::fabsf(left) < 0.5f || ::fabsf(right) < 0.5f) return Fail("(c) steering produced no lateral displacement"); if ((left > 0) == (right > 0)) return Fail("(c) left/right steer did not oppose"); } @@ -195,7 +195,7 @@ int main() { kite.set_anchor(anc); Step(world, kite, in); const f32 a = kite.state().altitude_m; // height above the (moving) anchor - if (!::isfinite(a)) return Fail("(e) NaN while towed"); + if (!isfinite(a)) return Fail("(e) NaN while towed"); max_alt = rx::Max(max_alt, a); } ::fprintf(stderr, "(e) towed max altitude=%.2f m tension=%.1f N\n", max_alt, @@ -217,18 +217,18 @@ int main() { const f32 t = i * kDt; // Violent gusting: base wind plus large multi-frequency swings and a // rotating cross-component. - const f32 base = 8.0f + 7.0f * ::sin(t * 1.3f) + 4.0f * ::sin(t * 5.1f + 0.7f); - const f32 cross = 6.0f * ::sin(t * 0.9f + 2.0f); - world.set_wind({cross, 2.0f * ::sin(t * 3.3f), base}); + const f32 base = 8.0f + 7.0f * ::sinf(t * 1.3f) + 4.0f * ::sinf(t * 5.1f + 0.7f); + const f32 cross = 6.0f * ::sinf(t * 0.9f + 2.0f); + world.set_wind({cross, 2.0f * ::sinf(t * 3.3f), base}); // Also jerk the anchor around to stress the one-sided spring. - kite.set_anchor(Vec3{2.0f * ::sin(t * 2.0f), 0.0f, 2.0f * ::cos(t * 2.0f)}); + kite.set_anchor(Vec3{2.0f * ::sinf(t * 2.0f), 0.0f, 2.0f * ::cosf(t * 2.0f)}); KiteInput in; - in.steer = ::sin(t * 4.0f); + in.steer = ::sinf(t * 4.0f); Step(world, kite, in); const KiteState s = kite.state(); - if (!::isfinite(s.position.x) || !::isfinite(s.position.y) || - !::isfinite(s.position.z) || !::isfinite(s.tension_n) || - !::isfinite(s.alpha_deg)) + if (!isfinite(s.position.x) || !isfinite(s.position.y) || + !isfinite(s.position.z) || !isfinite(s.tension_n) || + !isfinite(s.alpha_deg)) return Fail("(f) NaN under gusting"); max_tension = rx::Max(max_tension, s.tension_n); } diff --git a/test/lens_flare_test.cc b/test/lens_flare_test.cc index 83eddd2b..75b023ec 100644 --- a/test/lens_flare_test.cc +++ b/test/lens_flare_test.cc @@ -82,10 +82,10 @@ int main() { for (u32 c = 0; c < 3; ++c) { const u32 index = (y*w+x)*4+c; const f32 value = pixels[index]; - if (!::isfinite(value)) ++failures; - sum += ::abs(value); - if (!expected) outside += ::abs(value); - if (mode == 2) difference = rx::Max(difference, double(::abs(value-reference[index]))); + if (!isfinite(value)) ++failures; + sum += ::fabsf(value); + if (!expected) outside += ::fabsf(value); + if (mode == 2) difference = rx::Max(difference, double(::fabsf(value-reference[index]))); } } ::printf("flare mode=%u energy=%g outside_ghosts=%g exposure_error=%g\n", mode, sum, outside, difference); diff --git a/test/locomotion_math_test.cc b/test/locomotion_math_test.cc index 817087b9..3ef749c4 100644 --- a/test/locomotion_math_test.cc +++ b/test/locomotion_math_test.cc @@ -29,18 +29,18 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-4f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "locomotion_math_test: FAIL: %s (got %.6f, expected %.6f)\n", message, actual, expected); ++failures; } bool Finite(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } bool Finite(const Quat& q) { - return ::isfinite(q.x) && ::isfinite(q.y) && ::isfinite(q.z) && ::isfinite(q.w); + return isfinite(q.x) && isfinite(q.y) && isfinite(q.z) && isfinite(q.w); } // synthetic terrain probes @@ -215,7 +215,7 @@ void TestGaitRampSmooth() { for (int i = 0; i < 400; ++i) { clock.Update(m, run, params, false, dt); const f32 rate = clock.state().phase_rate; - if (prev_rate > 0 && ::abs(rate - prev_rate) / prev_rate > 0.2f) smooth = false; + if (prev_rate > 0 && ::fabsf(rate - prev_rate) / prev_rate > 0.2f) smooth = false; prev_rate = rate; } Check(smooth, "phase rate ramps smoothly (<20% per tick)"); @@ -231,7 +231,7 @@ void TestCapturePoint() { const Vec3 v{0.5f, 0, -0.3f}; const Vec3 cp1 = CapturePoint(com, v, 9.81f, 0.95f); - const f32 omega = ::sqrt(9.81f / 0.95f); + const f32 omega = ::sqrtf(9.81f / 0.95f); Near(cp1.x - com.x, v.x / omega, "capture offset x = v/sqrt(g/h)"); Near(cp1.z - com.z, v.z / omega, "capture offset z = v/sqrt(g/h)"); @@ -360,7 +360,7 @@ void TestFootstepPlanner() { // Rotation angle of a quaternion delta from identity (radians, [0,pi]). f32 QuatAngle(const Quat& q) { const Quat n = Normalize(q); - return 2.0f * ::acos(::abs(n.w) > 1.0f ? 1.0f : ::abs(n.w)); + return 2.0f * ::acosf(::fabsf(n.w) > 1.0f ? 1.0f : ::fabsf(n.w)); } // Independent forward kinematics matching the module's chain convention: the @@ -416,7 +416,7 @@ void TestLegIkForwardKinematics() { const Vec3 target{x, y, z}; const Vec3 ankle_target = target + flat_normal * foot_height; const LegIkResult r = SolveLegIk(target, flat_normal, upper, lower, foot_height); - Check(Finite(r.hip) && Finite(r.ankle) && ::isfinite(r.knee_flexion), "leg IK finite"); + Check(Finite(r.hip) && Finite(r.ankle) && isfinite(r.knee_flexion), "leg IK finite"); Check(r.knee_flexion >= 0.0f, "knee flexion non-negative"); Check(!r.clamped, "reachable target not clamped"); const Vec3 ankle = LegForwardAnkle(r, upper, lower); @@ -458,13 +458,13 @@ void TestLegIkUnreachable() { Near(r.knee_flexion, 0.0f, "unreachable leg is ~straight", 0.05f); const Vec3 sole = LegForwardKinematics(r, upper, lower, foot_height); const f32 cos_angle = Dot(Normalize(sole), Normalize(target)); - const f32 angle = ::acos(cos_angle > 1.0f ? 1.0f : cos_angle); + const f32 angle = ::acosf(cos_angle > 1.0f ? 1.0f : cos_angle); Check(angle < 2.0f * 3.14159265f / 180.0f, "FK aims within 2deg of the target direction"); } void TestLegIkDegenerate() { const LegIkResult r = SolveLegIk({0, 0, 0}, {0, 1, 0}, 0.45f, 0.40f, 0.054f); - Check(Finite(r.hip) && Finite(r.ankle) && ::isfinite(r.knee_flexion), "degenerate finite"); + Check(Finite(r.hip) && Finite(r.ankle) && isfinite(r.knee_flexion), "degenerate finite"); Check(r.clamped, "zero-length target flagged clamped"); } @@ -523,7 +523,7 @@ void TestWholeBodyStanding() { for (u32 j = 0; j < kRigJointCount; ++j) { Check(Finite(out.joint_target[j]), "joint target finite"); - Check(::isfinite(out.joint_drive_scale[j]), "drive scale finite"); + Check(isfinite(out.joint_drive_scale[j]), "drive scale finite"); } Check(Finite(out.root_assist_force) && Finite(out.root_assist_torque), "root assists finite"); diff --git a/test/locomotion_test.cc b/test/locomotion_test.cc index e7f647e5..cc385ca6 100644 --- a/test/locomotion_test.cc +++ b/test/locomotion_test.cc @@ -33,7 +33,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-2f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "locomotion_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; @@ -90,19 +90,19 @@ Vec3 BodyPos(const physics::PhysicsWorld& phys, physics::BodyId id) { } bool FiniteVec(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } bool MeasurementsFinite(const CharacterMeasurements& m) { - bool ok = FiniteVec(m.root_position) && ::isfinite(m.root_rotation.x) && - ::isfinite(m.root_rotation.w) && FiniteVec(m.root_linear_velocity) && + bool ok = FiniteVec(m.root_position) && isfinite(m.root_rotation.x) && + isfinite(m.root_rotation.w) && FiniteVec(m.root_linear_velocity) && FiniteVec(m.root_angular_velocity) && FiniteVec(m.com_position) && FiniteVec(m.com_velocity) && FiniteVec(m.ground_normal) && - ::isfinite(m.estimated_body_height); + isfinite(m.estimated_body_height); for (u32 f = 0; f < kFootCount; ++f) { ok = ok && FiniteVec(m.foot[f].position) && FiniteVec(m.foot[f].velocity) && - FiniteVec(m.foot[f].contact_normal) && ::isfinite(m.foot[f].contact_impulse) && - ::isfinite(m.foot[f].slip_speed); + FiniteVec(m.foot[f].contact_normal) && isfinite(m.foot[f].contact_impulse) && + isfinite(m.foot[f].slip_speed); } return ok; } @@ -147,7 +147,7 @@ void TestBuild() { Check(sole_r.y > -0.01f && sole_r.y < 0.05f, "right sole near y in [0, 0.05]"); bool binds_ok = true; - for (u32 j = 0; j < kRigJointCount; ++j) binds_ok = binds_ok && ::abs(rig.bind_constraint[j].w) > 0.99f; + for (u32 j = 0; j < kRigJointCount; ++j) binds_ok = binds_ok && ::fabsf(rig.bind_constraint[j].w) > 0.99f; Check(binds_ok, "every bind constraint orientation is near identity (|w| > 0.99)"); Check(rig.leg_length > 0 && rig.upper_leg_length > 0 && rig.lower_leg_length > 0 && @@ -466,15 +466,15 @@ void CheckFinite(const physics::PhysicsWorld& phys, const LocomotionController& phys.GetBodyTransform(rig.body[i], &p, r); Vec3 lin, ang; phys.GetBodyVelocity(rig.body[i], &lin, &ang); - ok = ok && FiniteVec(p) && ::isfinite(r[0]) && ::isfinite(r[1]) && ::isfinite(r[2]) && - ::isfinite(r[3]) && FiniteVec(lin) && FiniteVec(ang); + ok = ok && FiniteVec(p) && isfinite(r[0]) && isfinite(r[1]) && isfinite(r[2]) && + isfinite(r[3]) && FiniteVec(lin) && FiniteVec(ang); } const DebugState& d = c.debug(); ok = ok && FiniteVec(d.desired_velocity) && FiniteVec(d.controlled_facing) && FiniteVec(d.measured_velocity) && FiniteVec(d.com_position) && FiniteVec(d.com_velocity) && FiniteVec(d.capture_point) && - FiniteVec(d.support_center) && ::isfinite(d.gait_phase) && - ::isfinite(d.max_torque_saturation) && ::isfinite(d.mode_time); + FiniteVec(d.support_center) && isfinite(d.gait_phase) && + isfinite(d.max_torque_saturation) && isfinite(d.mode_time); for (u32 f = 0; f < kFootCount; ++f) ok = ok && FiniteVec(d.foot_target[f]) && FiniteVec(d.swing_position[f]); if (!ok) { @@ -528,7 +528,7 @@ void TestStand() { min_pelvis = rx::Min(min_pelvis, py); max_pelvis = rx::Max(max_pelvis, py); const Vec3 com = c.measurements().com_position; - max_drift = rx::Max(max_drift, ::sqrt((com.x - com0.x) * (com.x - com0.x) + + max_drift = rx::Max(max_drift, ::sqrtf((com.x - com0.x) * (com.x - com0.x) + (com.z - com0.z) * (com.z - com0.z))); } @@ -578,7 +578,7 @@ void TestPushes() { py); Check(py > 0.85f * nominal, msg); const Vec3 v = c.measurements().com_velocity; - const f32 planar = ::sqrt(v.x * v.x + v.z * v.z); + const f32 planar = ::sqrtf(v.x * v.x + v.z * v.z); ::snprintf(msg, sizeof msg, "push %s planar COM speed < 0.3 (got %.2f)", names[d], planar); Check(planar < 0.3f, msg); CheckFinite(s.physics, c, "push"); @@ -720,7 +720,7 @@ void TestStartStop() { Check(!fell, "start/stop never falls"); Check(c.mode() == ControlMode::kStable, "settles to kStable after stop"); const Vec3 vs = c.measurements().com_velocity; - Check(::sqrt(vs.x * vs.x + vs.z * vs.z) < 0.3f, "planar speed < 0.3 after stop"); + Check(::sqrtf(vs.x * vs.x + vs.z * vs.z) < 0.3f, "planar speed < 0.3 after stop"); // Second walk: verify the gait RE-ENGAGES on the renewed command. Net forward // distance is not asserted (relaxed from the spec's "> 0.7 m/s") because by @@ -810,7 +810,7 @@ void TestTurnRate() { c.Tick(left, mods, kDt); s.physics.Update(kDt); const Vec3 first = c.debug().controlled_facing; - const f32 first_angle = ::atan2(Cross(Vec3{0, 0, -1}, first).y, + const f32 first_angle = ::atan2f(Cross(Vec3{0, 0, -1}, first).y, Dot(Vec3{0, 0, -1}, first)); Check(first_angle > 0, "turn target starts moving toward requested facing"); Check(first_angle <= params.max_turn_rate * kDt + 1e-4f, diff --git a/test/materialx_test.cc b/test/materialx_test.cc index b45e298a..a715dac0 100644 --- a/test/materialx_test.cc +++ b/test/materialx_test.cc @@ -114,7 +114,7 @@ void TestOpenPbrImages() { Check(maps.metallic.empty(), "a constant input leaves its map slot empty"); // OpenPBR spells it base_metalness; the engine field is the same one // standard_surface's metalness fills. - Check(::fabs(material.metallic_factor - 0.25f) < 1e-6f, + Check(::fabsf(material.metallic_factor - 0.25f) < 1e-6f, "the OpenPBR spelling of a constant input maps onto the same field"); // The shader multiplies each map by its factor. The OpenPBR defaults seeded // before parsing (0.8 base colour, 0.3 roughness) must not survive onto a @@ -137,7 +137,7 @@ void TestNodegraphAndUnsupportedNode() { // empty (and warning by name) is the honest answer; binding the operand as if // it were the result would render a material nobody authored. Check(maps.roughness.empty(), "a connection through an unevaluated node binds nothing"); - Check(::fabs(material.ior - 1.7f) < 1e-6f, "constants beside a connection still load"); + Check(::fabsf(material.ior - 1.7f) < 1e-6f, "constants beside a connection still load"); fs::Remove(path); } @@ -147,12 +147,12 @@ void TestConstantsStillLoad() { Check(asset::LoadMaterialX(path, &material, nullptr), "a constants-only document loads with no maps requested"); // base is a weight on base_color, not a field of its own. - Check(::fabs(material.base_color_factor[0] - 0.1f) < 1e-6f && - ::fabs(material.base_color_factor[2] - 0.3f) < 1e-6f, + Check(::fabsf(material.base_color_factor[0] - 0.1f) < 1e-6f && + ::fabsf(material.base_color_factor[2] - 0.3f) < 1e-6f, "base weight multiplies base_color"); - Check(::fabs(material.metallic_factor - 1.0f) < 1e-6f && - ::fabs(material.roughness_factor - 0.3f) < 1e-6f && - ::fabs(material.clearcoat - 0.75f) < 1e-6f, + Check(::fabsf(material.metallic_factor - 1.0f) < 1e-6f && + ::fabsf(material.roughness_factor - 0.3f) < 1e-6f && + ::fabsf(material.clearcoat - 0.75f) < 1e-6f, "the standard_surface constants map onto the engine's lobes"); fs::Remove(path); } diff --git a/test/morph_test.cc b/test/morph_test.cc index f80293ca..7521f5f3 100644 --- a/test/morph_test.cc +++ b/test/morph_test.cc @@ -77,7 +77,7 @@ constexpr char kNamedTargetsGltf[] = R"({ "buffers": [{"byteLength": 132, "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgD8AAIA+AABAPwAAgD8AAAAA"}] })"; -bool Near(f32 a, f32 b, f32 tolerance = 1e-5f) { return ::abs(a - b) <= tolerance; } +bool Near(f32 a, f32 b, f32 tolerance = 1e-5f) { return ::fabsf(a - b) <= tolerance; } int TestNamedTargets() { base::String path = @@ -139,7 +139,7 @@ int TestAnimatedMorphCube(const char* path) { if (target.position_deltas.size() != verts * 3) return Fail("position delta size"); if (target.normal_deltas.size() != verts * 3) return Fail("normal delta size"); if (target.tangent_deltas.size() != verts * 3) return Fail("tangent delta size"); - for (f32 d : target.position_deltas) magnitude = rx::Max(magnitude, ::abs(d)); + for (f32 d : target.position_deltas) magnitude = rx::Max(magnitude, ::fabsf(d)); } if (magnitude <= 0) return Fail("all position deltas are zero"); @@ -277,7 +277,7 @@ int TestGpuEvaluation(const char* path) { for (const Pair& pair : pairs) { expected += pair.weight * deltas[(static_cast(pair.target) * verts + v) * 9 + c]; } - worst = rx::Max(worst, ::abs(result[v * 9 + c] - expected)); + worst = rx::Max(worst, ::fabsf(result[v * 9 + c] - expected)); } } ::printf("morph_test: gpu vs cpu max error %g\n", worst); diff --git a/test/nav_test.cc b/test/nav_test.cc index 9ec82d9b..5bb3bcbc 100644 --- a/test/nav_test.cc +++ b/test/nav_test.cc @@ -28,7 +28,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-3f) { - if (::fabs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "nav_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; @@ -84,7 +84,7 @@ void TestBuildAndQueries(NavMesh& mesh) { Check(mesh.Area(mesh.CellAt({14, 0, 8})) == kAreaRock, "rock band painted by sampler"); Check(mesh.Area(mesh.CellAt({16, 0, 25})) == kAreaWater, "river present"); f32 h = 1; - Check(mesh.HeightAt(10, 10, &h) && ::fabs(h) < 1e-3f, "surface height on open ground"); + Check(mesh.HeightAt(10, 10, &h) && ::fabsf(h) < 1e-3f, "surface height on open ground"); const CellRef clamp = mesh.ClampToWalkable({5.0f, 0, 5.0f}, 3.0f); Check(clamp.valid() && mesh.Walkable(clamp), "off-mesh point clamps to walkable cell"); diff --git a/test/net_test.cc b/test/net_test.cc index 31a73740..3924f1b7 100644 --- a/test/net_test.cc +++ b/test/net_test.cc @@ -288,9 +288,9 @@ void TestInterpolation() { net::TickInterpolation(world, 0.5f); const scene::Transform* now = world.Get(e); - CHECK(::fabs(now->position[0] - 5.0f) < 1e-4f); + CHECK(::fabsf(now->position[0] - 5.0f) < 1e-4f); const net::ReplicatedGait* gait = world.Get(e); - CHECK(gait->moving && ::fabs(gait->speed - 10.0f) < 1e-3f); + CHECK(gait->moving && ::fabsf(gait->speed - 10.0f) < 1e-3f); net::TickInterpolation(world, 0.6f); now = world.Get(e); diff --git a/test/openpbr_test.cc b/test/openpbr_test.cc index 6e18bf32..0d05eade 100644 --- a/test/openpbr_test.cc +++ b/test/openpbr_test.cc @@ -101,7 +101,7 @@ bool Write(const base::String &path, const char *text, size_t size) { return ok; } -bool Near(f32 value, f32 expected) { return ::fabs(value - expected) < 1e-4f; } +bool Near(f32 value, f32 expected) { return ::fabsf(value - expected) < 1e-4f; } bool Near3(const f32 *value, f32 x, f32 y, f32 z) { return Near(value[0], x) && Near(value[1], y) && Near(value[2], z); @@ -231,7 +231,7 @@ void CheckUnknownShaderRejected() { Check(!loaded, "a document with neither surface node is rejected"); } -bool Finite(f32 v) { return ::isfinite(v); } +bool Finite(f32 v) { return isfinite(v); } bool Finite3(const f32 *v) { return Finite(v[0]) && Finite(v[1]) && Finite(v[2]); } diff --git a/test/path_motion_test.cc b/test/path_motion_test.cc index 078b80cb..16569f95 100644 --- a/test/path_motion_test.cc +++ b/test/path_motion_test.cc @@ -118,9 +118,9 @@ int main() { recon ? "recon" : "nrd", previous, data[0], data[1], data[2], data[4], data[5], data[6]); check(data[7] == 1 && data[3] == (valid ? 1 : 0), "trace hit and motion validity"); if (valid) { - check(::abs(data[0] - expected_x) < 1e-5f && ::abs(data[1] - .5f) < 1e-5f, + check(::fabsf(data[0] - expected_x) < 1e-5f && ::fabsf(data[1] - .5f) < 1e-5f, "previous position includes rigid transform and previous vertex pose"); - check(::abs(data[4] - rx::Clamp(expected_x * .5f, -2.f, 2.f)) < 1e-5f && ::abs(data[5] - .25f) < 1e-5f, + check(::fabsf(data[4] - rx::Clamp(expected_x * .5f, -2.f, 2.f)) < 1e-5f && ::fabsf(data[5] - .25f) < 1e-5f, "motion is current-to-previous in UV units"); } else { check(data[4] == 2 && data[5] == 2, "missing surface history rejects reprojection"); diff --git a/test/path_sampling_test.cc b/test/path_sampling_test.cc index ded6b8f3..15d27dd6 100644 --- a/test/path_sampling_test.cc +++ b/test/path_sampling_test.cc @@ -115,7 +115,7 @@ int main() { f32 light[16] = {0, 1, 0, 10, 1, 1, 1, 0}; GpuBuffer lights = device->CreateBuffer(sizeof(light), kBufferUsageStorage, true); base::Vector cdf(1 + kSkyH + 2 * kSkyW * kSkyH); - const f32 omega = 2 * kPi / kSkyW * (1 - ::cos(kPi / kSkyH)); + const f32 omega = 2 * kPi / kSkyW * (1 - ::cosf(kPi / kSkyH)); cdf[0] = omega; for (u32 r = 0; r < kSkyH; ++r) cdf[1 + r] = omega; for (u32 c = 0; c < kSkyW; ++c) cdf[1 + kSkyH + c] = 1; @@ -164,7 +164,7 @@ int main() { f32 expected = mode == 2 ? 2 : 1; bool correct = true; for (u32 p = 0; p < kPixels; ++p) - correct &= ::abs(values[1][4 * p + 2] - expected) < 1e-4f; + correct &= ::fabsf(values[1][4 * p + 2] - expected) < 1e-4f; ::printf("candidates=%u mode=%u W=%g expected=%g\n", candidates, mode, values[1][2], expected); check(correct, "candidate count must not change total light energy"); @@ -173,11 +173,11 @@ int main() { Push push; push.candidates = 0; run(push, 1); - check(::abs(values[1][2] - 1) < 1e-5f, "zero point proposals retain sun energy"); + check(::fabsf(values[1][2] - 1) < 1e-5f, "zero point proposals retain sun energy"); push.candidates = 8; push.light_count = 0; run(push, 0); - check(::abs(values[1][2] - 1) < 1e-5f, "sun-only scene retains its energy"); + check(::fabsf(values[1][2] - 1) < 1e-5f, "sun-only scene retains its energy"); push.sun_direction[3] = 0; push.sky_candidates = 1; run(push, 0); @@ -197,8 +197,8 @@ int main() { ::printf("sky solid-angle mean=%g lower-half fraction=%g retained=%u/%u\n", mean, fraction, samples, kPixels); check(samples >= kPixels - 8, "sky proposals must retain positive target mass"); - check(::abs(mean - .5) < .015, "sky cells must be uniform in solid angle"); - check(::abs(fraction - .5) < .02, "sky PDF must match cell samples"); + check(::fabs(mean - .5) < .015, "sky cells must be uniform in solid angle"); + check(::fabs(fraction - .5) < .02, "sky PDF must match cell samples"); const f32 dead_id[4] = {0, 0, 0, -1}, light_id[4] = {0, 0, 0, 1}; const f32 dead_mass[4] = {0, 2, 0, 0}, live_mass[4] = {4, 2, 2, 0}; @@ -212,12 +212,12 @@ int main() { reuse.reset = 0; run(reuse, 1, dead_sample, dead_history); const f32 dark_estimate = values[1][2]; - check(::abs(values[1][1] - 4) < 1e-5f, "zero-weight DI history retains sample count"); + check(::fabsf(values[1][1] - 4) < 1e-5f, "zero-weight DI history retains sample count"); run(reuse, 1, live_sample, live_history); const f32 bright_estimate = values[1][2]; ::printf("DI reuse: dark=%g bright=%g mean=%g expected=1\n", dark_estimate, bright_estimate, (dark_estimate + bright_estimate) / 2); - check(::abs((dark_estimate + bright_estimate) / 2 - 1) < 1e-5f, + check(::fabsf((dark_estimate + bright_estimate) / 2 - 1) < 1e-5f, "equally likely zero and double-energy histories must preserve expected energy"); reuse.pad[1] = 1; run(reuse, 1, live_sample, live_history); @@ -226,7 +226,7 @@ int main() { reuse.light_count = 0; reuse.sky_candidates = 1; run(reuse, 0, {}, {}, dead_sample, dead_history); - check(::abs(values[3][1] - 3) < 1e-5f, "zero-weight sky history retains sample count"); + check(::fabsf(values[3][1] - 3) < 1e-5f, "zero-weight sky history retains sample count"); check(values[3][4 * (kWidth - 1) + 1] == 1, "sky reservoir reprojection includes the jitter delta"); @@ -271,7 +271,7 @@ int main() { check(device->ReadbackImage(mass, ResourceState::kGeneral, values[0].data(), values[0].size() * sizeof(f32)), "read reservoir count"); ::printf("%s: M=%g\n", name, values[0][center]); - check(values[0][center] > 2 && ::isfinite(values[0][center]), name); + check(values[0][center] > 2 && isfinite(values[0][center]), name); } device->ImmediateSubmit([&](CommandList& cmd) { cmd.Barrier(Transition(mass, ResourceState::kCopySrc, ResourceState::kGeneral)); @@ -323,7 +323,7 @@ int main() { check(device->ReadbackImage(out[0], ResourceState::kGeneral, values[0].data(), values[0].size() * sizeof(f32)), "read GI reconnection weight"); ::printf("GI reconnection W=%g expected=%g\n", values[0][3], kPi * .5f); - check(::abs(values[0][3] - kPi * .5f) < 1e-5f, "temporal GI must convert source solid angle to current solid angle"); + check(::fabsf(values[0][3] - kPi * .5f) < 1e-5f, "temporal GI must convert source solid angle to current solid angle"); device->ImmediateSubmit([&](CommandList& cmd) { cmd.Barrier(Transition(out[0], ResourceState::kCopySrc, ResourceState::kGeneral)); }); @@ -385,7 +385,7 @@ int main() { for (u32 p = 0; p < kPixels; ++p) for (u32 c = 0; c < 3; ++c) energy[c] += values[0][4 * p + c] / kPixels; for (u32 c = 0; c < 3; ++c) - check(::abs(energy[c] - .001 * (c + 1)) < .00015, "roulette retains expected energy of dim paths"); + check(::fabs(energy[c] - .001 * (c + 1)) < .00015, "roulette retains expected energy of dim paths"); ::printf("dim-path expected energy=(.001,.002,.003), measured=(%g,%g,%g)\n", energy[0], energy[1], energy[2]); device->DestroyPipeline(continuation); device->DestroyImage(half_out); diff --git a/test/physics_body_test.cc b/test/physics_body_test.cc index 35056344..60f41af1 100644 --- a/test/physics_body_test.cc +++ b/test/physics_body_test.cc @@ -23,7 +23,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-2f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "physics_body_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; @@ -31,10 +31,10 @@ void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-2f) { // `actual` within `frac` (fraction, e.g. 0.1 = 10%) of `expected`. void NearRel(f32 actual, f32 expected, f32 frac, const char* message) { - Near(actual, expected, message, frac * ::abs(expected)); + Near(actual, expected, message, frac * ::fabsf(expected)); } -bool Finite(f32 v) { return ::isfinite(v); } +bool Finite(f32 v) { return isfinite(v); } bool Finite(const Vec3& v) { return Finite(v.x) && Finite(v.y) && Finite(v.z); } void CheckFinite(const Vec3& v, const char* message) { Check(Finite(v), message); } @@ -153,7 +153,7 @@ void TestApplyTorque() { Check(w.GetBodyVelocity(box, &lin, &ang1), "angular velocity readable"); CheckFinite(ang1, "angular velocity finite (early)"); Check(ang1.y > 0, "torque about +Y spins the body positively about Y"); - Check(::abs(ang1.y) > ::abs(ang1.x) && ::abs(ang1.y) > ::abs(ang1.z), + Check(::fabsf(ang1.y) > ::fabsf(ang1.x) && ::fabsf(ang1.y) > ::fabsf(ang1.z), "spin stays about the applied (Y) axis"); spin(20); @@ -220,7 +220,7 @@ void TestContacts() { Check(Finite(c.impulse), "contact impulse finite"); // Normal points INTO the box, i.e. up for a box resting on the floor; // the contact sits at the box's bottom face (y ~ 0). - if (c.normal.y > 0.7f && ::abs(c.position.y) < 0.1f) floor_like = true; + if (c.normal.y > 0.7f && ::fabsf(c.position.y) < 0.1f) floor_like = true; } } Check(saw_contact, "a box landing on the floor reports at least one contact"); @@ -276,7 +276,7 @@ void TestMotors() { Check(w.GetJointOrientation(joint, q), "joint orientation readable"); Check(Finite(q[0]) && Finite(q[1]) && Finite(q[2]) && Finite(q[3]), "joint orientation finite"); // |dot| of unit quaternions = cos(half-angle); 1 means aligned. - return ::abs(q[0] * target[0] + q[1] * target[1] + q[2] * target[2] + q[3] * target[3]); + return ::fabsf(q[0] * target[0] + q[1] * target[1] + q[2] * target[2] + q[3] * target[3]); }; step(120); // 2 s @@ -304,7 +304,7 @@ void TestMotors() { step(20); f32 after[4] = {0, 0, 0, 1}; w.GetJointOrientation(joint, after); - const f32 moved = ::abs(before[0] * after[0] + before[1] * after[1] + before[2] * after[2] + + const f32 moved = ::fabsf(before[0] * after[0] + before[1] * after[1] + before[2] * after[2] + before[3] * after[3]); Check(moved < 0.999f, "disabled motors let the joint swing free"); } diff --git a/test/placement_gpu_test.cc b/test/placement_gpu_test.cc index e38897ec..950df721 100644 --- a/test/placement_gpu_test.cc +++ b/test/placement_gpu_test.cc @@ -78,11 +78,11 @@ int main() { WorldData world(0.0f, 0.0f, 512.0f, 128); u32 height = world.AddMap("height"); world.Generate(height, [](f32 x, f32 z) { - return 6.0f * ::sin(x * 0.011f) + 4.0f * ::cos(z * 0.017f); + return 6.0f * ::sinf(x * 0.011f) + 4.0f * ::cosf(z * 0.017f); }); u32 forest = world.AddMap("forest"); world.Generate(forest, [](f32 x, f32 z) { - return 0.5f + 0.5f * ::sin(x * 0.007f) * ::cos(z * 0.009f); + return 0.5f + 0.5f * ::sinf(x * 0.007f) * ::cosf(z * 0.009f); }); PlacementConfig config; @@ -157,7 +157,7 @@ int main() { continue; } for (u32 e = 0; e < 16; ++e) { - if (::fabs(gpu_a[i].transform.m[e] - cpu[i].transform.m[e]) > 2e-3f) { + if (::fabsf(gpu_a[i].transform.m[e] - cpu[i].transform.m[e]) > 2e-3f) { ++mismatches; break; } diff --git a/test/placement_test.cc b/test/placement_test.cc index f3567bd8..77bb2943 100644 --- a/test/placement_test.cc +++ b/test/placement_test.cc @@ -31,18 +31,18 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-3f) { - if (::fabs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "placement_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; } f32 ToroidalDistance(f32 ax, f32 ay, f32 bx, f32 by) { - f32 dx = ::fabs(ax - bx); - f32 dy = ::fabs(ay - by); + f32 dx = ::fabsf(ax - bx); + f32 dy = ::fabsf(ay - by); dx = rx::Min(dx, 1.0f - dx); dy = rx::Min(dy, 1.0f - dy); - return ::sqrt(dx * dx + dy * dy); + return ::sqrtf(dx * dx + dy * dy); } // The two pattern-generator rules: even threshold coverage at every prefix, @@ -64,7 +64,7 @@ void TestPattern() { kPatternXY[j * 2], kPatternXY[j * 2 + 1])); } } - f32 ideal = ::sqrt(1.0f / static_cast(prefix)); + f32 ideal = ::sqrtf(1.0f / static_cast(prefix)); Check(min_dist >= 0.5f * ideal, "pattern prefix keeps half the ideal spacing"); } @@ -170,7 +170,7 @@ void TestDeterminismAndSpacing() { WorldData world(0.0f, 0.0f, 512.0f, 256); u32 height = world.AddMap("height"); world.Generate(height, [](f32 x, f32 z) { - return 4.0f * ::sin(x * 0.02f) + 3.0f * ::cos(z * 0.015f); + return 4.0f * ::sinf(x * 0.02f) + 3.0f * ::cosf(z * 0.015f); }); u32 forest = world.AddMap("forest", 1.0f); u32 road = world.AddMap("road"); @@ -197,7 +197,7 @@ void TestDeterminismAndSpacing() { for (u32 j = i + 1; j < a.size(); ++j) { f32 dx = a[i].transform.m[12] - a[j].transform.m[12]; f32 dz = a[i].transform.m[14] - a[j].transform.m[14]; - min_dist = rx::Min(min_dist, ::sqrt(dx * dx + dz * dz)); + min_dist = rx::Min(min_dist, ::sqrtf(dx * dx + dz * dz)); } } Check(min_dist >= 0.6f * stack.footprint, "instances keep footprint spacing"); @@ -225,7 +225,7 @@ void TestDeterminismAndSpacing() { f32 z = instance.transform.m[14]; Near(instance.transform.m[13], world.Sample(height, x, z), "instance sits on ground", 0.01f); - f32 sx = ::sqrt(instance.transform.m[0] * instance.transform.m[0] + + f32 sx = ::sqrtf(instance.transform.m[0] * instance.transform.m[0] + instance.transform.m[1] * instance.transform.m[1] + instance.transform.m[2] * instance.transform.m[2]); Check(sx >= 0.79f && sx <= 1.31f, "instance scale within layer range"); diff --git a/test/post_sampling_test.cc b/test/post_sampling_test.cc index 55a01e0e..5561ed90 100644 --- a/test/post_sampling_test.cc +++ b/test/post_sampling_test.cc @@ -17,7 +17,7 @@ constexpr u32 kW = 256, kH = 128; f32 Half(u16 b) { if ((b & 0x7c00u) == 0x7c00u) return INFINITY; const int exponent = (b >> 10) & 31; - return ::ldexp(float((b & 1023) + (exponent ? 1024 : 0)), + return ::ldexpf(float((b & 1023) + (exponent ? 1024 : 0)), exponent ? exponent - 25 : -24) * ((b & 0x8000) ? -1.f : 1.f); } struct TilePush { @@ -103,8 +103,8 @@ int main() { for (u32 y = top; y < bottom; ++y) for (u32 x = left; x < right; ++x) for (u32 c = 0; c < 3; ++c) { const u32 i = (y*kW+x)*4+c; - if (!::isfinite(a[i]) || !::isfinite(b[i])) return double(INFINITY); - error = rx::Max(error, double(::abs(a[i]-b[i]))); + if (!isfinite(a[i]) || !isfinite(b[i])) return double(INFINITY); + error = rx::Max(error, double(::fabsf(a[i]-b[i]))); } return error; }; @@ -206,7 +206,7 @@ int main() { if (!device->ReadbackImage(tiles, ResourceState::kGeneral, bits.data(), bits.size()*sizeof(u16))) return 1; double error = 0; for (u32 p = 0; p < bits.size()/2; ++p) - error = rx::Max(error, double(::abs(Half(bits[p*2])-12.f/kW) + ::abs(Half(bits[p*2+1])))); + error = rx::Max(error, double(::fabsf(Half(bits[p*2])-12.f/kW) + ::fabsf(Half(bits[p*2+1])))); check(error < .0001, "Motion blur aspect-correct maximum", error); device->WaitIdle(); device->DestroyPipeline(pipeline); diff --git a/test/procedural_asset_test.cc b/test/procedural_asset_test.cc index e1a6c7ac..0e592dad 100644 --- a/test/procedural_asset_test.cc +++ b/test/procedural_asset_test.cc @@ -43,9 +43,9 @@ void TestCheckerMask() { CHECK(low < 0.01f); CHECK(high > 0.99f); // Diagonal neighbours share a colour, orthogonal ones do not. - CHECK(::abs(asset::SamplePattern(desc, 0.375f, 0.375f) - low) < 0.01f); + CHECK(::fabsf(asset::SamplePattern(desc, 0.375f, 0.375f) - low) < 0.01f); // Tiles: the mask at u and at u + 1 is the same field. - CHECK(::abs(asset::SamplePattern(desc, 1.125f, 0.125f) - low) < 0.01f); + CHECK(::fabsf(asset::SamplePattern(desc, 1.125f, 0.125f) - low) < 0.01f); } // The two axes have to be independent, because the thing they describe is: a @@ -77,9 +77,9 @@ void TestPatternAxes() { desc.scale[1] = 12.0f; for (u32 i = 0; i < 8; ++i) { const f32 u = i / 8.0f, v = i / 5.0f; - CHECK(::abs(asset::SamplePattern(desc, u + 1.0f, v) - + CHECK(::fabsf(asset::SamplePattern(desc, u + 1.0f, v) - asset::SamplePattern(desc, u, v)) < 1e-4f); - CHECK(::abs(asset::SamplePattern(desc, u, v + 1.0f) - + CHECK(::fabsf(asset::SamplePattern(desc, u, v + 1.0f) - asset::SamplePattern(desc, u, v)) < 1e-4f); } } @@ -156,9 +156,9 @@ void TestNormalMap() { for (size_t i = 0; i < relief.data.size(); i += 4) { f32 n[3]; for (int c = 0; c < 3; ++c) n[c] = relief.data[i + c] / 255.0f * 2.0f - 1.0f; - CHECK(::abs(::sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]) - 1.0f) < 0.02f); + CHECK(::fabsf(::sqrtf(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]) - 1.0f) < 0.02f); CHECK(n[2] > 0.0f); // a heightfield normal never points into the surface - tilted |= ::abs(n[0]) > 0.2f || ::abs(n[1]) > 0.2f; + tilted |= ::fabsf(n[0]) > 0.2f || ::fabsf(n[1]) > 0.2f; } CHECK(tilted); } @@ -197,15 +197,15 @@ void CheckMesh(const char* what, const asset::Mesh& mesh) { for (u32 index : lod.indices) CHECK(index < lod.vertices.size()); for (const asset::Vertex& v : lod.vertices) { - f32 len = ::sqrt(v.normal[0] * v.normal[0] + v.normal[1] * v.normal[1] + + f32 len = ::sqrtf(v.normal[0] * v.normal[0] + v.normal[1] * v.normal[1] + v.normal[2] * v.normal[2]); - if (::abs(len - 1.0f) > 1e-3f) { + if (::fabsf(len - 1.0f) > 1e-3f) { ::fprintf(stderr, "procedural_asset_test: %s has a non-unit normal (%f)\n", what, len); ++failures; break; } f32 dot = v.normal[0] * v.tangent[0] + v.normal[1] * v.tangent[1] + v.normal[2] * v.tangent[2]; - if (::abs(dot) > 1e-3f) { + if (::fabsf(dot) > 1e-3f) { ::fprintf(stderr, "procedural_asset_test: %s tangent not perpendicular (%f)\n", what, dot); ++failures; break; @@ -231,9 +231,9 @@ void TestPrimitives() { asset::Mesh plane = asset::MakePlane(2.0f, 3.0f, id); for (const asset::Vertex& v : plane.lods[0].vertices) { CHECK(v.normal[1] > 0.999f); - CHECK(::abs(::abs(v.position[0]) - 2.0f) < 1e-5f); - CHECK(::abs(v.position[1]) < 1e-5f); - CHECK(::abs(::abs(v.position[2]) - 3.0f) < 1e-5f); + CHECK(::fabsf(::fabsf(v.position[0]) - 2.0f) < 1e-5f); + CHECK(::fabsf(v.position[1]) < 1e-5f); + CHECK(::fabsf(::fabsf(v.position[2]) - 3.0f) < 1e-5f); } // A capsule is convex around its axis segment, so every normal points away @@ -243,8 +243,8 @@ void TestPrimitives() { for (const asset::Vertex& v : capsule.lods[0].vertices) { f32 axis_y = v.position[1] > 0.6f ? 0.6f : (v.position[1] < -0.6f ? -0.6f : v.position[1]); f32 d[3] = {v.position[0], v.position[1] - axis_y, v.position[2]}; - f32 len = ::sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); - CHECK(::abs(len - 0.4f) < 1e-3f); // every point is one radius off the axis + f32 len = ::sqrtf(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); + CHECK(::fabsf(len - 0.4f) < 1e-3f); // every point is one radius off the axis CHECK((d[0] * v.normal[0] + d[1] * v.normal[1] + d[2] * v.normal[2]) / len > 0.999f); } @@ -252,12 +252,12 @@ void TestPrimitives() { // test above cannot express (the inner half faces the axis). asset::Mesh torus = asset::MakeTorus(1.0f, 0.25f, 20, 32, id); for (const asset::Vertex& v : torus.lods[0].vertices) { - f32 radial = ::sqrt(v.position[0] * v.position[0] + v.position[2] * v.position[2]); + f32 radial = ::sqrtf(v.position[0] * v.position[0] + v.position[2] * v.position[2]); f32 scale = radial > 1e-6f ? 1.0f / radial : 0.0f; f32 d[3] = {v.position[0] - v.position[0] * scale, v.position[1], v.position[2] - v.position[2] * scale}; - f32 len = ::sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); - CHECK(::abs(len - 0.25f) < 1e-3f); + f32 len = ::sqrtf(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]); + CHECK(::fabsf(len - 0.25f) < 1e-3f); CHECK((d[0] * v.normal[0] + d[1] * v.normal[1] + d[2] * v.normal[2]) / len > 0.999f); } @@ -276,7 +276,7 @@ void TestPrimitives() { } f32 n[3] = {e1[1] * e2[2] - e1[2] * e2[1], e1[2] * e2[0] - e1[0] * e2[2], e1[0] * e2[1] - e1[1] * e2[0]}; - CHECK(::sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]) > 1e-6f); + CHECK(::sqrtf(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]) > 1e-6f); } } diff --git a/test/procedural_grass_test.cc b/test/procedural_grass_test.cc index 7c9cff53..b4e6601c 100644 --- a/test/procedural_grass_test.cc +++ b/test/procedural_grass_test.cc @@ -16,7 +16,7 @@ void Check(bool condition, const char* message) { } bool Near(rx::f32 a, rx::f32 b) { - return ::fabs(a - b) < 1e-5f; + return ::fabsf(a - b) < 1e-5f; } void SetPoint(rx::f32 point[3], rx::f32 x, rx::f32 y, rx::f32 z) { @@ -69,11 +69,11 @@ int main() { non_finite.fade_end = NAN; non_finite.bend_recovery_time = INFINITY; const GrassGenerationSettings finite = SanitizeGrassSettings(non_finite); - Check(::isfinite(finite.candidate_spacing), "non-finite spacing uses a default"); - Check(::isfinite(finite.stream_radius), "non-finite radius uses a default"); + Check(isfinite(finite.candidate_spacing), "non-finite spacing uses a default"); + Check(isfinite(finite.stream_radius), "non-finite radius uses a default"); Check(finite.fade_end <= finite.stream_radius, "fade completes inside the stream radius"); - Check(::isfinite(finite.bend_recovery_time), + Check(isfinite(finite.bend_recovery_time), "non-finite bend recovery uses a default"); GrassGenerationSettings distant; diff --git a/test/raytracing_test.cc b/test/raytracing_test.cc index d1fe3969..f9d83e20 100644 --- a/test/raytracing_test.cc +++ b/test/raytracing_test.cc @@ -75,12 +75,12 @@ int main() { device->ImmediateSubmit([&](CommandList& cmd) { rt->BuildTlas(cmd, 0, frame, instances); }); }; build(0); - check(::abs(trace(0) - 1.0f) < 1e-5f, "compacted triangle must hit at distance 1"); + check(::fabsf(trace(0) - 1.0f) < 1e-5f, "compacted triangle must hit at distance 1"); check(rt->ReserveTlas(0, 65), "grow built TLAS"); check(!rt->TlasValid(0), "replacement remains invalid until built"); check(trace(0) == -1.0f, "replacement must use fallback before build"); build(1); - check(::abs(trace(0) - 1.0f) < 1e-5f, "grown TLAS must hit after build"); + check(::fabsf(trace(0) - 1.0f) < 1e-5f, "grown TLAS must hit after build"); rt->RemoveBlasDeferred(1); check(trace(0) == -1.0f, "retired BLAS must invalidate TLAS"); build(2); @@ -101,7 +101,7 @@ int main() { cmd.MemoryBarrier(BarrierScope::kAccelBuildWrite, BarrierScope::kAccelBuildWrite); rt->BuildTlas(cmd, 0, 4, instances); }); - check(::abs(trace(0) - 1.0f) < 1e-5f, "built skinned BLAS must hit"); + check(::fabsf(trace(0) - 1.0f) < 1e-5f, "built skinned BLAS must hit"); check(rt->ReserveSkinnedBlas(3, geometry), "reserve refit target"); instances[0].mesh_key = 3; device->ImmediateSubmit([&](CommandList& cmd) { @@ -109,7 +109,7 @@ int main() { cmd.MemoryBarrier(BarrierScope::kAccelBuildWrite, BarrierScope::kAccelBuildWrite); rt->BuildTlas(cmd, 0, 5, instances); }); - check(::abs(trace(0) - 1.0f) < 1e-5f, "refitted BLAS must hit"); + check(::fabsf(trace(0) - 1.0f) < 1e-5f, "refitted BLAS must hit"); rt->RemoveSkinnedBlasDeferred(2); rt->RemoveSkinnedBlasDeferred(3); @@ -141,7 +141,7 @@ int main() { skin.Record(cmd, *rt, bones); rt->BuildTlas(cmd, 0, frame, instances); }); - check(::abs(trace(0) - (z + 1.0f)) < 1e-5f, "ray must hit the current skinned pose"); + check(::fabsf(trace(0) - (z + 1.0f)) < 1e-5f, "ray must hit the current skinned pose"); }; pose(1, 6); check(skin.previous_custom_index(actor) == SkinnedRayTracing::kInvalidIndex, diff --git a/test/rcgi_interior_test.cc b/test/rcgi_interior_test.cc index 645b0aac..d1ba1be6 100644 --- a/test/rcgi_interior_test.cc +++ b/test/rcgi_interior_test.cc @@ -24,7 +24,7 @@ int g_failures = 0; } \ } while (0) -bool Near(f32 a, f32 b, f32 eps) { return ::fabs(a - b) <= eps; } +bool Near(f32 a, f32 b, f32 eps) { return ::fabsf(a - b) <= eps; } } // namespace diff --git a/test/recon_atrous_test.cc b/test/recon_atrous_test.cc index 95129b3b..229103c6 100644 --- a/test/recon_atrous_test.cc +++ b/test/recon_atrous_test.cc @@ -21,7 +21,7 @@ struct Push { }; f32 Half(u16 b) { const int exponent = (b >> 10) & 31; - return ::ldexp(float((b & 1023) + (exponent ? 1024 : 0)), + return ::ldexpf(float((b & 1023) + (exponent ? 1024 : 0)), exponent ? exponent - 25 : -24) * ((b & 0x8000) ? -1.f : 1.f); } } @@ -110,7 +110,7 @@ int main() { mean += value / kPixels; } ::printf("specular mode=%u RMS=%g mean=%g\n", mode, ::sqrt(mse), mean); - const bool ok = finite && (mode == 0 ? ::sqrt(mse) < .14 && ::abs(mean - 1) < .03 : ::sqrt(mse) < .005); + const bool ok = finite && (mode == 0 ? ::sqrt(mse) < .14 && ::fabs(mean - 1) < .03 : ::sqrt(mse) < .005); if (!ok) { ::printf("FAIL: reflection noise reduction / edge preservation\n"); ++failures; } } device->WaitIdle(); diff --git a/test/recon_temporal_test.cc b/test/recon_temporal_test.cc index bc8a6f99..edcab1db 100644 --- a/test/recon_temporal_test.cc +++ b/test/recon_temporal_test.cc @@ -119,8 +119,8 @@ int main() { f32 values[12]{}; check(device->ReadbackImage(moments, ResourceState::kGeneral, values, sizeof(values)), "read back temporal moments"); - for (f32 value : values) check(::isfinite(value), "HDR moments must remain finite"); - check(::abs(values[5] - 1000000.0f) < 1.0f, "squared HDR luminance must not overflow"); + for (f32 value : values) check(isfinite(value), "HDR moments must remain finite"); + check(::fabsf(values[5] - 1000000.0f) < 1.0f, "squared HDR luminance must not overflow"); check(values[7] == 1.0f, "reset or invalid history must seed one frame"); u16 half[12]{}; check(device->ReadbackImage(accum, ResourceState::kGeneral, half, sizeof(half)), diff --git a/test/render2d_test.cc b/test/render2d_test.cc index 5dcb04dc..c32e87c3 100644 --- a/test/render2d_test.cc +++ b/test/render2d_test.cc @@ -20,7 +20,7 @@ void Check(bool condition, const char* message) { } void Near(float actual, float expected, const char* message, float epsilon = 1e-4f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "render2d_test: FAIL: %s (got %.6f, expected %.6f)\n", message, actual, expected); ++failures; @@ -51,7 +51,7 @@ void TestCameraRejectsDegenerateInputs() { const rx::Mat4 view_proj = camera.ViewProj(); Check(camera.viewport().x == 1.0f && camera.viewport().y == 1.0f, "zero viewport is kept invertible"); - Check(::isfinite(view_proj.m[0]) && ::isfinite(view_proj.m[5]), + Check(isfinite(view_proj.m[0]) && isfinite(view_proj.m[5]), "degenerate camera inputs produce a finite matrix"); } diff --git a/test/scene_authoring_test.cc b/test/scene_authoring_test.cc index e2be5424..1da1a968 100644 --- a/test/scene_authoring_test.cc +++ b/test/scene_authoring_test.cc @@ -40,7 +40,7 @@ int failures = 0; } \ } while (0) -#define CHECK_NEAR(a, b, eps) CHECK(::abs((a) - (b)) <= (eps)) +#define CHECK_NEAR(a, b, eps) CHECK(::fabsf((a) - (b)) <= (eps)) namespace fs = rx::fs; @@ -151,7 +151,7 @@ Rotation.euler = 90 90 0 // --validate's non_unit_rotation warns past 5%, and MakeFromQuat does not // normalize, so a euler that did not resolve to a unit quaternion would scale // every mesh it is written to. - const f32 length = ::sqrt(yaw.x * yaw.x + yaw.y * yaw.y + yaw.z * yaw.z + yaw.w * yaw.w); + const f32 length = ::sqrtf(yaw.x * yaw.x + yaw.y * yaw.y + yaw.z * yaw.z + yaw.w * yaw.w); CHECK_NEAR(length, 1.0f, 1e-5f); fs::Remove(path); @@ -244,7 +244,7 @@ Shape.size = 0.5 0.5 0.5 const scene::Transform* upright = world.Get(FindByName(world, "Upright")); CHECK_NEAR(upright->position[1], 1.5f, 1e-4f); const scene::Transform* cornered = world.Get(FindByName(world, "Cornered")); - CHECK_NEAR(cornered->position[1], 1.0f + 0.5f * ::sqrt(2.0f), 1e-4f); + CHECK_NEAR(cornered->position[1], 1.0f + 0.5f * ::sqrtf(2.0f), 1e-4f); // The two axes the mode does not stack along still centre on the target. CHECK_NEAR(cornered->position[0], 0.0f, 1e-4f); CHECK_NEAR(cornered->position[2], 0.0f, 1e-4f); @@ -360,8 +360,8 @@ Shape.size = 0.5 0.5 0.5 // ... and the member's own 45 adds to the container's 90, so its +z face ends // up 135 degrees round. const Vec3 facing = Rotate(WorldRotation(world, FindByName(world, "Second")), {0, 0, 1}); - CHECK_NEAR(facing.x, ::sin(135.0f * 3.14159265f / 180.0f), 1e-4f); - CHECK_NEAR(facing.z, ::cos(135.0f * 3.14159265f / 180.0f), 1e-4f); + CHECK_NEAR(facing.x, ::sinf(135.0f * 3.14159265f / 180.0f), 1e-4f); + CHECK_NEAR(facing.z, ::cosf(135.0f * 3.14159265f / 180.0f), 1e-4f); const Vec3 unrotated = Rotate(WorldRotation(world, FindByName(world, "First")), {0, 0, 1}); CHECK_NEAR(unrotated.x, 1.0f, 1e-4f); @@ -645,7 +645,7 @@ Prefab.path = "rx_stretch_prefab_cell.rxscene" // ... and the facade rides along, which is the other half of "the instance // owns only what it authored". const SceneSurface* surface = world.Get(entity); - CHECK(surface && ::abs(surface->base_color[2] - 0.6f) < 1e-6f); + CHECK(surface && ::fabsf(surface->base_color[2] - 0.6f) < 1e-6f); } // Three proportions of one prefab are three meshes, never a shared one. diff --git a/test/script_test.cc b/test/script_test.cc index a41cf4df..dbbca8ed 100644 --- a/test/script_test.cc +++ b/test/script_test.cc @@ -221,16 +221,16 @@ void TestWorldSpaceDispatch() { rig.world.Add(child, scene::Parent{parent}); V ret = rig.Call("World.GetPosition", {V::EntityRef(child)}); - CHECK(::fabs(ret.as_vec3().x - 10.0f) < 1e-4f); - CHECK(::fabs(ret.as_vec3().y - 2.0f) < 1e-4f); + CHECK(::fabsf(ret.as_vec3().x - 10.0f) < 1e-4f); + CHECK(::fabsf(ret.as_vec3().y - 2.0f) < 1e-4f); rig.Call("World.Teleport", {V::EntityRef(child), V::Vec(Vec3{8, 0, 0})}); scene::Transform* local = rig.world.Get(child); - CHECK(::fabs(local->position[0] - 0.0f) < 1e-4f); - CHECK(::fabs(local->position[1] - 1.0f) < 1e-4f); + CHECK(::fabsf(local->position[0] - 0.0f) < 1e-4f); + CHECK(::fabsf(local->position[1] - 1.0f) < 1e-4f); ret = rig.Call("World.GetPosition", {V::EntityRef(child)}); - CHECK(::fabs(ret.as_vec3().x - 8.0f) < 1e-4f); - CHECK(::fabs(ret.as_vec3().y - 0.0f) < 1e-4f); + CHECK(::fabsf(ret.as_vec3().x - 8.0f) < 1e-4f); + CHECK(::fabsf(ret.as_vec3().y - 0.0f) < 1e-4f); ecs::Entity other = rig.world.Create(); rig.world.Add(other, scene::Transform{{8, 0, 0}}); @@ -246,7 +246,7 @@ void TestWorldSpaceDispatch() { rig.world.Add(tiny_child, scene::Parent{tiny_parent}); rig.Call("World.Teleport", {V::EntityRef(tiny_child), V::Vec(Vec3{1, 0, 0})}); ret = rig.Call("World.GetPosition", {V::EntityRef(tiny_child)}); - CHECK(::fabs(ret.as_vec3().x - 1.0f) < 1e-4f); + CHECK(::fabsf(ret.as_vec3().x - 1.0f) < 1e-4f); // Over-depth hierarchies are rejected consistently: reads report no position // and writes leave the local transform untouched. diff --git a/test/settings_ini_test.cc b/test/settings_ini_test.cc index 02f6dfe2..0066a25c 100644 --- a/test/settings_ini_test.cc +++ b/test/settings_ini_test.cc @@ -37,7 +37,7 @@ int main() { settings.cloud_coverage = 0.5f; Check(rx::render::ApplyIni("cloud_coverage = nan", settings) == 0, "non-finite floats are rejected"); - Check(::isfinite(settings.cloud_coverage) && + Check(isfinite(settings.cloud_coverage) && settings.cloud_coverage == 0.5f, "a rejected float leaves the setting unchanged"); diff --git a/test/terrain_test.cc b/test/terrain_test.cc index 550e2a84..3750878a 100644 --- a/test/terrain_test.cc +++ b/test/terrain_test.cc @@ -35,7 +35,7 @@ void Check(bool condition, const char *message) { } void Near(f32 actual, f32 expected, const char *message, f32 epsilon = 1e-4f) { - if (::abs(actual - expected) <= epsilon) + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "terrain_test: FAIL: %s (got %.6f, expected %.6f)\n", message, actual, expected); @@ -280,7 +280,7 @@ void TestMeshAndRaycast() { "layer debug colors are blended into vertex colors"); Near(mesh->bounds_center[0], 1, "mesh bounds center x is tile-local"); Near(mesh->bounds_center[1], 2, "mesh bounds center includes height range"); - Near(mesh->bounds_radius, ::sqrt(6.0f), + Near(mesh->bounds_radius, ::sqrtf(6.0f), "mesh sphere contains xz and height extents"); } diff --git a/test/thunder_synth_test.cc b/test/thunder_synth_test.cc index 0d837e7c..a2145ea9 100644 --- a/test/thunder_synth_test.cc +++ b/test/thunder_synth_test.cc @@ -52,12 +52,12 @@ void TestFiniteDeterministicStream() { bool finite = true; bool non_silent = false; for (float sample : lhs) { - finite &= ::isfinite(sample) && ::abs(sample) <= 0.951f; - non_silent |= ::abs(sample) > 1e-4f; + finite &= isfinite(sample) && ::fabsf(sample) <= 0.951f; + non_silent |= ::fabsf(sample) > 1e-4f; } Check(finite, "all samples remain finite and bounded"); Check(non_silent, "positive energy produces an audible signal"); - Check(!lhs.empty() && ::abs(lhs.back()) < 1e-4f, + Check(!lhs.empty() && ::fabsf(lhs.back()) < 1e-4f, "the end-of-stream fade reaches silence"); } diff --git a/test/upscaler_motion_test.cc b/test/upscaler_motion_test.cc index 80130ff2..dfff59c3 100644 --- a/test/upscaler_motion_test.cc +++ b/test/upscaler_motion_test.cc @@ -17,12 +17,12 @@ using namespace rx::render; namespace { constexpr u32 kW = 96, kH = 64, kOutW = 192, kOutH = 128; float Pattern(float x, float y, u32 channel) { - if (channel == 0) return .5f + .4f * ::sin(x * 1.1f); - if (channel == 1) return .5f + .4f * ::sin(y * .9f); - return .5f + .3f * ::sin(x * .6f + y * .7f); + if (channel == 0) return .5f + .4f * ::sinf(x * 1.1f); + if (channel == 1) return .5f + .4f * ::sinf(y * .9f); + return .5f + .3f * ::sinf(x * .6f + y * .7f); } float Half(u16 bits) { - return ::ldexp(float((bits & 1023) | 1024), int((bits >> 10) & 31) - 25) * + return ::ldexpf(float((bits & 1023) | 1024), int((bits >> 10) & 31) - 25) * ((bits & 0x8000) ? -1.f : 1.f); } } // namespace @@ -143,5 +143,5 @@ int main() { device->DestroyImage(color); device->DestroyImage(depth); device->DestroyImage(motion); - return positive < negative && moving_correct < moving_wrong && ::abs(resumed - reset) < 1e-6 ? 0 : 1; + return positive < negative && moving_correct < moving_wrong && ::fabs(resumed - reset) < 1e-6 ? 0 : 1; } diff --git a/test/usd_scene_test.cc b/test/usd_scene_test.cc index 7a5bffec..7924e3ee 100644 --- a/test/usd_scene_test.cc +++ b/test/usd_scene_test.cc @@ -188,7 +188,7 @@ bool Write(const base::String &path, const char *text, size_t size) { return ok; } -bool Near(f32 value, f32 expected) { return ::fabs(value - expected) < 1e-4f; } +bool Near(f32 value, f32 expected) { return ::fabsf(value - expected) < 1e-4f; } } // namespace diff --git a/test/vehicle_audio_test.cc b/test/vehicle_audio_test.cc index 82caa675..19367817 100644 --- a/test/vehicle_audio_test.cc +++ b/test/vehicle_audio_test.cc @@ -40,13 +40,13 @@ constexpr u32 kRate = 48000; bool AllFinite(const base::Vector& b) { for (f32 v : b) - if (!::isfinite(v)) return false; + if (!isfinite(v)) return false; return true; } f32 MaxAbs(const base::Vector& b) { f32 m = 0.0f; - for (f32 v : b) m = rx::Max(m, ::fabs(v)); + for (f32 v : b) m = rx::Max(m, ::fabsf(v)); return m; } @@ -58,14 +58,14 @@ f32 Rms(const base::Vector& b) { f32 MaxDelta(const base::Vector& b) { f32 m = 0.0f; - for (size_t i = 1; i < b.size(); ++i) m = rx::Max(m, ::fabs(b[i] - b[i - 1])); + for (size_t i = 1; i < b.size(); ++i) m = rx::Max(m, ::fabsf(b[i] - b[i - 1])); return m; } // One-pole low-pass in place, to isolate the firing fundamental from the noise // bed before counting zero crossings. void LowPass(base::Vector& b, f32 cutoff) { - const f32 a = 1.0f - ::exp(-6.28318531f * cutoff / kRate); + const f32 a = 1.0f - ::expf(-6.28318531f * cutoff / kRate); f32 s = 0.0f; for (f32& v : b) { s += a * (v - s); @@ -276,8 +276,8 @@ void TestMixerIntegration() { for (int i = 0; i < 40; ++i) { mixer.MixInto(out.data(), 1024); for (f32 v : out) { - CHECK(::isfinite(v)); - peak = rx::Max(peak, ::fabs(v)); + CHECK(isfinite(v)); + peak = rx::Max(peak, ::fabsf(v)); } } CHECK(peak > 0.01f); // the vehicle is audible in the mix @@ -361,7 +361,7 @@ void TestSignedThrottleEquivalence() { const base::Vector astern = run(-0.6f); CHECK(ahead.size() == astern.size()); f32 diff = 0.0f; - for (size_t i = 0; i < ahead.size(); ++i) diff = rx::Max(diff, ::fabs(ahead[i] - astern[i])); + for (size_t i = 0; i < ahead.size(); ++i) diff = rx::Max(diff, ::fabsf(ahead[i] - astern[i])); ::fprintf(stderr, "vehicle_audio_test: signed-throttle max diff=%.6g\n", diff); CHECK(Rms(ahead) > 0.005f); // audible (so the equivalence is not trivial silence) CHECK(diff < 1e-6f); // |−0.6| == |+0.6|: bit-for-bit identical @@ -418,13 +418,13 @@ void TestPerWheelSlipPansSkid() { const base::Vector quad = render_side(balanced, 4, 0.0f); f32 diff = 0.0f; for (size_t i = 0; i < rx::Min(agg.size(), quad.size()); ++i) - diff = rx::Max(diff, ::fabs(agg[i] - quad[i])); + diff = rx::Max(diff, ::fabsf(agg[i] - quad[i])); const f32 aL = ChannelRms(agg, 0), aR = ChannelRms(agg, 1); ::fprintf(stderr, "vehicle_audio_test: skid fallback diff=%.6g balanced L=%.4f R=%.4f\n", diff, aL, aR); CHECK(Rms(agg) > 0.005f); // the skid is actually audible CHECK(diff < 1e-6f); // count=0 aggregate == 4 equal wheels - CHECK(::fabs(aL - aR) < 0.1f * (aL + aR)); // balanced slip stays centred + CHECK(::fabsf(aL - aR) < 0.1f * (aL + aR)); // balanced slip stays centred } // (4) A gear shift produces a bounded, click-free level excursion, and nothing at @@ -470,7 +470,7 @@ void TestShiftFlare() { CHECK(up.worst < 0.15f); // ... without a click CHECK(down.flr > down.ref * 1.05f); // downshift audibly blips it up CHECK(down.worst < 0.15f); - CHECK(::fabs(none.flr - none.ref) < none.ref * 0.06f); // flat when idle + CHECK(::fabsf(none.flr - none.ref) < none.ref * 0.06f); // flat when idle // Mapping level: a gear left INT_MIN must yield no flare even as is_shifting // pulses, so the mix is bit-identical to a run that never touches either field. @@ -495,7 +495,7 @@ void TestShiftFlare() { const base::Vector plain = run_gate(false); const base::Vector pulsed = run_gate(true); f32 gate_diff = 0.0f; - for (size_t i = 0; i < plain.size(); ++i) gate_diff = rx::Max(gate_diff, ::fabs(plain[i] - pulsed[i])); + for (size_t i = 0; i < plain.size(); ++i) gate_diff = rx::Max(gate_diff, ::fabsf(plain[i] - pulsed[i])); ::fprintf(stderr, "vehicle_audio_test: shift gate (unknown gear) diff=%.6g\n", gate_diff); CHECK(gate_diff < 1e-6f); // unknown gear -> no flare, nothing changes } @@ -574,7 +574,7 @@ void TestUpdateAfterStopAllIsSafe() { st.slip = 0.5f; va.Update(st); mixer.MixInto(out.data(), 1024); - for (f32 v : out) CHECK(::isfinite(v)); + for (f32 v : out) CHECK(isfinite(v)); } va.Stop(); // idempotent, also safe after the voices are gone } diff --git a/test/vehicle_integration_test.cc b/test/vehicle_integration_test.cc index 281a7942..cbae10d2 100644 --- a/test/vehicle_integration_test.cc +++ b/test/vehicle_integration_test.cc @@ -61,18 +61,18 @@ int Fail(const char* what) { } bool IsFinite(const Vec3& v) { - return ::isfinite(v.x) && ::isfinite(v.y) && ::isfinite(v.z); + return isfinite(v.x) && isfinite(v.y) && isfinite(v.z); } // audio buffer helpers (mirror vehicle_audio_test) bool AllFinite(const base::Vector& b) { for (f32 v : b) - if (!::isfinite(v)) return false; + if (!isfinite(v)) return false; return true; } f32 MaxAbs(const base::Vector& b) { f32 m = 0.0f; - for (f32 v : b) m = rx::Max(m, ::fabs(v)); + for (f32 v : b) m = rx::Max(m, ::fabsf(v)); return m; } // RMS over the half-open sample window [lo, hi). @@ -181,7 +181,7 @@ int main() { // (a) Car: idle briefly, then full throttle with a mild weave. const f32 car_throttle = frame < kIdleEnd ? 0.0f : 1.0f; - const f32 car_steer = frame < kIdleEnd ? 0.0f : 0.25f * ::sin(frame * 0.02f); + const f32 car_steer = frame < kIdleEnd ? 0.0f : 0.25f * ::sinf(frame * 0.02f); world.DriveVehicle(car, car_throttle, car_steer, 0.0f, 0.0f); // (b) Boat: straight-ahead throttle across the chop. @@ -222,12 +222,12 @@ int main() { if (!ast.on_ground) plane_peak_climb = rx::Max(plane_peak_climb, ast.vertical_speed_mps); // Per-frame NaN gate: three simulators must never poison the shared world. - if (!::isfinite(car_speed) || !::isfinite(cst.rpm)) return Fail("(a) car NaN in telemetry"); - if (!IsFinite(bst.position) || !::isfinite(bst.rpm) || !::isfinite(bst.forward_speed) || - !::isfinite(bst.rotation.w)) + if (!isfinite(car_speed) || !isfinite(cst.rpm)) return Fail("(a) car NaN in telemetry"); + if (!IsFinite(bst.position) || !isfinite(bst.rpm) || !isfinite(bst.forward_speed) || + !isfinite(bst.rotation.w)) return Fail("(b) boat NaN in telemetry"); - if (!IsFinite(ast.position) || !::isfinite(ast.airspeed_mps) || - !::isfinite(ast.vertical_speed_mps) || !::isfinite(ast.rotation.w)) + if (!IsFinite(ast.position) || !isfinite(ast.airspeed_mps) || + !isfinite(ast.vertical_speed_mps) || !isfinite(ast.rotation.w)) return Fail("(c) aircraft NaN in telemetry"); // (d) Telemetry -> SynthParams -> one rendered block per vehicle. @@ -235,7 +235,7 @@ int main() { cp.rpm = cst.rpm; cp.load = cst.engine_load; cp.throttle = car_throttle; - cp.speed_mps = ::fabs(car_speed); + cp.speed_mps = ::fabsf(car_speed); cp.slip = car_slip; car_synth.Render(&car_audio[static_cast(frame) * kBlock], kBlock, cp); @@ -260,7 +260,7 @@ int main() { f32 rot[4]; world.GetVehicleTransform(car, &pos, rot); const f32 dx = pos.x - car_start.x, dz = pos.z - car_start.z; - const f32 travelled = ::sqrt(dx * dx + dz * dz); + const f32 travelled = ::sqrtf(dx * dx + dz * dz); ::fprintf(stderr, "(a) car: travelled=%.1f m max_speed=%.1f m/s max_gear=%d\n", travelled, car_max_speed, car_max_gear); if (travelled < 20.0f) return Fail("(a) car did not drive"); @@ -316,7 +316,7 @@ int main() { for (u32 w = 0; w < cst.wheel_count; ++w) car_grounded |= cst.wheels[w].contact; if (!IsFinite(cpos)) return Fail("(e) car position NaN"); if (!car_grounded) return Fail("(e) car left the ground"); - if (::fabs(cpos.y) > 5.0f) return Fail("(e) car position drifted off the surface"); + if (::fabsf(cpos.y) > 5.0f) return Fail("(e) car position drifted off the surface"); if (!IsFinite(bfin.position)) return Fail("(e) boat position NaN"); if (boat_max_wetted <= 0.0f) return Fail("(e) boat never touched the water"); diff --git a/test/vehicle_test.cc b/test/vehicle_test.cc index 9643373f..3feb529a 100644 --- a/test/vehicle_test.cc +++ b/test/vehicle_test.cc @@ -61,7 +61,7 @@ VehicleId SpawnSettledCar(PhysicsWorld& world, const PhysicsWorld::VehicleDesc& f32 HorizontalDistance(const Vec3& a, const Vec3& b) { const f32 dx = a.x - b.x; const f32 dz = a.z - b.z; - return ::sqrt(dx * dx + dz * dz); + return ::sqrtf(dx * dx + dz * dz); } // Full-throttle until the car reaches `target` m/s or `max_steps` elapse. @@ -86,7 +86,7 @@ f32 BrakeToStop(PhysicsWorld& world, VehicleId id, int max_steps) { world.DriveVehicle(id, 0.0f, 0.0f, 1.0f, 0.0f); world.Update(kDt); world.GetVehicleTransform(id, &last, rot); - if (::fabs(world.VehicleForwardSpeed(id)) < 0.5f) break; + if (::fabsf(world.VehicleForwardSpeed(id)) < 0.5f) break; } return HorizontalDistance(start, last); } @@ -243,7 +243,7 @@ int main() { world.Update(kDt); Vec3 pos; world.GetVehicleTransform(car, &pos, rot); - peak = rx::Max(peak, ::fabs(pos.x - start.x)); + peak = rx::Max(peak, ::fabsf(pos.x - start.x)); } return peak; }; @@ -306,7 +306,7 @@ int main() { const f32 self_driven = world.VehicleForwardSpeed(trailer); ::fprintf(stderr, "(h) free-rolling self-driven speed after 3 s throttle=%.3f m/s\n", self_driven); - if (::fabs(self_driven) > 1.0f) return Fail("(h) free-rolling vehicle drove itself"); + if (::fabsf(self_driven) > 1.0f) return Fail("(h) free-rolling vehicle drove itself"); // (3) Tow it: a steady forward (+Z) force on the chassis body makes it roll. const physics::BodyId body = world.GetVehicleBody(trailer); @@ -327,7 +327,7 @@ int main() { Vec3 p0{}; f32 r0[4]; world.GetVehicleTransform(trailer, &p0, r0); - const f32 start_heading = ::atan2(Rotate(Quat{r0[0], r0[1], r0[2], r0[3]}, Vec3{0, 0, 1}).x, + const f32 start_heading = ::atan2f(Rotate(Quat{r0[0], r0[1], r0[2], r0[3]}, Vec3{0, 0, 1}).x, Rotate(Quat{r0[0], r0[1], r0[2], r0[3]}, Vec3{0, 0, 1}).z); for (int i = 0; i < 60 * 3; ++i) { Vec3 pos{}; @@ -341,13 +341,13 @@ int main() { f32 r1[4]; world.GetVehicleTransform(trailer, &p1, r1); const Vec3 fdir = Rotate(Quat{r1[0], r1[1], r1[2], r1[3]}, Vec3{0, 0, 1}); - const f32 end_heading = ::atan2(fdir.x, fdir.z); + const f32 end_heading = ::atan2f(fdir.x, fdir.z); f32 dh = end_heading - start_heading; while (dh > 3.14159265f) dh -= 6.2831853f; while (dh < -3.14159265f) dh += 6.2831853f; ::fprintf(stderr, "(h) free-rolling heading change while steering=%.1f deg\n", dh * 57.2958f); - if (::fabs(dh) < 0.05f) return Fail("(h) free-rolling front axle did not steer"); + if (::fabsf(dh) < 0.05f) return Fail("(h) free-rolling front axle did not steer"); } // (i) Manual transmission routes through traction control: on ice, TC-on holds @@ -370,12 +370,12 @@ int main() { world.Update(kDt); // Only sample once rolling: TC (like a real system) is disengaged at // launch, where the slip-ratio denominator makes the reading meaningless. - if (::fabs(world.VehicleForwardSpeed(car)) < 5.0f) continue; + if (::fabsf(world.VehicleForwardSpeed(car)) < 5.0f) continue; PhysicsWorld::VehicleState st; if (!world.GetVehicleState(car, &st)) continue; f32 peak = 0; for (u32 w = 0; w < st.wheel_count; ++w) - peak = rx::Max(peak, ::fabs(st.wheels[w].longitudinal_slip)); + peak = rx::Max(peak, ::fabsf(st.wheels[w].longitudinal_slip)); slip_sum += peak; ++slip_n; } diff --git a/test/walk_style_test.cc b/test/walk_style_test.cc index 3ce67853..38af0fc8 100644 --- a/test/walk_style_test.cc +++ b/test/walk_style_test.cc @@ -21,7 +21,7 @@ void Check(bool condition, const char *message) { } f32 RotationDelta(const Quat &a, const Quat &b) { - const f32 dot = ::fabs(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); + const f32 dot = ::fabsf(a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w); return 1.0f - rx::Min(dot, 1.0f); } @@ -102,8 +102,8 @@ void TestGenesisAliases() { march_pose.rotation[hip]) * 2.0f, "Genesis aliases receive stronger Hip Sway pelvis rotation"); - Check(::fabs(sway_pose.translation[hip].x) > - ::fabs(march_pose.translation[hip].x) * 4.0f, + Check(::fabsf(sway_pose.translation[hip].x) > + ::fabsf(march_pose.translation[hip].x) * 4.0f, "Genesis hip receives stronger Hip Sway lateral travel"); Check(RotationDelta(skeleton.bones[thigh].bind_rotation, march_pose.rotation[thigh]) > @@ -122,7 +122,7 @@ void TestGenesisAliases() { "styled Genesis pose produces a complete model palette"); for (const Mat4 &matrix : matrices) for (f32 value : matrix.m) - Check(::isfinite(value), "styled pose matrices stay finite"); + Check(isfinite(value), "styled pose matrices stay finite"); } } // namespace diff --git a/test/weather_test.cc b/test/weather_test.cc index d1d9be5e..2ddad833 100644 --- a/test/weather_test.cc +++ b/test/weather_test.cc @@ -25,7 +25,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-3f) { - if (::fabs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "weather_test: FAIL: %s (got %.4f, expected %.4f)\n", message, actual, expected); ++failures; @@ -94,7 +94,7 @@ void TestDeterministic() { lhs.Update(0.5f, Vec3{0, 0, 0}, 0.5f); rhs.Update(0.5f, Vec3{0, 0, 0}, 0.5f); if (lhs.active_state() != rhs.active_state() || lhs.target_state() != rhs.target_state() || - ::fabs(lhs.transition() - rhs.transition()) > 1e-6f) { + ::fabsf(lhs.transition() - rhs.transition()) > 1e-6f) { identical = false; } if (lhs.active_state() != last) saw_change = true; @@ -254,7 +254,7 @@ void TestWindYawWrap() { sys.ForceState(0, 0.0f); sys.ForceState(1, 4.0f); sys.Update(2.0f, Vec3{0, 0, 0}, 0.5f); - Check(::fabs(sys.cloudscape().wind_yaw) > 3.0f, + Check(::fabsf(sys.cloudscape().wind_yaw) > 3.0f, "wind yaw crosses the wrap without reversing through zero"); } @@ -433,7 +433,7 @@ void TestHugeDeltaTimeIsBounded() { sys.AddState(Clear(1)); sys.ForceState(0, 0.0f); sys.Update(FLT_MAX, Vec3{0, 0, 0}, 0.5f); - Check(::isfinite(sys.cloudscape().map_offset.x), + Check(isfinite(sys.cloudscape().map_offset.x), "a huge finite delta is bounded and returns finite output"); } @@ -452,7 +452,7 @@ void TestStateValidation() { sys.ForceState(0, 0.0f); sys.Update(0.0f, Vec3{0, 0, 0}, 0.5f); const render::CloudscapeControls& controls = sys.cloudscape(); - Check(::isfinite(controls.map_a.coverage) && controls.map_a.coverage == 0.0f, + Check(isfinite(controls.map_a.coverage) && controls.map_a.coverage == 0.0f, "non-finite state controls are sanitized at registration"); Check(controls.density == 0.0f, "negative density is clamped"); Check(controls.top > controls.bottom, "cloud shell keeps a positive thickness"); @@ -532,7 +532,7 @@ void TestLightning() { if (w.strike_age >= 0.0f) { struck = true; f32 dx = w.strike_pos.x - player.x, dz = w.strike_pos.z - player.z; - f32 d = ::sqrt(dx * dx + dz * dz); + f32 d = ::sqrtf(dx * dx + dz * dz); if (d < 90.0f || d > 320.0f) in_range = false; } if (w.lightning > 0.0f) flashed = true; diff --git a/test/world_streaming_test.cc b/test/world_streaming_test.cc index 86758075..bc4e02b4 100644 --- a/test/world_streaming_test.cc +++ b/test/world_streaming_test.cc @@ -25,7 +25,7 @@ void Check(bool condition, const char* message) { } void Near(f32 actual, f32 expected, const char* message, f32 epsilon = 1e-4f) { - if (::abs(actual - expected) <= epsilon) return; + if (::fabsf(actual - expected) <= epsilon) return; ::fprintf(stderr, "world_streaming_test: FAIL: %s (got %.6f, expected %.6f)\n", message, actual, expected); ++failures; @@ -138,12 +138,12 @@ void TestDemandAndQueries() { observer.prediction_seconds = maximum; observer.maximum_prediction_distance = maximum; query = BuildWorldStreamQuery(observer); - Check(::isfinite(query.predicted.x), "large finite prediction remains finite"); + Check(isfinite(query.predicted.x), "large finite prediction remains finite"); demand = EvaluateWorldStreamDemand(observer, Region(3, -maximum, 0, -maximum, 1)); Check(!demand.load, "overflow-scale distances do not spuriously load a region"); const f32 large = 1.0e30f; - const f32 adjacent = ::nextafter(large, maximum); + const f32 adjacent = ::nextafterf(large, maximum); observer = Observer({large, 0, 0}, 0, 0); observer.velocity = {adjacent - large, 0, 0}; observer.prediction_seconds = 1; @@ -262,7 +262,7 @@ void TestBudgetsPriorityAndFairness() { WorldStreamPlan large_distance; const f32 farther = 1.0e30f; - const f32 nearer = ::nextafter(farther, 0.0f); + const f32 nearer = ::nextafterf(farther, 0.0f); const WorldStreamObservation maximum_range = Observer({0, 0, 0}, FLT_MAX, FLT_MAX); const WorldStreamRegion distant[] = {Region(1, farther, 0, farther, 1), diff --git a/tools/rxdiff.cc b/tools/rxdiff.cc index d8e84f13..be2cdcc7 100644 --- a/tools/rxdiff.cc +++ b/tools/rxdiff.cc @@ -97,7 +97,7 @@ Result Compare(const Image& a, const Image& b, float hot_delta, (static_cast(a.pixels[base + c]) - static_cast(b.pixels[base + c])) / 255.0f; sum_squares += static_cast(delta) * delta; - const float magnitude = ::fabs(delta); + const float magnitude = ::fabsf(delta); if (magnitude > worst) worst = magnitude; // Amplified so a difference the eye cannot find in the source frames is // obvious in the diff; saturating is the point, not a defect. From 9d0ccc4473b71e8317e709e82567210cfe671a16 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sat, 26 Sep 2026 23:48:47 +0200 Subject: [PATCH 2/7] fix(build): keep rx compiling on Windows --- cmake/mingw-shims/WinSock2.h | 3 +++ engine/core/window_sdl3.cc | 6 +++--- engine/http/tcp_stream.cc | 12 +++++++++++- engine/render/gi/path_tracer.cc | 4 ++-- engine/world/world_map.cc | 4 ++-- engine/world/world_stream.cc | 8 ++++---- engine/world/world_stream.h | 3 ++- 7 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 cmake/mingw-shims/WinSock2.h diff --git a/cmake/mingw-shims/WinSock2.h b/cmake/mingw-shims/WinSock2.h new file mode 100644 index 00000000..755b91b9 --- /dev/null +++ b/cmake/mingw-shims/WinSock2.h @@ -0,0 +1,3 @@ +// Case shim for the mingw cross build: zetanet includes , mingw +// ships lowercase on a case-sensitive fs. +#include diff --git a/engine/core/window_sdl3.cc b/engine/core/window_sdl3.cc index 6dbe5cf7..ccd5fa92 100644 --- a/engine/core/window_sdl3.cc +++ b/engine/core/window_sdl3.cc @@ -3,13 +3,13 @@ #include -#include "core/log.h" -#include "core/window.h" -#if defined(RX_HAS_WAYLAND_KDE_HDR) #include "base/containers/vector.h" #include "base/memory/mem_ops.h" #include "base/memory/unique_pointer.h" +#include "core/log.h" #include "core/scalar.h" +#include "core/window.h" +#if defined(RX_HAS_WAYLAND_KDE_HDR) #include "core/wayland_kde_hdr.h" #endif diff --git a/engine/http/tcp_stream.cc b/engine/http/tcp_stream.cc index 4ae588a1..660ffa0e 100644 --- a/engine/http/tcp_stream.cc +++ b/engine/http/tcp_stream.cc @@ -31,6 +31,16 @@ i64 StreamLimits::remaining_ms() const { namespace { +// The resolver's message for a getaddrinfo error. Under UNICODE, which Windows +// builds define, gai_strerror is the wide-character variant. +const char* ResolveErrorText(int rc) { +#if defined(_WIN32) + return ::gai_strerrorA(rc); +#else + return ::gai_strerror(rc); +#endif +} + #ifdef _WIN32 using SocketHandle = SOCKET; using SockLen = int; @@ -188,7 +198,7 @@ class TcpStream final : public Stream { if (rc != 0 || resolved == nullptr) { char buffer[256] = {}; ::snprintf(buffer, sizeof(buffer), "cannot resolve %s: %s", host.c_str(), - rc != 0 ? ::gai_strerror(rc) : "the resolver returned no addresses"); + rc != 0 ? ResolveErrorText(rc) : "the resolver returned no addresses"); *error = base::String(buffer); if (resolved != nullptr) ::freeaddrinfo(resolved); diff --git a/engine/render/gi/path_tracer.cc b/engine/render/gi/path_tracer.cc index eaaa0704..61301c64 100644 --- a/engine/render/gi/path_tracer.cc +++ b/engine/render/gi/path_tracer.cc @@ -2,13 +2,13 @@ #include +#include "base/memory/mem_ops.h" +#include "base/numeric_limits.h" #include "core/log.h" #include "render/gi/raytracing.h" #include "render/rhi/device.h" #include "shaders/pathtrace_cs_hlsl.h" #if defined(RX_HAS_NRD) -#include "base/memory/mem_ops.h" -#include "base/numeric_limits.h" #include "shaders/pathtrace_composite_cs_hlsl.h" #include "shaders/pathtrace_gbuffer_cs_hlsl.h" #endif diff --git a/engine/world/world_map.cc b/engine/world/world_map.cc index 15acefe1..4cefecc6 100644 --- a/engine/world/world_map.cc +++ b/engine/world/world_map.cc @@ -210,8 +210,8 @@ Tier ResolveTier(const WorldIndexData& index, const WorldCellRecord& cell, Domai Tier TargetTier(const WorldIndexData& index, const WorldCellRecord& cell, Domain domain, const DomainStreamPolicy& policy, f32 distance) { - const bool near = InNearTierBand(policy, distance, /*currently_near=*/false); - return ResolveTier(index, cell, domain, near ? policy.near_tier : policy.far_tier); + const bool in_near_band = InNearTierBand(policy, distance, /*currently_near=*/false); + return ResolveTier(index, cell, domain, in_near_band ? policy.near_tier : policy.far_tier); } } // namespace rx::world diff --git a/engine/world/world_stream.cc b/engine/world/world_stream.cc index 49df7b1b..ef095b52 100644 --- a/engine/world/world_stream.cc +++ b/engine/world/world_stream.cc @@ -638,12 +638,12 @@ void WorldStreamer::MergeCandidates(Domain domain, DomainState& state) { state.bands.begin(), state.bands.end(), id, [](const CellBand& entry, u64 wanted) { return entry.cell < wanted; }); const bool was_near = - previous != state.bands.end() && previous->cell == id && previous->near; - const bool near = InNearTierBand(domain_policy, band_distance, was_near); + previous != state.bands.end() && previous->cell == id && previous->near_tier; + const bool in_near_band = InNearTierBand(domain_policy, band_distance, was_near); const Tier tier = ResolveTier(map_.index(), *record, domain, - near ? domain_policy.near_tier : domain_policy.far_tier); + in_near_band ? domain_policy.near_tier : domain_policy.far_tier); if (tier == Tier::kAbsent) continue; - state.bands_scratch.push_back({id, near}); + state.bands_scratch.push_back({id, in_near_band}); scene::WorldStreamRegion region = nearest.region; // A world baked at one tier resolves both bands to the same payload, so its diff --git a/engine/world/world_stream.h b/engine/world/world_stream.h index 6611d211..b58ad51f 100644 --- a/engine/world/world_stream.h +++ b/engine/world/world_stream.h @@ -278,7 +278,8 @@ class RX_WORLD_EXPORT WorldStreamer { // other. struct CellBand { u64 cell = 0; - bool near = false; + // Not "near": defines near (and far) as empty macros. + bool near_tier = false; }; // A cell whose payload failed to load. Cook errors are deterministic, so From 0c239f0dbfee1d35b2d4bc06b0f5ee1785d594e8 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sat, 26 Sep 2026 23:54:24 +0200 Subject: [PATCH 3/7] Bump equilibrium for the Windows header fixes --- third_party/equilibrium | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/equilibrium b/third_party/equilibrium index bdb537f3..07595176 160000 --- a/third_party/equilibrium +++ b/third_party/equilibrium @@ -1 +1 @@ -Subproject commit bdb537f39fa1b37155850c9f7dcf980453b7faff +Subproject commit 075951762de11cd8736428627164a91f1b569c02 From 6ae184a99069af3a600949c348401919df44e7d1 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sun, 27 Sep 2026 00:10:22 +0200 Subject: [PATCH 4/7] fix(script): drop constexpr the string view and hash cannot honour --- engine/script/script_string.h | 10 +++++----- third_party/equilibrium | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/script/script_string.h b/engine/script/script_string.h index fa94288b..646d39bf 100644 --- a/engine/script/script_string.h +++ b/engine/script/script_string.h @@ -42,8 +42,8 @@ struct ScriptStringView { size = static_cast(s.size()); } - constexpr base::StringRef view() const { return {data, size}; } - constexpr operator base::StringRef() const { return view(); } // NOLINT + base::StringRef view() const { return {data, size}; } + operator base::StringRef() const { return view(); } // NOLINT bool empty() const { return size == 0; } }; static_assert(sizeof(ScriptStringView) == 16, "ABI-boundary layout must stay fixed"); @@ -82,11 +82,11 @@ class ScriptString { // Interned identifier hash for handler/category names. Names are compile-time // tokens, not content, so dispatch keys on this 64-bit hash rather than dragging -// a string type onto the hot path. FNV-1a, constexpr so a runtime can hash a -// name once and dispatch by id. +// a string type onto the hot path. FNV-1a, so a runtime can hash a name once +// and dispatch by id. enum class StrId : u64 {}; -constexpr StrId HashStr(base::StringRef s) { +inline StrId HashStr(base::StringRef s) { return static_cast(Fnv1a(s)); } diff --git a/third_party/equilibrium b/third_party/equilibrium index 07595176..ae2e5e60 160000 --- a/third_party/equilibrium +++ b/third_party/equilibrium @@ -1 +1 @@ -Subproject commit 075951762de11cd8736428627164a91f1b569c02 +Subproject commit ae2e5e6089e1618a6cb13fdefea0a2a1f1f4f192 From e65cdc299e61c894e7fdd8063dd22d31e6deb964 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sun, 27 Sep 2026 00:23:00 +0200 Subject: [PATCH 5/7] fix(asset): order AssetId without --- engine/asset/asset_id.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/asset/asset_id.h b/engine/asset/asset_id.h index 5634a63f..b67af1c3 100644 --- a/engine/asset/asset_id.h +++ b/engine/asset/asset_id.h @@ -26,7 +26,11 @@ struct AssetId { u64 hash = 0; bool operator==(const AssetId&) const = default; - auto operator<=>(const AssetId&) const = default; + // Spelled out rather than a defaulted <=>, which needs . + bool operator<(const AssetId& o) const { return hash < o.hash; } + bool operator<=(const AssetId& o) const { return hash <= o.hash; } + bool operator>(const AssetId& o) const { return hash > o.hash; } + bool operator>=(const AssetId& o) const { return hash >= o.hash; } explicit operator bool() const { return hash != 0; } }; From 5dcd614325c9f2473c2719b64ccbe2dadde2aa00 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sun, 27 Sep 2026 00:36:13 +0200 Subject: [PATCH 6/7] fix(script): take a base::String directly in ScriptStringView --- engine/script/script_string.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engine/script/script_string.h b/engine/script/script_string.h index 646d39bf..27135e52 100644 --- a/engine/script/script_string.h +++ b/engine/script/script_string.h @@ -41,6 +41,10 @@ struct ScriptStringView { BASE_FATAL_CHECK(s.size() <= base::MinMax::max(), "script string longer than u32"); size = static_cast(s.size()); } + // A base::String reaches base::StringRef through two viable constructor + // templates there; MSVC calls that ambiguous, so take it directly. + ScriptStringView(const base::String& s) // NOLINT(google-explicit-constructor) + : ScriptStringView(base::StringRef(s.data(), s.size(), /*is_null_terminated=*/true)) {} base::StringRef view() const { return {data, size}; } operator base::StringRef() const { return view(); } // NOLINT From b18025e25b0db9fbdaac0f34ad65e4271e98e408 Mon Sep 17 00:00:00 2001 From: Vincent Hengel Date: Sun, 27 Sep 2026 00:47:49 +0200 Subject: [PATCH 7/7] Bump equilibrium to devel5 --- third_party/equilibrium | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/equilibrium b/third_party/equilibrium index ae2e5e60..d489251b 160000 --- a/third_party/equilibrium +++ b/third_party/equilibrium @@ -1 +1 @@ -Subproject commit ae2e5e6089e1618a6cb13fdefea0a2a1f1f4f192 +Subproject commit d489251bebcbed1c35e2edc231ecbac2f51e6313