-Added an optimization so physics shapes are configured later, speeds up grid map loading and editing

This commit is contained in:
Juan Linietsky 2017-09-03 14:53:17 -03:00
parent 29db531fc8
commit adde89e8b1
9 changed files with 65 additions and 14 deletions

View file

@ -88,7 +88,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
if (mesh.is_null())
continue;
int id = p_library->find_item_name(mi->get_name());
int id = p_library->find_item_by_name(mi->get_name());
if (id < 0) {
id = p_library->get_last_unused_item_id();

View file

@ -972,6 +972,14 @@ void ScriptEditor::_menu_option(int p_option) {
EditorNode::get_singleton()->show_warning("Can't obtain the script for running");
break;
}
current->apply_code();
Error err = scr->reload(false); //hard reload script before running always
if (err != OK) {
EditorNode::get_singleton()->show_warning("Script failed reloading, check console for errors.");
return;
}
if (!scr->is_tool()) {
EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run");

View file

@ -396,8 +396,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
Map<int, List<Pair<Transform, IndexKey> > > multimesh_items;
print_line("updating octant " + itos(p_key.x) + ", " + itos(p_key.y) + ", " + itos(p_key.z) + " cells: " + itos(g.cells.size()));
for (Set<IndexKey>::Element *E = g.cells.front(); E; E = E->next()) {
ERR_CONTINUE(!cell_map.has(E->get()));
@ -464,7 +462,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
//update multimeshes
for (Map<int, List<Pair<Transform, IndexKey> > >::Element *E = multimesh_items.front(); E; E = E->next()) {
print_line("multimesh item " + itos(E->key()) + " transforms " + itos(E->get().size()));
Octant::MultimeshInstance mmi;
RID mm = VS::get_singleton()->multimesh_create();

View file

@ -214,7 +214,7 @@ Vector<int> MeshLibrary::get_item_list() const {
return ret;
}
int MeshLibrary::find_item_name(const String &p_name) const {
int MeshLibrary::find_item_by_name(const String &p_name) const {
for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) {
@ -275,6 +275,9 @@ void MeshLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes);
ClassDB::bind_method(D_METHOD("get_item_preview", "id"), &MeshLibrary::get_item_preview);
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
ClassDB::bind_method(D_METHOD("find_item_by_name", "name"), &MeshLibrary::find_item_by_name);
ClassDB::bind_method(D_METHOD("clear"), &MeshLibrary::clear);
ClassDB::bind_method(D_METHOD("get_item_list"), &MeshLibrary::get_item_list);
ClassDB::bind_method(D_METHOD("get_last_unused_item_id"), &MeshLibrary::get_last_unused_item_id);

View file

@ -84,7 +84,7 @@ public:
void clear();
int find_item_name(const String &p_name) const;
int find_item_by_name(const String &p_name) const;
Vector<int> get_item_list() const;
int get_last_unused_item_id() const;

View file

@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "collision_object_sw.h"
#include "servers/physics/physics_server_sw.h"
#include "space_sw.h"
void CollisionObjectSW::add_shape(ShapeSW *p_shape, const Transform &p_transform) {
@ -39,8 +40,12 @@ void CollisionObjectSW::add_shape(ShapeSW *p_shape, const Transform &p_transform
s.bpid = 0; //needs update
shapes.push_back(s);
p_shape->add_owner(this);
_update_shapes();
_shapes_changed();
if (!pending_shape_update_list.in_list()) {
PhysicsServerSW::singleton->pending_shape_update_list.add(&pending_shape_update_list);
}
//_update_shapes();
//_shapes_changed();
}
void CollisionObjectSW::set_shape(int p_index, ShapeSW *p_shape) {
@ -50,8 +55,11 @@ void CollisionObjectSW::set_shape(int p_index, ShapeSW *p_shape) {
shapes[p_index].shape = p_shape;
p_shape->add_owner(this);
_update_shapes();
_shapes_changed();
if (!pending_shape_update_list.in_list()) {
PhysicsServerSW::singleton->pending_shape_update_list.add(&pending_shape_update_list);
}
//_update_shapes();
//_shapes_changed();
}
void CollisionObjectSW::set_shape_transform(int p_index, const Transform &p_transform) {
@ -59,8 +67,11 @@ void CollisionObjectSW::set_shape_transform(int p_index, const Transform &p_tran
shapes[p_index].xform = p_transform;
shapes[p_index].xform_inv = p_transform.affine_inverse();
_update_shapes();
_shapes_changed();
if (!pending_shape_update_list.in_list()) {
PhysicsServerSW::singleton->pending_shape_update_list.add(&pending_shape_update_list);
}
//_update_shapes();
//_shapes_changed();
}
void CollisionObjectSW::remove_shape(ShapeSW *p_shape) {
@ -90,7 +101,11 @@ void CollisionObjectSW::remove_shape(int p_index) {
shapes[p_index].shape->remove_owner(this);
shapes.remove(p_index);
_shapes_changed();
if (!pending_shape_update_list.in_list()) {
PhysicsServerSW::singleton->pending_shape_update_list.add(&pending_shape_update_list);
}
//_update_shapes();
//_shapes_changed();
}
void CollisionObjectSW::_set_static(bool p_static) {
@ -202,7 +217,8 @@ void CollisionObjectSW::_shape_changed() {
_shapes_changed();
}
CollisionObjectSW::CollisionObjectSW(Type p_type) {
CollisionObjectSW::CollisionObjectSW(Type p_type)
: pending_shape_update_list(this) {
_static = true;
type = p_type;

View file

@ -75,6 +75,8 @@ private:
Transform inv_transform;
bool _static;
SelfList<CollisionObjectSW> pending_shape_update_list;
void _update_shapes();
protected:

View file

@ -763,6 +763,8 @@ void PhysicsServerSW::body_apply_impulse(RID p_body, const Vector3 &p_pos, const
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
_update_shapes();
body->apply_impulse(p_pos, p_impulse);
body->wakeup();
};
@ -772,6 +774,8 @@ void PhysicsServerSW::body_apply_torque_impulse(RID p_body, const Vector3 &p_imp
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
_update_shapes();
body->apply_torque_impulse(p_impulse);
body->wakeup();
};
@ -781,6 +785,8 @@ void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_v
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
_update_shapes();
Vector3 v = body->get_linear_velocity();
Vector3 axis = p_axis_velocity.normalized();
v -= axis * axis.dot(v);
@ -793,6 +799,7 @@ void PhysicsServerSW::body_set_axis_lock(RID p_body, BodyAxisLock p_lock) {
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
body->set_axis_lock(p_lock);
body->wakeup();
}
@ -902,6 +909,8 @@ bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, cons
ERR_FAIL_COND_V(!body->get_space(), false);
ERR_FAIL_COND_V(body->get_space()->is_locked(), false);
_update_shapes();
return body->get_space()->test_body_motion(body, p_from, p_motion, p_margin, r_result);
}
@ -1209,6 +1218,8 @@ bool PhysicsServerSW::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_a
void PhysicsServerSW::free(RID p_rid) {
_update_shapes(); //just in case
if (shape_owner.owns(p_rid)) {
ShapeSW *shape = shape_owner.get(p_rid);
@ -1312,6 +1323,8 @@ void PhysicsServerSW::step(real_t p_step) {
if (!active)
return;
_update_shapes();
doing_sync = false;
last_step = p_step;
@ -1409,6 +1422,14 @@ int PhysicsServerSW::get_process_info(ProcessInfo p_info) {
return 0;
}
void PhysicsServerSW::_update_shapes() {
while (pending_shape_update_list.first()) {
pending_shape_update_list.first()->self()->_shape_changed();
pending_shape_update_list.remove(pending_shape_update_list.first());
}
}
void PhysicsServerSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 &p_point_B, void *p_userdata) {
CollCbkData *cbk = (CollCbkData *)p_userdata;

View file

@ -62,6 +62,10 @@ class PhysicsServerSW : public PhysicsServer {
mutable RID_Owner<JointSW> joint_owner;
//void _clear_query(QuerySW *p_query);
friend class CollisionObjectSW;
SelfList<CollisionObjectSW>::List pending_shape_update_list;
void _update_shapes();
public:
static PhysicsServerSW *singleton;