Ejemplo n.º 1
0
RID PhysicsServerSW::space_create() {

	SpaceSW *space = memnew( SpaceSW );
	RID id = space_owner.make_rid(space);
	space->set_self(id);
	RID area_id = area_create();
	AreaSW *area = area_owner.get(area_id);
	ERR_FAIL_COND_V(!area,RID());
	space->set_default_area(area);
	area->set_space(space);
	area->set_priority(-1);
	RID sgb = body_create();
	body_set_space(sgb,id);
	body_set_mode(sgb,BODY_MODE_STATIC);
	space->set_static_global_body(sgb);

	return id;
};
Ejemplo n.º 2
0
void Physics2DServerSW::free(RID p_rid) {

	if (shape_owner.owns(p_rid)) {

		Shape2DSW *shape = shape_owner.get(p_rid);

		while (shape->get_owners().size()) {
			ShapeOwner2DSW *so = shape->get_owners().front()->key();
			so->remove_shape(shape);
		}

		shape_owner.free(p_rid);
		memdelete(shape);
	} else if (body_owner.owns(p_rid)) {

		Body2DSW *body = body_owner.get(p_rid);

		/*
		if (body->get_state_query())
			_clear_query(body->get_state_query());

		if (body->get_direct_state_query())
			_clear_query(body->get_direct_state_query());
		*/

		body_set_space(p_rid, RID());

		while (body->get_shape_count()) {

			body->remove_shape(0);
		}

		body_owner.free(p_rid);
		memdelete(body);

	} else if (area_owner.owns(p_rid)) {

		Area2DSW *area = area_owner.get(p_rid);

		/*
		if (area->get_monitor_query())
			_clear_query(area->get_monitor_query());
		*/

		area->set_space(NULL);

		while (area->get_shape_count()) {

			area->remove_shape(0);
		}

		area_owner.free(p_rid);
		memdelete(area);
	} else if (space_owner.owns(p_rid)) {

		Space2DSW *space = space_owner.get(p_rid);

		while (space->get_objects().size()) {
			CollisionObject2DSW *co = (CollisionObject2DSW *)space->get_objects().front()->get();
			co->set_space(NULL);
		}

		active_spaces.erase(space);
		free(space->get_default_area()->get_self());
		space_owner.free(p_rid);
		memdelete(space);
	} else if (joint_owner.owns(p_rid)) {

		Joint2DSW *joint = joint_owner.get(p_rid);

		joint_owner.free(p_rid);
		memdelete(joint);

	} else {

		ERR_EXPLAIN("Invalid ID");
		ERR_FAIL();
	}
};