ronantakizawa/codereview-bench huggingface dataset:
Repository: godotengine/godot
File: scene/main/viewport.cpp (C++)

Code before:
	return canvas_cull_mask;
}

void Viewport::set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable) {
	ERR_MAIN_THREAD_GUARD;
	ERR_FAIL_UNSIGNED_INDEX(p_layer, 32);
	if (p_enable) {
		set_canvas_cull_mask(canvas_cull_mask | (1 << p_layer));
	} else {
		set_canvas_cull_mask(canvas_cull_mask & (~(1 << p_layer)));
	}
}

bool Viewport::get_canvas_cull_mask_bit(uint32_t p_layer) const {
	ERR_READ_THREAD_GUARD_V(false);
	ERR_FAIL_UNSIGNED_INDEX_V(p_layer, 32, false);
	return (canvas_cull_mask & (1 << p_layer));
}

void Viewport::_update_audio_listener_2d() {
	if (AudioServer::get_singleton()) {
		AudioServer::get_singleton()->notify_listener_changed();
	}
}

void Viewport::_audio_listener_2d_set(AudioListener2D *p_audio_listener) {
	if (audio_listener_2d == p_audio_listener) {
		return;
	} else if (audio_listener_2d) {
		audio_listener_2d->clear_current();
	}
	audio_listener_2d = p_audio_listener;
}

void Viewport::_audio_listener_2d_remove(AudioListener2D *p_audio_listener) {
	if (audio_listener_2d == p_audio_listener) {
		audio_listener_2d = nullptr;
	}
}

void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
	camera_2d = p_camera_2d;
}

void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) {
	List<ObjectID> to_erase;
	List<ObjectID> to_mouse_exit;

	for (const KeyValue<ObjectID, uint64_t> &E : physics_2d_mouseover) {
		if (!p_clean_all_frames && E.value == p_frame_reference) {
			continue;

Review comment (suggestion):
```suggestion
```

The code below performs exactly the same check and the code below is necessary because of the cast. So this call to `is_attached_in_viewport()` can be removed.

Code after:
	return canvas_cull_mask;
}

void Viewport::set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable) {
	ERR_MAIN_THREAD_GUARD;
	ERR_FAIL_UNSIGNED_INDEX(p_layer, 32);
	if (p_enable) {
		set_canvas_cull_mask(canvas_cull_mask | (1 << p_layer));
	} else {
		set_canvas_cull_mask(canvas_cull_mask & (~(1 << p_layer)));
	}
}

bool Viewport::get_canvas_cull_mask_bit(uint32_t p_layer) const {
	ERR_READ_THREAD_GUARD_V(false);
	ERR_FAIL_UNSIGNED_INDEX_V(p_layer, 32, false);
	return (canvas_cull_mask & (1 << p_layer));
}

#ifdef TOOLS_ENABLED
bool Viewport::is_visible_subviewport() const {
	if (!is_sub_viewport()) {
		return true;
	}
	SubViewportContainer *container = Object::cast_to<SubViewportContainer>(get_parent());
	return container && container->is_visible_in_tree();
}
#endif // TOOLS_ENABLED

void Viewport::_update_audio_listener_2d() {
	if (AudioServer::get_singleton()) {
		AudioServer::get_singleton()->notify_listener_changed();
	}
}

void Viewport::_audio_listener_2d_set(AudioListener2D *p_audio_listener) {
	if (audio_listener_2d == p_audio_listener) {
		return;
	} else if (audio_listener_2d) {
		audio_listener_2d->clear_current();
	}
	audio_listener_2d = p_audio_listener;
}

void Viewport::_audio_listener_2d_remove(AudioListener2D *p_audio_listener) {
	if (audio_listener_2d == p_audio_listener) {
		audio_listener_2d = nullptr;
	}
}

void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
Repository: godotengine/godot
File: scene/gui/view_panner.h (C/C++)

Code before:
public:
	enum ControlScheme {
		SCROLL_ZOOMS,
		SCROLL_PANS,
	};

	enum PanAxis {
		PAN_AXIS_BOTH,
		PAN_AXIS_HORIZONTAL,
		PAN_AXIS_VERTICAL,
	};

private:
	int scroll_speed = 32;
	float scroll_zoom_factor = 1.1;
	PanAxis pan_axis = PAN_AXIS_BOTH;

	bool is_dragging = false;
	bool pan_key_pressed = false;
	bool force_drag = false;

	bool enable_rmb = false;
	bool simple_panning_enabled = false;

	Ref<Shortcut> pan_view_shortcut;

	Callable pan_callback;
	Callable zoom_callback;

	ControlScheme control_scheme = SCROLL_ZOOMS;

public:
	void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback);
	void set_control_scheme(ControlScheme p_scheme);
	void set_enable_rmb(bool p_enable);
	void set_pan_shortcut(Ref<Shortcut> p_shortcut);
	void set_simple_panning_enabled(bool p_enabled);
	void set_scroll_speed(int p_scroll_speed);
	void set_scroll_zoom_factor(float p_scroll_zoom_factor);
	void set_pan_axis(PanAxis p_pan_axis);

	void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);

	bool is_panning() const;
	void set_force_drag(bool p_force);

	bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2());
	void release_pan_key();

	ViewPanner();
};

