mirror of
https://github.com/Relintai/props.git
synced 2025-02-10 16:30:06 +01:00
Cleanups to the collision shape code in TiledWall. Still unfinished though.
This commit is contained in:
parent
cd4f9adfd9
commit
5f915d4dd2
@ -210,7 +210,6 @@ void TiledWall::generate_mesh() {
|
|||||||
PhysicsServer::get_singleton()->body_set_state(_physics_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
PhysicsServer::get_singleton()->body_set_state(_physics_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
//_mesher->tiled wall mesh_wimple(w, h, TWD, cache)
|
|
||||||
_mesher->add_tiled_wall_simple(_width, _height, Transform(), _data, _cache);
|
_mesher->add_tiled_wall_simple(_width, _height, Transform(), _data, _cache);
|
||||||
|
|
||||||
_mesh_array = _mesher->build_mesh();
|
_mesh_array = _mesher->build_mesh();
|
||||||
@ -253,6 +252,7 @@ void TiledWall::clear_mesh() {
|
|||||||
|
|
||||||
void TiledWall::free_mesh() {
|
void TiledWall::free_mesh() {
|
||||||
if (_mesh_rid != RID()) {
|
if (_mesh_rid != RID()) {
|
||||||
|
VS::get_singleton()->instance_set_base(get_instance(), RID());
|
||||||
VS::get_singleton()->free(_mesh_rid);
|
VS::get_singleton()->free(_mesh_rid);
|
||||||
_mesh_rid = RID();
|
_mesh_rid = RID();
|
||||||
}
|
}
|
||||||
@ -268,31 +268,12 @@ void TiledWall::create_colliders() {
|
|||||||
ERR_FAIL_COND(!get_world().is_valid() && get_world()->get_space() == RID());
|
ERR_FAIL_COND(!get_world().is_valid() && get_world()->get_space() == RID());
|
||||||
|
|
||||||
_physics_shape_rid = PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_BOX);
|
_physics_shape_rid = PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_BOX);
|
||||||
_physics_body_rid = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
|
|
||||||
|
|
||||||
PhysicsServer::get_singleton()->shape_set_data(_physics_shape_rid, Vector3(_width / 2.0, _height / 2.0, 0.01));
|
PhysicsServer::get_singleton()->shape_set_data(_physics_shape_rid, Vector3(_width / 2.0, _height / 2.0, 0.01));
|
||||||
|
|
||||||
//todo layer mask
|
|
||||||
PhysicsServer::get_singleton()->body_set_collision_layer(_physics_body_rid, _collision_layer);
|
|
||||||
PhysicsServer::get_singleton()->body_set_collision_mask(_physics_body_rid, _collision_mask);
|
|
||||||
|
|
||||||
PhysicsServer::get_singleton()->body_add_shape(_physics_body_rid, _physics_shape_rid);
|
PhysicsServer::get_singleton()->body_add_shape(_physics_body_rid, _physics_shape_rid);
|
||||||
|
|
||||||
Transform t = get_global_transform();
|
|
||||||
t.translate(Vector3(_width / 2.0, _height / 2.0, 0));
|
|
||||||
|
|
||||||
PhysicsServer::get_singleton()->body_set_state(_physics_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
|
||||||
|
|
||||||
PhysicsServer::get_singleton()->body_set_space(_physics_body_rid, get_world()->get_space());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TiledWall::free_colliders() {
|
void TiledWall::free_colliders() {
|
||||||
if (_physics_body_rid != RID()) {
|
|
||||||
PhysicsServer::get_singleton()->free(_physics_body_rid);
|
|
||||||
|
|
||||||
_physics_body_rid = RID();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_physics_shape_rid != RID()) {
|
if (_physics_shape_rid != RID()) {
|
||||||
PhysicsServer::get_singleton()->free(_physics_shape_rid);
|
PhysicsServer::get_singleton()->free(_physics_shape_rid);
|
||||||
|
|
||||||
@ -307,6 +288,8 @@ TiledWall::TiledWall() {
|
|||||||
_collision_layer = 1;
|
_collision_layer = 1;
|
||||||
_collision_mask = 1;
|
_collision_mask = 1;
|
||||||
|
|
||||||
|
_physics_body_rid = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC);
|
||||||
|
|
||||||
//temporary
|
//temporary
|
||||||
set_portal_mode(PORTAL_MODE_GLOBAL);
|
set_portal_mode(PORTAL_MODE_GLOBAL);
|
||||||
|
|
||||||
@ -316,39 +299,44 @@ TiledWall::~TiledWall() {
|
|||||||
_data.unref();
|
_data.unref();
|
||||||
_cache.unref();
|
_cache.unref();
|
||||||
_mesher.unref();
|
_mesher.unref();
|
||||||
|
|
||||||
|
PhysicsServer::get_singleton()->free(_physics_body_rid);
|
||||||
|
|
||||||
|
_physics_body_rid = RID();
|
||||||
|
|
||||||
|
free_mesh();
|
||||||
|
free_colliders();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TiledWall::_notification(int p_what) {
|
void TiledWall::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
case NOTIFICATION_ENTER_TREE: {
|
case NOTIFICATION_ENTER_WORLD: {
|
||||||
//if (_collision) {
|
Transform t = get_global_transform();
|
||||||
// call_deferred("create_colliders");
|
t.translate(Vector3(_width / 2.0, _height / 2.0, 0));
|
||||||
//}
|
|
||||||
|
PhysicsServer::get_singleton()->body_set_state(_physics_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
||||||
|
|
||||||
|
RID space = get_world()->get_space();
|
||||||
|
PhysicsServer::get_singleton()->body_set_space(_physics_body_rid, space);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_WORLD: {
|
||||||
free_mesh();
|
PhysicsServer::get_singleton()->body_set_space(_physics_body_rid, RID());
|
||||||
|
|
||||||
//if (_collision) {
|
|
||||||
// free_colliders();
|
|
||||||
//}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// case NOTIFICATION_TRANSFORM_CHANGED: {
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||||
/*
|
if (_collision) {
|
||||||
if (_physics_body_rid != RID()) {
|
|
||||||
Transform t = get_global_transform();
|
Transform t = get_global_transform();
|
||||||
t.translate(Vector3(_width / 2.0, _height / 2.0, 0));
|
t.translate(Vector3(_width / 2.0, _height / 2.0, 0));
|
||||||
|
|
||||||
PhysicsServer::get_singleton()->body_set_state(_physics_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
PhysicsServer::get_singleton()->body_set_state(_physics_body_rid, PhysicsServer::BODY_STATE_TRANSFORM, t);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user