godot/modules/godot_physics_2d/godot_physics_server_2d.cpp

/**************************************************************************/
/*  godot_physics_server_2d.cpp                                           */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "godot_physics_server_2d.h"

#include "godot_body_direct_state_2d.h"
#include "godot_broad_phase_2d_bvh.h"
#include "godot_collision_solver_2d.h"

#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "core/os/os.h"

#define FLUSH_QUERY_CHECK(m_object)

RID GodotPhysicsServer2D::_shape_create(ShapeType p_shape) {}

RID GodotPhysicsServer2D::world_boundary_shape_create() {}

RID GodotPhysicsServer2D::separation_ray_shape_create() {}

RID GodotPhysicsServer2D::segment_shape_create() {}

RID GodotPhysicsServer2D::circle_shape_create() {}

RID GodotPhysicsServer2D::rectangle_shape_create() {}

RID GodotPhysicsServer2D::capsule_shape_create() {}

RID GodotPhysicsServer2D::convex_polygon_shape_create() {}

RID GodotPhysicsServer2D::concave_polygon_shape_create() {}

void GodotPhysicsServer2D::shape_set_data(RID p_shape, const Variant &p_data) {
	GodotShape2D *shape = shape_owner.get_or_null(p_shape);
	ERR_FAIL_NULL(shape);
	shape->set_data(p_data);
};

void GodotPhysicsServer2D::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {}

PhysicsServer2D::ShapeType GodotPhysicsServer2D::shape_get_type(RID p_shape) const {
	const GodotShape2D *shape = shape_owner.get_or_null(p_shape);
	ERR_FAIL_NULL_V(shape, SHAPE_CUSTOM);
	return shape->get_type();
};

Variant GodotPhysicsServer2D::shape_get_data(RID p_shape) const {
	const GodotShape2D *shape = shape_owner.get_or_null(p_shape);
	ERR_FAIL_NULL_V(shape, Variant());
	ERR_FAIL_COND_V(!shape->is_configured(), Variant());
	return shape->get_data();
};

real_t GodotPhysicsServer2D::shape_get_custom_solver_bias(RID p_shape) const {}

void GodotPhysicsServer2D::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata) {}

bool GodotPhysicsServer2D::shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) {}

RID GodotPhysicsServer2D::space_create() {
	GodotSpace2D *space = memnew(GodotSpace2D);
	RID id = space_owner.make_rid(space);
	space->set_self(id);
	RID area_id = area_create();
	GodotArea2D *area = area_owner.get_or_null(area_id);
	ERR_FAIL_NULL_V(area, RID());
	space->set_default_area(area);
	area->set_space(space);
	area->set_priority(-1);

	return id;
};

void GodotPhysicsServer2D::space_set_active(RID p_space, bool p_active) {}

bool GodotPhysicsServer2D::space_is_active(RID p_space) const {}

void GodotPhysicsServer2D::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {}

real_t GodotPhysicsServer2D::space_get_param(RID p_space, SpaceParameter p_param) const {}

void GodotPhysicsServer2D::space_set_debug_contacts(RID p_space, int p_max_contacts) {}

Vector<Vector2> GodotPhysicsServer2D::space_get_contacts(RID p_space) const {}

int GodotPhysicsServer2D::space_get_contact_count(RID p_space) const {}

PhysicsDirectSpaceState2D *GodotPhysicsServer2D::space_get_direct_state(RID p_space) {}

RID GodotPhysicsServer2D::area_create() {}

void GodotPhysicsServer2D::area_set_space(RID p_area, RID p_space) {}

RID GodotPhysicsServer2D::area_get_space(RID p_area) const {}

void GodotPhysicsServer2D::area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform, bool p_disabled) {}

void GodotPhysicsServer2D::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {}

void GodotPhysicsServer2D::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) {}

void GodotPhysicsServer2D::area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) {}

int GodotPhysicsServer2D::area_get_shape_count(RID p_area) const {}

