From fb1643e6e62b5ac63fcd0993aa6694d39e985cc6 Mon Sep 17 00:00:00 2001 From: sergeypdev Date: Sun, 16 Mar 2025 00:17:00 +0400 Subject: [PATCH] Fix mem leak, change number of stacks --- game/game.odin | 17 ++++++++++------- game/physics/simulation.odin | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/game/game.odin b/game/game.odin index c0c5f17..9b6418f 100644 --- a/game/game.odin +++ b/game/game.odin @@ -277,8 +277,8 @@ update_runtime_world :: proc(runtime_world: ^Runtime_World, dt: f32) { ) if true { - for x in 0 ..< 5 { - for y in 0 ..< 20 { + for x in 0 ..< 10 { + for y in 0 ..< 10 { physics.immediate_body( &world.physics_scene, &runtime_world.solver_state, @@ -320,8 +320,8 @@ update_runtime_world :: proc(runtime_world: ^Runtime_World, dt: f32) { wheel_extent_x := f32(1.7) wheel_y := f32(-0.5) rest := f32(1) - natural_frequency := f32(0.2) - damping := f32(0.12) + natural_frequency := f32(0.3) + damping := f32(0.08) radius := f32(0.6) wheel_front_z := f32(3.05) wheel_back_z := f32(-2.45) @@ -388,7 +388,7 @@ update_runtime_world :: proc(runtime_world: ^Runtime_World, dt: f32) { DRIVE_IMPULSE :: 10000 BRAKE_IMPULSE :: 10000 - TURN_ANGLE :: -f32(30) * math.RAD_PER_DEG + TURN_ANGLE :: -f32(20) * math.RAD_PER_DEG for wheel_handle in drive_wheels { wheel := physics.get_suspension_constraint(sim_state, wheel_handle) @@ -405,16 +405,19 @@ update_runtime_world :: proc(runtime_world: ^Runtime_World, dt: f32) { } } + car_body := physics.get_body(sim_state, runtime_world.car_handle) + turn_vel_correction := clamp(30.0 / linalg.length(car_body.v), 0, 1) + for wheel_handle in turn_wheels { wheel := physics.get_suspension_constraint(sim_state, wheel_handle) wheel.turn_angle = 0 if rl.IsKeyDown(.A) && !g_mem.free_cam { - wheel.turn_angle += -TURN_ANGLE + wheel.turn_angle += -TURN_ANGLE * turn_vel_correction } if rl.IsKeyDown(.D) && !g_mem.free_cam { - wheel.turn_angle += TURN_ANGLE + wheel.turn_angle += TURN_ANGLE * turn_vel_correction } } diff --git a/game/physics/simulation.odin b/game/physics/simulation.odin index 6365179..6fff0bb 100644 --- a/game/physics/simulation.odin +++ b/game/physics/simulation.odin @@ -357,7 +357,7 @@ pgs_solve_contacts :: proc( impulse_coef = 0 } - random_order := make([]i32, len(sim_state.contact_container.contacts)) + random_order := make([]i32, len(sim_state.contact_container.contacts), context.temp_allocator) { for i in 0 ..< len(random_order) { random_order[i] = i32(i) @@ -522,7 +522,7 @@ pgs_solve_suspension :: proc(sim_state: ^Sim_State, config: Solver_Config, dt: f lateral_vel := lg.dot(right, vel_contact) - friction := f32(0.8) + friction := f32(1) friction_clamp := -v.spring_impulse * friction incremental_impulse := -inv_w * lateral_vel