Review comment (bug):
```suggestion
	Viewport *viewport = nullptr;
```

Code after:

public:
	enum ControlScheme {
		SCROLL_ZOOMS,
		SCROLL_PANS,
	};

	enum PanAxis {
		PAN_AXIS_BOTH,
		PAN_AXIS_HORIZONTAL,
		PAN_AXIS_VERTICAL,
	};

private:
	int scroll_speed = 32;
	float scroll_zoom_factor = 1.1;
	PanAxis pan_axis = PAN_AXIS_BOTH;

	bool is_dragging = false;
	bool pan_key_pressed = false;
	bool force_drag = false;

	bool enable_rmb = false;
	bool simple_panning_enabled = false;

	Viewport *viewport = nullptr;

	Ref<Shortcut> pan_view_shortcut;

	Callable pan_callback;
	Callable zoom_callback;

	ControlScheme control_scheme = SCROLL_ZOOMS;

public:
	void set_callbacks(Callable p_pan_callback, Callable p_zoom_callback);
	void set_control_scheme(ControlScheme p_scheme);
	void set_enable_rmb(bool p_enable);
	void set_pan_shortcut(Ref<Shortcut> p_shortcut);
	void set_simple_panning_enabled(bool p_enabled);
	void set_scroll_speed(int p_scroll_speed);
	void set_scroll_zoom_factor(float p_scroll_zoom_factor);
	void set_pan_axis(PanAxis p_pan_axis);

	void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);
	void set_viewport(Viewport *p_viewport);

	bool is_panning() const;
	void set_force_drag(bool p_force);

	bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2());
Repository: godotengine/godot
File: modules/jolt_physics/objects/jolt_soft_body_3d.cpp (C++)

Code before:
	pressure = MAX(p_pressure, 0.0f);

	_pressure_changed();
}

void JoltSoftBody3D::set_linear_damping(float p_damping) {
	if (unlikely(linear_damping == p_damping)) {
		return;
	}

	linear_damping = MAX(p_damping, 0.0f);

	_damping_changed();
}

float JoltSoftBody3D::get_drag() const {
	// Drag is not a thing in Jolt, and not supported by Godot Physics either.
	return 0.0f;
}

void JoltSoftBody3D::set_drag(float p_drag) {
	// Drag is not a thing in Jolt, and not supported by Godot Physics either.
}

