2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* physics_2d_server_sw.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 14:50:53 +01:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef PHYSICS_2D_SERVER_SW
|
|
|
|
#define PHYSICS_2D_SERVER_SW
|
|
|
|
|
|
|
|
|
|
|
|
#include "servers/physics_2d_server.h"
|
|
|
|
#include "shape_2d_sw.h"
|
|
|
|
#include "space_2d_sw.h"
|
|
|
|
#include "step_2d_sw.h"
|
|
|
|
#include "joints_2d_sw.h"
|
|
|
|
|
|
|
|
|
|
|
|
class Physics2DServerSW : public Physics2DServer {
|
|
|
|
|
|
|
|
OBJ_TYPE( Physics2DServerSW, Physics2DServer );
|
|
|
|
|
|
|
|
friend class Physics2DDirectSpaceStateSW;
|
2016-01-04 00:23:44 +01:00
|
|
|
friend class Physics2DDirectBodyStateSW;
|
2014-02-10 02:10:30 +01:00
|
|
|
bool active;
|
|
|
|
int iterations;
|
|
|
|
bool doing_sync;
|
|
|
|
real_t last_step;
|
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
int island_count;
|
|
|
|
int active_objects;
|
|
|
|
int collision_pairs;
|
|
|
|
|
2015-05-26 06:05:08 +02:00
|
|
|
bool using_threads;
|
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Step2DSW *stepper;
|
|
|
|
Set<const Space2DSW*> active_spaces;
|
|
|
|
|
|
|
|
Physics2DDirectBodyStateSW *direct_state;
|
|
|
|
|
|
|
|
mutable RID_Owner<Shape2DSW> shape_owner;
|
|
|
|
mutable RID_Owner<Space2DSW> space_owner;
|
|
|
|
mutable RID_Owner<Area2DSW> area_owner;
|
|
|
|
mutable RID_Owner<Body2DSW> body_owner;
|
|
|
|
mutable RID_Owner<Joint2DSW> joint_owner;
|
|
|
|
|
2016-01-04 00:23:44 +01:00
|
|
|
static Physics2DServerSW *singletonsw;
|
2014-02-23 00:28:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
// void _clear_query(Query2DSW *p_query);
|
|
|
|
public:
|
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
struct CollCbkData {
|
|
|
|
|
2015-01-14 01:19:11 +01:00
|
|
|
Vector2 valid_dir;
|
|
|
|
float valid_depth;
|
2014-02-19 15:57:14 +01:00
|
|
|
int max;
|
|
|
|
int amount;
|
|
|
|
Vector2 *ptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void _shape_col_cbk(const Vector2& p_point_A,const Vector2& p_point_B,void *p_userdata);
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual RID shape_create(ShapeType p_shape);
|
|
|
|
virtual void shape_set_data(RID p_shape, const Variant& p_data);
|
|
|
|
virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias);
|
|
|
|
|
|
|
|
virtual ShapeType shape_get_type(RID p_shape) const;
|
|
|
|
virtual Variant shape_get_data(RID p_shape) const;
|
|
|
|
virtual real_t shape_get_custom_solver_bias(RID p_shape) const;
|
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
virtual bool shape_collide(RID p_shape_A, const Matrix32& p_xform_A,const Vector2& p_motion_A,RID p_shape_B, const Matrix32& p_xform_B, const Vector2& p_motion_B,Vector2 *r_results,int p_result_max,int &r_result_count);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/* SPACE API */
|
|
|
|
|
|
|
|
virtual RID space_create();
|
|
|
|
virtual void space_set_active(RID p_space,bool p_active);
|
|
|
|
virtual bool space_is_active(RID p_space) const;
|
|
|
|
|
|
|
|
virtual void space_set_param(RID p_space,SpaceParameter p_param, real_t p_value);
|
|
|
|
virtual real_t space_get_param(RID p_space,SpaceParameter p_param) const;
|
|
|
|
|
2015-09-20 18:03:46 +02:00
|
|
|
virtual void space_set_debug_contacts(RID p_space,int p_max_contacts);
|
|
|
|
virtual Vector<Vector2> space_get_contacts(RID p_space) const;
|
|
|
|
virtual int space_get_contact_count(RID p_space) const;
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// this function only works on fixed process, errors and returns null otherwise
|
|
|
|
virtual Physics2DDirectSpaceState* space_get_direct_state(RID p_space);
|
|
|
|
|
|
|
|
|
|
|
|
/* AREA API */
|
|
|
|
|
|
|
|
virtual RID area_create();
|
|
|
|
|
|
|
|
virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode);
|
|
|
|
virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const;
|
|
|
|
|
|
|
|
virtual void area_set_space(RID p_area, RID p_space);
|
|
|
|
virtual RID area_get_space(RID p_area) const;
|
|
|
|
|
|
|
|
virtual void area_add_shape(RID p_area, RID p_shape, const Matrix32& p_transform=Matrix32());
|
|
|
|
virtual void area_set_shape(RID p_area, int p_shape_idx,RID p_shape);
|
|
|
|
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Matrix32& p_transform);
|
|
|
|
|
|
|
|
virtual int area_get_shape_count(RID p_area) const;
|
|
|
|
virtual RID area_get_shape(RID p_area, int p_shape_idx) const;
|
|
|
|
virtual Matrix32 area_get_shape_transform(RID p_area, int p_shape_idx) const;
|
|
|
|
|
|
|
|
virtual void area_remove_shape(RID p_area, int p_shape_idx);
|
|
|
|
virtual void area_clear_shapes(RID p_area);
|
|
|
|
|
|
|
|
virtual void area_attach_object_instance_ID(RID p_area,ObjectID p_ID);
|
|
|
|
virtual ObjectID area_get_object_instance_ID(RID p_area) const;
|
|
|
|
|
|
|
|
virtual void area_set_param(RID p_area,AreaParameter p_param,const Variant& p_value);
|
|
|
|
virtual void area_set_transform(RID p_area, const Matrix32& p_transform);
|
|
|
|
|
|
|
|
virtual Variant area_get_param(RID p_parea,AreaParameter p_param) const;
|
|
|
|
virtual Matrix32 area_get_transform(RID p_area) const;
|
2015-03-17 04:45:25 +01:00
|
|
|
virtual void area_set_monitorable(RID p_area,bool p_monitorable);
|
2015-05-03 21:47:21 +02:00
|
|
|
virtual void area_set_collision_mask(RID p_area,uint32_t p_mask);
|
|
|
|
virtual void area_set_layer_mask(RID p_area,uint32_t p_mask);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method);
|
2015-03-17 04:45:25 +01:00
|
|
|
virtual void area_set_area_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-03-22 05:46:18 +01:00
|
|
|
virtual void area_set_pickable(RID p_area,bool p_pickable);
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/* BODY API */
|
|
|
|
|
|
|
|
// create a body of a given type
|
|
|
|
virtual RID body_create(BodyMode p_mode=BODY_MODE_RIGID,bool p_init_sleeping=false);
|
|
|
|
|
|
|
|
virtual void body_set_space(RID p_body, RID p_space);
|
|
|
|
virtual RID body_get_space(RID p_body) const;
|
|
|
|
|
|
|
|
virtual void body_set_mode(RID p_body, BodyMode p_mode);
|
2014-02-19 15:57:14 +01:00
|
|
|
virtual BodyMode body_get_mode(RID p_body) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void body_add_shape(RID p_body, RID p_shape, const Matrix32& p_transform=Matrix32());
|
|
|
|
virtual void body_set_shape(RID p_body, int p_shape_idx,RID p_shape);
|
|
|
|
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Matrix32& p_transform);
|
2014-10-16 05:06:34 +02:00
|
|
|
virtual void body_set_shape_metadata(RID p_body, int p_shape_idx, const Variant& p_metadata);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual int body_get_shape_count(RID p_body) const;
|
|
|
|
virtual RID body_get_shape(RID p_body, int p_shape_idx) const;
|
|
|
|
virtual Matrix32 body_get_shape_transform(RID p_body, int p_shape_idx) const;
|
2014-10-16 05:06:34 +02:00
|
|
|
virtual Variant body_get_shape_metadata(RID p_body, int p_shape_idx) const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void body_remove_shape(RID p_body, int p_shape_idx);
|
|
|
|
virtual void body_clear_shapes(RID p_body);
|
|
|
|
|
|
|
|
virtual void body_set_shape_as_trigger(RID p_body, int p_shape_idx,bool p_enable);
|
|
|
|
virtual bool body_is_shape_set_as_trigger(RID p_body, int p_shape_idx) const;
|
|
|
|
|
|
|
|
virtual void body_attach_object_instance_ID(RID p_body,uint32_t p_ID);
|
|
|
|
virtual uint32_t body_get_object_instance_ID(RID p_body) const;
|
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
virtual void body_set_continuous_collision_detection_mode(RID p_body,CCDMode p_mode);
|
|
|
|
virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-05-14 06:22:15 +02:00
|
|
|
virtual void body_set_layer_mask(RID p_body, uint32_t p_mask);
|
2015-05-26 06:05:08 +02:00
|
|
|
virtual uint32_t body_get_layer_mask(RID p_body) const;
|
2014-05-14 06:22:15 +02:00
|
|
|
|
2015-05-03 21:47:21 +02:00
|
|
|
virtual void body_set_collision_mask(RID p_body, uint32_t p_mask);
|
2015-05-26 06:05:08 +02:00
|
|
|
virtual uint32_t body_get_collision_mask(RID p_) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value);
|
|
|
|
virtual float body_get_param(RID p_body, BodyParameter p_param) const;
|
|
|
|
|
|
|
|
|
|
|
|
virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant);
|
|
|
|
virtual Variant body_get_state(RID p_body, BodyState p_state) const;
|
|
|
|
|
|
|
|
virtual void body_set_applied_force(RID p_body, const Vector2& p_force);
|
|
|
|
virtual Vector2 body_get_applied_force(RID p_body) const;
|
|
|
|
|
|
|
|
virtual void body_set_applied_torque(RID p_body, float p_torque);
|
|
|
|
virtual float body_get_applied_torque(RID p_body) const;
|
|
|
|
|
2016-04-26 14:15:15 +02:00
|
|
|
virtual void body_add_force(RID p_body, const Vector2& p_offset, const Vector2& p_force);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void body_apply_impulse(RID p_body, const Vector2& p_pos, const Vector2& p_impulse);
|
|
|
|
virtual void body_set_axis_velocity(RID p_body, const Vector2& p_axis_velocity);
|
|
|
|
|
|
|
|
virtual void body_add_collision_exception(RID p_body, RID p_body_b);
|
|
|
|
virtual void body_remove_collision_exception(RID p_body, RID p_body_b);
|
|
|
|
virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions);
|
|
|
|
|
|
|
|
virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold);
|
|
|
|
virtual float body_get_contacts_reported_depth_treshold(RID p_body) const;
|
|
|
|
|
|
|
|
virtual void body_set_omit_force_integration(RID p_body,bool p_omit);
|
|
|
|
virtual bool body_is_omitting_force_integration(RID p_body) const;
|
|
|
|
|
|
|
|
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts);
|
|
|
|
virtual int body_get_max_contacts_reported(RID p_body) const;
|
|
|
|
|
2015-01-13 14:49:26 +01:00
|
|
|
virtual void body_set_one_way_collision_direction(RID p_body,const Vector2& p_direction);
|
|
|
|
virtual Vector2 body_get_one_way_collision_direction(RID p_body) const;
|
|
|
|
|
2015-01-14 01:19:11 +01:00
|
|
|
virtual void body_set_one_way_collision_max_depth(RID p_body,float p_max_depth);
|
|
|
|
virtual float body_get_one_way_collision_max_depth(RID p_body) const;
|
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void body_set_force_integration_callback(RID p_body,Object *p_receiver,const StringName& p_method,const Variant& p_udata=Variant());
|
2014-02-19 15:57:14 +01:00
|
|
|
virtual bool body_collide_shape(RID p_body, int p_body_shape,RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,Vector2 *r_results,int p_result_max,int &r_result_count);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-03-22 05:46:18 +01:00
|
|
|
virtual void body_set_pickable(RID p_body,bool p_pickable);
|
|
|
|
|
2016-09-01 17:03:55 +02:00
|
|
|
virtual bool body_test_motion(RID p_body,const Matrix32& p_from,const Vector2& p_motion,float p_margin=0.001,MotionResult *r_result=NULL);
|
2015-04-20 01:50:55 +02:00
|
|
|
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/* JOINT API */
|
|
|
|
|
|
|
|
virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value);
|
|
|
|
virtual real_t joint_get_param(RID p_joint,JointParam p_param) const;
|
|
|
|
|
|
|
|
virtual RID pin_joint_create(const Vector2& p_pos,RID p_body_a,RID p_body_b=RID());
|
|
|
|
virtual RID groove_joint_create(const Vector2& p_a_groove1,const Vector2& p_a_groove2, const Vector2& p_b_anchor, RID p_body_a,RID p_body_b);
|
|
|
|
virtual RID damped_spring_joint_create(const Vector2& p_anchor_a,const Vector2& p_anchor_b,RID p_body_a,RID p_body_b=RID());
|
2015-10-10 22:28:05 +02:00
|
|
|
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value);
|
|
|
|
virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value);
|
|
|
|
virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const;
|
|
|
|
|
|
|
|
virtual JointType joint_get_type(RID p_joint) const;
|
|
|
|
|
|
|
|
/* MISC */
|
|
|
|
|
|
|
|
virtual void free(RID p_rid);
|
|
|
|
|
|
|
|
virtual void set_active(bool p_active);
|
|
|
|
virtual void init();
|
|
|
|
virtual void step(float p_step);
|
2016-03-09 00:00:52 +01:00
|
|
|
virtual void sync();
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void flush_queries();
|
2015-05-26 06:05:08 +02:00
|
|
|
virtual void end_sync();
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void finish();
|
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
int get_process_info(ProcessInfo p_info);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Physics2DServerSW();
|
|
|
|
~Physics2DServerSW();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|