RID GodotPhysicsServer2D::area_get_shape(RID p_area, int p_shape_idx) const {}

Transform2D GodotPhysicsServer2D::area_get_shape_transform(RID p_area, int p_shape_idx) const {}

void GodotPhysicsServer2D::area_remove_shape(RID p_area, int p_shape_idx) {}

void GodotPhysicsServer2D::area_clear_shapes(RID p_area) {}

void GodotPhysicsServer2D::area_attach_object_instance_id(RID p_area, ObjectID p_id) {}

ObjectID GodotPhysicsServer2D::area_get_object_instance_id(RID p_area) const {}

void GodotPhysicsServer2D::area_attach_canvas_instance_id(RID p_area, ObjectID p_id) {}

ObjectID GodotPhysicsServer2D::area_get_canvas_instance_id(RID p_area) const {}

void GodotPhysicsServer2D::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
	if (space_owner.owns(p_area)) {
		GodotSpace2D *space = space_owner.get_or_null(p_area);
		p_area = space->get_default_area()->get_self();
	}
	GodotArea2D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL(area);
	area->set_param(p_param, p_value);
};

void GodotPhysicsServer2D::area_set_transform(RID p_area, const Transform2D &p_transform) {
	GodotArea2D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL(area);
	area->set_transform(p_transform);
};

Variant GodotPhysicsServer2D::area_get_param(RID p_area, AreaParameter p_param) const {
	if (space_owner.owns(p_area)) {
		GodotSpace2D *space = space_owner.get_or_null(p_area);
		p_area = space->get_default_area()->get_self();
	}
	GodotArea2D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL_V(area, Variant());

	return area->get_param(p_param);
};

Transform2D GodotPhysicsServer2D::area_get_transform(RID p_area) const {
	GodotArea2D *area = area_owner.get_or_null(p_area);
	ERR_FAIL_NULL_V(area, Transform2D());

	return area->get_transform();
};

void GodotPhysicsServer2D::area_set_pickable(RID p_area, bool p_pickable) {}

void GodotPhysicsServer2D::area_set_monitorable(RID p_area, bool p_monitorable) {}

void GodotPhysicsServer2D::area_set_collision_layer(RID p_area, uint32_t p_layer) {}

uint32_t GodotPhysicsServer2D::area_get_collision_layer(RID p_area) const {}

void GodotPhysicsServer2D::area_set_collision_mask(RID p_area, uint32_t p_mask) {}

uint32_t GodotPhysicsServer2D::area_get_collision_mask(RID p_area) const {}

void GodotPhysicsServer2D::area_set_monitor_callback(RID p_area, const Callable &p_callback) {}

void GodotPhysicsServer2D::area_set_area_monitor_callback(RID p_area, const Callable &p_callback) {}

/* BODY API */

RID GodotPhysicsServer2D::body_create() {}

void GodotPhysicsServer2D::body_set_space(RID p_body, RID p_space) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);
	GodotSpace2D *space = nullptr;
	if (p_space.is_valid()) {
		space = space_owner.get_or_null(p_space);
		ERR_FAIL_NULL(space);
	}

	if (body->get_space() == space) {
		return; //pointless
	}

	body->clear_constraint_list();
	body->set_space(space);
};

RID GodotPhysicsServer2D::body_get_space(RID p_body) const {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL_V(body, RID());

	GodotSpace2D *space = body->get_space();
	if (!space) {
		return RID();
	}
	return space->get_self();
};

void GodotPhysicsServer2D::body_set_mode(RID p_body, BodyMode p_mode) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);
	FLUSH_QUERY_CHECK(body);

	body->set_mode(p_mode);
};

PhysicsServer2D::BodyMode GodotPhysicsServer2D::body_get_mode(RID p_body) const {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL_V(body, BODY_MODE_STATIC);

	return body->get_mode();
};

void GodotPhysicsServer2D::body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform, bool p_disabled) {}

void GodotPhysicsServer2D::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {}