Variant JoltSoftBody3D::get_state(PhysicsServer3D::BodyState p_state) const {
	switch (p_state) {
		case PhysicsServer3D::BODY_STATE_TRANSFORM: {
			return get_transform();
		}
		case PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY: {
			ERR_FAIL_V_MSG(Variant(), "Linear velocity is not supported for soft bodies.");
		}
		case PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY: {
			ERR_FAIL_V_MSG(Variant(), "Angular velocity is not supported for soft bodies.");
		}
		case PhysicsServer3D::BODY_STATE_SLEEPING: {
			return is_sleeping();
		}
		case PhysicsServer3D::BODY_STATE_CAN_SLEEP: {
			return is_sleep_allowed();
		}
		default: {
			ERR_FAIL_V_MSG(Variant(), vformat("Unhandled body state: '%d'. This should not happen. Please report this.", p_state));
		}
	}
}

void JoltSoftBody3D::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_value) {
	switch (p_state) {
		case PhysicsServer3D::BODY_STATE_TRANSFORM: {
			set_transform(p_value);

Review comment (suggestion):
So this could be:

`physics_vertex.mVelocity += impulse * physics_vertex.mInvMass;`

where

`impulse = force * last_step`

Code after:
	if (p_enabled) {
		body_iface.DeactivateBody(jolt_body->GetID());
	} else {
		body_iface.ActivateBody(jolt_body->GetID());
	}
}

bool JoltSoftBody3D::is_sleep_allowed() const {
	if (!in_space()) {
		return jolt_settings->mAllowSleeping;
	} else {
		return jolt_body->GetAllowSleeping();
	}
}

void JoltSoftBody3D::set_is_sleep_allowed(bool p_enabled) {
	if (!in_space()) {
		jolt_settings->mAllowSleeping = p_enabled;
	} else {
		jolt_body->SetAllowSleeping(p_enabled);
	}
}

void JoltSoftBody3D::set_simulation_precision(int p_precision) {
	if (unlikely(simulation_precision == p_precision)) {
		return;
	}

	simulation_precision = MAX(p_precision, 0);

	_simulation_precision_changed();
}

void JoltSoftBody3D::set_mass(float p_mass) {
	if (unlikely(mass == p_mass)) {
		return;
	}

	mass = MAX(p_mass, 0.0f);

	_mass_changed();
}

float JoltSoftBody3D::get_stiffness_coefficient() const {
	return stiffness_coefficient;
}

void JoltSoftBody3D::set_stiffness_coefficient(float p_coefficient) {
	stiffness_coefficient = CLAMP(p_coefficient, 0.0f, 1.0f);
}
Repository: godotengine/godot
File: modules/jolt_physics/jolt_physics_server_3d.cpp (C++)

Code before:
void JoltPhysicsServer3D::area_set_space(RID p_area, RID p_space) {
	JoltArea3D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL(area);

	JoltSpace3D *space = nullptr;

	if (p_space.is_valid()) {
		space = space_owner.get_or_null(p_space);
		ERR_FAIL_NULL(space);
	}

	area->set_space(space);
}

void JoltPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, const Vector3 p_impulse, int p_node_index) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_node_impulse(p_node_index, p_impulse);
}

void JoltPhysicsServer3D::soft_body_apply_point_force(RID p_body, const Vector3 p_force, int p_node_index) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_node_force(p_node_index, p_force);
}

void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 p_impulse) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_impulse(p_impulse);
}
void JoltPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 p_force) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_force(p_force);
}

RID JoltPhysicsServer3D::area_get_space(RID p_area) const {
	const JoltArea3D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL_V(area, RID());

	const JoltSpace3D *space = area->get_space();

	if (space == nullptr) {
		return RID();
	}


Review comment (suggestion):
```suggestion
	body->apply_vertex_force(p_node_index, p_force);
```

Code after:
void JoltPhysicsServer3D::area_set_space(RID p_area, RID p_space) {
	JoltArea3D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL(area);

	JoltSpace3D *space = nullptr;

	if (p_space.is_valid()) {
		space = space_owner.get_or_null(p_space);
		ERR_FAIL_NULL(space);
	}

	area->set_space(space);
}

void JoltPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_vertex_impulse(p_point_index, p_impulse);
}

void JoltPhysicsServer3D::soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_vertex_force(p_point_index, p_force);
}

