diff options
Diffstat (limited to 'scene/resources')
43 files changed, 1495 insertions, 838 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index fb22b99b26..c9fc68233d 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -66,17 +66,17 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(track, tracks.size(), false); - if (what == "path") + if (what == "path") { track_set_path(track, p_value); - else if (what == "interp") + } else if (what == "interp") { track_set_interpolation_type(track, InterpolationType(p_value.operator int())); - else if (what == "loop_wrap") + } else if (what == "loop_wrap") { track_set_interpolation_loop_wrap(track, p_value); - else if (what == "imported") + } else if (what == "imported") { track_set_imported(track, p_value); - else if (what == "enabled") + } else if (what == "enabled") { track_set_enabled(track, p_value); - else if (what == "keys" || what == "key_values") { + } else if (what == "keys" || what == "key_values") { if (track_get_type(track) == TYPE_TRANSFORM) { TransformTrack *tt = static_cast<TransformTrack *>(tracks[track]); Vector<float> values = p_value; @@ -119,10 +119,11 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { if (d.has("update")) { int um = d["update"]; - if (um < 0) + if (um < 0) { um = 0; - else if (um > 3) + } else if (um > 3) { um = 3; + } vt->update_mode = UpdateMode(um); } @@ -158,8 +159,9 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { return true; } else if (track_get_type(track) == TYPE_METHOD) { - while (track_get_key_count(track)) + while (track_get_key_count(track)) { track_remove_key(track, 0); //well shouldn't be set anyway + } Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("times"), false); @@ -241,12 +243,15 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { for (int i = 0; i < valcount; i++) { Dictionary d2 = clips[i]; - if (!d2.has("start_offset")) + if (!d2.has("start_offset")) { continue; - if (!d2.has("end_offset")) + } + if (!d2.has("end_offset")) { continue; - if (!d2.has("stream")) + } + if (!d2.has("stream")) { continue; + } TKey<AudioKey> ak; ak.time = rt[i]; @@ -290,10 +295,12 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { } else { return false; } - } else + } else { return false; - } else + } + } else { return false; + } return true; } @@ -301,13 +308,13 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { bool Animation::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; - if (name == "length") + if (name == "length") { r_ret = length; - else if (name == "loop") + } else if (name == "loop") { r_ret = loop; - else if (name == "step") + } else if (name == "step") { r_ret = step; - else if (name.begins_with("tracks/")) { + } else if (name.begins_with("tracks/")) { int track = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); ERR_FAIL_INDEX_V(track, tracks.size(), false); @@ -335,17 +342,17 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; - } else if (what == "path") + } else if (what == "path") { r_ret = track_get_path(track); - else if (what == "interp") + } else if (what == "interp") { r_ret = track_get_interpolation_type(track); - else if (what == "loop_wrap") + } else if (what == "loop_wrap") { r_ret = track_get_interpolation_loop_wrap(track); - else if (what == "imported") + } else if (what == "imported") { r_ret = track_is_imported(track); - else if (what == "enabled") + } else if (what == "enabled") { r_ret = track_is_enabled(track); - else if (what == "keys") { + } else if (what == "keys") { if (track_get_type(track) == TYPE_TRANSFORM) { Vector<float> keys; int kk = track_get_key_count(track); @@ -553,10 +560,12 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; } - } else + } else { return false; - } else + } + } else { return false; + } return true; } @@ -574,8 +583,9 @@ void Animation::_get_property_list(List<PropertyInfo> *p_list) const { } int Animation::add_track(TrackType p_type, int p_at_pos) { - if (p_at_pos < 0 || p_at_pos >= tracks.size()) + if (p_at_pos < 0 || p_at_pos >= tracks.size()) { p_at_pos = tracks.size(); + } switch (p_type) { case TYPE_TRANSFORM: { @@ -677,8 +687,9 @@ NodePath Animation::track_get_path(int p_track) const { int Animation::find_track(const NodePath &p_path) const { for (int i = 0; i < tracks.size(); i++) { - if (tracks[i]->path == p_path) + if (tracks[i]->path == p_path) { return i; + } }; return -1; }; @@ -769,12 +780,15 @@ Error Animation::transform_track_get_key(int p_track, int p_key, Vector3 *r_loc, ERR_FAIL_COND_V(t->type != TYPE_TRANSFORM, ERR_INVALID_PARAMETER); ERR_FAIL_INDEX_V(p_key, tt->transforms.size(), ERR_INVALID_PARAMETER); - if (r_loc) + if (r_loc) { *r_loc = tt->transforms[p_key].value.loc; - if (r_rot) + } + if (r_rot) { *r_rot = tt->transforms[p_key].value.rot; - if (r_scale) + } + if (r_scale) { *r_scale = tt->transforms[p_key].value.scale; + } return OK; } @@ -857,60 +871,72 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { case TYPE_TRANSFORM: { TransformTrack *tt = static_cast<TransformTrack *>(t); int k = _find(tt->transforms, p_time); - if (k < 0 || k >= tt->transforms.size()) + if (k < 0 || k >= tt->transforms.size()) { return -1; - if (tt->transforms[k].time != p_time && p_exact) + } + if (tt->transforms[k].time != p_time && p_exact) { return -1; + } return k; } break; case TYPE_VALUE: { ValueTrack *vt = static_cast<ValueTrack *>(t); int k = _find(vt->values, p_time); - if (k < 0 || k >= vt->values.size()) + if (k < 0 || k >= vt->values.size()) { return -1; - if (vt->values[k].time != p_time && p_exact) + } + if (vt->values[k].time != p_time && p_exact) { return -1; + } return k; } break; case TYPE_METHOD: { MethodTrack *mt = static_cast<MethodTrack *>(t); int k = _find(mt->methods, p_time); - if (k < 0 || k >= mt->methods.size()) + if (k < 0 || k >= mt->methods.size()) { return -1; - if (mt->methods[k].time != p_time && p_exact) + } + if (mt->methods[k].time != p_time && p_exact) { return -1; + } return k; } break; case TYPE_BEZIER: { BezierTrack *bt = static_cast<BezierTrack *>(t); int k = _find(bt->values, p_time); - if (k < 0 || k >= bt->values.size()) + if (k < 0 || k >= bt->values.size()) { return -1; - if (bt->values[k].time != p_time && p_exact) + } + if (bt->values[k].time != p_time && p_exact) { return -1; + } return k; } break; case TYPE_AUDIO: { AudioTrack *at = static_cast<AudioTrack *>(t); int k = _find(at->values, p_time); - if (k < 0 || k >= at->values.size()) + if (k < 0 || k >= at->values.size()) { return -1; - if (at->values[k].time != p_time && p_exact) + } + if (at->values[k].time != p_time && p_exact) { return -1; + } return k; } break; case TYPE_ANIMATION: { AnimationTrack *at = static_cast<AnimationTrack *>(t); int k = _find(at->values, p_time); - if (k < 0 || k >= at->values.size()) + if (k < 0 || k >= at->values.size()) { return -1; - if (at->values[k].time != p_time && p_exact) + } + if (at->values[k].time != p_time && p_exact) { return -1; + } return k; } break; @@ -927,16 +953,19 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key case TYPE_TRANSFORM: { Dictionary d = p_key; Vector3 loc; - if (d.has("location")) + if (d.has("location")) { loc = d["location"]; + } Quat rot; - if (d.has("rotation")) + if (d.has("rotation")) { rot = d["rotation"]; + } Vector3 scale; - if (d.has("scale")) + if (d.has("scale")) { scale = d["scale"]; + } int idx = transform_track_insert_key(p_track, p_time, loc, rot, scale); track_set_key_transition(p_track, idx, p_transition); @@ -1277,12 +1306,15 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p Dictionary d = p_value; - if (d.has("location")) + if (d.has("location")) { tt->transforms.write[p_key_idx].value.loc = d["location"]; - if (d.has("rotation")) + } + if (d.has("rotation")) { tt->transforms.write[p_key_idx].value.rot = d["rotation"]; - if (d.has("scale")) + } + if (d.has("scale")) { tt->transforms.write[p_key_idx].value.scale = d["scale"]; + } } break; case TYPE_VALUE: { @@ -1298,10 +1330,12 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p Dictionary d = p_value; - if (d.has("method")) + if (d.has("method")) { mt->methods.write[p_key_idx].method = d["method"]; - if (d.has("args")) + } + if (d.has("args")) { mt->methods.write[p_key_idx].params = d["args"]; + } } break; case TYPE_BEZIER: { @@ -1379,16 +1413,18 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx, float p_tra template <class K> int Animation::_find(const Vector<K> &p_keys, float p_time) const { int len = p_keys.size(); - if (len == 0) + if (len == 0) { return -2; + } int low = 0; int high = len - 1; int middle = 0; #ifdef DEBUG_ENABLED - if (low > high) + if (low > high) { ERR_PRINT("low > high, this may be a bug"); + } #endif const K *keys = &p_keys[0]; @@ -1398,14 +1434,16 @@ int Animation::_find(const Vector<K> &p_keys, float p_time) const { if (Math::is_equal_approx(p_time, keys[middle].time)) { //match return middle; - } else if (p_time < keys[middle].time) + } else if (p_time < keys[middle].time) { high = middle - 1; //search low end of array - else + } else { low = middle + 1; //search high end of array + } } - if (keys[middle].time > p_time) + if (keys[middle].time > p_time) { middle--; + } return middle; } @@ -1551,13 +1589,15 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola if (len <= 0) { // (-1 or -2 returned originally) (plus one above) // meaning no keys, or only key time is larger than length - if (p_ok) + if (p_ok) { *p_ok = false; + } return T(); } else if (len == 1) { // one key found (0+1), return it - if (p_ok) + if (p_ok) { *p_ok = true; + } return p_keys[0].value; } @@ -1578,20 +1618,22 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola float delta = p_keys[next].time - p_keys[idx].time; float from = p_time - p_keys[idx].time; - if (Math::is_zero_approx(delta)) + if (Math::is_zero_approx(delta)) { c = 0; - else + } else { c = from / delta; + } } else { next = 0; float delta = (length - p_keys[idx].time) + p_keys[next].time; float from = p_time - p_keys[idx].time; - if (Math::is_zero_approx(delta)) + if (Math::is_zero_approx(delta)) { c = 0; - else + } else { c = from / delta; + } } } else { @@ -1599,15 +1641,17 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola idx = len - 1; next = 0; float endtime = (length - p_keys[idx].time); - if (endtime < 0) // may be keys past the end + if (endtime < 0) { // may be keys past the end endtime = 0; + } float delta = endtime + p_keys[next].time; float from = endtime + p_time; - if (Math::is_zero_approx(delta)) + if (Math::is_zero_approx(delta)) { c = 0; - else + } else { c = from / delta; + } } } else { // no loop @@ -1618,10 +1662,11 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola float delta = p_keys[next].time - p_keys[idx].time; float from = p_time - p_keys[idx].time; - if (Math::is_zero_approx(delta)) + if (Math::is_zero_approx(delta)) { c = 0; - else + } else { c = from / delta; + } } else { next = idx; @@ -1629,17 +1674,20 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola } else { // only allow extending first key to anim start if looping - if (loop) + if (loop) { idx = next = 0; - else + } else { result = false; + } } } - if (p_ok) + if (p_ok) { *p_ok = result; - if (!result) + } + if (!result) { return T(); + } float tr = p_keys[idx].transition; @@ -1661,11 +1709,13 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola } break; case INTERPOLATION_CUBIC: { int pre = idx - 1; - if (pre < 0) + if (pre < 0) { pre = 0; + } int post = next + 1; - if (post >= len) + if (post >= len) { post = next; + } return _cubic_interpolate(p_keys[pre].value, p_keys[idx].value, p_keys[next].value, p_keys[post].value, c); @@ -1688,17 +1738,21 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 TransformKey tk = _interpolate(tt->transforms, p_time, tt->interpolation, tt->loop_wrap, &ok); - if (!ok) + if (!ok) { return ERR_UNAVAILABLE; + } - if (r_loc) + if (r_loc) { *r_loc = tk.loc; + } - if (r_rot) + if (r_rot) { *r_rot = tk.rot; + } - if (r_scale) + if (r_scale) { *r_scale = tk.scale; + } return OK; } @@ -1721,8 +1775,9 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { } void Animation::_value_track_get_key_indices_in_range(const ValueTrack *vt, float from_time, float to_time, List<int> *p_indices) const { - if (from_time != length && to_time == length) + if (from_time != length && to_time == length) { to_time = length * 1.001; //include a little more if at the end + } int to = _find(vt->values, to_time); if (to >= 0 && from_time == to_time && vt->values[to].time == from_time) { @@ -1733,17 +1788,20 @@ void Animation::_value_track_get_key_indices_in_range(const ValueTrack *vt, floa // can't really send the events == time, will be sent in the next frame. // if event>=len then it will probably never be requested by the anim player. - if (to >= 0 && vt->values[to].time >= to_time) + if (to >= 0 && vt->values[to].time >= to_time) { to--; + } - if (to < 0) + if (to < 0) { return; // not bother + } int from = _find(vt->values, from_time); // position in the right first event.+ - if (from < 0 || vt->values[from].time < from_time) + if (from < 0 || vt->values[from].time < from_time) { from++; + } int max = vt->values.size(); @@ -1763,8 +1821,9 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d float from_time = p_time - p_delta; float to_time = p_time; - if (from_time > to_time) + if (from_time > to_time) { SWAP(from_time, to_time); + } if (loop) { from_time = Math::fposmod(from_time, length); @@ -1777,15 +1836,19 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d return; } } else { - if (from_time < 0) + if (from_time < 0) { from_time = 0; - if (from_time > length) + } + if (from_time > length) { from_time = length; + } - if (to_time < 0) + if (to_time < 0) { to_time = 0; - if (to_time > length) + } + if (to_time > length) { to_time = length; + } } _value_track_get_key_indices_in_range(vt, from_time, to_time, p_indices); @@ -1812,25 +1875,29 @@ Animation::UpdateMode Animation::value_track_get_update_mode(int p_track) const template <class T> void Animation::_track_get_key_indices_in_range(const Vector<T> &p_array, float from_time, float to_time, List<int> *p_indices) const { - if (from_time != length && to_time == length) + if (from_time != length && to_time == length) { to_time = length * 1.01; //include a little more if at the end + } int to = _find(p_array, to_time); // can't really send the events == time, will be sent in the next frame. // if event>=len then it will probably never be requested by the anim player. - if (to >= 0 && p_array[to].time >= to_time) + if (to >= 0 && p_array[to].time >= to_time) { to--; + } - if (to < 0) + if (to < 0) { return; // not bother + } int from = _find(p_array, from_time); // position in the right first event.+ - if (from < 0 || p_array[from].time < from_time) + if (from < 0 || p_array[from].time < from_time) { from++; + } int max = p_array.size(); @@ -1847,15 +1914,18 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float float from_time = p_time - p_delta; float to_time = p_time; - if (from_time > to_time) + if (from_time > to_time) { SWAP(from_time, to_time); + } if (loop) { - if (from_time > length || from_time < 0) + if (from_time > length || from_time < 0) { from_time = Math::fposmod(from_time, length); + } - if (to_time > length || to_time < 0) + if (to_time > length || to_time < 0) { to_time = Math::fposmod(to_time, length); + } if (from_time > to_time) { // handle loop by splitting @@ -1901,15 +1971,19 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float return; } } else { - if (from_time < 0) + if (from_time < 0) { from_time = 0; - if (from_time > length) + } + if (from_time > length) { from_time = length; + } - if (to_time < 0) + if (to_time < 0) { to_time = 0; - if (to_time > length) + } + if (to_time > length) { to_time = length; + } } switch (t->type) { @@ -1947,25 +2021,29 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float } void Animation::_method_track_get_key_indices_in_range(const MethodTrack *mt, float from_time, float to_time, List<int> *p_indices) const { - if (from_time != length && to_time == length) + if (from_time != length && to_time == length) { to_time = length * 1.01; //include a little more if at the end + } int to = _find(mt->methods, to_time); // can't really send the events == time, will be sent in the next frame. // if event>=len then it will probably never be requested by the anim player. - if (to >= 0 && mt->methods[to].time >= to_time) + if (to >= 0 && mt->methods[to].time >= to_time) { to--; + } - if (to < 0) + if (to < 0) { return; // not bother + } int from = _find(mt->methods, from_time); // position in the right first event.+ - if (from < 0 || mt->methods[from].time < from_time) + if (from < 0 || mt->methods[from].time < from_time) { from++; + } int max = mt->methods.size(); @@ -1985,15 +2063,18 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ float from_time = p_time - p_delta; float to_time = p_time; - if (from_time > to_time) + if (from_time > to_time) { SWAP(from_time, to_time); + } if (loop) { - if (from_time > length || from_time < 0) + if (from_time > length || from_time < 0) { from_time = Math::fposmod(from_time, length); + } - if (to_time > length || to_time < 0) + if (to_time > length || to_time < 0) { to_time = Math::fposmod(to_time, length); + } if (from_time > to_time) { // handle loop by splitting @@ -2002,15 +2083,19 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ return; } } else { - if (from_time < 0) + if (from_time < 0) { from_time = 0; - if (from_time > length) + } + if (from_time > length) { from_time = length; + } - if (to_time < 0) + if (to_time < 0) { to_time = 0; - if (to_time > length) + } + if (to_time > length) { to_time = length; + } } _method_track_get_key_indices_in_range(mt, from_time, to_time, p_indices); @@ -2237,11 +2322,13 @@ int Animation::audio_track_insert_key(int p_track, float p_time, const RES &p_st k.time = p_time; k.value.stream = p_stream; k.value.start_offset = p_start_offset; - if (k.value.start_offset < 0) + if (k.value.start_offset < 0) { k.value.start_offset = 0; + } k.value.end_offset = p_end_offset; - if (k.value.end_offset < 0) + if (k.value.end_offset < 0) { k.value.end_offset = 0; + } int key = _insert(p_time, at->values, k); @@ -2273,8 +2360,9 @@ void Animation::audio_track_set_key_start_offset(int p_track, int p_key, float p ERR_FAIL_INDEX(p_key, at->values.size()); - if (p_offset < 0) + if (p_offset < 0) { p_offset = 0; + } at->values.write[p_key].value.start_offset = p_offset; @@ -2290,8 +2378,9 @@ void Animation::audio_track_set_key_end_offset(int p_track, int p_key, float p_o ERR_FAIL_INDEX(p_key, at->values.size()); - if (p_offset < 0) + if (p_offset < 0) { p_offset = 0; + } at->values.write[p_key].value.end_offset = p_offset; @@ -2443,8 +2532,9 @@ void Animation::track_move_down(int p_track) { void Animation::track_move_to(int p_track, int p_to_index) { ERR_FAIL_INDEX(p_track, tracks.size()); ERR_FAIL_INDEX(p_to_index, tracks.size() + 1); - if (p_track == p_to_index || p_track == p_to_index - 1) + if (p_track == p_to_index || p_track == p_to_index - 1) { return; + } Track *track = tracks.get(p_track); tracks.remove(p_track); @@ -2458,8 +2548,9 @@ void Animation::track_move_to(int p_track, int p_to_index) { void Animation::track_swap(int p_track, int p_with_track) { ERR_FAIL_INDEX(p_track, tracks.size()); ERR_FAIL_INDEX(p_with_track, tracks.size()); - if (p_track == p_with_track) + if (p_track == p_with_track) { return; + } SWAP(tracks.write[p_track], tracks.write[p_with_track]); emit_changed(); @@ -2602,8 +2693,9 @@ void Animation::_bind_methods() { } void Animation::clear() { - for (int i = 0; i < tracks.size(); i++) + for (int i = 0; i < tracks.size(); i++) { memdelete(tracks[i]); + } tracks.clear(); loop = false; length = 1; @@ -2644,8 +2736,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons return false; //beyond allowed error for colinearity } - if (p_norm != Vector3() && Math::acos(pd.normalized().dot(p_norm)) > p_alowed_angular_err) + if (p_norm != Vector3() && Math::acos(pd.normalized().dot(p_norm)) > p_alowed_angular_err) { return false; + } t[0] = (d1 - d0) / (d2 - d0); } @@ -2660,8 +2753,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons //localize both to rotation from q0 if (q0.is_equal_approx(q2)) { - if (!q0.is_equal_approx(q1)) + if (!q0.is_equal_approx(q1)) { return false; + } } else { Quat r02 = (q0.inverse() * q2).normalized(); @@ -2673,8 +2767,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons r02.get_axis_angle(v02, a02); r01.get_axis_angle(v01, a01); - if (Math::abs(a02) > p_max_optimizable_angle) + if (Math::abs(a02) > p_max_optimizable_angle) { return false; + } if (v01.dot(v02) < 0) { //make sure both rotations go the same way to compare @@ -2694,8 +2789,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons } real_t tr = a01 / a02; - if (tr < 0 || tr > 1) + if (tr < 0 || tr > 1) { return false; //rotating too much or too less + } t[1] = tr; } @@ -2746,8 +2842,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons lt = t[j]; //official t //validate rest for (int k = j + 1; k < 3; k++) { - if (t[k] == -1) + if (t[k] == -1) { continue; + } if (Math::abs(lt - t[k]) > p_alowed_linear_err) { erase = false; @@ -2815,8 +2912,9 @@ void Animation::_transform_track_optimize(int p_idx, float p_allowed_linear_err, void Animation::optimize(float p_allowed_linear_err, float p_allowed_angular_err, float p_max_optimizable_angle) { for (int i = 0; i < tracks.size(); i++) { - if (tracks[i]->type == TYPE_TRANSFORM) + if (tracks[i]->type == TYPE_TRANSFORM) { _transform_track_optimize(i, p_allowed_linear_err, p_allowed_angular_err, p_max_optimizable_angle); + } } } @@ -2827,6 +2925,7 @@ Animation::Animation() { } Animation::~Animation() { - for (int i = 0; i < tracks.size(); i++) + for (int i = 0; i < tracks.size(); i++) { memdelete(tracks[i]); + } } diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index dafcf12183..f02e7987a9 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -72,8 +72,9 @@ float AudioStreamPlaybackSample::get_playback_position() const { } void AudioStreamPlaybackSample::seek(float p_time) { - if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) + if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) { return; //no seeking in ima-adpcm + } float max = base->get_length(); if (p_time < 0) { @@ -93,8 +94,9 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds while (amount) { amount--; int64_t pos = offset >> MIX_FRAC_BITS; - if (is_stereo && !is_ima_adpcm) + if (is_stereo && !is_ima_adpcm) { pos <<= 1; + } if (is_ima_adpcm) { int64_t sample_pos = pos + ima_adpcm[0].window_ofs; @@ -129,26 +131,33 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds step = _ima_adpcm_step_table[ima_adpcm[i].step_index]; ima_adpcm[i].step_index += _ima_adpcm_index_table[nibble]; - if (ima_adpcm[i].step_index < 0) + if (ima_adpcm[i].step_index < 0) { ima_adpcm[i].step_index = 0; - if (ima_adpcm[i].step_index > 88) + } + if (ima_adpcm[i].step_index > 88) { ima_adpcm[i].step_index = 88; + } diff = step >> 3; - if (nibble & 1) + if (nibble & 1) { diff += step >> 2; - if (nibble & 2) + } + if (nibble & 2) { diff += step >> 1; - if (nibble & 4) + } + if (nibble & 4) { diff += step; - if (nibble & 8) + } + if (nibble & 8) { diff = -diff; + } ima_adpcm[i].predictor += diff; - if (ima_adpcm[i].predictor < -0x8000) + if (ima_adpcm[i].predictor < -0x8000) { ima_adpcm[i].predictor = -0x8000; - else if (ima_adpcm[i].predictor > 0x7FFF) + } else if (ima_adpcm[i].predictor > 0x7FFF) { ima_adpcm[i].predictor = 0x7FFF; + } /* store loop if there */ if (ima_adpcm[i].last_nibble == ima_adpcm[i].loop_pos) { @@ -167,13 +176,15 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds } else { final = p_src[pos]; - if (is_stereo) + if (is_stereo) { final_r = p_src[pos + 1]; + } if (sizeof(Depth) == 1) { /* conditions will not exist anymore when compiled! */ final <<= 8; - if (is_stereo) + if (is_stereo) { final_r <<= 8; + } } if (is_stereo) { @@ -185,15 +196,17 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds if (sizeof(Depth) == 1) { next <<= 8; - if (is_stereo) + if (is_stereo) { next_r <<= 8; + } } int32_t frac = int64_t(offset & MIX_FRAC_MASK); final = final + ((next - final) * frac >> MIX_FRAC_BITS); - if (is_stereo) + if (is_stereo) { final_r = final_r + ((next_r - final_r) * frac >> MIX_FRAC_BITS); + } } if (!is_stereo) { @@ -353,23 +366,26 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in switch (base->format) { case AudioStreamSample::FORMAT_8_BITS: { - if (is_stereo) + if (is_stereo) { do_resample<int8_t, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); - else + } else { do_resample<int8_t, false, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); + } } break; case AudioStreamSample::FORMAT_16_BITS: { - if (is_stereo) + if (is_stereo) { do_resample<int16_t, true, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm); - else + } else { do_resample<int16_t, false, false>((int16_t *)data, dst_buff, offset, increment, target, ima_adpcm); + } } break; case AudioStreamSample::FORMAT_IMA_ADPCM: { - if (is_stereo) + if (is_stereo) { do_resample<int8_t, true, true>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); - else + } else { do_resample<int8_t, false, true>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); + } } break; } diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp index e23e3f4c4d..10f0de8ff8 100644 --- a/scene/resources/bit_map.cpp +++ b/scene/resources/bit_map.cpp @@ -74,10 +74,11 @@ void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) { uint8_t b = data[bbyte]; - if (p_value) + if (p_value) { b |= (1 << bbit); - else + } else { b &= ~(1 << bbit); + } data[bbyte] = b; } @@ -118,10 +119,11 @@ void BitMap::set_bit(const Point2 &p_pos, bool p_value) { uint8_t b = bitmask[bbyte]; - if (p_value) + if (p_value) { b |= (1 << bbit); - else + } else { b &= ~(1 << bbit); + } bitmask.write[bbyte] = b; } @@ -339,8 +341,9 @@ static float perpendicular_distance(const Vector2 &i, const Vector2 &start, cons } static Vector<Vector2> rdp(const Vector<Vector2> &v, float optimization) { - if (v.size() < 3) + if (v.size() < 3) { return v; + } int index = -1; float dist = 0; @@ -436,15 +439,17 @@ static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_ continue; } - if (i < rect.position.x || i >= rect.position.x + rect.size.x) + if (i < rect.position.x || i >= rect.position.x + rect.size.x) { continue; - if (j < rect.position.y || j >= rect.position.y + rect.size.y) + } + if (j < rect.position.y || j >= rect.position.y + rect.size.y) { continue; + } - if (p_map->get_bit(Vector2(i, j))) + if (p_map->get_bit(Vector2(i, j))) { continue; - else if (p_src->get_bit(Vector2(i, j))) { + } else if (p_src->get_bit(Vector2(i, j))) { p_map->set_bit(Vector2(i, j), true); FillBitsStackEntry se = { pos, i, j }; @@ -526,8 +531,9 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) { for (int i = r.position.y; i < r.position.y + r.size.height; i++) { for (int j = r.position.x; j < r.position.x + r.size.width; j++) { - if (bit_value == get_bit(Point2(j, i))) + if (bit_value == get_bit(Point2(j, i))) { continue; + } bool found = false; @@ -537,23 +543,26 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) { if ((x < p_rect.position.x) || (x >= p_rect.position.x + p_rect.size.x) || (y < p_rect.position.y) || (y >= p_rect.position.y + p_rect.size.y)) { // outside of rectangle counts as bit not set - if (!bit_value) + if (!bit_value) { outside = true; - else + } else { continue; + } } float d = Point2(j, i).distance_to(Point2(x, y)) - CMP_EPSILON; - if (d > p_pixels) + if (d > p_pixels) { continue; + } if (outside || (bit_value == copy->get_bit(Point2(x, y)))) { found = true; break; } } - if (found) + if (found) { break; + } } if (found) { @@ -634,10 +643,12 @@ void BitMap::blit(const Vector2 &p_pos, const Ref<BitMap> &p_bitmap) { for (int j = 0; j < h; j++) { int px = x + i; int py = y + j; - if (px < 0 || px >= width) + if (px < 0 || px >= width) { continue; - if (py < 0 || py >= height) + } + if (py < 0 || py >= height) { continue; + } if (p_bitmap->get_bit(Vector2(i, j))) { set_bit(Vector2(x, y), true); } diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 1054365459..0e784e04ff 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -39,8 +39,9 @@ Vector<Vector2> CapsuleShape2D::_get_points() const { Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5); points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() + ofs); - if (i == 6 || i == 18) + if (i == 6 || i == 18) { points.push_back(Vector2(Math::sin(i * Math_PI * 2 / 24.0), Math::cos(i * Math_PI * 2 / 24.0)) * get_radius() - ofs); + } } return points; @@ -66,8 +67,9 @@ real_t CapsuleShape2D::get_radius() const { void CapsuleShape2D::set_height(real_t p_height) { height = p_height; - if (height < 0) + if (height < 0) { height = 0; + } _update_shape(); } diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index 9cc8ea0fac..2154633111 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -36,14 +36,16 @@ bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { Vector<Vector2> s = get_segments(); int len = s.size(); - if (len == 0 || (len % 2) == 1) + if (len == 0 || (len % 2) == 1) { return false; + } const Vector2 *r = s.ptr(); for (int i = 0; i < len; i += 2) { Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, &r[i]); - if (p_point.distance_to(closest) < p_tolerance) + if (p_point.distance_to(closest) < p_tolerance) { return true; + } } return false; @@ -61,8 +63,9 @@ Vector<Vector2> ConcavePolygonShape2D::get_segments() const { void ConcavePolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector<Vector2> s = get_segments(); int len = s.size(); - if (len == 0 || (len % 2) == 1) + if (len == 0 || (len % 2) == 1) { return; + } const Vector2 *r = s.ptr(); for (int i = 0; i < len; i += 2) { @@ -73,17 +76,19 @@ void ConcavePolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { Rect2 ConcavePolygonShape2D::get_rect() const { Vector<Vector2> s = get_segments(); int len = s.size(); - if (len == 0) + if (len == 0) { return Rect2(); + } Rect2 rect; const Vector2 *r = s.ptr(); for (int i = 0; i < len; i++) { - if (i == 0) + if (i == 0) { rect.position = r[i]; - else + } else { rect.expand_to(r[i]); + } } return rect; diff --git a/scene/resources/concave_polygon_shape_3d.h b/scene/resources/concave_polygon_shape_3d.h index 3646724131..c268ed9f37 100644 --- a/scene/resources/concave_polygon_shape_3d.h +++ b/scene/resources/concave_polygon_shape_3d.h @@ -40,10 +40,11 @@ class ConcavePolygonShape3D : public Shape3D { Vector3 a; Vector3 b; bool operator<(const DrawEdge &p_edge) const { - if (a == p_edge.a) + if (a == p_edge.a) { return b < p_edge.b; - else + } else { return a < p_edge.a; + } } DrawEdge(const Vector3 &p_a = Vector3(), const Vector3 &p_b = Vector3()) { diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index 59b2e3a9cd..7df7c3ac72 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -80,10 +80,11 @@ void ConvexPolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { Rect2 ConvexPolygonShape2D::get_rect() const { Rect2 rect; for (int i = 0; i < points.size(); i++) { - if (i == 0) + if (i == 0) { rect.position = points[i]; - else + } else { rect.expand_to(points[i]); + } } return rect; diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 9c3e5ad437..de076670cf 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -58,10 +58,11 @@ int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, T // Add a point and preserve order // Curve bounds is in 0..1 - if (p_pos.x > MAX_X) + if (p_pos.x > MAX_X) { p_pos.x = MAX_X; - else if (p_pos.x < MIN_X) + } else if (p_pos.x < MIN_X) { p_pos.x = MIN_X; + } int ret = -1; @@ -128,8 +129,9 @@ int Curve::get_index(real_t offset) const { } // Will happen if the offset is out of bounds - if (offset > _points[imax].pos.x) + if (offset > _points[imax].pos.x) { return imax; + } return imin; } @@ -145,8 +147,9 @@ void Curve::clean_dupes() { } } - if (dirty) + if (dirty) { mark_dirty(); + } } void Curve::set_point_left_tangent(int i, real_t tangent) { @@ -234,8 +237,9 @@ int Curve::set_point_offset(int p_index, float offset) { _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) + if (p_index != i) { update_auto_tangents(p_index); + } update_auto_tangents(i); return i; } @@ -301,20 +305,24 @@ void Curve::set_max_value(float p_max) { } real_t Curve::interpolate(real_t offset) const { - if (_points.size() == 0) + if (_points.size() == 0) { return 0; - if (_points.size() == 1) + } + if (_points.size() == 1) { return _points[0].pos.y; + } int i = get_index(offset); - if (i == _points.size() - 1) + if (i == _points.size() - 1) { return _points[i].pos.y; + } real_t local = offset - _points[i].pos.x; - if (i == 0 && local <= 0) + if (i == 0 && local <= 0) { return _points[0].pos.y; + } return interpolate_local_nocheck(i, local); } @@ -339,8 +347,9 @@ real_t Curve::interpolate_local_nocheck(int index, real_t local_offset) const { // Control points are chosen at equal distances real_t d = b.pos.x - a.pos.x; - if (Math::abs(d) <= CMP_EPSILON) + if (Math::abs(d) <= CMP_EPSILON) { return b.pos.y; + } local_offset /= d; d /= 3.0; real_t yac = a.pos.y + d * a.right_tangent; @@ -449,8 +458,9 @@ real_t Curve::interpolate_baked(real_t offset) { // Special cases if the cache is too small if (_baked_cache.size() == 0) { - if (_points.size() == 0) + if (_points.size() == 0) { return 0; + } return _points[0].pos.y; } else if (_baked_cache.size() == 1) { return _baked_cache[0]; @@ -535,10 +545,11 @@ void Curve2D::add_point(const Vector2 &p_pos, const Vector2 &p_in, const Vector2 n.pos = p_pos; n.in = p_in; n.out = p_out; - if (p_atpos >= 0 && p_atpos < points.size()) + if (p_atpos >= 0 && p_atpos < points.size()) { points.insert(p_atpos, n); - else + } else { points.push_back(n); + } baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); @@ -602,10 +613,11 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const { int pc = points.size(); ERR_FAIL_COND_V(pc == 0, Vector2()); - if (p_index >= pc - 1) + if (p_index >= pc - 1) { return points[pc - 1].pos; - else if (p_index < 0) + } else if (p_index < 0) { return points[0].pos; + } Vector2 p0 = points[p_index].pos; Vector2 p1 = p0 + points[p_index].out; @@ -616,10 +628,11 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const { } Vector2 Curve2D::interpolatef(real_t p_findex) const { - if (p_findex < 0) + if (p_findex < 0) { p_findex = 0; - else if (p_findex >= points.size()) + } else if (p_findex >= points.size()) { p_findex = points.size(); + } return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0)); } @@ -645,8 +658,9 @@ void Curve2D::_bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float } void Curve2D::_bake() const { - if (!baked_cache_dirty) + if (!baked_cache_dirty) { return; + } baked_max_ofs = 0; baked_cache_dirty = false; @@ -673,8 +687,9 @@ void Curve2D::_bake() const { while (p < 1.0) { float np = p + step; - if (np > 1.0) + if (np > 1.0) { np = 1.0; + } Vector2 npp = _bezier_interp(np, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); float d = pos.distance_to(npp); @@ -692,10 +707,11 @@ void Curve2D::_bake() const { npp = _bezier_interp(mid, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); d = pos.distance_to(npp); - if (bake_interval < d) + if (bake_interval < d) { hi = mid; - else + } else { low = mid; + } mid = low + (hi - low) * 0.5; } @@ -725,30 +741,35 @@ void Curve2D::_bake() const { } float Curve2D::get_baked_length() const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } return baked_max_ofs; } Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_point_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D."); - if (pc == 1) + if (pc == 1) { return baked_point_cache.get(0); + } int bpc = baked_point_cache.size(); const Vector2 *r = baked_point_cache.ptr(); - if (p_offset < 0) + if (p_offset < 0) { return r[0]; - if (p_offset >= baked_max_ofs) + } + if (p_offset >= baked_max_ofs) { return r[bpc - 1]; + } int idx = Math::floor((double)p_offset / (double)bake_interval); float frac = Math::fmod(p_offset, (float)bake_interval); @@ -756,8 +777,9 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { if (idx >= bpc - 1) { return r[bpc - 1]; } else if (idx == bpc - 2) { - if (frac > 0) + if (frac > 0) { frac /= Math::fmod(baked_max_ofs, bake_interval); + } } else { frac /= bake_interval; } @@ -772,8 +794,9 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { } PackedVector2Array Curve2D::get_baked_points() const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } return baked_point_cache; } @@ -791,15 +814,17 @@ float Curve2D::get_bake_interval() const { Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const { // Brute force method - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_point_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, Vector2(), "No points in Curve2D."); - if (pc == 1) + if (pc == 1) { return baked_point_cache.get(0); + } const Vector2 *r = baked_point_cache.ptr(); @@ -827,15 +852,17 @@ Vector2 Curve2D::get_closest_point(const Vector2 &p_to_point) const { float Curve2D::get_closest_offset(const Vector2 &p_to_point) const { // Brute force method - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_point_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve2D."); - if (pc == 1) + if (pc == 1) { return 0.0f; + } const Vector2 *r = baked_point_cache.ptr(); @@ -990,10 +1017,11 @@ void Curve3D::add_point(const Vector3 &p_pos, const Vector3 &p_in, const Vector3 n.pos = p_pos; n.in = p_in; n.out = p_out; - if (p_atpos >= 0 && p_atpos < points.size()) + if (p_atpos >= 0 && p_atpos < points.size()) { points.insert(p_atpos, n); - else + } else { points.push_back(n); + } baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); @@ -1070,10 +1098,11 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const { int pc = points.size(); ERR_FAIL_COND_V(pc == 0, Vector3()); - if (p_index >= pc - 1) + if (p_index >= pc - 1) { return points[pc - 1].pos; - else if (p_index < 0) + } else if (p_index < 0) { return points[0].pos; + } Vector3 p0 = points[p_index].pos; Vector3 p1 = p0 + points[p_index].out; @@ -1084,10 +1113,11 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const { } Vector3 Curve3D::interpolatef(real_t p_findex) const { - if (p_findex < 0) + if (p_findex < 0) { p_findex = 0; - else if (p_findex >= points.size()) + } else if (p_findex >= points.size()) { p_findex = points.size(); + } return interpolate((int)p_findex, Math::fmod(p_findex, (real_t)1.0)); } @@ -1112,8 +1142,9 @@ void Curve3D::_bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float } void Curve3D::_bake() const { - if (!baked_cache_dirty) + if (!baked_cache_dirty) { return; + } baked_max_ofs = 0; baked_cache_dirty = false; @@ -1134,8 +1165,9 @@ void Curve3D::_bake() const { if (up_vector_enabled) { baked_up_vector_cache.resize(1); baked_up_vector_cache.set(0, Vector3(0, 1, 0)); - } else + } else { baked_up_vector_cache.resize(0); + } return; } @@ -1150,8 +1182,9 @@ void Curve3D::_bake() const { while (p < 1.0) { float np = p + step; - if (np > 1.0) + if (np > 1.0) { np = 1.0; + } Vector3 npp = _bezier_interp(np, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); float d = pos.distance_to(npp); @@ -1169,10 +1202,11 @@ void Curve3D::_bake() const { npp = _bezier_interp(mid, points[i].pos, points[i].pos + points[i].out, points[i + 1].pos + points[i + 1].in, points[i + 1].pos); d = pos.distance_to(npp); - if (bake_interval < d) + if (bake_interval < d) { hi = mid; - else + } else { low = mid; + } mid = low + (hi - low) * 0.5; } @@ -1237,8 +1271,9 @@ void Curve3D::_bake() const { up = forward.cross(sideways).normalized(); } - if (idx == 1) + if (idx == 1) { up_write[0] = up; + } up_write[idx] = up; @@ -1251,30 +1286,35 @@ void Curve3D::_bake() const { } float Curve3D::get_baked_length() const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } return baked_max_ofs; } Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_point_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D."); - if (pc == 1) + if (pc == 1) { return baked_point_cache.get(0); + } int bpc = baked_point_cache.size(); const Vector3 *r = baked_point_cache.ptr(); - if (p_offset < 0) + if (p_offset < 0) { return r[0]; - if (p_offset >= baked_max_ofs) + } + if (p_offset >= baked_max_ofs) { return r[bpc - 1]; + } int idx = Math::floor((double)p_offset / (double)bake_interval); float frac = Math::fmod(p_offset, bake_interval); @@ -1282,8 +1322,9 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { if (idx >= bpc - 1) { return r[bpc - 1]; } else if (idx == bpc - 2) { - if (frac > 0) + if (frac > 0) { frac /= Math::fmod(baked_max_ofs, bake_interval); + } } else { frac /= bake_interval; } @@ -1298,23 +1339,27 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { } float Curve3D::interpolate_baked_tilt(float p_offset) const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_tilt_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, 0, "No tilts in Curve3D."); - if (pc == 1) + if (pc == 1) { return baked_tilt_cache.get(0); + } int bpc = baked_tilt_cache.size(); const real_t *r = baked_tilt_cache.ptr(); - if (p_offset < 0) + if (p_offset < 0) { return r[0]; - if (p_offset >= baked_max_ofs) + } + if (p_offset >= baked_max_ofs) { return r[bpc - 1]; + } int idx = Math::floor((double)p_offset / (double)bake_interval); float frac = Math::fmod(p_offset, bake_interval); @@ -1322,8 +1367,9 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { if (idx >= bpc - 1) { return r[bpc - 1]; } else if (idx == bpc - 2) { - if (frac > 0) + if (frac > 0) { frac /= Math::fmod(baked_max_ofs, bake_interval); + } } else { frac /= bake_interval; } @@ -1332,16 +1378,18 @@ float Curve3D::interpolate_baked_tilt(float p_offset) const { } Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// // curve may not have baked up vectors int count = baked_up_vector_cache.size(); ERR_FAIL_COND_V_MSG(count == 0, Vector3(0, 1, 0), "No up vectors in Curve3D."); - if (count == 1) + if (count == 1) { return baked_up_vector_cache.get(0); + } const Vector3 *r = baked_up_vector_cache.ptr(); const Vector3 *rp = baked_point_cache.ptr(); @@ -1352,8 +1400,9 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) int idx = Math::floor((double)offset / (double)bake_interval); float frac = Math::fmod(offset, bake_interval) / bake_interval; - if (idx == count - 1) + if (idx == count - 1) { return p_apply_tilt ? r[idx].rotated((rp[idx] - rp[idx - 1]).normalized(), rt[idx]) : r[idx]; + } Vector3 forward = (rp[idx + 1] - rp[idx]).normalized(); Vector3 up = r[idx]; @@ -1366,31 +1415,35 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) Vector3 axis = up.cross(up1); - if (axis.length_squared() < CMP_EPSILON2) + if (axis.length_squared() < CMP_EPSILON2) { axis = forward; - else + } else { axis.normalize(); + } return up.rotated(axis, up.angle_to(up1) * frac); } PackedVector3Array Curve3D::get_baked_points() const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } return baked_point_cache; } PackedFloat32Array Curve3D::get_baked_tilts() const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } return baked_tilt_cache; } PackedVector3Array Curve3D::get_baked_up_vectors() const { - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } return baked_up_vector_cache; } @@ -1398,15 +1451,17 @@ PackedVector3Array Curve3D::get_baked_up_vectors() const { Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { // Brute force method - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_point_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, Vector3(), "No points in Curve3D."); - if (pc == 1) + if (pc == 1) { return baked_point_cache.get(0); + } const Vector3 *r = baked_point_cache.ptr(); @@ -1434,15 +1489,17 @@ Vector3 Curve3D::get_closest_point(const Vector3 &p_to_point) const { float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { // Brute force method - if (baked_cache_dirty) + if (baked_cache_dirty) { _bake(); + } //validate// int pc = baked_point_cache.size(); ERR_FAIL_COND_V_MSG(pc == 0, 0.0f, "No points in Curve3D."); - if (pc == 1) + if (pc == 1) { return 0.0f; + } const Vector3 *r = baked_point_cache.ptr(); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 9f7fdc2316..67617a946f 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -770,8 +770,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const // TooltipPanel Ref<StyleBoxTexture> style_tt = make_stylebox(tooltip_bg_png, 4, 4, 4, 4); - for (int i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { style_tt->set_expand_margin_size((Margin)i, 4 * scale); + } theme->set_stylebox("panel", "TooltipPanel", style_tt); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 3581fffdba..3b4e4b73f8 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -247,15 +247,17 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon //not found, try in fallbacks for (int i = 0; i < p_fallbacks.size(); i++) { DynamicFontAtSize *fb = const_cast<DynamicFontAtSize *>(p_fallbacks[i].ptr()); - if (!fb->valid) + if (!fb->valid) { continue; + } fb->_update_char(p_char); const Character *fallback_chr = fb->char_map.getptr(p_char); ERR_CONTINUE(!fallback_chr); - if (!fallback_chr->found) + if (!fallback_chr->found) { continue; + } return Pair<const Character *, DynamicFontAtSize *>(fallback_chr, fb); } @@ -270,8 +272,9 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon } Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const { - if (!valid) + if (!valid) { return Size2(1, 1); + } const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); Pair<const Character *, DynamicFontAtSize *> char_pair_with_font = _find_char_with_font(p_char, p_fallbacks); @@ -288,8 +291,9 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V } float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks, bool p_advance_only, bool p_outline) const { - if (!valid) + if (!valid) { return 0; + } const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); @@ -344,8 +348,9 @@ unsigned long DynamicFontAtSize::_ft_stream_io(FT_Stream stream, unsigned long o f->seek(offset); } - if (count == 0) + if (count == 0) { return 0; + } return f->get_buffer(buffer, count); } @@ -378,11 +383,13 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp for (int i = 0; i < textures.size(); i++) { const CharTexture &ct = textures[i]; - if (ct.texture->get_format() != p_image_format) + if (ct.texture->get_format() != p_image_format) { continue; + } - if (mw > ct.texture_size || mh > ct.texture_size) //too big for this texture + if (mw > ct.texture_size || mh > ct.texture_size) { //too big for this texture continue; + } ret.y = 0x7FFFFFFF; ret.x = 0; @@ -392,8 +399,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp for (int k = j; k < j + mw; k++) { int y = ct.offsets[k]; - if (y > max_y) + if (y > max_y) { max_y = y; + } } if (max_y < ret.y) { @@ -402,8 +410,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp } } - if (ret.y == 0x7FFFFFFF || ret.y + mh > ct.texture_size) + if (ret.y == 0x7FFFFFFF || ret.y + mh > ct.texture_size) { continue; //fail, could not fit it here + } ret.index = i; break; @@ -415,10 +424,12 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp ret.y = 0; int texsize = MAX(id.size * oversampling * 8, 256); - if (mw > texsize) + if (mw > texsize) { texsize = mw; //special case, adapt to it? - if (mh > texsize) + } + if (mh > texsize) { texsize = mh; //special case, adapt to it? + } texsize = next_power_of_2(texsize); @@ -437,8 +448,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp } } tex.offsets.resize(texsize); - for (int i = 0; i < texsize; i++) //zero offsets + for (int i = 0; i < texsize; i++) { //zero offsets tex.offsets.write[i] = 0; + } textures.push_back(tex); ret.index = textures.size() - 1; @@ -536,23 +548,28 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b DynamicFontAtSize::Character DynamicFontAtSize::_make_outline_char(CharType p_char) { Character ret = Character::not_found(); - if (FT_Load_Char(face, p_char, FT_LOAD_NO_BITMAP | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)) != 0) + if (FT_Load_Char(face, p_char, FT_LOAD_NO_BITMAP | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)) != 0) { return ret; + } FT_Stroker stroker; - if (FT_Stroker_New(library, &stroker) != 0) + if (FT_Stroker_New(library, &stroker) != 0) { return ret; + } FT_Stroker_Set(stroker, (int)(id.outline_size * oversampling * 64.0), FT_STROKER_LINECAP_BUTT, FT_STROKER_LINEJOIN_ROUND, 0); FT_Glyph glyph; FT_BitmapGlyph glyph_bitmap; - if (FT_Get_Glyph(face->glyph, &glyph) != 0) + if (FT_Get_Glyph(face->glyph, &glyph) != 0) { goto cleanup_stroker; - if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) + } + if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) { goto cleanup_glyph; - if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0) + } + if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, nullptr, 1) != 0) { goto cleanup_glyph; + } glyph_bitmap = (FT_BitmapGlyph)glyph; ret = _bitmap_to_character(glyph_bitmap->bitmap, glyph_bitmap->top, glyph_bitmap->left, glyph->advance.x / 65536.0); @@ -565,8 +582,9 @@ cleanup_stroker: } void DynamicFontAtSize::_update_char(CharType p_char) { - if (char_map.has(p_char)) + if (char_map.has(p_char)) { return; + } _THREAD_SAFE_METHOD_ @@ -603,16 +621,18 @@ void DynamicFontAtSize::_update_char(CharType p_char) { character = _make_outline_char(p_char); } else { error = FT_Render_Glyph(face->glyph, font->antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO); - if (!error) + if (!error) { character = _bitmap_to_character(slot->bitmap, slot->bitmap_top, slot->bitmap_left, slot->advance.x / 64.0); + } } char_map[p_char] = character; } void DynamicFontAtSize::update_oversampling() { - if (oversampling == font_oversampling || !valid) + if (oversampling == font_oversampling || !valid) { return; + } FT_Done_FreeType(library); textures.clear(); @@ -664,8 +684,9 @@ void DynamicFont::_reload_cache() { for (int i = 0; i < fallbacks.size(); i++) { fallback_data_at_size.write[i] = fallbacks.write[i]->_get_dynamic_font_at_size(cache_id); - if (outline_cache_id.outline_size > 0) + if (outline_cache_id.outline_size > 0) { fallback_outline_data_at_size.write[i] = fallbacks.write[i]->_get_dynamic_font_at_size(outline_cache_id); + } } emit_changed(); @@ -685,8 +706,9 @@ Ref<DynamicFontData> DynamicFont::get_font_data() const { } void DynamicFont::set_size(int p_size) { - if (cache_id.size == p_size) + if (cache_id.size == p_size) { return; + } cache_id.size = p_size; outline_cache_id.size = p_size; _reload_cache(); @@ -697,8 +719,9 @@ int DynamicFont::get_size() const { } void DynamicFont::set_outline_size(int p_size) { - if (outline_cache_id.outline_size == p_size) + if (outline_cache_id.outline_size == p_size) { return; + } ERR_FAIL_COND(p_size < 0 || p_size > UINT8_MAX); outline_cache_id.outline_size = p_size; _reload_cache(); @@ -725,8 +748,9 @@ bool DynamicFontData::is_antialiased() const { } void DynamicFontData::set_antialiased(bool p_antialiased) { - if (antialiased == p_antialiased) + if (antialiased == p_antialiased) { return; + } antialiased = p_antialiased; } @@ -735,8 +759,9 @@ DynamicFontData::Hinting DynamicFontData::get_hinting() const { } void DynamicFontData::set_hinting(Hinting p_hinting) { - if (hinting == p_hinting) + if (hinting == p_hinting) { return; + } hinting = p_hinting; } @@ -770,49 +795,56 @@ void DynamicFont::set_spacing(int p_type, int p_value) { } float DynamicFont::get_height() const { - if (!data_at_size.is_valid()) + if (!data_at_size.is_valid()) { return 1; + } return data_at_size->get_height() + spacing_top + spacing_bottom; } float DynamicFont::get_ascent() const { - if (!data_at_size.is_valid()) + if (!data_at_size.is_valid()) { return 1; + } return data_at_size->get_ascent() + spacing_top; } float DynamicFont::get_descent() const { - if (!data_at_size.is_valid()) + if (!data_at_size.is_valid()) { return 1; + } return data_at_size->get_descent() + spacing_bottom; } float DynamicFont::get_underline_position() const { - if (!data_at_size.is_valid()) + if (!data_at_size.is_valid()) { return 2; + } return data_at_size->get_underline_position(); } float DynamicFont::get_underline_thickness() const { - if (!data_at_size.is_valid()) + if (!data_at_size.is_valid()) { return 1; + } return data_at_size->get_underline_thickness(); } Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const { - if (!data_at_size.is_valid()) + if (!data_at_size.is_valid()) { return Size2(1, 1); + } Size2 ret = data_at_size->get_char_size(p_char, p_next, fallback_data_at_size); - if (p_char == ' ') + if (p_char == ' ') { ret.width += spacing_space + spacing_char; - else if (p_next) + } else if (p_next) { ret.width += spacing_char; + } return ret; } @@ -828,8 +860,9 @@ bool DynamicFont::has_outline() const { float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { const Ref<DynamicFontAtSize> &font_at_size = p_outline && outline_cache_id.outline_size > 0 ? outline_data_at_size : data_at_size; - if (!font_at_size.is_valid()) + if (!font_at_size.is_valid()) { return 0; + } const Vector<Ref<DynamicFontAtSize>> &fallbacks = p_outline && outline_cache_id.outline_size > 0 ? fallback_outline_data_at_size : fallback_data_at_size; Color color = p_outline && outline_cache_id.outline_size > 0 ? p_modulate * outline_color : p_modulate; @@ -850,8 +883,9 @@ 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.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(cache_id)); //const.. - if (outline_cache_id.outline_size > 0) + if (outline_cache_id.outline_size > 0) { fallback_outline_data_at_size.push_back(fallbacks.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(outline_cache_id)); + } _change_notify(); emit_changed(); @@ -1038,15 +1072,17 @@ void DynamicFont::update_oversampling() { ///////////////////////// RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } Ref<DynamicFontData> dfont; dfont.instance(); dfont->set_font_path(p_path); - if (r_error) + if (r_error) { *r_error = OK; + } return dfont; } @@ -1062,8 +1098,9 @@ bool ResourceFormatLoaderDynamicFont::handles_type(const String &p_type) const { String ResourceFormatLoaderDynamicFont::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "ttf" || el == "otf") + if (el == "ttf" || el == "otf") { return "DynamicFontData"; + } return ""; } diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 5356b5bea2..80ee0c148d 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -47,8 +47,9 @@ void Environment::set_sky(const Ref<Sky> &p_sky) { bg_sky = p_sky; RID sb_rid; - if (bg_sky.is_valid()) + if (bg_sky.is_valid()) { sb_rid = bg_sky->get_rid(); + } RS::get_singleton()->environment_set_sky(environment, sb_rid); } @@ -504,10 +505,11 @@ bool Environment::is_glow_enabled() const { void Environment::set_glow_level(int p_level, bool p_enabled) { ERR_FAIL_INDEX(p_level, RS::MAX_GLOW_LEVELS); - if (p_enabled) + if (p_enabled) { glow_levels |= (1 << p_level); - else + } else { glow_levels &= ~(1 << p_level); + } RS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_mix, glow_bloom, RS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap); } diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index e0cd1be456..1878b174e8 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -67,8 +67,9 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co for (int i = 0; i < p_text.length(); i++) { int width = get_char_size(p_text[i]).width; - if (p_clip_w >= 0 && (ofs.x + width) > p_clip_w) + if (p_clip_w >= 0 && (ofs.x + width) > p_clip_w) { break; //clip + } ofs.x += draw_char(p_canvas_item, p_pos + ofs, p_text[i], p_text[i + 1], with_outline ? p_outline_modulate : p_modulate, with_outline); ++chars_drawn; @@ -108,8 +109,9 @@ void BitmapFont::_set_chars(const Vector<int> &p_chars) { int len = p_chars.size(); //char 1 charsize 1 texture, 4 rect, 2 align, advance 1 ERR_FAIL_COND(len % 9); - if (!len) + if (!len) { return; //none to do + } int chars = len / 9; const int *r = p_chars.ptr(); @@ -145,8 +147,9 @@ Vector<int> BitmapFont::_get_chars() const { void BitmapFont::_set_kernings(const Vector<int> &p_kernings) { int len = p_kernings.size(); ERR_FAIL_COND(len % 3); - if (!len) + if (!len) { return; + } const int *r = p_kernings.ptr(); for (int i = 0; i < len / 3; i++) { @@ -178,8 +181,9 @@ void BitmapFont::_set_textures(const Vector<Variant> &p_textures) { Vector<Variant> BitmapFont::_get_textures() const { Vector<Variant> rtextures; - for (int i = 0; i < textures.size(); i++) + for (int i = 0; i < textures.size(); i++) { rtextures.push_back(textures[i]); + } return rtextures; } @@ -201,51 +205,59 @@ Error BitmapFont::create_from_fnt(const String &p_file) { int pos = delimiter + 1; Map<String, String> keys; - while (pos < line.size() && line[pos] == ' ') + while (pos < line.size() && line[pos] == ' ') { pos++; + } while (pos < line.size()) { int eq = line.find("=", pos); - if (eq == -1) + if (eq == -1) { break; + } String key = line.substr(pos, eq - pos); int end = -1; String value; if (line[eq + 1] == '"') { end = line.find("\"", eq + 2); - if (end == -1) + if (end == -1) { break; + } value = line.substr(eq + 2, end - 1 - eq - 1); pos = end + 1; } else { end = line.find(" ", eq + 1); - if (end == -1) + if (end == -1) { end = line.size(); + } value = line.substr(eq + 1, end - eq); pos = end; } - while (pos < line.size() && line[pos] == ' ') + while (pos < line.size() && line[pos] == ' ') { pos++; + } keys[key] = value; } if (type == "info") { - if (keys.has("face")) + if (keys.has("face")) { set_name(keys["face"]); + } /* if (keys.has("size")) font->set_height(keys["size"].to_int()); */ } else if (type == "common") { - if (keys.has("lineHeight")) + if (keys.has("lineHeight")) { set_height(keys["lineHeight"].to_int()); - if (keys.has("base")) + } + if (keys.has("base")) { set_ascent(keys["base"].to_int()); + } } else if (type == "page") { if (keys.has("file")) { @@ -260,33 +272,42 @@ Error BitmapFont::create_from_fnt(const String &p_file) { } } else if (type == "char") { CharType idx = 0; - if (keys.has("id")) + if (keys.has("id")) { idx = keys["id"].to_int(); + } Rect2 rect; - if (keys.has("x")) + if (keys.has("x")) { rect.position.x = keys["x"].to_int(); - if (keys.has("y")) + } + if (keys.has("y")) { rect.position.y = keys["y"].to_int(); - if (keys.has("width")) + } + if (keys.has("width")) { rect.size.width = keys["width"].to_int(); - if (keys.has("height")) + } + if (keys.has("height")) { rect.size.height = keys["height"].to_int(); + } Point2 ofs; - if (keys.has("xoffset")) + if (keys.has("xoffset")) { ofs.x = keys["xoffset"].to_int(); - if (keys.has("yoffset")) + } + if (keys.has("yoffset")) { ofs.y = keys["yoffset"].to_int(); + } int texture = 0; - if (keys.has("page")) + if (keys.has("page")) { texture = keys["page"].to_int(); + } int advance = -1; - if (keys.has("xadvance")) + if (keys.has("xadvance")) { advance = keys["xadvance"].to_int(); + } add_char(idx, texture, rect, ofs, advance); @@ -294,18 +315,22 @@ Error BitmapFont::create_from_fnt(const String &p_file) { CharType first = 0, second = 0; int k = 0; - if (keys.has("first")) + if (keys.has("first")) { first = keys["first"].to_int(); - if (keys.has("second")) + } + if (keys.has("second")) { second = keys["second"].to_int(); - if (keys.has("amount")) + } + if (keys.has("amount")) { k = keys["amount"].to_int(); + } add_kerning_pair(first, second, -k); } - if (f->eof_reached()) + if (f->eof_reached()) { break; + } } memdelete(f); @@ -380,8 +405,9 @@ BitmapFont::Character BitmapFont::get_character(CharType p_char) const { }; void BitmapFont::add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance) { - if (p_advance < 0) + if (p_advance < 0) { p_advance = p_rect.size.width; + } Character c; c.rect = p_rect; @@ -423,8 +449,9 @@ int BitmapFont::get_kerning_pair(CharType p_A, CharType p_B) const { kpk.B = p_B; const Map<KerningPairKey, int>::Element *E = kerning_map.find(kpk); - if (E) + if (E) { return E->get(); + } return 0; } @@ -451,8 +478,9 @@ Size2 Font::get_string_size(const String &p_string) const { float w = 0; int l = p_string.length(); - if (l == 0) + if (l == 0) { return Size2(0, get_height()); + } const CharType *sptr = &p_string[0]; for (int i = 0; i < l; i++) { @@ -466,8 +494,9 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons ERR_FAIL_COND_V(p_width <= 0, Vector2(0, get_height())); int l = p_string.length(); - if (l == 0) + if (l == 0) { return Size2(p_width, get_height()); + } float line_w = 0; float h = 0; @@ -508,8 +537,9 @@ float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_c const Character *c = char_map.getptr(p_char); if (!c) { - if (fallback.is_valid()) + if (fallback.is_valid()) { return fallback->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, p_outline); + } return 0; } @@ -529,8 +559,9 @@ Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const { const Character *c = char_map.getptr(p_char); if (!c) { - if (fallback.is_valid()) + if (fallback.is_valid()) { return fallback->get_char_size(p_char, p_next); + } return Size2(); } @@ -604,8 +635,9 @@ BitmapFont::~BitmapFont() { //////////// RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } Ref<BitmapFont> font; font.instance(); @@ -613,8 +645,9 @@ RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_origi Error err = font->create_from_fnt(p_path); if (err) { - if (r_error) + if (r_error) { *r_error = err; + } return RES(); } @@ -631,7 +664,8 @@ bool ResourceFormatLoaderBMFont::handles_type(const String &p_type) const { String ResourceFormatLoaderBMFont::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "fnt") + if (el == "fnt") { return "BitmapFont"; + } return ""; } diff --git a/scene/resources/gradient.cpp b/scene/resources/gradient.cpp index 2ccabe0b80..d271c906ff 100644 --- a/scene/resources/gradient.cpp +++ b/scene/resources/gradient.cpp @@ -103,8 +103,9 @@ void Gradient::set_offsets(const Vector<float> &p_offsets) { } void Gradient::set_colors(const Vector<Color> &p_colors) { - if (points.size() < p_colors.size()) + if (points.size() < p_colors.size()) { is_sorted = false; + } points.resize(p_colors.size()); for (int i = 0; i < points.size(); i++) { points.write[i].color = p_colors[i]; @@ -141,8 +142,9 @@ void Gradient::set_points(Vector<Gradient::Point> &p_points) { void Gradient::set_offset(int pos, const float offset) { ERR_FAIL_COND(pos < 0); - if (points.size() <= pos) + if (points.size() <= pos) { points.resize(pos + 1); + } points.write[pos].offset = offset; is_sorted = false; emit_signal(CoreStringNames::get_singleton()->changed); diff --git a/scene/resources/gradient.h b/scene/resources/gradient.h index fa654cf31d..d40dcc8d44 100644 --- a/scene/resources/gradient.h +++ b/scene/resources/gradient.h @@ -76,8 +76,9 @@ public: Vector<Color> get_colors() const; _FORCE_INLINE_ Color get_color_at_offset(float p_offset) { - if (points.empty()) + if (points.empty()) { return Color(0, 0, 0, 1); + } if (!is_sorted) { points.sort(); @@ -90,8 +91,9 @@ public: int middle = 0; #ifdef DEBUG_ENABLED - if (low > high) + if (low > high) { ERR_PRINT("low > high, this may be a bug"); + } #endif while (low <= high) { @@ -112,10 +114,12 @@ public: } int first = middle; int second = middle + 1; - if (second >= points.size()) + if (second >= points.size()) { return points[points.size() - 1].color; - if (first < 0) + } + if (first < 0) { return points[0].color; + } const Point &pointFirst = points[first]; const Point &pointSecond = points[second]; return pointFirst.color.lerp(pointSecond.color, (p_offset - pointFirst.offset) / (pointSecond.offset - pointFirst.offset)); diff --git a/scene/resources/height_map_shape_3d.cpp b/scene/resources/height_map_shape_3d.cpp index 5450d78426..e112c6b436 100644 --- a/scene/resources/height_map_shape_3d.cpp +++ b/scene/resources/height_map_shape_3d.cpp @@ -159,11 +159,13 @@ void HeightMapShape3D::set_map_data(PackedFloat32Array p_new) { min_height = val; max_height = val; } else { - if (min_height > val) + if (min_height > val) { min_height = val; + } - if (max_height < val) + if (max_height < val) { max_height = val; + } } } diff --git a/scene/resources/line_shape_2d.cpp b/scene/resources/line_shape_2d.cpp index 22dd426295..802ccaaee6 100644 --- a/scene/resources/line_shape_2d.cpp +++ b/scene/resources/line_shape_2d.cpp @@ -39,8 +39,9 @@ bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tol for (int i = 0; i < 2; i++) { Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, l[i]); - if (p_point.distance_to(closest) < p_tolerance) + if (p_point.distance_to(closest) < p_tolerance) { return true; + } } return false; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 3a3fb77f02..1e95a35726 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -43,13 +43,15 @@ void Material::set_next_pass(const Ref<Material> &p_pass) { ERR_FAIL_COND_MSG(pass_child == this, "Can't set as next_pass one of its parents to prevent crashes due to recursive loop."); } - if (next_pass == p_pass) + if (next_pass == p_pass) { return; + } next_pass = p_pass; RID next_pass_rid; - if (next_pass.is_valid()) + if (next_pass.is_valid()) { next_pass_rid = next_pass->get_rid(); + } RS::get_singleton()->material_set_next_pass(material, next_pass_rid); } @@ -252,10 +254,11 @@ bool ShaderMaterial::_can_do_next_pass() const { } Shader::Mode ShaderMaterial::get_shader_mode() const { - if (shader.is_valid()) + if (shader.is_valid()) { return shader->get_mode(); - else + } else { return Shader::MODE_SPATIAL; + } } ShaderMaterial::ShaderMaterial() { @@ -365,8 +368,9 @@ void BaseMaterial3D::_update_shader() { dirty_materials->remove(&element); MaterialKey mk = _compute_key(); - if (mk == current_key) + if (mk == current_key) { return; //no update required in the end + } if (shader_map.has(current_key)) { shader_map[current_key].users--; @@ -1372,8 +1376,9 @@ float BaseMaterial3D::get_refraction() const { } void BaseMaterial3D::set_detail_uv(DetailUV p_detail_uv) { - if (detail_uv == p_detail_uv) + if (detail_uv == p_detail_uv) { return; + } detail_uv = p_detail_uv; _queue_shader_change(); @@ -1384,8 +1389,9 @@ BaseMaterial3D::DetailUV BaseMaterial3D::get_detail_uv() const { } void BaseMaterial3D::set_blend_mode(BlendMode p_mode) { - if (blend_mode == p_mode) + if (blend_mode == p_mode) { return; + } blend_mode = p_mode; _queue_shader_change(); @@ -1433,8 +1439,9 @@ BaseMaterial3D::ShadingMode BaseMaterial3D::get_shading_mode() const { } void BaseMaterial3D::set_depth_draw_mode(DepthDrawMode p_mode) { - if (depth_draw_mode == p_mode) + if (depth_draw_mode == p_mode) { return; + } depth_draw_mode = p_mode; _queue_shader_change(); @@ -1445,8 +1452,9 @@ BaseMaterial3D::DepthDrawMode BaseMaterial3D::get_depth_draw_mode() const { } void BaseMaterial3D::set_cull_mode(CullMode p_mode) { - if (cull_mode == p_mode) + if (cull_mode == p_mode) { return; + } cull_mode = p_mode; _queue_shader_change(); @@ -1457,8 +1465,9 @@ BaseMaterial3D::CullMode BaseMaterial3D::get_cull_mode() const { } void BaseMaterial3D::set_diffuse_mode(DiffuseMode p_mode) { - if (diffuse_mode == p_mode) + if (diffuse_mode == p_mode) { return; + } diffuse_mode = p_mode; _queue_shader_change(); @@ -1469,8 +1478,9 @@ BaseMaterial3D::DiffuseMode BaseMaterial3D::get_diffuse_mode() const { } void BaseMaterial3D::set_specular_mode(SpecularMode p_mode) { - if (specular_mode == p_mode) + if (specular_mode == p_mode) { return; + } specular_mode = p_mode; _queue_shader_change(); @@ -1483,8 +1493,9 @@ BaseMaterial3D::SpecularMode BaseMaterial3D::get_specular_mode() const { void BaseMaterial3D::set_flag(Flags p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); - if (flags[p_flag] == p_enabled) + if (flags[p_flag] == p_enabled) { return; + } flags[p_flag] = p_enabled; if (p_flag == FLAG_USE_SHADOW_TO_OPACITY || p_flag == FLAG_USE_TEXTURE_REPEAT || p_flag == FLAG_SUBSURFACE_MODE_SKIN) { @@ -1500,8 +1511,9 @@ bool BaseMaterial3D::get_flag(Flags p_flag) const { void BaseMaterial3D::set_feature(Feature p_feature, bool p_enabled) { ERR_FAIL_INDEX(p_feature, FEATURE_MAX); - if (features[p_feature] == p_enabled) + if (features[p_feature] == p_enabled) { return; + } features[p_feature] = p_enabled; _change_notify(); @@ -1530,8 +1542,9 @@ Ref<Texture2D> BaseMaterial3D::get_texture(TextureParam p_param) const { Ref<Texture2D> BaseMaterial3D::get_texture_by_name(StringName p_name) const { for (int i = 0; i < (int)BaseMaterial3D::TEXTURE_MAX; i++) { TextureParam param = TextureParam(i); - if (p_name == shader_names->texture_names[param]) + if (p_name == shader_names->texture_names[param]) { return textures[param]; + } } return Ref<Texture2D>(); } @@ -1895,20 +1908,27 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_refraction_texture_channel() RID BaseMaterial3D::get_material_rid_for_2d(bool p_shaded, bool p_transparent, bool p_double_sided, bool p_cut_alpha, bool p_opaque_prepass, bool p_billboard, bool p_billboard_y) { int version = 0; - if (p_shaded) + if (p_shaded) { version = 1; - if (p_transparent) + } + if (p_transparent) { version |= 2; - if (p_cut_alpha) + } + if (p_cut_alpha) { version |= 4; - if (p_opaque_prepass) + } + if (p_opaque_prepass) { version |= 8; - if (p_double_sided) + } + if (p_double_sided) { version |= 16; - if (p_billboard) + } + if (p_billboard) { version |= 32; - if (p_billboard_y) + } + if (p_billboard_y) { version |= 64; + } if (materials_for_2d[version].is_valid()) { return materials_for_2d[version]->get_rid(); @@ -1986,8 +2006,9 @@ float BaseMaterial3D::get_distance_fade_min_distance() const { } void BaseMaterial3D::set_emission_operator(EmissionOperator p_op) { - if (emission_op == p_op) + if (emission_op == p_op) { return; + } emission_op = p_op; _queue_shader_change(); } diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index e293a421b9..10f0a040d0 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -40,14 +40,16 @@ Mesh::ConvexDecompositionFunc Mesh::convex_composition_function = nullptr; Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { - if (triangle_mesh.is_valid()) + if (triangle_mesh.is_valid()) { return triangle_mesh; + } int facecount = 0; for (int i = 0; i < get_surface_count(); i++) { - if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) + if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) { continue; + } if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { facecount += surface_get_array_index_len(i); @@ -56,8 +58,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { } } - if (facecount == 0 || (facecount % 3) != 0) + if (facecount == 0 || (facecount % 3) != 0) { return triangle_mesh; + } Vector<Vector3> faces; faces.resize(facecount); @@ -66,8 +69,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { int widx = 0; for (int i = 0; i < get_surface_count(); i++) { - if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) + if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) { continue; + } Array a = surface_get_arrays(i); ERR_FAIL_COND_V(a.empty(), Ref<TriangleMesh>()); @@ -87,8 +91,9 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { } } else { - for (int j = 0; j < vc; j++) + for (int j = 0; j < vc; j++) { facesw[widx++] = vr[j]; + } } } @@ -105,8 +110,9 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) { } Ref<TriangleMesh> tm = generate_triangle_mesh(); - if (tm.is_null()) + if (tm.is_null()) { return; + } Vector<int> triangle_indices; tm->get_indices(&triangle_indices); @@ -136,8 +142,9 @@ void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) { void Mesh::generate_debug_mesh_indices(Vector<Vector3> &r_points) { Ref<TriangleMesh> tm = generate_triangle_mesh(); - if (tm.is_null()) + if (tm.is_null()) { return; + } Vector<Vector3> vertices = tm->get_vertices(); @@ -155,8 +162,9 @@ bool Mesh::surface_is_softbody_friendly(int p_idx) const { Vector<Face3> Mesh::get_faces() const { Ref<TriangleMesh> tm = generate_triangle_mesh(); - if (tm.is_valid()) + if (tm.is_valid()) { return tm->get_faces(); + } return Vector<Face3>(); /* for (int i=0;i<surfaces.size();i++) { @@ -235,8 +243,9 @@ Ref<Shape3D> Mesh::create_convex_shape() const { Ref<Shape3D> Mesh::create_trimesh_shape() const { Vector<Face3> faces = get_faces(); - if (faces.size() == 0) + if (faces.size() == 0) { return Ref<Shape3D>(); + } Vector<Vector3> face_points; face_points.resize(faces.size() * 3); @@ -257,8 +266,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { Array arrays; int index_accum = 0; for (int i = 0; i < get_surface_count(); i++) { - if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) + if (surface_get_primitive_type(i) != PRIMITIVE_TRIANGLES) { continue; + } Array a = surface_get_arrays(i); ERR_FAIL_COND_V(a.empty(), Ref<ArrayMesh>()); @@ -281,8 +291,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { case ARRAY_NORMAL: { Vector<Vector3> dst = arrays[j]; Vector<Vector3> src = a[j]; - if (j == ARRAY_VERTEX) + if (j == ARRAY_VERTEX) { vcount = src.size(); + } if (dst.size() == 0 || src.size() == 0) { arrays[j] = Variant(); continue; @@ -392,8 +403,9 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { normal_accum[t[j]] = n; } else { float d = n.dot(E->get()); - if (d < 1.0) + if (d < 1.0) { E->get() += n * (1.0 - d); + } //E->get()+=n; } } @@ -672,8 +684,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { Vector<String> sk = p_value; int sz = sk.size(); const String *r = sk.ptr(); - for (int i = 0; i < sz; i++) + for (int i = 0; i < sz; i++) { add_blend_shape(r[i]); + } return true; } @@ -684,21 +697,24 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { if (sname.begins_with("surface_")) { int sl = sname.find("/"); - if (sl == -1) + if (sl == -1) { return false; + } int idx = sname.substr(8, sl - 8).to_int() - 1; String what = sname.get_slicec('/', 1); - if (what == "material") + if (what == "material") { surface_set_material(idx, p_value); - else if (what == "name") + } else if (what == "name") { surface_set_name(idx, p_value); + } return true; } #ifndef DISABLE_DEPRECATED // Kept for compatibility from 3.x to 4.0. - if (!sname.begins_with("surfaces")) + if (!sname.begins_with("surfaces")) { return false; + } WARN_DEPRECATED_MSG("Mesh uses old surface format, which is deprecated (and loads slower). Consider re-importing or re-saving the scene."); @@ -720,8 +736,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { //older format (3.x) Vector<uint8_t> array_data = d["array_data"]; Vector<uint8_t> array_index_data; - if (d.has("array_index_data")) + if (d.has("array_index_data")) { array_index_data = d["array_index_data"]; + } ERR_FAIL_COND_V(!d.has("format"), false); uint32_t format = d["format"]; @@ -746,8 +763,9 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { array_data = _fix_array_compatibility(array_data, format, vertex_count); int index_count = 0; - if (d.has("index_count")) + if (d.has("index_count")) { index_count = d["index_count"]; + } Vector<Vector<uint8_t>> blend_shapes; @@ -989,15 +1007,17 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) { } bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { - if (_is_generated()) + if (_is_generated()) { return false; + } String sname = p_name; if (p_name == "blend_shape/names") { Vector<String> sk; - for (int i = 0; i < blend_shapes.size(); i++) + for (int i = 0; i < blend_shapes.size(); i++) { sk.push_back(blend_shapes[i]); + } r_ret = sk; return true; } else if (p_name == "blend_shape/mode") { @@ -1005,14 +1025,16 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { return true; } else if (sname.begins_with("surface_")) { int sl = sname.find("/"); - if (sl == -1) + if (sl == -1) { return false; + } int idx = sname.substr(8, sl - 8).to_int() - 1; String what = sname.get_slicec('/', 1); - if (what == "material") + if (what == "material") { r_ret = surface_get_material(idx); - else if (what == "name") + } else if (what == "name") { r_ret = surface_get_name(idx); + } return true; } @@ -1020,8 +1042,9 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { } void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { - if (_is_generated()) + if (_is_generated()) { return; + } if (blend_shapes.size()) { p_list->push_back(PropertyInfo(Variant::PACKED_STRING_ARRAY, "blend_shape/names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); @@ -1043,10 +1066,11 @@ void ArrayMesh::_recompute_aabb() { aabb = AABB(); for (int i = 0; i < surfaces.size(); i++) { - if (i == 0) + if (i == 0) { aabb = surfaces[i].aabb; - else + } else { aabb.merge_with(surfaces[i].aabb); + } } } #ifndef _MSC_VER @@ -1188,8 +1212,9 @@ ArrayMesh::PrimitiveType ArrayMesh::surface_get_primitive_type(int p_idx) const 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) + if (surfaces[p_idx].material == p_material) { return; + } surfaces.write[p_idx].material = p_material; RenderingServer::get_singleton()->mesh_surface_set_material(mesh, p_idx, p_material.is_null() ? RID() : p_material->get_rid()); @@ -1363,8 +1388,9 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach if (ic == 0) { for (int j = 0; j < vc / 3; j++) { - if (Face3(r[j * 3 + 0], r[j * 3 + 1], r[j * 3 + 2]).is_degenerate()) + if (Face3(r[j * 3 + 0], r[j * 3 + 1], r[j * 3 + 2]).is_degenerate()) { continue; + } indices.push_back(vertex_ofs + j * 3 + 0); indices.push_back(vertex_ofs + j * 3 + 1); @@ -1375,8 +1401,9 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach const int *ri = rindices.ptr(); for (int j = 0; j < ic / 3; j++) { - if (Face3(r[ri[j * 3 + 0]], r[ri[j * 3 + 1]], r[ri[j * 3 + 2]]).is_degenerate()) + if (Face3(r[ri[j * 3 + 0]], r[ri[j * 3 + 1]], r[ri[j * 3 + 2]]).is_degenerate()) { continue; + } indices.push_back(vertex_ofs + ri[j * 3 + 0]); indices.push_back(vertex_ofs + ri[j * 3 + 1]); indices.push_back(vertex_ofs + ri[j * 3 + 2]); diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 3176b83bb8..a5c360f123 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -57,47 +57,59 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf const Vector3 *vr = varray.ptr(); const Vector3 *nr = nullptr; - if (arrays[Mesh::ARRAY_NORMAL].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_NORMAL].get_type() != Variant::NIL) { nr = arrays[Mesh::ARRAY_NORMAL].operator Vector<Vector3>().ptr(); + } const real_t *ta = nullptr; - if (arrays[Mesh::ARRAY_TANGENT].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_TANGENT].get_type() != Variant::NIL) { ta = arrays[Mesh::ARRAY_TANGENT].operator Vector<real_t>().ptr(); + } const Vector2 *uv = nullptr; - if (arrays[Mesh::ARRAY_TEX_UV].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_TEX_UV].get_type() != Variant::NIL) { uv = arrays[Mesh::ARRAY_TEX_UV].operator Vector<Vector2>().ptr(); + } const Vector2 *uv2 = nullptr; - if (arrays[Mesh::ARRAY_TEX_UV2].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_TEX_UV2].get_type() != Variant::NIL) { uv2 = arrays[Mesh::ARRAY_TEX_UV2].operator Vector<Vector2>().ptr(); + } const Color *col = nullptr; - if (arrays[Mesh::ARRAY_COLOR].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_COLOR].get_type() != Variant::NIL) { col = arrays[Mesh::ARRAY_COLOR].operator Vector<Color>().ptr(); + } const int *bo = nullptr; - if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL) { bo = arrays[Mesh::ARRAY_BONES].operator Vector<int>().ptr(); + } const real_t *we = nullptr; - if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL) + if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL) { we = arrays[Mesh::ARRAY_WEIGHTS].operator Vector<real_t>().ptr(); + } vertices.resize(vcount); for (int i = 0; i < vcount; i++) { Vertex v; v.vertex = vr[i]; - if (nr) + if (nr) { v.normal = nr[i]; - if (ta) + } + if (ta) { v.tangent = Plane(ta[i * 4 + 0], ta[i * 4 + 1], ta[i * 4 + 2], ta[i * 4 + 3]); - if (uv) + } + if (uv) { v.uv = uv[i]; - if (uv2) + } + if (uv2) { v.uv2 = uv2[i]; - if (col) + } + if (col) { v.color = col[i]; + } if (we) { v.weights.push_back(we[i * 4 + 0]); @@ -124,8 +136,9 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf //make code simpler indices.resize(vcount); int *iw = indices.ptrw(); - for (int i = 0; i < vcount; i++) + for (int i = 0; i < vcount; i++) { iw[i] = i; + } } int icount = indices.size(); @@ -238,20 +251,24 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { const Vertex &vtx = vertices[i]; vr[i] = vtx.vertex; - if (nr) + if (nr) { nr[i] = vtx.normal; + } if (ta) { ta[i * 4 + 0] = vtx.tangent.normal.x; ta[i * 4 + 1] = vtx.tangent.normal.y; ta[i * 4 + 2] = vtx.tangent.normal.z; ta[i * 4 + 3] = vtx.tangent.d; } - if (uv) + if (uv) { uv[i] = vtx.uv; - if (uv2) + } + if (uv2) { uv2[i] = vtx.uv2; - if (col) + } + if (col) { col[i] = vtx.color; + } if (we) { we[i * 4 + 0] = vtx.weights[0]; @@ -280,20 +297,27 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { arr[Mesh::ARRAY_VERTEX] = v; arr[Mesh::ARRAY_INDEX] = in; - if (n.size()) + if (n.size()) { arr[Mesh::ARRAY_NORMAL] = n; - if (c.size()) + } + if (c.size()) { arr[Mesh::ARRAY_COLOR] = c; - if (u.size()) + } + if (u.size()) { arr[Mesh::ARRAY_TEX_UV] = u; - if (u2.size()) + } + if (u2.size()) { arr[Mesh::ARRAY_TEX_UV2] = u2; - if (t.size()) + } + if (t.size()) { arr[Mesh::ARRAY_TANGENT] = t; - if (b.size()) + } + if (b.size()) { arr[Mesh::ARRAY_BONES] = b; - if (w.size()) + } + if (w.size()) { arr[Mesh::ARRAY_WEIGHTS] = w; + } Ref<ArrayMesh> ncmesh = p_mesh; int sc = ncmesh->get_surface_count(); diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index 0f2fd939ec..09b0d4b038 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -35,14 +35,15 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { if (name.begins_with("item/")) { int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); - if (!item_map.has(idx)) + if (!item_map.has(idx)) { create_item(idx); + } - if (what == "name") + if (what == "name") { set_item_name(idx, p_value); - else if (what == "mesh") + } else if (what == "mesh") { set_item_mesh(idx, p_value); - else if (what == "shape") { + } else if (what == "shape") { Vector<ShapeData> shapes; ShapeData sd; sd.shape = p_value; @@ -50,14 +51,15 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { set_item_shapes(idx, shapes); } else if (what == "shapes") { _set_item_shapes(idx, p_value); - } else if (what == "preview") + } else if (what == "preview") { set_item_preview(idx, p_value); - else if (what == "navmesh") + } else if (what == "navmesh") { set_item_navmesh(idx, p_value); - else if (what == "navmesh_transform") + } else if (what == "navmesh_transform") { set_item_navmesh_transform(idx, p_value); - else + } else { return false; + } return true; } @@ -71,20 +73,21 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const { ERR_FAIL_COND_V(!item_map.has(idx), false); String what = name.get_slicec('/', 2); - if (what == "name") + if (what == "name") { r_ret = get_item_name(idx); - else if (what == "mesh") + } else if (what == "mesh") { r_ret = get_item_mesh(idx); - else if (what == "shapes") + } else if (what == "shapes") { r_ret = _get_item_shapes(idx); - else if (what == "navmesh") + } else if (what == "navmesh") { r_ret = get_item_navmesh(idx); - else if (what == "navmesh_transform") + } else if (what == "navmesh_transform") { r_ret = get_item_navmesh_transform(idx); - else if (what == "preview") + } else if (what == "preview") { r_ret = get_item_preview(idx); - else + } else { return false; + } return true; } @@ -219,17 +222,19 @@ Vector<int> MeshLibrary::get_item_list() 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()) { - if (E->get().name == p_name) + if (E->get().name == p_name) { return E->key(); + } } return -1; } int MeshLibrary::get_last_unused_item_id() const { - if (!item_map.size()) + if (!item_map.size()) { return 0; - else + } else { return item_map.back()->key() + 1; + } } void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) { diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index 10b9e24fbd..f71cf383e5 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -36,14 +36,16 @@ // Kept for compatibility from 3.x to 4.0. void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) { - if (transform_format != TRANSFORM_3D) + if (transform_format != TRANSFORM_3D) { return; + } const Vector<Vector3> &xforms = p_array; int len = xforms.size(); ERR_FAIL_COND((len / 4) != instance_count); - if (len == 0) + if (len == 0) { return; + } const Vector3 *r = xforms.ptr(); @@ -59,11 +61,13 @@ void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) { } Vector<Vector3> MultiMesh::_get_transform_array() const { - if (transform_format != TRANSFORM_3D) + if (transform_format != TRANSFORM_3D) { return Vector<Vector3>(); + } - if (instance_count == 0) + if (instance_count == 0) { return Vector<Vector3>(); + } Vector<Vector3> xforms; xforms.resize(instance_count * 4); @@ -82,14 +86,16 @@ Vector<Vector3> MultiMesh::_get_transform_array() const { } void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) { - if (transform_format != TRANSFORM_2D) + if (transform_format != TRANSFORM_2D) { return; + } const Vector<Vector2> &xforms = p_array; int len = xforms.size(); ERR_FAIL_COND((len / 3) != instance_count); - if (len == 0) + if (len == 0) { return; + } const Vector2 *r = xforms.ptr(); @@ -104,11 +110,13 @@ void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) { } Vector<Vector2> MultiMesh::_get_transform_2d_array() const { - if (transform_format != TRANSFORM_2D) + if (transform_format != TRANSFORM_2D) { return Vector<Vector2>(); + } - if (instance_count == 0) + if (instance_count == 0) { return Vector<Vector2>(); + } Vector<Vector2> xforms; xforms.resize(instance_count * 3); @@ -128,8 +136,9 @@ Vector<Vector2> MultiMesh::_get_transform_2d_array() const { void MultiMesh::_set_color_array(const Vector<Color> &p_array) { const Vector<Color> &colors = p_array; int len = colors.size(); - if (len == 0) + if (len == 0) { return; + } ERR_FAIL_COND(len != instance_count); const Color *r = colors.ptr(); @@ -140,8 +149,9 @@ void MultiMesh::_set_color_array(const Vector<Color> &p_array) { } Vector<Color> MultiMesh::_get_color_array() const { - if (instance_count == 0 || !use_colors) + if (instance_count == 0 || !use_colors) { return Vector<Color>(); + } Vector<Color> colors; colors.resize(instance_count); @@ -156,8 +166,9 @@ Vector<Color> MultiMesh::_get_color_array() const { void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) { const Vector<Color> &custom_datas = p_array; int len = custom_datas.size(); - if (len == 0) + if (len == 0) { return; + } ERR_FAIL_COND(len != instance_count); const Color *r = custom_datas.ptr(); @@ -168,8 +179,9 @@ void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) { } Vector<Color> MultiMesh::_get_custom_data_array() const { - if (instance_count == 0 || !use_custom_data) + if (instance_count == 0 || !use_custom_data) { return Vector<Color>(); + } Vector<Color> custom_datas; custom_datas.resize(instance_count); @@ -192,10 +204,11 @@ Vector<float> MultiMesh::get_buffer() const { void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) { mesh = p_mesh; - if (!mesh.is_null()) + if (!mesh.is_null()) { RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); - else + } else { RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, RID()); + } } Ref<Mesh> MultiMesh::get_mesh() const { diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index 13d818188d..e815da5d45 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -35,13 +35,15 @@ void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) { clear_polygons(); for (int i = 0; i < p_mesh->get_surface_count(); i++) { - if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) + if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; + } Array arr = p_mesh->surface_get_arrays(i); Vector<Vector3> varr = arr[Mesh::ARRAY_VERTEX]; Vector<int> iarr = arr[Mesh::ARRAY_INDEX]; - if (varr.size() == 0 || iarr.size() == 0) + if (varr.size() == 0 || iarr.size() == 0) { continue; + } int from = vertices.size(); vertices.append_array(varr); @@ -89,10 +91,11 @@ uint32_t NavigationMesh::get_collision_mask() const { void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -294,8 +297,9 @@ void NavigationMesh::clear_polygons() { } Ref<Mesh> NavigationMesh::get_debug_mesh() { - if (debug_mesh.is_valid()) + if (debug_mesh.is_valid()) { return debug_mesh; + } Vector<Vector3> vertices = get_vertices(); const Vector3 *vr = vertices.ptr(); @@ -329,8 +333,9 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { _EdgeKey ek; ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); - if (ek.from < ek.to) + if (ek.from < ek.to) { SWAP(ek.from, ek.to); + } Map<_EdgeKey, bool>::Element *F = edge_map.find(ek); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index ba2cdf75e4..058e89cf2e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -64,13 +64,15 @@ Node *SceneState::instance(GenEditState p_edit_state) const { const StringName *snames = nullptr; int sname_count = names.size(); - if (sname_count) + if (sname_count) { snames = &names[0]; + } const Variant *props = nullptr; int prop_count = variants.size(); - if (prop_count) + if (prop_count) { props = &variants[0]; + } //Vector<Variant> properties; @@ -256,8 +258,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (i > 0) { if (parent) { parent->_add_child_nocheck(node, snames[n.name]); - if (n.index >= 0 && n.index < parent->get_child_count() - 1) + if (n.index >= 0 && n.index < parent->get_child_count() - 1) { parent->move_child(node, n.index); + } } else { //it may be possible that an instanced scene has changed //and the node has nowhere to go anymore @@ -275,8 +278,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { if (n.owner >= 0) { NODE_FROM_ID(owner, n.owner); - if (owner) + if (owner) { node->_set_owner_nocheck(owner); + } } } @@ -305,14 +309,16 @@ Node *SceneState::instance(GenEditState p_edit_state) const { NODE_FROM_ID(cfrom, c.from); NODE_FROM_ID(cto, c.to); - if (!cfrom || !cto) + if (!cfrom || !cto) { continue; + } Vector<Variant> binds; if (c.binds.size()) { binds.resize(c.binds.size()); - for (int j = 0; j < c.binds.size(); j++) + for (int j = 0; j < c.binds.size(); j++) { binds.write[j] = props[c.binds[j]]; + } } cfrom->connect(snames[c.signal], Callable(cto, snames[c.method]), binds, CONNECT_PERSIST | c.flags); @@ -337,8 +343,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } static int _nm_get_string(const String &p_string, Map<StringName, int> &name_map) { - if (name_map.has(p_string)) + if (name_map.has(p_string)) { return name_map[p_string]; + } int idx = name_map.size(); name_map[p_string] = idx; @@ -346,8 +353,9 @@ static int _nm_get_string(const String &p_string, Map<StringName, int> &name_map } static int _vm_get_variant(const Variant &p_variant, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map) { - if (variant_map.has(p_variant)) + if (variant_map.has(p_variant)) { return variant_map[p_variant]; + } int idx = variant_map.size(); variant_map[p_variant] = idx; @@ -361,13 +369,15 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map // document it. if you fail to understand something, please ask! //discard nodes that do not belong to be processed - if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) + if (p_node != p_owner && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) { return OK; + } // save the child instanced scenes that are chosen as editable, so they can be restored // upon load back - if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node)) + if (p_node != p_owner && p_node->get_filename() != String() && p_owner->is_editable_instance(p_node)) { editable_instances.push_back(p_owner->get_path_to(p_node)); + } NodeData nd; @@ -513,8 +523,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map float a = value; float b = original; - if (Math::is_equal_approx(a, b)) + if (Math::is_equal_approx(a, b)) { continue; + } } else if (bool(Variant::evaluate(Variant::OP_EQUAL, value, original))) { continue; } @@ -547,8 +558,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map for (List<Node::GroupInfo>::Element *E = groups.front(); E; E = E->next()) { Node::GroupInfo &gi = E->get(); - if (!gi.persistent) + if (!gi.persistent) { continue; + } /* if (instance_state_node>=0 && instance_state->is_node_in_group(instance_state_node,gi.name)) continue; //group was instanced, don't add here @@ -564,8 +576,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map } } - if (skip) + if (skip) { continue; + } nd.groups.push_back(_nm_get_string(gi.name, name_map)); } @@ -636,16 +649,18 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); Error err = _parse_node(p_owner, c, parent_node, name_map, variant_map, node_map, nodepath_map); - if (err) + if (err) { return err; + } } return OK; } Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, Map<Node *, int> &node_map, Map<Node *, int> &nodepath_map) { - if (p_node != p_owner && p_node->get_owner() && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) + if (p_node != p_owner && p_node->get_owner() && p_node->get_owner() != p_owner && !p_owner->is_editable_instance(p_node->get_owner())) { return OK; + } List<MethodInfo> _signals; p_node->get_signal_list(&_signals); @@ -663,8 +678,9 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName for (List<Node::Connection>::Element *F = conns.front(); F; F = F->next()) { const Node::Connection &c = F->get(); - if (!(c.flags & CONNECT_PERSIST)) //only persistent connections get saved + if (!(c.flags & CONNECT_PERSIST)) { //only persistent connections get saved continue; + } // only connections that originate or end into main saved scene are saved // everything else is discarded @@ -690,10 +706,11 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName while (common_parent) { Ref<SceneState> ps; - if (common_parent == p_owner) + if (common_parent == p_owner) { ps = common_parent->get_scene_inherited_state(); - else + } else { ps = common_parent->get_scene_instance_state(); + } if (ps.is_valid()) { NodePath signal_from = common_parent->get_path_to(p_node); @@ -705,10 +722,11 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName } } - if (common_parent == p_owner) + if (common_parent == p_owner) { break; - else + } else { common_parent = common_parent->get_owner(); + } } if (exists) { //already exists (comes from instance or inheritance), so don't save @@ -807,8 +825,9 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); Error err = _parse_connections(p_owner, c, name_map, variant_map, node_map, nodepath_map); - if (err) + if (err) { return err; + } } return OK; @@ -973,8 +992,9 @@ bool SceneState::is_node_in_group(int p_node, const StringName &p_group) const { if (p_node < nodes.size()) { const StringName *namep = names.ptr(); for (int i = 0; i < nodes[p_node].groups.size(); i++) { - if (namep[nodes[p_node].groups[i]] == p_group) + if (namep[nodes[p_node].groups[i]] == p_group) { return true; + } } } @@ -1034,8 +1054,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { //ERR_FAIL_COND( !p_dictionary.has("path")); int version = 1; - if (p_dictionary.has("version")) + if (p_dictionary.has("version")) { version = p_dictionary["version"]; + } ERR_FAIL_COND_MSG(version > PACKED_SCENE_VERSION, "Save format version too new."); @@ -1052,8 +1073,9 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { int namecount = snames.size(); names.resize(namecount); const String *r = snames.ptr(); - for (int i = 0; i < names.size(); i++) + for (int i = 0; i < names.size(); i++) { names.write[i] = r[i]; + } } Array svariants = p_dictionary["variants"]; @@ -1147,8 +1169,9 @@ Dictionary SceneState::get_bundled_scene() const { if (names.size()) { String *r = rnames.ptrw(); - for (int i = 0; i < names.size(); i++) + for (int i = 0; i < names.size(); i++) { r[i] = names[i]; + } } Dictionary d; @@ -1193,8 +1216,9 @@ Dictionary SceneState::get_bundled_scene() const { rconns.push_back(cd.method); rconns.push_back(cd.flags); rconns.push_back(cd.binds.size()); - for (int j = 0; j < cd.binds.size(); j++) + for (int j = 0; j < cd.binds.size(); j++) { rconns.push_back(cd.binds[j]); + } } d["conns"] = rconns; @@ -1227,8 +1251,9 @@ int SceneState::get_node_count() const { StringName SceneState::get_node_type(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, nodes.size(), StringName()); - if (nodes[p_idx].type == TYPE_INSTANCED) + if (nodes[p_idx].type == TYPE_INSTANCED) { return StringName(); + } return names[nodes[p_idx].type]; } @@ -1252,10 +1277,11 @@ Ref<PackedScene> SceneState::get_node_instance(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, nodes.size(), Ref<PackedScene>()); if (nodes[p_idx].instance >= 0) { - if (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER) + if (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER) { return Ref<PackedScene>(); - else + } else { return variants[nodes[p_idx].instance & FLAG_MASK]; + } } else if (nodes[p_idx].parent < 0 || nodes[p_idx].parent == NO_PARENT_SAVED) { if (base_scene_idx >= 0) { return variants[base_scene_idx]; @@ -1347,8 +1373,9 @@ Variant SceneState::get_node_property_value(int p_idx, int p_prop) const { NodePath SceneState::get_node_owner_path(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, nodes.size(), NodePath()); - if (nodes[p_idx].owner < 0 || nodes[p_idx].owner == NO_PARENT_SAVED) + if (nodes[p_idx].owner < 0 || nodes[p_idx].owner == NO_PARENT_SAVED) { return NodePath(); //root likely + } if (nodes[p_idx].owner & FLAG_ID_IS_PATH) { return node_paths[nodes[p_idx].owner & FLAG_MASK]; } else { @@ -1453,8 +1480,9 @@ int SceneState::add_name(const StringName &p_name) { int SceneState::find_name(const StringName &p_name) const { for (int i = 0; i < names.size(); i++) { - if (names[i] == p_name) + if (names[i] == p_name) { return i; + } } return -1; @@ -1531,8 +1559,9 @@ Vector<String> SceneState::_get_node_groups(int p_idx) const { Vector<StringName> groups = get_node_groups(p_idx); Vector<String> ret; - for (int i = 0; i < groups.size(); i++) + for (int i = 0; i < groups.size(); i++) { ret.push_back(groups[i]); + } return ret; } @@ -1599,15 +1628,17 @@ Node *PackedScene::instance(GenEditState p_edit_state) const { #endif Node *s = state->instance((SceneState::GenEditState)p_edit_state); - if (!s) + if (!s) { return nullptr; + } if (p_edit_state != GEN_EDIT_STATE_DISABLED) { s->set_scene_instance_state(state); } - if (get_path() != "" && get_path().find("::") == -1) + if (get_path() != "" && get_path().find("::") == -1) { s->set_filename(get_path()); + } s->notification(Node::NOTIFICATION_INSTANCED); diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index 2f65c92181..fc92a721db 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -111,8 +111,9 @@ void ParticlesMaterial::_update_shader() { dirty_materials->remove(&element); MaterialKey mk = _compute_key(); - if (mk.key == current_key.key) + if (mk.key == current_key.key) { return; //no update required in the end + } if (shader_map.has(current_key)) { shader_map[current_key].users--; @@ -197,33 +198,46 @@ void ParticlesMaterial::_update_shader() { code += "uniform vec3 gravity;\n"; - if (color_ramp.is_valid()) + if (color_ramp.is_valid()) { code += "uniform sampler2D color_ramp;\n"; + } - if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) + if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) { code += "uniform sampler2D linear_velocity_texture;\n"; - if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) + } + if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) { code += "uniform sampler2D orbit_velocity_texture;\n"; - if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) + } + if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) { code += "uniform sampler2D angular_velocity_texture;\n"; - if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) + } + if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) { code += "uniform sampler2D linear_accel_texture;\n"; - if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) + } + if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) { code += "uniform sampler2D radial_accel_texture;\n"; - if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) + } + if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) { code += "uniform sampler2D tangent_accel_texture;\n"; - if (tex_parameters[PARAM_DAMPING].is_valid()) + } + if (tex_parameters[PARAM_DAMPING].is_valid()) { code += "uniform sampler2D damping_texture;\n"; - if (tex_parameters[PARAM_ANGLE].is_valid()) + } + if (tex_parameters[PARAM_ANGLE].is_valid()) { code += "uniform sampler2D angle_texture;\n"; - if (tex_parameters[PARAM_SCALE].is_valid()) + } + if (tex_parameters[PARAM_SCALE].is_valid()) { code += "uniform sampler2D scale_texture;\n"; - if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) + } + if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) { code += "uniform sampler2D hue_variation_texture;\n"; - if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) + } + if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) { code += "uniform sampler2D anim_speed_texture;\n"; - if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) + } + if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) { code += "uniform sampler2D anim_offset_texture;\n"; + } if (trail_size_modifier.is_valid()) { code += "uniform sampler2D trail_size_modifier;\n"; @@ -285,20 +299,23 @@ void ParticlesMaterial::_update_shader() { code += " }\n\n"; code += " if (RESTART || restart) {\n"; - if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) + if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) { code += " float tex_linear_velocity = textureLod(linear_velocity_texture, vec2(0.0, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_linear_velocity = 0.0;\n"; + } - if (tex_parameters[PARAM_ANGLE].is_valid()) + if (tex_parameters[PARAM_ANGLE].is_valid()) { code += " float tex_angle = textureLod(angle_texture, vec2(0.0, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_angle = 0.0;\n"; + } - if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) + if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) { code += " float tex_anim_offset = textureLod(anim_offset_texture, vec2(0.0, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_anim_offset = 0.0;\n"; + } code += " float spread_rad = spread * degree_to_rad;\n"; @@ -374,57 +391,67 @@ void ParticlesMaterial::_update_shader() { code += " } else {\n"; code += " CUSTOM.y += DELTA / LIFETIME;\n"; - if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) + if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) { code += " float tex_linear_velocity = textureLod(linear_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_linear_velocity = 0.0;\n"; + } if (flags[FLAG_DISABLE_Z]) { - if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) + if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) { code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_orbit_velocity = 0.0;\n"; + } } - if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) + if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) { code += " float tex_angular_velocity = textureLod(angular_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_angular_velocity = 0.0;\n"; + } - if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) + if (tex_parameters[PARAM_LINEAR_ACCEL].is_valid()) { code += " float tex_linear_accel = textureLod(linear_accel_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_linear_accel = 0.0;\n"; + } - if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) + if (tex_parameters[PARAM_RADIAL_ACCEL].is_valid()) { code += " float tex_radial_accel = textureLod(radial_accel_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_radial_accel = 0.0;\n"; + } - if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) + if (tex_parameters[PARAM_TANGENTIAL_ACCEL].is_valid()) { code += " float tex_tangent_accel = textureLod(tangent_accel_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_tangent_accel = 0.0;\n"; + } - if (tex_parameters[PARAM_DAMPING].is_valid()) + if (tex_parameters[PARAM_DAMPING].is_valid()) { code += " float tex_damping = textureLod(damping_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_damping = 0.0;\n"; + } - if (tex_parameters[PARAM_ANGLE].is_valid()) + if (tex_parameters[PARAM_ANGLE].is_valid()) { code += " float tex_angle = textureLod(angle_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_angle = 0.0;\n"; + } - if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) + if (tex_parameters[PARAM_ANIM_SPEED].is_valid()) { code += " float tex_anim_speed = textureLod(anim_speed_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_anim_speed = 0.0;\n"; + } - if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) + if (tex_parameters[PARAM_ANIM_OFFSET].is_valid()) { code += " float tex_anim_offset = textureLod(anim_offset_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_anim_offset = 0.0;\n"; + } code += " vec3 force = gravity;\n"; code += " vec3 pos = TRANSFORM[3].xyz;\n"; @@ -478,15 +505,17 @@ void ParticlesMaterial::_update_shader() { code += " }\n"; // apply color // apply hue rotation - if (tex_parameters[PARAM_SCALE].is_valid()) + if (tex_parameters[PARAM_SCALE].is_valid()) { code += " float tex_scale = textureLod(scale_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_scale = 1.0;\n"; + } - if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) + if (tex_parameters[PARAM_HUE_VARIATION].is_valid()) { code += " float tex_hue_variation = textureLod(hue_variation_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n"; - else + } else { code += " float tex_hue_variation = 0.0;\n"; + } code += " float hue_rot_angle = (hue_variation + tex_hue_variation) * pi * 2.0 * mix(1.0, hue_rot_rand * 2.0 - 1.0, hue_variation_random);\n"; code += " float hue_rot_c = cos(hue_rot_angle);\n"; @@ -750,8 +779,9 @@ float ParticlesMaterial::get_param_randomness(Parameter p_param) const { static void _adjust_curve_range(const Ref<Texture2D> &p_texture, float p_min, float p_max) { Ref<CurveTexture> curve_tex = p_texture; - if (!curve_tex.is_valid()) + if (!curve_tex.is_valid()) { return; + } curve_tex->ensure_default_setup(p_min, p_max); } diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 8e65ae8bed..0546c92948 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -92,21 +92,24 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> for (int i = 0; i < point_count; i++) { for (int j = i + 1; j < point_count; j++) { - if (edges.has(Edge(i, j))) + if (edges.has(Edge(i, j))) { continue; //if in edge ignore + } Vector2 from = points[i].pos; Vector2 to = points[j].pos; - if (!_is_point_inside(from * 0.5 + to * 0.5)) //connection between points in inside space + if (!_is_point_inside(from * 0.5 + to * 0.5)) { //connection between points in inside space continue; + } bool valid = true; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { const Edge &e = E->get(); - if (e.points[0] == i || e.points[1] == i || e.points[0] == j || e.points[1] == j) + if (e.points[0] == i || e.points[1] == i || e.points[0] == j || e.points[1] == j) { continue; + } Vector2 a = points[e.points[0]].pos; Vector2 b = points[e.points[1]].pos; @@ -187,10 +190,12 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { const Edge &e = E->get(); - if (e.points[0] == ignore_from_edge.points[0] && e.points[1] == ignore_from_edge.points[1]) + if (e.points[0] == ignore_from_edge.points[0] && e.points[1] == ignore_from_edge.points[1]) { continue; - if (e.points[0] == ignore_to_edge.points[0] && e.points[1] == ignore_to_edge.points[1]) + } + if (e.points[0] == ignore_to_edge.points[0] && e.points[1] == ignore_to_edge.points[1]) { continue; + } Vector2 a = points[e.points[0]].pos; Vector2 b = points[e.points[1]].pos; @@ -238,8 +243,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { const Edge &e = E->get(); - if (e.points[0] == i || e.points[1] == i) + if (e.points[0] == i || e.points[1] == i) { continue; + } Vector2 a = points[e.points[0]].pos; Vector2 b = points[e.points[1]].pos; @@ -266,8 +272,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } } - if (!valid_a && !valid_b) + if (!valid_a && !valid_b) { break; + } } if (valid_a) { @@ -346,8 +353,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } } - if (found_route) + if (found_route) { break; + } open_list.erase(least_cost_point); } @@ -390,8 +398,9 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) { Array c = p_data["connections"]; ERR_FAIL_COND(c.size() != p.size()); - if (c.size()) + if (c.size()) { return; + } int pc = p.size(); points.resize(pc + 2); diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h index f29299055e..baee4dc20d 100644 --- a/scene/resources/polygon_path_finder.h +++ b/scene/resources/polygon_path_finder.h @@ -48,10 +48,11 @@ class PolygonPathFinder : public Resource { int points[2]; _FORCE_INLINE_ bool operator<(const Edge &p_edge) const { - if (points[0] == p_edge.points[0]) + if (points[0] == p_edge.points[0]) { return points[1] < p_edge.points[1]; - else + } else { return points[0] < p_edge.points[0]; + } } Edge(int a = 0, int b = 0) { diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 6e662b1085..99edf26dc1 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -48,10 +48,11 @@ void PrimitiveMesh::_update() const { { const Vector3 *r = points.ptr(); for (int i = 0; i < pc; i++) { - if (i == 0) + if (i == 0) { aabb.position = r[i]; - else + } else { aabb.expand_to(r[i]); + } } } @@ -96,8 +97,9 @@ void PrimitiveMesh::_update() const { } void PrimitiveMesh::_request_update() { - if (pending_request) + if (pending_request) { return; + } _update(); } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index f758427bd6..93db8b725f 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -253,8 +253,9 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars if (next_tag.fields.has("owner")) { owner = packed_scene->get_state()->add_node_path(next_tag.fields["owner"]); } else { - if (parent != -1 && !(type == SceneState::TYPE_INSTANCED && instance == -1)) + if (parent != -1 && !(type == SceneState::TYPE_INSTANCED && instance == -1)) { owner = 0; //if no owner, owner is root + } } if (next_tag.fields.has("index")) { @@ -391,8 +392,9 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } Error ResourceLoaderText::load() { - if (error != OK) + if (error != OK) { return error; + } while (true) { if (next_tag.name != "ext_resource") { @@ -659,8 +661,9 @@ Error ResourceLoaderText::load() { Ref<PackedScene> packed_scene = _parse_node_tag(rp); - if (!packed_scene.is_valid()) + if (!packed_scene.is_valid()) { return error; + } error = OK; //get it here @@ -784,8 +787,9 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p if (next_tag.name != "ext_resource") { //nothing was done - if (!fw) + if (!fw) { return OK; + } break; @@ -939,8 +943,9 @@ static void bs_save_unicode_string(FileAccess *f, const String &p_string, bool p } Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) { - if (error) + if (error) { return error; + } FileAccessRef wf = FileAccess::open(p_path, FileAccess::WRITE); if (!wf) { @@ -960,8 +965,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) bs_save_unicode_string(wf.f, is_scene ? "PackedScene" : resource_type); wf->store_64(0); //offset to import metadata, this is no longer used - for (int i = 0; i < 14; i++) + for (int i = 0; i < 14; i++) { wf->store_32(0); // reserved + } wf->store_32(0); //string table size, will not be in use size_t ext_res_count_pos = wf->get_position(); @@ -1130,8 +1136,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) Ref<PackedScene> packed_scene = _parse_node_tag(rp); - if (!packed_scene.is_valid()) + if (!packed_scene.is_valid()) { return error; + } error = OK; //get it here @@ -1150,8 +1157,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) int prop_count = 0; for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; + } String name = E->get().name; Variant value = packed_scene->get(name); @@ -1221,11 +1229,13 @@ String ResourceLoaderText::recognize(FileAccess *p_f) { } } - if (tag.name == "gd_scene") + if (tag.name == "gd_scene") { return "PackedScene"; + } - if (tag.name != "gd_resource") + if (tag.name != "gd_resource") { return ""; + } if (!tag.fields.has("type")) { error_text = "Missing 'type' field in 'gd_resource' tag"; @@ -1239,8 +1249,9 @@ String ResourceLoaderText::recognize(FileAccess *p_f) { ///////////////////// RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_CANT_OPEN; + } Error err; @@ -1274,10 +1285,11 @@ void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String & return; } - if (p_type == "PackedScene") + if (p_type == "PackedScene") { p_extensions->push_back("tscn"); - else + } else { p_extensions->push_back("tres"); + } } void ResourceFormatLoaderText::get_recognized_extensions(List<String> *p_extensions) const { @@ -1291,10 +1303,11 @@ bool ResourceFormatLoaderText::handles_type(const String &p_type) const { String ResourceFormatLoaderText::get_resource_type(const String &p_path) const { String ext = p_path.get_extension().to_lower(); - if (ext == "tscn") + if (ext == "tscn") { return "PackedScene"; - else if (ext != "tres") + } else if (ext != "tres") { return String(); + } //for anyhting else must test.. @@ -1395,8 +1408,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, case Variant::OBJECT: { RES res = p_variant; - if (res.is_null() || external_resources.has(res)) + if (res.is_null() || external_resources.has(res)) { return; + } if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) { if (res->get_path() == local_path) { @@ -1408,8 +1422,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, return; } - if (resource_set.has(res)) + if (resource_set.has(res)) { return; + } List<PropertyInfo> property_list; @@ -1495,8 +1510,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r if (packed_scene.is_valid()) { //add instances to external resources if saving a packed scene for (int i = 0; i < packed_scene->get_state()->get_node_count(); i++) { - if (packed_scene->get_state()->is_node_instance_placeholder(i)) + if (packed_scene->get_state()->is_node_instance_placeholder(i)) { continue; + } Ref<PackedScene> instance = packed_scene->get_state()->get_node_instance(i); if (instance.is_valid() && !external_resources.has(instance)) { @@ -1508,8 +1524,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r { String title = packed_scene.is_valid() ? "[gd_scene " : "[gd_resource "; - if (packed_scene.is_null()) + if (packed_scene.is_null()) { title += "type=\"" + p_resource->get_class() + "\" "; + } int load_steps = saved_resources.size() + external_resources.size(); /* if (packed_scene.is_valid()) { @@ -1580,8 +1597,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_string("[ext_resource path=\"" + p + "\" type=\"" + sorted_er[i].resource->get_save_class() + "\" id=" + itos(sorted_er[i].index) + "]\n"); //bundled } - if (external_resources.size()) + if (external_resources.size()) { f->store_line(String()); //separate + } Set<int> used_indices; @@ -1603,8 +1621,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r ERR_CONTINUE(!resource_set.has(res)); bool main = (E->next() == nullptr); - if (main && packed_scene.is_valid()) + if (main && packed_scene.is_valid()) { break; //save as a scene + } if (main) { f->store_line("[resource]"); @@ -1637,8 +1656,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r res->get_property_list(&property_list); //property_list.sort(); for (List<PropertyInfo>::Element *PE = property_list.front(); PE; PE = PE->next()) { - if (skip_editor && PE->get().name.begins_with("__editor")) + if (skip_editor && PE->get().name.begins_with("__editor")) { continue; + } if (PE->get().usage & PROPERTY_USAGE_STORAGE) { String name = PE->get().name; @@ -1659,8 +1679,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r continue; } - if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL)) + if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL)) { continue; + } String vars; VariantWriter::write_to_string(value, vars, _write_resources, this); @@ -1668,8 +1689,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } } - if (E->next()) + if (E->next()) { f->store_line(String()); + } } if (packed_scene.is_valid()) { @@ -1735,8 +1757,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_string(String(state->get_node_property_name(i, j)).property_name_encode() + " = " + vars + "\n"); } - if (i < state->get_node_count() - 1) + if (i < state->get_node_count() - 1) { f->store_line(String()); + } } for (int i = 0; i < state->get_connection_count(); i++) { @@ -1792,10 +1815,11 @@ bool ResourceFormatSaverText::recognize(const RES &p_resource) const { } void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (p_resource->get_class() == "PackedScene") + if (p_resource->get_class() == "PackedScene") { p_extensions->push_back("tscn"); //text scene - else + } else { p_extensions->push_back("tres"); //text resource + } } ResourceFormatSaverText *ResourceFormatSaverText::singleton = nullptr; diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp index 2f7fbfb311..7b409eebbb 100644 --- a/scene/resources/segment_shape_2d.cpp +++ b/scene/resources/segment_shape_2d.cpp @@ -117,8 +117,9 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) { pts.push_back(tip + Vector2(Math_SQRT12 * tsize, 0)); pts.push_back(tip + Vector2(-Math_SQRT12 * tsize, 0)); Vector<Color> cols; - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { cols.push_back(p_color); + } RS::get_singleton()->canvas_item_add_primitive(p_to_rid, pts, cols, Vector<Point2>(), RID()); } diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 341139e1c4..4ca8032d65 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -80,8 +80,9 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const { params_cache[pi.name] = E->get().name; if (p_params) { //small little hack - if (pi.type == Variant::_RID) + if (pi.type == Variant::_RID) { pi.type = Variant::OBJECT; + } p_params->push_back(pi); } } @@ -106,10 +107,11 @@ void Shader::set_default_texture_param(const StringName &p_param, const Ref<Text } Ref<Texture2D> Shader::get_default_texture_param(const StringName &p_param) const { - if (default_textures.has(p_param)) + if (default_textures.has(p_param)) { return default_textures[p_param]; - else + } else { return Ref<Texture2D>(); + } } void Shader::get_default_texture_param_list(List<StringName> *r_textures) const { @@ -163,8 +165,9 @@ Shader::~Shader() { //////////// RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } Ref<Shader> shader; shader.instance(); @@ -176,8 +179,9 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi shader->set_code(str); - if (r_error) + if (r_error) { *r_error = OK; + } return shader; } @@ -192,8 +196,9 @@ bool ResourceFormatLoaderShader::handles_type(const String &p_type) const { String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "shader") + if (el == "shader") { return "Shader"; + } return ""; } diff --git a/scene/resources/shader.h b/scene/resources/shader.h index 9fa8a9ae95..2cdc2ec93f 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -82,12 +82,14 @@ public: virtual bool is_text_shader() const; _FORCE_INLINE_ StringName remap_param(const StringName &p_param) const { - if (params_cache_dirty) + if (params_cache_dirty) { get_param_list(nullptr); + } const Map<StringName, StringName>::Element *E = params_cache.find(p_param); - if (E) + if (E) { return E->get(); + } return StringName(); } diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 60c796f9f9..99e8020e34 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -61,8 +61,9 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x Vector2 result[max_contacts * 2]; int contacts = 0; - if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) + if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, result, max_contacts, contacts)) { return Array(); + } Array results; results.resize(contacts * 2); @@ -79,8 +80,9 @@ Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Vector2 result[max_contacts * 2]; int contacts = 0; - if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) + if (!PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, Vector2(), p_shape->get_rid(), p_shape_xform, Vector2(), result, max_contacts, contacts)) { return Array(); + } Array results; results.resize(contacts * 2); diff --git a/scene/resources/shape_3d.cpp b/scene/resources/shape_3d.cpp index 110543723c..59766f4f1f 100644 --- a/scene/resources/shape_3d.cpp +++ b/scene/resources/shape_3d.cpp @@ -58,8 +58,9 @@ void Shape3D::set_margin(real_t p_margin) { } Ref<ArrayMesh> Shape3D::get_debug_mesh() { - if (debug_mesh_cache.is_valid()) + if (debug_mesh_cache.is_valid()) { return debug_mesh_cache; + } Vector<Vector3> lines = get_debug_mesh_lines(); diff --git a/scene/resources/sky.cpp b/scene/resources/sky.cpp index e7ca12162b..54b6cde8bd 100644 --- a/scene/resources/sky.cpp +++ b/scene/resources/sky.cpp @@ -58,8 +58,9 @@ Sky::ProcessMode Sky::get_process_mode() const { void Sky::set_material(const Ref<Material> &p_material) { sky_material = p_material; RID material_rid; - if (sky_material.is_valid()) + if (sky_material.is_valid()) { material_rid = sky_material->get_rid(); + } RS::get_singleton()->sky_set_material(sky, material_rid); } diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index b7c26dd3c3..eb65f10ec9 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -54,10 +54,11 @@ float StyleBox::get_default_margin(Margin p_margin) const { float StyleBox::get_margin(Margin p_margin) const { ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); - if (margin[p_margin] < 0) + if (margin[p_margin] < 0) { return get_style_margin(p_margin); - else + } else { return margin[p_margin]; + } } CanvasItem *StyleBox::get_current_item_drawn() const { @@ -111,8 +112,9 @@ StyleBox::StyleBox() { } void StyleBoxTexture::set_texture(Ref<Texture2D> p_texture) { - if (texture == p_texture) + if (texture == p_texture) { return; + } texture = p_texture; if (p_texture.is_null()) { region_rect = Rect2(0, 0, 0, 0); @@ -129,8 +131,9 @@ Ref<Texture2D> StyleBoxTexture::get_texture() const { } void StyleBoxTexture::set_normal_map(Ref<Texture2D> p_normal_map) { - if (normal_map == p_normal_map) + if (normal_map == p_normal_map) { return; + } normal_map = p_normal_map; emit_changed(); } @@ -170,8 +173,9 @@ Rect2 StyleBoxTexture::get_draw_rect(const Rect2 &p_rect) const { } void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { - if (texture.is_null()) + if (texture.is_null()) { return; + } Rect2 rect = p_rect; Rect2 src_rect = region_rect; @@ -184,8 +188,9 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { rect.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM]; RID normal_rid; - if (normal_map.is_valid()) + if (normal_map.is_valid()) { normal_rid = normal_map->get_rid(); + } RenderingServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center, modulate, normal_rid); } @@ -200,8 +205,9 @@ bool StyleBoxTexture::is_draw_center_enabled() const { } Size2 StyleBoxTexture::get_center_size() const { - if (texture.is_null()) + if (texture.is_null()) { return Size2(); + } return region_rect.size - get_minimum_size(); } @@ -233,8 +239,9 @@ float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const { } void StyleBoxTexture::set_region_rect(const Rect2 &p_region_rect) { - if (region_rect == p_region_rect) + if (region_rect == p_region_rect) { return; + } region_rect = p_region_rect; emit_changed(); @@ -265,8 +272,9 @@ StyleBoxTexture::AxisStretchMode StyleBoxTexture::get_v_axis_stretch_mode() cons } void StyleBoxTexture::set_modulate(const Color &p_modulate) { - if (modulate == p_modulate) + if (modulate == p_modulate) { return; + } modulate = p_modulate; emit_changed(); } diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index feba8c6c70..1a2dcc84bb 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -36,35 +36,44 @@ #define EQ_VERTEX_DIST 0.00001 bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const { - if (vertex != p_vertex.vertex) + if (vertex != p_vertex.vertex) { return false; + } - if (uv != p_vertex.uv) + if (uv != p_vertex.uv) { return false; + } - if (uv2 != p_vertex.uv2) + if (uv2 != p_vertex.uv2) { return false; + } - if (normal != p_vertex.normal) + if (normal != p_vertex.normal) { return false; + } - if (binormal != p_vertex.binormal) + if (binormal != p_vertex.binormal) { return false; + } - if (color != p_vertex.color) + if (color != p_vertex.color) { return false; + } - if (bones.size() != p_vertex.bones.size()) + if (bones.size() != p_vertex.bones.size()) { return false; + } for (int i = 0; i < bones.size(); i++) { - if (bones[i] != p_vertex.bones[i]) + if (bones[i] != p_vertex.bones[i]) { return false; + } } for (int i = 0; i < weights.size(); i++) { - if (weights[i] != p_vertex.weights[i]) + if (weights[i] != p_vertex.weights[i]) { return false; + } } return true; @@ -266,8 +275,9 @@ Array SurfaceTool::commit_to_arrays() { a.resize(Mesh::ARRAY_MAX); for (int i = 0; i < Mesh::ARRAY_MAX; i++) { - if (!(format & (1 << i))) + if (!(format & (1 << i))) { continue; //not in format + } switch (i) { case Mesh::ARRAY_VERTEX: @@ -412,15 +422,17 @@ Array SurfaceTool::commit_to_arrays() { Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_flags) { Ref<ArrayMesh> mesh; - if (p_existing.is_valid()) + if (p_existing.is_valid()) { mesh = p_existing; - else + } else { mesh.instance(); + } int varr_len = vertex_array.size(); - if (varr_len == 0) + if (varr_len == 0) { return mesh; + } int surface = mesh->get_surface_count(); @@ -428,15 +440,17 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_ mesh->add_surface_from_arrays(primitive, a, Array(), Dictionary(), p_flags); - if (material.is_valid()) + if (material.is_valid()) { mesh->surface_set_material(surface, material); + } return mesh; } void SurfaceTool::index() { - if (index_array.size()) + if (index_array.size()) { return; //already indexed + } HashMap<Vertex, int, VertexHasher> indices; List<Vertex> new_vertices; @@ -462,8 +476,9 @@ void SurfaceTool::index() { } void SurfaceTool::deindex() { - if (index_array.size() == 0) + if (index_array.size() == 0) { return; //nothing to deindex + } Vector<Vertex> varr; varr.resize(vertex_array.size()); int idx = 0; @@ -498,8 +513,9 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array Vector<float> warr = p_arrays[RS::ARRAY_WEIGHTS]; int vc = varr.size(); - if (vc == 0) + if (vc == 0) { return ret; + } int lformat = 0; if (varr.size()) { @@ -529,21 +545,26 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array for (int i = 0; i < vc; i++) { Vertex v; - if (lformat & RS::ARRAY_FORMAT_VERTEX) + if (lformat & RS::ARRAY_FORMAT_VERTEX) { v.vertex = varr[i]; - if (lformat & RS::ARRAY_FORMAT_NORMAL) + } + if (lformat & RS::ARRAY_FORMAT_NORMAL) { v.normal = narr[i]; + } if (lformat & RS::ARRAY_FORMAT_TANGENT) { Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]); v.tangent = p.normal; v.binormal = p.normal.cross(v.tangent).normalized() * p.d; } - if (lformat & RS::ARRAY_FORMAT_COLOR) + if (lformat & RS::ARRAY_FORMAT_COLOR) { v.color = carr[i]; - if (lformat & RS::ARRAY_FORMAT_TEX_UV) + } + if (lformat & RS::ARRAY_FORMAT_TEX_UV) { v.uv = uvarr[i]; - if (lformat & RS::ARRAY_FORMAT_TEX_UV2) + } + if (lformat & RS::ARRAY_FORMAT_TEX_UV2) { v.uv2 = uv2arr[i]; + } if (lformat & RS::ARRAY_FORMAT_BONES) { Vector<int> b; b.resize(4); @@ -580,8 +601,9 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li Vector<float> warr = arr[RS::ARRAY_WEIGHTS]; int vc = varr.size(); - if (vc == 0) + if (vc == 0) { return; + } lformat = 0; if (varr.size()) { @@ -611,21 +633,26 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li for (int i = 0; i < vc; i++) { Vertex v; - if (lformat & RS::ARRAY_FORMAT_VERTEX) + if (lformat & RS::ARRAY_FORMAT_VERTEX) { v.vertex = varr[i]; - if (lformat & RS::ARRAY_FORMAT_NORMAL) + } + if (lformat & RS::ARRAY_FORMAT_NORMAL) { v.normal = narr[i]; + } if (lformat & RS::ARRAY_FORMAT_TANGENT) { Plane p(tarr[i * 4 + 0], tarr[i * 4 + 1], tarr[i * 4 + 2], tarr[i * 4 + 3]); v.tangent = p.normal; v.binormal = p.normal.cross(v.tangent).normalized() * p.d; } - if (lformat & RS::ARRAY_FORMAT_COLOR) + if (lformat & RS::ARRAY_FORMAT_COLOR) { v.color = carr[i]; - if (lformat & RS::ARRAY_FORMAT_TEX_UV) + } + if (lformat & RS::ARRAY_FORMAT_TEX_UV) { v.uv = uvarr[i]; - if (lformat & RS::ARRAY_FORMAT_TEX_UV2) + } + if (lformat & RS::ARRAY_FORMAT_TEX_UV2) { v.uv2 = uv2arr[i]; + } if (lformat & RS::ARRAY_FORMAT_BONES) { Vector<int> b; b.resize(4); @@ -869,8 +896,9 @@ void SurfaceTool::generate_normals(bool p_flip) { int count = 0; bool smooth = false; - if (smooth_groups.has(0)) + if (smooth_groups.has(0)) { smooth = smooth_groups[0]; + } List<Vertex>::Element *B = vertex_array.front(); for (List<Vertex>::Element *E = B; E;) { @@ -883,10 +911,11 @@ void SurfaceTool::generate_normals(bool p_flip) { E = v[2]->next(); Vector3 normal; - if (!p_flip) + if (!p_flip) { normal = Plane(v[0]->get().vertex, v[1]->get().vertex, v[2]->get().vertex).normal; - else + } else { normal = Plane(v[2]->get().vertex, v[1]->get().vertex, v[0]->get().vertex).normal; + } if (smooth) { for (int i = 0; i < 3; i++) { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index b549bea4f4..331cffed5d 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -91,8 +91,9 @@ Texture2D::Texture2D() { void ImageTexture::reload_from_file() { String path = ResourceLoader::path_remap(get_path()); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } Ref<Image> img; img.instance(); @@ -107,26 +108,28 @@ void ImageTexture::reload_from_file() { } bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "image") + if (p_name == "image") { create_from_image(p_value); - else if (p_name == "size") { + } else if (p_name == "size") { Size2 s = p_value; w = s.width; h = s.height; RenderingServer::get_singleton()->texture_set_size_override(texture, w, h); - } else + } else { return false; + } return true; } bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "image") + if (p_name == "image") { r_ret = get_data(); - else if (p_name == "size") + } else if (p_name == "size") { r_ret = Size2(w, h); - else + } else { return false; + } return true; } @@ -138,8 +141,9 @@ void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const { void ImageTexture::_reload_hook(const RID &p_hook) { String path = get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } Ref<Image> img; img.instance(); @@ -230,24 +234,27 @@ bool ImageTexture::has_alpha() const { } void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); @@ -288,10 +295,12 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { void ImageTexture::set_size_override(const Size2 &p_size) { Size2 s = p_size; - if (s.x != 0) + if (s.x != 0) { w = s.x; - if (s.y != 0) + } + if (s.y != 0) { h = s.y; + } RenderingServer::get_singleton()->texture_set_size_override(texture, w, h); } @@ -568,8 +577,9 @@ Error StreamTexture2D::load(const String &p_path) { int mipmap_limit; Error err = _load_data(p_path, lw, lh, lwc, lhc, image, request_3d, request_normal, request_roughness, mipmap_limit); - if (err) + if (err) { return err; + } if (texture.is_valid()) { RID new_texture = RS::get_singleton()->texture_2d_create(image); @@ -643,24 +653,27 @@ RID StreamTexture2D::get_rid() const { } void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, Size2(w, h)), texture, false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, texture, p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { - if ((w | h) == 0) + if ((w | h) == 0) { return; + } RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); RID specular_rid = p_specular_map.is_valid() ? p_specular_map->get_rid() : RID(); RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, texture, p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); @@ -714,13 +727,15 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const { void StreamTexture2D::reload_from_file() { String path = get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } path = ResourceLoader::path_remap(path); //remap for translation path = ResourceLoader::import_remap(path); //remap for import - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } load(path); } @@ -751,10 +766,12 @@ RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String Ref<StreamTexture2D> st; st.instance(); Error err = st->load(p_path); - if (r_error) + if (r_error) { *r_error = err; - if (err != OK) + } + if (err != OK) { return RES(); + } return st; } @@ -768,8 +785,9 @@ bool ResourceFormatLoaderStreamTexture2D::handles_type(const String &p_type) con } String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "stex") + if (p_path.get_extension().to_lower() == "stex") { return "StreamTexture2D"; + } return ""; } @@ -777,8 +795,9 @@ String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_pa int AtlasTexture::get_width() const { if (region.size.width == 0) { - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->get_width(); + } return 1; } else { return region.size.width + margin.size.width; @@ -787,8 +806,9 @@ int AtlasTexture::get_width() const { int AtlasTexture::get_height() const { if (region.size.height == 0) { - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->get_height(); + } return 1; } else { return region.size.height + margin.size.height; @@ -796,23 +816,26 @@ int AtlasTexture::get_height() const { } RID AtlasTexture::get_rid() const { - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->get_rid(); + } return RID(); } bool AtlasTexture::has_alpha() const { - if (atlas.is_valid()) + if (atlas.is_valid()) { return atlas->has_alpha(); + } return false; } void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) { ERR_FAIL_COND(p_atlas == this); - if (atlas == p_atlas) + if (atlas == p_atlas) { return; + } atlas = p_atlas; emit_changed(); _change_notify("atlas"); @@ -823,8 +846,9 @@ Ref<Texture2D> AtlasTexture::get_atlas() const { } void AtlasTexture::set_region(const Rect2 &p_region) { - if (region == p_region) + if (region == p_region) { return; + } region = p_region; emit_changed(); _change_notify("region"); @@ -835,8 +859,9 @@ Rect2 AtlasTexture::get_region() const { } void AtlasTexture::set_margin(const Rect2 &p_margin) { - if (margin == p_margin) + if (margin == p_margin) { return; + } margin = p_margin; emit_changed(); _change_notify("margin"); @@ -876,8 +901,9 @@ void AtlasTexture::_bind_methods() { } void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return; + } Rect2 rc = region; @@ -895,8 +921,9 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m } void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return; + } Rect2 rc = region; @@ -918,8 +945,9 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { //this might not necessarily work well if using a rect, needs to be fixed properly - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return; + } Rect2 dr; Rect2 src_c; @@ -931,8 +959,9 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons } bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return false; + } Rect2 rc = region; @@ -944,8 +973,9 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, src.position += (rc.position - margin.position); Rect2 src_c = rc.clip(src); - if (src_c.size == Size2()) + if (src_c.size == Size2()) { return false; + } Vector2 ofs = (src_c.position - src.position); if (scale.x < 0) { @@ -966,17 +996,20 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, } bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const { - if (!atlas.is_valid()) + if (!atlas.is_valid()) { return true; + } int x = p_x + region.position.x - margin.position.x; int y = p_y + region.position.y - margin.position.y; // margin edge may outside of atlas - if (x < 0 || x >= atlas->get_width()) + if (x < 0 || x >= atlas->get_width()) { return false; - if (y < 0 || y >= atlas->get_height()) + } + if (y < 0 || y >= atlas->get_height()) { return false; + } return atlas->is_pixel_opaque(x, y); } @@ -1132,8 +1165,9 @@ RID LargeTexture::get_rid() const { bool LargeTexture::has_alpha() const { for (int i = 0; i < pieces.size(); i++) { - if (pieces[i].texture->has_alpha()) + if (pieces[i].texture->has_alpha()) { return true; + } } return false; @@ -1240,8 +1274,9 @@ void LargeTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat) const { //tiling not supported for this - if (size.x == 0 || size.y == 0) + if (size.x == 0 || size.y == 0) { return; + } Size2 scale = p_rect.size / size; @@ -1253,16 +1288,18 @@ void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture2D> &p_normal_map, const Ref<Texture2D> &p_specular_map, const Color &p_specular_color_shininess, RS::CanvasItemTextureFilter p_texture_filter, RS::CanvasItemTextureRepeat p_texture_repeat, bool p_clip_uv) const { //tiling not supported for this - if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0) + if (p_src_rect.size.x == 0 || p_src_rect.size.y == 0) { return; + } Size2 scale = p_rect.size / p_src_rect.size; for (int i = 0; i < pieces.size(); i++) { // TODO Rect2 rect(pieces[i].offset, pieces[i].texture->get_size()); - if (!p_src_rect.intersects(rect)) + if (!p_src_rect.intersects(rect)) { continue; + } Rect2 local = p_src_rect.clip(rect); Rect2 target = local; target.size *= scale; @@ -1275,8 +1312,9 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons bool LargeTexture::is_pixel_opaque(int p_x, int p_y) const { for (int i = 0; i < pieces.size(); i++) { // TODO - if (!pieces[i].texture.is_valid()) + if (!pieces[i].texture.is_valid()) { continue; + } Rect2 rect(pieces[i].offset, pieces[i].texture->get_size()); if (rect.has_point(Point2(p_x, p_y))) { @@ -1429,8 +1467,9 @@ void GradientTexture::_bind_methods() { } void GradientTexture::set_gradient(Ref<Gradient> p_gradient) { - if (p_gradient == gradient) + if (p_gradient == gradient) { return; + } if (gradient.is_valid()) { gradient->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &GradientTexture::_update)); } @@ -1447,8 +1486,9 @@ Ref<Gradient> GradientTexture::get_gradient() const { } void GradientTexture::_queue_update() { - if (update_pending) + if (update_pending) { return; + } update_pending = true; call_deferred("_update"); @@ -1457,8 +1497,9 @@ void GradientTexture::_queue_update() { void GradientTexture::_update() { update_pending = false; - if (gradient.is_null()) + if (gradient.is_null()) { return; + } Vector<uint8_t> data; data.resize(width * 4); @@ -1536,14 +1577,16 @@ Ref<Texture2D> ProxyTexture::get_base() const { } int ProxyTexture::get_width() const { - if (base.is_valid()) + if (base.is_valid()) { return base->get_width(); + } return 1; } int ProxyTexture::get_height() const { - if (base.is_valid()) + if (base.is_valid()) { return base->get_height(); + } return 1; } @@ -1556,8 +1599,9 @@ RID ProxyTexture::get_rid() const { } bool ProxyTexture::has_alpha() const { - if (base.is_valid()) + if (base.is_valid()) { return base->has_alpha(); + } return false; } @@ -2061,8 +2105,9 @@ Error StreamTextureLayered::load(const String &p_path) { int mipmap_limit; Error err = _load_data(p_path, images, mipmap_limit); - if (err) + if (err) { return err; + } if (texture.is_valid()) { RID new_texture = RS::get_singleton()->texture_2d_layered_create(images, RS::TextureLayeredType(layered_type)); @@ -2130,13 +2175,15 @@ Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const { void StreamTextureLayered::reload_from_file() { String path = get_path(); - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } path = ResourceLoader::path_remap(path); //remap for translation path = ResourceLoader::import_remap(path); //remap for import - if (!path.is_resource_file()) + if (!path.is_resource_file()) { return; + } load(path); } @@ -2189,10 +2236,12 @@ RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const S return RES(); } Error err = st->load(p_path); - if (r_error) + if (r_error) { *r_error = err; - if (err != OK) + } + if (err != OK) { return RES(); + } return st; } @@ -2208,12 +2257,15 @@ bool ResourceFormatLoaderStreamTextureLayered::handles_type(const String &p_type } String ResourceFormatLoaderStreamTextureLayered::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "stexarray") + if (p_path.get_extension().to_lower() == "stexarray") { return "StreamTexture2DArray"; - if (p_path.get_extension().to_lower() == "scube") + } + if (p_path.get_extension().to_lower() == "scube") { return "StreamCubemap"; - if (p_path.get_extension().to_lower() == "scubearray") + } + if (p_path.get_extension().to_lower() == "scubearray") { return "StreamCubemapArray"; + } return ""; } diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 7a2abffed0..6a85d357ff 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -159,8 +159,9 @@ bool Theme::_set(const StringName &p_name, const Variant &p_value) { set_color(name, node_type, p_value); } else if (type == "constants") { set_constant(name, node_type, p_value); - } else + } else { return false; + } return true; } @@ -177,26 +178,30 @@ bool Theme::_get(const StringName &p_name, Variant &r_ret) const { String name = sname.get_slicec('/', 2); if (type == "icons") { - if (!has_icon(name, node_type)) + if (!has_icon(name, node_type)) { r_ret = Ref<Texture2D>(); - else + } else { r_ret = get_icon(name, node_type); + } } else if (type == "styles") { - if (!has_stylebox(name, node_type)) + if (!has_stylebox(name, node_type)) { r_ret = Ref<StyleBox>(); - else + } else { r_ret = get_stylebox(name, node_type); + } } else if (type == "fonts") { - if (!has_font(name, node_type)) + if (!has_font(name, node_type)) { r_ret = Ref<Font>(); - else + } else { r_ret = get_font(name, node_type); + } } else if (type == "colors") { r_ret = get_color(name, node_type); } else if (type == "constants") { r_ret = get_constant(name, node_type); - } else + } else { return false; + } return true; } @@ -264,8 +269,9 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { } void Theme::set_default_theme_font(const Ref<Font> &p_default_font) { - if (default_theme_font == p_default_font) + if (default_theme_font == p_default_font) { return; + } if (default_theme_font.is_valid()) { default_theme_font->disconnect("changed", callable_mp(this, &Theme::_emit_theme_changed)); @@ -369,8 +375,9 @@ void Theme::clear_icon(const StringName &p_name, const StringName &p_type) { void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - if (!icon_map.has(p_type)) + if (!icon_map.has(p_type)) { return; + } const StringName *key = nullptr; @@ -414,8 +421,9 @@ void Theme::clear_shader(const StringName &p_name, const StringName &p_type) { void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - if (!shader_map.has(p_type)) + if (!shader_map.has(p_type)) { return; + } const StringName *key = nullptr; @@ -439,8 +447,9 @@ void Theme::set_stylebox(const StringName &p_name, const StringName &p_type, con style_map[p_type][p_name]->connect("changed", callable_mp(this, &Theme::_emit_theme_changed), varray(), CONNECT_REFERENCE_COUNTED); } - if (new_value) + if (new_value) { _change_notify(); + } emit_changed(); } @@ -473,8 +482,9 @@ void Theme::clear_stylebox(const StringName &p_name, const StringName &p_type) { void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - if (!style_map.has(p_type)) + if (!style_map.has(p_type)) { return; + } const StringName *key = nullptr; @@ -514,12 +524,13 @@ void Theme::set_font(const StringName &p_name, const StringName &p_type, const R } Ref<Font> Theme::get_font(const StringName &p_name, const StringName &p_type) const { - if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) + if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) { return font_map[p_type][p_name]; - else if (default_theme_font.is_valid()) + } else if (default_theme_font.is_valid()) { return default_theme_font; - else + } else { return default_font; + } } bool Theme::has_font(const StringName &p_name, const StringName &p_type) const { @@ -542,8 +553,9 @@ void Theme::clear_font(const StringName &p_name, const StringName &p_type) { void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - if (!font_map.has(p_type)) + if (!font_map.has(p_type)) { return; + } const StringName *key = nullptr; @@ -564,10 +576,11 @@ void Theme::set_color(const StringName &p_name, const StringName &p_type, const } Color Theme::get_color(const StringName &p_name, const StringName &p_type) const { - if (color_map.has(p_type) && color_map[p_type].has(p_name)) + if (color_map.has(p_type) && color_map[p_type].has(p_name)) { return color_map[p_type][p_name]; - else + } else { return Color(); + } } bool Theme::has_color(const StringName &p_name, const StringName &p_type) const { @@ -586,8 +599,9 @@ void Theme::clear_color(const StringName &p_name, const StringName &p_type) { void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - if (!color_map.has(p_type)) + if (!color_map.has(p_type)) { return; + } const StringName *key = nullptr; @@ -607,9 +621,9 @@ void Theme::set_constant(const StringName &p_name, const StringName &p_type, int } int Theme::get_constant(const StringName &p_name, const StringName &p_type) const { - if (constant_map.has(p_type) && constant_map[p_type].has(p_name)) + if (constant_map.has(p_type) && constant_map[p_type].has(p_name)) { return constant_map[p_type][p_name]; - else { + } else { return 0; } } @@ -630,8 +644,9 @@ void Theme::clear_constant(const StringName &p_name, const StringName &p_type) { void Theme::get_constant_list(StringName p_type, List<StringName> *p_list) const { ERR_FAIL_NULL(p_list); - if (!constant_map.has(p_type)) + if (!constant_map.has(p_type)) { return; + } const StringName *key = nullptr; diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 38e50e35f1..c17b6f8817 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -35,47 +35,50 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { String n = p_name; int slash = n.find("/"); - if (slash == -1) + if (slash == -1) { return false; + } int id = String::to_int(n.c_str(), slash); - if (!tile_map.has(id)) + if (!tile_map.has(id)) { create_tile(id); + } String what = n.substr(slash + 1, n.length()); - if (what == "name") + if (what == "name") { tile_set_name(id, p_value); - else if (what == "texture") + } else if (what == "texture") { tile_set_texture(id, p_value); - else if (what == "normal_map") + } else if (what == "normal_map") { tile_set_normal_map(id, p_value); - else if (what == "tex_offset") + } else if (what == "tex_offset") { tile_set_texture_offset(id, p_value); - else if (what == "material") + } else if (what == "material") { tile_set_material(id, p_value); - else if (what == "modulate") + } else if (what == "modulate") { tile_set_modulate(id, p_value); - else if (what == "region") + } else if (what == "region") { tile_set_region(id, p_value); - else if (what == "tile_mode") + } else if (what == "tile_mode") { tile_set_tile_mode(id, (TileMode)((int)p_value)); - else if (what == "is_autotile") { + } else if (what == "is_autotile") { // backward compatibility for Godot 3.0.x // autotile used to be a bool, it's now an enum bool is_autotile = p_value; - if (is_autotile) + if (is_autotile) { tile_set_tile_mode(id, AUTO_TILE); + } } else if (what.left(9) == "autotile/") { what = what.right(9); - if (what == "bitmask_mode") + if (what == "bitmask_mode") { autotile_set_bitmask_mode(id, (BitmaskMode)((int)p_value)); - else if (what == "icon_coordinate") + } else if (what == "icon_coordinate") { autotile_set_icon_coordinate(id, p_value); - else if (what == "tile_size") + } else if (what == "tile_size") { autotile_set_size(id, p_value); - else if (what == "spacing") + } else if (what == "spacing") { autotile_set_spacing(id, p_value); - else if (what == "bitmask_flags") { + } else if (what == "bitmask_flags") { tile_map[id].autotile_data.flags.clear(); if (p_value.is_array()) { Array p = p_value; @@ -146,7 +149,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { p.pop_front(); } } - } else if (what == "shape") + } else if (what == "shape") { if (tile_get_shape_count(id) > 0) { for (int i = 0; i < tile_get_shape_count(id); i++) { tile_set_shape(id, i, p_value); @@ -154,7 +157,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } else { tile_set_shape(id, 0, p_value); } - else if (what == "shape_offset") + } else if (what == "shape_offset") { if (tile_get_shape_count(id) > 0) { for (int i = 0; i < tile_get_shape_count(id); i++) { tile_set_shape_offset(id, i, p_value); @@ -162,7 +165,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } else { tile_set_shape_offset(id, 0, p_value); } - else if (what == "shape_transform") + } else if (what == "shape_transform") { if (tile_get_shape_count(id) > 0) { for (int i = 0; i < tile_get_shape_count(id); i++) { tile_set_shape_transform(id, i, p_value); @@ -170,7 +173,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } else { tile_set_shape_transform(id, 0, p_value); } - else if (what == "shape_one_way") + } else if (what == "shape_one_way") { if (tile_get_shape_count(id) > 0) { for (int i = 0; i < tile_get_shape_count(id); i++) { tile_set_shape_one_way(id, i, p_value); @@ -178,7 +181,7 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } else { tile_set_shape_one_way(id, 0, p_value); } - else if (what == "shape_one_way_margin") + } else if (what == "shape_one_way_margin") { if (tile_get_shape_count(id) > 0) { for (int i = 0; i < tile_get_shape_count(id); i++) { tile_set_shape_one_way_margin(id, i, p_value); @@ -186,20 +189,21 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } else { tile_set_shape_one_way_margin(id, 0, p_value); } - else if (what == "shapes") + } else if (what == "shapes") { _tile_set_shapes(id, p_value); - else if (what == "occluder") + } else if (what == "occluder") { tile_set_light_occluder(id, p_value); - else if (what == "occluder_offset") + } else if (what == "occluder_offset") { tile_set_occluder_offset(id, p_value); - else if (what == "navigation") + } else if (what == "navigation") { tile_set_navigation_polygon(id, p_value); - else if (what == "navigation_offset") + } else if (what == "navigation_offset") { tile_set_navigation_polygon_offset(id, p_value); - else if (what == "z_index") + } else if (what == "z_index") { tile_set_z_index(id, p_value); - else + } else { return false; + } return true; } @@ -207,41 +211,42 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { String n = p_name; int slash = n.find("/"); - if (slash == -1) + if (slash == -1) { return false; + } int id = String::to_int(n.c_str(), slash); ERR_FAIL_COND_V(!tile_map.has(id), false); String what = n.substr(slash + 1, n.length()); - if (what == "name") + if (what == "name") { r_ret = tile_get_name(id); - else if (what == "texture") + } else if (what == "texture") { r_ret = tile_get_texture(id); - else if (what == "normal_map") + } else if (what == "normal_map") { r_ret = tile_get_normal_map(id); - else if (what == "tex_offset") + } else if (what == "tex_offset") { r_ret = tile_get_texture_offset(id); - else if (what == "material") + } else if (what == "material") { r_ret = tile_get_material(id); - else if (what == "modulate") + } else if (what == "modulate") { r_ret = tile_get_modulate(id); - else if (what == "region") + } else if (what == "region") { r_ret = tile_get_region(id); - else if (what == "tile_mode") + } else if (what == "tile_mode") { r_ret = tile_get_tile_mode(id); - else if (what.left(9) == "autotile/") { + } else if (what.left(9) == "autotile/") { what = what.right(9); - if (what == "bitmask_mode") + if (what == "bitmask_mode") { r_ret = autotile_get_bitmask_mode(id); - else if (what == "icon_coordinate") + } else if (what == "icon_coordinate") { r_ret = autotile_get_icon_coordinate(id); - else if (what == "tile_size") + } else if (what == "tile_size") { r_ret = autotile_get_size(id); - else if (what == "spacing") + } else if (what == "spacing") { r_ret = autotile_get_spacing(id); - else if (what == "bitmask_flags") { + } else if (what == "bitmask_flags") { Array p; for (Map<Vector2, uint32_t>::Element *E = tile_map[id].autotile_data.flags.front(); E; E = E->next()) { p.push_back(E->key()); @@ -289,30 +294,31 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { } r_ret = p; } - } else if (what == "shape") + } else if (what == "shape") { r_ret = tile_get_shape(id, 0); - else if (what == "shape_offset") + } else if (what == "shape_offset") { r_ret = tile_get_shape_offset(id, 0); - else if (what == "shape_transform") + } else if (what == "shape_transform") { r_ret = tile_get_shape_transform(id, 0); - else if (what == "shape_one_way") + } else if (what == "shape_one_way") { r_ret = tile_get_shape_one_way(id, 0); - else if (what == "shape_one_way_margin") + } else if (what == "shape_one_way_margin") { r_ret = tile_get_shape_one_way_margin(id, 0); - else if (what == "shapes") + } else if (what == "shapes") { r_ret = _tile_get_shapes(id); - else if (what == "occluder") + } else if (what == "occluder") { r_ret = tile_get_light_occluder(id); - else if (what == "occluder_offset") + } else if (what == "occluder_offset") { r_ret = tile_get_occluder_offset(id); - else if (what == "navigation") + } else if (what == "navigation") { r_ret = tile_get_navigation_polygon(id); - else if (what == "navigation_offset") + } else if (what == "navigation_offset") { r_ret = tile_get_navigation_polygon_offset(id); - else if (what == "z_index") + } else if (what == "z_index") { r_ret = tile_get_z_index(id); - else + } else { return false; + } return true; } @@ -547,8 +553,9 @@ const Map<Vector2, int> &TileSet::autotile_get_z_index_map(int p_id) const { void TileSet::autotile_set_bitmask(int p_id, Vector2 p_coord, uint32_t p_flag) { ERR_FAIL_COND(!tile_map.has(p_id)); if (p_flag == 0) { - if (tile_map[p_id].autotile_data.flags.has(p_coord)) + if (tile_map[p_id].autotile_data.flags.has(p_coord)) { tile_map[p_id].autotile_data.flags.erase(p_coord); + } } else { tile_map[p_id].autotile_data.flags[p_coord] = p_flag; } @@ -577,8 +584,9 @@ const Map<Vector2, uint32_t> &TileSet::autotile_get_bitmask_map(int p_id) { } } return dummy_atlas; - } else + } else { return tile_map[p_id].autotile_data.flags; + } } Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) { @@ -709,8 +717,9 @@ 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)); ERR_FAIL_COND(p_shape_id < 0); - if (p_shape_id >= tile_map[p_id].shapes_data.size()) + if (p_shape_id >= tile_map[p_id].shapes_data.size()) { tile_map[p_id].shapes_data.resize(p_shape_id + 1); + } tile_map[p_id].shapes_data.write[p_shape_id].shape = p_shape; _decompose_convex_shape(p_shape); emit_changed(); @@ -720,8 +729,9 @@ Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Shape2D>()); ERR_FAIL_COND_V(p_shape_id < 0, Ref<Shape2D>()); - if (p_shape_id < tile_map[p_id].shapes_data.size()) + if (p_shape_id < tile_map[p_id].shapes_data.size()) { return tile_map[p_id].shapes_data[p_shape_id].shape; + } return Ref<Shape2D>(); } @@ -730,8 +740,9 @@ void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_shape_id < 0); - if (p_shape_id >= tile_map[p_id].shapes_data.size()) + if (p_shape_id >= tile_map[p_id].shapes_data.size()) { tile_map[p_id].shapes_data.resize(p_shape_id + 1); + } tile_map[p_id].shapes_data.write[p_shape_id].shape_transform = p_offset; emit_changed(); } @@ -740,8 +751,9 @@ Transform2D TileSet::tile_get_shape_transform(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), Transform2D()); ERR_FAIL_COND_V(p_shape_id < 0, Transform2D()); - if (p_shape_id < tile_map[p_id].shapes_data.size()) + if (p_shape_id < tile_map[p_id].shapes_data.size()) { return tile_map[p_id].shapes_data[p_shape_id].shape_transform; + } return Transform2D(); } @@ -760,8 +772,9 @@ 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)); ERR_FAIL_COND(p_shape_id < 0); - if (p_shape_id >= tile_map[p_id].shapes_data.size()) + if (p_shape_id >= tile_map[p_id].shapes_data.size()) { tile_map[p_id].shapes_data.resize(p_shape_id + 1); + } tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision = p_one_way; emit_changed(); } @@ -770,8 +783,9 @@ bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), false); ERR_FAIL_COND_V(p_shape_id < 0, false); - if (p_shape_id < tile_map[p_id].shapes_data.size()) + if (p_shape_id < tile_map[p_id].shapes_data.size()) { return tile_map[p_id].shapes_data[p_shape_id].one_way_collision; + } return false; } @@ -780,8 +794,9 @@ void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_ma ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_shape_id < 0); - if (p_shape_id >= tile_map[p_id].shapes_data.size()) + if (p_shape_id >= tile_map[p_id].shapes_data.size()) { tile_map[p_id].shapes_data.resize(p_shape_id + 1); + } tile_map[p_id].shapes_data.write[p_shape_id].one_way_collision_margin = p_margin; emit_changed(); } @@ -790,8 +805,9 @@ float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const { ERR_FAIL_COND_V(!tile_map.has(p_id), 0); ERR_FAIL_COND_V(p_shape_id < 0, 0); - if (p_shape_id < tile_map[p_id].shapes_data.size()) + if (p_shape_id < tile_map[p_id].shapes_data.size()) { return tile_map[p_id].shapes_data[p_shape_id].one_way_collision_margin; + } return 0; } @@ -926,8 +942,9 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { if (p_shapes[i].get_type() == Variant::OBJECT) { Ref<Shape2D> shape = p_shapes[i]; - if (shape.is_null()) + if (shape.is_null()) { continue; + } s.shape = shape; s.shape_transform = default_transform; @@ -939,30 +956,35 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT) { s.shape = d["shape"]; _decompose_convex_shape(s.shape); - } else + } else { continue; + } - if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D) + if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D) { s.shape_transform = d["shape_transform"]; - else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2) + } else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2) { s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]); - else + } else { s.shape_transform = default_transform; + } - if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL) + if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL) { s.one_way_collision = d["one_way"]; - else + } else { s.one_way_collision = default_one_way; + } - if (d.has("one_way_margin") && d["one_way_margin"].is_num()) + if (d.has("one_way_margin") && d["one_way_margin"].is_num()) { s.one_way_collision_margin = d["one_way_margin"]; - else + } else { s.one_way_collision_margin = 1.0; + } - if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2) + if (d.has("autotile_coord") && d["autotile_coord"].get_type() == Variant::VECTOR2) { s.autotile_coord = d["autotile_coord"]; - else + } else { s.autotile_coord = default_autotile_coord; + } } else { ERR_CONTINUE_MSG(true, "Expected an array of objects or dictionaries for tile_set_shapes."); @@ -1004,11 +1026,13 @@ Array TileSet::_get_tiles_ids() const { } void TileSet::_decompose_convex_shape(Ref<Shape2D> p_shape) { - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint()) { return; + } Ref<ConvexPolygonShape2D> convex = p_shape; - if (!convex.is_valid()) + if (!convex.is_valid()) { return; + } Vector<Vector<Vector2>> decomp = Geometry::decompose_polygon_in_convex(convex->get_points()); if (decomp.size() > 1) { Array sub_shapes; @@ -1055,16 +1079,18 @@ void TileSet::remove_tile(int p_id) { } int TileSet::get_last_unused_tile_id() const { - if (tile_map.size()) + if (tile_map.size()) { return tile_map.back()->key() + 1; - else + } else { return 0; + } } int TileSet::find_tile_by_name(const String &p_name) const { for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) { - if (p_name == E->get().name) + if (p_name == E->get().name) { return E->key(); + } } return -1; } diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 5faa256abd..77d4dee21e 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -400,8 +400,9 @@ int VisualShader::get_valid_node_id(Type p_type) const { int VisualShader::find_node_id(Type p_type, const Ref<VisualShaderNode> &p_node) const { for (const Map<int, Node>::Element *E = graph[p_type].nodes.front(); E; E = E->next()) { - if (E->get().node == p_node) + if (E->get().node == p_node) { return E->key(); + } } return NODE_ID_INVALID; @@ -471,20 +472,25 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po ERR_FAIL_INDEX_V(p_type, TYPE_MAX, false); const Graph *g = &graph[p_type]; - if (!g->nodes.has(p_from_node)) + if (!g->nodes.has(p_from_node)) { return false; + } - if (p_from_node == p_to_node) + if (p_from_node == p_to_node) { return false; + } - if (p_from_port < 0 || p_from_port >= g->nodes[p_from_node].node->get_output_port_count()) + if (p_from_port < 0 || p_from_port >= g->nodes[p_from_node].node->get_output_port_count()) { return false; + } - if (!g->nodes.has(p_to_node)) + if (!g->nodes.has(p_to_node)) { return false; + } - if (p_to_port < 0 || p_to_port >= g->nodes[p_to_node].node->get_input_port_count()) + if (p_to_port < 0 || p_to_port >= g->nodes[p_to_node].node->get_input_port_count()) { return false; + } VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port); VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port); @@ -499,8 +505,9 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po } } - if (is_nodes_connected_relatively(g, p_from_node, p_to_node)) + if (is_nodes_connected_relatively(g, p_from_node, p_to_node)) { return false; + } return true; } @@ -1090,8 +1097,9 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui } Error err = _write_node(type, global_code, global_code_per_node, global_code_per_func, code, def_tex_params, input_connections, output_connections, from_node, processed, for_preview, r_classes); - if (err) + if (err) { return err; + } } } @@ -1280,8 +1288,9 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui } void VisualShader::_update_shader() const { - if (!dirty) + if (!dirty) { return; + } dirty = false; @@ -2207,8 +2216,9 @@ Vector2 VisualShaderNodeGroupBase::get_size() const { } void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) { - if (inputs == p_inputs) + if (inputs == p_inputs) { return; + } clear_input_ports(); @@ -2238,8 +2248,9 @@ String VisualShaderNodeGroupBase::get_inputs() const { } void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) { - if (outputs == p_outputs) + if (outputs == p_outputs) { return; + } clear_output_ports(); @@ -2433,8 +2444,9 @@ void VisualShaderNodeGroupBase::set_input_port_type(int p_id, int p_type) { ERR_FAIL_COND(!has_input_port(p_id)); ERR_FAIL_COND(p_type < 0 || p_type >= PORT_TYPE_MAX); - if (input_ports[p_id].type == p_type) + if (input_ports[p_id].type == p_type) { return; + } Vector<String> inputs_strings = inputs.split(";", false); int count = 0; @@ -2467,8 +2479,9 @@ void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_na ERR_FAIL_COND(!has_input_port(p_id)); ERR_FAIL_COND(!is_valid_port_name(p_name)); - if (input_ports[p_id].name == p_name) + if (input_ports[p_id].name == p_name) { return; + } Vector<String> inputs_strings = inputs.split(";", false); int count = 0; @@ -2501,8 +2514,9 @@ void VisualShaderNodeGroupBase::set_output_port_type(int p_id, int p_type) { ERR_FAIL_COND(!has_output_port(p_id)); ERR_FAIL_COND(p_type < 0 || p_type >= PORT_TYPE_MAX); - if (output_ports[p_id].type == p_type) + if (output_ports[p_id].type == p_type) { return; + } Vector<String> output_strings = outputs.split(";", false); int count = 0; @@ -2535,8 +2549,9 @@ void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_n ERR_FAIL_COND(!has_output_port(p_id)); ERR_FAIL_COND(!is_valid_port_name(p_name)); - if (output_ports[p_id].name == p_name) + if (output_ports[p_id].name == p_name) { return; + } Vector<String> output_strings = outputs.split(";", false); int count = 0; diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index b89f069211..87720cf110 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -441,14 +441,16 @@ int VisualShaderNodeTexture::get_output_port_count() const { } VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_output_port_type(int p_port) const { - if (p_port == 0 && source == SOURCE_DEPTH) + if (p_port == 0 && source == SOURCE_DEPTH) { return PORT_TYPE_SCALAR; + } return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR; } String VisualShaderNodeTexture::get_output_port_name(int p_port) const { - if (p_port == 0 && source == SOURCE_DEPTH) + if (p_port == 0 && source == SOURCE_DEPTH) { return "depth"; + } return p_port == 0 ? "rgb" : "alpha"; } @@ -2429,12 +2431,13 @@ VisualShaderNodeScalarClamp::PortType VisualShaderNodeScalarClamp::get_input_por } String VisualShaderNodeScalarClamp::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return ""; - else if (p_port == 1) + } else if (p_port == 1) { return "min"; - else if (p_port == 2) + } else if (p_port == 2) { return "max"; + } return ""; } @@ -2475,12 +2478,13 @@ VisualShaderNodeVectorClamp::PortType VisualShaderNodeVectorClamp::get_input_por } String VisualShaderNodeVectorClamp::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return ""; - else if (p_port == 1) + } else if (p_port == 1) { return "min"; - else if (p_port == 2) + } else if (p_port == 2) { return "max"; + } return ""; } @@ -2619,10 +2623,11 @@ VisualShaderNodeVectorScalarStep::PortType VisualShaderNodeVectorScalarStep::get } String VisualShaderNodeVectorScalarStep::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "edge"; - else if (p_port == 1) + } else if (p_port == 1) { return "x"; + } return ""; } @@ -2662,12 +2667,13 @@ VisualShaderNodeScalarSmoothStep::PortType VisualShaderNodeScalarSmoothStep::get } String VisualShaderNodeScalarSmoothStep::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "edge0"; - else if (p_port == 1) + } else if (p_port == 1) { return "edge1"; - else if (p_port == 2) + } else if (p_port == 2) { return "x"; + } return ""; } @@ -2708,12 +2714,13 @@ VisualShaderNodeVectorSmoothStep::PortType VisualShaderNodeVectorSmoothStep::get } String VisualShaderNodeVectorSmoothStep::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "edge0"; - else if (p_port == 1) + } else if (p_port == 1) { return "edge1"; - else if (p_port == 2) + } else if (p_port == 2) { return "x"; + } return ""; } @@ -2759,12 +2766,13 @@ VisualShaderNodeVectorScalarSmoothStep::PortType VisualShaderNodeVectorScalarSmo } String VisualShaderNodeVectorScalarSmoothStep::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "edge0"; - else if (p_port == 1) + } else if (p_port == 1) { return "edge1"; - else if (p_port == 2) + } else if (p_port == 2) { return "x"; + } return ""; } @@ -2988,8 +2996,9 @@ int VisualShaderNodeVectorScalarMix::get_input_port_count() const { } VisualShaderNodeVectorScalarMix::PortType VisualShaderNodeVectorScalarMix::get_input_port_type(int p_port) const { - if (p_port == 2) + if (p_port == 2) { return PORT_TYPE_SCALAR; + } return PORT_TYPE_VECTOR; } @@ -3705,16 +3714,18 @@ String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, Visu switch (texture_type) { case TYPE_DATA: - if (color_default == COLOR_DEFAULT_BLACK) + if (color_default == COLOR_DEFAULT_BLACK) { code += " : hint_black;\n"; - else + } else { code += ";\n"; + } break; case TYPE_COLOR: - if (color_default == COLOR_DEFAULT_BLACK) + if (color_default == COLOR_DEFAULT_BLACK) { code += " : hint_black_albedo;\n"; - else + } else { code += " : hint_albedo;\n"; + } break; case TYPE_NORMALMAP: code += " : hint_normal;\n"; @@ -3954,16 +3965,18 @@ String VisualShaderNodeCubemapUniform::generate_global(Shader::Mode p_mode, Visu switch (texture_type) { case TYPE_DATA: - if (color_default == COLOR_DEFAULT_BLACK) + if (color_default == COLOR_DEFAULT_BLACK) { code += " : hint_black;\n"; - else + } else { code += ";\n"; + } break; case TYPE_COLOR: - if (color_default == COLOR_DEFAULT_BLACK) + if (color_default == COLOR_DEFAULT_BLACK) { code += " : hint_black_albedo;\n"; - else + } else { code += " : hint_albedo;\n"; + } break; case TYPE_NORMALMAP: code += " : hint_normal;\n"; @@ -4311,8 +4324,9 @@ int VisualShaderNodeCompare::get_input_port_count() const { } VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(int p_port) const { - if (p_port == 2) + if (p_port == 2) { return PORT_TYPE_SCALAR; + } switch (ctype) { case CTYPE_SCALAR: return PORT_TYPE_SCALAR; @@ -4329,12 +4343,13 @@ VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(i } String VisualShaderNodeCompare::get_input_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "a"; - else if (p_port == 1) + } else if (p_port == 1) { return "b"; - else if (p_port == 2) + } else if (p_port == 2) { return "tolerance"; + } return ""; } @@ -4347,8 +4362,9 @@ VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_output_port_type( } String VisualShaderNodeCompare::get_output_port_name(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "result"; + } return ""; } @@ -4410,14 +4426,16 @@ String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader: break; case CTYPE_BOOLEAN: - if (func > FUNC_NOT_EQUAL) + if (func > FUNC_NOT_EQUAL) { return "\t" + p_output_vars[0] + " = false;\n"; + } code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; break; case CTYPE_TRANSFORM: - if (func > FUNC_NOT_EQUAL) + if (func > FUNC_NOT_EQUAL) { return "\t" + p_output_vars[0] + " = false;\n"; + } code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; break; @@ -4486,8 +4504,9 @@ Vector<StringName> VisualShaderNodeCompare::get_editable_properties() const { Vector<StringName> props; props.push_back("type"); props.push_back("function"); - if (ctype == CTYPE_VECTOR) + if (ctype == CTYPE_VECTOR) { props.push_back("condition"); + } return props; } diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 368a9d351d..1c753fdb91 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -103,8 +103,9 @@ struct SpatialIndexer2D { Map<CellKey, CellData>::Element *E = cells.find(ck); if (p_add) { - if (!E) + if (!E) { E = cells.insert(ck, CellData()); + } E->get().notifiers[p_notifier].inc(); } else { ERR_CONTINUE(!E); @@ -129,8 +130,9 @@ struct SpatialIndexer2D { void _notifier_update(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect) { Map<VisibilityNotifier2D *, Rect2>::Element *E = notifiers.find(p_notifier); ERR_FAIL_COND(!E); - if (E->get() == p_rect) + if (E->get() == p_rect) { return; + } _notifier_update_cells(p_notifier, p_rect, true); _notifier_update_cells(p_notifier, E->get(), false); @@ -173,8 +175,9 @@ struct SpatialIndexer2D { void _update_viewport(Viewport *p_viewport, const Rect2 &p_rect) { Map<Viewport *, ViewportData>::Element *E = viewports.find(p_viewport); ERR_FAIL_COND(!E); - if (E->get().rect == p_rect) + if (E->get().rect == p_rect) { return; + } E->get().rect = p_rect; changed = true; } @@ -195,8 +198,9 @@ struct SpatialIndexer2D { } void _update() { - if (!changed) + if (!changed) { return; + } for (Map<Viewport *, ViewportData>::Element *E = viewports.front(); E; E = E->next()) { Point2i begin = E->get().rect.position; @@ -215,10 +219,12 @@ struct SpatialIndexer2D { for (Map<CellKey, CellData>::Element *F = cells.front(); F; F = F->next()) { const CellKey &ck = F->key(); - if (ck.x < begin.x || ck.x > end.x) + if (ck.x < begin.x || ck.x > end.x) { continue; - if (ck.y < begin.y || ck.y > end.y) + } + if (ck.y < begin.y || ck.y > end.y) { continue; + } //notifiers in cell for (Map<VisibilityNotifier2D *, CellRef>::Element *G = F->get().notifiers.front(); G; G = G->next()) { @@ -260,8 +266,9 @@ struct SpatialIndexer2D { } for (Map<VisibilityNotifier2D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) { - if (F->get() != pass) + if (F->get() != pass) { removed.push_back(F->key()); + } } while (!added.empty()) { diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp index f53a24596a..8100f150ef 100644 --- a/scene/resources/world_3d.cpp +++ b/scene/resources/world_3d.cpp @@ -71,8 +71,9 @@ struct SpatialIndexer { void _notifier_update(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier); ERR_FAIL_COND(!E); - if (E->get().aabb == p_rect) + if (E->get().aabb == p_rect) { return; + } E->get().aabb = p_rect; octree.move(E->get().id, E->get().aabb); @@ -133,12 +134,14 @@ struct SpatialIndexer { } void _update(uint64_t p_frame) { - if (p_frame == last_frame) + if (p_frame == last_frame) { return; + } last_frame = p_frame; - if (!changed) + if (!changed) { return; + } for (Map<Camera3D *, CameraData>::Element *E = cameras.front(); E; E = E->next()) { pass++; @@ -167,8 +170,9 @@ struct SpatialIndexer { } for (Map<VisibilityNotifier3D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) { - if (F->get() != pass) + if (F->get() != pass) { removed.push_back(F->key()); + } } while (!added.empty()) { @@ -249,10 +253,11 @@ void World3D::set_environment(const Ref<Environment> &p_environment) { } environment = p_environment; - if (environment.is_valid()) + if (environment.is_valid()) { RS::get_singleton()->scenario_set_environment(scenario, environment->get_rid()); - else + } else { RS::get_singleton()->scenario_set_environment(scenario, RID()); + } emit_changed(); } @@ -267,10 +272,11 @@ void World3D::set_fallback_environment(const Ref<Environment> &p_environment) { } fallback_environment = p_environment; - if (fallback_environment.is_valid()) + if (fallback_environment.is_valid()) { RS::get_singleton()->scenario_set_fallback_environment(scenario, p_environment->get_rid()); - else + } else { RS::get_singleton()->scenario_set_fallback_environment(scenario, RID()); + } emit_changed(); } @@ -281,10 +287,11 @@ Ref<Environment> World3D::get_fallback_environment() const { void World3D::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { camera_effects = p_camera_effects; - if (camera_effects.is_valid()) + if (camera_effects.is_valid()) { RS::get_singleton()->scenario_set_camera_effects(scenario, camera_effects->get_rid()); - else + } else { RS::get_singleton()->scenario_set_camera_effects(scenario, RID()); + } } Ref<CameraEffects> World3D::get_camera_effects() const { |