diff options
author | Hein-Pieter van Braam <hp@tmm.cx> | 2018-07-25 03:11:03 +0200 |
---|---|---|
committer | Hein-Pieter van Braam <hp@tmm.cx> | 2018-07-26 00:54:16 +0200 |
commit | 0e29f7974b59e4440cf02e1388fb9d8ab2b5c5fd (patch) | |
tree | 18b7ff35f1eeee39031a16e9c1d834ebf03d44cf /scene/resources | |
parent | 9423f23ffb80c946dec380f73f3f313ec44d0d18 (diff) |
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.
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/animation.cpp | 92 | ||||
-rw-r--r-- | scene/resources/bit_mask.cpp | 14 | ||||
-rw-r--r-- | scene/resources/color_ramp.cpp | 20 | ||||
-rw-r--r-- | scene/resources/color_ramp.h | 6 | ||||
-rw-r--r-- | scene/resources/concave_polygon_shape.cpp | 4 | ||||
-rw-r--r-- | scene/resources/convex_polygon_shape.cpp | 4 | ||||
-rw-r--r-- | scene/resources/curve.cpp | 72 | ||||
-rw-r--r-- | scene/resources/dynamic_font.cpp | 24 | ||||
-rw-r--r-- | scene/resources/font.cpp | 4 | ||||
-rw-r--r-- | scene/resources/mesh.cpp | 64 | ||||
-rw-r--r-- | scene/resources/mesh_data_tool.cpp | 30 | ||||
-rw-r--r-- | scene/resources/mesh_library.cpp | 2 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 32 | ||||
-rw-r--r-- | scene/resources/polygon_path_finder.cpp | 80 | ||||
-rw-r--r-- | scene/resources/scene_format_text.cpp | 2 | ||||
-rw-r--r-- | scene/resources/surface_tool.cpp | 36 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 6 | ||||
-rw-r--r-- | scene/resources/tile_set.cpp | 6 |
18 files changed, 249 insertions, 249 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 8acfdc482a..7041b62487 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -100,7 +100,7 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { for (int i = 0; i < (vcount / 12); i++) { - TKey<TransformKey> &tk = tt->transforms[i]; + TKey<TransformKey> &tk = tt->transforms.write[i]; const float *ofs = &r[i * 12]; tk.time = ofs[0]; tk.transition = ofs[1]; @@ -154,8 +154,8 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { for (int i = 0; i < valcount; i++) { - vt->values[i].time = rt[i]; - vt->values[i].value = values[i]; + vt->values.write[i].time = rt[i]; + vt->values.write[i].value = values[i]; } if (d.has("transitions")) { @@ -167,7 +167,7 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { for (int i = 0; i < valcount; i++) { - vt->values[i].transition = rtr[i]; + vt->values.write[i].transition = rtr[i]; } } } @@ -235,13 +235,13 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { for (int i = 0; i < valcount; i++) { - bt->values[i].time = rt[i]; - bt->values[i].transition = 0; //unused in bezier - bt->values[i].value.value = rv[i * 5 + 0]; - bt->values[i].value.in_handle.x = rv[i * 5 + 1]; - bt->values[i].value.in_handle.y = rv[i * 5 + 2]; - bt->values[i].value.out_handle.x = rv[i * 5 + 3]; - bt->values[i].value.out_handle.y = rv[i * 5 + 4]; + bt->values.write[i].time = rt[i]; + bt->values.write[i].transition = 0; //unused in bezier + bt->values.write[i].value.value = rv[i * 5 + 0]; + bt->values.write[i].value.in_handle.x = rv[i * 5 + 1]; + bt->values.write[i].value.in_handle.y = rv[i * 5 + 2]; + bt->values.write[i].value.out_handle.x = rv[i * 5 + 3]; + bt->values.write[i].value.out_handle.y = rv[i * 5 + 4]; } } @@ -313,7 +313,7 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { TKey<StringName> ak; ak.time = rt[i]; ak.value = rc[i]; - an->values[i] = ak; + an->values.write[i] = ak; } } @@ -822,7 +822,7 @@ int Animation::_insert(float p_time, T &p_keys, const V &p_value) { } else if (p_keys[idx - 1].time == p_time) { // condition for replacing. - p_keys[idx - 1] = p_value; + p_keys.write[idx - 1] = p_value; return idx - 1; } @@ -1349,18 +1349,18 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); Dictionary d = p_value; if (d.has("location")) - tt->transforms[p_key_idx].value.loc = d["location"]; + tt->transforms.write[p_key_idx].value.loc = d["location"]; if (d.has("rotation")) - tt->transforms[p_key_idx].value.rot = d["rotation"]; + tt->transforms.write[p_key_idx].value.rot = d["rotation"]; if (d.has("scale")) - tt->transforms[p_key_idx].value.scale = d["scale"]; + tt->transforms.write[p_key_idx].value.scale = d["scale"]; } break; case TYPE_VALUE: { ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX(p_key_idx, vt->values.size()); - vt->values[p_key_idx].value = p_value; + vt->values.write[p_key_idx].value = p_value; } break; case TYPE_METHOD: { @@ -1369,9 +1369,9 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); Dictionary d = p_value; if (d.has("method")) - mt->methods[p_key_idx].method = d["method"]; + mt->methods.write[p_key_idx].method = d["method"]; if (d.has("args")) - mt->methods[p_key_idx].params = d["args"]; + mt->methods.write[p_key_idx].params = d["args"]; } break; case TYPE_BEZIER: { @@ -1381,11 +1381,11 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p Array arr = p_value; ERR_FAIL_COND(arr.size() != 5); - bt->values[p_key_idx].value.value = arr[0]; - bt->values[p_key_idx].value.in_handle.x = arr[1]; - bt->values[p_key_idx].value.in_handle.y = arr[2]; - bt->values[p_key_idx].value.out_handle.x = arr[3]; - bt->values[p_key_idx].value.out_handle.y = arr[4]; + bt->values.write[p_key_idx].value.value = arr[0]; + bt->values.write[p_key_idx].value.in_handle.x = arr[1]; + bt->values.write[p_key_idx].value.in_handle.y = arr[2]; + bt->values.write[p_key_idx].value.out_handle.x = arr[3]; + bt->values.write[p_key_idx].value.out_handle.y = arr[4]; } break; case TYPE_AUDIO: { @@ -1397,16 +1397,16 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p ERR_FAIL_COND(!k.has("end_offset")); ERR_FAIL_COND(!k.has("stream")); - at->values[p_key_idx].value.start_offset = k["start_offset"]; - at->values[p_key_idx].value.end_offset = k["end_offset"]; - at->values[p_key_idx].value.stream = k["stream"]; + at->values.write[p_key_idx].value.start_offset = k["start_offset"]; + at->values.write[p_key_idx].value.end_offset = k["end_offset"]; + at->values.write[p_key_idx].value.stream = k["stream"]; } break; case TYPE_ANIMATION: { AnimationTrack *at = static_cast<AnimationTrack *>(t); - at->values[p_key_idx].value = p_value; + at->values.write[p_key_idx].value = p_value; } break; } @@ -1423,20 +1423,20 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx, float p_tra TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); - tt->transforms[p_key_idx].transition = p_transition; + tt->transforms.write[p_key_idx].transition = p_transition; } break; case TYPE_VALUE: { ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX(p_key_idx, vt->values.size()); - vt->values[p_key_idx].transition = p_transition; + vt->values.write[p_key_idx].transition = p_transition; } break; case TYPE_METHOD: { MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); - mt->methods[p_key_idx].transition = p_transition; + mt->methods.write[p_key_idx].transition = p_transition; } break; case TYPE_BEZIER: @@ -2210,7 +2210,7 @@ void Animation::bezier_track_set_key_value(int p_track, int p_index, float p_val ERR_FAIL_INDEX(p_index, bt->values.size()); - bt->values[p_index].value.value = p_value; + bt->values.write[p_index].value.value = p_value; emit_changed(); } @@ -2224,9 +2224,9 @@ void Animation::bezier_track_set_key_in_handle(int p_track, int p_index, const V ERR_FAIL_INDEX(p_index, bt->values.size()); - bt->values[p_index].value.in_handle = p_handle; + bt->values.write[p_index].value.in_handle = p_handle; if (bt->values[p_index].value.in_handle.x > 0) { - bt->values[p_index].value.in_handle.x = 0; + bt->values.write[p_index].value.in_handle.x = 0; } emit_changed(); } @@ -2240,9 +2240,9 @@ void Animation::bezier_track_set_key_out_handle(int p_track, int p_index, const ERR_FAIL_INDEX(p_index, bt->values.size()); - bt->values[p_index].value.out_handle = p_handle; + bt->values.write[p_index].value.out_handle = p_handle; if (bt->values[p_index].value.out_handle.x < 0) { - bt->values[p_index].value.out_handle.x = 0; + bt->values.write[p_index].value.out_handle.x = 0; } emit_changed(); } @@ -2396,7 +2396,7 @@ void Animation::audio_track_set_key_stream(int p_track, int p_key, const RES &p_ ERR_FAIL_INDEX(p_key, at->values.size()); - at->values[p_key].value.stream = p_stream; + at->values.write[p_key].value.stream = p_stream; emit_changed(); } @@ -2414,7 +2414,7 @@ void Animation::audio_track_set_key_start_offset(int p_track, int p_key, float p if (p_offset < 0) p_offset = 0; - at->values[p_key].value.start_offset = p_offset; + at->values.write[p_key].value.start_offset = p_offset; emit_changed(); } @@ -2432,7 +2432,7 @@ void Animation::audio_track_set_key_end_offset(int p_track, int p_key, float p_o if (p_offset < 0) p_offset = 0; - at->values[p_key].value.end_offset = p_offset; + at->values.write[p_key].value.end_offset = p_offset; emit_changed(); } @@ -2505,7 +2505,7 @@ void Animation::animation_track_set_key_animation(int p_track, int p_key, const ERR_FAIL_INDEX(p_key, at->values.size()); - at->values[p_key].value = p_animation; + at->values.write[p_key].value = p_animation; emit_changed(); } @@ -2550,7 +2550,7 @@ void Animation::track_move_up(int p_track) { if (p_track >= 0 && p_track < (tracks.size() - 1)) { - SWAP(tracks[p_track], tracks[p_track + 1]); + SWAP(tracks.write[p_track], tracks.write[p_track + 1]); } emit_changed(); @@ -2585,7 +2585,7 @@ void Animation::track_move_down(int p_track) { if (p_track > 0 && p_track < tracks.size()) { - SWAP(tracks[p_track], tracks[p_track - 1]); + SWAP(tracks.write[p_track], tracks.write[p_track - 1]); } emit_changed(); } @@ -2596,7 +2596,7 @@ void Animation::track_swap(int p_track, int p_with_track) { ERR_FAIL_INDEX(p_with_track, tracks.size()); if (p_track == p_with_track) return; - SWAP(tracks[p_track], tracks[p_with_track]); + SWAP(tracks.write[p_track], tracks.write[p_with_track]); emit_changed(); } @@ -2927,9 +2927,9 @@ void Animation::_transform_track_optimize(int p_idx, float p_allowed_linear_err, for (int i = 1; i < tt->transforms.size() - 1; i++) { - TKey<TransformKey> &t0 = tt->transforms[i - 1]; - TKey<TransformKey> &t1 = tt->transforms[i]; - TKey<TransformKey> &t2 = tt->transforms[i + 1]; + TKey<TransformKey> &t0 = tt->transforms.write[i - 1]; + TKey<TransformKey> &t1 = tt->transforms.write[i]; + TKey<TransformKey> &t2 = tt->transforms.write[i + 1]; bool erase = _transform_track_optimize_key(t0, t1, t2, p_allowed_linear_err, p_allowed_angular_err, p_max_optimizable_angle, norm); if (erase && !prev_erased) { diff --git a/scene/resources/bit_mask.cpp b/scene/resources/bit_mask.cpp index 29ffefd9d6..85e36abf4e 100644 --- a/scene/resources/bit_mask.cpp +++ b/scene/resources/bit_mask.cpp @@ -130,7 +130,7 @@ void BitMap::set_bit(const Point2 &p_pos, bool p_value) { else b &= ~(1 << bbit); - bitmask[bbyte] = b; + bitmask.write[bbyte] = b; } bool BitMap::get_bit(const Point2 &p_pos) const { @@ -322,8 +322,8 @@ Vector<Vector2> BitMap::_march_square(const Rect2i &rect, const Point2i &start) curx += stepx; cury += stepy; if (stepx == prevx && stepy == prevy) { - _points[_points.size() - 1].x = (float)(curx - rect.position.x); - _points[_points.size() - 1].y = (float)(cury + rect.position.y); + _points.write[_points.size() - 1].x = (float)(curx - rect.position.x); + _points.write[_points.size() - 1].y = (float)(cury + rect.position.y); } else { _points.push_back(Vector2((float)(curx - rect.position.x), (float)(cury + rect.position.y))); } @@ -373,11 +373,11 @@ static Vector<Vector2> rdp(const Vector<Vector2> &v, float optimization) { Vector<Vector2> left, right; left.resize(index); for (int i = 0; i < index; i++) { - left[i] = v[i]; + left.write[i] = v[i]; } right.resize(v.size() - index); for (int i = 0; i < right.size(); i++) { - right[i] = v[index + i]; + right.write[i] = v[index + i]; } Vector<Vector2> r1 = rdp(left, optimization); Vector<Vector2> r2 = rdp(right, optimization); @@ -385,7 +385,7 @@ static Vector<Vector2> rdp(const Vector<Vector2> &v, float optimization) { int middle = r1.size(); r1.resize(r1.size() + r2.size()); for (int i = 0; i < r2.size(); i++) { - r1[middle + i] = r2[i]; + r1.write[middle + i] = r2[i]; } return r1; } else { @@ -412,7 +412,7 @@ static Vector<Vector2> reduce(const Vector<Vector2> &points, const Rect2i &rect, Vector2 last = result[result.size() - 1]; if (last.y > result[0].y && last.distance_to(result[0]) < ep * 0.5f) { - result[0].y = last.y; + result.write[0].y = last.y; result.resize(result.size() - 1); } return result; diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp index b2f586d02d..4a43303d84 100644 --- a/scene/resources/color_ramp.cpp +++ b/scene/resources/color_ramp.cpp @@ -40,10 +40,10 @@ Gradient::Gradient() { //Set initial color ramp transition from black to white points.resize(2); - points[0].color = Color(0, 0, 0, 1); - points[0].offset = 0; - points[1].color = Color(1, 1, 1, 1); - points[1].offset = 1; + points.write[0].color = Color(0, 0, 0, 1); + points.write[0].offset = 0; + points.write[1].color = Color(1, 1, 1, 1); + points.write[1].offset = 1; is_sorted = true; } @@ -79,7 +79,7 @@ Vector<float> Gradient::get_offsets() const { Vector<float> offsets; offsets.resize(points.size()); for (int i = 0; i < points.size(); i++) { - offsets[i] = points[i].offset; + offsets.write[i] = points[i].offset; } return offsets; } @@ -88,7 +88,7 @@ Vector<Color> Gradient::get_colors() const { Vector<Color> colors; colors.resize(points.size()); for (int i = 0; i < points.size(); i++) { - colors[i] = points[i].color; + colors.write[i] = points[i].color; } return colors; } @@ -96,7 +96,7 @@ Vector<Color> Gradient::get_colors() const { void Gradient::set_offsets(const Vector<float> &p_offsets) { points.resize(p_offsets.size()); for (int i = 0; i < points.size(); i++) { - points[i].offset = p_offsets[i]; + points.write[i].offset = p_offsets[i]; } is_sorted = false; emit_signal(CoreStringNames::get_singleton()->changed); @@ -107,7 +107,7 @@ void Gradient::set_colors(const Vector<Color> &p_colors) { is_sorted = false; points.resize(p_colors.size()); for (int i = 0; i < points.size(); i++) { - points[i].color = p_colors[i]; + points.write[i].color = p_colors[i]; } emit_signal(CoreStringNames::get_singleton()->changed); } @@ -144,7 +144,7 @@ void Gradient::set_points(Vector<Gradient::Point> &p_points) { void Gradient::set_offset(int pos, const float offset) { if (points.size() <= pos) points.resize(pos + 1); - points[pos].offset = offset; + points.write[pos].offset = offset; is_sorted = false; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -160,7 +160,7 @@ void Gradient::set_color(int pos, const Color &color) { points.resize(pos + 1); is_sorted = false; } - points[pos].color = color; + points.write[pos].color = color; emit_signal(CoreStringNames::get_singleton()->changed); } diff --git a/scene/resources/color_ramp.h b/scene/resources/color_ramp.h index c042a0d3d0..070ad7f0d3 100644 --- a/scene/resources/color_ramp.h +++ b/scene/resources/color_ramp.h @@ -98,7 +98,7 @@ public: while (low <= high) { middle = (low + high) / 2; - Point &point = points[middle]; + const Point &point = points[middle]; if (point.offset > p_offset) { high = middle - 1; //search low end of array } else if (point.offset < p_offset) { @@ -118,8 +118,8 @@ public: return points[points.size() - 1].color; if (first < 0) return points[0].color; - Point &pointFirst = points[first]; - Point &pointSecond = points[second]; + const Point &pointFirst = points[first]; + const Point &pointSecond = points[second]; return pointFirst.color.linear_interpolate(pointSecond.color, (p_offset - pointFirst.offset) / (pointSecond.offset - pointFirst.offset)); } diff --git a/scene/resources/concave_polygon_shape.cpp b/scene/resources/concave_polygon_shape.cpp index 935f041837..bc9e2848b3 100644 --- a/scene/resources/concave_polygon_shape.cpp +++ b/scene/resources/concave_polygon_shape.cpp @@ -56,8 +56,8 @@ Vector<Vector3> ConcavePolygonShape::_gen_debug_mesh_lines() { int idx = 0; for (Set<DrawEdge>::Element *E = edges.front(); E; E = E->next()) { - points[idx + 0] = E->get().a; - points[idx + 1] = E->get().b; + points.write[idx + 0] = E->get().a; + points.write[idx + 1] = E->get().b; idx += 2; } diff --git a/scene/resources/convex_polygon_shape.cpp b/scene/resources/convex_polygon_shape.cpp index a2e0996996..fa9369d3bc 100644 --- a/scene/resources/convex_polygon_shape.cpp +++ b/scene/resources/convex_polygon_shape.cpp @@ -46,8 +46,8 @@ Vector<Vector3> ConvexPolygonShape::_gen_debug_mesh_lines() { Vector<Vector3> lines; lines.resize(md.edges.size() * 2); for (int i = 0; i < md.edges.size(); i++) { - lines[i * 2 + 0] = md.vertices[md.edges[i].a]; - lines[i * 2 + 1] = md.vertices[md.edges[i].b]; + lines.write[i * 2 + 0] = md.vertices[md.edges[i].a]; + lines.write[i * 2 + 1] = md.vertices[md.edges[i].b]; } return lines; } diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index f2fd919f20..d8989bf062 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -153,25 +153,25 @@ void Curve::clean_dupes() { void Curve::set_point_left_tangent(int i, real_t tangent) { ERR_FAIL_INDEX(i, _points.size()); - _points[i].left_tangent = tangent; - _points[i].left_mode = TANGENT_FREE; + _points.write[i].left_tangent = tangent; + _points.write[i].left_mode = TANGENT_FREE; mark_dirty(); } void Curve::set_point_right_tangent(int i, real_t tangent) { ERR_FAIL_INDEX(i, _points.size()); - _points[i].right_tangent = tangent; - _points[i].right_mode = TANGENT_FREE; + _points.write[i].right_tangent = tangent; + _points.write[i].right_mode = TANGENT_FREE; mark_dirty(); } void Curve::set_point_left_mode(int i, TangentMode p_mode) { ERR_FAIL_INDEX(i, _points.size()); - _points[i].left_mode = p_mode; + _points.write[i].left_mode = p_mode; if (i > 0) { if (p_mode == TANGENT_LINEAR) { Vector2 v = (_points[i - 1].pos - _points[i].pos).normalized(); - _points[i].left_tangent = v.y / v.x; + _points.write[i].left_tangent = v.y / v.x; } } mark_dirty(); @@ -179,11 +179,11 @@ void Curve::set_point_left_mode(int i, TangentMode p_mode) { void Curve::set_point_right_mode(int i, TangentMode p_mode) { ERR_FAIL_INDEX(i, _points.size()); - _points[i].right_mode = p_mode; + _points.write[i].right_mode = p_mode; if (i + 1 < _points.size()) { if (p_mode == TANGENT_LINEAR) { Vector2 v = (_points[i + 1].pos - _points[i].pos).normalized(); - _points[i].right_tangent = v.y / v.x; + _points.write[i].right_tangent = v.y / v.x; } } mark_dirty(); @@ -222,7 +222,7 @@ void Curve::clear_points() { void Curve::set_point_value(int p_index, real_t pos) { ERR_FAIL_INDEX(p_index, _points.size()); - _points[p_index].pos.y = pos; + _points.write[p_index].pos.y = pos; update_auto_tangents(p_index); mark_dirty(); } @@ -232,10 +232,10 @@ int Curve::set_point_offset(int p_index, float offset) { Point p = _points[p_index]; remove_point(p_index); int i = add_point(Vector2(offset, p.pos.y)); - _points[i].left_tangent = p.left_tangent; - _points[i].right_tangent = p.right_tangent; - _points[i].left_mode = p.left_mode; - _points[i].right_mode = p.right_mode; + _points.write[i].left_tangent = p.left_tangent; + _points.write[i].right_tangent = p.right_tangent; + _points.write[i].left_mode = p.left_mode; + _points.write[i].right_mode = p.right_mode; if (p_index != i) update_auto_tangents(p_index); update_auto_tangents(i); @@ -254,7 +254,7 @@ Curve::Point Curve::get_point(int p_index) const { void Curve::update_auto_tangents(int i) { - Point &p = _points[i]; + Point &p = _points.write[i]; if (i > 0) { if (p.left_mode == TANGENT_LINEAR) { @@ -263,7 +263,7 @@ void Curve::update_auto_tangents(int i) { } if (_points[i - 1].right_mode == TANGENT_LINEAR) { Vector2 v = (_points[i - 1].pos - p.pos).normalized(); - _points[i - 1].right_tangent = v.y / v.x; + _points.write[i - 1].right_tangent = v.y / v.x; } } @@ -274,7 +274,7 @@ void Curve::update_auto_tangents(int i) { } if (_points[i + 1].left_mode == TANGENT_LINEAR) { Vector2 v = (_points[i + 1].pos - p.pos).normalized(); - _points[i + 1].left_tangent = v.y / v.x; + _points.write[i + 1].left_tangent = v.y / v.x; } } } @@ -402,7 +402,7 @@ void Curve::set_data(Array input) { for (int j = 0; j < _points.size(); ++j) { - Point &p = _points[j]; + Point &p = _points.write[j]; int i = j * ELEMS; p.pos = input[i]; @@ -426,12 +426,12 @@ void Curve::bake() { for (int i = 1; i < _bake_resolution - 1; ++i) { real_t x = i / static_cast<real_t>(_bake_resolution); real_t y = interpolate(x); - _baked_cache[i] = y; + _baked_cache.write[i] = y; } if (_points.size() != 0) { - _baked_cache[0] = _points[0].pos.y; - _baked_cache[_baked_cache.size() - 1] = _points[_points.size() - 1].pos.y; + _baked_cache.write[0] = _points[0].pos.y; + _baked_cache.write[_baked_cache.size() - 1] = _points[_points.size() - 1].pos.y; } _baked_cache_dirty = false; @@ -553,7 +553,7 @@ void Curve2D::set_point_position(int p_index, const Vector2 &p_pos) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].pos = p_pos; + points.write[p_index].pos = p_pos; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -567,7 +567,7 @@ void Curve2D::set_point_in(int p_index, const Vector2 &p_in) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].in = p_in; + points.write[p_index].in = p_in; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -581,7 +581,7 @@ void Curve2D::set_point_out(int p_index, const Vector2 &p_out) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].out = p_out; + points.write[p_index].out = p_out; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -930,9 +930,9 @@ void Curve2D::_set_data(const Dictionary &p_data) { for (int i = 0; i < points.size(); i++) { - points[i].in = r[i * 3 + 0]; - points[i].out = r[i * 3 + 1]; - points[i].pos = r[i * 3 + 2]; + points.write[i].in = r[i * 3 + 0]; + points.write[i].out = r[i * 3 + 1]; + points.write[i].pos = r[i * 3 + 2]; } baked_cache_dirty = true; @@ -952,7 +952,7 @@ PoolVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const int pc = 1; for (int i = 0; i < points.size() - 1; i++) { - _bake_segment2d(midpoints[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); + _bake_segment2d(midpoints.write[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); pc++; pc += midpoints[i].size(); } @@ -1049,7 +1049,7 @@ void Curve3D::set_point_position(int p_index, const Vector3 &p_pos) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].pos = p_pos; + points.write[p_index].pos = p_pos; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -1063,7 +1063,7 @@ void Curve3D::set_point_tilt(int p_index, float p_tilt) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].tilt = p_tilt; + points.write[p_index].tilt = p_tilt; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -1077,7 +1077,7 @@ void Curve3D::set_point_in(int p_index, const Vector3 &p_in) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].in = p_in; + points.write[p_index].in = p_in; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -1091,7 +1091,7 @@ void Curve3D::set_point_out(int p_index, const Vector3 &p_out) { ERR_FAIL_INDEX(p_index, points.size()); - points[p_index].out = p_out; + points.write[p_index].out = p_out; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } @@ -1621,10 +1621,10 @@ void Curve3D::_set_data(const Dictionary &p_data) { for (int i = 0; i < points.size(); i++) { - points[i].in = r[i * 3 + 0]; - points[i].out = r[i * 3 + 1]; - points[i].pos = r[i * 3 + 2]; - points[i].tilt = rt[i]; + points.write[i].in = r[i * 3 + 0]; + points.write[i].out = r[i * 3 + 1]; + points.write[i].pos = r[i * 3 + 2]; + points.write[i].tilt = rt[i]; } baked_cache_dirty = true; @@ -1644,7 +1644,7 @@ PoolVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const int pc = 1; for (int i = 0; i < points.size() - 1; i++) { - _bake_segment3d(midpoints[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); + _bake_segment3d(midpoints.write[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); pc++; pc += midpoints[i].size(); } diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index eb7d517841..2f2abd4e08 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -314,7 +314,7 @@ void DynamicFontAtSize::set_texture_flags(uint32_t p_flags) { texture_flags = p_flags; for (int i = 0; i < textures.size(); i++) { - Ref<ImageTexture> &tex = textures[i].texture; + Ref<ImageTexture> &tex = textures.write[i].texture; if (!tex.is_null()) tex->set_flags(p_flags); } @@ -400,7 +400,7 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp for (int i = 0; i < textures.size(); i++) { - CharTexture &ct = textures[i]; + const CharTexture &ct = textures[i]; if (ct.texture->get_format() != p_image_format) continue; @@ -466,7 +466,7 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp } tex.offsets.resize(texsize); for (int i = 0; i < texsize; i++) //zero offsets - tex.offsets[i] = 0; + tex.offsets.write[i] = 0; textures.push_back(tex); ret.index = textures.size() - 1; @@ -493,7 +493,7 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b //fit character in char texture - CharTexture &tex = textures[tex_pos.index]; + CharTexture &tex = textures.write[tex_pos.index]; { PoolVector<uint8_t>::Write wr = tex.imgdata.write(); @@ -547,7 +547,7 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b // update height array for (int k = tex_pos.x; k < tex_pos.x + mw; k++) { - tex.offsets[k] = tex_pos.y + mh; + tex.offsets.write[k] = tex_pos.y + mh; } Character chr; @@ -698,9 +698,9 @@ void DynamicFont::_reload_cache() { } for (int i = 0; i < fallbacks.size(); i++) { - fallback_data_at_size[i] = fallbacks[i]->_get_dynamic_font_at_size(cache_id); + fallback_data_at_size.write[i] = fallbacks.write[i]->_get_dynamic_font_at_size(cache_id); if (outline_cache_id.outline_size > 0) - fallback_outline_data_at_size[i] = fallbacks[i]->_get_dynamic_font_at_size(outline_cache_id); + fallback_outline_data_at_size.write[i] = fallbacks.write[i]->_get_dynamic_font_at_size(outline_cache_id); } emit_changed(); @@ -895,17 +895,17 @@ void DynamicFont::set_fallback(int p_idx, const Ref<DynamicFontData> &p_data) { ERR_FAIL_COND(p_data.is_null()); ERR_FAIL_INDEX(p_idx, fallbacks.size()); - fallbacks[p_idx] = p_data; - fallback_data_at_size[p_idx] = fallbacks[p_idx]->_get_dynamic_font_at_size(cache_id); + fallbacks.write[p_idx] = p_data; + fallback_data_at_size.write[p_idx] = fallbacks.write[p_idx]->_get_dynamic_font_at_size(cache_id); } void DynamicFont::add_fallback(const Ref<DynamicFontData> &p_data) { ERR_FAIL_COND(p_data.is_null()); fallbacks.push_back(p_data); - fallback_data_at_size.push_back(fallbacks[fallbacks.size() - 1]->_get_dynamic_font_at_size(cache_id)); //const.. + fallback_data_at_size.push_back(fallbacks.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(cache_id)); //const.. if (outline_cache_id.outline_size > 0) - fallback_outline_data_at_size.push_back(fallbacks[fallbacks.size() - 1]->_get_dynamic_font_at_size(outline_cache_id)); + fallback_outline_data_at_size.push_back(fallbacks.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(outline_cache_id)); _change_notify(); emit_changed(); @@ -1092,7 +1092,7 @@ void DynamicFont::update_oversampling() { dynamic_font_mutex->unlock(); for (int i = 0; i < changed.size(); i++) { - changed[i]->emit_changed(); + changed.write[i]->emit_changed(); } } diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 0bae9d9b2d..3dfde01320 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -386,7 +386,7 @@ Vector<CharType> BitmapFont::get_char_keys() const { int count = 0; while ((ct = char_map.next(ct))) { - chars[count++] = *ct; + chars.write[count++] = *ct; }; return chars; @@ -438,7 +438,7 @@ Vector<BitmapFont::KerningPairKey> BitmapFont::get_kerning_pair_keys() const { int i = 0; for (Map<KerningPairKey, int>::Element *E = kerning_map.front(); E; E = E->next()) { - ret[i++] = E->key(); + ret.write[i++] = E->key(); } return ret; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index fe87dcdd2c..e74ad2e55b 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -126,16 +126,16 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) { PoolVector<Vector3>::Read ver_r = vertices.read(); for (int j = 0, x = 0, i = 0; i < triangles_num; j += 6, x += 3, ++i) { // Triangle line 1 - r_lines[j + 0] = ver_r[ind_r[x + 0]]; - r_lines[j + 1] = ver_r[ind_r[x + 1]]; + r_lines.write[j + 0] = ver_r[ind_r[x + 0]]; + r_lines.write[j + 1] = ver_r[ind_r[x + 1]]; // Triangle line 2 - r_lines[j + 2] = ver_r[ind_r[x + 1]]; - r_lines[j + 3] = ver_r[ind_r[x + 2]]; + r_lines.write[j + 2] = ver_r[ind_r[x + 1]]; + r_lines.write[j + 3] = ver_r[ind_r[x + 2]]; // Triangle line 3 - r_lines[j + 4] = ver_r[ind_r[x + 2]]; - r_lines[j + 5] = ver_r[ind_r[x + 0]]; + r_lines.write[j + 4] = ver_r[ind_r[x + 2]]; + r_lines.write[j + 5] = ver_r[ind_r[x + 0]]; } } void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) { @@ -148,7 +148,7 @@ void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) { int vertices_size = vertices.size(); r_points.resize(vertices_size); for (int i = 0; i < vertices_size; ++i) { - r_points[i] = vertices[i]; + r_points.write[i] = vertices[i]; } } @@ -667,7 +667,7 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { bone_aabb.resize(baabb.size()); for (int i = 0; i < baabb.size(); i++) { - bone_aabb[i] = baabb[i]; + bone_aabb.write[i] = baabb[i]; } } @@ -839,8 +839,8 @@ void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array & aabb.expand_to(vtx[i]); } - surfaces[surfaces.size() - 1].aabb = aabb; - surfaces[surfaces.size() - 1].is_2d = arr.get_type() == Variant::POOL_VECTOR2_ARRAY; + surfaces.write[surfaces.size() - 1].aabb = aabb; + surfaces.write[surfaces.size() - 1].is_2d = arr.get_type() == Variant::POOL_VECTOR2_ARRAY; _recompute_aabb(); } @@ -959,7 +959,7 @@ void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) ERR_FAIL_INDEX(p_idx, surfaces.size()); if (surfaces[p_idx].material == p_material) return; - surfaces[p_idx].material = p_material; + surfaces.write[p_idx].material = p_material; VisualServer::get_singleton()->mesh_surface_set_material(mesh, p_idx, p_material.is_null() ? RID() : p_material->get_rid()); _change_notify("material"); @@ -970,7 +970,7 @@ void ArrayMesh::surface_set_name(int p_idx, const String &p_name) { ERR_FAIL_INDEX(p_idx, surfaces.size()); - surfaces[p_idx].name = p_name; + surfaces.write[p_idx].name = p_name; emit_changed(); } @@ -990,7 +990,7 @@ void ArrayMesh::surface_update_region(int p_surface, int p_offset, const PoolVec void ArrayMesh::surface_set_custom_aabb(int p_idx, const AABB &p_aabb) { ERR_FAIL_INDEX(p_idx, surfaces.size()); - surfaces[p_idx].aabb = p_aabb; + surfaces.write[p_idx].aabb = p_aabb; // set custom aabb too? emit_changed(); } @@ -1093,8 +1093,8 @@ void ArrayMesh::regen_normalmaps() { for (int i = 0; i < surfs.size(); i++) { - surfs[i]->generate_tangents(); - surfs[i]->commit(Ref<ArrayMesh>(this)); + surfs.write[i]->generate_tangents(); + surfs.write[i]->commit(Ref<ArrayMesh>(this)); } } @@ -1159,13 +1159,13 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe Vector3 v = p_base_transform.xform(r[j]); Vector3 n = p_base_transform.basis.xform(rn[j]).normalized(); - vertices[(j + vertex_ofs) * 3 + 0] = v.x; - vertices[(j + vertex_ofs) * 3 + 1] = v.y; - vertices[(j + vertex_ofs) * 3 + 2] = v.z; - normals[(j + vertex_ofs) * 3 + 0] = n.x; - normals[(j + vertex_ofs) * 3 + 1] = n.y; - normals[(j + vertex_ofs) * 3 + 2] = n.z; - uv_index[j + vertex_ofs] = Pair<int, int>(i, j); + vertices.write[(j + vertex_ofs) * 3 + 0] = v.x; + vertices.write[(j + vertex_ofs) * 3 + 1] = v.y; + vertices.write[(j + vertex_ofs) * 3 + 2] = v.z; + normals.write[(j + vertex_ofs) * 3 + 0] = n.x; + normals.write[(j + vertex_ofs) * 3 + 1] = n.y; + normals.write[(j + vertex_ofs) * 3 + 2] = n.z; + uv_index.write[j + vertex_ofs] = Pair<int, int>(i, j); } PoolVector<int> rindices = arrays[Mesh::ARRAY_INDEX]; @@ -1248,31 +1248,31 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe SurfaceTool::Vertex v = surfaces[surface].vertices[uv_index[gen_vertices[gen_indices[i + j]]].second]; if (surfaces[surface].format & ARRAY_FORMAT_COLOR) { - surfaces_tools[surface]->add_color(v.color); + surfaces_tools.write[surface]->add_color(v.color); } if (surfaces[surface].format & ARRAY_FORMAT_TEX_UV) { - surfaces_tools[surface]->add_uv(v.uv); + surfaces_tools.write[surface]->add_uv(v.uv); } if (surfaces[surface].format & ARRAY_FORMAT_NORMAL) { - surfaces_tools[surface]->add_normal(v.normal); + surfaces_tools.write[surface]->add_normal(v.normal); } if (surfaces[surface].format & ARRAY_FORMAT_TANGENT) { Plane t; t.normal = v.tangent; t.d = v.binormal.dot(v.normal.cross(v.tangent)) < 0 ? -1 : 1; - surfaces_tools[surface]->add_tangent(t); + surfaces_tools.write[surface]->add_tangent(t); } if (surfaces[surface].format & ARRAY_FORMAT_BONES) { - surfaces_tools[surface]->add_bones(v.bones); + surfaces_tools.write[surface]->add_bones(v.bones); } if (surfaces[surface].format & ARRAY_FORMAT_WEIGHTS) { - surfaces_tools[surface]->add_weights(v.weights); + surfaces_tools.write[surface]->add_weights(v.weights); } Vector2 uv2(gen_uvs[gen_indices[i + j] * 2 + 0], gen_uvs[gen_indices[i + j] * 2 + 1]); - surfaces_tools[surface]->add_uv2(uv2); + surfaces_tools.write[surface]->add_uv2(uv2); - surfaces_tools[surface]->add_vertex(v.vertex); + surfaces_tools.write[surface]->add_vertex(v.vertex); } } @@ -1284,8 +1284,8 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe //generate surfaces for (int i = 0; i < surfaces_tools.size(); i++) { - surfaces_tools[i]->index(); - surfaces_tools[i]->commit(Ref<ArrayMesh>((ArrayMesh *)this), surfaces[i].format); + surfaces_tools.write[i]->index(); + surfaces_tools.write[i]->commit(Ref<ArrayMesh>((ArrayMesh *)this), surfaces[i].format); } set_lightmap_size_hint(Size2(size_x, size_y)); diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 8639b325c3..6732303925 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -120,7 +120,7 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf v.bones.push_back(bo[i * 4 + 3]); } - vertices[i] = v; + vertices.write[i] = v; } PoolVector<int> indices; @@ -143,7 +143,7 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf for (int i = 0; i < icount; i += 3) { - Vertex *v[3] = { &vertices[r[i + 0]], &vertices[r[i + 1]], &vertices[r[i + 2]] }; + Vertex *v[3] = { &vertices.write[r[i + 0]], &vertices.write[r[i + 1]], &vertices.write[r[i + 2]] }; int fidx = faces.size(); Face face; @@ -169,7 +169,7 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf edges.push_back(e); } - edges[face.edges[j]].faces.push_back(fidx); + edges.write[face.edges[j]].faces.push_back(fidx); v[j]->faces.push_back(fidx); v[j]->edges.push_back(face.edges[j]); } @@ -247,7 +247,7 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { for (int i = 0; i < vcount; i++) { - Vertex &vtx = vertices[i]; + const Vertex &vtx = vertices[i]; vr[i] = vtx.vertex; if (nr.ptr()) @@ -344,7 +344,7 @@ Vector3 MeshDataTool::get_vertex(int p_idx) const { void MeshDataTool::set_vertex(int p_idx, const Vector3 &p_vertex) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].vertex = p_vertex; + vertices.write[p_idx].vertex = p_vertex; } Vector3 MeshDataTool::get_vertex_normal(int p_idx) const { @@ -355,7 +355,7 @@ Vector3 MeshDataTool::get_vertex_normal(int p_idx) const { void MeshDataTool::set_vertex_normal(int p_idx, const Vector3 &p_normal) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].normal = p_normal; + vertices.write[p_idx].normal = p_normal; format |= Mesh::ARRAY_FORMAT_NORMAL; } @@ -367,7 +367,7 @@ Plane MeshDataTool::get_vertex_tangent(int p_idx) const { void MeshDataTool::set_vertex_tangent(int p_idx, const Plane &p_tangent) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].tangent = p_tangent; + vertices.write[p_idx].tangent = p_tangent; format |= Mesh::ARRAY_FORMAT_TANGENT; } @@ -379,7 +379,7 @@ Vector2 MeshDataTool::get_vertex_uv(int p_idx) const { void MeshDataTool::set_vertex_uv(int p_idx, const Vector2 &p_uv) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].uv = p_uv; + vertices.write[p_idx].uv = p_uv; format |= Mesh::ARRAY_FORMAT_TEX_UV; } @@ -391,7 +391,7 @@ Vector2 MeshDataTool::get_vertex_uv2(int p_idx) const { void MeshDataTool::set_vertex_uv2(int p_idx, const Vector2 &p_uv2) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].uv2 = p_uv2; + vertices.write[p_idx].uv2 = p_uv2; format |= Mesh::ARRAY_FORMAT_TEX_UV2; } @@ -403,7 +403,7 @@ Color MeshDataTool::get_vertex_color(int p_idx) const { void MeshDataTool::set_vertex_color(int p_idx, const Color &p_color) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].color = p_color; + vertices.write[p_idx].color = p_color; format |= Mesh::ARRAY_FORMAT_COLOR; } @@ -415,7 +415,7 @@ Vector<int> MeshDataTool::get_vertex_bones(int p_idx) const { void MeshDataTool::set_vertex_bones(int p_idx, const Vector<int> &p_bones) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].bones = p_bones; + vertices.write[p_idx].bones = p_bones; format |= Mesh::ARRAY_FORMAT_BONES; } @@ -426,7 +426,7 @@ Vector<float> MeshDataTool::get_vertex_weights(int p_idx) const { } void MeshDataTool::set_vertex_weights(int p_idx, const Vector<float> &p_weights) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].weights = p_weights; + vertices.write[p_idx].weights = p_weights; format |= Mesh::ARRAY_FORMAT_WEIGHTS; } @@ -439,7 +439,7 @@ Variant MeshDataTool::get_vertex_meta(int p_idx) const { void MeshDataTool::set_vertex_meta(int p_idx, const Variant &p_meta) { ERR_FAIL_INDEX(p_idx, vertices.size()); - vertices[p_idx].meta = p_meta; + vertices.write[p_idx].meta = p_meta; } Vector<int> MeshDataTool::get_vertex_edges(int p_idx) const { @@ -472,7 +472,7 @@ Variant MeshDataTool::get_edge_meta(int p_idx) const { void MeshDataTool::set_edge_meta(int p_idx, const Variant &p_meta) { ERR_FAIL_INDEX(p_idx, edges.size()); - edges[p_idx].meta = p_meta; + edges.write[p_idx].meta = p_meta; } int MeshDataTool::get_face_vertex(int p_face, int p_vertex) const { @@ -495,7 +495,7 @@ Variant MeshDataTool::get_face_meta(int p_face) const { void MeshDataTool::set_face_meta(int p_face, const Variant &p_meta) { ERR_FAIL_INDEX(p_face, faces.size()); - faces[p_face].meta = p_meta; + faces.write[p_face].meta = p_meta; } Vector3 MeshDataTool::get_face_normal(int p_face) const { diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index e1d3540fd1..a1d3e0ba1e 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -209,7 +209,7 @@ Vector<int> MeshLibrary::get_item_list() const { int idx = 0; for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) { - ret[idx++] = E->key(); + ret.write[idx++] = E->key(); } return ret; diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 846f6e356e..b95e0495d9 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -325,7 +325,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (c.binds.size()) { binds.resize(c.binds.size()); for (int j = 0; j < c.binds.size(); j++) - binds[j] = props[c.binds[j]]; + binds.write[j] = props[c.binds[j]]; } cfrom->connect(snames[c.signal], cto, snames[c.method], binds, CONNECT_PERSIST | c.flags); @@ -875,7 +875,7 @@ Error SceneState::pack(Node *p_scene) { for (Map<StringName, int>::Element *E = name_map.front(); E; E = E->next()) { - names[E->get()] = E->key(); + names.write[E->get()] = E->key(); } variants.resize(variant_map.size()); @@ -883,13 +883,13 @@ Error SceneState::pack(Node *p_scene) { while ((K = variant_map.next(K))) { int idx = variant_map[*K]; - variants[idx] = *K; + variants.write[idx] = *K; } node_paths.resize(nodepath_map.size()); for (Map<Node *, int>::Element *E = nodepath_map.front(); E; E = E->next()) { - node_paths[E->get()] = scene->get_path_to(E->key()); + node_paths.write[E->get()] = scene->get_path_to(E->key()); } return OK; @@ -1090,7 +1090,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { names.resize(namecount); PoolVector<String>::Read r = snames.read(); for (int i = 0; i < names.size(); i++) - names[i] = r[i]; + names.write[i] = r[i]; } Array svariants = p_dictionary["variants"]; @@ -1100,7 +1100,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { variants.resize(varcount); for (int i = 0; i < varcount; i++) { - variants[i] = svariants[i]; + variants.write[i] = svariants[i]; } } else { @@ -1114,7 +1114,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { PoolVector<int>::Read r = snodes.read(); int idx = 0; for (int i = 0; i < nc; i++) { - NodeData &nd = nodes[i]; + NodeData &nd = nodes.write[i]; nd.parent = r[idx++]; nd.owner = r[idx++]; nd.type = r[idx++]; @@ -1126,13 +1126,13 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { nd.properties.resize(r[idx++]); for (int j = 0; j < nd.properties.size(); j++) { - nd.properties[j].name = r[idx++]; - nd.properties[j].value = r[idx++]; + nd.properties.write[j].name = r[idx++]; + nd.properties.write[j].value = r[idx++]; } nd.groups.resize(r[idx++]); for (int j = 0; j < nd.groups.size(); j++) { - nd.groups[j] = r[idx++]; + nd.groups.write[j] = r[idx++]; } } } @@ -1146,7 +1146,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { PoolVector<int>::Read r = sconns.read(); int idx = 0; for (int i = 0; i < cc; i++) { - ConnectionData &cd = connections[i]; + ConnectionData &cd = connections.write[i]; cd.from = r[idx++]; cd.to = r[idx++]; cd.signal = r[idx++]; @@ -1156,7 +1156,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { for (int j = 0; j < cd.binds.size(); j++) { - cd.binds[j] = r[idx++]; + cd.binds.write[j] = r[idx++]; } } } @@ -1167,7 +1167,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { } node_paths.resize(np.size()); for (int i = 0; i < np.size(); i++) { - node_paths[i] = np[i]; + node_paths.write[i] = np[i]; } Array ei; @@ -1181,7 +1181,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { editable_instances.resize(ei.size()); for (int i = 0; i < editable_instances.size(); i++) { - editable_instances[i] = ei[i]; + editable_instances.write[i] = ei[i]; } //path=p_dictionary["path"]; @@ -1563,13 +1563,13 @@ void SceneState::add_node_property(int p_node, int p_name, int p_value) { NodeData::Property prop; prop.name = p_name; prop.value = p_value; - nodes[p_node].properties.push_back(prop); + nodes.write[p_node].properties.push_back(prop); } void SceneState::add_node_group(int p_node, int p_group) { ERR_FAIL_INDEX(p_node, nodes.size()); ERR_FAIL_INDEX(p_group, names.size()); - nodes[p_node].groups.push_back(p_group); + nodes.write[p_node].groups.push_back(p_group); } void SceneState::set_base_scene(int p_idx) { diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 6fea2e1a8e..44f9ebaf33 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -65,8 +65,8 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> for (int i = 0; i < p_points.size(); i++) { - points[i].pos = p_points[i]; - points[i].penalty = 0; + points.write[i].pos = p_points[i]; + points.write[i].penalty = 0; outside_point.x = i == 0 ? p_points[0].x : (MAX(p_points[i].x, outside_point.x)); outside_point.y = i == 0 ? p_points[0].y : (MAX(p_points[i].y, outside_point.y)); @@ -88,8 +88,8 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> Edge e(p_connections[i], p_connections[i + 1]); ERR_FAIL_INDEX(e.points[0], point_count); ERR_FAIL_INDEX(e.points[1], point_count); - points[p_connections[i]].connections.insert(p_connections[i + 1]); - points[p_connections[i + 1]].connections.insert(p_connections[i]); + points.write[p_connections[i]].connections.insert(p_connections[i + 1]); + points.write[p_connections[i + 1]].connections.insert(p_connections[i]); edges.insert(e); } @@ -126,8 +126,8 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> } if (valid) { - points[i].connections.insert(j); - points[j].connections.insert(i); + points.write[i].connections.insert(j); + points.write[j].connections.insert(i); } } } @@ -227,21 +227,21 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector int aidx = points.size() - 2; int bidx = points.size() - 1; - points[aidx].pos = from; - points[bidx].pos = to; - points[aidx].distance = 0; - points[bidx].distance = 0; - points[aidx].prev = -1; - points[bidx].prev = -1; - points[aidx].penalty = 0; - points[bidx].penalty = 0; + points.write[aidx].pos = from; + points.write[bidx].pos = to; + points.write[aidx].distance = 0; + points.write[bidx].distance = 0; + points.write[aidx].prev = -1; + points.write[bidx].prev = -1; + points.write[aidx].penalty = 0; + points.write[bidx].penalty = 0; for (int i = 0; i < points.size() - 2; i++) { bool valid_a = true; bool valid_b = true; - points[i].prev = -1; - points[i].distance = 0; + points.write[i].prev = -1; + points.write[i].distance = 0; if (!_is_point_inside(from * 0.5 + points[i].pos * 0.5)) { valid_a = false; @@ -292,26 +292,26 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } if (valid_a) { - points[i].connections.insert(aidx); - points[aidx].connections.insert(i); + points.write[i].connections.insert(aidx); + points.write[aidx].connections.insert(i); } if (valid_b) { - points[i].connections.insert(bidx); - points[bidx].connections.insert(i); + points.write[i].connections.insert(bidx); + points.write[bidx].connections.insert(i); } } //solve graph Set<int> open_list; - points[aidx].distance = 0; - points[aidx].prev = aidx; + points.write[aidx].distance = 0; + points.write[aidx].prev = aidx; for (Set<int>::Element *E = points[aidx].connections.front(); E; E = E->next()) { open_list.insert(E->get()); - points[E->get()].distance = from.distance_to(points[E->get()].pos); - points[E->get()].prev = aidx; + points.write[E->get()].distance = from.distance_to(points[E->get()].pos); + points.write[E->get()].prev = aidx; } bool found_route = false; @@ -342,12 +342,12 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } } - Point &np = points[least_cost_point]; + const Point &np = points[least_cost_point]; //open the neighbours for search for (Set<int>::Element *E = np.connections.front(); E; E = E->next()) { - Point &p = points[E->get()]; + Point &p = points.write[E->get()]; float distance = np.pos.distance_to(p.pos) + np.distance; if (p.prev != -1) { @@ -392,18 +392,18 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector for (int i = 0; i < points.size() - 2; i++) { - points[i].connections.erase(aidx); - points[i].connections.erase(bidx); - points[i].prev = -1; - points[i].distance = 0; + points.write[i].connections.erase(aidx); + points.write[i].connections.erase(bidx); + points.write[i].prev = -1; + points.write[i].distance = 0; } - points[aidx].connections.clear(); - points[aidx].prev = -1; - points[aidx].distance = 0; - points[bidx].connections.clear(); - points[bidx].prev = -1; - points[bidx].distance = 0; + points.write[aidx].connections.clear(); + points.write[aidx].prev = -1; + points.write[aidx].distance = 0; + points.write[bidx].connections.clear(); + points.write[bidx].prev = -1; + points.write[bidx].distance = 0; return path; } @@ -427,13 +427,13 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) { PoolVector<Vector2>::Read pr = p.read(); for (int i = 0; i < pc; i++) { - points[i].pos = pr[i]; + points.write[i].pos = pr[i]; PoolVector<int> con = c[i]; PoolVector<int>::Read cr = con.read(); int cc = con.size(); for (int j = 0; j < cc; j++) { - points[i].connections.insert(cr[j]); + points.write[i].connections.insert(cr[j]); } } @@ -443,7 +443,7 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) { if (penalties.size() == pc) { PoolVector<float>::Read pr = penalties.read(); for (int i = 0; i < pc; i++) { - points[i].penalty = pr[i]; + points.write[i].penalty = pr[i]; } } } @@ -566,7 +566,7 @@ Rect2 PolygonPathFinder::get_bounds() const { void PolygonPathFinder::set_point_penalty(int p_point, float p_penalty) { ERR_FAIL_INDEX(p_point, points.size() - 2); - points[p_point].penalty = p_penalty; + points.write[p_point].penalty = p_penalty; } float PolygonPathFinder::get_point_penalty(int p_point) const { diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 9df117d09c..fd9989fe72 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -1523,7 +1523,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) { - sorted_er[E->get()] = E->key(); + sorted_er.write[E->get()] = E->key(); } for (int i = 0; i < sorted_er.size(); i++) { diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 3df9ab26a4..ec489e5c5b 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -466,7 +466,7 @@ void SurfaceTool::deindex() { int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) { - varr[idx++] = E->get(); + varr.write[idx++] = E->get(); } vertex_array.clear(); for (List<int>::Element *E = index_array.front(); E; E = E->next()) { @@ -570,19 +570,19 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array if (lformat & VS::ARRAY_FORMAT_BONES) { Vector<int> b; b.resize(4); - b[0] = barr[i * 4 + 0]; - b[1] = barr[i * 4 + 1]; - b[2] = barr[i * 4 + 2]; - b[3] = barr[i * 4 + 3]; + b.write[0] = barr[i * 4 + 0]; + b.write[1] = barr[i * 4 + 1]; + b.write[2] = barr[i * 4 + 2]; + b.write[3] = barr[i * 4 + 3]; v.bones = b; } if (lformat & VS::ARRAY_FORMAT_WEIGHTS) { Vector<float> w; w.resize(4); - w[0] = warr[i * 4 + 0]; - w[1] = warr[i * 4 + 1]; - w[2] = warr[i * 4 + 2]; - w[3] = warr[i * 4 + 3]; + w.write[0] = warr[i * 4 + 0]; + w.write[1] = warr[i * 4 + 1]; + w.write[2] = warr[i * 4 + 2]; + w.write[3] = warr[i * 4 + 3]; v.weights = w; } @@ -675,19 +675,19 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li if (lformat & VS::ARRAY_FORMAT_BONES) { Vector<int> b; b.resize(4); - b[0] = barr[i * 4 + 0]; - b[1] = barr[i * 4 + 1]; - b[2] = barr[i * 4 + 2]; - b[3] = barr[i * 4 + 3]; + b.write[0] = barr[i * 4 + 0]; + b.write[1] = barr[i * 4 + 1]; + b.write[2] = barr[i * 4 + 2]; + b.write[3] = barr[i * 4 + 3]; v.bones = b; } if (lformat & VS::ARRAY_FORMAT_WEIGHTS) { Vector<float> w; w.resize(4); - w[0] = warr[i * 4 + 0]; - w[1] = warr[i * 4 + 1]; - w[2] = warr[i * 4 + 2]; - w[3] = warr[i * 4 + 3]; + w.write[0] = warr[i * 4 + 0]; + w.write[1] = warr[i * 4 + 1]; + w.write[2] = warr[i * 4 + 2]; + w.write[3] = warr[i * 4 + 3]; v.weights = w; } @@ -846,7 +846,7 @@ void SurfaceTool::generate_tangents() { vtx.resize(vertex_array.size()); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) { - vtx[idx++] = E; + vtx.write[idx++] = E; E->get().binormal = Vector3(); E->get().tangent = Vector3(); } diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 5fb9f79a1e..c8d12b88fc 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1039,7 +1039,7 @@ bool LargeTexture::has_alpha() const { void LargeTexture::set_flags(uint32_t p_flags) { for (int i = 0; i < pieces.size(); i++) { - pieces[i].texture->set_flags(p_flags); + pieces.write[i].texture->set_flags(p_flags); } } @@ -1065,13 +1065,13 @@ int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture> &p_textur void LargeTexture::set_piece_offset(int p_idx, const Point2 &p_offset) { ERR_FAIL_INDEX(p_idx, pieces.size()); - pieces[p_idx].offset = p_offset; + pieces.write[p_idx].offset = p_offset; }; void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture> &p_texture) { ERR_FAIL_INDEX(p_idx, pieces.size()); - pieces[p_idx].texture = p_texture; + pieces.write[p_idx].texture = p_texture; }; void LargeTexture::set_size(const Size2 &p_size) { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index f9df6b4304..dd50671fa0 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -576,7 +576,7 @@ void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_sha ERR_FAIL_COND(!tile_map.has(p_id)); if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); - tile_map[p_id].shapes_data[p_shape_id].shape = p_shape; + tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape; emit_changed(); } @@ -594,7 +594,7 @@ void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform ERR_FAIL_COND(!tile_map.has(p_id)); if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); - tile_map[p_id].shapes_data[p_shape_id].shape_transform = p_offset; + tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset; emit_changed(); } @@ -622,7 +622,7 @@ void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_ ERR_FAIL_COND(!tile_map.has(p_id)); if (tile_map[p_id].shapes_data.size() <= p_shape_id) tile_map[p_id].shapes_data.resize(p_shape_id + 1); - tile_map[p_id].shapes_data[p_shape_id].one_way_collision = p_one_way; + tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way; emit_changed(); } |