void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_impulse(p_impulse);
}

void JoltPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 &p_force) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_force(p_force);
}

RID JoltPhysicsServer3D::area_get_space(RID p_area) const {
	const JoltArea3D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL_V(area, RID());

	const JoltSpace3D *space = area->get_space();

	if (space == nullptr) {
		return RID();
	}
Repository: godotengine/godot
File: modules/jolt_physics/jolt_physics_server_3d.cpp (C++)

Code before:

	JoltSpace3D *space = nullptr;

	if (p_space.is_valid()) {
		space = space_owner.get_or_null(p_space);
		ERR_FAIL_NULL(space);
	}

	area->set_space(space);
}

void JoltPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, const Vector3 p_impulse, int p_node_index) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_node_impulse(p_node_index, p_impulse);
}

void JoltPhysicsServer3D::soft_body_apply_point_force(RID p_body, const Vector3 p_force, int p_node_index) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_node_force(p_node_index, p_force);
}

void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 p_impulse) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_impulse(p_impulse);
}
void JoltPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 p_force) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_force(p_force);
}

RID JoltPhysicsServer3D::area_get_space(RID p_area) const {
	const JoltArea3D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL_V(area, RID());

	const JoltSpace3D *space = area->get_space();

	if (space == nullptr) {
		return RID();
	}

	return space->get_rid();
}


Review comment (suggestion):
```suggestion
void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
```

Code after:

	JoltSpace3D *space = nullptr;

	if (p_space.is_valid()) {
		space = space_owner.get_or_null(p_space);
		ERR_FAIL_NULL(space);
	}

	area->set_space(space);
}

void JoltPhysicsServer3D::soft_body_apply_point_impulse(RID p_body, int p_point_index, const Vector3 &p_impulse) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_vertex_impulse(p_point_index, p_impulse);
}

void JoltPhysicsServer3D::soft_body_apply_point_force(RID p_body, int p_point_index, const Vector3 &p_force) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_vertex_force(p_point_index, p_force);
}

void JoltPhysicsServer3D::soft_body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_impulse(p_impulse);
}

void JoltPhysicsServer3D::soft_body_apply_central_force(RID p_body, const Vector3 &p_force) {
	JoltSoftBody3D *body = soft_body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->apply_central_force(p_force);
}

RID JoltPhysicsServer3D::area_get_space(RID p_area) const {
	const JoltArea3D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL_V(area, RID());

	const JoltSpace3D *space = area->get_space();

	if (space == nullptr) {
		return RID();
	}

	return space->get_rid();
}
Repository: godotengine/godot
File: modules/jolt_physics/objects/jolt_soft_body_3d.cpp (C++)

Code before:

		if (pinned_vertices.has(physics_index)) {
			continue;
		}

		JPH::SoftBodyVertex &physics_vertex = physics_vertices[physics_index];

		physics_vertex.mVelocity += impulse * physics_vertex.mInvMass;
	}
}

void JoltSoftBody3D::apply_central_force(const Vector3 &p_force) {
	ERR_FAIL_COND_MSG(!in_space(), vformat("Failed to apply central force for '%s'. Doing so without a physics space is not supported when using Jolt Physics. If this relates to a node, try adding the node to a scene tree first.", to_string()));

	ERR_FAIL_NULL(shared);

	const float last_step = space->get_last_step();
	if (unlikely(last_step == 0.0f)) {
		return;
	}

	JPH::BodyInterface &body_iface = space->get_body_iface();

	const JPH::Vec3 force = to_jolt(p_force);

	body_iface.AddForce(jolt_id, force, JPH::EActivation::Activate);
}

void JoltSoftBody3D::set_is_sleeping(bool p_enabled) {
	if (!in_space()) {
		return;
	}

	JPH::BodyInterface &body_iface = space->get_body_iface();

	if (p_enabled) {
		body_iface.DeactivateBody(jolt_id);
	} else {
		body_iface.ActivateBody(jolt_id);
	}
}