void GodotPhysicsServer2D::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) {}

int GodotPhysicsServer2D::body_get_shape_count(RID p_body) const {}

RID GodotPhysicsServer2D::body_get_shape(RID p_body, int p_shape_idx) const {}

Transform2D GodotPhysicsServer2D::body_get_shape_transform(RID p_body, int p_shape_idx) const {}

void GodotPhysicsServer2D::body_remove_shape(RID p_body, int p_shape_idx) {}

void GodotPhysicsServer2D::body_clear_shapes(RID p_body) {}

void GodotPhysicsServer2D::body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) {}

void GodotPhysicsServer2D::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, real_t p_margin) {}

void GodotPhysicsServer2D::body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) {}

GodotPhysicsServer2D::CCDMode GodotPhysicsServer2D::body_get_continuous_collision_detection_mode(RID p_body) const {}

void GodotPhysicsServer2D::body_attach_object_instance_id(RID p_body, ObjectID p_id) {}

ObjectID GodotPhysicsServer2D::body_get_object_instance_id(RID p_body) const {}

void GodotPhysicsServer2D::body_attach_canvas_instance_id(RID p_body, ObjectID p_id) {}

ObjectID GodotPhysicsServer2D::body_get_canvas_instance_id(RID p_body) const {}

void GodotPhysicsServer2D::body_set_collision_layer(RID p_body, uint32_t p_layer) {}

uint32_t GodotPhysicsServer2D::body_get_collision_layer(RID p_body) const {}

void GodotPhysicsServer2D::body_set_collision_mask(RID p_body, uint32_t p_mask) {}

uint32_t GodotPhysicsServer2D::body_get_collision_mask(RID p_body) const {}

void GodotPhysicsServer2D::body_set_collision_priority(RID p_body, real_t p_priority) {}

real_t GodotPhysicsServer2D::body_get_collision_priority(RID p_body) const {}

void GodotPhysicsServer2D::body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) {}

Variant GodotPhysicsServer2D::body_get_param(RID p_body, BodyParameter p_param) const {}

void GodotPhysicsServer2D::body_reset_mass_properties(RID p_body) {}

void GodotPhysicsServer2D::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {}

Variant GodotPhysicsServer2D::body_get_state(RID p_body, BodyState p_state) const {}

void GodotPhysicsServer2D::body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) {}

void GodotPhysicsServer2D::body_apply_torque_impulse(RID p_body, real_t p_torque) {}

void GodotPhysicsServer2D::body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position) {}

void GodotPhysicsServer2D::body_apply_central_force(RID p_body, const Vector2 &p_force) {}

void GodotPhysicsServer2D::body_apply_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position) {}

void GodotPhysicsServer2D::body_apply_torque(RID p_body, real_t p_torque) {}

void GodotPhysicsServer2D::body_add_constant_central_force(RID p_body, const Vector2 &p_force) {}

void GodotPhysicsServer2D::body_add_constant_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position) {}

void GodotPhysicsServer2D::body_add_constant_torque(RID p_body, real_t p_torque) {}

void GodotPhysicsServer2D::body_set_constant_force(RID p_body, const Vector2 &p_force) {}

Vector2 GodotPhysicsServer2D::body_get_constant_force(RID p_body) const {}

void GodotPhysicsServer2D::body_set_constant_torque(RID p_body, real_t p_torque) {}

real_t GodotPhysicsServer2D::body_get_constant_torque(RID p_body) const {}

void GodotPhysicsServer2D::body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	_update_shapes();

	Vector2 v = body->get_linear_velocity();
	Vector2 axis = p_axis_velocity.normalized();
	v -= axis * axis.dot(v);
	v += p_axis_velocity;
	body->set_linear_velocity(v);
	body->wakeup();
};

void GodotPhysicsServer2D::body_add_collision_exception(RID p_body, RID p_body_b) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->add_exception(p_body_b);
	body->wakeup();
};

