Move server files into their subfolders
This commit is contained in:
6
servers/physics_2d/SCsub
Normal file
6
servers/physics_2d/SCsub
Normal file
@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from misc.utility.scons_hints import *
|
||||
|
||||
Import("env")
|
||||
|
||||
env.add_source_files(env.servers_sources, "*.cpp")
|
||||
1012
servers/physics_2d/physics_server_2d.cpp
Normal file
1012
servers/physics_2d/physics_server_2d.cpp
Normal file
File diff suppressed because it is too large
Load Diff
859
servers/physics_2d/physics_server_2d.h
Normal file
859
servers/physics_2d/physics_server_2d.h
Normal file
@ -0,0 +1,859 @@
|
||||
/**************************************************************************/
|
||||
/* physics_server_2d.h */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/object/ref_counted.h"
|
||||
|
||||
constexpr int MAX_CONTACTS_REPORTED_2D_MAX = 4096;
|
||||
|
||||
class PhysicsDirectSpaceState2D;
|
||||
template <typename T>
|
||||
class TypedArray;
|
||||
|
||||
class PhysicsDirectBodyState2D : public Object {
|
||||
GDCLASS(PhysicsDirectBodyState2D, Object);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual Vector2 get_total_gravity() const = 0; // get gravity vector working on this body space/area
|
||||
virtual real_t get_total_linear_damp() const = 0; // get density of this body space/area
|
||||
virtual real_t get_total_angular_damp() const = 0; // get density of this body space/area
|
||||
|
||||
virtual Vector2 get_center_of_mass() const = 0;
|
||||
virtual Vector2 get_center_of_mass_local() const = 0;
|
||||
virtual real_t get_inverse_mass() const = 0; // get the mass
|
||||
virtual real_t get_inverse_inertia() const = 0; // get density of this body space
|
||||
|
||||
virtual void set_linear_velocity(const Vector2 &p_velocity) = 0;
|
||||
virtual Vector2 get_linear_velocity() const = 0;
|
||||
|
||||
virtual void set_angular_velocity(real_t p_velocity) = 0;
|
||||
virtual real_t get_angular_velocity() const = 0;
|
||||
|
||||
virtual void set_transform(const Transform2D &p_transform) = 0;
|
||||
virtual Transform2D get_transform() const = 0;
|
||||
|
||||
virtual Vector2 get_velocity_at_local_position(const Vector2 &p_position) const = 0;
|
||||
|
||||
virtual void apply_central_impulse(const Vector2 &p_impulse) = 0;
|
||||
virtual void apply_torque_impulse(real_t p_torque) = 0;
|
||||
virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) = 0;
|
||||
|
||||
virtual void apply_central_force(const Vector2 &p_force) = 0;
|
||||
virtual void apply_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void apply_torque(real_t p_torque) = 0;
|
||||
|
||||
virtual void add_constant_central_force(const Vector2 &p_force) = 0;
|
||||
virtual void add_constant_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void add_constant_torque(real_t p_torque) = 0;
|
||||
|
||||
virtual void set_constant_force(const Vector2 &p_force) = 0;
|
||||
virtual Vector2 get_constant_force() const = 0;
|
||||
|
||||
virtual void set_constant_torque(real_t p_torque) = 0;
|
||||
virtual real_t get_constant_torque() const = 0;
|
||||
|
||||
virtual void set_sleep_state(bool p_enable) = 0;
|
||||
virtual bool is_sleeping() const = 0;
|
||||
|
||||
virtual void set_collision_layer(uint32_t p_layer) = 0;
|
||||
virtual uint32_t get_collision_layer() const = 0;
|
||||
|
||||
virtual void set_collision_mask(uint32_t p_mask) = 0;
|
||||
virtual uint32_t get_collision_mask() const = 0;
|
||||
|
||||
virtual int get_contact_count() const = 0;
|
||||
|
||||
virtual Vector2 get_contact_local_position(int p_contact_idx) const = 0;
|
||||
virtual Vector2 get_contact_local_normal(int p_contact_idx) const = 0;
|
||||
virtual int get_contact_local_shape(int p_contact_idx) const = 0;
|
||||
virtual Vector2 get_contact_local_velocity_at_position(int p_contact_idx) const = 0;
|
||||
|
||||
virtual RID get_contact_collider(int p_contact_idx) const = 0;
|
||||
virtual Vector2 get_contact_collider_position(int p_contact_idx) const = 0;
|
||||
virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0;
|
||||
virtual Object *get_contact_collider_object(int p_contact_idx) const;
|
||||
virtual int get_contact_collider_shape(int p_contact_idx) const = 0;
|
||||
virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const = 0;
|
||||
virtual Vector2 get_contact_impulse(int p_contact_idx) const = 0;
|
||||
|
||||
virtual real_t get_step() const = 0;
|
||||
virtual void integrate_forces();
|
||||
|
||||
virtual PhysicsDirectSpaceState2D *get_space_state() = 0;
|
||||
|
||||
PhysicsDirectBodyState2D();
|
||||
};
|
||||
|
||||
class PhysicsRayQueryParameters2D;
|
||||
class PhysicsPointQueryParameters2D;
|
||||
class PhysicsShapeQueryParameters2D;
|
||||
|
||||
class PhysicsDirectSpaceState2D : public Object {
|
||||
GDCLASS(PhysicsDirectSpaceState2D, Object);
|
||||
|
||||
Dictionary _intersect_ray(const Ref<PhysicsRayQueryParameters2D> &p_ray_query);
|
||||
TypedArray<Dictionary> _intersect_point(const Ref<PhysicsPointQueryParameters2D> &p_point_query, int p_max_results = 32);
|
||||
TypedArray<Dictionary> _intersect_shape(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query, int p_max_results = 32);
|
||||
Vector<real_t> _cast_motion(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query);
|
||||
TypedArray<Vector2> _collide_shape(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query, int p_max_results = 32);
|
||||
Dictionary _get_rest_info(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
struct RayParameters {
|
||||
Vector2 from;
|
||||
Vector2 to;
|
||||
HashSet<RID> exclude;
|
||||
uint32_t collision_mask = UINT32_MAX;
|
||||
|
||||
bool collide_with_bodies = true;
|
||||
bool collide_with_areas = false;
|
||||
|
||||
bool hit_from_inside = false;
|
||||
};
|
||||
|
||||
struct RayResult {
|
||||
Vector2 position;
|
||||
Vector2 normal;
|
||||
RID rid;
|
||||
ObjectID collider_id;
|
||||
Object *collider = nullptr;
|
||||
int shape = 0;
|
||||
};
|
||||
|
||||
virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) = 0;
|
||||
|
||||
struct ShapeResult {
|
||||
RID rid;
|
||||
ObjectID collider_id;
|
||||
Object *collider = nullptr;
|
||||
int shape = 0;
|
||||
};
|
||||
|
||||
struct PointParameters {
|
||||
Vector2 position;
|
||||
ObjectID canvas_instance_id;
|
||||
HashSet<RID> exclude;
|
||||
uint32_t collision_mask = UINT32_MAX;
|
||||
|
||||
bool collide_with_bodies = true;
|
||||
bool collide_with_areas = false;
|
||||
|
||||
bool pick_point = false;
|
||||
};
|
||||
|
||||
virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
|
||||
|
||||
struct ShapeParameters {
|
||||
RID shape_rid;
|
||||
Transform2D transform;
|
||||
Vector2 motion;
|
||||
real_t margin = 0.0;
|
||||
HashSet<RID> exclude;
|
||||
uint32_t collision_mask = UINT32_MAX;
|
||||
|
||||
bool collide_with_bodies = true;
|
||||
bool collide_with_areas = false;
|
||||
};
|
||||
|
||||
struct ShapeRestInfo {
|
||||
Vector2 point;
|
||||
Vector2 normal;
|
||||
RID rid;
|
||||
ObjectID collider_id;
|
||||
int shape = 0;
|
||||
Vector2 linear_velocity; // Velocity at contact point.
|
||||
};
|
||||
|
||||
virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
|
||||
virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) = 0;
|
||||
virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;
|
||||
virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) = 0;
|
||||
|
||||
PhysicsDirectSpaceState2D();
|
||||
};
|
||||
|
||||
class PhysicsTestMotionParameters2D;
|
||||
class PhysicsTestMotionResult2D;
|
||||
|
||||
class PhysicsServer2D : public Object {
|
||||
GDCLASS(PhysicsServer2D, Object);
|
||||
|
||||
static PhysicsServer2D *singleton;
|
||||
|
||||
virtual bool _body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters2D> &p_parameters, const Ref<PhysicsTestMotionResult2D> &p_result = Ref<PhysicsTestMotionResult2D>());
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static PhysicsServer2D *get_singleton();
|
||||
|
||||
enum ShapeType {
|
||||
SHAPE_WORLD_BOUNDARY, ///< plane:"plane"
|
||||
SHAPE_SEPARATION_RAY, ///< float:"length"
|
||||
SHAPE_SEGMENT, ///< float:"length"
|
||||
SHAPE_CIRCLE, ///< float:"radius"
|
||||
SHAPE_RECTANGLE, ///< vec3:"extents"
|
||||
SHAPE_CAPSULE,
|
||||
SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
|
||||
SHAPE_CONCAVE_POLYGON, ///< Vector2 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector2 array)
|
||||
SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
|
||||
};
|
||||
|
||||
virtual RID world_boundary_shape_create() = 0;
|
||||
virtual RID separation_ray_shape_create() = 0;
|
||||
virtual RID segment_shape_create() = 0;
|
||||
virtual RID circle_shape_create() = 0;
|
||||
virtual RID rectangle_shape_create() = 0;
|
||||
virtual RID capsule_shape_create() = 0;
|
||||
virtual RID convex_polygon_shape_create() = 0;
|
||||
virtual RID concave_polygon_shape_create() = 0;
|
||||
|
||||
virtual void shape_set_data(RID p_shape, const Variant &p_data) = 0;
|
||||
virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) = 0;
|
||||
|
||||
virtual ShapeType shape_get_type(RID p_shape) const = 0;
|
||||
virtual Variant shape_get_data(RID p_shape) const = 0;
|
||||
virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0;
|
||||
|
||||
//these work well, but should be used from the main thread only
|
||||
virtual bool 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) = 0;
|
||||
|
||||
/* SPACE API */
|
||||
|
||||
virtual RID space_create() = 0;
|
||||
virtual void space_set_active(RID p_space, bool p_active) = 0;
|
||||
virtual bool space_is_active(RID p_space) const = 0;
|
||||
|
||||
enum SpaceParameter {
|
||||
SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
|
||||
SPACE_PARAM_CONTACT_MAX_SEPARATION,
|
||||
SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION,
|
||||
SPACE_PARAM_CONTACT_DEFAULT_BIAS,
|
||||
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD,
|
||||
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD,
|
||||
SPACE_PARAM_BODY_TIME_TO_SLEEP,
|
||||
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
|
||||
SPACE_PARAM_SOLVER_ITERATIONS,
|
||||
};
|
||||
|
||||
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
|
||||
virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0;
|
||||
|
||||
// this function only works on physics process, errors and returns null otherwise
|
||||
virtual PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) = 0;
|
||||
|
||||
virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0;
|
||||
virtual Vector<Vector2> space_get_contacts(RID p_space) const = 0;
|
||||
virtual int space_get_contact_count(RID p_space) const = 0;
|
||||
|
||||
//missing space parameters
|
||||
|
||||
/* AREA API */
|
||||
|
||||
//missing attenuation? missing better override?
|
||||
|
||||
enum AreaParameter {
|
||||
AREA_PARAM_GRAVITY_OVERRIDE_MODE,
|
||||
AREA_PARAM_GRAVITY,
|
||||
AREA_PARAM_GRAVITY_VECTOR,
|
||||
AREA_PARAM_GRAVITY_IS_POINT,
|
||||
AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE,
|
||||
AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
|
||||
AREA_PARAM_LINEAR_DAMP,
|
||||
AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
|
||||
AREA_PARAM_ANGULAR_DAMP,
|
||||
AREA_PARAM_PRIORITY
|
||||
};
|
||||
|
||||
virtual RID area_create() = 0;
|
||||
|
||||
virtual void area_set_space(RID p_area, RID p_space) = 0;
|
||||
virtual RID area_get_space(RID p_area) const = 0;
|
||||
|
||||
enum AreaSpaceOverrideMode {
|
||||
AREA_SPACE_OVERRIDE_DISABLED,
|
||||
AREA_SPACE_OVERRIDE_COMBINE,
|
||||
AREA_SPACE_OVERRIDE_COMBINE_REPLACE, // Combines, then discards all subsequent calculations
|
||||
AREA_SPACE_OVERRIDE_REPLACE,
|
||||
AREA_SPACE_OVERRIDE_REPLACE_COMBINE // Discards all previous calculations, then keeps combining
|
||||
};
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) = 0;
|
||||
|
||||
virtual int area_get_shape_count(RID p_area) const = 0;
|
||||
virtual RID area_get_shape(RID p_area, int p_shape_idx) const = 0;
|
||||
virtual Transform2D area_get_shape_transform(RID p_area, int p_shape_idx) const = 0;
|
||||
|
||||
virtual void area_remove_shape(RID p_area, int p_shape_idx) = 0;
|
||||
virtual void area_clear_shapes(RID p_area) = 0;
|
||||
|
||||
virtual void area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) = 0;
|
||||
|
||||
virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) = 0;
|
||||
virtual ObjectID area_get_object_instance_id(RID p_area) const = 0;
|
||||
|
||||
virtual void area_attach_canvas_instance_id(RID p_area, ObjectID p_id) = 0;
|
||||
virtual ObjectID area_get_canvas_instance_id(RID p_area) const = 0;
|
||||
|
||||
virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) = 0;
|
||||
virtual void area_set_transform(RID p_area, const Transform2D &p_transform) = 0;
|
||||
|
||||
virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0;
|
||||
virtual Transform2D area_get_transform(RID p_area) const = 0;
|
||||
|
||||
virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) = 0;
|
||||
virtual uint32_t area_get_collision_layer(RID p_area) const = 0;
|
||||
|
||||
virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0;
|
||||
virtual uint32_t area_get_collision_mask(RID p_area) const = 0;
|
||||
|
||||
virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0;
|
||||
virtual void area_set_pickable(RID p_area, bool p_pickable) = 0;
|
||||
|
||||
virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) = 0;
|
||||
virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) = 0;
|
||||
|
||||
/* BODY API */
|
||||
|
||||
//missing ccd?
|
||||
|
||||
enum BodyMode {
|
||||
BODY_MODE_STATIC,
|
||||
BODY_MODE_KINEMATIC,
|
||||
BODY_MODE_RIGID,
|
||||
BODY_MODE_RIGID_LINEAR,
|
||||
};
|
||||
|
||||
virtual RID body_create() = 0;
|
||||
|
||||
virtual void body_set_space(RID p_body, RID p_space) = 0;
|
||||
virtual RID body_get_space(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
|
||||
virtual BodyMode body_get_mode(RID p_body) const = 0;
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) = 0;
|
||||
|
||||
virtual int body_get_shape_count(RID p_body) const = 0;
|
||||
virtual RID body_get_shape(RID p_body, int p_shape_idx) const = 0;
|
||||
virtual Transform2D body_get_shape_transform(RID p_body, int p_shape_idx) const = 0;
|
||||
|
||||
virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) = 0;
|
||||
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, real_t p_margin = 0) = 0;
|
||||
|
||||
virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
|
||||
virtual void body_clear_shapes(RID p_body) = 0;
|
||||
|
||||
virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) = 0;
|
||||
virtual ObjectID body_get_object_instance_id(RID p_body) const = 0;
|
||||
|
||||
virtual void body_attach_canvas_instance_id(RID p_body, ObjectID p_id) = 0;
|
||||
virtual ObjectID body_get_canvas_instance_id(RID p_body) const = 0;
|
||||
|
||||
enum CCDMode {
|
||||
CCD_MODE_DISABLED,
|
||||
CCD_MODE_CAST_RAY,
|
||||
CCD_MODE_CAST_SHAPE,
|
||||
};
|
||||
|
||||
virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) = 0;
|
||||
virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) = 0;
|
||||
virtual uint32_t body_get_collision_layer(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
|
||||
virtual uint32_t body_get_collision_mask(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_collision_priority(RID p_body, real_t p_priority) = 0;
|
||||
virtual real_t body_get_collision_priority(RID p_body) const = 0;
|
||||
|
||||
// common body variables
|
||||
enum BodyParameter {
|
||||
BODY_PARAM_BOUNCE,
|
||||
BODY_PARAM_FRICTION,
|
||||
BODY_PARAM_MASS, ///< unused for static, always infinite
|
||||
BODY_PARAM_INERTIA,
|
||||
BODY_PARAM_CENTER_OF_MASS,
|
||||
BODY_PARAM_GRAVITY_SCALE,
|
||||
BODY_PARAM_LINEAR_DAMP_MODE,
|
||||
BODY_PARAM_ANGULAR_DAMP_MODE,
|
||||
BODY_PARAM_LINEAR_DAMP,
|
||||
BODY_PARAM_ANGULAR_DAMP,
|
||||
BODY_PARAM_MAX,
|
||||
};
|
||||
|
||||
enum BodyDampMode {
|
||||
BODY_DAMP_MODE_COMBINE,
|
||||
BODY_DAMP_MODE_REPLACE,
|
||||
};
|
||||
|
||||
virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) = 0;
|
||||
virtual Variant body_get_param(RID p_body, BodyParameter p_param) const = 0;
|
||||
|
||||
virtual void body_reset_mass_properties(RID p_body) = 0;
|
||||
|
||||
//state
|
||||
enum BodyState {
|
||||
BODY_STATE_TRANSFORM,
|
||||
BODY_STATE_LINEAR_VELOCITY,
|
||||
BODY_STATE_ANGULAR_VELOCITY,
|
||||
BODY_STATE_SLEEPING,
|
||||
BODY_STATE_CAN_SLEEP,
|
||||
};
|
||||
|
||||
virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
|
||||
virtual Variant body_get_state(RID p_body, BodyState p_state) const = 0;
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) = 0;
|
||||
virtual void body_apply_torque_impulse(RID p_body, real_t p_torque) = 0;
|
||||
virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) = 0;
|
||||
|
||||
virtual void body_apply_central_force(RID p_body, const Vector2 &p_force) = 0;
|
||||
virtual void body_apply_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void body_apply_torque(RID p_body, real_t p_torque) = 0;
|
||||
|
||||
virtual void body_add_constant_central_force(RID p_body, const Vector2 &p_force) = 0;
|
||||
virtual void body_add_constant_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
||||
virtual void body_add_constant_torque(RID p_body, real_t p_torque) = 0;
|
||||
|
||||
virtual void body_set_constant_force(RID p_body, const Vector2 &p_force) = 0;
|
||||
virtual Vector2 body_get_constant_force(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_constant_torque(RID p_body, real_t p_torque) = 0;
|
||||
virtual real_t body_get_constant_torque(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) = 0;
|
||||
|
||||
//fix
|
||||
virtual void body_add_collision_exception(RID p_body, RID p_body_b) = 0;
|
||||
virtual void body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
|
||||
virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
|
||||
|
||||
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) = 0;
|
||||
virtual int body_get_max_contacts_reported(RID p_body) const = 0;
|
||||
|
||||
//missing remove
|
||||
virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) = 0;
|
||||
virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_omit_force_integration(RID p_body, bool p_omit) = 0;
|
||||
virtual bool body_is_omitting_force_integration(RID p_body) const = 0;
|
||||
|
||||
virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) = 0;
|
||||
virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) = 0;
|
||||
|
||||
virtual bool 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) = 0;
|
||||
|
||||
virtual void body_set_pickable(RID p_body, bool p_pickable) = 0;
|
||||
|
||||
// this function only works on physics process, errors and returns null otherwise
|
||||
virtual PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) = 0;
|
||||
|
||||
struct MotionParameters {
|
||||
Transform2D from;
|
||||
Vector2 motion;
|
||||
real_t margin = 0.08;
|
||||
bool collide_separation_ray = false;
|
||||
HashSet<RID> exclude_bodies;
|
||||
HashSet<ObjectID> exclude_objects;
|
||||
bool recovery_as_collision = false;
|
||||
|
||||
MotionParameters() {}
|
||||
|
||||
MotionParameters(const Transform2D &p_from, const Vector2 &p_motion, real_t p_margin = 0.08) :
|
||||
from(p_from),
|
||||
motion(p_motion),
|
||||
margin(p_margin) {}
|
||||
};
|
||||
|
||||
struct MotionResult {
|
||||
Vector2 travel;
|
||||
Vector2 remainder;
|
||||
|
||||
Vector2 collision_point;
|
||||
Vector2 collision_normal;
|
||||
Vector2 collider_velocity;
|
||||
real_t collision_depth = 0.0;
|
||||
real_t collision_safe_fraction = 0.0;
|
||||
real_t collision_unsafe_fraction = 0.0;
|
||||
int collision_local_shape = 0;
|
||||
ObjectID collider_id;
|
||||
RID collider;
|
||||
int collider_shape = 0;
|
||||
|
||||
real_t get_angle(Vector2 p_up_direction) const {
|
||||
return Math::acos(collision_normal.dot(p_up_direction));
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) = 0;
|
||||
|
||||
/* JOINT API */
|
||||
|
||||
virtual RID joint_create() = 0;
|
||||
|
||||
virtual void joint_clear(RID p_joint) = 0;
|
||||
|
||||
enum JointType {
|
||||
JOINT_TYPE_PIN,
|
||||
JOINT_TYPE_GROOVE,
|
||||
JOINT_TYPE_DAMPED_SPRING,
|
||||
JOINT_TYPE_MAX
|
||||
};
|
||||
|
||||
enum JointParam {
|
||||
JOINT_PARAM_BIAS,
|
||||
JOINT_PARAM_MAX_BIAS,
|
||||
JOINT_PARAM_MAX_FORCE,
|
||||
};
|
||||
|
||||
virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value) = 0;
|
||||
virtual real_t joint_get_param(RID p_joint, JointParam p_param) const = 0;
|
||||
|
||||
virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) = 0;
|
||||
virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const = 0;
|
||||
|
||||
virtual void joint_make_pin(RID p_joint, const Vector2 &p_anchor, RID p_body_a, RID p_body_b = RID()) = 0;
|
||||
virtual void 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) = 0;
|
||||
virtual void 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 = RID()) = 0;
|
||||
|
||||
enum PinJointParam {
|
||||
PIN_JOINT_SOFTNESS,
|
||||
PIN_JOINT_LIMIT_UPPER,
|
||||
PIN_JOINT_LIMIT_LOWER,
|
||||
PIN_JOINT_MOTOR_TARGET_VELOCITY
|
||||
};
|
||||
|
||||
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) = 0;
|
||||
virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const = 0;
|
||||
|
||||
enum PinJointFlag {
|
||||
PIN_JOINT_FLAG_ANGULAR_LIMIT_ENABLED,
|
||||
PIN_JOINT_FLAG_MOTOR_ENABLED
|
||||
};
|
||||
|
||||
virtual void pin_joint_set_flag(RID p_joint, PinJointFlag p_flag, bool p_enabled) = 0;
|
||||
virtual bool pin_joint_get_flag(RID p_joint, PinJointFlag p_flag) const = 0;
|
||||
|
||||
enum DampedSpringParam {
|
||||
DAMPED_SPRING_REST_LENGTH,
|
||||
DAMPED_SPRING_STIFFNESS,
|
||||
DAMPED_SPRING_DAMPING
|
||||
};
|
||||
virtual void damped_spring_joint_set_param(RID p_joint, DampedSpringParam p_param, real_t p_value) = 0;
|
||||
virtual real_t damped_spring_joint_get_param(RID p_joint, DampedSpringParam p_param) const = 0;
|
||||
|
||||
virtual JointType joint_get_type(RID p_joint) const = 0;
|
||||
|
||||
/* QUERY API */
|
||||
|
||||
enum AreaBodyStatus {
|
||||
AREA_BODY_ADDED,
|
||||
AREA_BODY_REMOVED
|
||||
};
|
||||
|
||||
/* MISC */
|
||||
|
||||
virtual void free_rid(RID p_rid) = 0;
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
[[deprecated("Use `free_rid()` instead.")]] void free(RID p_rid) {
|
||||
free_rid(p_rid);
|
||||
}
|
||||
#endif // DISABLE_DEPRECATED
|
||||
|
||||
virtual void set_active(bool p_active) = 0;
|
||||
virtual void init() = 0;
|
||||
virtual void step(real_t p_step) = 0;
|
||||
virtual void sync() = 0;
|
||||
virtual void flush_queries() = 0;
|
||||
virtual void end_sync() = 0;
|
||||
virtual void finish() = 0;
|
||||
|
||||
virtual bool is_flushing_queries() const = 0;
|
||||
|
||||
enum ProcessInfo {
|
||||
INFO_ACTIVE_OBJECTS,
|
||||
INFO_COLLISION_PAIRS,
|
||||
INFO_ISLAND_COUNT
|
||||
};
|
||||
|
||||
virtual int get_process_info(ProcessInfo p_info) = 0;
|
||||
|
||||
PhysicsServer2D();
|
||||
~PhysicsServer2D();
|
||||
};
|
||||
|
||||
class PhysicsRayQueryParameters2D : public RefCounted {
|
||||
GDCLASS(PhysicsRayQueryParameters2D, RefCounted);
|
||||
|
||||
PhysicsDirectSpaceState2D::RayParameters parameters;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static Ref<PhysicsRayQueryParameters2D> create(Vector2 p_from, Vector2 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude);
|
||||
const PhysicsDirectSpaceState2D::RayParameters &get_parameters() const { return parameters; }
|
||||
|
||||
void set_from(const Vector2 &p_from) { parameters.from = p_from; }
|
||||
const Vector2 &get_from() const { return parameters.from; }
|
||||
|
||||
void set_to(const Vector2 &p_to) { parameters.to = p_to; }
|
||||
const Vector2 &get_to() const { return parameters.to; }
|
||||
|
||||
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
|
||||
uint32_t get_collision_mask() const { return parameters.collision_mask; }
|
||||
|
||||
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
|
||||
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
|
||||
|
||||
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
|
||||
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
|
||||
|
||||
void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; }
|
||||
bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; }
|
||||
|
||||
void set_exclude(const TypedArray<RID> &p_exclude);
|
||||
TypedArray<RID> get_exclude() const;
|
||||
};
|
||||
|
||||
class PhysicsPointQueryParameters2D : public RefCounted {
|
||||
GDCLASS(PhysicsPointQueryParameters2D, RefCounted);
|
||||
|
||||
PhysicsDirectSpaceState2D::PointParameters parameters;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
const PhysicsDirectSpaceState2D::PointParameters &get_parameters() const { return parameters; }
|
||||
|
||||
void set_position(const Vector2 &p_position) { parameters.position = p_position; }
|
||||
const Vector2 &get_position() const { return parameters.position; }
|
||||
|
||||
void set_canvas_instance_id(ObjectID p_canvas_instance_id) { parameters.canvas_instance_id = p_canvas_instance_id; }
|
||||
ObjectID get_canvas_instance_id() const { return parameters.canvas_instance_id; }
|
||||
|
||||
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
|
||||
uint32_t get_collision_mask() const { return parameters.collision_mask; }
|
||||
|
||||
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
|
||||
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
|
||||
|
||||
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
|
||||
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
|
||||
|
||||
void set_exclude(const TypedArray<RID> &p_exclude);
|
||||
TypedArray<RID> get_exclude() const;
|
||||
};
|
||||
|
||||
class PhysicsShapeQueryParameters2D : public RefCounted {
|
||||
GDCLASS(PhysicsShapeQueryParameters2D, RefCounted);
|
||||
|
||||
PhysicsDirectSpaceState2D::ShapeParameters parameters;
|
||||
|
||||
Ref<Resource> shape_ref;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
const PhysicsDirectSpaceState2D::ShapeParameters &get_parameters() const { return parameters; }
|
||||
|
||||
void set_shape(const Ref<Resource> &p_shape_ref);
|
||||
Ref<Resource> get_shape() const { return shape_ref; }
|
||||
|
||||
void set_shape_rid(const RID &p_shape);
|
||||
RID get_shape_rid() const { return parameters.shape_rid; }
|
||||
|
||||
void set_transform(const Transform2D &p_transform) { parameters.transform = p_transform; }
|
||||
const Transform2D &get_transform() const { return parameters.transform; }
|
||||
|
||||
void set_motion(const Vector2 &p_motion) { parameters.motion = p_motion; }
|
||||
const Vector2 &get_motion() const { return parameters.motion; }
|
||||
|
||||
void set_margin(real_t p_margin) { parameters.margin = p_margin; }
|
||||
real_t get_margin() const { return parameters.margin; }
|
||||
|
||||
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
|
||||
uint32_t get_collision_mask() const { return parameters.collision_mask; }
|
||||
|
||||
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
|
||||
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
|
||||
|
||||
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
|
||||
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
|
||||
|
||||
void set_exclude(const TypedArray<RID> &p_exclude);
|
||||
TypedArray<RID> get_exclude() const;
|
||||
};
|
||||
|
||||
class PhysicsTestMotionParameters2D : public RefCounted {
|
||||
GDCLASS(PhysicsTestMotionParameters2D, RefCounted);
|
||||
|
||||
PhysicsServer2D::MotionParameters parameters;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
const PhysicsServer2D::MotionParameters &get_parameters() const { return parameters; }
|
||||
|
||||
const Transform2D &get_from() const { return parameters.from; }
|
||||
void set_from(const Transform2D &p_from) { parameters.from = p_from; }
|
||||
|
||||
const Vector2 &get_motion() const { return parameters.motion; }
|
||||
void set_motion(const Vector2 &p_motion) { parameters.motion = p_motion; }
|
||||
|
||||
real_t get_margin() const { return parameters.margin; }
|
||||
void set_margin(real_t p_margin) { parameters.margin = p_margin; }
|
||||
|
||||
bool is_collide_separation_ray_enabled() const { return parameters.collide_separation_ray; }
|
||||
void set_collide_separation_ray_enabled(bool p_enabled) { parameters.collide_separation_ray = p_enabled; }
|
||||
|
||||
TypedArray<RID> get_exclude_bodies() const;
|
||||
void set_exclude_bodies(const TypedArray<RID> &p_exclude);
|
||||
|
||||
TypedArray<uint64_t> get_exclude_objects() const;
|
||||
void set_exclude_objects(const TypedArray<uint64_t> &p_exclude);
|
||||
|
||||
bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; }
|
||||
void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }
|
||||
};
|
||||
|
||||
class PhysicsTestMotionResult2D : public RefCounted {
|
||||
GDCLASS(PhysicsTestMotionResult2D, RefCounted);
|
||||
|
||||
PhysicsServer2D::MotionResult result;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
PhysicsServer2D::MotionResult *get_result_ptr() { return &result; }
|
||||
|
||||
Vector2 get_travel() const;
|
||||
Vector2 get_remainder() const;
|
||||
|
||||
Vector2 get_collision_point() const;
|
||||
Vector2 get_collision_normal() const;
|
||||
Vector2 get_collider_velocity() const;
|
||||
ObjectID get_collider_id() const;
|
||||
RID get_collider_rid() const;
|
||||
Object *get_collider() const;
|
||||
int get_collider_shape() const;
|
||||
int get_collision_local_shape() const;
|
||||
real_t get_collision_depth() const;
|
||||
real_t get_collision_safe_fraction() const;
|
||||
real_t get_collision_unsafe_fraction() const;
|
||||
};
|
||||
|
||||
class PhysicsServer2DManager : public Object {
|
||||
GDCLASS(PhysicsServer2DManager, Object);
|
||||
|
||||
static PhysicsServer2DManager *singleton;
|
||||
|
||||
struct ClassInfo {
|
||||
String name;
|
||||
Callable create_callback;
|
||||
|
||||
ClassInfo() {}
|
||||
|
||||
ClassInfo(String p_name, Callable p_create_callback) :
|
||||
name(p_name),
|
||||
create_callback(p_create_callback) {}
|
||||
|
||||
ClassInfo(const ClassInfo &p_ci) :
|
||||
name(p_ci.name),
|
||||
create_callback(p_ci.create_callback) {}
|
||||
|
||||
void operator=(const ClassInfo &p_ci) {
|
||||
name = p_ci.name;
|
||||
create_callback = p_ci.create_callback;
|
||||
}
|
||||
};
|
||||
|
||||
Vector<ClassInfo> physics_2d_servers;
|
||||
int default_server_id = -1;
|
||||
int default_server_priority = -1;
|
||||
|
||||
void on_servers_changed();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
static const String setting_property_name;
|
||||
|
||||
static PhysicsServer2DManager *get_singleton();
|
||||
|
||||
void register_server(const String &p_name, const Callable &p_create_callback);
|
||||
void set_default_server(const String &p_name, int p_priority = 0);
|
||||
int find_server_id(const String &p_name);
|
||||
int get_servers_count();
|
||||
String get_server_name(int p_id);
|
||||
PhysicsServer2D *new_default_server();
|
||||
PhysicsServer2D *new_server(const String &p_name);
|
||||
|
||||
PhysicsServer2DManager();
|
||||
~PhysicsServer2DManager();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::ShapeType);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::SpaceParameter);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::AreaParameter);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::AreaSpaceOverrideMode);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::BodyMode);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::BodyParameter);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::BodyDampMode);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::BodyState);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::JointParam);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::JointType);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::PinJointParam);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::PinJointFlag);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus);
|
||||
VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo);
|
||||
353
servers/physics_2d/physics_server_2d_dummy.h
Normal file
353
servers/physics_2d/physics_server_2d_dummy.h
Normal file
@ -0,0 +1,353 @@
|
||||
/**************************************************************************/
|
||||
/* physics_server_2d_dummy.h */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "physics_server_2d.h"
|
||||
|
||||
class PhysicsDirectBodyState2DDummy : public PhysicsDirectBodyState2D {
|
||||
GDCLASS(PhysicsDirectBodyState2DDummy, PhysicsDirectBodyState2D);
|
||||
|
||||
PhysicsDirectSpaceState2D *space_state_dummy = nullptr;
|
||||
|
||||
public:
|
||||
virtual Vector2 get_total_gravity() const override { return Vector2(); }
|
||||
virtual real_t get_total_linear_damp() const override { return 0; }
|
||||
virtual real_t get_total_angular_damp() const override { return 0; }
|
||||
|
||||
virtual Vector2 get_center_of_mass() const override { return Vector2(); }
|
||||
virtual Vector2 get_center_of_mass_local() const override { return Vector2(); }
|
||||
virtual real_t get_inverse_mass() const override { return 0; }
|
||||
virtual real_t get_inverse_inertia() const override { return 0; }
|
||||
|
||||
virtual void set_linear_velocity(const Vector2 &p_velocity) override {}
|
||||
virtual Vector2 get_linear_velocity() const override { return Vector2(); }
|
||||
|
||||
virtual void set_angular_velocity(real_t p_velocity) override {}
|
||||
virtual real_t get_angular_velocity() const override { return 0; }
|
||||
|
||||
virtual void set_transform(const Transform2D &p_transform) override {}
|
||||
virtual Transform2D get_transform() const override { return Transform2D(); }
|
||||
|
||||
virtual Vector2 get_velocity_at_local_position(const Vector2 &p_position) const override { return Vector2(); }
|
||||
|
||||
virtual void apply_central_impulse(const Vector2 &p_impulse) override {}
|
||||
virtual void apply_torque_impulse(real_t p_torque) override {}
|
||||
virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) override {}
|
||||
|
||||
virtual void apply_central_force(const Vector2 &p_force) override {}
|
||||
virtual void apply_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
|
||||
virtual void apply_torque(real_t p_torque) override {}
|
||||
|
||||
virtual void add_constant_central_force(const Vector2 &p_force) override {}
|
||||
virtual void add_constant_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
|
||||
virtual void add_constant_torque(real_t p_torque) override {}
|
||||
|
||||
virtual void set_constant_force(const Vector2 &p_force) override {}
|
||||
virtual Vector2 get_constant_force() const override { return Vector2(); }
|
||||
|
||||
virtual void set_constant_torque(real_t p_torque) override {}
|
||||
virtual real_t get_constant_torque() const override { return 0; }
|
||||
|
||||
virtual void set_sleep_state(bool p_enable) override {}
|
||||
virtual bool is_sleeping() const override { return false; }
|
||||
|
||||
virtual void set_collision_layer(uint32_t p_layer) override {}
|
||||
virtual uint32_t get_collision_layer() const override { return 0; }
|
||||
|
||||
virtual void set_collision_mask(uint32_t p_mask) override {}
|
||||
virtual uint32_t get_collision_mask() const override { return 0; }
|
||||
|
||||
virtual int get_contact_count() const override { return 0; }
|
||||
|
||||
virtual Vector2 get_contact_local_position(int p_contact_idx) const override { return Vector2(); }
|
||||
virtual Vector2 get_contact_local_normal(int p_contact_idx) const override { return Vector2(); }
|
||||
virtual int get_contact_local_shape(int p_contact_idx) const override { return 0; }
|
||||
virtual Vector2 get_contact_local_velocity_at_position(int p_contact_idx) const override { return Vector2(); }
|
||||
|
||||
virtual RID get_contact_collider(int p_contact_idx) const override { return RID(); }
|
||||
virtual Vector2 get_contact_collider_position(int p_contact_idx) const override { return Vector2(); }
|
||||
virtual ObjectID get_contact_collider_id(int p_contact_idx) const override { return ObjectID(); }
|
||||
virtual Object *get_contact_collider_object(int p_contact_idx) const override { return nullptr; }
|
||||
virtual int get_contact_collider_shape(int p_contact_idx) const override { return 0; }
|
||||
virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const override { return Vector2(); }
|
||||
virtual Vector2 get_contact_impulse(int p_contact_idx) const override { return Vector2(); }
|
||||
|
||||
virtual real_t get_step() const override { return 0; }
|
||||
virtual void integrate_forces() override {}
|
||||
|
||||
virtual PhysicsDirectSpaceState2D *get_space_state() override { return space_state_dummy; }
|
||||
|
||||
PhysicsDirectBodyState2DDummy(PhysicsDirectSpaceState2D *p_space_state_dummy) {
|
||||
space_state_dummy = p_space_state_dummy;
|
||||
}
|
||||
};
|
||||
|
||||
class PhysicsDirectSpaceState2DDummy : public PhysicsDirectSpaceState2D {
|
||||
GDCLASS(PhysicsDirectSpaceState2DDummy, PhysicsDirectSpaceState2D);
|
||||
|
||||
public:
|
||||
virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) override { return false; }
|
||||
|
||||
virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; }
|
||||
|
||||
virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) override { return 0; }
|
||||
virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) override { return false; }
|
||||
virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) override { return false; }
|
||||
virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) override { return false; }
|
||||
};
|
||||
|
||||
class PhysicsServer2DDummy : public PhysicsServer2D {
|
||||
GDCLASS(PhysicsServer2DDummy, PhysicsServer2D);
|
||||
|
||||
PhysicsDirectSpaceState2DDummy *space_state_dummy = nullptr;
|
||||
PhysicsDirectBodyState2DDummy *body_state_dummy = nullptr;
|
||||
|
||||
public:
|
||||
virtual RID world_boundary_shape_create() override { return RID(); }
|
||||
virtual RID separation_ray_shape_create() override { return RID(); }
|
||||
virtual RID segment_shape_create() override { return RID(); }
|
||||
virtual RID circle_shape_create() override { return RID(); }
|
||||
virtual RID rectangle_shape_create() override { return RID(); }
|
||||
virtual RID capsule_shape_create() override { return RID(); }
|
||||
virtual RID convex_polygon_shape_create() override { return RID(); }
|
||||
virtual RID concave_polygon_shape_create() override { return RID(); }
|
||||
|
||||
virtual void shape_set_data(RID p_shape, const Variant &p_data) override {}
|
||||
virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) override {}
|
||||
|
||||
virtual ShapeType shape_get_type(RID p_shape) const override { return ShapeType::SHAPE_CIRCLE; }
|
||||
virtual Variant shape_get_data(RID p_shape) const override { return Variant(); }
|
||||
virtual real_t shape_get_custom_solver_bias(RID p_shape) const override { return 0; }
|
||||
|
||||
virtual bool 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) override { return false; }
|
||||
|
||||
/* SPACE API */
|
||||
|
||||
virtual RID space_create() override { return RID(); }
|
||||
virtual void space_set_active(RID p_space, bool p_active) override {}
|
||||
virtual bool space_is_active(RID p_space) const override { return false; }
|
||||
|
||||
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) override {}
|
||||
virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const override { return 0; }
|
||||
|
||||
virtual PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) override { return space_state_dummy; }
|
||||
|
||||
virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) override {}
|
||||
virtual Vector<Vector2> space_get_contacts(RID p_space) const override { return Vector<Vector2>(); }
|
||||
virtual int space_get_contact_count(RID p_space) const override { return 0; }
|
||||
|
||||
/* AREA API */
|
||||
|
||||
virtual RID area_create() override { return RID(); }
|
||||
|
||||
virtual void area_set_space(RID p_area, RID p_space) override {}
|
||||
virtual RID area_get_space(RID p_area) const override { return RID(); }
|
||||
|
||||
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) override {}
|
||||
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) override {}
|
||||
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) override {}
|
||||
|
||||
virtual int area_get_shape_count(RID p_area) const override { return 0; }
|
||||
virtual RID area_get_shape(RID p_area, int p_shape_idx) const override { return RID(); }
|
||||
virtual Transform2D area_get_shape_transform(RID p_area, int p_shape_idx) const override { return Transform2D(); }
|
||||
|
||||
virtual void area_remove_shape(RID p_area, int p_shape_idx) override {}
|
||||
virtual void area_clear_shapes(RID p_area) override {}
|
||||
|
||||
virtual void area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) override {}
|
||||
|
||||
virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) override {}
|
||||
virtual ObjectID area_get_object_instance_id(RID p_area) const override { return ObjectID(); }
|
||||
|
||||
virtual void area_attach_canvas_instance_id(RID p_area, ObjectID p_id) override {}
|
||||
virtual ObjectID area_get_canvas_instance_id(RID p_area) const override { return ObjectID(); }
|
||||
|
||||
virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) override {}
|
||||
virtual void area_set_transform(RID p_area, const Transform2D &p_transform) override {}
|
||||
|
||||
virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const override { return Variant(); }
|
||||
virtual Transform2D area_get_transform(RID p_area) const override { return Transform2D(); }
|
||||
|
||||
virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override {}
|
||||
virtual uint32_t area_get_collision_layer(RID p_area) const override { return 0; }
|
||||
|
||||
virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override {}
|
||||
virtual uint32_t area_get_collision_mask(RID p_area) const override { return 0; }
|
||||
|
||||
virtual void area_set_monitorable(RID p_area, bool p_monitorable) override {}
|
||||
virtual void area_set_pickable(RID p_area, bool p_pickable) override {}
|
||||
|
||||
virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) override {}
|
||||
virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) override {}
|
||||
|
||||
/* BODY API */
|
||||
|
||||
virtual RID body_create() override { return RID(); }
|
||||
|
||||
virtual void body_set_space(RID p_body, RID p_space) override {}
|
||||
virtual RID body_get_space(RID p_body) const override { return RID(); }
|
||||
|
||||
virtual void body_set_mode(RID p_body, BodyMode p_mode) override {}
|
||||
virtual BodyMode body_get_mode(RID p_body) const override { return BodyMode::BODY_MODE_STATIC; }
|
||||
|
||||
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) override {}
|
||||
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) override {}
|
||||
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) override {}
|
||||
|
||||
virtual int body_get_shape_count(RID p_body) const override { return 0; }
|
||||
virtual RID body_get_shape(RID p_body, int p_shape_idx) const override { return RID(); }
|
||||
virtual Transform2D body_get_shape_transform(RID p_body, int p_shape_idx) const override { return Transform2D(); }
|
||||
|
||||
virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) override {}
|
||||
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, real_t p_margin = 0) override {}
|
||||
|
||||
virtual void body_remove_shape(RID p_body, int p_shape_idx) override {}
|
||||
virtual void body_clear_shapes(RID p_body) override {}
|
||||
|
||||
virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) override {}
|
||||
virtual ObjectID body_get_object_instance_id(RID p_body) const override { return ObjectID(); }
|
||||
|
||||
virtual void body_attach_canvas_instance_id(RID p_body, ObjectID p_id) override {}
|
||||
virtual ObjectID body_get_canvas_instance_id(RID p_body) const override { return ObjectID(); }
|
||||
|
||||
virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) override {}
|
||||
virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const override { return CCDMode::CCD_MODE_DISABLED; }
|
||||
|
||||
virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) override {}
|
||||
virtual uint32_t body_get_collision_layer(RID p_body) const override { return 0; }
|
||||
|
||||
virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) override {}
|
||||
virtual uint32_t body_get_collision_mask(RID p_body) const override { return 0; }
|
||||
|
||||
virtual void body_set_collision_priority(RID p_body, real_t p_priority) override {}
|
||||
virtual real_t body_get_collision_priority(RID p_body) const override { return 0; }
|
||||
|
||||
virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) override {}
|
||||
virtual Variant body_get_param(RID p_body, BodyParameter p_param) const override { return Variant(); }
|
||||
|
||||
virtual void body_reset_mass_properties(RID p_body) override {}
|
||||
|
||||
virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override {}
|
||||
virtual Variant body_get_state(RID p_body, BodyState p_state) const override { return Variant(); }
|
||||
|
||||
virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) override {}
|
||||
virtual void body_apply_torque_impulse(RID p_body, real_t p_torque) override {}
|
||||
virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) override {}
|
||||
|
||||
virtual void body_apply_central_force(RID p_body, const Vector2 &p_force) override {}
|
||||
virtual void body_apply_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
|
||||
virtual void body_apply_torque(RID p_body, real_t p_torque) override {}
|
||||
|
||||
virtual void body_add_constant_central_force(RID p_body, const Vector2 &p_force) override {}
|
||||
virtual void body_add_constant_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) override {}
|
||||
virtual void body_add_constant_torque(RID p_body, real_t p_torque) override {}
|
||||
|
||||
virtual void body_set_constant_force(RID p_body, const Vector2 &p_force) override {}
|
||||
virtual Vector2 body_get_constant_force(RID p_body) const override { return Vector2(); }
|
||||
|
||||
virtual void body_set_constant_torque(RID p_body, real_t p_torque) override {}
|
||||
virtual real_t body_get_constant_torque(RID p_body) const override { return 0; }
|
||||
|
||||
virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) override {}
|
||||
|
||||
virtual void body_add_collision_exception(RID p_body, RID p_body_b) override {}
|
||||
virtual void body_remove_collision_exception(RID p_body, RID p_body_b) override {}
|
||||
virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override {}
|
||||
|
||||
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override {}
|
||||
virtual int body_get_max_contacts_reported(RID p_body) const override { return 0; }
|
||||
|
||||
virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) override {}
|
||||
virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const override { return 0; }
|
||||
|
||||
virtual void body_set_omit_force_integration(RID p_body, bool p_omit) override {}
|
||||
virtual bool body_is_omitting_force_integration(RID p_body) const override { return false; }
|
||||
|
||||
virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) override {}
|
||||
virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) override {}
|
||||
|
||||
virtual bool 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) override { return false; }
|
||||
|
||||
virtual void body_set_pickable(RID p_body, bool p_pickable) override {}
|
||||
|
||||
virtual PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) override { return body_state_dummy; }
|
||||
|
||||
virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override { return false; }
|
||||
|
||||
/* JOINT API */
|
||||
|
||||
virtual RID joint_create() override { return RID(); }
|
||||
|
||||
virtual void joint_clear(RID p_joint) override {}
|
||||
|
||||
virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value) override {}
|
||||
virtual real_t joint_get_param(RID p_joint, JointParam p_param) const override { return 0; }
|
||||
|
||||
virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) override {}
|
||||
virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const override { return false; }
|
||||
|
||||
virtual void joint_make_pin(RID p_joint, const Vector2 &p_anchor, RID p_body_a, RID p_body_b = RID()) override {}
|
||||
virtual void 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) override {}
|
||||
virtual void 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 = RID()) override {}
|
||||
|
||||
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) override {}
|
||||
virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const override { return 0; }
|
||||
|
||||
virtual void pin_joint_set_flag(RID p_joint, PinJointFlag p_flag, bool p_enabled) override {}
|
||||
virtual bool pin_joint_get_flag(RID p_joint, PinJointFlag p_flag) const override { return false; }
|
||||
|
||||
virtual void damped_spring_joint_set_param(RID p_joint, DampedSpringParam p_param, real_t p_value) override {}
|
||||
virtual real_t damped_spring_joint_get_param(RID p_joint, DampedSpringParam p_param) const override { return 0; }
|
||||
|
||||
virtual JointType joint_get_type(RID p_joint) const override { return JointType::JOINT_TYPE_PIN; }
|
||||
|
||||
/* MISC */
|
||||
|
||||
virtual void free_rid(RID p_rid) override {}
|
||||
|
||||
virtual void set_active(bool p_active) override {}
|
||||
virtual void init() override {
|
||||
space_state_dummy = memnew(PhysicsDirectSpaceState2DDummy);
|
||||
body_state_dummy = memnew(PhysicsDirectBodyState2DDummy(space_state_dummy));
|
||||
}
|
||||
virtual void step(real_t p_step) override {}
|
||||
virtual void sync() override {}
|
||||
virtual void flush_queries() override {}
|
||||
virtual void end_sync() override {}
|
||||
virtual void finish() override {
|
||||
memdelete(body_state_dummy);
|
||||
memdelete(space_state_dummy);
|
||||
}
|
||||
|
||||
virtual bool is_flushing_queries() const override { return false; }
|
||||
|
||||
virtual int get_process_info(ProcessInfo p_info) override { return 0; }
|
||||
};
|
||||
357
servers/physics_2d/physics_server_2d_extension.cpp
Normal file
357
servers/physics_2d/physics_server_2d_extension.cpp
Normal file
@ -0,0 +1,357 @@
|
||||
/**************************************************************************/
|
||||
/* physics_server_2d_extension.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 "physics_server_2d_extension.h"
|
||||
|
||||
bool PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query(const RID &p_body) const {
|
||||
return exclude && exclude->has(p_body);
|
||||
}
|
||||
|
||||
thread_local const HashSet<RID> *PhysicsDirectSpaceState2DExtension::exclude = nullptr;
|
||||
|
||||
void PhysicsDirectSpaceState2DExtension::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("is_body_excluded_from_query", "body"), &PhysicsDirectSpaceState2DExtension::is_body_excluded_from_query);
|
||||
|
||||
GDVIRTUAL_BIND(_intersect_ray, "from", "to", "collision_mask", "collide_with_bodies", "collide_with_areas", "hit_from_inside", "result");
|
||||
GDVIRTUAL_BIND(_intersect_point, "position", "canvas_instance_id", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results");
|
||||
GDVIRTUAL_BIND(_intersect_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "result", "max_results");
|
||||
GDVIRTUAL_BIND(_cast_motion, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "closest_safe", "closest_unsafe");
|
||||
GDVIRTUAL_BIND(_collide_shape, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "results", "max_results", "result_count");
|
||||
GDVIRTUAL_BIND(_rest_info, "shape_rid", "transform", "motion", "margin", "collision_mask", "collide_with_bodies", "collide_with_areas", "rest_info");
|
||||
}
|
||||
|
||||
PhysicsDirectSpaceState2DExtension::PhysicsDirectSpaceState2DExtension() {
|
||||
}
|
||||
|
||||
void PhysicsDirectBodyState2DExtension::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_get_total_gravity);
|
||||
GDVIRTUAL_BIND(_get_total_linear_damp);
|
||||
GDVIRTUAL_BIND(_get_total_angular_damp);
|
||||
|
||||
GDVIRTUAL_BIND(_get_center_of_mass);
|
||||
GDVIRTUAL_BIND(_get_center_of_mass_local);
|
||||
GDVIRTUAL_BIND(_get_inverse_mass);
|
||||
GDVIRTUAL_BIND(_get_inverse_inertia);
|
||||
|
||||
GDVIRTUAL_BIND(_set_linear_velocity, "velocity");
|
||||
GDVIRTUAL_BIND(_get_linear_velocity);
|
||||
|
||||
GDVIRTUAL_BIND(_set_angular_velocity, "velocity");
|
||||
GDVIRTUAL_BIND(_get_angular_velocity);
|
||||
|
||||
GDVIRTUAL_BIND(_set_transform, "transform");
|
||||
GDVIRTUAL_BIND(_get_transform);
|
||||
|
||||
GDVIRTUAL_BIND(_get_velocity_at_local_position, "local_position");
|
||||
|
||||
GDVIRTUAL_BIND(_apply_central_impulse, "impulse");
|
||||
GDVIRTUAL_BIND(_apply_impulse, "impulse", "position");
|
||||
GDVIRTUAL_BIND(_apply_torque_impulse, "impulse");
|
||||
|
||||
GDVIRTUAL_BIND(_apply_central_force, "force");
|
||||
GDVIRTUAL_BIND(_apply_force, "force", "position");
|
||||
GDVIRTUAL_BIND(_apply_torque, "torque");
|
||||
|
||||
GDVIRTUAL_BIND(_add_constant_central_force, "force");
|
||||
GDVIRTUAL_BIND(_add_constant_force, "force", "position");
|
||||
GDVIRTUAL_BIND(_add_constant_torque, "torque");
|
||||
|
||||
GDVIRTUAL_BIND(_set_constant_force, "force");
|
||||
GDVIRTUAL_BIND(_get_constant_force);
|
||||
|
||||
GDVIRTUAL_BIND(_set_constant_torque, "torque");
|
||||
GDVIRTUAL_BIND(_get_constant_torque);
|
||||
|
||||
GDVIRTUAL_BIND(_set_sleep_state, "enabled");
|
||||
GDVIRTUAL_BIND(_is_sleeping);
|
||||
|
||||
GDVIRTUAL_BIND(_set_collision_layer, "layer");
|
||||
GDVIRTUAL_BIND(_get_collision_layer);
|
||||
|
||||
GDVIRTUAL_BIND(_set_collision_mask, "mask");
|
||||
GDVIRTUAL_BIND(_get_collision_mask);
|
||||
|
||||
GDVIRTUAL_BIND(_get_contact_count);
|
||||
|
||||
GDVIRTUAL_BIND(_get_contact_local_position, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_local_normal, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_local_shape, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_local_velocity_at_position, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_collider, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_collider_position, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_collider_id, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_collider_object, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_collider_shape, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_collider_velocity_at_position, "contact_idx");
|
||||
GDVIRTUAL_BIND(_get_contact_impulse, "contact_idx");
|
||||
|
||||
GDVIRTUAL_BIND(_get_step);
|
||||
GDVIRTUAL_BIND(_integrate_forces);
|
||||
|
||||
GDVIRTUAL_BIND(_get_space_state);
|
||||
}
|
||||
|
||||
PhysicsDirectBodyState2DExtension::PhysicsDirectBodyState2DExtension() {
|
||||
}
|
||||
|
||||
thread_local const HashSet<RID> *PhysicsServer2DExtension::exclude_bodies = nullptr;
|
||||
thread_local const HashSet<ObjectID> *PhysicsServer2DExtension::exclude_objects = nullptr;
|
||||
|
||||
bool PhysicsServer2DExtension::body_test_motion_is_excluding_body(RID p_body) const {
|
||||
return exclude_bodies && exclude_bodies->has(p_body);
|
||||
}
|
||||
|
||||
bool PhysicsServer2DExtension::body_test_motion_is_excluding_object(ObjectID p_object) const {
|
||||
return exclude_objects && exclude_objects->has(p_object);
|
||||
}
|
||||
|
||||
void PhysicsServer2DExtension::_bind_methods() {
|
||||
/* SHAPE API */
|
||||
|
||||
GDVIRTUAL_BIND(_world_boundary_shape_create);
|
||||
GDVIRTUAL_BIND(_separation_ray_shape_create);
|
||||
GDVIRTUAL_BIND(_segment_shape_create);
|
||||
GDVIRTUAL_BIND(_circle_shape_create);
|
||||
GDVIRTUAL_BIND(_rectangle_shape_create);
|
||||
GDVIRTUAL_BIND(_capsule_shape_create);
|
||||
GDVIRTUAL_BIND(_convex_polygon_shape_create);
|
||||
GDVIRTUAL_BIND(_concave_polygon_shape_create);
|
||||
|
||||
GDVIRTUAL_BIND(_shape_set_data, "shape", "data");
|
||||
GDVIRTUAL_BIND(_shape_set_custom_solver_bias, "shape", "bias");
|
||||
|
||||
GDVIRTUAL_BIND(_shape_get_type, "shape");
|
||||
GDVIRTUAL_BIND(_shape_get_data, "shape");
|
||||
GDVIRTUAL_BIND(_shape_get_custom_solver_bias, "shape");
|
||||
GDVIRTUAL_BIND(_shape_collide, "shape_A", "xform_A", "motion_A", "shape_B", "xform_B", "motion_B", "results", "result_max", "result_count");
|
||||
|
||||
/* SPACE API */
|
||||
|
||||
GDVIRTUAL_BIND(_space_create);
|
||||
GDVIRTUAL_BIND(_space_set_active, "space", "active");
|
||||
GDVIRTUAL_BIND(_space_is_active, "space");
|
||||
|
||||
GDVIRTUAL_BIND(_space_set_param, "space", "param", "value");
|
||||
GDVIRTUAL_BIND(_space_get_param, "space", "param");
|
||||
|
||||
GDVIRTUAL_BIND(_space_get_direct_state, "space");
|
||||
|
||||
GDVIRTUAL_BIND(_space_set_debug_contacts, "space", "max_contacts");
|
||||
GDVIRTUAL_BIND(_space_get_contacts, "space");
|
||||
GDVIRTUAL_BIND(_space_get_contact_count, "space");
|
||||
|
||||
/* AREA API */
|
||||
|
||||
GDVIRTUAL_BIND(_area_create);
|
||||
|
||||
GDVIRTUAL_BIND(_area_set_space, "area", "space");
|
||||
GDVIRTUAL_BIND(_area_get_space, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_add_shape, "area", "shape", "transform", "disabled");
|
||||
GDVIRTUAL_BIND(_area_set_shape, "area", "shape_idx", "shape");
|
||||
GDVIRTUAL_BIND(_area_set_shape_transform, "area", "shape_idx", "transform");
|
||||
GDVIRTUAL_BIND(_area_set_shape_disabled, "area", "shape_idx", "disabled");
|
||||
|
||||
GDVIRTUAL_BIND(_area_get_shape_count, "area");
|
||||
GDVIRTUAL_BIND(_area_get_shape, "area", "shape_idx");
|
||||
GDVIRTUAL_BIND(_area_get_shape_transform, "area", "shape_idx");
|
||||
|
||||
GDVIRTUAL_BIND(_area_remove_shape, "area", "shape_idx");
|
||||
GDVIRTUAL_BIND(_area_clear_shapes, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_attach_object_instance_id, "area", "id");
|
||||
GDVIRTUAL_BIND(_area_get_object_instance_id, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_attach_canvas_instance_id, "area", "id");
|
||||
GDVIRTUAL_BIND(_area_get_canvas_instance_id, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_set_param, "area", "param", "value");
|
||||
GDVIRTUAL_BIND(_area_set_transform, "area", "transform");
|
||||
|
||||
GDVIRTUAL_BIND(_area_get_param, "area", "param");
|
||||
GDVIRTUAL_BIND(_area_get_transform, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_set_collision_layer, "area", "layer");
|
||||
GDVIRTUAL_BIND(_area_get_collision_layer, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_set_collision_mask, "area", "mask");
|
||||
GDVIRTUAL_BIND(_area_get_collision_mask, "area");
|
||||
|
||||
GDVIRTUAL_BIND(_area_set_monitorable, "area", "monitorable");
|
||||
GDVIRTUAL_BIND(_area_set_pickable, "area", "pickable");
|
||||
|
||||
GDVIRTUAL_BIND(_area_set_monitor_callback, "area", "callback");
|
||||
GDVIRTUAL_BIND(_area_set_area_monitor_callback, "area", "callback");
|
||||
|
||||
/* BODY API */
|
||||
|
||||
ClassDB::bind_method(D_METHOD("body_test_motion_is_excluding_body", "body"), &PhysicsServer2DExtension::body_test_motion_is_excluding_body);
|
||||
ClassDB::bind_method(D_METHOD("body_test_motion_is_excluding_object", "object"), &PhysicsServer2DExtension::body_test_motion_is_excluding_object);
|
||||
|
||||
GDVIRTUAL_BIND(_body_create);
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_space, "body", "space");
|
||||
GDVIRTUAL_BIND(_body_get_space, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_mode, "body", "mode");
|
||||
GDVIRTUAL_BIND(_body_get_mode, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_add_shape, "body", "shape", "transform", "disabled");
|
||||
GDVIRTUAL_BIND(_body_set_shape, "body", "shape_idx", "shape");
|
||||
GDVIRTUAL_BIND(_body_set_shape_transform, "body", "shape_idx", "transform");
|
||||
|
||||
GDVIRTUAL_BIND(_body_get_shape_count, "body");
|
||||
GDVIRTUAL_BIND(_body_get_shape, "body", "shape_idx");
|
||||
GDVIRTUAL_BIND(_body_get_shape_transform, "body", "shape_idx");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_shape_disabled, "body", "shape_idx", "disabled");
|
||||
GDVIRTUAL_BIND(_body_set_shape_as_one_way_collision, "body", "shape_idx", "enable", "margin");
|
||||
|
||||
GDVIRTUAL_BIND(_body_remove_shape, "body", "shape_idx");
|
||||
GDVIRTUAL_BIND(_body_clear_shapes, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_attach_object_instance_id, "body", "id");
|
||||
GDVIRTUAL_BIND(_body_get_object_instance_id, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_attach_canvas_instance_id, "body", "id");
|
||||
GDVIRTUAL_BIND(_body_get_canvas_instance_id, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_continuous_collision_detection_mode, "body", "mode");
|
||||
GDVIRTUAL_BIND(_body_get_continuous_collision_detection_mode, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_collision_layer, "body", "layer");
|
||||
GDVIRTUAL_BIND(_body_get_collision_layer, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_collision_mask, "body", "mask");
|
||||
GDVIRTUAL_BIND(_body_get_collision_mask, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_collision_priority, "body", "priority");
|
||||
GDVIRTUAL_BIND(_body_get_collision_priority, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_param, "body", "param", "value");
|
||||
GDVIRTUAL_BIND(_body_get_param, "body", "param");
|
||||
|
||||
GDVIRTUAL_BIND(_body_reset_mass_properties, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_state, "body", "state", "value");
|
||||
GDVIRTUAL_BIND(_body_get_state, "body", "state");
|
||||
|
||||
GDVIRTUAL_BIND(_body_apply_central_impulse, "body", "impulse");
|
||||
GDVIRTUAL_BIND(_body_apply_torque_impulse, "body", "impulse");
|
||||
GDVIRTUAL_BIND(_body_apply_impulse, "body", "impulse", "position");
|
||||
|
||||
GDVIRTUAL_BIND(_body_apply_central_force, "body", "force");
|
||||
GDVIRTUAL_BIND(_body_apply_force, "body", "force", "position");
|
||||
GDVIRTUAL_BIND(_body_apply_torque, "body", "torque");
|
||||
|
||||
GDVIRTUAL_BIND(_body_add_constant_central_force, "body", "force");
|
||||
GDVIRTUAL_BIND(_body_add_constant_force, "body", "force", "position");
|
||||
GDVIRTUAL_BIND(_body_add_constant_torque, "body", "torque");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_constant_force, "body", "force");
|
||||
GDVIRTUAL_BIND(_body_get_constant_force, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_constant_torque, "body", "torque");
|
||||
GDVIRTUAL_BIND(_body_get_constant_torque, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_axis_velocity, "body", "axis_velocity");
|
||||
|
||||
GDVIRTUAL_BIND(_body_add_collision_exception, "body", "excepted_body");
|
||||
GDVIRTUAL_BIND(_body_remove_collision_exception, "body", "excepted_body");
|
||||
GDVIRTUAL_BIND(_body_get_collision_exceptions, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_max_contacts_reported, "body", "amount");
|
||||
GDVIRTUAL_BIND(_body_get_max_contacts_reported, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_contacts_reported_depth_threshold, "body", "threshold");
|
||||
GDVIRTUAL_BIND(_body_get_contacts_reported_depth_threshold, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_omit_force_integration, "body", "enable");
|
||||
GDVIRTUAL_BIND(_body_is_omitting_force_integration, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_state_sync_callback, "body", "callable");
|
||||
GDVIRTUAL_BIND(_body_set_force_integration_callback, "body", "callable", "userdata");
|
||||
|
||||
GDVIRTUAL_BIND(_body_collide_shape, "body", "body_shape", "shape", "shape_xform", "motion", "results", "result_max", "result_count");
|
||||
|
||||
GDVIRTUAL_BIND(_body_set_pickable, "body", "pickable");
|
||||
|
||||
GDVIRTUAL_BIND(_body_get_direct_state, "body");
|
||||
|
||||
GDVIRTUAL_BIND(_body_test_motion, "body", "from", "motion", "margin", "collide_separation_ray", "recovery_as_collision", "result");
|
||||
|
||||
/* JOINT API */
|
||||
|
||||
GDVIRTUAL_BIND(_joint_create);
|
||||
GDVIRTUAL_BIND(_joint_clear, "joint");
|
||||
|
||||
GDVIRTUAL_BIND(_joint_set_param, "joint", "param", "value");
|
||||
GDVIRTUAL_BIND(_joint_get_param, "joint", "param");
|
||||
|
||||
GDVIRTUAL_BIND(_joint_disable_collisions_between_bodies, "joint", "disable");
|
||||
GDVIRTUAL_BIND(_joint_is_disabled_collisions_between_bodies, "joint");
|
||||
|
||||
GDVIRTUAL_BIND(_joint_make_pin, "joint", "anchor", "body_a", "body_b");
|
||||
GDVIRTUAL_BIND(_joint_make_groove, "joint", "a_groove1", "a_groove2", "b_anchor", "body_a", "body_b");
|
||||
GDVIRTUAL_BIND(_joint_make_damped_spring, "joint", "anchor_a", "anchor_b", "body_a", "body_b");
|
||||
|
||||
GDVIRTUAL_BIND(_pin_joint_set_flag, "joint", "flag", "enabled");
|
||||
GDVIRTUAL_BIND(_pin_joint_get_flag, "joint", "flag");
|
||||
|
||||
GDVIRTUAL_BIND(_pin_joint_set_param, "joint", "param", "value");
|
||||
GDVIRTUAL_BIND(_pin_joint_get_param, "joint", "param");
|
||||
|
||||
GDVIRTUAL_BIND(_damped_spring_joint_set_param, "joint", "param", "value");
|
||||
GDVIRTUAL_BIND(_damped_spring_joint_get_param, "joint", "param");
|
||||
|
||||
GDVIRTUAL_BIND(_joint_get_type, "joint");
|
||||
|
||||
/* MISC */
|
||||
|
||||
GDVIRTUAL_BIND(_free_rid, "rid");
|
||||
|
||||
GDVIRTUAL_BIND(_set_active, "active");
|
||||
|
||||
GDVIRTUAL_BIND(_init);
|
||||
GDVIRTUAL_BIND(_step, "step");
|
||||
GDVIRTUAL_BIND(_sync);
|
||||
GDVIRTUAL_BIND(_flush_queries);
|
||||
GDVIRTUAL_BIND(_end_sync);
|
||||
GDVIRTUAL_BIND(_finish);
|
||||
|
||||
GDVIRTUAL_BIND(_is_flushing_queries);
|
||||
GDVIRTUAL_BIND(_get_process_info, "process_info");
|
||||
}
|
||||
|
||||
PhysicsServer2DExtension::PhysicsServer2DExtension() {
|
||||
}
|
||||
|
||||
PhysicsServer2DExtension::~PhysicsServer2DExtension() {
|
||||
}
|
||||
458
servers/physics_2d/physics_server_2d_extension.h
Normal file
458
servers/physics_2d/physics_server_2d_extension.h
Normal file
@ -0,0 +1,458 @@
|
||||
/**************************************************************************/
|
||||
/* physics_server_2d_extension.h */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/extension/ext_wrappers.gen.inc"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
#include "core/variant/native_ptr.h"
|
||||
#include "core/variant/typed_array.h"
|
||||
#include "servers/physics_2d/physics_server_2d.h"
|
||||
|
||||
class PhysicsDirectBodyState2DExtension : public PhysicsDirectBodyState2D {
|
||||
GDCLASS(PhysicsDirectBodyState2DExtension, PhysicsDirectBodyState2D);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
// The warning is valid, but unavoidable. If the function is not overridden it will error anyway.
|
||||
|
||||
EXBIND0RC(Vector2, get_total_gravity)
|
||||
EXBIND0RC(real_t, get_total_angular_damp)
|
||||
EXBIND0RC(real_t, get_total_linear_damp)
|
||||
|
||||
EXBIND0RC(Vector2, get_center_of_mass)
|
||||
EXBIND0RC(Vector2, get_center_of_mass_local)
|
||||
EXBIND0RC(real_t, get_inverse_mass)
|
||||
EXBIND0RC(real_t, get_inverse_inertia)
|
||||
|
||||
EXBIND1(set_linear_velocity, const Vector2 &)
|
||||
EXBIND0RC(Vector2, get_linear_velocity)
|
||||
|
||||
EXBIND1(set_angular_velocity, real_t)
|
||||
EXBIND0RC(real_t, get_angular_velocity)
|
||||
|
||||
EXBIND1(set_transform, const Transform2D &)
|
||||
EXBIND0RC(Transform2D, get_transform)
|
||||
|
||||
EXBIND1RC(Vector2, get_velocity_at_local_position, const Vector2 &)
|
||||
|
||||
EXBIND1(apply_central_impulse, const Vector2 &)
|
||||
EXBIND1(apply_torque_impulse, real_t)
|
||||
EXBIND2(apply_impulse, const Vector2 &, const Vector2 &)
|
||||
|
||||
EXBIND1(apply_central_force, const Vector2 &)
|
||||
EXBIND2(apply_force, const Vector2 &, const Vector2 &)
|
||||
EXBIND1(apply_torque, real_t)
|
||||
|
||||
EXBIND1(add_constant_central_force, const Vector2 &)
|
||||
EXBIND2(add_constant_force, const Vector2 &, const Vector2 &)
|
||||
EXBIND1(add_constant_torque, real_t)
|
||||
|
||||
EXBIND1(set_constant_force, const Vector2 &)
|
||||
EXBIND0RC(Vector2, get_constant_force)
|
||||
|
||||
EXBIND1(set_constant_torque, real_t)
|
||||
EXBIND0RC(real_t, get_constant_torque)
|
||||
|
||||
EXBIND1(set_sleep_state, bool)
|
||||
EXBIND0RC(bool, is_sleeping)
|
||||
|
||||
EXBIND1(set_collision_layer, uint32_t);
|
||||
EXBIND0RC(uint32_t, get_collision_layer);
|
||||
|
||||
EXBIND1(set_collision_mask, uint32_t);
|
||||
EXBIND0RC(uint32_t, get_collision_mask);
|
||||
|
||||
EXBIND0RC(int, get_contact_count)
|
||||
|
||||
EXBIND1RC(Vector2, get_contact_local_position, int)
|
||||
EXBIND1RC(Vector2, get_contact_local_normal, int)
|
||||
EXBIND1RC(Vector2, get_contact_local_velocity_at_position, int)
|
||||
EXBIND1RC(int, get_contact_local_shape, int)
|
||||
EXBIND1RC(RID, get_contact_collider, int)
|
||||
EXBIND1RC(Vector2, get_contact_collider_position, int)
|
||||
EXBIND1RC(ObjectID, get_contact_collider_id, int)
|
||||
EXBIND1RC(Object *, get_contact_collider_object, int)
|
||||
EXBIND1RC(int, get_contact_collider_shape, int)
|
||||
EXBIND1RC(Vector2, get_contact_collider_velocity_at_position, int)
|
||||
EXBIND1RC(Vector2, get_contact_impulse, int)
|
||||
|
||||
EXBIND0RC(real_t, get_step)
|
||||
EXBIND0(integrate_forces)
|
||||
|
||||
EXBIND0R(PhysicsDirectSpaceState2D *, get_space_state)
|
||||
|
||||
PhysicsDirectBodyState2DExtension();
|
||||
};
|
||||
|
||||
typedef PhysicsDirectSpaceState2D::RayResult PhysicsServer2DExtensionRayResult;
|
||||
typedef PhysicsDirectSpaceState2D::ShapeResult PhysicsServer2DExtensionShapeResult;
|
||||
typedef PhysicsDirectSpaceState2D::ShapeRestInfo PhysicsServer2DExtensionShapeRestInfo;
|
||||
|
||||
GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionRayResult)
|
||||
GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionShapeResult)
|
||||
GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionShapeRestInfo)
|
||||
|
||||
class PhysicsDirectSpaceState2DExtension : public PhysicsDirectSpaceState2D {
|
||||
GDCLASS(PhysicsDirectSpaceState2DExtension, PhysicsDirectSpaceState2D);
|
||||
|
||||
thread_local static const HashSet<RID> *exclude;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
bool is_body_excluded_from_query(const RID &p_body) const;
|
||||
|
||||
GDVIRTUAL7R_REQUIRED(bool, _intersect_ray, const Vector2 &, const Vector2 &, uint32_t, bool, bool, bool, GDExtensionPtr<PhysicsServer2DExtensionRayResult>)
|
||||
GDVIRTUAL7R_REQUIRED(int, _intersect_point, const Vector2 &, ObjectID, uint32_t, bool, bool, GDExtensionPtr<PhysicsServer2DExtensionShapeResult>, int)
|
||||
GDVIRTUAL9R_REQUIRED(int, _intersect_shape, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDExtensionPtr<PhysicsServer2DExtensionShapeResult>, int)
|
||||
GDVIRTUAL9R_REQUIRED(bool, _cast_motion, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDExtensionPtr<real_t>, GDExtensionPtr<real_t>)
|
||||
GDVIRTUAL10R_REQUIRED(bool, _collide_shape, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDExtensionPtr<Vector2>, int, GDExtensionPtr<int>)
|
||||
GDVIRTUAL8R_REQUIRED(bool, _rest_info, RID, const Transform2D &, const Vector2 &, real_t, uint32_t, bool, bool, GDExtensionPtr<PhysicsServer2DExtensionShapeRestInfo>)
|
||||
|
||||
public:
|
||||
virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) override {
|
||||
exclude = &p_parameters.exclude;
|
||||
bool ret = false;
|
||||
GDVIRTUAL_CALL(_intersect_ray, p_parameters.from, p_parameters.to, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, p_parameters.hit_from_inside, &r_result, ret);
|
||||
exclude = nullptr;
|
||||
return ret;
|
||||
}
|
||||
virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) override {
|
||||
exclude = &p_parameters.exclude;
|
||||
int ret = false;
|
||||
GDVIRTUAL_CALL(_intersect_point, p_parameters.position, p_parameters.canvas_instance_id, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_results, p_result_max, ret);
|
||||
exclude = nullptr;
|
||||
return ret;
|
||||
}
|
||||
virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) override {
|
||||
exclude = &p_parameters.exclude;
|
||||
int ret = 0;
|
||||
GDVIRTUAL_CALL(_intersect_shape, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_results, p_result_max, ret);
|
||||
exclude = nullptr;
|
||||
return ret;
|
||||
}
|
||||
virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) override {
|
||||
exclude = &p_parameters.exclude;
|
||||
bool ret = false;
|
||||
GDVIRTUAL_CALL(_cast_motion, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, &p_closest_safe, &p_closest_unsafe, ret);
|
||||
exclude = nullptr;
|
||||
return ret;
|
||||
}
|
||||
virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) override {
|
||||
exclude = &p_parameters.exclude;
|
||||
bool ret = false;
|
||||
GDVIRTUAL_CALL(_collide_shape, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_results, p_result_max, &r_result_count, ret);
|
||||
exclude = nullptr;
|
||||
return ret;
|
||||
}
|
||||
virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) override {
|
||||
exclude = &p_parameters.exclude;
|
||||
bool ret = false;
|
||||
GDVIRTUAL_CALL(_rest_info, p_parameters.shape_rid, p_parameters.transform, p_parameters.motion, p_parameters.margin, p_parameters.collision_mask, p_parameters.collide_with_bodies, p_parameters.collide_with_areas, r_info, ret);
|
||||
exclude = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
PhysicsDirectSpaceState2DExtension();
|
||||
};
|
||||
|
||||
typedef PhysicsServer2D::MotionResult PhysicsServer2DExtensionMotionResult;
|
||||
|
||||
GDVIRTUAL_NATIVE_PTR(PhysicsServer2DExtensionMotionResult)
|
||||
|
||||
class PhysicsServer2DExtension : public PhysicsServer2D {
|
||||
GDCLASS(PhysicsServer2DExtension, PhysicsServer2D);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
GDVIRTUAL9R_REQUIRED(bool, _shape_collide, RID, const Transform2D &, const Vector2 &, RID, const Transform2D &, const Vector2 &, GDExtensionPtr<Vector2>, int, GDExtensionPtr<int>)
|
||||
|
||||
GDVIRTUAL8R_REQUIRED(bool, _body_collide_shape, RID, int, RID, const Transform2D &, const Vector2 &, GDExtensionPtr<Vector2>, int, GDExtensionPtr<int>)
|
||||
|
||||
public:
|
||||
// The warning is valid, but unavoidable. If the function is not overridden it will error anyway.
|
||||
|
||||
/* SHAPE API */
|
||||
|
||||
EXBIND0R(RID, world_boundary_shape_create)
|
||||
EXBIND0R(RID, separation_ray_shape_create)
|
||||
EXBIND0R(RID, segment_shape_create)
|
||||
EXBIND0R(RID, circle_shape_create)
|
||||
EXBIND0R(RID, rectangle_shape_create)
|
||||
EXBIND0R(RID, capsule_shape_create)
|
||||
EXBIND0R(RID, convex_polygon_shape_create)
|
||||
EXBIND0R(RID, concave_polygon_shape_create)
|
||||
|
||||
EXBIND2(shape_set_data, RID, const Variant &)
|
||||
EXBIND2(shape_set_custom_solver_bias, RID, real_t)
|
||||
|
||||
EXBIND1RC(ShapeType, shape_get_type, RID)
|
||||
EXBIND1RC(Variant, shape_get_data, RID)
|
||||
EXBIND1RC(real_t, shape_get_custom_solver_bias, RID)
|
||||
|
||||
virtual bool 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) override {
|
||||
bool ret = false;
|
||||
GDVIRTUAL_CALL(_shape_collide, p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, &r_result_count, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* SPACE API */
|
||||
|
||||
EXBIND0R(RID, space_create)
|
||||
EXBIND2(space_set_active, RID, bool)
|
||||
EXBIND1RC(bool, space_is_active, RID)
|
||||
|
||||
EXBIND3(space_set_param, RID, SpaceParameter, real_t)
|
||||
EXBIND2RC(real_t, space_get_param, RID, SpaceParameter)
|
||||
|
||||
EXBIND1R(PhysicsDirectSpaceState2D *, space_get_direct_state, RID)
|
||||
|
||||
EXBIND2(space_set_debug_contacts, RID, int)
|
||||
EXBIND1RC(Vector<Vector2>, space_get_contacts, RID)
|
||||
EXBIND1RC(int, space_get_contact_count, RID)
|
||||
|
||||
/* AREA API */
|
||||
|
||||
//EXBIND0RID(area);
|
||||
EXBIND0R(RID, area_create)
|
||||
|
||||
EXBIND2(area_set_space, RID, RID)
|
||||
EXBIND1RC(RID, area_get_space, RID)
|
||||
|
||||
EXBIND4(area_add_shape, RID, RID, const Transform2D &, bool)
|
||||
EXBIND3(area_set_shape, RID, int, RID)
|
||||
EXBIND3(area_set_shape_transform, RID, int, const Transform2D &)
|
||||
EXBIND3(area_set_shape_disabled, RID, int, bool)
|
||||
|
||||
EXBIND1RC(int, area_get_shape_count, RID)
|
||||
EXBIND2RC(RID, area_get_shape, RID, int)
|
||||
EXBIND2RC(Transform2D, area_get_shape_transform, RID, int)
|
||||
|
||||
EXBIND2(area_remove_shape, RID, int)
|
||||
EXBIND1(area_clear_shapes, RID)
|
||||
|
||||
EXBIND2(area_attach_object_instance_id, RID, ObjectID)
|
||||
EXBIND1RC(ObjectID, area_get_object_instance_id, RID)
|
||||
|
||||
EXBIND2(area_attach_canvas_instance_id, RID, ObjectID)
|
||||
EXBIND1RC(ObjectID, area_get_canvas_instance_id, RID)
|
||||
|
||||
EXBIND3(area_set_param, RID, AreaParameter, const Variant &)
|
||||
EXBIND2(area_set_transform, RID, const Transform2D &)
|
||||
|
||||
EXBIND2RC(Variant, area_get_param, RID, AreaParameter)
|
||||
EXBIND1RC(Transform2D, area_get_transform, RID)
|
||||
|
||||
EXBIND2(area_set_collision_layer, RID, uint32_t)
|
||||
EXBIND1RC(uint32_t, area_get_collision_layer, RID)
|
||||
|
||||
EXBIND2(area_set_collision_mask, RID, uint32_t)
|
||||
EXBIND1RC(uint32_t, area_get_collision_mask, RID)
|
||||
|
||||
EXBIND2(area_set_monitorable, RID, bool)
|
||||
EXBIND2(area_set_pickable, RID, bool)
|
||||
|
||||
EXBIND2(area_set_monitor_callback, RID, const Callable &)
|
||||
EXBIND2(area_set_area_monitor_callback, RID, const Callable &)
|
||||
|
||||
/* BODY API */
|
||||
|
||||
//EXBIND2RID(body,BodyMode,bool);
|
||||
EXBIND0R(RID, body_create)
|
||||
|
||||
EXBIND2(body_set_space, RID, RID)
|
||||
EXBIND1RC(RID, body_get_space, RID)
|
||||
|
||||
EXBIND2(body_set_mode, RID, BodyMode)
|
||||
EXBIND1RC(BodyMode, body_get_mode, RID)
|
||||
|
||||
EXBIND4(body_add_shape, RID, RID, const Transform2D &, bool)
|
||||
EXBIND3(body_set_shape, RID, int, RID)
|
||||
EXBIND3(body_set_shape_transform, RID, int, const Transform2D &)
|
||||
|
||||
EXBIND1RC(int, body_get_shape_count, RID)
|
||||
EXBIND2RC(RID, body_get_shape, RID, int)
|
||||
EXBIND2RC(Transform2D, body_get_shape_transform, RID, int)
|
||||
|
||||
EXBIND3(body_set_shape_disabled, RID, int, bool)
|
||||
EXBIND4(body_set_shape_as_one_way_collision, RID, int, bool, real_t)
|
||||
|
||||
EXBIND2(body_remove_shape, RID, int)
|
||||
EXBIND1(body_clear_shapes, RID)
|
||||
|
||||
EXBIND2(body_attach_object_instance_id, RID, ObjectID)
|
||||
EXBIND1RC(ObjectID, body_get_object_instance_id, RID)
|
||||
|
||||
EXBIND2(body_attach_canvas_instance_id, RID, ObjectID)
|
||||
EXBIND1RC(ObjectID, body_get_canvas_instance_id, RID)
|
||||
|
||||
EXBIND2(body_set_continuous_collision_detection_mode, RID, CCDMode)
|
||||
EXBIND1RC(CCDMode, body_get_continuous_collision_detection_mode, RID)
|
||||
|
||||
EXBIND2(body_set_collision_layer, RID, uint32_t)
|
||||
EXBIND1RC(uint32_t, body_get_collision_layer, RID)
|
||||
|
||||
EXBIND2(body_set_collision_mask, RID, uint32_t)
|
||||
EXBIND1RC(uint32_t, body_get_collision_mask, RID)
|
||||
|
||||
EXBIND2(body_set_collision_priority, RID, real_t)
|
||||
EXBIND1RC(real_t, body_get_collision_priority, RID)
|
||||
|
||||
EXBIND3(body_set_param, RID, BodyParameter, const Variant &)
|
||||
EXBIND2RC(Variant, body_get_param, RID, BodyParameter)
|
||||
|
||||
EXBIND1(body_reset_mass_properties, RID)
|
||||
|
||||
EXBIND3(body_set_state, RID, BodyState, const Variant &)
|
||||
EXBIND2RC(Variant, body_get_state, RID, BodyState)
|
||||
|
||||
EXBIND2(body_apply_central_impulse, RID, const Vector2 &)
|
||||
EXBIND2(body_apply_torque_impulse, RID, real_t)
|
||||
EXBIND3(body_apply_impulse, RID, const Vector2 &, const Vector2 &)
|
||||
|
||||
EXBIND2(body_apply_central_force, RID, const Vector2 &)
|
||||
EXBIND3(body_apply_force, RID, const Vector2 &, const Vector2 &)
|
||||
EXBIND2(body_apply_torque, RID, real_t)
|
||||
|
||||
EXBIND2(body_add_constant_central_force, RID, const Vector2 &)
|
||||
EXBIND3(body_add_constant_force, RID, const Vector2 &, const Vector2 &)
|
||||
EXBIND2(body_add_constant_torque, RID, real_t)
|
||||
|
||||
EXBIND2(body_set_constant_force, RID, const Vector2 &)
|
||||
EXBIND1RC(Vector2, body_get_constant_force, RID)
|
||||
|
||||
EXBIND2(body_set_constant_torque, RID, real_t)
|
||||
EXBIND1RC(real_t, body_get_constant_torque, RID)
|
||||
|
||||
EXBIND2(body_set_axis_velocity, RID, const Vector2 &)
|
||||
|
||||
EXBIND2(body_add_collision_exception, RID, RID)
|
||||
EXBIND2(body_remove_collision_exception, RID, RID)
|
||||
GDVIRTUAL1RC_REQUIRED(TypedArray<RID>, _body_get_collision_exceptions, RID)
|
||||
|
||||
void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override {
|
||||
TypedArray<RID> ret;
|
||||
GDVIRTUAL_CALL(_body_get_collision_exceptions, p_body, ret);
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
p_exceptions->push_back(ret[i]);
|
||||
}
|
||||
}
|
||||
|
||||
EXBIND2(body_set_max_contacts_reported, RID, int)
|
||||
EXBIND1RC(int, body_get_max_contacts_reported, RID)
|
||||
|
||||
EXBIND2(body_set_contacts_reported_depth_threshold, RID, real_t)
|
||||
EXBIND1RC(real_t, body_get_contacts_reported_depth_threshold, RID)
|
||||
|
||||
EXBIND2(body_set_omit_force_integration, RID, bool)
|
||||
EXBIND1RC(bool, body_is_omitting_force_integration, RID)
|
||||
|
||||
EXBIND2(body_set_state_sync_callback, RID, const Callable &)
|
||||
EXBIND3(body_set_force_integration_callback, RID, const Callable &, const Variant &)
|
||||
|
||||
virtual bool 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) override {
|
||||
bool ret = false;
|
||||
GDVIRTUAL_CALL(_body_collide_shape, p_body, p_body_shape, p_shape, p_shape_xform, p_motion, r_results, p_result_max, &r_result_count, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EXBIND2(body_set_pickable, RID, bool)
|
||||
|
||||
EXBIND1R(PhysicsDirectBodyState2D *, body_get_direct_state, RID)
|
||||
|
||||
GDVIRTUAL7RC_REQUIRED(bool, _body_test_motion, RID, const Transform2D &, const Vector2 &, real_t, bool, bool, GDExtensionPtr<PhysicsServer2DExtensionMotionResult>)
|
||||
|
||||
thread_local static const HashSet<RID> *exclude_bodies;
|
||||
thread_local static const HashSet<ObjectID> *exclude_objects;
|
||||
|
||||
bool body_test_motion_is_excluding_body(RID p_body) const;
|
||||
bool body_test_motion_is_excluding_object(ObjectID p_object) const;
|
||||
|
||||
bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override {
|
||||
bool ret = false;
|
||||
exclude_bodies = &p_parameters.exclude_bodies;
|
||||
exclude_objects = &p_parameters.exclude_objects;
|
||||
GDVIRTUAL_CALL(_body_test_motion, p_body, p_parameters.from, p_parameters.motion, p_parameters.margin, p_parameters.collide_separation_ray, p_parameters.recovery_as_collision, r_result, ret);
|
||||
exclude_bodies = nullptr;
|
||||
exclude_objects = nullptr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* JOINT API */
|
||||
|
||||
EXBIND0R(RID, joint_create)
|
||||
EXBIND1(joint_clear, RID)
|
||||
|
||||
EXBIND3(joint_set_param, RID, JointParam, real_t)
|
||||
EXBIND2RC(real_t, joint_get_param, RID, JointParam)
|
||||
|
||||
EXBIND2(joint_disable_collisions_between_bodies, RID, bool)
|
||||
EXBIND1RC(bool, joint_is_disabled_collisions_between_bodies, RID)
|
||||
|
||||
EXBIND4(joint_make_pin, RID, const Vector2 &, RID, RID)
|
||||
EXBIND6(joint_make_groove, RID, const Vector2 &, const Vector2 &, const Vector2 &, RID, RID)
|
||||
EXBIND5(joint_make_damped_spring, RID, const Vector2 &, const Vector2 &, RID, RID)
|
||||
|
||||
EXBIND3(pin_joint_set_flag, RID, PinJointFlag, bool)
|
||||
EXBIND2RC(bool, pin_joint_get_flag, RID, PinJointFlag)
|
||||
|
||||
EXBIND3(pin_joint_set_param, RID, PinJointParam, real_t)
|
||||
EXBIND2RC(real_t, pin_joint_get_param, RID, PinJointParam)
|
||||
|
||||
EXBIND3(damped_spring_joint_set_param, RID, DampedSpringParam, real_t)
|
||||
EXBIND2RC(real_t, damped_spring_joint_get_param, RID, DampedSpringParam)
|
||||
|
||||
EXBIND1RC(JointType, joint_get_type, RID)
|
||||
|
||||
/* MISC */
|
||||
|
||||
GDVIRTUAL1_REQUIRED(_free_rid, RID)
|
||||
virtual void free_rid(RID p_rid) override {
|
||||
GDVIRTUAL_CALL(_free_rid, p_rid);
|
||||
}
|
||||
|
||||
EXBIND1(set_active, bool)
|
||||
|
||||
EXBIND0(init)
|
||||
EXBIND1(step, real_t)
|
||||
EXBIND0(sync)
|
||||
EXBIND0(flush_queries)
|
||||
EXBIND0(end_sync)
|
||||
EXBIND0(finish)
|
||||
|
||||
EXBIND0RC(bool, is_flushing_queries)
|
||||
EXBIND1R(int, get_process_info, ProcessInfo)
|
||||
|
||||
PhysicsServer2DExtension();
|
||||
~PhysicsServer2DExtension();
|
||||
};
|
||||
121
servers/physics_2d/physics_server_2d_wrap_mt.cpp
Normal file
121
servers/physics_2d/physics_server_2d_wrap_mt.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/**************************************************************************/
|
||||
/* physics_server_2d_wrap_mt.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 "physics_server_2d_wrap_mt.h"
|
||||
|
||||
void PhysicsServer2DWrapMT::_assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id) {
|
||||
server_thread = Thread::get_caller_id();
|
||||
server_task_id = p_pump_task_id;
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::_thread_exit() {
|
||||
exit = true;
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::_thread_loop() {
|
||||
while (!exit) {
|
||||
WorkerThreadPool::get_singleton()->yield();
|
||||
|
||||
if (!doing_sync.is_set()) {
|
||||
command_queue.flush_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::_thread_sync() {
|
||||
doing_sync.set();
|
||||
}
|
||||
|
||||
/* EVENT QUEUING */
|
||||
|
||||
void PhysicsServer2DWrapMT::step(real_t p_step) {
|
||||
if (create_thread) {
|
||||
command_queue.push(physics_server_2d, &PhysicsServer2D::step, p_step);
|
||||
} else {
|
||||
physics_server_2d->step(p_step);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::sync() {
|
||||
if (create_thread) {
|
||||
command_queue.push_and_sync(this, &PhysicsServer2DWrapMT::_thread_sync);
|
||||
} else {
|
||||
command_queue.flush_all(); // Flush all pending from other threads.
|
||||
}
|
||||
physics_server_2d->sync();
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::flush_queries() {
|
||||
physics_server_2d->flush_queries();
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::end_sync() {
|
||||
physics_server_2d->end_sync();
|
||||
|
||||
if (create_thread) {
|
||||
doing_sync.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::init() {
|
||||
if (create_thread) {
|
||||
WorkerThreadPool::TaskID tid = WorkerThreadPool::get_singleton()->add_task(callable_mp(this, &PhysicsServer2DWrapMT::_thread_loop), true, "Physics server 2D pump task", true);
|
||||
command_queue.set_pump_task_id(tid);
|
||||
command_queue.push(this, &PhysicsServer2DWrapMT::_assign_mt_ids, tid);
|
||||
command_queue.push_and_sync(physics_server_2d, &PhysicsServer2D::init);
|
||||
DEV_ASSERT(server_task_id == tid);
|
||||
} else {
|
||||
server_thread = Thread::MAIN_ID;
|
||||
physics_server_2d->init();
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsServer2DWrapMT::finish() {
|
||||
if (create_thread) {
|
||||
command_queue.push(physics_server_2d, &PhysicsServer2D::finish);
|
||||
command_queue.push(this, &PhysicsServer2DWrapMT::_thread_exit);
|
||||
if (server_task_id != WorkerThreadPool::INVALID_TASK_ID) {
|
||||
WorkerThreadPool::get_singleton()->wait_for_task_completion(server_task_id);
|
||||
server_task_id = WorkerThreadPool::INVALID_TASK_ID;
|
||||
}
|
||||
server_thread = Thread::MAIN_ID;
|
||||
} else {
|
||||
physics_server_2d->finish();
|
||||
}
|
||||
}
|
||||
|
||||
PhysicsServer2DWrapMT::PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool p_create_thread) {
|
||||
physics_server_2d = p_contained;
|
||||
create_thread = p_create_thread;
|
||||
}
|
||||
|
||||
PhysicsServer2DWrapMT::~PhysicsServer2DWrapMT() {
|
||||
memdelete(physics_server_2d);
|
||||
}
|
||||
347
servers/physics_2d/physics_server_2d_wrap_mt.h
Normal file
347
servers/physics_2d/physics_server_2d_wrap_mt.h
Normal file
@ -0,0 +1,347 @@
|
||||
/**************************************************************************/
|
||||
/* physics_server_2d_wrap_mt.h */
|
||||
/**************************************************************************/
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/object/worker_thread_pool.h"
|
||||
#include "core/os/thread.h"
|
||||
#include "core/templates/command_queue_mt.h"
|
||||
#include "servers/physics_2d/physics_server_2d.h"
|
||||
|
||||
#define ASYNC_COND_PUSH (Thread::get_caller_id() != server_thread)
|
||||
#define ASYNC_COND_PUSH_AND_RET (Thread::get_caller_id() != server_thread && !(doing_sync.is_set() && Thread::is_main_thread()))
|
||||
#define ASYNC_COND_PUSH_AND_SYNC (Thread::get_caller_id() != server_thread && !(doing_sync.is_set() && Thread::is_main_thread()))
|
||||
|
||||
#ifdef DEBUG_SYNC
|
||||
#define SYNC_DEBUG print_line("sync on: " + String(__FUNCTION__));
|
||||
#else
|
||||
#define SYNC_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#ifdef DEV_ENABLED
|
||||
#define MAIN_THREAD_SYNC_WARN WARN_PRINT("Call to " + String(__FUNCTION__) + " causing PhysicsServer2D synchronizations on every frame. This significantly affects performance.");
|
||||
#else
|
||||
#define MAIN_THREAD_SYNC_WARN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class PhysicsServer2DWrapMT : public PhysicsServer2D {
|
||||
GDSOFTCLASS(PhysicsServer2DWrapMT, PhysicsServer2D);
|
||||
|
||||
mutable PhysicsServer2D *physics_server_2d = nullptr;
|
||||
|
||||
mutable CommandQueueMT command_queue;
|
||||
|
||||
Thread::ID server_thread = Thread::UNASSIGNED_ID;
|
||||
WorkerThreadPool::TaskID server_task_id = WorkerThreadPool::INVALID_TASK_ID;
|
||||
bool exit = false;
|
||||
bool create_thread = false;
|
||||
SafeFlag doing_sync;
|
||||
|
||||
void _assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id);
|
||||
void _thread_exit();
|
||||
void _thread_loop();
|
||||
void _thread_sync();
|
||||
|
||||
public:
|
||||
#define ServerName PhysicsServer2D
|
||||
#define ServerNameWrapMT PhysicsServer2DWrapMT
|
||||
#define server_name physics_server_2d
|
||||
#define WRITE_ACTION
|
||||
|
||||
#include "servers/server_wrap_mt_common.h"
|
||||
|
||||
//FUNC1RID(shape,ShapeType); todo fix
|
||||
FUNCRID(world_boundary_shape)
|
||||
FUNCRID(separation_ray_shape)
|
||||
FUNCRID(segment_shape)
|
||||
FUNCRID(circle_shape)
|
||||
FUNCRID(rectangle_shape)
|
||||
FUNCRID(capsule_shape)
|
||||
FUNCRID(convex_polygon_shape)
|
||||
FUNCRID(concave_polygon_shape)
|
||||
|
||||
FUNC2(shape_set_data, RID, const Variant &);
|
||||
FUNC2(shape_set_custom_solver_bias, RID, real_t);
|
||||
|
||||
FUNC1RC(ShapeType, shape_get_type, RID);
|
||||
FUNC1RC(Variant, shape_get_data, RID);
|
||||
FUNC1RC(real_t, shape_get_custom_solver_bias, RID);
|
||||
|
||||
//these work well, but should be used from the main thread only
|
||||
bool 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) override {
|
||||
ERR_FAIL_COND_V(!Thread::is_main_thread(), false);
|
||||
return physics_server_2d->shape_collide(p_shape_A, p_xform_A, p_motion_A, p_shape_B, p_xform_B, p_motion_B, r_results, p_result_max, r_result_count);
|
||||
}
|
||||
|
||||
/* SPACE API */
|
||||
|
||||
FUNCRID(space);
|
||||
FUNC2(space_set_active, RID, bool);
|
||||
FUNC1RC(bool, space_is_active, RID);
|
||||
|
||||
FUNC3(space_set_param, RID, SpaceParameter, real_t);
|
||||
FUNC2RC(real_t, space_get_param, RID, SpaceParameter);
|
||||
|
||||
// this function only works on physics process, errors and returns null otherwise
|
||||
PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) override {
|
||||
ERR_FAIL_COND_V(!Thread::is_main_thread(), nullptr);
|
||||
return physics_server_2d->space_get_direct_state(p_space);
|
||||
}
|
||||
|
||||
FUNC2(space_set_debug_contacts, RID, int);
|
||||
virtual Vector<Vector2> space_get_contacts(RID p_space) const override {
|
||||
ERR_FAIL_COND_V(!Thread::is_main_thread(), Vector<Vector2>());
|
||||
return physics_server_2d->space_get_contacts(p_space);
|
||||
}
|
||||
|
||||
virtual int space_get_contact_count(RID p_space) const override {
|
||||
ERR_FAIL_COND_V(!Thread::is_main_thread(), 0);
|
||||
return physics_server_2d->space_get_contact_count(p_space);
|
||||
}
|
||||
|
||||
/* AREA API */
|
||||
|
||||
//FUNC0RID(area);
|
||||
FUNCRID(area);
|
||||
|
||||
FUNC2(area_set_space, RID, RID);
|
||||
FUNC1RC(RID, area_get_space, RID);
|
||||
|
||||
FUNC4(area_add_shape, RID, RID, const Transform2D &, bool);
|
||||
FUNC3(area_set_shape, RID, int, RID);
|
||||
FUNC3(area_set_shape_transform, RID, int, const Transform2D &);
|
||||
FUNC3(area_set_shape_disabled, RID, int, bool);
|
||||
|
||||
FUNC1RC(int, area_get_shape_count, RID);
|
||||
FUNC2RC(RID, area_get_shape, RID, int);
|
||||
FUNC2RC(Transform2D, area_get_shape_transform, RID, int);
|
||||
FUNC2(area_remove_shape, RID, int);
|
||||
FUNC1(area_clear_shapes, RID);
|
||||
|
||||
FUNC2(area_attach_object_instance_id, RID, ObjectID);
|
||||
FUNC1RC(ObjectID, area_get_object_instance_id, RID);
|
||||
|
||||
FUNC2(area_attach_canvas_instance_id, RID, ObjectID);
|
||||
FUNC1RC(ObjectID, area_get_canvas_instance_id, RID);
|
||||
|
||||
FUNC3(area_set_param, RID, AreaParameter, const Variant &);
|
||||
FUNC2(area_set_transform, RID, const Transform2D &);
|
||||
|
||||
FUNC2RC(Variant, area_get_param, RID, AreaParameter);
|
||||
FUNC1RC(Transform2D, area_get_transform, RID);
|
||||
|
||||
FUNC2(area_set_collision_layer, RID, uint32_t);
|
||||
FUNC1RC(uint32_t, area_get_collision_layer, RID);
|
||||
|
||||
FUNC2(area_set_collision_mask, RID, uint32_t);
|
||||
FUNC1RC(uint32_t, area_get_collision_mask, RID);
|
||||
|
||||
FUNC2(area_set_monitorable, RID, bool);
|
||||
FUNC2(area_set_pickable, RID, bool);
|
||||
|
||||
FUNC2(area_set_monitor_callback, RID, const Callable &);
|
||||
FUNC2(area_set_area_monitor_callback, RID, const Callable &);
|
||||
|
||||
/* BODY API */
|
||||
|
||||
//FUNC2RID(body,BodyMode,bool);
|
||||
FUNCRID(body)
|
||||
|
||||
FUNC2(body_set_space, RID, RID);
|
||||
FUNC1RC(RID, body_get_space, RID);
|
||||
|
||||
FUNC2(body_set_mode, RID, BodyMode);
|
||||
FUNC1RC(BodyMode, body_get_mode, RID);
|
||||
|
||||
FUNC4(body_add_shape, RID, RID, const Transform2D &, bool);
|
||||
FUNC3(body_set_shape, RID, int, RID);
|
||||
FUNC3(body_set_shape_transform, RID, int, const Transform2D &);
|
||||
|
||||
FUNC1RC(int, body_get_shape_count, RID);
|
||||
FUNC2RC(Transform2D, body_get_shape_transform, RID, int);
|
||||
FUNC2RC(RID, body_get_shape, RID, int);
|
||||
|
||||
FUNC3(body_set_shape_disabled, RID, int, bool);
|
||||
FUNC4(body_set_shape_as_one_way_collision, RID, int, bool, real_t);
|
||||
|
||||
FUNC2(body_remove_shape, RID, int);
|
||||
FUNC1(body_clear_shapes, RID);
|
||||
|
||||
FUNC2(body_attach_object_instance_id, RID, ObjectID);
|
||||
FUNC1RC(ObjectID, body_get_object_instance_id, RID);
|
||||
|
||||
FUNC2(body_attach_canvas_instance_id, RID, ObjectID);
|
||||
FUNC1RC(ObjectID, body_get_canvas_instance_id, RID);
|
||||
|
||||
FUNC2(body_set_continuous_collision_detection_mode, RID, CCDMode);
|
||||
FUNC1RC(CCDMode, body_get_continuous_collision_detection_mode, RID);
|
||||
|
||||
FUNC2(body_set_collision_layer, RID, uint32_t);
|
||||
FUNC1RC(uint32_t, body_get_collision_layer, RID);
|
||||
|
||||
FUNC2(body_set_collision_mask, RID, uint32_t);
|
||||
FUNC1RC(uint32_t, body_get_collision_mask, RID);
|
||||
|
||||
FUNC2(body_set_collision_priority, RID, real_t);
|
||||
FUNC1RC(real_t, body_get_collision_priority, RID);
|
||||
|
||||
FUNC3(body_set_param, RID, BodyParameter, const Variant &);
|
||||
FUNC2RC(Variant, body_get_param, RID, BodyParameter);
|
||||
|
||||
FUNC1(body_reset_mass_properties, RID);
|
||||
|
||||
FUNC3(body_set_state, RID, BodyState, const Variant &);
|
||||
FUNC2RC(Variant, body_get_state, RID, BodyState);
|
||||
|
||||
FUNC2(body_apply_central_impulse, RID, const Vector2 &);
|
||||
FUNC2(body_apply_torque_impulse, RID, real_t);
|
||||
FUNC3(body_apply_impulse, RID, const Vector2 &, const Vector2 &);
|
||||
|
||||
FUNC2(body_apply_central_force, RID, const Vector2 &);
|
||||
FUNC3(body_apply_force, RID, const Vector2 &, const Vector2 &);
|
||||
FUNC2(body_apply_torque, RID, real_t);
|
||||
|
||||
FUNC2(body_add_constant_central_force, RID, const Vector2 &);
|
||||
FUNC3(body_add_constant_force, RID, const Vector2 &, const Vector2 &);
|
||||
FUNC2(body_add_constant_torque, RID, real_t);
|
||||
|
||||
FUNC2(body_set_constant_force, RID, const Vector2 &);
|
||||
FUNC1RC(Vector2, body_get_constant_force, RID);
|
||||
|
||||
FUNC2(body_set_constant_torque, RID, real_t);
|
||||
FUNC1RC(real_t, body_get_constant_torque, RID);
|
||||
|
||||
FUNC2(body_set_axis_velocity, RID, const Vector2 &);
|
||||
|
||||
FUNC2(body_add_collision_exception, RID, RID);
|
||||
FUNC2(body_remove_collision_exception, RID, RID);
|
||||
FUNC2S(body_get_collision_exceptions, RID, List<RID> *);
|
||||
|
||||
FUNC2(body_set_max_contacts_reported, RID, int);
|
||||
FUNC1RC(int, body_get_max_contacts_reported, RID);
|
||||
|
||||
FUNC2(body_set_contacts_reported_depth_threshold, RID, real_t);
|
||||
FUNC1RC(real_t, body_get_contacts_reported_depth_threshold, RID);
|
||||
|
||||
FUNC2(body_set_omit_force_integration, RID, bool);
|
||||
FUNC1RC(bool, body_is_omitting_force_integration, RID);
|
||||
|
||||
FUNC2(body_set_state_sync_callback, RID, const Callable &);
|
||||
FUNC3(body_set_force_integration_callback, RID, const Callable &, const Variant &);
|
||||
|
||||
bool 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) override {
|
||||
return physics_server_2d->body_collide_shape(p_body, p_body_shape, p_shape, p_shape_xform, p_motion, r_results, p_result_max, r_result_count);
|
||||
}
|
||||
|
||||
FUNC2(body_set_pickable, RID, bool);
|
||||
|
||||
bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) override {
|
||||
ERR_FAIL_COND_V(!Thread::is_main_thread(), false);
|
||||
return physics_server_2d->body_test_motion(p_body, p_parameters, r_result);
|
||||
}
|
||||
|
||||
// this function only works on physics process, errors and returns null otherwise
|
||||
PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) override {
|
||||
ERR_FAIL_COND_V(!Thread::is_main_thread(), nullptr);
|
||||
return physics_server_2d->body_get_direct_state(p_body);
|
||||
}
|
||||
|
||||
/* JOINT API */
|
||||
|
||||
FUNCRID(joint)
|
||||
|
||||
FUNC1(joint_clear, RID)
|
||||
|
||||
FUNC3(joint_set_param, RID, JointParam, real_t);
|
||||
FUNC2RC(real_t, joint_get_param, RID, JointParam);
|
||||
|
||||
FUNC2(joint_disable_collisions_between_bodies, RID, const bool);
|
||||
FUNC1RC(bool, joint_is_disabled_collisions_between_bodies, RID);
|
||||
|
||||
///FUNC3RID(pin_joint,const Vector2&,RID,RID);
|
||||
///FUNC5RID(groove_joint,const Vector2&,const Vector2&,const Vector2&,RID,RID);
|
||||
///FUNC4RID(damped_spring_joint,const Vector2&,const Vector2&,RID,RID);
|
||||
|
||||
//TODO need to convert this to FUNCRID, but it's a hassle..
|
||||
|
||||
FUNC4(joint_make_pin, RID, const Vector2 &, RID, RID);
|
||||
FUNC6(joint_make_groove, RID, const Vector2 &, const Vector2 &, const Vector2 &, RID, RID);
|
||||
FUNC5(joint_make_damped_spring, RID, const Vector2 &, const Vector2 &, RID, RID);
|
||||
|
||||
FUNC3(pin_joint_set_param, RID, PinJointParam, real_t);
|
||||
FUNC2RC(real_t, pin_joint_get_param, RID, PinJointParam);
|
||||
|
||||
FUNC3(pin_joint_set_flag, RID, PinJointFlag, bool);
|
||||
FUNC2RC(bool, pin_joint_get_flag, RID, PinJointFlag);
|
||||
|
||||
FUNC3(damped_spring_joint_set_param, RID, DampedSpringParam, real_t);
|
||||
FUNC2RC(real_t, damped_spring_joint_get_param, RID, DampedSpringParam);
|
||||
|
||||
FUNC1RC(JointType, joint_get_type, RID);
|
||||
|
||||
/* MISC */
|
||||
|
||||
FUNC1(free_rid, RID);
|
||||
FUNC1(set_active, bool);
|
||||
|
||||
virtual void init() override;
|
||||
virtual void step(real_t p_step) override;
|
||||
virtual void sync() override;
|
||||
virtual void end_sync() override;
|
||||
virtual void flush_queries() override;
|
||||
virtual void finish() override;
|
||||
|
||||
virtual bool is_flushing_queries() const override {
|
||||
return physics_server_2d->is_flushing_queries();
|
||||
}
|
||||
|
||||
int get_process_info(ProcessInfo p_info) override {
|
||||
return physics_server_2d->get_process_info(p_info);
|
||||
}
|
||||
|
||||
PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool p_create_thread);
|
||||
~PhysicsServer2DWrapMT();
|
||||
|
||||
#undef ServerNameWrapMT
|
||||
#undef ServerName
|
||||
#undef server_name
|
||||
#undef WRITE_ACTION
|
||||
};
|
||||
|
||||
#ifdef DEBUG_SYNC
|
||||
#undef DEBUG_SYNC
|
||||
#endif
|
||||
#undef SYNC_DEBUG
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#undef MAIN_THREAD_SYNC_WARN
|
||||
#endif
|
||||
Reference in New Issue
Block a user