bool JoltSoftBody3D::can_sleep() const {
	if (!in_space()) {
		return true;
	}

	const JoltReadableBody3D body = space->read_body(jolt_id);
	ERR_FAIL_COND_V(body.is_invalid(), false);

	return body->GetAllowSleeping();

Review comment (suggestion):
```suggestion
	body_iface.AddForce(jolt_id, to_jolt(p_force), JPH::EActivation::Activate);
```

Code after:
}

void JoltSoftBody3D::set_mass(float p_mass) {
	if (unlikely(mass == p_mass)) {
		return;
	}

	mass = MAX(p_mass, 0.0f);

	_mass_changed();
}

float JoltSoftBody3D::get_stiffness_coefficient() const {
	return stiffness_coefficient;
}

void JoltSoftBody3D::set_stiffness_coefficient(float p_coefficient) {
	stiffness_coefficient = CLAMP(p_coefficient, 0.0f, 1.0f);
}

void JoltSoftBody3D::set_pressure(float p_pressure) {
	if (unlikely(pressure == p_pressure)) {
		return;
	}

	pressure = MAX(p_pressure, 0.0f);

	_pressure_changed();
}

void JoltSoftBody3D::set_linear_damping(float p_damping) {
	if (unlikely(linear_damping == p_damping)) {
		return;
	}

	linear_damping = MAX(p_damping, 0.0f);

	_damping_changed();
}

float JoltSoftBody3D::get_drag() const {
	// Drag is not a thing in Jolt, and not supported by Godot Physics either.
	return 0.0f;
}

void JoltSoftBody3D::set_drag(float p_drag) {
	// Drag is not a thing in Jolt, and not supported by Godot Physics either.
}

Variant JoltSoftBody3D::get_state(PhysicsServer3D::BodyState p_state) const {
	switch (p_state) {
Repository: godotengine/godot
File: modules/jolt_physics/objects/jolt_soft_body_3d.h (C/C++)

Code before:
	float get_drag() const;
	void set_drag(float p_drag);

	Variant get_state(PhysicsServer3D::BodyState p_state) const;
	void set_state(PhysicsServer3D::BodyState p_state, const Variant &p_value);

	Transform3D get_transform() const;
	void set_transform(const Transform3D &p_transform);

	AABB get_bounds() const;

	void update_rendering_server(PhysicsServer3DRenderingServerHandler *p_rendering_server_handler);

	Vector3 get_vertex_position(int p_index);
	void set_vertex_position(int p_index, const Vector3 &p_position);

	void pin_vertex(int p_index);
	void unpin_vertex(int p_index);

	void unpin_all_vertices();

	bool is_vertex_pinned(int p_index) const;

	void apply_node_impulse(int p_index, const Vector3 &p_impulse);
	void apply_node_force(int p_index, const Vector3 &p_force);
	void apply_central_impulse(const Vector3 &p_impulse);
	void apply_central_force(const Vector3 &p_force);

	String to_string() const;
};

#endif // JOLT_SOFT_BODY_3D_H


Review comment (suggestion):
```suggestion
	void apply_vertex_impulse(int p_index, const Vector3 &p_impulse);
	void apply_vertex_force(int p_index, const Vector3 &p_force);
	void apply_central_impulse(const Vector3 &p_impulse);
	void apply_central_force(const Vector3 &p_force);
```

Code after:
	void set_drag(float p_drag);

	Variant get_state(PhysicsServer3D::BodyState p_state) const;
	void set_state(PhysicsServer3D::BodyState p_state, const Variant &p_value);

	Transform3D get_transform() const;
	void set_transform(const Transform3D &p_transform);

	AABB get_bounds() const;

	void update_rendering_server(PhysicsServer3DRenderingServerHandler *p_rendering_server_handler);

	Vector3 get_vertex_position(int p_index);
	void set_vertex_position(int p_index, const Vector3 &p_position);

	void pin_vertex(int p_index);
	void unpin_vertex(int p_index);

	void unpin_all_vertices();

	bool is_vertex_pinned(int p_index) const;

	void apply_vertex_impulse(int p_index, const Vector3 &p_impulse);
	void apply_vertex_force(int p_index, const Vector3 &p_force);
	void apply_central_impulse(const Vector3 &p_impulse);
	void apply_central_force(const Vector3 &p_force);
};
Repository: godotengine/godot
File: modules/jolt_physics/objects/jolt_soft_body_3d.cpp (C++)