void GodotPhysicsServer2D::body_remove_collision_exception(RID p_body, RID p_body_b) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->remove_exception(p_body_b);
	body->wakeup();
};

void GodotPhysicsServer2D::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	for (int i = 0; i < body->get_exceptions().size(); i++) {
		p_exceptions->push_back(body->get_exceptions()[i]);
	}
};

void GodotPhysicsServer2D::body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);
};

real_t GodotPhysicsServer2D::body_get_contacts_reported_depth_threshold(RID p_body) const {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL_V(body, 0);
	return 0;
};

void GodotPhysicsServer2D::body_set_omit_force_integration(RID p_body, bool p_omit) {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL(body);

	body->set_omit_force_integration(p_omit);
};

bool GodotPhysicsServer2D::body_is_omitting_force_integration(RID p_body) const {
	GodotBody2D *body = body_owner.get_or_null(p_body);
	ERR_FAIL_NULL_V(body, false);
	return body->get_omit_force_integration();
};

void GodotPhysicsServer2D::body_set_max_contacts_reported(RID p_body, int p_contacts) {}

int GodotPhysicsServer2D::body_get_max_contacts_reported(RID p_body) const {}

void GodotPhysicsServer2D::body_set_state_sync_callback(RID p_body, const Callable &p_callable) {}

void GodotPhysicsServer2D::body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata) {}

bool GodotPhysicsServer2D::body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) {}

void GodotPhysicsServer2D::body_set_pickable(RID p_body, bool p_pickable) {}

bool GodotPhysicsServer2D::body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result) {}

PhysicsDirectBodyState2D *GodotPhysicsServer2D::body_get_direct_state(RID p_body) {}

/* JOINT API */

RID GodotPhysicsServer2D::joint_create() {}

void GodotPhysicsServer2D::joint_clear(RID p_joint) {}

void GodotPhysicsServer2D::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) {}

real_t GodotPhysicsServer2D::joint_get_param(RID p_joint, JointParam p_param) const {}

void GodotPhysicsServer2D::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {}

bool GodotPhysicsServer2D::joint_is_disabled_collisions_between_bodies(RID p_joint) const {}

void GodotPhysicsServer2D::joint_make_pin(RID p_joint, const Vector2 &p_pos, RID p_body_a, RID p_body_b) {}

void GodotPhysicsServer2D::joint_make_groove(RID p_joint, const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) {}

void GodotPhysicsServer2D::joint_make_damped_spring(RID p_joint, const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b) {}

void GodotPhysicsServer2D::pin_joint_set_flag(RID p_joint, PinJointFlag p_flag, bool p_enabled) {}

bool GodotPhysicsServer2D::pin_joint_get_flag(RID p_joint, PinJointFlag p_flag) const {}

void GodotPhysicsServer2D::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {}

real_t GodotPhysicsServer2D::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {}

void GodotPhysicsServer2D::damped_spring_joint_set_param(RID p_joint, DampedSpringParam p_param, real_t p_value) {}

real_t GodotPhysicsServer2D::damped_spring_joint_get_param(RID p_joint, DampedSpringParam p_param) const {}

PhysicsServer2D::JointType GodotPhysicsServer2D::joint_get_type(RID p_joint) const {}

void GodotPhysicsServer2D::free(RID p_rid) {}

void GodotPhysicsServer2D::set_active(bool p_active) {}

void GodotPhysicsServer2D::init() {}

void GodotPhysicsServer2D::step(real_t p_step) {}

void GodotPhysicsServer2D::sync() {}

void GodotPhysicsServer2D::flush_queries() {}

void GodotPhysicsServer2D::end_sync() {}

void GodotPhysicsServer2D::finish() {}

void GodotPhysicsServer2D::_update_shapes() {}

int GodotPhysicsServer2D::get_process_info(ProcessInfo p_info) {}

GodotPhysicsServer2D *GodotPhysicsServer2D::godot_singleton =;

GodotPhysicsServer2D::GodotPhysicsServer2D(bool p_using_threads) {}