summaryrefslogtreecommitdiff
path: root/servers/physics_2d
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-11-09 23:34:01 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-11-09 23:35:34 -0300
commit192a4d7de5c557bdfe83bd180cd603d7e280ebd4 (patch)
tree94ce9779b3f84fbc320ba83624e326d487ca1c04 /servers/physics_2d
parent0de6cba7e7e114f71fabb3dbe02cf260f7d3e2c6 (diff)
Reworked how servers preallocate RIDs, should fix #10970
Diffstat (limited to 'servers/physics_2d')
-rw-r--r--servers/physics_2d/physics_2d_server_sw.cpp47
-rw-r--r--servers/physics_2d/physics_2d_server_sw.h15
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.cpp27
-rw-r--r--servers/physics_2d/physics_2d_server_wrap_mt.h33
4 files changed, 81 insertions, 41 deletions
diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp
index 5d3305c82d..475a3fe3b3 100644
--- a/servers/physics_2d/physics_2d_server_sw.cpp
+++ b/servers/physics_2d/physics_2d_server_sw.cpp
@@ -35,7 +35,7 @@
#include "project_settings.h"
#include "script_language.h"
-RID Physics2DServerSW::shape_create(ShapeType p_shape) {
+RID Physics2DServerSW::_shape_create(ShapeType p_shape) {
Shape2DSW *shape = NULL;
switch (p_shape) {
@@ -83,7 +83,42 @@ RID Physics2DServerSW::shape_create(ShapeType p_shape) {
shape->set_self(id);
return id;
-};
+}
+
+RID Physics2DServerSW::line_shape_create() {
+
+ return _shape_create(SHAPE_LINE);
+}
+
+RID Physics2DServerSW::ray_shape_create() {
+
+ return _shape_create(SHAPE_RAY);
+}
+RID Physics2DServerSW::segment_shape_create() {
+
+ return _shape_create(SHAPE_SEGMENT);
+}
+RID Physics2DServerSW::circle_shape_create() {
+
+ return _shape_create(SHAPE_CIRCLE);
+}
+RID Physics2DServerSW::rectangle_shape_create() {
+
+ return _shape_create(SHAPE_RECTANGLE);
+}
+RID Physics2DServerSW::capsule_shape_create() {
+
+ return _shape_create(SHAPE_CAPSULE);
+}
+
+RID Physics2DServerSW::convex_polygon_shape_create() {
+
+ return _shape_create(SHAPE_CONVEX_POLYGON);
+}
+RID Physics2DServerSW::concave_polygon_shape_create() {
+
+ return _shape_create(SHAPE_CONCAVE_POLYGON);
+}
void Physics2DServerSW::shape_set_data(RID p_shape, const Variant &p_data) {
@@ -519,17 +554,13 @@ void Physics2DServerSW::area_set_area_monitor_callback(RID p_area, Object *p_rec
/* BODY API */
-RID Physics2DServerSW::body_create(BodyMode p_mode, bool p_init_sleeping) {
+RID Physics2DServerSW::body_create() {
Body2DSW *body = memnew(Body2DSW);
- if (p_mode != BODY_MODE_RIGID)
- body->set_mode(p_mode);
- if (p_init_sleeping)
- body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
RID rid = body_owner.make_rid(body);
body->set_self(rid);
return rid;
-};
+}
void Physics2DServerSW::body_set_space(RID p_body, RID p_space) {
diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h
index c40cf0e3e0..171a0b7a81 100644
--- a/servers/physics_2d/physics_2d_server_sw.h
+++ b/servers/physics_2d/physics_2d_server_sw.h
@@ -67,6 +67,9 @@ class Physics2DServerSW : public Physics2DServer {
static Physics2DServerSW *singletonsw;
//void _clear_query(Query2DSW *p_query);
+
+ RID _shape_create(ShapeType p_shape);
+
public:
struct CollCbkData {
@@ -78,9 +81,17 @@ public:
Vector2 *ptr;
};
+ virtual RID line_shape_create();
+ virtual RID ray_shape_create();
+ virtual RID segment_shape_create();
+ virtual RID circle_shape_create();
+ virtual RID rectangle_shape_create();
+ virtual RID capsule_shape_create();
+ virtual RID convex_polygon_shape_create();
+ virtual RID concave_polygon_shape_create();
+
static void _shape_col_cbk(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_userdata);
- 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);
@@ -149,7 +160,7 @@ public:
/* 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 RID body_create();
virtual void body_set_space(RID p_body, RID p_space);
virtual RID body_get_space(RID p_body) const;
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp
index f8f3b620d4..f92ed18de2 100644
--- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp
+++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp
@@ -130,19 +130,23 @@ void Physics2DServerWrapMT::finish() {
Thread::wait_to_finish(thread);
memdelete(thread);
- /*
- shape_free_cached_ids();
- area_free_cached_ids();
- body_free_cached_ids();
- pin_joint_free_cached_ids();
- groove_joint_free_cached_ids();
- damped_string_free_cached_ids();
-*/
thread = NULL;
} else {
physics_2d_server->finish();
}
+ line_shape_free_cached_ids();
+ ray_shape_free_cached_ids();
+ segment_shape_free_cached_ids();
+ circle_shape_free_cached_ids();
+ rectangle_shape_free_cached_ids();
+ convex_polygon_shape_free_cached_ids();
+ concave_polygon_shape_free_cached_ids();
+
+ space_free_cached_ids();
+ area_free_cached_ids();
+ body_free_cached_ids();
+
if (step_sem)
memdelete(step_sem);
}
@@ -158,12 +162,7 @@ Physics2DServerWrapMT::Physics2DServerWrapMT(Physics2DServer *p_contained, bool
step_thread_up = false;
alloc_mutex = Mutex::create();
- shape_pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
- area_pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
- body_pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
- pin_joint_pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
- groove_joint_pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
- damped_spring_joint_pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
+ pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
if (!p_create_thread) {
server_thread = Thread::get_caller_id();
diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h
index 50e9ab1005..cbc316cb7a 100644
--- a/servers/physics_2d/physics_2d_server_wrap_mt.h
+++ b/servers/physics_2d/physics_2d_server_wrap_mt.h
@@ -64,21 +64,10 @@ class Physics2DServerWrapMT : public Physics2DServer {
void thread_exit();
- Mutex *alloc_mutex;
bool first_frame;
- int shape_pool_max_size;
- List<RID> shape_id_pool;
- int area_pool_max_size;
- List<RID> area_id_pool;
- int body_pool_max_size;
- List<RID> body_id_pool;
- int pin_joint_pool_max_size;
- List<RID> pin_joint_id_pool;
- int groove_joint_pool_max_size;
- List<RID> groove_joint_id_pool;
- int damped_spring_joint_pool_max_size;
- List<RID> damped_spring_joint_id_pool;
+ Mutex *alloc_mutex;
+ int pool_max_size;
public:
#define ServerName Physics2DServer
@@ -87,7 +76,15 @@ public:
#include "servers/server_wrap_mt_common.h"
//FUNC1RID(shape,ShapeType); todo fix
- FUNC1R(RID, shape_create, ShapeType);
+ FUNCRID(line_shape)
+ FUNCRID(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);
@@ -104,7 +101,7 @@ public:
/* SPACE API */
- FUNC0R(RID, space_create);
+ FUNCRID(space);
FUNC2(space_set_active, RID, bool);
FUNC1RC(bool, space_is_active, RID);
@@ -134,7 +131,7 @@ public:
/* AREA API */
//FUNC0RID(area);
- FUNC0R(RID, area_create);
+ FUNCRID(area);
FUNC2(area_set_space, RID, RID);
FUNC1RC(RID, area_get_space, RID);
@@ -174,7 +171,7 @@ public:
/* BODY API */
//FUNC2RID(body,BodyMode,bool);
- FUNC2R(RID, body_create, BodyMode, bool)
+ FUNCRID(body)
FUNC2(body_set_space, RID, RID);
FUNC1RC(RID, body_get_space, RID);
@@ -269,6 +266,8 @@ public:
///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..
+
FUNC3R(RID, pin_joint_create, const Vector2 &, RID, RID);
FUNC5R(RID, groove_joint_create, const Vector2 &, const Vector2 &, const Vector2 &, RID, RID);
FUNC4R(RID, damped_spring_joint_create, const Vector2 &, const Vector2 &, RID, RID);