Code before:
	JoltWritableBody3D body = space->write_body(jolt_id);
	ERR_FAIL_COND(body.is_invalid());

	JPH::SoftBodyMotionProperties &motion_properties = static_cast<JPH::SoftBodyMotionProperties &>(*body->GetMotionPropertiesUnchecked());

	JPH::Array<JPH::SoftBodyVertex> &physics_vertices = motion_properties.GetVertices();

	const int mesh_vertex_count = shared->mesh_to_physics.size();

	const JPH::Vec3 impulse = to_jolt(p_impulse) / mesh_vertex_count;

	for (int i = 0; i < mesh_vertex_count; ++i) {
		const size_t physics_index = (size_t)shared->mesh_to_physics[i];

		if (pinned_vertices.has(physics_index)) {
			continue;
		}

		JPH::SoftBodyVertex &physics_vertex = physics_vertices[physics_index];

		physics_vertex.mVelocity += impulse * physics_vertex.mInvMass;
	}
}

void JoltSoftBody3D::apply_central_force(const Vector3 &p_force) {
	ERR_FAIL_COND_MSG(!in_space(), vformat("Failed to apply central force for '%s'. Doing so without a physics space is not supported when using Jolt Physics. If this relates to a node, try adding the node to a scene tree first.", to_string()));

	ERR_FAIL_NULL(shared);

	const float last_step = space->get_last_step();
	if (unlikely(last_step == 0.0f)) {
		return;
	}

	JPH::BodyInterface &body_iface = space->get_body_iface();

	const JPH::Vec3 force = to_jolt(p_force);

	body_iface.AddForce(jolt_id, force, JPH::EActivation::Activate);
}

void JoltSoftBody3D::set_is_sleeping(bool p_enabled) {
	if (!in_space()) {
		return;
	}

	JPH::BodyInterface &body_iface = space->get_body_iface();

	if (p_enabled) {
		body_iface.DeactivateBody(jolt_id);
	} else {

Review comment (bug):
```suggestion
	ERR_FAIL_COND_MSG(!in_space(), vformat("Failed to apply central force to '%s'. Doing so without a physics space is not supported when using Jolt Physics. If this relates to a node, try adding the node to a scene tree first.", to_string()));
```

Code after:
	} else {
		jolt_body->SetAllowSleeping(p_enabled);
	}
}

void JoltSoftBody3D::set_simulation_precision(int p_precision) {
	if (unlikely(simulation_precision == p_precision)) {
		return;
	}

	simulation_precision = MAX(p_precision, 0);

	_simulation_precision_changed();
}

void JoltSoftBody3D::set_mass(float p_mass) {
	if (unlikely(mass == p_mass)) {
		return;
	}

	mass = MAX(p_mass, 0.0f);

	_mass_changed();
}

float JoltSoftBody3D::get_stiffness_coefficient() const {
	return stiffness_coefficient;
}

void JoltSoftBody3D::set_stiffness_coefficient(float p_coefficient) {
	stiffness_coefficient = CLAMP(p_coefficient, 0.0f, 1.0f);
}

void JoltSoftBody3D::set_pressure(float p_pressure) {
	if (unlikely(pressure == p_pressure)) {
		return;
	}

	pressure = MAX(p_pressure, 0.0f);

	_pressure_changed();
}

void JoltSoftBody3D::set_linear_damping(float p_damping) {
	if (unlikely(linear_damping == p_damping)) {
		return;
	}

	linear_damping = MAX(p_damping, 0.0f);

	_damping_changed();