You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-14 13:41:12 +00:00
Reduce unnecessary COW on Vector by make writing explicit
This commit makes operator[] on Vector const and adds a write proxy to it. From now on writes to Vectors need to happen through the .write proxy. So for instance: Vector<int> vec; vec.push_back(10); std::cout << vec[0] << std::endl; vec.write[0] = 20; Failing to use the .write proxy will cause a compilation error. In addition COWable datatypes can now embed a CowData pointer to their data. This means that String, CharString, and VMap no longer use or derive from Vector. _ALWAYS_INLINE_ and _FORCE_INLINE_ are now equivalent for debug and non-debug builds. This is a lot faster for Vector in the editor and while running tests. The reason why this difference used to exist is because force-inlined methods used to give a bad debugging experience. After extensive testing with modern compilers this is no longer the case.
This commit is contained in:
@@ -53,7 +53,7 @@ void CollisionObjectSW::set_shape(int p_index, ShapeSW *p_shape) {
|
||||
|
||||
ERR_FAIL_INDEX(p_index, shapes.size());
|
||||
shapes[p_index].shape->remove_owner(this);
|
||||
shapes[p_index].shape = p_shape;
|
||||
shapes.write[p_index].shape = p_shape;
|
||||
|
||||
p_shape->add_owner(this);
|
||||
if (!pending_shape_update_list.in_list()) {
|
||||
@@ -66,8 +66,8 @@ void CollisionObjectSW::set_shape_transform(int p_index, const Transform &p_tran
|
||||
|
||||
ERR_FAIL_INDEX(p_index, shapes.size());
|
||||
|
||||
shapes[p_index].xform = p_transform;
|
||||
shapes[p_index].xform_inv = p_transform.affine_inverse();
|
||||
shapes.write[p_index].xform = p_transform;
|
||||
shapes.write[p_index].xform_inv = p_transform.affine_inverse();
|
||||
if (!pending_shape_update_list.in_list()) {
|
||||
PhysicsServerSW::singleton->pending_shape_update_list.add(&pending_shape_update_list);
|
||||
}
|
||||
@@ -97,7 +97,7 @@ void CollisionObjectSW::remove_shape(int p_index) {
|
||||
continue;
|
||||
//should never get here with a null owner
|
||||
space->get_broadphase()->remove(shapes[i].bpid);
|
||||
shapes[i].bpid = 0;
|
||||
shapes.write[i].bpid = 0;
|
||||
}
|
||||
shapes[p_index].shape->remove_owner(this);
|
||||
shapes.remove(p_index);
|
||||
@@ -117,7 +117,7 @@ void CollisionObjectSW::_set_static(bool p_static) {
|
||||
if (!space)
|
||||
return;
|
||||
for (int i = 0; i < get_shape_count(); i++) {
|
||||
Shape &s = shapes[i];
|
||||
const Shape &s = shapes[i];
|
||||
if (s.bpid > 0) {
|
||||
space->get_broadphase()->set_static(s.bpid, _static);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void CollisionObjectSW::_unregister_shapes() {
|
||||
|
||||
for (int i = 0; i < shapes.size(); i++) {
|
||||
|
||||
Shape &s = shapes[i];
|
||||
Shape &s = shapes.write[i];
|
||||
if (s.bpid > 0) {
|
||||
space->get_broadphase()->remove(s.bpid);
|
||||
s.bpid = 0;
|
||||
@@ -143,7 +143,7 @@ void CollisionObjectSW::_update_shapes() {
|
||||
|
||||
for (int i = 0; i < shapes.size(); i++) {
|
||||
|
||||
Shape &s = shapes[i];
|
||||
Shape &s = shapes.write[i];
|
||||
if (s.bpid == 0) {
|
||||
s.bpid = space->get_broadphase()->create(this, i);
|
||||
space->get_broadphase()->set_static(s.bpid, _static);
|
||||
@@ -170,7 +170,7 @@ void CollisionObjectSW::_update_shapes_with_motion(const Vector3 &p_motion) {
|
||||
|
||||
for (int i = 0; i < shapes.size(); i++) {
|
||||
|
||||
Shape &s = shapes[i];
|
||||
Shape &s = shapes.write[i];
|
||||
if (s.bpid == 0) {
|
||||
s.bpid = space->get_broadphase()->create(this, i);
|
||||
space->get_broadphase()->set_static(s.bpid, _static);
|
||||
@@ -195,7 +195,7 @@ void CollisionObjectSW::_set_space(SpaceSW *p_space) {
|
||||
|
||||
for (int i = 0; i < shapes.size(); i++) {
|
||||
|
||||
Shape &s = shapes[i];
|
||||
Shape &s = shapes.write[i];
|
||||
if (s.bpid) {
|
||||
space->get_broadphase()->remove(s.bpid);
|
||||
s.bpid = 0;
|
||||
|
||||
Reference in New Issue
Block a user