diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 13:23:58 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:54:55 +0200 |
commit | 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a (patch) | |
tree | a27e497da7104dd0a64f98a04fa3067668735e91 /scene/resources | |
parent | 710b34b70227becdc652b4ae027fe0ac47409642 (diff) |
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to
will now be changed automatically to remove the first empty line.
This makes us lean closer to 1TBS (the one true brace style) instead
of hybridating it with some Allman-inspired spacing.
There's still the case of braces around single-statement blocks that
needs to be addressed (but clang-format can't help with that, but
clang-tidy may if we agree about it).
Part of #33027.
Diffstat (limited to 'scene/resources')
93 files changed, 0 insertions, 2515 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index c5806ee7b3..44aa3f8319 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -36,38 +36,28 @@ #define ANIM_MIN_LENGTH 0.001 bool Animation::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (name.begins_with("tracks/")) { - int track = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (tracks.size() == track && what == "type") { - String type = p_value; if (type == "transform") { - add_track(TYPE_TRANSFORM); } else if (type == "value") { - add_track(TYPE_VALUE); } else if (type == "method") { - add_track(TYPE_METHOD); } else if (type == "bezier") { - add_track(TYPE_BEZIER); } else if (type == "audio") { - add_track(TYPE_AUDIO); } else if (type == "animation") { - add_track(TYPE_ANIMATION); } else { - return false; } @@ -87,9 +77,7 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { else if (what == "enabled") track_set_enabled(track, p_value); 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; int vcount = values.size(); @@ -100,7 +88,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { tt->transforms.resize(vcount / 12); for (int i = 0; i < (vcount / 12); i++) { - TKey<TransformKey> &tk = tt->transforms.write[i]; const float *ofs = &r[i * 12]; tk.time = ofs[0]; @@ -121,7 +108,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { } } else if (track_get_type(track) == TYPE_VALUE) { - ValueTrack *vt = static_cast<ValueTrack *>(tracks[track]); Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("times"), false); @@ -146,7 +132,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND_V(times.size() != values.size(), false); if (times.size()) { - int valcount = times.size(); const float *rt = times.ptr(); @@ -154,20 +139,17 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { vt->values.resize(valcount); for (int i = 0; i < valcount; i++) { - vt->values.write[i].time = rt[i]; vt->values.write[i].value = values[i]; } if (d.has("transitions")) { - Vector<float> transitions = d["transitions"]; ERR_FAIL_COND_V(transitions.size() != valcount, false); const float *rtr = transitions.ptr(); for (int i = 0; i < valcount; i++) { - vt->values.write[i].transition = rtr[i]; } } @@ -176,7 +158,6 @@ 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)) track_remove_key(track, 0); //well shouldn't be set anyway @@ -190,31 +171,26 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND_V(times.size() != values.size(), false); if (times.size()) { - int valcount = times.size(); const float *rt = times.ptr(); for (int i = 0; i < valcount; i++) { - track_insert_key(track, rt[i], values[i]); } if (d.has("transitions")) { - Vector<float> transitions = d["transitions"]; ERR_FAIL_COND_V(transitions.size() != valcount, false); const float *rtr = transitions.ptr(); for (int i = 0; i < valcount; i++) { - track_set_key_transition(track, i, rtr[i]); } } } } else if (track_get_type(track) == TYPE_BEZIER) { - BezierTrack *bt = static_cast<BezierTrack *>(tracks[track]); Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("times"), false); @@ -226,7 +202,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND_V(times.size() * 5 != values.size(), false); if (times.size()) { - int valcount = times.size(); const float *rt = times.ptr(); @@ -235,7 +210,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { bt->values.resize(valcount); for (int i = 0; i < valcount; i++) { - bt->values.write[i].time = rt[i]; bt->values.write[i].transition = 0; //unused in bezier bt->values.write[i].value.value = rv[i * 5 + 0]; @@ -248,7 +222,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { return true; } else if (track_get_type(track) == TYPE_AUDIO) { - AudioTrack *ad = static_cast<AudioTrack *>(tracks[track]); Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("times"), false); @@ -260,7 +233,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND_V(clips.size() != times.size(), false); if (times.size()) { - int valcount = times.size(); const float *rt = times.ptr(); @@ -268,7 +240,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ad->values.clear(); for (int i = 0; i < valcount; i++) { - Dictionary d2 = clips[i]; if (!d2.has("start_offset")) continue; @@ -289,7 +260,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { return true; } else if (track_get_type(track) == TYPE_ANIMATION) { - AnimationTrack *an = static_cast<AnimationTrack *>(tracks[track]); Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("times"), false); @@ -301,7 +271,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_COND_V(clips.size() != times.size(), false); if (times.size()) { - int valcount = times.size(); const float *rt = times.ptr(); @@ -310,7 +279,6 @@ bool Animation::_set(const StringName &p_name, const Variant &p_value) { an->values.resize(valcount); for (int i = 0; i < valcount; i++) { - TKey<StringName> ak; ak.time = rt[i]; ak.value = rc[i]; @@ -331,7 +299,6 @@ 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") @@ -341,14 +308,11 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { else if (name == "step") r_ret = step; 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); if (what == "type") { - switch (track_get_type(track)) { - case TYPE_TRANSFORM: r_ret = "transform"; break; @@ -382,9 +346,7 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { else if (what == "enabled") r_ret = track_is_enabled(track); else if (what == "keys") { - if (track_get_type(track) == TYPE_TRANSFORM) { - Vector<float> keys; int kk = track_get_key_count(track); keys.resize(kk * 12); @@ -393,7 +355,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { int idx = 0; for (int i = 0; i < track_get_key_count(track); i++) { - Vector3 loc; Quat rot; Vector3 scale; @@ -419,7 +380,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; } else if (track_get_type(track) == TYPE_VALUE) { - const ValueTrack *vt = static_cast<const ValueTrack *>(tracks[track]); Dictionary d; @@ -442,7 +402,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { const TKey<Variant> *vls = vt->values.ptr(); for (int i = 0; i < kk; i++) { - wti[idx] = vls[i].time; wtr[idx] = vls[i].transition; key_values[idx] = vls[i].value; @@ -461,7 +420,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; } else if (track_get_type(track) == TYPE_METHOD) { - Dictionary d; Vector<float> key_times; @@ -479,7 +437,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { int idx = 0; for (int i = 0; i < track_get_key_count(track); i++) { - wti[idx] = track_get_key_time(track, i); wtr[idx] = track_get_key_transition(track, i); key_values[idx] = track_get_key_value(track, i); @@ -497,7 +454,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; } else if (track_get_type(track) == TYPE_BEZIER) { - const BezierTrack *bt = static_cast<const BezierTrack *>(tracks[track]); Dictionary d; @@ -518,7 +474,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { const TKey<BezierKey> *vls = bt->values.ptr(); for (int i = 0; i < kk; i++) { - wti[idx] = vls[i].time; wpo[idx * 5 + 0] = vls[i].value.value; wpo[idx * 5 + 1] = vls[i].value.in_handle.x; @@ -535,7 +490,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; } else if (track_get_type(track) == TYPE_AUDIO) { - const AudioTrack *ad = static_cast<const AudioTrack *>(tracks[track]); Dictionary d; @@ -554,7 +508,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { const TKey<AudioKey> *vls = ad->values.ptr(); for (int i = 0; i < kk; i++) { - wti[idx] = vls[i].time; Dictionary clip; clip["start_offset"] = vls[i].value.start_offset; @@ -571,7 +524,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { return true; } else if (track_get_type(track) == TYPE_ANIMATION) { - const AnimationTrack *an = static_cast<const AnimationTrack *>(tracks[track]); Dictionary d; @@ -590,7 +542,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { const TKey<StringName> *vls = an->values.ptr(); for (int i = 0; i < kk; i++) { - wti[i] = vls[i].time; wcl[i] = vls[i].value; } @@ -612,7 +563,6 @@ bool Animation::_get(const StringName &p_name, Variant &r_ret) const { void Animation::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < tracks.size(); i++) { - p_list->push_back(PropertyInfo(Variant::STRING, "tracks/" + itos(i) + "/type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::NODE_PATH, "tracks/" + itos(i) + "/path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::INT, "tracks/" + itos(i) + "/interp", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); @@ -624,44 +574,35 @@ 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()) p_at_pos = tracks.size(); switch (p_type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = memnew(TransformTrack); tracks.insert(p_at_pos, tt); } break; case TYPE_VALUE: { - tracks.insert(p_at_pos, memnew(ValueTrack)); } break; case TYPE_METHOD: { - tracks.insert(p_at_pos, memnew(MethodTrack)); } break; case TYPE_BEZIER: { - tracks.insert(p_at_pos, memnew(BezierTrack)); } break; case TYPE_AUDIO: { - tracks.insert(p_at_pos, memnew(AudioTrack)); } break; case TYPE_ANIMATION: { - tracks.insert(p_at_pos, memnew(AnimationTrack)); } break; default: { - ERR_PRINT("Unknown track type"); } } @@ -671,44 +612,36 @@ int Animation::add_track(TrackType p_type, int p_at_pos) { } void Animation::remove_track(int p_track) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); _clear(tt->transforms); } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); _clear(vt->values); } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); _clear(mt->methods); } break; case TYPE_BEZIER: { - BezierTrack *bz = static_cast<BezierTrack *>(t); _clear(bz->values); } break; case TYPE_AUDIO: { - AudioTrack *ad = static_cast<AudioTrack *>(t); _clear(ad->values); } break; case TYPE_ANIMATION: { - AnimationTrack *an = static_cast<AnimationTrack *>(t); _clear(an->values); @@ -722,18 +655,15 @@ void Animation::remove_track(int p_track) { } int Animation::get_track_count() const { - return tracks.size(); } Animation::TrackType Animation::track_get_type(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), TYPE_TRANSFORM); return tracks[p_track]->type; } void Animation::track_set_path(int p_track, const NodePath &p_path) { - ERR_FAIL_INDEX(p_track, tracks.size()); tracks[p_track]->path = p_path; emit_changed(); @@ -741,15 +671,12 @@ void Animation::track_set_path(int p_track, const NodePath &p_path) { } NodePath Animation::track_get_path(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), NodePath()); return tracks[p_track]->path; } int Animation::find_track(const NodePath &p_path) const { - for (int i = 0; i < tracks.size(); i++) { - if (tracks[i]->path == p_path) return i; }; @@ -757,7 +684,6 @@ int Animation::find_track(const NodePath &p_path) const { }; void Animation::track_set_interpolation_type(int p_track, InterpolationType p_interp) { - ERR_FAIL_INDEX(p_track, tracks.size()); ERR_FAIL_INDEX(p_interp, 3); tracks[p_track]->interpolation = p_interp; @@ -765,7 +691,6 @@ void Animation::track_set_interpolation_type(int p_track, InterpolationType p_in } Animation::InterpolationType Animation::track_get_interpolation_type(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), INTERPOLATION_NEAREST); return tracks[p_track]->interpolation; } @@ -777,7 +702,6 @@ void Animation::track_set_interpolation_loop_wrap(int p_track, bool p_enable) { } bool Animation::track_get_interpolation_loop_wrap(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), INTERPOLATION_NEAREST); return tracks[p_track]->loop_wrap; } @@ -811,20 +735,16 @@ int Animation::_insert_pos(float p_time, T& p_keys) { */ template <class T, class V> int Animation::_insert(float p_time, T &p_keys, const V &p_value) { - int idx = p_keys.size(); while (true) { - // Condition for replacement. if (idx > 0 && Math::is_equal_approx(p_keys[idx - 1].time, p_time)) { - p_keys.write[idx - 1] = p_value; return idx - 1; // Condition for insert. } else if (idx == 0 || p_keys[idx - 1].time < p_time) { - p_keys.insert(idx, p_value); return idx; } @@ -837,12 +757,10 @@ int Animation::_insert(float p_time, T &p_keys, const V &p_value) { template <class T> void Animation::_clear(T &p_keys) { - p_keys.clear(); } Error Animation::transform_track_get_key(int p_track, int p_key, Vector3 *r_loc, Quat *r_rot, Vector3 *r_scale) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), ERR_INVALID_PARAMETER); Track *t = tracks[p_track]; @@ -861,7 +779,6 @@ Error Animation::transform_track_get_key(int p_track, int p_key, Vector3 *r_loc, } int Animation::transform_track_insert_key(int p_track, float p_time, const Vector3 &p_loc, const Quat &p_rot, const Vector3 &p_scale) { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_TRANSFORM, -1); @@ -880,55 +797,47 @@ int Animation::transform_track_insert_key(int p_track, float p_time, const Vecto } void Animation::track_remove_key_at_position(int p_track, float p_pos) { - int idx = track_find_key(p_track, p_pos, true); ERR_FAIL_COND(idx < 0); track_remove_key(p_track, idx); } void Animation::track_remove_key(int p_track, int p_idx) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; switch (t->type) { case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX(p_idx, tt->transforms.size()); tt->transforms.remove(p_idx); } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX(p_idx, vt->values.size()); vt->values.remove(p_idx); } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX(p_idx, mt->methods.size()); mt->methods.remove(p_idx); } break; case TYPE_BEZIER: { - BezierTrack *bz = static_cast<BezierTrack *>(t); ERR_FAIL_INDEX(p_idx, bz->values.size()); bz->values.remove(p_idx); } break; case TYPE_AUDIO: { - AudioTrack *ad = static_cast<AudioTrack *>(t); ERR_FAIL_INDEX(p_idx, ad->values.size()); ad->values.remove(p_idx); } break; case TYPE_ANIMATION: { - AnimationTrack *an = static_cast<AnimationTrack *>(t); ERR_FAIL_INDEX(p_idx, an->values.size()); an->values.remove(p_idx); @@ -940,13 +849,11 @@ void Animation::track_remove_key(int p_track, int p_idx) { } int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; switch (t->type) { case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); int k = _find(tt->transforms, p_time); if (k < 0 || k >= tt->transforms.size()) @@ -957,7 +864,6 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); int k = _find(vt->values, p_time); if (k < 0 || k >= vt->values.size()) @@ -968,7 +874,6 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); int k = _find(mt->methods, p_time); if (k < 0 || k >= mt->methods.size()) @@ -979,7 +884,6 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { } break; case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); int k = _find(bt->values, p_time); if (k < 0 || k >= bt->values.size()) @@ -990,7 +894,6 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { } break; case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); int k = _find(at->values, p_time); if (k < 0 || k >= at->values.size()) @@ -1001,7 +904,6 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { } break; case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); int k = _find(at->values, p_time); if (k < 0 || k >= at->values.size()) @@ -1017,14 +919,11 @@ int Animation::track_find_key(int p_track, float p_time, bool p_exact) const { } void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key, float p_transition) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - Dictionary d = p_key; Vector3 loc; if (d.has("location")) @@ -1043,7 +942,6 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); TKey<Variant> k; @@ -1054,7 +952,6 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_COND(p_key.get_type() != Variant::DICTIONARY); @@ -1074,7 +971,6 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key } break; case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); Array arr = p_key; @@ -1091,7 +987,6 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key } break; case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); Dictionary k = p_key; @@ -1108,7 +1003,6 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key } break; case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); TKey<StringName> ak; @@ -1124,40 +1018,32 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant &p_key } int Animation::track_get_key_count(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); return tt->transforms.size(); } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); return vt->values.size(); } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); return mt->methods.size(); } break; case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); return bt->values.size(); } break; case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); return at->values.size(); } break; case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); return at->values.size(); } break; @@ -1167,14 +1053,11 @@ int Animation::track_get_key_count(int p_track) const { } Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), Variant()); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, tt->transforms.size(), Variant()); @@ -1186,14 +1069,12 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { return d; } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, vt->values.size(), Variant()); return vt->values[p_key_idx].value; } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, mt->methods.size(), Variant()); Dictionary d; @@ -1203,7 +1084,6 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { } break; case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, bt->values.size(), Variant()); @@ -1218,7 +1098,6 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { } break; case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, at->values.size(), Variant()); @@ -1230,7 +1109,6 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { } break; case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, at->values.size(), Variant()); @@ -1243,48 +1121,40 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { } float Animation::track_get_key_time(int p_track, int p_key_idx) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, tt->transforms.size(), -1); return tt->transforms[p_key_idx].time; } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, vt->values.size(), -1); return vt->values[p_key_idx].time; } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, mt->methods.size(), -1); return mt->methods[p_key_idx].time; } break; case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, bt->values.size(), -1); return bt->values[p_key_idx].time; } break; case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, at->values.size(), -1); return at->values[p_key_idx].time; } break; case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, at->values.size(), -1); return at->values[p_key_idx].time; @@ -1296,14 +1166,11 @@ float Animation::track_get_key_time(int p_track, int p_key_idx) const { } void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); TKey<TransformKey> key = tt->transforms[p_key_idx]; @@ -1313,7 +1180,6 @@ void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { return; } case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX(p_key_idx, vt->values.size()); TKey<Variant> key = vt->values[p_key_idx]; @@ -1323,7 +1189,6 @@ void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { return; } case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); MethodKey key = mt->methods[p_key_idx]; @@ -1333,7 +1198,6 @@ void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { return; } case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); ERR_FAIL_INDEX(p_key_idx, bt->values.size()); TKey<BezierKey> key = bt->values[p_key_idx]; @@ -1343,7 +1207,6 @@ void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { return; } case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); ERR_FAIL_INDEX(p_key_idx, at->values.size()); TKey<AudioKey> key = at->values[p_key_idx]; @@ -1353,7 +1216,6 @@ void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { return; } case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); ERR_FAIL_INDEX(p_key_idx, at->values.size()); TKey<StringName> key = at->values[p_key_idx]; @@ -1368,42 +1230,34 @@ void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { } float Animation::track_get_key_transition(int p_track, int p_key_idx) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, tt->transforms.size(), -1); return tt->transforms[p_key_idx].transition; } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, vt->values.size(), -1); return vt->values[p_key_idx].transition; } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX_V(p_key_idx, mt->methods.size(), -1); return mt->methods[p_key_idx].transition; } break; case TYPE_BEZIER: { - return 1; //bezier does not really use transitions } break; case TYPE_AUDIO: { - return 1; //audio does not really use transitions } break; case TYPE_ANIMATION: { - return 1; //animation does not really use transitions } break; } @@ -1412,14 +1266,11 @@ float Animation::track_get_key_transition(int p_track, int p_key_idx) const { } void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p_value) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); @@ -1434,7 +1285,6 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX(p_key_idx, vt->values.size()); @@ -1442,7 +1292,6 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); @@ -1455,7 +1304,6 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p } break; case TYPE_BEZIER: { - BezierTrack *bt = static_cast<BezierTrack *>(t); ERR_FAIL_INDEX(p_key_idx, bt->values.size()); @@ -1470,7 +1318,6 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p } break; case TYPE_AUDIO: { - AudioTrack *at = static_cast<AudioTrack *>(t); ERR_FAIL_INDEX(p_key_idx, at->values.size()); @@ -1485,7 +1332,6 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p } break; case TYPE_ANIMATION: { - AnimationTrack *at = static_cast<AnimationTrack *>(t); ERR_FAIL_INDEX(p_key_idx, at->values.size()); @@ -1498,27 +1344,22 @@ void Animation::track_set_key_value(int p_track, int p_key_idx, const Variant &p } void Animation::track_set_key_transition(int p_track, int p_key_idx, float p_transition) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; switch (t->type) { - case TYPE_TRANSFORM: { - TransformTrack *tt = static_cast<TransformTrack *>(t); ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); tt->transforms.write[p_key_idx].transition = p_transition; } break; case TYPE_VALUE: { - ValueTrack *vt = static_cast<ValueTrack *>(t); ERR_FAIL_INDEX(p_key_idx, vt->values.size()); vt->values.write[p_key_idx].transition = p_transition; } break; case TYPE_METHOD: { - MethodTrack *mt = static_cast<MethodTrack *>(t); ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); mt->methods.write[p_key_idx].transition = p_transition; @@ -1536,7 +1377,6 @@ 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) return -2; @@ -1553,7 +1393,6 @@ int Animation::_find(const Vector<K> &p_keys, float p_time) const { const K *keys = &p_keys[0]; while (low <= high) { - middle = (low + high) / 2; if (Math::is_equal_approx(p_time, keys[middle].time)) { //match @@ -1571,7 +1410,6 @@ int Animation::_find(const Vector<K> &p_keys, float p_time) const { } Animation::TransformKey Animation::_interpolate(const Animation::TransformKey &p_a, const Animation::TransformKey &p_b, float p_c) const { - TransformKey ret; ret.loc = _interpolate(p_a.loc, p_b.loc, p_c); ret.rot = _interpolate(p_a.rot, p_b.rot, p_c); @@ -1581,27 +1419,22 @@ Animation::TransformKey Animation::_interpolate(const Animation::TransformKey &p } Vector3 Animation::_interpolate(const Vector3 &p_a, const Vector3 &p_b, float p_c) const { - return p_a.lerp(p_b, p_c); } Quat Animation::_interpolate(const Quat &p_a, const Quat &p_b, float p_c) const { - return p_a.slerp(p_b, p_c); } Variant Animation::_interpolate(const Variant &p_a, const Variant &p_b, float p_c) const { - Variant dst; Variant::interpolate(p_a, p_b, p_c, dst); return dst; } float Animation::_interpolate(const float &p_a, const float &p_b, float p_c) const { - return p_a * (1.0 - p_c) + p_b * p_c; } Animation::TransformKey Animation::_cubic_interpolate(const Animation::TransformKey &p_pre_a, const Animation::TransformKey &p_a, const Animation::TransformKey &p_b, const Animation::TransformKey &p_post_b, float p_c) const { - Animation::TransformKey tk; tk.loc = p_a.loc.cubic_interpolate(p_b.loc, p_pre_a.loc, p_post_b.loc, p_c); @@ -1611,15 +1444,12 @@ Animation::TransformKey Animation::_cubic_interpolate(const Animation::Transform return tk; } Vector3 Animation::_cubic_interpolate(const Vector3 &p_pre_a, const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_post_b, float p_c) const { - return p_a.cubic_interpolate(p_b, p_pre_a, p_post_b, p_c); } Quat Animation::_cubic_interpolate(const Quat &p_pre_a, const Quat &p_a, const Quat &p_b, const Quat &p_post_b, float p_c) const { - return p_a.cubic_slerp(p_b, p_pre_a, p_post_b, p_c); } Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a, const Variant &p_b, const Variant &p_post_b, float p_c) const { - Variant::Type type_a = p_a.get_type(); Variant::Type type_b = p_b.get_type(); Variant::Type type_pa = p_pre_a.get_type(); @@ -1650,14 +1480,11 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3); } else if ((vformat & (vformat - 1))) { - return p_a; //can't interpolate, mix of types } switch (type_a) { - case Variant::VECTOR2: { - Vector2 a = p_a; Vector2 b = p_b; Vector2 pa = p_pre_a; @@ -1666,7 +1493,6 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return a.cubic_interpolate(b, pa, pb, p_c); } case Variant::RECT2: { - Rect2 a = p_a; Rect2 b = p_b; Rect2 pa = p_pre_a; @@ -1677,7 +1503,6 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); } case Variant::VECTOR3: { - Vector3 a = p_a; Vector3 b = p_b; Vector3 pa = p_pre_a; @@ -1686,7 +1511,6 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return a.cubic_interpolate(b, pa, pb, p_c); } case Variant::QUAT: { - Quat a = p_a; Quat b = p_b; Quat pa = p_pre_a; @@ -1695,7 +1519,6 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a return a.cubic_slerp(b, pa, pb, p_c); } case Variant::AABB: { - AABB a = p_a; AABB b = p_b; AABB pa = p_pre_a; @@ -1706,19 +1529,16 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a a.size.cubic_interpolate(b.size, pa.size, pb.size, p_c)); } default: { - return _interpolate(p_a, p_b, p_c); } } } float Animation::_cubic_interpolate(const float &p_pre_a, const float &p_a, const float &p_b, const float &p_post_b, float p_c) const { - return _interpolate(p_a, p_b, p_c); } template <class T> T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok) const { - int len = _find(p_keys, length) + 1; // try to find last key (there may be more past the end) if (len <= 0) { @@ -1746,9 +1566,7 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola if (loop && p_loop_wrap) { // loop if (idx >= 0) { - if ((idx + 1) < len) { - next = idx + 1; float delta = p_keys[next].time - p_keys[idx].time; float from = p_time - p_keys[idx].time; @@ -1759,7 +1577,6 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola 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; @@ -1789,9 +1606,7 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola } else { // no loop if (idx >= 0) { - if ((idx + 1) < len) { - next = idx + 1; float delta = p_keys[next].time - p_keys[idx].time; float from = p_time - p_keys[idx].time; @@ -1802,12 +1617,10 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola c = from / delta; } else { - next = idx; } } else { - // only allow extending first key to anim start if looping if (loop) idx = next = 0; @@ -1829,18 +1642,14 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola } if (tr != 1.0) { - c = Math::ease(c, tr); } switch (p_interp) { - case INTERPOLATION_NEAREST: { - return p_keys[idx].value; } break; case INTERPOLATION_LINEAR: { - return _interpolate(p_keys[idx].value, p_keys[next].value, c); } break; case INTERPOLATION_CUBIC: { @@ -1862,7 +1671,6 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, float p_time, Interpola } Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 *r_loc, Quat *r_rot, Vector3 *r_scale) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), ERR_INVALID_PARAMETER); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_TRANSFORM, ERR_INVALID_PARAMETER); @@ -1889,7 +1697,6 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 } Variant Animation::value_track_interpolate(int p_track, float p_time) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), 0); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_VALUE, Variant()); @@ -1900,7 +1707,6 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { Variant res = _interpolate(vt->values, p_time, (vt->update_mode == UPDATE_CONTINUOUS || vt->update_mode == UPDATE_CAPTURE) ? vt->interpolation : INTERPOLATION_NEAREST, vt->loop_wrap, &ok); if (ok) { - return res; } @@ -1908,7 +1714,6 @@ 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) to_time = length * 1.001; //include a little more if at the end int to = _find(vt->values, to_time); @@ -1936,14 +1741,12 @@ void Animation::_value_track_get_key_indices_in_range(const ValueTrack *vt, floa int max = vt->values.size(); for (int i = from; i <= to; i++) { - ERR_CONTINUE(i < 0 || i >= max); // shouldn't happen p_indices->push_back(i); } } void Animation::value_track_get_key_indices(int p_track, float p_time, float p_delta, List<int> *p_indices) const { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_VALUE); @@ -1957,7 +1760,6 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d SWAP(from_time, to_time); if (loop) { - from_time = Math::fposmod(from_time, length); to_time = Math::fposmod(to_time, length); @@ -1968,7 +1770,6 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d return; } } else { - if (from_time < 0) from_time = 0; if (from_time > length) @@ -1984,7 +1785,6 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d } void Animation::value_track_set_update_mode(int p_track, UpdateMode p_mode) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_VALUE); @@ -1995,7 +1795,6 @@ void Animation::value_track_set_update_mode(int p_track, UpdateMode p_mode) { } Animation::UpdateMode Animation::value_track_get_update_mode(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), UPDATE_CONTINUOUS); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_VALUE, UPDATE_CONTINUOUS); @@ -2006,7 +1805,6 @@ 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) to_time = length * 1.01; //include a little more if at the end @@ -2030,14 +1828,12 @@ void Animation::_track_get_key_indices_in_range(const Vector<T> &p_array, float int max = p_array.size(); for (int i = from; i <= to; i++) { - ERR_CONTINUE(i < 0 || i >= max); // shouldn't happen p_indices->push_back(i); } } void Animation::track_get_key_indices_in_range(int p_track, float p_time, float p_delta, List<int> *p_indices) const { - ERR_FAIL_INDEX(p_track, tracks.size()); const Track *t = tracks[p_track]; @@ -2048,7 +1844,6 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float SWAP(from_time, to_time); if (loop) { - if (from_time > length || from_time < 0) from_time = Math::fposmod(from_time, length); @@ -2059,44 +1854,37 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float // handle loop by splitting switch (t->type) { - case TYPE_TRANSFORM: { - const TransformTrack *tt = static_cast<const TransformTrack *>(t); _track_get_key_indices_in_range(tt->transforms, from_time, length, p_indices); _track_get_key_indices_in_range(tt->transforms, 0, to_time, p_indices); } break; case TYPE_VALUE: { - const ValueTrack *vt = static_cast<const ValueTrack *>(t); _track_get_key_indices_in_range(vt->values, from_time, length, p_indices); _track_get_key_indices_in_range(vt->values, 0, to_time, p_indices); } break; case TYPE_METHOD: { - const MethodTrack *mt = static_cast<const MethodTrack *>(t); _track_get_key_indices_in_range(mt->methods, from_time, length, p_indices); _track_get_key_indices_in_range(mt->methods, 0, to_time, p_indices); } break; case TYPE_BEZIER: { - const BezierTrack *bz = static_cast<const BezierTrack *>(t); _track_get_key_indices_in_range(bz->values, from_time, length, p_indices); _track_get_key_indices_in_range(bz->values, 0, to_time, p_indices); } break; case TYPE_AUDIO: { - const AudioTrack *ad = static_cast<const AudioTrack *>(t); _track_get_key_indices_in_range(ad->values, from_time, length, p_indices); _track_get_key_indices_in_range(ad->values, 0, to_time, p_indices); } break; case TYPE_ANIMATION: { - const AnimationTrack *an = static_cast<const AnimationTrack *>(t); _track_get_key_indices_in_range(an->values, from_time, length, p_indices); _track_get_key_indices_in_range(an->values, 0, to_time, p_indices); @@ -2106,7 +1894,6 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float return; } } else { - if (from_time < 0) from_time = 0; if (from_time > length) @@ -2119,39 +1906,32 @@ void Animation::track_get_key_indices_in_range(int p_track, float p_time, float } switch (t->type) { - case TYPE_TRANSFORM: { - const TransformTrack *tt = static_cast<const TransformTrack *>(t); _track_get_key_indices_in_range(tt->transforms, from_time, to_time, p_indices); } break; case TYPE_VALUE: { - const ValueTrack *vt = static_cast<const ValueTrack *>(t); _track_get_key_indices_in_range(vt->values, from_time, to_time, p_indices); } break; case TYPE_METHOD: { - const MethodTrack *mt = static_cast<const MethodTrack *>(t); _track_get_key_indices_in_range(mt->methods, from_time, to_time, p_indices); } break; case TYPE_BEZIER: { - const BezierTrack *bz = static_cast<const BezierTrack *>(t); _track_get_key_indices_in_range(bz->values, from_time, to_time, p_indices); } break; case TYPE_AUDIO: { - const AudioTrack *ad = static_cast<const AudioTrack *>(t); _track_get_key_indices_in_range(ad->values, from_time, to_time, p_indices); } break; case TYPE_ANIMATION: { - const AnimationTrack *an = static_cast<const AnimationTrack *>(t); _track_get_key_indices_in_range(an->values, from_time, to_time, p_indices); @@ -2160,7 +1940,6 @@ 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) to_time = length * 1.01; //include a little more if at the end @@ -2184,14 +1963,12 @@ void Animation::_method_track_get_key_indices_in_range(const MethodTrack *mt, fl int max = mt->methods.size(); for (int i = from; i <= to; i++) { - ERR_CONTINUE(i < 0 || i >= max); // shouldn't happen p_indices->push_back(i); } } void Animation::method_track_get_key_indices(int p_track, float p_time, float p_delta, List<int> *p_indices) const { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_METHOD); @@ -2205,7 +1982,6 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ SWAP(from_time, to_time); if (loop) { - if (from_time > length || from_time < 0) from_time = Math::fposmod(from_time, length); @@ -2219,7 +1995,6 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ return; } } else { - if (from_time < 0) from_time = 0; if (from_time > length) @@ -2234,7 +2009,6 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ _method_track_get_key_indices_in_range(mt, from_time, to_time, p_indices); } Vector<Variant> Animation::method_track_get_params(int p_track, int p_key_idx) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), Vector<Variant>()); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_METHOD, Vector<Variant>()); @@ -2248,7 +2022,6 @@ Vector<Variant> Animation::method_track_get_params(int p_track, int p_key_idx) c return mk.params; } StringName Animation::method_track_get_name(int p_track, int p_key_idx) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), StringName()); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_METHOD, StringName()); @@ -2261,7 +2034,6 @@ StringName Animation::method_track_get_name(int p_track, int p_key_idx) const { } int Animation::bezier_track_insert_key(int p_track, float p_time, float p_value, const Vector2 &p_in_handle, const Vector2 &p_out_handle) { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_BEZIER, -1); @@ -2288,7 +2060,6 @@ int Animation::bezier_track_insert_key(int p_track, float p_time, float p_value, } void Animation::bezier_track_set_key_value(int p_track, int p_index, float p_value) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_BEZIER); @@ -2302,7 +2073,6 @@ void Animation::bezier_track_set_key_value(int p_track, int p_index, float p_val } void Animation::bezier_track_set_key_in_handle(int p_track, int p_index, const Vector2 &p_handle) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_BEZIER); @@ -2318,7 +2088,6 @@ void Animation::bezier_track_set_key_in_handle(int p_track, int p_index, const V emit_changed(); } void Animation::bezier_track_set_key_out_handle(int p_track, int p_index, const Vector2 &p_handle) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_BEZIER); @@ -2334,7 +2103,6 @@ void Animation::bezier_track_set_key_out_handle(int p_track, int p_index, const emit_changed(); } float Animation::bezier_track_get_key_value(int p_track, int p_index) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), 0); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_BEZIER, 0); @@ -2346,7 +2114,6 @@ float Animation::bezier_track_get_key_value(int p_track, int p_index) const { return bt->values[p_index].value.value; } Vector2 Animation::bezier_track_get_key_in_handle(int p_track, int p_index) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), Vector2()); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_BEZIER, Vector2()); @@ -2358,7 +2125,6 @@ Vector2 Animation::bezier_track_get_key_in_handle(int p_track, int p_index) cons return bt->values[p_index].value.in_handle; } Vector2 Animation::bezier_track_get_key_out_handle(int p_track, int p_index) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), Vector2()); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_BEZIER, Vector2()); @@ -2428,7 +2194,6 @@ float Animation::bezier_track_interpolate(int p_track, float p_time) const { //narrow high and low as much as possible for (int i = 0; i < iterations; i++) { - middle = (low + high) / 2; Vector2 interp = _bezier_interp(middle, start, start_out, end_in, end); @@ -2449,7 +2214,6 @@ float Animation::bezier_track_interpolate(int p_track, float p_time) const { } int Animation::audio_track_insert_key(int p_track, float p_time, const RES &p_stream, float p_start_offset, float p_end_offset) { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_AUDIO, -1); @@ -2474,7 +2238,6 @@ int Animation::audio_track_insert_key(int p_track, float p_time, const RES &p_st } void Animation::audio_track_set_key_stream(int p_track, int p_key, const RES &p_stream) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_AUDIO); @@ -2489,7 +2252,6 @@ void Animation::audio_track_set_key_stream(int p_track, int p_key, const RES &p_ } void Animation::audio_track_set_key_start_offset(int p_track, int p_key, float p_offset) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_AUDIO); @@ -2507,7 +2269,6 @@ void Animation::audio_track_set_key_start_offset(int p_track, int p_key, float p } void Animation::audio_track_set_key_end_offset(int p_track, int p_key, float p_offset) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_AUDIO); @@ -2525,7 +2286,6 @@ void Animation::audio_track_set_key_end_offset(int p_track, int p_key, float p_o } RES Animation::audio_track_get_key_stream(int p_track, int p_key) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), RES()); const Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_AUDIO, RES()); @@ -2537,7 +2297,6 @@ RES Animation::audio_track_get_key_stream(int p_track, int p_key) const { return at->values[p_key].value.stream; } float Animation::audio_track_get_key_start_offset(int p_track, int p_key) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), 0); const Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_AUDIO, 0); @@ -2549,7 +2308,6 @@ float Animation::audio_track_get_key_start_offset(int p_track, int p_key) const return at->values[p_key].value.start_offset; } float Animation::audio_track_get_key_end_offset(int p_track, int p_key) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), 0); const Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_AUDIO, 0); @@ -2564,7 +2322,6 @@ float Animation::audio_track_get_key_end_offset(int p_track, int p_key) const { // int Animation::animation_track_insert_key(int p_track, float p_time, const StringName &p_animation) { - ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_ANIMATION, -1); @@ -2583,7 +2340,6 @@ int Animation::animation_track_insert_key(int p_track, float p_time, const Strin } void Animation::animation_track_set_key_animation(int p_track, int p_key, const StringName &p_animation) { - ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_ANIMATION); @@ -2598,7 +2354,6 @@ void Animation::animation_track_set_key_animation(int p_track, int p_key, const } StringName Animation::animation_track_get_key_animation(int p_track, int p_key) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), StringName()); const Track *t = tracks[p_track]; ERR_FAIL_COND_V(t->type != TYPE_ANIMATION, StringName()); @@ -2611,7 +2366,6 @@ StringName Animation::animation_track_get_key_animation(int p_track, int p_key) } void Animation::set_length(float p_length) { - if (p_length < ANIM_MIN_LENGTH) { p_length = ANIM_MIN_LENGTH; } @@ -2619,49 +2373,40 @@ void Animation::set_length(float p_length) { emit_changed(); } float Animation::get_length() const { - return length; } void Animation::set_loop(bool p_enabled) { - loop = p_enabled; emit_changed(); } bool Animation::has_loop() const { - return loop; } void Animation::track_set_imported(int p_track, bool p_imported) { - ERR_FAIL_INDEX(p_track, tracks.size()); tracks[p_track]->imported = p_imported; } bool Animation::track_is_imported(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), false); return tracks[p_track]->imported; } void Animation::track_set_enabled(int p_track, bool p_enabled) { - ERR_FAIL_INDEX(p_track, tracks.size()); tracks[p_track]->enabled = p_enabled; emit_changed(); } bool Animation::track_is_enabled(int p_track) const { - ERR_FAIL_INDEX_V(p_track, tracks.size(), false); return tracks[p_track]->enabled; } void Animation::track_move_up(int p_track) { - if (p_track >= 0 && p_track < (tracks.size() - 1)) { - SWAP(tracks.write[p_track], tracks.write[p_track + 1]); } @@ -2670,9 +2415,7 @@ void Animation::track_move_up(int p_track) { } void Animation::track_move_down(int p_track) { - if (p_track > 0 && p_track < tracks.size()) { - SWAP(tracks.write[p_track], tracks.write[p_track - 1]); } @@ -2681,7 +2424,6 @@ 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) @@ -2697,7 +2439,6 @@ 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) @@ -2709,13 +2450,11 @@ void Animation::track_swap(int p_track, int p_with_track) { } void Animation::set_step(float p_step) { - step = p_step; emit_changed(); } float Animation::get_step() const { - return step; } @@ -2737,7 +2476,6 @@ void Animation::copy_track(int p_track, Ref<Animation> p_to_animation) { } void Animation::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_track", "type", "at_position"), &Animation::add_track, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("remove_track", "track_idx"), &Animation::remove_track); ClassDB::bind_method(D_METHOD("get_track_count"), &Animation::get_track_count); @@ -2847,7 +2585,6 @@ void Animation::_bind_methods() { } void Animation::clear() { - for (int i = 0; i < tracks.size(); i++) memdelete(tracks[i]); tracks.clear(); @@ -2858,7 +2595,6 @@ void Animation::clear() { } bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err, float p_alowed_angular_err, float p_max_optimizable_angle, const Vector3 &p_norm) { - real_t c = (t1.time - t0.time) / (t2.time - t0.time); real_t t[3] = { -1, -1, -1 }; @@ -2876,7 +2612,6 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons } } else { - Vector3 pd = (v2 - v0); float d0 = pd.dot(v0); float d1 = pd.dot(v1); @@ -2908,12 +2643,10 @@ 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)) return false; } else { - Quat r02 = (q0.inverse() * q2).normalized(); Quat r01 = (q0.inverse() * q1).normalized(); @@ -2965,7 +2698,6 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons } } else { - Vector3 pd = (v2 - v0); float d0 = pd.dot(v0); float d1 = pd.dot(v1); @@ -2987,10 +2719,8 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons bool erase = false; if (t[0] == -1 && t[1] == -1 && t[2] == -1) { - erase = true; } else { - erase = true; real_t lt = -1; for (int j = 0; j < 3; j++) { @@ -3014,7 +2744,6 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons ERR_FAIL_COND_V(lt == -1, false); if (erase) { - if (Math::abs(lt - c) > p_alowed_linear_err) { //todo, evaluate changing the transition if this fails? //this could be done as a second pass and would be @@ -3028,7 +2757,6 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons } void Animation::_transform_track_optimize(int p_idx, float p_allowed_linear_err, float p_allowed_angular_err, float p_max_optimizable_angle) { - ERR_FAIL_INDEX(p_idx, tracks.size()); ERR_FAIL_COND(tracks[p_idx]->type != TYPE_TRANSFORM); TransformTrack *tt = static_cast<TransformTrack *>(tracks[p_idx]); @@ -3038,7 +2766,6 @@ void Animation::_transform_track_optimize(int p_idx, float p_allowed_linear_err, Vector3 norm; for (int i = 1; i < tt->transforms.size() - 1; i++) { - TKey<TransformKey> &t0 = tt->transforms.write[i - 1]; TKey<TransformKey> &t1 = tt->transforms.write[i]; TKey<TransformKey> &t2 = tt->transforms.write[i + 1]; @@ -3054,7 +2781,6 @@ void Animation::_transform_track_optimize(int p_idx, float p_allowed_linear_err, } if (erase) { - if (!prev_erased) { first_erased = t1; prev_erased = true; @@ -3071,23 +2797,19 @@ 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) _transform_track_optimize(i, p_allowed_linear_err, p_allowed_angular_err, p_max_optimizable_angle); } } Animation::Animation() { - step = 0.1; loop = false; length = 1; } Animation::~Animation() { - for (int i = 0; i < tracks.size(); i++) memdelete(tracks[i]); } diff --git a/scene/resources/animation.h b/scene/resources/animation.h index e4e5177a8c..722a400fd6 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -34,7 +34,6 @@ #include "core/resource.h" class Animation : public Resource { - GDCLASS(Animation, Resource); RES_BASE_EXTENSION("anim"); @@ -64,7 +63,6 @@ public: private: struct Track { - TrackType type; InterpolationType interpolation; bool loop_wrap; @@ -81,7 +79,6 @@ private: }; struct Key { - float transition; float time; // time in secs Key() { @@ -93,12 +90,10 @@ private: // transform key holds either Vector3 or Quaternion template <class T> struct TKey : public Key { - T value; }; struct TransformKey { - Vector3 loc; Quat rot; Vector3 scale; @@ -107,7 +102,6 @@ private: /* TRANSFORM TRACK */ struct TransformTrack : public Track { - Vector<TKey<TransformKey>> transforms; TransformTrack() { type = TYPE_TRANSFORM; } @@ -116,7 +110,6 @@ private: /* PROPERTY VALUE TRACK */ struct ValueTrack : public Track { - UpdateMode update_mode; bool update_on_seek; Vector<TKey<Variant>> values; @@ -130,13 +123,11 @@ private: /* METHOD TRACK */ struct MethodKey : public Key { - StringName method; Vector<Variant> params; }; struct MethodTrack : public Track { - Vector<MethodKey> methods; MethodTrack() { type = TYPE_METHOD; } }; @@ -150,7 +141,6 @@ private: }; struct BezierTrack : public Track { - Vector<TKey<BezierKey>> values; BezierTrack() { @@ -171,7 +161,6 @@ private: }; struct AudioTrack : public Track { - Vector<TKey<AudioKey>> values; AudioTrack() { @@ -182,7 +171,6 @@ private: /* AUDIO TRACK */ struct AnimationTrack : public Track { - Vector<TKey<StringName>> values; AnimationTrack() { @@ -246,25 +234,21 @@ private: } Vector<int> _value_track_get_key_indices(int p_track, float p_time, float p_delta) const { - List<int> idxs; value_track_get_key_indices(p_track, p_time, p_delta, &idxs); Vector<int> idxr; for (List<int>::Element *E = idxs.front(); E; E = E->next()) { - idxr.push_back(E->get()); } return idxr; } Vector<int> _method_track_get_key_indices(int p_track, float p_time, float p_delta) const { - List<int> idxs; method_track_get_key_indices(p_track, p_time, p_delta, &idxs); Vector<int> idxr; for (List<int>::Element *E = idxs.front(); E; E = E->next()) { - idxr.push_back(E->get()); } return idxr; diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index fdf5e2c2d0..b6608b47d0 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -34,7 +34,6 @@ #include "core/os/file_access.h" void AudioStreamPlaybackSample::start(float p_from_pos) { - if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) { //no seeking in IMA_ADPCM for (int i = 0; i < 2; i++) { @@ -57,26 +56,21 @@ void AudioStreamPlaybackSample::start(float p_from_pos) { } void AudioStreamPlaybackSample::stop() { - active = false; } bool AudioStreamPlaybackSample::is_playing() const { - return active; } int AudioStreamPlaybackSample::get_loop_count() const { - return 0; } float AudioStreamPlaybackSample::get_playback_position() const { - return float(offset >> MIX_FRAC_BITS) / base->mix_rate; } void AudioStreamPlaybackSample::seek(float p_time) { - if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) return; //no seeking in ima-adpcm @@ -92,7 +86,6 @@ void AudioStreamPlaybackSample::seek(float p_time) { template <class Depth, bool is_stereo, bool is_ima_adpcm> void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_dst, int64_t &offset, int32_t &increment, uint32_t amount, IMA_ADPCM_State *ima_adpcm) { - // this function will be compiled branchless by any decent compiler int32_t final, final_r, next, next_r; @@ -103,11 +96,9 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds pos <<= 1; if (is_ima_adpcm) { - int64_t sample_pos = pos + ima_adpcm[0].window_ofs; while (sample_pos > ima_adpcm[0].last_nibble) { - static const int16_t _ima_adpcm_step_table[89] = { 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, @@ -126,7 +117,6 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds }; for (int i = 0; i < (is_stereo ? 2 : 1); i++) { - int16_t nibble, diff, step; ima_adpcm[i].last_nibble++; @@ -161,7 +151,6 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds /* store loop if there */ if (ima_adpcm[i].last_nibble == ima_adpcm[i].loop_pos) { - ima_adpcm[i].loop_step_index = ima_adpcm[i].step_index; ima_adpcm[i].loop_predictor = ima_adpcm[i].predictor; } @@ -187,7 +176,6 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds } if (is_stereo) { - next = p_src[pos + 2]; next_r = p_src[pos + 3]; } else { @@ -220,7 +208,6 @@ void AudioStreamPlaybackSample::do_resample(const Depth *p_src, AudioFrame *p_ds } void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames) { - if (!base->data || !active) { for (int i = 0; i < p_frames; i++) { p_buffer[i] = AudioFrame(0, 0); @@ -279,7 +266,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in AudioFrame *dst_buff = p_buffer; if (format == AudioStreamSample::FORMAT_IMA_ADPCM) { - if (loop_format != AudioStreamSample::LOOP_DISABLED) { ima_adpcm[0].loop_pos = loop_begin_fp >> MIX_FRAC_BITS; ima_adpcm[1].loop_pos = loop_begin_fp >> MIX_FRAC_BITS; @@ -288,7 +274,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in } while (todo > 0) { - int64_t limit = 0; int32_t target = 0, aux = 0; @@ -311,7 +296,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in } else { /* check for sample not reaching beginning */ if (offset < 0) { - active = false; break; } @@ -343,7 +327,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in } else { /* no loop, check for end of sample */ if (offset >= length_fp) { - active = false; break; } @@ -369,7 +352,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in switch (base->format) { case AudioStreamSample::FORMAT_8_BITS: { - if (is_stereo) do_resample<int8_t, true, false>((int8_t *)data, dst_buff, offset, increment, target, ima_adpcm); else @@ -404,7 +386,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in } AudioStreamPlaybackSample::AudioStreamPlaybackSample() { - active = false; offset = 0; sign = 1; @@ -413,62 +394,49 @@ AudioStreamPlaybackSample::AudioStreamPlaybackSample() { ///////////////////// void AudioStreamSample::set_format(Format p_format) { - format = p_format; } AudioStreamSample::Format AudioStreamSample::get_format() const { - return format; } void AudioStreamSample::set_loop_mode(LoopMode p_loop_mode) { - loop_mode = p_loop_mode; } AudioStreamSample::LoopMode AudioStreamSample::get_loop_mode() const { - return loop_mode; } void AudioStreamSample::set_loop_begin(int p_frame) { - loop_begin = p_frame; } int AudioStreamSample::get_loop_begin() const { - return loop_begin; } void AudioStreamSample::set_loop_end(int p_frame) { - loop_end = p_frame; } int AudioStreamSample::get_loop_end() const { - return loop_end; } void AudioStreamSample::set_mix_rate(int p_hz) { - ERR_FAIL_COND(p_hz == 0); mix_rate = p_hz; } int AudioStreamSample::get_mix_rate() const { - return mix_rate; } void AudioStreamSample::set_stereo(bool p_enable) { - stereo = p_enable; } bool AudioStreamSample::is_stereo() const { - return stereo; } float AudioStreamSample::get_length() const { - int len = data_bytes; switch (format) { case AudioStreamSample::FORMAT_8_BITS: @@ -490,7 +458,6 @@ float AudioStreamSample::get_length() const { } void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) { - AudioServer::get_singleton()->lock(); if (data) { memfree(data); @@ -500,7 +467,6 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) { int datalen = p_data.size(); if (datalen) { - const uint8_t *r = p_data.ptr(); int alloc_len = datalen + DATA_PAD * 2; data = memalloc(alloc_len); //alloc with some padding for interpolation @@ -513,13 +479,11 @@ void AudioStreamSample::set_data(const Vector<uint8_t> &p_data) { AudioServer::get_singleton()->unlock(); } Vector<uint8_t> AudioStreamSample::get_data() const { - Vector<uint8_t> pv; if (data) { pv.resize(data_bytes); { - uint8_t *w = pv.ptrw(); uint8_t *dataptr = (uint8_t *)data; copymem(w, dataptr + DATA_PAD, data_bytes); @@ -610,7 +574,6 @@ Error AudioStreamSample::save_to_wav(const String &p_path) { } Ref<AudioStreamPlayback> AudioStreamSample::instance_playback() { - Ref<AudioStreamPlaybackSample> sample; sample.instance(); sample->base = Ref<AudioStreamSample>(this); @@ -618,12 +581,10 @@ Ref<AudioStreamPlayback> AudioStreamSample::instance_playback() { } String AudioStreamSample::get_stream_name() const { - return ""; } void AudioStreamSample::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamSample::set_data); ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamSample::get_data); diff --git a/scene/resources/audio_stream_sample.h b/scene/resources/audio_stream_sample.h index 0b46bc1c75..2bd358117c 100644 --- a/scene/resources/audio_stream_sample.h +++ b/scene/resources/audio_stream_sample.h @@ -36,7 +36,6 @@ class AudioStreamSample; class AudioStreamPlaybackSample : public AudioStreamPlayback { - GDCLASS(AudioStreamPlaybackSample, AudioStreamPlayback); enum { MIX_FRAC_BITS = 13, @@ -45,7 +44,6 @@ class AudioStreamPlaybackSample : public AudioStreamPlayback { }; struct IMA_ADPCM_State { - int16_t step_index; int32_t predictor; /* values at loop point */ diff --git a/scene/resources/bit_map.cpp b/scene/resources/bit_map.cpp index d45f36dfd1..27a5fee934 100644 --- a/scene/resources/bit_map.cpp +++ b/scene/resources/bit_map.cpp @@ -33,7 +33,6 @@ #include "core/io/image_loader.h" void BitMap::create(const Size2 &p_size) { - ERR_FAIL_COND(p_size.width < 1); ERR_FAIL_COND(p_size.height < 1); @@ -44,7 +43,6 @@ void BitMap::create(const Size2 &p_size) { } void BitMap::create_from_image_alpha(const Ref<Image> &p_image, float p_threshold) { - ERR_FAIL_COND(p_image.is_null() || p_image->empty()); Ref<Image> img = p_image->duplicate(); img->convert(Image::FORMAT_LA8); @@ -56,7 +54,6 @@ void BitMap::create_from_image_alpha(const Ref<Image> &p_image, float p_threshol uint8_t *w = bitmask.ptrw(); for (int i = 0; i < width * height; i++) { - int bbyte = i / 8; int bbit = i % 8; if (r[i * 2 + 1] / 255.0 > p_threshold) { @@ -66,14 +63,11 @@ void BitMap::create_from_image_alpha(const Ref<Image> &p_image, float p_threshol } void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) { - Rect2i current = Rect2i(0, 0, width, height).clip(p_rect); uint8_t *data = bitmask.ptrw(); for (int i = current.position.x; i < current.position.x + current.size.x; i++) { - for (int j = current.position.y; j < current.position.y + current.size.y; j++) { - int ofs = width * j + i; int bbyte = ofs / 8; int bbit = ofs % 8; @@ -91,7 +85,6 @@ void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) { } int BitMap::get_true_bit_count() const { - int ds = bitmask.size(); const uint8_t *d = bitmask.ptr(); int c = 0; @@ -99,7 +92,6 @@ int BitMap::get_true_bit_count() const { //fast, almost branchless version for (int i = 0; i < ds; i++) { - c += (d[i] & (1 << 7)) >> 7; c += (d[i] & (1 << 6)) >> 6; c += (d[i] & (1 << 5)) >> 5; @@ -114,7 +106,6 @@ int BitMap::get_true_bit_count() const { } void BitMap::set_bit(const Point2 &p_pos, bool p_value) { - int x = p_pos.x; int y = p_pos.y; @@ -136,7 +127,6 @@ void BitMap::set_bit(const Point2 &p_pos, bool p_value) { } bool BitMap::get_bit(const Point2 &p_pos) const { - int x = Math::fast_ftoi(p_pos.x); int y = Math::fast_ftoi(p_pos.y); ERR_FAIL_INDEX_V(x, width, false); @@ -150,12 +140,10 @@ bool BitMap::get_bit(const Point2 &p_pos) const { } Size2 BitMap::get_size() const { - return Size2(width, height); } void BitMap::_set_data(const Dictionary &p_d) { - ERR_FAIL_COND(!p_d.has("size")); ERR_FAIL_COND(!p_d.has("data")); @@ -164,7 +152,6 @@ void BitMap::_set_data(const Dictionary &p_d) { } Dictionary BitMap::_get_data() const { - Dictionary d; d["size"] = get_size(); d["data"] = bitmask; @@ -172,7 +159,6 @@ Dictionary BitMap::_get_data() const { } Vector<Vector2> BitMap::_march_square(const Rect2i &rect, const Point2i &start) const { - int stepx = 0; int stepy = 0; int prevx = 0; @@ -209,7 +195,6 @@ Vector<Vector2> BitMap::_march_square(const Rect2i &rect, const Point2i &start) } switch (sv) { - case 1: case 5: case 13: @@ -368,7 +353,6 @@ static Vector<Vector2> rdp(const Vector<Vector2> &v, float optimization) { } } if (dist > optimization) { - Vector<Vector2> left, right; left.resize(index); for (int i = 0; i < index; i++) { @@ -424,7 +408,6 @@ struct FillBitsStackEntry { }; static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_pos, const Rect2i &rect) { - // Using a custom stack to work iteratively to avoid stack overflow on big bitmaps Vector<FillBitsStackEntry> stack; // Tracking size since we won't be shrinking the stack vector @@ -494,7 +477,6 @@ static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_ } Vector<Vector<Vector2>> BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, float p_epsilon) const { - Rect2i r = Rect2i(0, 0, width, height).clip(p_rect); print_verbose("BitMap: Rect: " + r); @@ -507,7 +489,6 @@ Vector<Vector<Vector2>> BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, flo 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 (!fill->get_bit(Point2(j, i)) && get_bit(Point2(j, i))) { - fill_bits(this, fill, Point2i(j, i), r); Vector<Vector2> polygon = _march_square(r, Point2i(j, i)); @@ -529,7 +510,6 @@ Vector<Vector<Vector2>> BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, flo } void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) { - if (p_pixels == 0) { return; } @@ -553,7 +533,6 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) { for (int y = i - p_pixels; y <= i + p_pixels; y++) { for (int x = j - p_pixels; x <= j + p_pixels; x++) { - bool outside = false; 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)) { @@ -585,12 +564,10 @@ void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) { } void BitMap::shrink_mask(int p_pixels, const Rect2 &p_rect) { - grow_mask(-p_pixels, p_rect); } Array BitMap::_opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) const { - Vector<Vector<Vector2>> result = clip_opaque_to_polygons(p_rect, p_epsilon); // Convert result to bindable types @@ -598,7 +575,6 @@ Array BitMap::_opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) con Array result_array; result_array.resize(result.size()); for (int i = 0; i < result.size(); i++) { - const Vector<Vector2> &polygon = result[i]; PackedVector2Array polygon_array; @@ -618,7 +594,6 @@ Array BitMap::_opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) con } void BitMap::resize(const Size2 &p_new_size) { - Ref<BitMap> new_bitmap; new_bitmap.instance(); new_bitmap->create(p_new_size); @@ -636,7 +611,6 @@ void BitMap::resize(const Size2 &p_new_size) { } Ref<Image> BitMap::convert_to_image() const { - Ref<Image> image; image.instance(); image->create(width, height, false, Image::FORMAT_L8); @@ -650,7 +624,6 @@ Ref<Image> BitMap::convert_to_image() const { return image; } void BitMap::blit(const Vector2 &p_pos, const Ref<BitMap> &p_bitmap) { - int x = p_pos.x; int y = p_pos.y; int w = p_bitmap->get_size().width; @@ -672,7 +645,6 @@ void BitMap::blit(const Vector2 &p_pos, const Ref<BitMap> &p_bitmap) { } void BitMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("create", "size"), &BitMap::create); ClassDB::bind_method(D_METHOD("create_from_image_alpha", "image", "threshold"), &BitMap::create_from_image_alpha, DEFVAL(0.1)); @@ -694,7 +666,6 @@ void BitMap::_bind_methods() { } BitMap::BitMap() { - width = 0; height = 0; } diff --git a/scene/resources/bit_map.h b/scene/resources/bit_map.h index 05313a0cff..59f3b4dc3c 100644 --- a/scene/resources/bit_map.h +++ b/scene/resources/bit_map.h @@ -36,7 +36,6 @@ #include "core/resource.h" class BitMap : public Resource { - GDCLASS(BitMap, Resource); OBJ_SAVE_TYPE(BitMap); diff --git a/scene/resources/box_shape_3d.cpp b/scene/resources/box_shape_3d.cpp index 64c821a011..69339faf76 100644 --- a/scene/resources/box_shape_3d.cpp +++ b/scene/resources/box_shape_3d.cpp @@ -32,7 +32,6 @@ #include "servers/physics_server_3d.h" Vector<Vector3> BoxShape3D::get_debug_mesh_lines() { - Vector<Vector3> lines; AABB aabb; aabb.position = -get_extents(); @@ -53,13 +52,11 @@ real_t BoxShape3D::get_enclosing_radius() const { } void BoxShape3D::_update_shape() { - PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), extents); Shape3D::_update_shape(); } void BoxShape3D::set_extents(const Vector3 &p_extents) { - extents = p_extents; _update_shape(); notify_change_to_owners(); @@ -67,12 +64,10 @@ void BoxShape3D::set_extents(const Vector3 &p_extents) { } Vector3 BoxShape3D::get_extents() const { - return extents; } void BoxShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_extents", "extents"), &BoxShape3D::set_extents); ClassDB::bind_method(D_METHOD("get_extents"), &BoxShape3D::get_extents); @@ -81,6 +76,5 @@ void BoxShape3D::_bind_methods() { BoxShape3D::BoxShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_BOX)) { - set_extents(Vector3(1, 1, 1)); } diff --git a/scene/resources/box_shape_3d.h b/scene/resources/box_shape_3d.h index a93fd8d33a..e00b523815 100644 --- a/scene/resources/box_shape_3d.h +++ b/scene/resources/box_shape_3d.h @@ -34,7 +34,6 @@ #include "scene/resources/shape_3d.h" class BoxShape3D : public Shape3D { - GDCLASS(BoxShape3D, Shape3D); Vector3 extents; diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp index 5a3282478c..1054365459 100644 --- a/scene/resources/capsule_shape_2d.cpp +++ b/scene/resources/capsule_shape_2d.cpp @@ -34,7 +34,6 @@ #include "servers/rendering_server.h" Vector<Vector2> CapsuleShape2D::_get_points() const { - Vector<Vector2> points; for (int i = 0; i < 24; i++) { Vector2 ofs = Vector2(0, (i > 6 && i <= 18) ? -get_height() * 0.5 : get_height() * 0.5); @@ -48,29 +47,24 @@ Vector<Vector2> CapsuleShape2D::_get_points() const { } bool CapsuleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return Geometry::is_point_in_polygon(p_point, _get_points()); } void CapsuleShape2D::_update_shape() { - PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), Vector2(radius, height)); emit_changed(); } void CapsuleShape2D::set_radius(real_t p_radius) { - radius = p_radius; _update_shape(); } real_t CapsuleShape2D::get_radius() const { - return radius; } void CapsuleShape2D::set_height(real_t p_height) { - height = p_height; if (height < 0) height = 0; @@ -79,12 +73,10 @@ void CapsuleShape2D::set_height(real_t p_height) { } real_t CapsuleShape2D::get_height() const { - return height; } void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { - Vector<Vector2> points = _get_points(); Vector<Color> col; col.push_back(p_color); @@ -92,7 +84,6 @@ void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) { } Rect2 CapsuleShape2D::get_rect() const { - Vector2 he = Point2(get_radius(), get_radius() + get_height() * 0.5); Rect2 rect; rect.position = -he; @@ -105,7 +96,6 @@ real_t CapsuleShape2D::get_enclosing_radius() const { } void CapsuleShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleShape2D::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleShape2D::get_radius); @@ -118,7 +108,6 @@ void CapsuleShape2D::_bind_methods() { CapsuleShape2D::CapsuleShape2D() : Shape2D(PhysicsServer2D::get_singleton()->capsule_shape_create()) { - radius = 10; height = 20; _update_shape(); diff --git a/scene/resources/capsule_shape_3d.cpp b/scene/resources/capsule_shape_3d.cpp index da3ffcb306..28fc0d470c 100644 --- a/scene/resources/capsule_shape_3d.cpp +++ b/scene/resources/capsule_shape_3d.cpp @@ -32,7 +32,6 @@ #include "servers/physics_server_3d.h" Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() { - float radius = get_radius(); float height = get_height(); @@ -40,7 +39,6 @@ Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() { Vector3 d(0, height * 0.5, 0); for (int i = 0; i < 360; i++) { - float ra = Math::deg2rad((float)i); float rb = Math::deg2rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; @@ -53,7 +51,6 @@ Vector<Vector3> CapsuleShape3D::get_debug_mesh_lines() { points.push_back(Vector3(b.x, 0, b.y) - d); if (i % 90 == 0) { - points.push_back(Vector3(a.x, 0, a.y) + d); points.push_back(Vector3(a.x, 0, a.y) - d); } @@ -74,7 +71,6 @@ real_t CapsuleShape3D::get_enclosing_radius() const { } void CapsuleShape3D::_update_shape() { - Dictionary d; d["radius"] = radius; d["height"] = height; @@ -83,7 +79,6 @@ void CapsuleShape3D::_update_shape() { } void CapsuleShape3D::set_radius(float p_radius) { - radius = p_radius; _update_shape(); notify_change_to_owners(); @@ -91,12 +86,10 @@ void CapsuleShape3D::set_radius(float p_radius) { } float CapsuleShape3D::get_radius() const { - return radius; } void CapsuleShape3D::set_height(float p_height) { - height = p_height; _update_shape(); notify_change_to_owners(); @@ -104,12 +97,10 @@ void CapsuleShape3D::set_height(float p_height) { } float CapsuleShape3D::get_height() const { - return height; } void CapsuleShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CapsuleShape3D::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &CapsuleShape3D::get_radius); ClassDB::bind_method(D_METHOD("set_height", "height"), &CapsuleShape3D::set_height); @@ -121,7 +112,6 @@ void CapsuleShape3D::_bind_methods() { CapsuleShape3D::CapsuleShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CAPSULE)) { - radius = 1.0; height = 1.0; _update_shape(); diff --git a/scene/resources/capsule_shape_3d.h b/scene/resources/capsule_shape_3d.h index dca7a6c983..5892f97709 100644 --- a/scene/resources/capsule_shape_3d.h +++ b/scene/resources/capsule_shape_3d.h @@ -34,7 +34,6 @@ #include "scene/resources/shape_3d.h" class CapsuleShape3D : public Shape3D { - GDCLASS(CapsuleShape3D, Shape3D); float radius; float height; diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp index afb7597280..dc1bf3b185 100644 --- a/scene/resources/circle_shape_2d.cpp +++ b/scene/resources/circle_shape_2d.cpp @@ -34,29 +34,24 @@ #include "servers/rendering_server.h" bool CircleShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return p_point.length() < get_radius() + p_tolerance; } void CircleShape2D::_update_shape() { - PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), radius); emit_changed(); } void CircleShape2D::set_radius(real_t p_radius) { - radius = p_radius; _update_shape(); } real_t CircleShape2D::get_radius() const { - return radius; } void CircleShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CircleShape2D::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &CircleShape2D::get_radius); @@ -75,10 +70,8 @@ real_t CircleShape2D::get_enclosing_radius() const { } void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) { - Vector<Vector2> points; for (int i = 0; i < 24; i++) { - points.push_back(Vector2(Math::cos(i * Math_PI * 2 / 24.0), Math::sin(i * Math_PI * 2 / 24.0)) * get_radius()); } @@ -89,7 +82,6 @@ void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) { CircleShape2D::CircleShape2D() : Shape2D(PhysicsServer2D::get_singleton()->circle_shape_create()) { - radius = 10; _update_shape(); } diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index c8fec3b72d..9cc8ea0fac 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -34,7 +34,6 @@ #include "servers/rendering_server.h" 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) @@ -51,18 +50,15 @@ bool ConcavePolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, do } void ConcavePolygonShape2D::set_segments(const Vector<Vector2> &p_segments) { - PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), p_segments); emit_changed(); } Vector<Vector2> ConcavePolygonShape2D::get_segments() const { - return PhysicsServer2D::get_singleton()->shape_get_data(get_rid()); } 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) @@ -75,7 +71,6 @@ 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) @@ -105,7 +100,6 @@ real_t ConcavePolygonShape2D::get_enclosing_radius() const { } void ConcavePolygonShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_segments", "segments"), &ConcavePolygonShape2D::set_segments); ClassDB::bind_method(D_METHOD("get_segments"), &ConcavePolygonShape2D::get_segments); diff --git a/scene/resources/concave_polygon_shape_3d.cpp b/scene/resources/concave_polygon_shape_3d.cpp index 42e06a49b6..7315945c03 100644 --- a/scene/resources/concave_polygon_shape_3d.cpp +++ b/scene/resources/concave_polygon_shape_3d.cpp @@ -33,7 +33,6 @@ #include "servers/physics_server_3d.h" Vector<Vector3> ConcavePolygonShape3D::get_debug_mesh_lines() { - Set<DrawEdge> edges; Vector<Vector3> data = get_faces(); @@ -43,9 +42,7 @@ Vector<Vector3> ConcavePolygonShape3D::get_debug_mesh_lines() { const Vector3 *r = data.ptr(); for (int i = 0; i < datalen; i += 3) { - for (int j = 0; j < 3; j++) { - DrawEdge de(r[i + j], r[i + ((j + 1) % 3)]); edges.insert(de); } @@ -55,7 +52,6 @@ Vector<Vector3> ConcavePolygonShape3D::get_debug_mesh_lines() { points.resize(edges.size() * 2); int idx = 0; for (Set<DrawEdge>::Element *E = edges.front(); E; E = E->next()) { - points.write[idx + 0] = E->get().a; points.write[idx + 1] = E->get().b; idx += 2; @@ -79,18 +75,15 @@ void ConcavePolygonShape3D::_update_shape() { } void ConcavePolygonShape3D::set_faces(const Vector<Vector3> &p_faces) { - PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), p_faces); notify_change_to_owners(); } Vector<Vector3> ConcavePolygonShape3D::get_faces() const { - return PhysicsServer3D::get_singleton()->shape_get_data(get_shape()); } void ConcavePolygonShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_faces", "faces"), &ConcavePolygonShape3D::set_faces); ClassDB::bind_method(D_METHOD("get_faces"), &ConcavePolygonShape3D::get_faces); ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "set_faces", "get_faces"); @@ -98,6 +91,5 @@ void ConcavePolygonShape3D::_bind_methods() { ConcavePolygonShape3D::ConcavePolygonShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CONCAVE_POLYGON)) { - //set_planes(Vector3(1,1,1)); } diff --git a/scene/resources/concave_polygon_shape_3d.h b/scene/resources/concave_polygon_shape_3d.h index b4e96c662f..3646724131 100644 --- a/scene/resources/concave_polygon_shape_3d.h +++ b/scene/resources/concave_polygon_shape_3d.h @@ -34,11 +34,9 @@ #include "scene/resources/shape_3d.h" class ConcavePolygonShape3D : public Shape3D { - GDCLASS(ConcavePolygonShape3D, Shape3D); struct DrawEdge { - Vector3 a; Vector3 b; bool operator<(const DrawEdge &p_edge) const { diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index 6b1ddec507..59b2e3a9cd 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -35,12 +35,10 @@ #include "servers/rendering_server.h" bool ConvexPolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return Geometry::is_point_in_polygon(p_point, points); } void ConvexPolygonShape2D::_update_shape() { - Vector<Vector2> final_points = points; if (Geometry::is_polygon_clockwise(final_points)) { //needs to be counter clockwise final_points.invert(); @@ -50,26 +48,22 @@ void ConvexPolygonShape2D::_update_shape() { } void ConvexPolygonShape2D::set_point_cloud(const Vector<Vector2> &p_points) { - Vector<Point2> hull = Geometry::convex_hull_2d(p_points); ERR_FAIL_COND(hull.size() < 3); set_points(hull); } void ConvexPolygonShape2D::set_points(const Vector<Vector2> &p_points) { - points = p_points; _update_shape(); } Vector<Vector2> ConvexPolygonShape2D::get_points() const { - return points; } void ConvexPolygonShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_point_cloud", "point_cloud"), &ConvexPolygonShape2D::set_point_cloud); ClassDB::bind_method(D_METHOD("set_points", "points"), &ConvexPolygonShape2D::set_points); ClassDB::bind_method(D_METHOD("get_points"), &ConvexPolygonShape2D::get_points); @@ -78,14 +72,12 @@ void ConvexPolygonShape2D::_bind_methods() { } void ConvexPolygonShape2D::draw(const RID &p_to_rid, const Color &p_color) { - Vector<Color> col; col.push_back(p_color); RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col); } Rect2 ConvexPolygonShape2D::get_rect() const { - Rect2 rect; for (int i = 0; i < points.size(); i++) { if (i == 0) diff --git a/scene/resources/convex_polygon_shape_3d.cpp b/scene/resources/convex_polygon_shape_3d.cpp index ec9ab68015..e52df73663 100644 --- a/scene/resources/convex_polygon_shape_3d.cpp +++ b/scene/resources/convex_polygon_shape_3d.cpp @@ -33,11 +33,9 @@ #include "servers/physics_server_3d.h" Vector<Vector3> ConvexPolygonShape3D::get_debug_mesh_lines() { - Vector<Vector3> points = get_points(); if (points.size() > 3) { - Vector<Vector3> varr = Variant(points); Geometry::MeshData md; Error err = QuickHull::build(varr, md); @@ -66,25 +64,21 @@ real_t ConvexPolygonShape3D::get_enclosing_radius() const { } void ConvexPolygonShape3D::_update_shape() { - PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), points); Shape3D::_update_shape(); } void ConvexPolygonShape3D::set_points(const Vector<Vector3> &p_points) { - points = p_points; _update_shape(); notify_change_to_owners(); } Vector<Vector3> ConvexPolygonShape3D::get_points() const { - return points; } void ConvexPolygonShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_points", "points"), &ConvexPolygonShape3D::set_points); ClassDB::bind_method(D_METHOD("get_points"), &ConvexPolygonShape3D::get_points); diff --git a/scene/resources/convex_polygon_shape_3d.h b/scene/resources/convex_polygon_shape_3d.h index 51e4c8eb0b..0e3dde47a5 100644 --- a/scene/resources/convex_polygon_shape_3d.h +++ b/scene/resources/convex_polygon_shape_3d.h @@ -34,7 +34,6 @@ #include "scene/resources/shape_3d.h" class ConvexPolygonShape3D : public Shape3D { - GDCLASS(ConvexPolygonShape3D, Shape3D); Vector<Vector3> points; diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index ae705a47e8..d8f0640242 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -83,7 +83,6 @@ int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, T } } else { - int i = get_index(p_pos.x); if (i == 0 && p_pos.x < _points[0].pos.x) { @@ -106,7 +105,6 @@ int Curve::add_point(Vector2 p_pos, real_t left_tangent, real_t right_tangent, T } int Curve::get_index(real_t offset) const { - // Lower-bound float binary search int imin = 0; @@ -136,7 +134,6 @@ int Curve::get_index(real_t offset) const { } void Curve::clean_dupes() { - bool dirty = false; for (int i = 1; i < _points.size(); ++i) { @@ -254,7 +251,6 @@ Curve::Point Curve::get_point(int p_index) const { } void Curve::update_auto_tangents(int i) { - Point &p = _points.write[i]; if (i > 0) { @@ -324,7 +320,6 @@ real_t Curve::interpolate(real_t offset) const { } real_t Curve::interpolate_local_nocheck(int index, real_t local_offset) const { - const Point a = _points[index]; const Point b = _points[index + 1]; @@ -362,13 +357,11 @@ void Curve::mark_dirty() { } Array Curve::get_data() const { - Array output; const unsigned int ELEMS = 5; output.resize(_points.size() * ELEMS); for (int j = 0; j < _points.size(); ++j) { - const Point p = _points[j]; int i = j * ELEMS; @@ -406,7 +399,6 @@ void Curve::set_data(Array input) { _points.resize(input.size() / ELEMS); for (int j = 0; j < _points.size(); ++j) { - Point &p = _points.write[j]; int i = j * ELEMS; @@ -486,7 +478,6 @@ real_t Curve::interpolate_baked(real_t offset) { void Curve::ensure_default_setup(float p_min, float p_max) { if (_points.size() == 0 && _min_value == 0 && _max_value == 1) { - add_point(Vector2(0, 1)); add_point(Vector2(1, 1)); set_min_value(p_min); @@ -495,7 +486,6 @@ void Curve::ensure_default_setup(float p_min, float p_max) { } void Curve::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_point_count"), &Curve::get_point_count); ClassDB::bind_method(D_METHOD("add_point", "position", "left_tangent", "right_tangent", "left_mode", "right_mode"), &Curve::add_point, DEFVAL(0), DEFVAL(0), DEFVAL(TANGENT_FREE), DEFVAL(TANGENT_FREE)); ClassDB::bind_method(D_METHOD("remove_point", "index"), &Curve::remove_point); @@ -537,11 +527,9 @@ void Curve::_bind_methods() { } int Curve2D::get_point_count() const { - return points.size(); } void Curve2D::add_point(const Vector2 &p_pos, const Vector2 &p_in, const Vector2 &p_out, int p_atpos) { - Point n; n.pos = p_pos; n.in = p_in; @@ -556,7 +544,6 @@ void Curve2D::add_point(const Vector2 &p_pos, const Vector2 &p_in, const Vector2 } void Curve2D::set_point_position(int p_index, const Vector2 &p_pos) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].pos = p_pos; @@ -564,13 +551,11 @@ void Curve2D::set_point_position(int p_index, const Vector2 &p_pos) { emit_signal(CoreStringNames::get_singleton()->changed); } Vector2 Curve2D::get_point_position(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), Vector2()); return points[p_index].pos; } void Curve2D::set_point_in(int p_index, const Vector2 &p_in) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].in = p_in; @@ -578,13 +563,11 @@ void Curve2D::set_point_in(int p_index, const Vector2 &p_in) { emit_signal(CoreStringNames::get_singleton()->changed); } Vector2 Curve2D::get_point_in(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), Vector2()); return points[p_index].in; } void Curve2D::set_point_out(int p_index, const Vector2 &p_out) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].out = p_out; @@ -593,13 +576,11 @@ void Curve2D::set_point_out(int p_index, const Vector2 &p_out) { } Vector2 Curve2D::get_point_out(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), Vector2()); return points[p_index].out; } void Curve2D::remove_point(int p_index) { - ERR_FAIL_INDEX(p_index, points.size()); points.remove(p_index); baked_cache_dirty = true; @@ -615,7 +596,6 @@ void Curve2D::clear_points() { } Vector2 Curve2D::interpolate(int p_index, float p_offset) const { - int pc = points.size(); ERR_FAIL_COND_V(pc == 0, Vector2()); @@ -633,7 +613,6 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const { } Vector2 Curve2D::interpolatef(real_t p_findex) const { - if (p_findex < 0) p_findex = 0; else if (p_findex >= points.size()) @@ -643,7 +622,6 @@ Vector2 Curve2D::interpolatef(real_t p_findex) const { } void Curve2D::_bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_max_depth, float p_tol) const { - float mp = p_begin + (p_end - p_begin) * 0.5; Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b); Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b); @@ -654,7 +632,6 @@ void Curve2D::_bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float float dp = na.dot(nb); if (dp < Math::cos(Math::deg2rad(p_tol))) { - r_bake[mp] = mid; } @@ -665,7 +642,6 @@ void Curve2D::_bake_segment2d(Map<float, Vector2> &r_bake, float p_begin, float } void Curve2D::_bake() const { - if (!baked_cache_dirty) return; @@ -678,7 +654,6 @@ void Curve2D::_bake() const { } if (points.size() == 1) { - baked_point_cache.resize(1); baked_point_cache.set(0, points[0].pos); return; @@ -690,12 +665,10 @@ void Curve2D::_bake() const { pointlist.push_back(pos); //start always from origin for (int i = 0; i < points.size() - 1; i++) { - float step = 0.1; // at least 10 substeps ought to be enough? float p = 0; while (p < 1.0) { - float np = p + step; if (np > 1.0) np = 1.0; @@ -713,7 +686,6 @@ void Curve2D::_bake() const { float mid = low + (hi - low) * 0.5; for (int j = 0; j < iterations; j++) { - 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); @@ -728,7 +700,6 @@ void Curve2D::_bake() const { p = mid; pointlist.push_back(pos); } else { - p = np; } } @@ -745,21 +716,18 @@ void Curve2D::_bake() const { int idx = 0; for (List<Vector2>::Element *E = pointlist.front(); E; E = E->next()) { - w[idx] = E->get(); idx++; } } float Curve2D::get_baked_length() const { - if (baked_cache_dirty) _bake(); return baked_max_ofs; } Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { - if (baked_cache_dirty) _bake(); @@ -791,7 +759,6 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { } if (p_cubic) { - Vector2 pre = idx > 0 ? r[idx - 1] : r[idx]; Vector2 post = (idx < (bpc - 2)) ? r[idx + 2] : r[idx + 1]; return r[idx].cubic_interpolate(r[idx + 1], pre, post, frac); @@ -801,7 +768,6 @@ Vector2 Curve2D::interpolate_baked(float p_offset, bool p_cubic) const { } PackedVector2Array Curve2D::get_baked_points() const { - if (baked_cache_dirty) _bake(); @@ -809,14 +775,12 @@ PackedVector2Array Curve2D::get_baked_points() const { } void Curve2D::set_bake_interval(float p_tolerance) { - bake_interval = p_tolerance; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } float Curve2D::get_bake_interval() const { - return bake_interval; } @@ -896,7 +860,6 @@ float Curve2D::get_closest_offset(const Vector2 &p_to_point) const { } Dictionary Curve2D::_get_data() const { - Dictionary dc; PackedVector2Array d; @@ -904,7 +867,6 @@ Dictionary Curve2D::_get_data() const { Vector2 *w = d.ptrw(); for (int i = 0; i < points.size(); i++) { - w[i * 3 + 0] = points[i].in; w[i * 3 + 1] = points[i].out; w[i * 3 + 2] = points[i].pos; @@ -915,7 +877,6 @@ Dictionary Curve2D::_get_data() const { return dc; } void Curve2D::_set_data(const Dictionary &p_data) { - ERR_FAIL_COND(!p_data.has("points")); PackedVector2Array rp = p_data["points"]; @@ -925,7 +886,6 @@ void Curve2D::_set_data(const Dictionary &p_data) { const Vector2 *r = rp.ptr(); for (int i = 0; i < points.size(); i++) { - points.write[i].in = r[i * 3 + 0]; points.write[i].out = r[i * 3 + 1]; points.write[i].pos = r[i * 3 + 2]; @@ -935,7 +895,6 @@ void Curve2D::_set_data(const Dictionary &p_data) { } PackedVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) const { - PackedVector2Array tess; if (points.size() == 0) { @@ -947,7 +906,6 @@ PackedVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) cons int pc = 1; for (int i = 0; i < points.size() - 1; i++) { - _bake_segment2d(midpoints.write[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); pc++; pc += midpoints[i].size(); @@ -959,9 +917,7 @@ PackedVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) cons int pidx = 0; for (int i = 0; i < points.size() - 1; i++) { - for (Map<float, Vector2>::Element *E = midpoints[i].front(); E; E = E->next()) { - pidx++; bpw[pidx] = E->get(); } @@ -974,7 +930,6 @@ PackedVector2Array Curve2D::tessellate(int p_max_stages, float p_tolerance) cons } void Curve2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_point_count"), &Curve2D::get_point_count); ClassDB::bind_method(D_METHOD("add_point", "position", "in", "out", "at_position"), &Curve2D::add_point, DEFVAL(Vector2()), DEFVAL(Vector2()), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("set_point_position", "idx", "position"), &Curve2D::set_point_position); @@ -1022,11 +977,9 @@ Curve2D::Curve2D() { /***********************************************************************************/ int Curve3D::get_point_count() const { - return points.size(); } void Curve3D::add_point(const Vector3 &p_pos, const Vector3 &p_in, const Vector3 &p_out, int p_atpos) { - Point n; n.pos = p_pos; n.in = p_in; @@ -1040,7 +993,6 @@ void Curve3D::add_point(const Vector3 &p_pos, const Vector3 &p_in, const Vector3 emit_signal(CoreStringNames::get_singleton()->changed); } void Curve3D::set_point_position(int p_index, const Vector3 &p_pos) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].pos = p_pos; @@ -1048,13 +1000,11 @@ void Curve3D::set_point_position(int p_index, const Vector3 &p_pos) { emit_signal(CoreStringNames::get_singleton()->changed); } Vector3 Curve3D::get_point_position(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), Vector3()); return points[p_index].pos; } void Curve3D::set_point_tilt(int p_index, float p_tilt) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].tilt = p_tilt; @@ -1062,13 +1012,11 @@ void Curve3D::set_point_tilt(int p_index, float p_tilt) { emit_signal(CoreStringNames::get_singleton()->changed); } float Curve3D::get_point_tilt(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), 0); return points[p_index].tilt; } void Curve3D::set_point_in(int p_index, const Vector3 &p_in) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].in = p_in; @@ -1076,13 +1024,11 @@ void Curve3D::set_point_in(int p_index, const Vector3 &p_in) { emit_signal(CoreStringNames::get_singleton()->changed); } Vector3 Curve3D::get_point_in(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), Vector3()); return points[p_index].in; } void Curve3D::set_point_out(int p_index, const Vector3 &p_out) { - ERR_FAIL_INDEX(p_index, points.size()); points.write[p_index].out = p_out; @@ -1091,13 +1037,11 @@ void Curve3D::set_point_out(int p_index, const Vector3 &p_out) { } Vector3 Curve3D::get_point_out(int p_index) const { - ERR_FAIL_INDEX_V(p_index, points.size(), Vector3()); return points[p_index].out; } void Curve3D::remove_point(int p_index) { - ERR_FAIL_INDEX(p_index, points.size()); points.remove(p_index); baked_cache_dirty = true; @@ -1105,7 +1049,6 @@ void Curve3D::remove_point(int p_index) { } void Curve3D::clear_points() { - if (!points.empty()) { points.clear(); baked_cache_dirty = true; @@ -1114,7 +1057,6 @@ void Curve3D::clear_points() { } Vector3 Curve3D::interpolate(int p_index, float p_offset) const { - int pc = points.size(); ERR_FAIL_COND_V(pc == 0, Vector3()); @@ -1132,7 +1074,6 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const { } Vector3 Curve3D::interpolatef(real_t p_findex) const { - if (p_findex < 0) p_findex = 0; else if (p_findex >= points.size()) @@ -1142,7 +1083,6 @@ Vector3 Curve3D::interpolatef(real_t p_findex) const { } void Curve3D::_bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float p_end, const Vector3 &p_a, const Vector3 &p_out, const Vector3 &p_b, const Vector3 &p_in, int p_depth, int p_max_depth, float p_tol) const { - float mp = p_begin + (p_end - p_begin) * 0.5; Vector3 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b); Vector3 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b); @@ -1153,7 +1093,6 @@ void Curve3D::_bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float float dp = na.dot(nb); if (dp < Math::cos(Math::deg2rad(p_tol))) { - r_bake[mp] = mid; } if (p_depth < p_max_depth) { @@ -1163,7 +1102,6 @@ void Curve3D::_bake_segment3d(Map<float, Vector3> &r_bake, float p_begin, float } void Curve3D::_bake() const { - if (!baked_cache_dirty) return; @@ -1178,14 +1116,12 @@ void Curve3D::_bake() const { } if (points.size() == 1) { - baked_point_cache.resize(1); baked_point_cache.set(0, points[0].pos); baked_tilt_cache.resize(1); baked_tilt_cache.set(0, points[0].tilt); if (up_vector_enabled) { - baked_up_vector_cache.resize(1); baked_up_vector_cache.set(0, Vector3(0, 1, 0)); } else @@ -1199,12 +1135,10 @@ void Curve3D::_bake() const { pointlist.push_back(Plane(pos, points[0].tilt)); for (int i = 0; i < points.size() - 1; i++) { - float step = 0.1; // at least 10 substeps ought to be enough? float p = 0; while (p < 1.0) { - float np = p + step; if (np > 1.0) np = 1.0; @@ -1222,7 +1156,6 @@ void Curve3D::_bake() const { float mid = low + (hi - low) * 0.5; for (int j = 0; j < iterations; j++) { - 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); @@ -1240,7 +1173,6 @@ void Curve3D::_bake() const { post.d = Math::lerp(points[i].tilt, points[i + 1].tilt, mid); pointlist.push_back(post); } else { - p = np; } } @@ -1272,7 +1204,6 @@ void Curve3D::_bake() const { Vector3 prev_forward = Vector3(0, 0, 1); for (List<Plane>::Element *E = pointlist.front(); E; E = E->next()) { - w[idx] = E->get().normal; wt[idx] = E->get().d; @@ -1310,14 +1241,12 @@ void Curve3D::_bake() const { } float Curve3D::get_baked_length() const { - if (baked_cache_dirty) _bake(); return baked_max_ofs; } Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { - if (baked_cache_dirty) _bake(); @@ -1349,7 +1278,6 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { } if (p_cubic) { - Vector3 pre = idx > 0 ? r[idx - 1] : r[idx]; Vector3 post = (idx < (bpc - 2)) ? r[idx + 2] : r[idx + 1]; return r[idx].cubic_interpolate(r[idx + 1], pre, post, frac); @@ -1359,7 +1287,6 @@ Vector3 Curve3D::interpolate_baked(float p_offset, bool p_cubic) const { } float Curve3D::interpolate_baked_tilt(float p_offset) const { - if (baked_cache_dirty) _bake(); @@ -1394,7 +1321,6 @@ 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) _bake(); @@ -1438,7 +1364,6 @@ Vector3 Curve3D::interpolate_baked_up_vector(float p_offset, bool p_apply_tilt) } PackedVector3Array Curve3D::get_baked_points() const { - if (baked_cache_dirty) _bake(); @@ -1446,7 +1371,6 @@ PackedVector3Array Curve3D::get_baked_points() const { } PackedFloat32Array Curve3D::get_baked_tilts() const { - if (baked_cache_dirty) _bake(); @@ -1454,7 +1378,6 @@ PackedFloat32Array Curve3D::get_baked_tilts() const { } PackedVector3Array Curve3D::get_baked_up_vectors() const { - if (baked_cache_dirty) _bake(); @@ -1537,31 +1460,26 @@ float Curve3D::get_closest_offset(const Vector3 &p_to_point) const { } void Curve3D::set_bake_interval(float p_tolerance) { - bake_interval = p_tolerance; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } float Curve3D::get_bake_interval() const { - return bake_interval; } void Curve3D::set_up_vector_enabled(bool p_enable) { - up_vector_enabled = p_enable; baked_cache_dirty = true; emit_signal(CoreStringNames::get_singleton()->changed); } bool Curve3D::is_up_vector_enabled() const { - return up_vector_enabled; } Dictionary Curve3D::_get_data() const { - Dictionary dc; PackedVector3Array d; @@ -1572,7 +1490,6 @@ Dictionary Curve3D::_get_data() const { real_t *wt = t.ptrw(); for (int i = 0; i < points.size(); i++) { - w[i * 3 + 0] = points[i].in; w[i * 3 + 1] = points[i].out; w[i * 3 + 2] = points[i].pos; @@ -1585,7 +1502,6 @@ Dictionary Curve3D::_get_data() const { return dc; } void Curve3D::_set_data(const Dictionary &p_data) { - ERR_FAIL_COND(!p_data.has("points")); ERR_FAIL_COND(!p_data.has("tilts")); @@ -1598,7 +1514,6 @@ void Curve3D::_set_data(const Dictionary &p_data) { const real_t *rt = rtl.ptr(); for (int i = 0; i < points.size(); i++) { - points.write[i].in = r[i * 3 + 0]; points.write[i].out = r[i * 3 + 1]; points.write[i].pos = r[i * 3 + 2]; @@ -1609,7 +1524,6 @@ void Curve3D::_set_data(const Dictionary &p_data) { } PackedVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) const { - PackedVector3Array tess; if (points.size() == 0) { @@ -1621,7 +1535,6 @@ PackedVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) cons int pc = 1; for (int i = 0; i < points.size() - 1; i++) { - _bake_segment3d(midpoints.write[i], 0, 1, points[i].pos, points[i].out, points[i + 1].pos, points[i + 1].in, 0, p_max_stages, p_tolerance); pc++; pc += midpoints[i].size(); @@ -1633,9 +1546,7 @@ PackedVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) cons int pidx = 0; for (int i = 0; i < points.size() - 1; i++) { - for (Map<float, Vector3>::Element *E = midpoints[i].front(); E; E = E->next()) { - pidx++; bpw[pidx] = E->get(); } @@ -1648,7 +1559,6 @@ PackedVector3Array Curve3D::tessellate(int p_max_stages, float p_tolerance) cons } void Curve3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_point_count"), &Curve3D::get_point_count); ClassDB::bind_method(D_METHOD("add_point", "position", "in", "out", "at_position"), &Curve3D::add_point, DEFVAL(Vector3()), DEFVAL(Vector3()), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("set_point_position", "idx", "position"), &Curve3D::set_point_position); diff --git a/scene/resources/curve.h b/scene/resources/curve.h index 7dcbf1ceff..57ddaf897d 100644 --- a/scene/resources/curve.h +++ b/scene/resources/curve.h @@ -68,7 +68,6 @@ public: real_t p_right = 0, TangentMode p_left_mode = TANGENT_FREE, TangentMode p_right_mode = TANGENT_FREE) { - pos = p_pos; left_tangent = p_left; right_tangent = p_right; @@ -149,11 +148,9 @@ private: VARIANT_ENUM_CAST(Curve::TangentMode) class Curve2D : public Resource { - GDCLASS(Curve2D, Resource); struct Point { - Vector2 in; Vector2 out; Vector2 pos; @@ -162,7 +159,6 @@ class Curve2D : public Resource { Vector<Point> points; struct BakedPoint { - float ofs; Vector2 point; }; @@ -212,11 +208,9 @@ public: }; class Curve3D : public Resource { - GDCLASS(Curve3D, Resource); struct Point { - Vector3 in; Vector3 out; Vector3 pos; @@ -228,7 +222,6 @@ class Curve3D : public Resource { Vector<Point> points; struct BakedPoint { - float ofs; Vector3 point; }; diff --git a/scene/resources/cylinder_shape_3d.cpp b/scene/resources/cylinder_shape_3d.cpp index 19f0542818..44786d6025 100644 --- a/scene/resources/cylinder_shape_3d.cpp +++ b/scene/resources/cylinder_shape_3d.cpp @@ -32,7 +32,6 @@ #include "servers/physics_server_3d.h" Vector<Vector3> CylinderShape3D::get_debug_mesh_lines() { - float radius = get_radius(); float height = get_height(); @@ -40,7 +39,6 @@ Vector<Vector3> CylinderShape3D::get_debug_mesh_lines() { Vector3 d(0, height * 0.5, 0); for (int i = 0; i < 360; i++) { - float ra = Math::deg2rad((float)i); float rb = Math::deg2rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius; @@ -53,7 +51,6 @@ Vector<Vector3> CylinderShape3D::get_debug_mesh_lines() { points.push_back(Vector3(b.x, 0, b.y) - d); if (i % 90 == 0) { - points.push_back(Vector3(a.x, 0, a.y) + d); points.push_back(Vector3(a.x, 0, a.y) - d); } @@ -67,7 +64,6 @@ real_t CylinderShape3D::get_enclosing_radius() const { } void CylinderShape3D::_update_shape() { - Dictionary d; d["radius"] = radius; d["height"] = height; @@ -76,7 +72,6 @@ void CylinderShape3D::_update_shape() { } void CylinderShape3D::set_radius(float p_radius) { - radius = p_radius; _update_shape(); notify_change_to_owners(); @@ -84,12 +79,10 @@ void CylinderShape3D::set_radius(float p_radius) { } float CylinderShape3D::get_radius() const { - return radius; } void CylinderShape3D::set_height(float p_height) { - height = p_height; _update_shape(); notify_change_to_owners(); @@ -97,12 +90,10 @@ void CylinderShape3D::set_height(float p_height) { } float CylinderShape3D::get_height() const { - return height; } void CylinderShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &CylinderShape3D::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &CylinderShape3D::get_radius); ClassDB::bind_method(D_METHOD("set_height", "height"), &CylinderShape3D::set_height); @@ -114,7 +105,6 @@ void CylinderShape3D::_bind_methods() { CylinderShape3D::CylinderShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CYLINDER)) { - radius = 1.0; height = 2.0; _update_shape(); diff --git a/scene/resources/cylinder_shape_3d.h b/scene/resources/cylinder_shape_3d.h index 7b37f733e0..23d206cbab 100644 --- a/scene/resources/cylinder_shape_3d.h +++ b/scene/resources/cylinder_shape_3d.h @@ -34,7 +34,6 @@ #include "scene/resources/shape_3d.h" class CylinderShape3D : public Shape3D { - GDCLASS(CylinderShape3D, Shape3D); float radius; float height; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index a1e8bf51bd..9f7fdc2316 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -45,13 +45,11 @@ static float scale = 1; template <class T> static Ref<StyleBoxTexture> make_stylebox(T p_src, float p_left, float p_top, float p_right, float p_botton, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_botton = -1, bool p_draw_center = true) { - Ref<ImageTexture> texture; if (tex_cache->has(p_src)) { texture = (*tex_cache)[p_src]; } else { - texture = Ref<ImageTexture>(memnew(ImageTexture)); Ref<Image> img = memnew(Image(p_src)); @@ -89,7 +87,6 @@ static Ref<StyleBoxTexture> make_stylebox(T p_src, float p_left, float p_top, fl } static Ref<StyleBoxTexture> sb_expand(Ref<StyleBoxTexture> p_sbox, float p_left, float p_top, float p_right, float p_botton) { - p_sbox->set_expand_margin_size(MARGIN_LEFT, p_left * scale); p_sbox->set_expand_margin_size(MARGIN_TOP, p_top * scale); p_sbox->set_expand_margin_size(MARGIN_RIGHT, p_right * scale); @@ -99,7 +96,6 @@ static Ref<StyleBoxTexture> sb_expand(Ref<StyleBoxTexture> p_sbox, float p_left, template <class T> static Ref<Texture2D> make_icon(T p_src) { - Ref<ImageTexture> texture(memnew(ImageTexture)); Ref<Image> img = memnew(Image(p_src)); if (scale > 1) { @@ -121,7 +117,6 @@ static Ref<Texture2D> make_icon(T p_src) { } static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_charcount, const int *p_char_rects, int p_kerning_count, const int *p_kernings, int p_w, int p_h, const unsigned char *p_img) { - Ref<BitmapFont> font(memnew(BitmapFont)); Ref<Image> image = memnew(Image(p_img)); @@ -131,7 +126,6 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_charcount, co font->add_texture(tex); for (int i = 0; i < p_charcount; i++) { - const int *c = &p_char_rects[i * 8]; int chr = c[0]; @@ -147,7 +141,6 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_charcount, co } for (int i = 0; i < p_kerning_count; i++) { - font->add_kerning_pair(p_kernings[i * 3 + 0], p_kernings[i * 3 + 1], p_kernings[i * 3 + 2]); } @@ -158,7 +151,6 @@ static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_charcount, co } static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_botton = -1) { - Ref<StyleBox> style(memnew(StyleBoxEmpty)); style->set_default_margin(MARGIN_LEFT, p_margin_left * scale); @@ -170,7 +162,6 @@ static Ref<StyleBox> make_empty_stylebox(float p_margin_left = -1, float p_margi } void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const Ref<Font> &large_font, Ref<Texture2D> &default_icon, Ref<StyleBox> &default_style, float p_scale) { - scale = p_scale; tex_cache = memnew(TexCacheMap); @@ -867,7 +858,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const } void make_default_theme(bool p_hidpi, Ref<Font> p_font) { - Ref<Theme> t; t.instance(); @@ -891,7 +881,6 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) { } void clear_default_theme() { - Theme::set_project_default(nullptr); Theme::set_default(nullptr); Theme::set_default_icon(nullptr); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 442151de36..5d2d690084 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -46,7 +46,6 @@ bool DynamicFontData::CacheID::operator<(CacheID right) const { } Ref<DynamicFontAtSize> DynamicFontData::_get_dynamic_font_at_size(CacheID p_cache_id) { - if (size_cache.has(p_cache_id)) { return Ref<DynamicFontAtSize>(size_cache[p_cache_id]); } @@ -65,13 +64,11 @@ Ref<DynamicFontAtSize> DynamicFontData::_get_dynamic_font_at_size(CacheID p_cach } void DynamicFontData::set_font_ptr(const uint8_t *p_font_mem, int p_font_mem_size) { - font_mem = p_font_mem; font_mem_size = p_font_mem_size; } void DynamicFontData::set_font_path(const String &p_path) { - font_path = p_path; } @@ -80,7 +77,6 @@ String DynamicFontData::get_font_path() const { } void DynamicFontData::set_force_autohinter(bool p_force) { - force_autohinter = p_force; } @@ -103,7 +99,6 @@ void DynamicFontData::_bind_methods() { } DynamicFontData::DynamicFontData() { - antialiased = true; force_autohinter = false; hinting = DynamicFontData::HINTING_NORMAL; @@ -118,7 +113,6 @@ DynamicFontData::~DynamicFontData() { HashMap<String, Vector<uint8_t>> DynamicFontAtSize::_fontdata; Error DynamicFontAtSize::_load() { - int error = FT_Init_FreeType(&library); ERR_FAIL_COND_V_MSG(error != 0, ERR_CANT_CREATE, "Error initializing FreeType."); @@ -127,11 +121,9 @@ Error DynamicFontAtSize::_load() { if (OS::get_singleton()->get_name() == "Android" && font->font_mem == nullptr && font->font_path != String()) { // cache font only once for each font->font_path if (_fontdata.has(font->font_path)) { - font->set_font_ptr(_fontdata[font->font_path].ptr(), _fontdata[font->font_path].size()); } else { - FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); if (!f) { FT_Done_FreeType(library); @@ -149,7 +141,6 @@ Error DynamicFontAtSize::_load() { } if (font->font_mem == nullptr && font->font_path != String()) { - FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); if (!f) { FT_Done_FreeType(library); @@ -170,7 +161,6 @@ Error DynamicFontAtSize::_load() { fargs.stream = &stream; error = FT_Open_Face(library, &fargs, 0, &face); } else if (font->font_mem) { - memset(&stream, 0, sizeof(FT_StreamRec)); stream.base = (unsigned char *)font->font_mem; stream.size = font->font_mem_size; @@ -192,12 +182,10 @@ Error DynamicFontAtSize::_load() { //error = FT_New_Face( library, src_path.utf8().get_data(),0,&face ); if (error == FT_Err_Unknown_File_Format) { - FT_Done_FreeType(library); ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "Unknown font format."); } else if (error) { - FT_Done_FreeType(library); ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "Error loading font."); } @@ -232,26 +220,21 @@ Error DynamicFontAtSize::_load() { float DynamicFontAtSize::font_oversampling = 1.0; float DynamicFontAtSize::get_height() const { - return ascent + descent; } float DynamicFontAtSize::get_ascent() const { - return ascent; } float DynamicFontAtSize::get_descent() const { - return descent; } float DynamicFontAtSize::get_underline_position() const { - return underline_position; } float DynamicFontAtSize::get_underline_thickness() const { - return underline_thickness; } @@ -260,10 +243,8 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(nullptr, nullptr))); if (!chr->found) { - //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) continue; @@ -288,7 +269,6 @@ 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) return Size2(1, 1); const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); @@ -307,7 +287,6 @@ 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) return 0; @@ -358,7 +337,6 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT } unsigned long DynamicFontAtSize::_ft_stream_io(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count) { - FileAccess *f = (FileAccess *)stream->descriptor.pointer; if (f->get_position() != offset) { @@ -371,7 +349,6 @@ unsigned long DynamicFontAtSize::_ft_stream_io(FT_Stream stream, unsigned long o return f->get_buffer(buffer, count); } void DynamicFontAtSize::_ft_stream_close(FT_Stream stream) { - FileAccess *f = (FileAccess *)stream->descriptor.pointer; f->close(); memdelete(f); @@ -397,7 +374,6 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp int mh = p_height; for (int i = 0; i < textures.size(); i++) { - const CharTexture &ct = textures[i]; if (ct.texture->get_format() != p_image_format) @@ -410,11 +386,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp ret.x = 0; for (int j = 0; j < ct.texture_size - mw; j++) { - int max_y = 0; for (int k = j; k < j + mw; k++) { - int y = ct.offsets[k]; if (y > max_y) max_y = y; @@ -496,7 +470,6 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - int ofs = ((i + tex_pos.y + rect_margin) * tex.texture_size + j + tex_pos.x + rect_margin) * color_size; ERR_FAIL_COND_V(ofs >= tex.imgdata.size(), Character::not_found()); switch (bitmap.pixel_mode) { @@ -528,7 +501,6 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b //blit to image and texture { - Ref<Image> img = memnew(Image(tex.texture_size, tex.texture_size, 0, require_format, tex.imgdata)); if (tex.texture.is_null()) { @@ -591,7 +563,6 @@ cleanup_stroker: } void DynamicFontAtSize::_update_char(CharType p_char) { - if (char_map.has(p_char)) return; @@ -650,7 +621,6 @@ void DynamicFontAtSize::update_oversampling() { } DynamicFontAtSize::DynamicFontAtSize() { - valid = false; rect_margin = 1; ascent = 1; @@ -661,7 +631,6 @@ DynamicFontAtSize::DynamicFontAtSize() { } DynamicFontAtSize::~DynamicFontAtSize() { - if (valid) { FT_Done_FreeType(library); } @@ -672,7 +641,6 @@ DynamicFontAtSize::~DynamicFontAtSize() { ///////////////////////// void DynamicFont::_reload_cache() { - ERR_FAIL_COND(cache_id.size < 1); if (!data.is_valid()) { data_at_size.unref(); @@ -703,7 +671,6 @@ void DynamicFont::_reload_cache() { } void DynamicFont::set_font_data(const Ref<DynamicFontData> &p_data) { - data = p_data; _reload_cache(); @@ -712,12 +679,10 @@ void DynamicFont::set_font_data(const Ref<DynamicFontData> &p_data) { } Ref<DynamicFontData> DynamicFont::get_font_data() const { - return data; } void DynamicFont::set_size(int p_size) { - if (cache_id.size == p_size) return; cache_id.size = p_size; @@ -726,7 +691,6 @@ void DynamicFont::set_size(int p_size) { } int DynamicFont::get_size() const { - return cache_id.size; } @@ -755,31 +719,26 @@ Color DynamicFont::get_outline_color() const { } bool DynamicFontData::is_antialiased() const { - return antialiased; } void DynamicFontData::set_antialiased(bool p_antialiased) { - if (antialiased == p_antialiased) return; antialiased = p_antialiased; } DynamicFontData::Hinting DynamicFontData::get_hinting() const { - return hinting; } void DynamicFontData::set_hinting(Hinting p_hinting) { - if (hinting == p_hinting) return; hinting = p_hinting; } int DynamicFont::get_spacing(int p_type) const { - if (p_type == SPACING_TOP) { return spacing_top; } else if (p_type == SPACING_BOTTOM) { @@ -794,7 +753,6 @@ int DynamicFont::get_spacing(int p_type) const { } void DynamicFont::set_spacing(int p_type, int p_value) { - if (p_type == SPACING_TOP) { spacing_top = p_value; } else if (p_type == SPACING_BOTTOM) { @@ -810,7 +768,6 @@ void DynamicFont::set_spacing(int p_type, int p_value) { } float DynamicFont::get_height() const { - if (!data_at_size.is_valid()) return 1; @@ -818,7 +775,6 @@ float DynamicFont::get_height() const { } float DynamicFont::get_ascent() const { - if (!data_at_size.is_valid()) return 1; @@ -826,7 +782,6 @@ float DynamicFont::get_ascent() const { } float DynamicFont::get_descent() const { - if (!data_at_size.is_valid()) return 1; @@ -834,7 +789,6 @@ float DynamicFont::get_descent() const { } float DynamicFont::get_underline_position() const { - if (!data_at_size.is_valid()) return 2; @@ -842,7 +796,6 @@ float DynamicFont::get_underline_position() const { } float DynamicFont::get_underline_thickness() const { - if (!data_at_size.is_valid()) return 1; @@ -850,7 +803,6 @@ float DynamicFont::get_underline_thickness() const { } Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const { - if (!data_at_size.is_valid()) return Size2(1, 1); @@ -864,7 +816,6 @@ Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const { } bool DynamicFont::is_distance_field_hint() const { - return false; } @@ -887,7 +838,6 @@ float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_ } void DynamicFont::set_fallback(int p_idx, const Ref<DynamicFontData> &p_data) { - ERR_FAIL_COND(p_data.is_null()); ERR_FAIL_INDEX(p_idx, fallbacks.size()); fallbacks.write[p_idx] = p_data; @@ -895,7 +845,6 @@ void DynamicFont::set_fallback(int p_idx, const Ref<DynamicFontData> &p_data) { } 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.. @@ -911,13 +860,11 @@ int DynamicFont::get_fallback_count() const { return fallbacks.size(); } Ref<DynamicFontData> DynamicFont::get_fallback(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, fallbacks.size(), Ref<DynamicFontData>()); return fallbacks[p_idx]; } void DynamicFont::remove_fallback(int p_idx) { - ERR_FAIL_INDEX(p_idx, fallbacks.size()); fallbacks.remove(p_idx); fallback_data_at_size.remove(p_idx); @@ -926,7 +873,6 @@ void DynamicFont::remove_fallback(int p_idx) { } bool DynamicFont::_set(const StringName &p_name, const Variant &p_value) { - String str = p_name; if (str.begins_with("fallback/")) { int idx = str.get_slicec('/', 1).to_int(); @@ -952,7 +898,6 @@ bool DynamicFont::_set(const StringName &p_name, const Variant &p_value) { } bool DynamicFont::_get(const StringName &p_name, Variant &r_ret) const { - String str = p_name; if (str.begins_with("fallback/")) { int idx = str.get_slicec('/', 1).to_int(); @@ -969,7 +914,6 @@ bool DynamicFont::_get(const StringName &p_name, Variant &r_ret) const { return false; } void DynamicFont::_get_property_list(List<PropertyInfo> *p_list) const { - for (int i = 0; i < fallbacks.size(); i++) { p_list->push_back(PropertyInfo(Variant::OBJECT, "fallback/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "DynamicFontData")); } @@ -978,7 +922,6 @@ void DynamicFont::_get_property_list(List<PropertyInfo> *p_list) const { } void DynamicFont::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_font_data", "data"), &DynamicFont::set_font_data); ClassDB::bind_method(D_METHOD("get_font_data"), &DynamicFont::get_font_data); @@ -1024,7 +967,6 @@ SelfList<DynamicFont>::List *DynamicFont::dynamic_fonts = nullptr; DynamicFont::DynamicFont() : font_list(this) { - valid = false; cache_id.size = 16; outline_cache_id.size = 16; @@ -1053,14 +995,12 @@ void DynamicFont::finish_dynamic_fonts() { } void DynamicFont::update_oversampling() { - Vector<Ref<DynamicFont>> changed; { MutexLock lock(dynamic_font_mutex); SelfList<DynamicFont> *E = dynamic_fonts->first(); while (E) { - if (E->self()->data_at_size.is_valid()) { E->self()->data_at_size->update_oversampling(); @@ -1093,7 +1033,6 @@ 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) *r_error = ERR_FILE_CANT_OPEN; @@ -1108,18 +1047,15 @@ RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_ } void ResourceFormatLoaderDynamicFont::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("ttf"); p_extensions->push_back("otf"); } bool ResourceFormatLoaderDynamicFont::handles_type(const String &p_type) const { - return (p_type == "DynamicFontData"); } String ResourceFormatLoaderDynamicFont::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "ttf" || el == "otf") return "DynamicFontData"; diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index 2fa1951d27..08ad20a92d 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -47,7 +47,6 @@ class DynamicFontAtSize; class DynamicFont; class DynamicFontData : public Resource { - GDCLASS(DynamicFontData, Resource); public: @@ -109,7 +108,6 @@ public: VARIANT_ENUM_CAST(DynamicFontData::Hinting); class DynamicFontAtSize : public Reference { - GDCLASS(DynamicFontAtSize, Reference); _THREAD_SAFE_CLASS_ @@ -130,7 +128,6 @@ class DynamicFontAtSize : public Reference { bool valid; struct CharTexture { - Vector<uint8_t> imgdata; int texture_size; Vector<int> offsets; @@ -140,7 +137,6 @@ class DynamicFontAtSize : public Reference { Vector<CharTexture> textures; struct Character { - bool found; int texture_idx; Rect2 rect; @@ -206,7 +202,6 @@ public: /////////////// class DynamicFont : public Font { - GDCLASS(DynamicFont, Font); public: diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index abbe579307..87d070db6f 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -34,19 +34,16 @@ #include "texture.h" RID Environment::get_rid() const { - return environment; } void Environment::set_background(BGMode p_bg) { - bg_mode = p_bg; RS::get_singleton()->environment_set_background(environment, RS::EnvironmentBG(p_bg)); _change_notify(); } void Environment::set_sky(const Ref<Sky> &p_sky) { - bg_sky = p_sky; RID sb_rid; @@ -57,37 +54,30 @@ void Environment::set_sky(const Ref<Sky> &p_sky) { } void Environment::set_sky_custom_fov(float p_scale) { - bg_sky_custom_fov = p_scale; RS::get_singleton()->environment_set_sky_custom_fov(environment, p_scale); } void Environment::set_bg_color(const Color &p_color) { - bg_color = p_color; RS::get_singleton()->environment_set_bg_color(environment, p_color); } void Environment::set_bg_energy(float p_energy) { - bg_energy = p_energy; RS::get_singleton()->environment_set_bg_energy(environment, p_energy); } void Environment::set_canvas_max_layer(int p_max_layer) { - bg_canvas_max_layer = p_max_layer; RS::get_singleton()->environment_set_canvas_max_layer(environment, p_max_layer); } void Environment::set_ambient_light_color(const Color &p_color) { - ambient_color = p_color; RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } void Environment::set_ambient_light_energy(float p_energy) { - ambient_energy = p_energy; RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } void Environment::set_ambient_light_sky_contribution(float p_energy) { - ambient_sky_contribution = p_energy; RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } @@ -117,16 +107,13 @@ Environment::ReflectionSource Environment::get_reflection_source() const { } Environment::BGMode Environment::get_background() const { - return bg_mode; } Ref<Sky> Environment::get_sky() const { - return bg_sky; } float Environment::get_sky_custom_fov() const { - return bg_sky_custom_fov; } @@ -136,176 +123,141 @@ void Environment::set_sky_rotation(const Vector3 &p_rotation) { } Vector3 Environment::get_sky_rotation() const { - return sky_rotation; } Color Environment::get_bg_color() const { - return bg_color; } float Environment::get_bg_energy() const { - return bg_energy; } int Environment::get_canvas_max_layer() const { - return bg_canvas_max_layer; } Color Environment::get_ambient_light_color() const { - return ambient_color; } float Environment::get_ambient_light_energy() const { - return ambient_energy; } float Environment::get_ambient_light_sky_contribution() const { - return ambient_sky_contribution; } int Environment::get_camera_feed_id() const { - return camera_feed_id; } void Environment::set_tonemapper(ToneMapper p_tone_mapper) { - tone_mapper = p_tone_mapper; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } Environment::ToneMapper Environment::get_tonemapper() const { - return tone_mapper; } void Environment::set_tonemap_exposure(float p_exposure) { - tonemap_exposure = p_exposure; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_exposure() const { - return tonemap_exposure; } void Environment::set_tonemap_white(float p_white) { - tonemap_white = p_white; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_white() const { - return tonemap_white; } void Environment::set_tonemap_auto_exposure(bool p_enabled) { - tonemap_auto_exposure = p_enabled; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); _change_notify(); } bool Environment::get_tonemap_auto_exposure() const { - return tonemap_auto_exposure; } void Environment::set_tonemap_auto_exposure_max(float p_auto_exposure_max) { - tonemap_auto_exposure_max = p_auto_exposure_max; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_max() const { - return tonemap_auto_exposure_max; } void Environment::set_tonemap_auto_exposure_min(float p_auto_exposure_min) { - tonemap_auto_exposure_min = p_auto_exposure_min; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_min() const { - return tonemap_auto_exposure_min; } void Environment::set_tonemap_auto_exposure_speed(float p_auto_exposure_speed) { - tonemap_auto_exposure_speed = p_auto_exposure_speed; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_speed() const { - return tonemap_auto_exposure_speed; } void Environment::set_tonemap_auto_exposure_grey(float p_auto_exposure_grey) { - tonemap_auto_exposure_grey = p_auto_exposure_grey; RS::get_singleton()->environment_set_tonemap(environment, RS::EnvironmentToneMapper(tone_mapper), tonemap_exposure, tonemap_white, tonemap_auto_exposure, tonemap_auto_exposure_min, tonemap_auto_exposure_max, tonemap_auto_exposure_speed, tonemap_auto_exposure_grey); } float Environment::get_tonemap_auto_exposure_grey() const { - return tonemap_auto_exposure_grey; } void Environment::set_adjustment_enable(bool p_enable) { - adjustment_enabled = p_enable; RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); _change_notify(); } bool Environment::is_adjustment_enabled() const { - return adjustment_enabled; } void Environment::set_adjustment_brightness(float p_brightness) { - adjustment_brightness = p_brightness; RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } float Environment::get_adjustment_brightness() const { - return adjustment_brightness; } void Environment::set_adjustment_contrast(float p_contrast) { - adjustment_contrast = p_contrast; RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } float Environment::get_adjustment_contrast() const { - return adjustment_contrast; } void Environment::set_adjustment_saturation(float p_saturation) { - adjustment_saturation = p_saturation; RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } float Environment::get_adjustment_saturation() const { - return adjustment_saturation; } void Environment::set_adjustment_color_correction(const Ref<Texture2D> &p_ramp) { - adjustment_color_correction = p_ramp; RS::get_singleton()->environment_set_adjustment(environment, adjustment_enabled, adjustment_brightness, adjustment_contrast, adjustment_saturation, adjustment_color_correction.is_valid() ? adjustment_color_correction->get_rid() : RID()); } Ref<Texture2D> Environment::get_adjustment_color_correction() const { - return adjustment_color_correction; } void Environment::_validate_property(PropertyInfo &property) const { - if (property.name == "sky" || property.name == "sky_custom_fov" || property.name == "sky_rotation" || property.name == "ambient_light/sky_contribution") { if (bg_mode != BG_SKY && ambient_source != AMBIENT_SOURCE_SKY && reflection_source != REFLECTION_SOURCE_SKY) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -387,166 +339,135 @@ void Environment::_validate_property(PropertyInfo &property) const { } void Environment::set_ssr_enabled(bool p_enable) { - ssr_enabled = p_enable; RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); _change_notify(); } bool Environment::is_ssr_enabled() const { - return ssr_enabled; } void Environment::set_ssr_max_steps(int p_steps) { - ssr_max_steps = p_steps; RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } int Environment::get_ssr_max_steps() const { - return ssr_max_steps; } void Environment::set_ssr_fade_in(float p_fade_in) { - ssr_fade_in = p_fade_in; RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } float Environment::get_ssr_fade_in() const { - return ssr_fade_in; } void Environment::set_ssr_fade_out(float p_fade_out) { - ssr_fade_out = p_fade_out; RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } float Environment::get_ssr_fade_out() const { - return ssr_fade_out; } void Environment::set_ssr_depth_tolerance(float p_depth_tolerance) { - ssr_depth_tolerance = p_depth_tolerance; RS::get_singleton()->environment_set_ssr(environment, ssr_enabled, ssr_max_steps, ssr_fade_in, ssr_fade_out, ssr_depth_tolerance); } float Environment::get_ssr_depth_tolerance() const { - return ssr_depth_tolerance; } void Environment::set_ssao_enabled(bool p_enable) { - ssao_enabled = p_enable; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); _change_notify(); } bool Environment::is_ssao_enabled() const { - return ssao_enabled; } void Environment::set_ssao_radius(float p_radius) { - ssao_radius = p_radius; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_radius() const { - return ssao_radius; } void Environment::set_ssao_intensity(float p_intensity) { - ssao_intensity = p_intensity; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_intensity() const { - return ssao_intensity; } void Environment::set_ssao_bias(float p_bias) { - ssao_bias = p_bias; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_bias() const { - return ssao_bias; } void Environment::set_ssao_direct_light_affect(float p_direct_light_affect) { - ssao_direct_light_affect = p_direct_light_affect; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_direct_light_affect() const { - return ssao_direct_light_affect; } void Environment::set_ssao_ao_channel_affect(float p_ao_channel_affect) { - ssao_ao_channel_affect = p_ao_channel_affect; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_ao_channel_affect() const { - return ssao_ao_channel_affect; } void Environment::set_ao_color(const Color &p_color) { - ao_color = p_color; RS::get_singleton()->environment_set_ambient_light(environment, ambient_color, RS::EnvironmentAmbientSource(ambient_source), ambient_energy, ambient_sky_contribution, RS::EnvironmentReflectionSource(reflection_source), ao_color); } Color Environment::get_ao_color() const { - return ao_color; } void Environment::set_ssao_blur(SSAOBlur p_blur) { - ssao_blur = p_blur; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } Environment::SSAOBlur Environment::get_ssao_blur() const { - return ssao_blur; } void Environment::set_ssao_edge_sharpness(float p_edge_sharpness) { - ssao_edge_sharpness = p_edge_sharpness; RS::get_singleton()->environment_set_ssao(environment, ssao_enabled, ssao_radius, ssao_intensity, ssao_bias, ssao_direct_light_affect, ssao_ao_channel_affect, RS::EnvironmentSSAOBlur(ssao_blur), ssao_edge_sharpness); } float Environment::get_ssao_edge_sharpness() const { - return ssao_edge_sharpness; } void Environment::set_glow_enabled(bool p_enabled) { - glow_enabled = p_enabled; 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); _change_notify(); } bool Environment::is_glow_enabled() const { - return glow_enabled; } void Environment::set_glow_level(int p_level, bool p_enabled) { - ERR_FAIL_INDEX(p_level, RS::MAX_GLOW_LEVELS); if (p_enabled) @@ -557,239 +478,194 @@ void Environment::set_glow_level(int p_level, bool p_enabled) { 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); } bool Environment::is_glow_level_enabled(int p_level) const { - ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, false); return glow_levels & (1 << p_level); } void Environment::set_glow_intensity(float p_intensity) { - glow_intensity = p_intensity; 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); } float Environment::get_glow_intensity() const { - return glow_intensity; } void Environment::set_glow_strength(float p_strength) { - glow_strength = p_strength; 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); } float Environment::get_glow_strength() const { - return glow_strength; } void Environment::set_glow_mix(float p_mix) { - glow_mix = p_mix; 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); } float Environment::get_glow_mix() const { - return glow_mix; } void Environment::set_glow_bloom(float p_threshold) { - glow_bloom = p_threshold; 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); } float Environment::get_glow_bloom() const { - return glow_bloom; } void Environment::set_glow_blend_mode(GlowBlendMode p_mode) { - glow_blend_mode = p_mode; 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); _change_notify(); } Environment::GlowBlendMode Environment::get_glow_blend_mode() const { - return glow_blend_mode; } void Environment::set_glow_hdr_bleed_threshold(float p_threshold) { - glow_hdr_bleed_threshold = p_threshold; 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); } float Environment::get_glow_hdr_bleed_threshold() const { - return glow_hdr_bleed_threshold; } void Environment::set_glow_hdr_luminance_cap(float p_amount) { - glow_hdr_luminance_cap = p_amount; 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); } float Environment::get_glow_hdr_luminance_cap() const { - return glow_hdr_luminance_cap; } void Environment::set_glow_hdr_bleed_scale(float p_scale) { - glow_hdr_bleed_scale = p_scale; 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); } float Environment::get_glow_hdr_bleed_scale() const { - return glow_hdr_bleed_scale; } void Environment::set_fog_enabled(bool p_enabled) { - fog_enabled = p_enabled; RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); _change_notify(); } bool Environment::is_fog_enabled() const { - return fog_enabled; } void Environment::set_fog_color(const Color &p_color) { - fog_color = p_color; RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); } Color Environment::get_fog_color() const { - return fog_color; } void Environment::set_fog_sun_color(const Color &p_color) { - fog_sun_color = p_color; RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); } Color Environment::get_fog_sun_color() const { - return fog_sun_color; } void Environment::set_fog_sun_amount(float p_amount) { - fog_sun_amount = p_amount; RS::get_singleton()->environment_set_fog(environment, fog_enabled, fog_color, fog_sun_color, fog_sun_amount); } float Environment::get_fog_sun_amount() const { - return fog_sun_amount; } void Environment::set_fog_depth_enabled(bool p_enabled) { - fog_depth_enabled = p_enabled; RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } bool Environment::is_fog_depth_enabled() const { - return fog_depth_enabled; } void Environment::set_fog_depth_begin(float p_distance) { - fog_depth_begin = p_distance; RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_begin() const { - return fog_depth_begin; } void Environment::set_fog_depth_end(float p_distance) { - fog_depth_end = p_distance; RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_end() const { - return fog_depth_end; } void Environment::set_fog_depth_curve(float p_curve) { - fog_depth_curve = p_curve; RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_curve() const { - return fog_depth_curve; } void Environment::set_fog_transmit_enabled(bool p_enabled) { - fog_transmit_enabled = p_enabled; RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } bool Environment::is_fog_transmit_enabled() const { - return fog_transmit_enabled; } void Environment::set_fog_transmit_curve(float p_curve) { - fog_transmit_curve = p_curve; RS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_transmit_curve() const { - return fog_transmit_curve; } void Environment::set_fog_height_enabled(bool p_enabled) { - fog_height_enabled = p_enabled; RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } bool Environment::is_fog_height_enabled() const { - return fog_height_enabled; } void Environment::set_fog_height_min(float p_distance) { - fog_height_min = p_distance; RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } float Environment::get_fog_height_min() const { - return fog_height_min; } void Environment::set_fog_height_max(float p_distance) { - fog_height_max = p_distance; RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } float Environment::get_fog_height_max() const { - return fog_height_max; } void Environment::set_fog_height_curve(float p_distance) { - fog_height_curve = p_distance; RS::get_singleton()->environment_set_fog_height(environment, fog_height_enabled, fog_height_min, fog_height_max, fog_height_curve); } float Environment::get_fog_height_curve() const { - return fog_height_curve; } @@ -813,7 +689,6 @@ bool Environment::_set(const StringName &p_name, const Variant &p_value) { #endif void Environment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_background", "mode"), &Environment::set_background); ClassDB::bind_method(D_METHOD("set_sky", "sky"), &Environment::set_sky); ClassDB::bind_method(D_METHOD("set_sky_custom_fov", "scale"), &Environment::set_sky_custom_fov); @@ -1118,7 +993,6 @@ void Environment::_bind_methods() { } Environment::Environment() { - environment = RS::get_singleton()->environment_create(); bg_mode = BG_CLEAR_COLOR; @@ -1200,84 +1074,69 @@ Environment::Environment() { } Environment::~Environment() { - RS::get_singleton()->free(environment); } ////////////////////// void CameraEffects::set_dof_blur_far_enabled(bool p_enable) { - dof_blur_far_enabled = p_enable; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } bool CameraEffects::is_dof_blur_far_enabled() const { - return dof_blur_far_enabled; } void CameraEffects::set_dof_blur_far_distance(float p_distance) { - dof_blur_far_distance = p_distance; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_far_distance() const { - return dof_blur_far_distance; } void CameraEffects::set_dof_blur_far_transition(float p_distance) { - dof_blur_far_transition = p_distance; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_far_transition() const { - return dof_blur_far_transition; } void CameraEffects::set_dof_blur_near_enabled(bool p_enable) { - dof_blur_near_enabled = p_enable; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); _change_notify(); } bool CameraEffects::is_dof_blur_near_enabled() const { - return dof_blur_near_enabled; } void CameraEffects::set_dof_blur_near_distance(float p_distance) { - dof_blur_near_distance = p_distance; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_near_distance() const { - return dof_blur_near_distance; } void CameraEffects::set_dof_blur_near_transition(float p_distance) { - dof_blur_near_transition = p_distance; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_near_transition() const { - return dof_blur_near_transition; } void CameraEffects::set_dof_blur_amount(float p_amount) { - dof_blur_amount = p_amount; RS::get_singleton()->camera_effects_set_dof_blur(camera_effects, dof_blur_far_enabled, dof_blur_far_distance, dof_blur_far_transition, dof_blur_near_enabled, dof_blur_near_distance, dof_blur_near_transition, dof_blur_amount); } float CameraEffects::get_dof_blur_amount() const { - return dof_blur_amount; } @@ -1304,7 +1163,6 @@ RID CameraEffects::get_rid() const { } void CameraEffects::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_dof_blur_far_enabled", "enabled"), &CameraEffects::set_dof_blur_far_enabled); ClassDB::bind_method(D_METHOD("is_dof_blur_far_enabled"), &CameraEffects::is_dof_blur_far_enabled); @@ -1346,7 +1204,6 @@ void CameraEffects::_bind_methods() { } CameraEffects::CameraEffects() { - camera_effects = RS::get_singleton()->camera_effects_create(); dof_blur_far_enabled = false; @@ -1364,6 +1221,5 @@ CameraEffects::CameraEffects() { } CameraEffects::~CameraEffects() { - RS::get_singleton()->free(camera_effects); } diff --git a/scene/resources/environment.h b/scene/resources/environment.h index f0ea8489ff..b8caa59aab 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -37,7 +37,6 @@ #include "servers/rendering_server.h" class Environment : public Resource { - GDCLASS(Environment, Resource); public: @@ -369,7 +368,6 @@ VARIANT_ENUM_CAST(Environment::GlowBlendMode) VARIANT_ENUM_CAST(Environment::SSAOBlur) class CameraEffects : public Resource { - GDCLASS(CameraEffects, Resource); private: diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 51c2ff389a..c67a300580 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -65,7 +65,6 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co int chars_drawn = 0; bool with_outline = has_outline(); 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) @@ -84,12 +83,10 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co } void Font::update_changes() { - emit_changed(); } void Font::_bind_methods() { - ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "string", "modulate", "clip_w", "outline_modulate"), &Font::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(-1), DEFVAL(Color(1, 1, 1))); ClassDB::bind_method(D_METHOD("get_ascent"), &Font::get_ascent); ClassDB::bind_method(D_METHOD("get_descent"), &Font::get_descent); @@ -108,7 +105,6 @@ Font::Font() { ///////////////////////////////////////////////////////////////// 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); @@ -118,20 +114,17 @@ void BitmapFont::_set_chars(const Vector<int> &p_chars) { const int *r = p_chars.ptr(); for (int i = 0; i < chars; i++) { - const int *data = &r[i * 9]; add_char(data[0], data[1], Rect2(data[2], data[3], data[4], data[5]), Size2(data[6], data[7]), data[8]); } } Vector<int> BitmapFont::_get_chars() const { - Vector<int> chars; const CharType *key = nullptr; while ((key = char_map.next(key))) { - const Character *c = char_map.getptr(*key); ERR_FAIL_COND_V(!c, Vector<int>()); chars.push_back(*key); @@ -150,7 +143,6 @@ 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) @@ -158,18 +150,15 @@ void BitmapFont::_set_kernings(const Vector<int> &p_kernings) { const int *r = p_kernings.ptr(); for (int i = 0; i < len / 3; i++) { - const int *data = &r[i * 3]; add_kerning_pair(data[0], data[1], data[2]); } } Vector<int> BitmapFont::_get_kernings() const { - Vector<int> kernings; for (Map<KerningPairKey, int>::Element *E = kerning_map.front(); E; E = E->next()) { - kernings.push_back(E->key().A); kernings.push_back(E->key().B); kernings.push_back(E->get()); @@ -179,7 +168,6 @@ Vector<int> BitmapFont::_get_kernings() const { } void BitmapFont::_set_textures(const Vector<Variant> &p_textures) { - textures.clear(); for (int i = 0; i < p_textures.size(); i++) { Ref<Texture2D> tex = p_textures[i]; @@ -189,7 +177,6 @@ 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++) rtextures.push_back(textures[i]); @@ -207,7 +194,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) { clear(); while (true) { - String line = f->get_line(); int delimiter = line.find(" "); @@ -219,7 +205,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) { pos++; while (pos < line.size()) { - int eq = line.find("=", pos); if (eq == -1) break; @@ -249,7 +234,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) { } if (type == "info") { - if (keys.has("face")) set_name(keys["face"]); /* @@ -258,16 +242,13 @@ Error BitmapFont::create_from_fnt(const String &p_file) { */ } else if (type == "common") { - if (keys.has("lineHeight")) set_height(keys["lineHeight"].to_int()); if (keys.has("base")) set_ascent(keys["base"].to_int()); } else if (type == "page") { - if (keys.has("file")) { - String base_dir = p_file.get_base_dir(); String file = base_dir.plus_file(keys["file"]); Ref<Texture2D> tex = ResourceLoader::load(file); @@ -278,7 +259,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) { } } } else if (type == "char") { - CharType idx = 0; if (keys.has("id")) idx = keys["id"].to_int(); @@ -311,7 +291,6 @@ Error BitmapFont::create_from_fnt(const String &p_file) { add_char(idx, texture, rect, ofs, advance); } else if (type == "kerning") { - CharType first = 0, second = 0; int k = 0; @@ -335,67 +314,54 @@ Error BitmapFont::create_from_fnt(const String &p_file) { } void BitmapFont::set_height(float p_height) { - height = p_height; } float BitmapFont::get_height() const { - return height; } void BitmapFont::set_ascent(float p_ascent) { - ascent = p_ascent; } float BitmapFont::get_ascent() const { - return ascent; } float BitmapFont::get_descent() const { - return height - ascent; } float BitmapFont::get_underline_position() const { - return 2; } float BitmapFont::get_underline_thickness() const { - return 1; } void BitmapFont::add_texture(const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object."); textures.push_back(p_texture); } int BitmapFont::get_texture_count() const { - return textures.size(); }; Ref<Texture2D> BitmapFont::get_texture(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, textures.size(), Ref<Texture2D>()); return textures[p_idx]; }; int BitmapFont::get_character_count() const { - return char_map.size(); }; Vector<CharType> BitmapFont::get_char_keys() const { - Vector<CharType> chars; chars.resize(char_map.size()); const CharType *ct = nullptr; int count = 0; while ((ct = char_map.next(ct))) { - chars.write[count++] = *ct; }; @@ -403,7 +369,6 @@ Vector<CharType> BitmapFont::get_char_keys() const { }; BitmapFont::Character BitmapFont::get_character(CharType p_char) const { - if (!char_map.has(p_char)) { ERR_FAIL_V(Character()); }; @@ -412,7 +377,6 @@ 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) p_advance = p_rect.size.width; @@ -427,22 +391,18 @@ void BitmapFont::add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rec } void BitmapFont::add_kerning_pair(CharType p_A, CharType p_B, int p_kerning) { - KerningPairKey kpk; kpk.A = p_A; kpk.B = p_B; if (p_kerning == 0 && kerning_map.has(kpk)) { - kerning_map.erase(kpk); } else { - kerning_map[kpk] = p_kerning; } } Vector<BitmapFont::KerningPairKey> BitmapFont::get_kerning_pair_keys() const { - Vector<BitmapFont::KerningPairKey> ret; ret.resize(kerning_map.size()); int i = 0; @@ -455,7 +415,6 @@ Vector<BitmapFont::KerningPairKey> BitmapFont::get_kerning_pair_keys() const { } int BitmapFont::get_kerning_pair(CharType p_A, CharType p_B) const { - KerningPairKey kpk; kpk.A = p_A; kpk.B = p_B; @@ -468,18 +427,15 @@ int BitmapFont::get_kerning_pair(CharType p_A, CharType p_B) const { } void BitmapFont::set_distance_field_hint(bool p_distance_field) { - distance_field_hint = p_distance_field; emit_changed(); } bool BitmapFont::is_distance_field_hint() const { - return distance_field_hint; } void BitmapFont::clear() { - height = 1; ascent = 0; char_map.clear(); @@ -489,7 +445,6 @@ void BitmapFont::clear() { } Size2 Font::get_string_size(const String &p_string) const { - float w = 0; int l = p_string.length(); @@ -498,7 +453,6 @@ Size2 Font::get_string_size(const String &p_string) const { const CharType *sptr = &p_string[0]; for (int i = 0; i < l; i++) { - w += get_char_size(sptr[i], sptr[i + 1]).width; } @@ -506,7 +460,6 @@ Size2 Font::get_string_size(const String &p_string) const { } Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) const { - ERR_FAIL_COND_V(p_width <= 0, Vector2(0, get_height())); int l = p_string.length(); @@ -537,7 +490,6 @@ Size2 Font::get_wordwrap_string_size(const String &p_string, float p_width) cons } void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) { - for (Ref<BitmapFont> fallback_child = p_fallback; fallback_child != nullptr; fallback_child = fallback_child->get_fallback()) { ERR_FAIL_COND_MSG(fallback_child == this, "Can't set as fallback one of its parents to prevent crashes due to recursive loop."); } @@ -546,12 +498,10 @@ void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) { } Ref<BitmapFont> BitmapFont::get_fallback() const { - return fallback; } float BitmapFont::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 Character *c = char_map.getptr(p_char); if (!c) { @@ -573,7 +523,6 @@ float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_c } Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const { - const Character *c = char_map.getptr(p_char); if (!c) { @@ -585,14 +534,12 @@ Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const { Size2 ret(c->advance, c->rect.size.y); if (p_next) { - KerningPairKey kpk; kpk.A = p_char; kpk.B = p_next; const Map<KerningPairKey, int>::Element *E = kerning_map.find(kpk); if (E) { - ret.width -= E->get(); } } @@ -601,7 +548,6 @@ Size2 BitmapFont::get_char_size(CharType p_char, CharType p_next) const { } void BitmapFont::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_from_fnt", "path"), &BitmapFont::create_from_fnt); ClassDB::bind_method(D_METHOD("set_height", "px"), &BitmapFont::set_height); @@ -645,19 +591,16 @@ void BitmapFont::_bind_methods() { } BitmapFont::BitmapFont() { - clear(); } BitmapFont::~BitmapFont() { - clear(); } //////////// 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) *r_error = ERR_FILE_CANT_OPEN; @@ -676,17 +619,14 @@ RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderBMFont::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("fnt"); } bool ResourceFormatLoaderBMFont::handles_type(const String &p_type) const { - return (p_type == "BitmapFont"); } String ResourceFormatLoaderBMFont::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "fnt") return "BitmapFont"; diff --git a/scene/resources/font.h b/scene/resources/font.h index 54b1eaa1b9..14312308bb 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -36,7 +36,6 @@ #include "scene/resources/texture.h" class Font : public Resource { - GDCLASS(Font, Resource); protected: @@ -106,7 +105,6 @@ public: }; class BitmapFont : public Font { - GDCLASS(BitmapFont, Font); RES_BASE_EXTENSION("font"); @@ -114,7 +112,6 @@ class BitmapFont : public Font { public: struct Character { - int texture_idx; Rect2 rect; float v_align; @@ -128,7 +125,6 @@ public: }; struct KerningPairKey { - union { struct { uint32_t A, B; diff --git a/scene/resources/gradient.cpp b/scene/resources/gradient.cpp index 7bce04beaf..2ccabe0b80 100644 --- a/scene/resources/gradient.cpp +++ b/scene/resources/gradient.cpp @@ -52,7 +52,6 @@ Gradient::~Gradient() { } void Gradient::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_point", "offset", "color"), &Gradient::add_point); ClassDB::bind_method(D_METHOD("remove_point", "offset"), &Gradient::remove_point); @@ -118,7 +117,6 @@ Vector<Gradient::Point> &Gradient::get_points() { } void Gradient::add_point(float p_offset, const Color &p_color) { - Point p; p.offset = p_offset; p.color = p_color; @@ -129,7 +127,6 @@ void Gradient::add_point(float p_offset, const Color &p_color) { } void Gradient::remove_point(int p_index) { - ERR_FAIL_INDEX(p_index, points.size()); ERR_FAIL_COND(points.size() <= 2); points.remove(p_index); @@ -143,7 +140,6 @@ 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) points.resize(pos + 1); diff --git a/scene/resources/gradient.h b/scene/resources/gradient.h index 573749ea7e..fa654cf31d 100644 --- a/scene/resources/gradient.h +++ b/scene/resources/gradient.h @@ -39,7 +39,6 @@ class Gradient : public Resource { public: struct Point { - float offset; Color color; bool operator<(const Point &p_ponit) const { @@ -77,7 +76,6 @@ public: Vector<Color> get_colors() const; _FORCE_INLINE_ Color get_color_at_offset(float p_offset) { - if (points.empty()) return Color(0, 0, 0, 1); diff --git a/scene/resources/height_map_shape_3d.cpp b/scene/resources/height_map_shape_3d.cpp index 33b6063299..5450d78426 100644 --- a/scene/resources/height_map_shape_3d.cpp +++ b/scene/resources/height_map_shape_3d.cpp @@ -35,7 +35,6 @@ Vector<Vector3> HeightMapShape3D::get_debug_mesh_lines() { Vector<Vector3> points; if ((map_width != 0) && (map_depth != 0)) { - // This will be slow for large maps... // also we'll have to figure out how well bullet centers this shape... @@ -81,7 +80,6 @@ real_t HeightMapShape3D::get_enclosing_radius() const { } void HeightMapShape3D::_update_shape() { - Dictionary d; d["width"] = map_width; d["depth"] = map_depth; @@ -193,7 +191,6 @@ void HeightMapShape3D::_bind_methods() { HeightMapShape3D::HeightMapShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_HEIGHTMAP)) { - map_width = 2; map_depth = 2; map_data.resize(map_width * map_depth); diff --git a/scene/resources/line_shape_2d.cpp b/scene/resources/line_shape_2d.cpp index 71d4f79e48..cc7108e92e 100644 --- a/scene/resources/line_shape_2d.cpp +++ b/scene/resources/line_shape_2d.cpp @@ -34,7 +34,6 @@ #include "servers/rendering_server.h" bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - Vector2 point = get_distance() * get_normal(); Vector2 l[2][2] = { { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 }, { point, point + get_normal() * 30 } }; @@ -48,7 +47,6 @@ bool LineShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tol } void LineShape2D::_update_shape() { - Array arr; arr.push_back(normal); arr.push_back(distance); @@ -57,28 +55,23 @@ void LineShape2D::_update_shape() { } void LineShape2D::set_normal(const Vector2 &p_normal) { - normal = p_normal; _update_shape(); } void LineShape2D::set_distance(real_t p_distance) { - distance = p_distance; _update_shape(); } Vector2 LineShape2D::get_normal() const { - return normal; } real_t LineShape2D::get_distance() const { - return distance; } void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) { - Vector2 point = get_distance() * get_normal(); Vector2 l1[2] = { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 }; @@ -87,7 +80,6 @@ void LineShape2D::draw(const RID &p_to_rid, const Color &p_color) { RS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, 3); } Rect2 LineShape2D::get_rect() const { - Vector2 point = get_distance() * get_normal(); Vector2 l1[2] = { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 }; @@ -105,7 +97,6 @@ real_t LineShape2D::get_enclosing_radius() const { } void LineShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_normal", "normal"), &LineShape2D::set_normal); ClassDB::bind_method(D_METHOD("get_normal"), &LineShape2D::get_normal); @@ -118,7 +109,6 @@ void LineShape2D::_bind_methods() { LineShape2D::LineShape2D() : Shape2D(PhysicsServer2D::get_singleton()->line_shape_create()) { - normal = Vector2(0, 1); distance = 0; _update_shape(); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 137657d239..aa5f7677c7 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -39,7 +39,6 @@ #include "scene/scene_string_names.h" void Material::set_next_pass(const Ref<Material> &p_pass) { - for (Ref<Material> pass_child = p_pass; pass_child != nullptr; pass_child = pass_child->get_next_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."); } @@ -55,12 +54,10 @@ void Material::set_next_pass(const Ref<Material> &p_pass) { } Ref<Material> Material::get_next_pass() const { - return next_pass; } void Material::set_render_priority(int p_priority) { - ERR_FAIL_COND(p_priority < RENDER_PRIORITY_MIN); ERR_FAIL_COND(p_priority > RENDER_PRIORITY_MAX); render_priority = p_priority; @@ -68,23 +65,19 @@ void Material::set_render_priority(int p_priority) { } int Material::get_render_priority() const { - return render_priority; } RID Material::get_rid() const { - return material; } void Material::_validate_property(PropertyInfo &property) const { - if (!_can_do_next_pass() && property.name == "next_pass") { property.usage = 0; } } void Material::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_next_pass", "next_pass"), &Material::set_next_pass); ClassDB::bind_method(D_METHOD("get_next_pass"), &Material::get_next_pass); @@ -99,22 +92,18 @@ void Material::_bind_methods() { } Material::Material() { - material = RenderingServer::get_singleton()->material_create(); render_priority = 0; } Material::~Material() { - RenderingServer::get_singleton()->free(material); } /////////////////////////////////// bool ShaderMaterial::_set(const StringName &p_name, const Variant &p_value) { - if (shader.is_valid()) { - StringName pr = shader->remap_param(p_name); if (!pr) { String n = p_name; @@ -135,9 +124,7 @@ bool ShaderMaterial::_set(const StringName &p_name, const Variant &p_value) { } bool ShaderMaterial::_get(const StringName &p_name, Variant &r_ret) const { - if (shader.is_valid()) { - StringName pr = shader->remap_param(p_name); if (!pr) { String n = p_name; @@ -159,16 +146,13 @@ bool ShaderMaterial::_get(const StringName &p_name, Variant &r_ret) const { } void ShaderMaterial::_get_property_list(List<PropertyInfo> *p_list) const { - if (!shader.is_null()) { - shader->get_param_list(p_list); } } bool ShaderMaterial::property_can_revert(const String &p_name) { if (shader.is_valid()) { - StringName pr = shader->remap_param(p_name); if (pr) { Variant default_value = RenderingServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr); @@ -192,7 +176,6 @@ Variant ShaderMaterial::property_get_revert(const String &p_name) { } void ShaderMaterial::set_shader(const Ref<Shader> &p_shader) { - // Only connect/disconnect the signal when running in the editor. // This can be a slow operation, and `_change_notify()` (which is called by `_shader_changed()`) // does nothing in non-editor builds anyway. See GH-34741 for details. @@ -217,17 +200,14 @@ void ShaderMaterial::set_shader(const Ref<Shader> &p_shader) { } Ref<Shader> ShaderMaterial::get_shader() const { - return shader; } void ShaderMaterial::set_shader_param(const StringName &p_param, const Variant &p_value) { - RS::get_singleton()->material_set_param(_get_material(), p_param, p_value); } Variant ShaderMaterial::get_shader_param(const StringName &p_param) const { - return RS::get_singleton()->material_get_param(_get_material(), p_param); } @@ -236,7 +216,6 @@ void ShaderMaterial::_shader_changed() { } void ShaderMaterial::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_shader", "shader"), &ShaderMaterial::set_shader); ClassDB::bind_method(D_METHOD("get_shader"), &ShaderMaterial::get_shader); ClassDB::bind_method(D_METHOD("set_shader_param", "param", "value"), &ShaderMaterial::set_shader_param); @@ -248,7 +227,6 @@ void ShaderMaterial::_bind_methods() { } void ShaderMaterial::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { - #ifdef TOOLS_ENABLED const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; #else @@ -257,7 +235,6 @@ void ShaderMaterial::get_argument_options(const StringName &p_function, int p_id String f = p_function.operator String(); if ((f == "get_shader_param" || f == "set_shader_param") && p_idx == 0) { - if (shader.is_valid()) { List<PropertyInfo> pl; shader->get_param_list(&pl); @@ -270,7 +247,6 @@ void ShaderMaterial::get_argument_options(const StringName &p_function, int p_id } bool ShaderMaterial::_can_do_next_pass() const { - return shader.is_valid() && shader->get_mode() == Shader::MODE_SPATIAL; } @@ -295,7 +271,6 @@ Map<BaseMaterial3D::MaterialKey, BaseMaterial3D::ShaderData> BaseMaterial3D::sha BaseMaterial3D::ShaderNames *BaseMaterial3D::shader_names = nullptr; void BaseMaterial3D::init_shaders() { - dirty_materials = memnew(SelfList<BaseMaterial3D>::List); shader_names = memnew(ShaderNames); @@ -375,7 +350,6 @@ void BaseMaterial3D::init_shaders() { Ref<StandardMaterial3D> BaseMaterial3D::materials_for_2d[BaseMaterial3D::MAX_MATERIALS_FOR_2D]; void BaseMaterial3D::finish_shaders() { - for (int i = 0; i < MAX_MATERIALS_FOR_2D; i++) { materials_for_2d[i].unref(); } @@ -387,7 +361,6 @@ void BaseMaterial3D::finish_shaders() { } void BaseMaterial3D::_update_shader() { - dirty_materials->remove(&element); MaterialKey mk = _compute_key(); @@ -406,7 +379,6 @@ void BaseMaterial3D::_update_shader() { current_key = mk; if (shader_map.has(mk)) { - RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); shader_map[mk].users++; return; @@ -606,7 +578,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_EMISSION]) { - code += "uniform sampler2D texture_emission : hint_black_albedo," + texfilter_str + ";\n"; code += "uniform vec4 emission : hint_color;\n"; code += "uniform float emission_energy;\n"; @@ -649,13 +620,11 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_SUBSURFACE_SCATTERING]) { - code += "uniform float subsurface_scattering_strength : hint_range(0,1);\n"; code += "uniform sampler2D texture_subsurface_scattering : hint_white," + texfilter_str + ";\n"; } if (features[FEATURE_SUBSURFACE_TRANSMITTANCE]) { - code += "uniform vec4 transmittance_color : hint_color;\n"; code += "uniform float transmittance_depth;\n"; code += "uniform sampler2D texture_subsurface_transmittance : hint_white," + texfilter_str + ";\n"; @@ -664,7 +633,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_BACKLIGHT]) { - code += "uniform vec4 backlight : hint_color;\n"; code += "uniform sampler2D texture_backlight : hint_black," + texfilter_str + ";\n"; } @@ -702,18 +670,15 @@ void BaseMaterial3D::_update_shader() { code += "void vertex() {\n"; if (flags[FLAG_SRGB_VERTEX_COLOR]) { - code += "\tif (!OUTPUT_IS_SRGB) {\n"; code += "\t\tCOLOR.rgb = mix( pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb* (1.0 / 12.92), lessThan(COLOR.rgb,vec3(0.04045)) );\n"; code += "\t}\n"; } if (flags[FLAG_USE_POINT_SIZE]) { - code += "\tPOINT_SIZE=point_size;\n"; } if (shading_mode == SHADING_MODE_PER_VERTEX) { - code += "\tROUGHNESS=roughness;\n"; } @@ -723,10 +688,8 @@ void BaseMaterial3D::_update_shader() { switch (billboard_mode) { case BILLBOARD_DISABLED: { - } break; case BILLBOARD_ENABLED: { - code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],CAMERA_MATRIX[1],CAMERA_MATRIX[2],WORLD_MATRIX[3]);\n"; if (flags[FLAG_BILLBOARD_KEEP_SCALE]) { @@ -734,7 +697,6 @@ void BaseMaterial3D::_update_shader() { } } break; case BILLBOARD_FIXED_Y: { - code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],WORLD_MATRIX[1],vec4(normalize(cross(CAMERA_MATRIX[0].xyz,WORLD_MATRIX[1].xyz)), 0.0),WORLD_MATRIX[3]);\n"; if (flags[FLAG_BILLBOARD_KEEP_SCALE]) { @@ -744,7 +706,6 @@ void BaseMaterial3D::_update_shader() { } } break; case BILLBOARD_PARTICLES: { - //make billboard code += "\tmat4 mat_world = mat4(normalize(CAMERA_MATRIX[0])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[1])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[2])*length(WORLD_MATRIX[2]),WORLD_MATRIX[3]);\n"; //rotate by rotation @@ -768,7 +729,6 @@ void BaseMaterial3D::_update_shader() { } if (flags[FLAG_FIXED_SIZE]) { - code += "\tif (PROJECTION_MATRIX[3][3] != 0.0) {\n"; //orthogonal matrix, try to do about the same //with viewport size @@ -803,7 +763,6 @@ void BaseMaterial3D::_update_shader() { } if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n"; code += "\tuv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n"; code += "\tuv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n"; @@ -811,7 +770,6 @@ void BaseMaterial3D::_update_shader() { } if (flags[FLAG_UV2_USE_TRIPLANAR]) { - code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n"; code += "\tuv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n"; code += "\tuv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n"; @@ -992,7 +950,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_REFRACTION]) { - if (features[FEATURE_NORMAL_MAPPING]) { code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * NORMALMAP.x + BINORMAL * NORMALMAP.y + NORMAL * NORMALMAP.z,NORMALMAP_DEPTH) );\n"; } else { @@ -1023,7 +980,6 @@ void BaseMaterial3D::_update_shader() { if (distance_fade != DISTANCE_FADE_DISABLED) { if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) { - if (!RenderingServer::get_singleton()->is_low_end()) { code += "\t{\n"; if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) { @@ -1097,7 +1053,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_AMBIENT_OCCLUSION]) { - if (!orm) { if (flags[FLAG_AO_ON_UV2]) { if (flags[FLAG_UV2_USE_TRIPLANAR]) { @@ -1120,7 +1075,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_SUBSURFACE_SCATTERING]) { - if (flags[FLAG_UV1_USE_TRIPLANAR]) { code += "\tfloat sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r;\n"; } else { @@ -1130,7 +1084,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_SUBSURFACE_TRANSMITTANCE]) { - if (flags[FLAG_UV1_USE_TRIPLANAR]) { code += "\tvec4 trans_color_tex = triplanar_texture(texture_subsurface_transmittance,uv1_power_normal,uv1_triplanar_pos);\n"; } else { @@ -1153,7 +1106,6 @@ void BaseMaterial3D::_update_shader() { } if (features[FEATURE_DETAIL]) { - bool triplanar = (flags[FLAG_UV1_USE_TRIPLANAR] && detail_uv == DETAIL_UV_1) || (flags[FLAG_UV2_USE_TRIPLANAR] && detail_uv == DETAIL_UV_2); if (triplanar) { @@ -1168,7 +1120,6 @@ void BaseMaterial3D::_update_shader() { } if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal,uv1_triplanar_pos);\n"; } else { code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n"; @@ -1208,17 +1159,14 @@ void BaseMaterial3D::_update_shader() { } void BaseMaterial3D::flush_changes() { - MutexLock lock(material_mutex); while (dirty_materials->first()) { - dirty_materials->first()->self()->_update_shader(); } } void BaseMaterial3D::_queue_shader_change() { - MutexLock lock(material_mutex); if (!element.in_list()) { @@ -1227,167 +1175,136 @@ void BaseMaterial3D::_queue_shader_change() { } bool BaseMaterial3D::_is_shader_dirty() const { - MutexLock lock(material_mutex); return element.in_list(); } void BaseMaterial3D::set_albedo(const Color &p_albedo) { - albedo = p_albedo; RS::get_singleton()->material_set_param(_get_material(), shader_names->albedo, p_albedo); } Color BaseMaterial3D::get_albedo() const { - return albedo; } void BaseMaterial3D::set_specular(float p_specular) { - specular = p_specular; RS::get_singleton()->material_set_param(_get_material(), shader_names->specular, p_specular); } float BaseMaterial3D::get_specular() const { - return specular; } void BaseMaterial3D::set_roughness(float p_roughness) { - roughness = p_roughness; RS::get_singleton()->material_set_param(_get_material(), shader_names->roughness, p_roughness); } float BaseMaterial3D::get_roughness() const { - return roughness; } void BaseMaterial3D::set_metallic(float p_metallic) { - metallic = p_metallic; RS::get_singleton()->material_set_param(_get_material(), shader_names->metallic, p_metallic); } float BaseMaterial3D::get_metallic() const { - return metallic; } void BaseMaterial3D::set_emission(const Color &p_emission) { - emission = p_emission; RS::get_singleton()->material_set_param(_get_material(), shader_names->emission, p_emission); } Color BaseMaterial3D::get_emission() const { - return emission; } void BaseMaterial3D::set_emission_energy(float p_emission_energy) { - emission_energy = p_emission_energy; RS::get_singleton()->material_set_param(_get_material(), shader_names->emission_energy, p_emission_energy); } float BaseMaterial3D::get_emission_energy() const { - return emission_energy; } void BaseMaterial3D::set_normal_scale(float p_normal_scale) { - normal_scale = p_normal_scale; RS::get_singleton()->material_set_param(_get_material(), shader_names->normal_scale, p_normal_scale); } float BaseMaterial3D::get_normal_scale() const { - return normal_scale; } void BaseMaterial3D::set_rim(float p_rim) { - rim = p_rim; RS::get_singleton()->material_set_param(_get_material(), shader_names->rim, p_rim); } float BaseMaterial3D::get_rim() const { - return rim; } void BaseMaterial3D::set_rim_tint(float p_rim_tint) { - rim_tint = p_rim_tint; RS::get_singleton()->material_set_param(_get_material(), shader_names->rim_tint, p_rim_tint); } float BaseMaterial3D::get_rim_tint() const { - return rim_tint; } void BaseMaterial3D::set_ao_light_affect(float p_ao_light_affect) { - ao_light_affect = p_ao_light_affect; RS::get_singleton()->material_set_param(_get_material(), shader_names->ao_light_affect, p_ao_light_affect); } float BaseMaterial3D::get_ao_light_affect() const { - return ao_light_affect; } void BaseMaterial3D::set_clearcoat(float p_clearcoat) { - clearcoat = p_clearcoat; RS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat, p_clearcoat); } float BaseMaterial3D::get_clearcoat() const { - return clearcoat; } void BaseMaterial3D::set_clearcoat_gloss(float p_clearcoat_gloss) { - clearcoat_gloss = p_clearcoat_gloss; RS::get_singleton()->material_set_param(_get_material(), shader_names->clearcoat_gloss, p_clearcoat_gloss); } float BaseMaterial3D::get_clearcoat_gloss() const { - return clearcoat_gloss; } void BaseMaterial3D::set_anisotropy(float p_anisotropy) { - anisotropy = p_anisotropy; RS::get_singleton()->material_set_param(_get_material(), shader_names->anisotropy, p_anisotropy); } float BaseMaterial3D::get_anisotropy() const { - return anisotropy; } void BaseMaterial3D::set_heightmap_scale(float p_heightmap_scale) { - heightmap_scale = p_heightmap_scale; RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_scale, p_heightmap_scale); } float BaseMaterial3D::get_heightmap_scale() const { - return heightmap_scale; } void BaseMaterial3D::set_subsurface_scattering_strength(float p_subsurface_scattering_strength) { - subsurface_scattering_strength = p_subsurface_scattering_strength; RS::get_singleton()->material_set_param(_get_material(), shader_names->subsurface_scattering_strength, subsurface_scattering_strength); } float BaseMaterial3D::get_subsurface_scattering_strength() const { - return subsurface_scattering_strength; } @@ -1425,29 +1342,24 @@ float BaseMaterial3D::get_transmittance_boost() const { } void BaseMaterial3D::set_backlight(const Color &p_backlight) { - backlight = p_backlight; RS::get_singleton()->material_set_param(_get_material(), shader_names->backlight, backlight); } Color BaseMaterial3D::get_backlight() const { - return backlight; } void BaseMaterial3D::set_refraction(float p_refraction) { - refraction = p_refraction; RS::get_singleton()->material_set_param(_get_material(), shader_names->refraction, refraction); } float BaseMaterial3D::get_refraction() const { - return refraction; } void BaseMaterial3D::set_detail_uv(DetailUV p_detail_uv) { - if (detail_uv == p_detail_uv) return; @@ -1455,12 +1367,10 @@ void BaseMaterial3D::set_detail_uv(DetailUV p_detail_uv) { _queue_shader_change(); } BaseMaterial3D::DetailUV BaseMaterial3D::get_detail_uv() const { - return detail_uv; } void BaseMaterial3D::set_blend_mode(BlendMode p_mode) { - if (blend_mode == p_mode) return; @@ -1468,22 +1378,18 @@ void BaseMaterial3D::set_blend_mode(BlendMode p_mode) { _queue_shader_change(); } BaseMaterial3D::BlendMode BaseMaterial3D::get_blend_mode() const { - return blend_mode; } void BaseMaterial3D::set_detail_blend_mode(BlendMode p_mode) { - detail_blend_mode = p_mode; _queue_shader_change(); } BaseMaterial3D::BlendMode BaseMaterial3D::get_detail_blend_mode() const { - return detail_blend_mode; } void BaseMaterial3D::set_transparency(Transparency p_transparency) { - if (transparency == p_transparency) { return; } @@ -1498,7 +1404,6 @@ BaseMaterial3D::Transparency BaseMaterial3D::get_transparency() const { } void BaseMaterial3D::set_shading_mode(ShadingMode p_shading_mode) { - if (shading_mode == p_shading_mode) { return; } @@ -1513,7 +1418,6 @@ BaseMaterial3D::ShadingMode BaseMaterial3D::get_shading_mode() const { } void BaseMaterial3D::set_depth_draw_mode(DepthDrawMode p_mode) { - if (depth_draw_mode == p_mode) return; @@ -1521,12 +1425,10 @@ void BaseMaterial3D::set_depth_draw_mode(DepthDrawMode p_mode) { _queue_shader_change(); } BaseMaterial3D::DepthDrawMode BaseMaterial3D::get_depth_draw_mode() const { - return depth_draw_mode; } void BaseMaterial3D::set_cull_mode(CullMode p_mode) { - if (cull_mode == p_mode) return; @@ -1534,12 +1436,10 @@ void BaseMaterial3D::set_cull_mode(CullMode p_mode) { _queue_shader_change(); } BaseMaterial3D::CullMode BaseMaterial3D::get_cull_mode() const { - return cull_mode; } void BaseMaterial3D::set_diffuse_mode(DiffuseMode p_mode) { - if (diffuse_mode == p_mode) return; @@ -1547,12 +1447,10 @@ void BaseMaterial3D::set_diffuse_mode(DiffuseMode p_mode) { _queue_shader_change(); } BaseMaterial3D::DiffuseMode BaseMaterial3D::get_diffuse_mode() const { - return diffuse_mode; } void BaseMaterial3D::set_specular_mode(SpecularMode p_mode) { - if (specular_mode == p_mode) return; @@ -1560,12 +1458,10 @@ void BaseMaterial3D::set_specular_mode(SpecularMode p_mode) { _queue_shader_change(); } BaseMaterial3D::SpecularMode BaseMaterial3D::get_specular_mode() const { - return specular_mode; } void BaseMaterial3D::set_flag(Flags p_flag, bool p_enabled) { - ERR_FAIL_INDEX(p_flag, FLAG_MAX); if (flags[p_flag] == p_enabled) @@ -1579,13 +1475,11 @@ void BaseMaterial3D::set_flag(Flags p_flag, bool p_enabled) { } bool BaseMaterial3D::get_flag(Flags p_flag) const { - ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } void BaseMaterial3D::set_feature(Feature p_feature, bool p_enabled) { - ERR_FAIL_INDEX(p_feature, FEATURE_MAX); if (features[p_feature] == p_enabled) return; @@ -1596,13 +1490,11 @@ void BaseMaterial3D::set_feature(Feature p_feature, bool p_enabled) { } bool BaseMaterial3D::get_feature(Feature p_feature) const { - ERR_FAIL_INDEX_V(p_feature, FEATURE_MAX, false); return features[p_feature]; } void BaseMaterial3D::set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture) { - ERR_FAIL_INDEX(p_param, TEXTURE_MAX); textures[p_param] = p_texture; RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); @@ -1612,7 +1504,6 @@ void BaseMaterial3D::set_texture(TextureParam p_param, const Ref<Texture2D> &p_t } Ref<Texture2D> BaseMaterial3D::get_texture(TextureParam p_param) const { - ERR_FAIL_INDEX_V(p_param, TEXTURE_MAX, Ref<Texture2D>()); return textures[p_param]; } @@ -1695,7 +1586,6 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { } if (orm) { - if (property.name == "shading_mode") { property.hint_string = "Unshaded,PerPixel"; //vertex not supported in ORM mode, since no individual roughness. } @@ -1710,9 +1600,7 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { } if (shading_mode != SHADING_MODE_PER_PIXEL) { - if (shading_mode != SHADING_MODE_PER_VERTEX) { - //these may still work per vertex if (property.name.begins_with("ao")) { property.usage = 0; @@ -1761,176 +1649,144 @@ void BaseMaterial3D::_validate_property(PropertyInfo &property) const { } void BaseMaterial3D::set_point_size(float p_point_size) { - point_size = p_point_size; RS::get_singleton()->material_set_param(_get_material(), shader_names->point_size, p_point_size); } float BaseMaterial3D::get_point_size() const { - return point_size; } void BaseMaterial3D::set_uv1_scale(const Vector3 &p_scale) { - uv1_scale = p_scale; RS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_scale, p_scale); } Vector3 BaseMaterial3D::get_uv1_scale() const { - return uv1_scale; } void BaseMaterial3D::set_uv1_offset(const Vector3 &p_offset) { - uv1_offset = p_offset; RS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_offset, p_offset); } Vector3 BaseMaterial3D::get_uv1_offset() const { - return uv1_offset; } void BaseMaterial3D::set_uv1_triplanar_blend_sharpness(float p_sharpness) { - uv1_triplanar_sharpness = p_sharpness; RS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, p_sharpness); } float BaseMaterial3D::get_uv1_triplanar_blend_sharpness() const { - return uv1_triplanar_sharpness; } void BaseMaterial3D::set_uv2_scale(const Vector3 &p_scale) { - uv2_scale = p_scale; RS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_scale, p_scale); } Vector3 BaseMaterial3D::get_uv2_scale() const { - return uv2_scale; } void BaseMaterial3D::set_uv2_offset(const Vector3 &p_offset) { - uv2_offset = p_offset; RS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_offset, p_offset); } Vector3 BaseMaterial3D::get_uv2_offset() const { - return uv2_offset; } void BaseMaterial3D::set_uv2_triplanar_blend_sharpness(float p_sharpness) { - uv2_triplanar_sharpness = p_sharpness; RS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, p_sharpness); } float BaseMaterial3D::get_uv2_triplanar_blend_sharpness() const { - return uv2_triplanar_sharpness; } void BaseMaterial3D::set_billboard_mode(BillboardMode p_mode) { - billboard_mode = p_mode; _queue_shader_change(); _change_notify(); } BaseMaterial3D::BillboardMode BaseMaterial3D::get_billboard_mode() const { - return billboard_mode; } void BaseMaterial3D::set_particles_anim_h_frames(int p_frames) { - particles_anim_h_frames = p_frames; RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_h_frames, p_frames); } int BaseMaterial3D::get_particles_anim_h_frames() const { - return particles_anim_h_frames; } void BaseMaterial3D::set_particles_anim_v_frames(int p_frames) { - particles_anim_v_frames = p_frames; RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_v_frames, p_frames); } int BaseMaterial3D::get_particles_anim_v_frames() const { - return particles_anim_v_frames; } void BaseMaterial3D::set_particles_anim_loop(bool p_loop) { - particles_anim_loop = p_loop; RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop); } bool BaseMaterial3D::get_particles_anim_loop() const { - return particles_anim_loop; } void BaseMaterial3D::set_heightmap_deep_parallax(bool p_enable) { - deep_parallax = p_enable; _queue_shader_change(); _change_notify(); } bool BaseMaterial3D::is_heightmap_deep_parallax_enabled() const { - return deep_parallax; } void BaseMaterial3D::set_heightmap_deep_parallax_min_layers(int p_layer) { - deep_parallax_min_layers = p_layer; RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_min_layers, p_layer); } int BaseMaterial3D::get_heightmap_deep_parallax_min_layers() const { - return deep_parallax_min_layers; } void BaseMaterial3D::set_heightmap_deep_parallax_max_layers(int p_layer) { - deep_parallax_max_layers = p_layer; RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_max_layers, p_layer); } int BaseMaterial3D::get_heightmap_deep_parallax_max_layers() const { - return deep_parallax_max_layers; } void BaseMaterial3D::set_heightmap_deep_parallax_flip_tangent(bool p_flip) { - heightmap_parallax_flip_tangent = p_flip; RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_flip, Vector2(heightmap_parallax_flip_tangent ? -1 : 1, heightmap_parallax_flip_binormal ? -1 : 1)); } bool BaseMaterial3D::get_heightmap_deep_parallax_flip_tangent() const { - return heightmap_parallax_flip_tangent; } void BaseMaterial3D::set_heightmap_deep_parallax_flip_binormal(bool p_flip) { - heightmap_parallax_flip_binormal = p_flip; RS::get_singleton()->material_set_param(_get_material(), shader_names->heightmap_flip, Vector2(heightmap_parallax_flip_tangent ? -1 : 1, heightmap_parallax_flip_binormal ? -1 : 1)); } bool BaseMaterial3D::get_heightmap_deep_parallax_flip_binormal() const { - return heightmap_parallax_flip_binormal; } @@ -1950,7 +1806,6 @@ void BaseMaterial3D::set_alpha_scissor_threshold(float p_threshold) { } float BaseMaterial3D::get_alpha_scissor_threshold() const { - return alpha_scissor_threshold; } @@ -1960,7 +1815,6 @@ void BaseMaterial3D::set_grow(float p_grow) { } float BaseMaterial3D::get_grow() const { - return grow; } @@ -1987,7 +1841,6 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_metallic_texture_channel() co } void BaseMaterial3D::set_roughness_texture_channel(TextureChannel p_channel) { - ERR_FAIL_INDEX(p_channel, 5); roughness_texture_channel = p_channel; _queue_shader_change(); @@ -1998,7 +1851,6 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_roughness_texture_channel() c } void BaseMaterial3D::set_ao_texture_channel(TextureChannel p_channel) { - ERR_FAIL_INDEX(p_channel, 5); ao_texture_channel = p_channel; RS::get_singleton()->material_set_param(_get_material(), shader_names->ao_texture_channel, _get_texture_mask(p_channel)); @@ -2009,7 +1861,6 @@ BaseMaterial3D::TextureChannel BaseMaterial3D::get_ao_texture_channel() const { } void BaseMaterial3D::set_refraction_texture_channel(TextureChannel p_channel) { - ERR_FAIL_INDEX(p_channel, 5); refraction_texture_channel = p_channel; RS::get_singleton()->material_set_param(_get_material(), shader_names->refraction_texture_channel, _get_texture_mask(p_channel)); @@ -2020,7 +1871,6 @@ 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) version = 1; @@ -2066,61 +1916,50 @@ void BaseMaterial3D::set_on_top_of_alpha() { } void BaseMaterial3D::set_proximity_fade(bool p_enable) { - proximity_fade_enabled = p_enable; _queue_shader_change(); _change_notify(); } bool BaseMaterial3D::is_proximity_fade_enabled() const { - return proximity_fade_enabled; } void BaseMaterial3D::set_proximity_fade_distance(float p_distance) { - proximity_fade_distance = p_distance; RS::get_singleton()->material_set_param(_get_material(), shader_names->proximity_fade_distance, p_distance); } float BaseMaterial3D::get_proximity_fade_distance() const { - return proximity_fade_distance; } void BaseMaterial3D::set_distance_fade(DistanceFadeMode p_mode) { - distance_fade = p_mode; _queue_shader_change(); _change_notify(); } BaseMaterial3D::DistanceFadeMode BaseMaterial3D::get_distance_fade() const { - return distance_fade; } void BaseMaterial3D::set_distance_fade_max_distance(float p_distance) { - distance_fade_max_distance = p_distance; RS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_max, distance_fade_max_distance); } float BaseMaterial3D::get_distance_fade_max_distance() const { - return distance_fade_max_distance; } void BaseMaterial3D::set_distance_fade_min_distance(float p_distance) { - distance_fade_min_distance = p_distance; RS::get_singleton()->material_set_param(_get_material(), shader_names->distance_fade_min, distance_fade_min_distance); } float BaseMaterial3D::get_distance_fade_min_distance() const { - return distance_fade_min_distance; } void BaseMaterial3D::set_emission_operator(EmissionOperator p_op) { - if (emission_op == p_op) return; emission_op = p_op; @@ -2128,23 +1967,19 @@ void BaseMaterial3D::set_emission_operator(EmissionOperator p_op) { } BaseMaterial3D::EmissionOperator BaseMaterial3D::get_emission_operator() const { - return emission_op; } RID BaseMaterial3D::get_shader_rid() const { - ERR_FAIL_COND_V(!shader_map.has(current_key), RID()); return shader_map[current_key].shader; } Shader::Mode BaseMaterial3D::get_shader_mode() const { - return Shader::MODE_SPATIAL; } void BaseMaterial3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &BaseMaterial3D::set_albedo); ClassDB::bind_method(D_METHOD("get_albedo"), &BaseMaterial3D::get_albedo); @@ -2622,7 +2457,6 @@ void BaseMaterial3D::_bind_methods() { BaseMaterial3D::BaseMaterial3D(bool p_orm) : element(this) { - orm = p_orm; // Initialize to the same values as the shader transparency = TRANSPARENCY_DISABLED; @@ -2709,7 +2543,6 @@ BaseMaterial3D::BaseMaterial3D(bool p_orm) : } BaseMaterial3D::~BaseMaterial3D() { - MutexLock lock(material_mutex); if (shader_map.has(current_key)) { diff --git a/scene/resources/material.h b/scene/resources/material.h index 241357ba9b..433e3d304e 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -39,7 +39,6 @@ #include "servers/rendering_server.h" class Material : public Resource { - GDCLASS(Material, Resource); RES_BASE_EXTENSION("material") OBJ_SAVE_TYPE(Material); @@ -74,7 +73,6 @@ public: }; class ShaderMaterial : public Material { - GDCLASS(ShaderMaterial, Material); Ref<Shader> shader; @@ -109,7 +107,6 @@ public: class StandardMaterial3D; class BaseMaterial3D : public Material { - GDCLASS(BaseMaterial3D, Material); public: @@ -269,7 +266,6 @@ public: private: union MaterialKey { - struct { uint64_t feature_mask : FEATURE_MAX; uint64_t detail_uv : 1; @@ -316,7 +312,6 @@ private: MaterialKey current_key; _FORCE_INLINE_ MaterialKey _compute_key() const { - MaterialKey mk; mk.key0 = 0; mk.key1 = 0; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 6548c65cd7..9c641cf6d8 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -40,22 +40,18 @@ Mesh::ConvexDecompositionFunc Mesh::convex_composition_function = nullptr; Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { - 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) continue; if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { - facecount += surface_get_array_index_len(i); } else { - facecount += surface_get_array_len(i); } } @@ -70,7 +66,6 @@ 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) continue; @@ -82,7 +77,6 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { const Vector3 *vr = vertices.ptr(); if (surface_get_format(i) & ARRAY_FORMAT_INDEX) { - int ic = surface_get_array_index_len(i); Vector<int> indices = a[ARRAY_INDEX]; const int *ir = indices.ptr(); @@ -93,7 +87,6 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { } } else { - for (int j = 0; j < vc; j++) facesw[widx++] = vr[j]; } @@ -106,7 +99,6 @@ Ref<TriangleMesh> Mesh::generate_triangle_mesh() const { } void Mesh::generate_debug_mesh_lines(Vector<Vector3> &r_lines) { - if (debug_lines.size() > 0) { r_lines = debug_lines; return; @@ -161,7 +153,6 @@ 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()) return tm->get_faces(); @@ -227,11 +218,9 @@ Vector<Face3> Mesh::get_faces() const { } Ref<Shape3D> Mesh::create_convex_shape() const { - Vector<Vector3> vertices; for (int i = 0; i < get_surface_count(); i++) { - Array a = surface_get_arrays(i); ERR_FAIL_COND_V(a.empty(), Ref<ConvexPolygonShape3D>()); Vector<Vector3> v = a[ARRAY_VERTEX]; @@ -244,7 +233,6 @@ Ref<Shape3D> Mesh::create_convex_shape() const { } Ref<Shape3D> Mesh::create_trimesh_shape() const { - Vector<Face3> faces = get_faces(); if (faces.size() == 0) return Ref<Shape3D>(); @@ -253,7 +241,6 @@ Ref<Shape3D> Mesh::create_trimesh_shape() const { face_points.resize(faces.size() * 3); for (int i = 0; i < face_points.size(); i += 3) { - Face3 f = faces.get(i / 3); face_points.set(i, f.vertex[0]); face_points.set(i + 1, f.vertex[1]); @@ -266,11 +253,9 @@ Ref<Shape3D> Mesh::create_trimesh_shape() const { } 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) continue; @@ -282,10 +267,8 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { Vector<Vector3> v = a[ARRAY_VERTEX]; index_accum += v.size(); } else { - int vcount = 0; for (int j = 0; j < arrays.size(); j++) { - if (arrays[j].get_type() == Variant::NIL || a[j].get_type() == Variant::NIL) { //mismatch, do not use arrays[j] = Variant(); @@ -293,10 +276,8 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { } switch (j) { - case ARRAY_VERTEX: case ARRAY_NORMAL: { - Vector<Vector3> dst = arrays[j]; Vector<Vector3> src = a[j]; if (j == ARRAY_VERTEX) @@ -311,7 +292,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { case ARRAY_TANGENT: case ARRAY_BONES: case ARRAY_WEIGHTS: { - Vector<real_t> dst = arrays[j]; Vector<real_t> src = a[j]; if (dst.size() == 0 || src.size() == 0) { @@ -391,7 +371,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { //fill normals with triangle normals for (int i = 0; i < vc; i += 3) { - Vector3 t[3]; if (has_indices) { @@ -407,7 +386,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { Vector3 n = Plane(t[0], t[1], t[2]).normal; for (int j = 0; j < 3; j++) { - Map<Vector3, Vector3>::Element *E = normal_accum.find(t[j]); if (!E) { normal_accum[t[j]] = n; @@ -430,7 +408,6 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { int vc2 = vertices.size(); for (int i = 0; i < vc2; i++) { - Vector3 t = r[i]; Map<Vector3, Vector3>::Element *E = normal_accum.find(t); @@ -443,13 +420,11 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { arrays[ARRAY_VERTEX] = vertices; if (!has_indices) { - Vector<int> new_indices; new_indices.resize(vertices.size()); int *iw = new_indices.ptrw(); for (int j = 0; j < vc2; j += 3) { - iw[j] = j; iw[j + 1] = j + 2; iw[j + 2] = j + 1; @@ -458,9 +433,7 @@ Ref<Mesh> Mesh::create_outline(float p_margin) const { arrays[ARRAY_INDEX] = new_indices; } else { - for (int j = 0; j < vc; j += 3) { - SWAP(ir[j + 1], ir[j + 2]); } arrays[ARRAY_INDEX] = indices; @@ -481,7 +454,6 @@ Size2i Mesh::get_lightmap_size_hint() const { } void Mesh::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &Mesh::set_lightmap_size_hint); ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint); ClassDB::bind_method(D_METHOD("get_aabb"), &Mesh::get_aabb); @@ -542,7 +514,6 @@ void Mesh::clear_cache() const { } Vector<Ref<Shape3D>> Mesh::convex_decompose() const { - ERR_FAIL_COND_V(!convex_composition_function, Vector<Ref<Shape3D>>()); const Vector<Face3> faces = get_faces(); @@ -582,7 +553,6 @@ Mesh::Mesh() { } static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, uint32_t p_format, uint32_t p_elements) { - bool vertex_16bit = p_format & ((1 << (Mesh::ARRAY_VERTEX + Mesh::ARRAY_COMPRESS_BASE))); bool has_bones = (p_format & Mesh::ARRAY_FORMAT_BONES); bool bone_8 = has_bones && !(p_format & (Mesh::ARRAY_COMPRESS_INDEX << 2)); @@ -607,7 +577,6 @@ static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, ui const uint8_t *r = p_src.ptr(); for (uint32_t i = 0; i < p_elements; i++) { - uint32_t remaining = src_stride; const uint8_t *src = (const uint8_t *)(r + src_stride * i); uint8_t *dst = (uint8_t *)(w + dst_stride * i); @@ -642,7 +611,6 @@ static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, ui } if (has_bones) { - remaining -= bone_8 ? 4 : 8; remaining -= weight_32 ? 16 : 8; } @@ -652,12 +620,10 @@ static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, ui } if (has_bones) { - dst += remaining; src += remaining; if (bone_8) { - const uint8_t *src_bones = (const uint8_t *)src; uint16_t *dst_bones = (uint16_t *)dst; @@ -678,7 +644,6 @@ static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, ui dst += 8; if (weight_32) { - const float *src_weights = (const float *)src; uint16_t *dst_weights = (uint16_t *)dst; @@ -700,11 +665,9 @@ static Vector<uint8_t> _fix_array_compatibility(const Vector<uint8_t> &p_src, ui } bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { - String sname = p_name; if (p_name == "blend_shape/names") { - Vector<String> sk = p_value; int sz = sk.size(); const String *r = sk.ptr(); @@ -714,13 +677,11 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } if (p_name == "blend_shape/mode") { - set_blend_shape_mode(BlendShapeMode(int(p_value))); return true; } if (sname.begins_with("surface_")) { - int sl = sname.find("/"); if (sl == -1) return false; @@ -744,7 +705,6 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { String what = sname.get_slicec('/', 2); if (idx == surfaces.size()) { - //create Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("primitive"), false); @@ -824,7 +784,6 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } if (d.has("material")) { - surface_set_material(idx, d["material"]); } if (d.has("name")) { @@ -839,7 +798,6 @@ bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { } Array ArrayMesh::_get_surfaces() const { - if (mesh.is_null()) { return Array(); } @@ -908,7 +866,6 @@ void ArrayMesh::_create_if_empty() const { } void ArrayMesh::_set_surfaces(const Array &p_surfaces) { - Vector<RS::SurfaceData> surface_data; Vector<Ref<Material>> surface_materials; Vector<String> surface_names; @@ -1031,25 +988,21 @@ void ArrayMesh::_set_surfaces(const Array &p_surfaces) { } bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { - 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++) sk.push_back(blend_shapes[i]); r_ret = sk; return true; } else if (p_name == "blend_shape/mode") { - r_ret = get_blend_shape_mode(); return true; } else if (sname.begins_with("surface_")) { - int sl = sname.find("/"); if (sl == -1) return false; @@ -1066,7 +1019,6 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { } void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { - if (_is_generated()) return; @@ -1076,7 +1028,6 @@ void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { } for (int i = 0; i < surfaces.size(); i++) { - p_list->push_back(PropertyInfo(Variant::STRING, "surface_" + itos(i + 1) + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); if (surfaces[i].is_2d) { p_list->push_back(PropertyInfo(Variant::OBJECT, "surface_" + itos(i + 1) + "/material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,CanvasItemMaterial", PROPERTY_USAGE_EDITOR)); @@ -1087,12 +1038,10 @@ void ArrayMesh::_get_property_list(List<PropertyInfo> *p_list) const { } void ArrayMesh::_recompute_aabb() { - // regenerate AABB aabb = AABB(); for (int i = 0; i < surfaces.size(); i++) { - if (i == 0) aabb = surfaces[i].aabb; else @@ -1103,7 +1052,6 @@ void ArrayMesh::_recompute_aabb() { #warning need to add binding to add_surface using future MeshSurfaceData object #endif void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const Vector<uint8_t> &p_array, int p_vertex_count, const Vector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<Vector<uint8_t>> &p_blend_shapes, const Vector<AABB> &p_bone_aabb, const Vector<RS::SurfaceData::LOD> &p_lods) { - _create_if_empty(); Surface s; @@ -1137,7 +1085,6 @@ void ArrayMesh::add_surface(uint32_t p_format, PrimitiveType p_primitive, const } void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, const Dictionary &p_lods, uint32_t p_flags) { - ERR_FAIL_COND(p_arrays.size() != ARRAY_MAX); RS::SurfaceData surface; @@ -1157,12 +1104,10 @@ void ArrayMesh::add_surface_from_arrays(PrimitiveType p_primitive, const Array & } Array ArrayMesh::surface_get_arrays(int p_surface) const { - ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); return RenderingServer::get_singleton()->mesh_surface_get_arrays(mesh, p_surface); } Array ArrayMesh::surface_get_blend_shape_arrays(int p_surface) const { - ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); return RenderingServer::get_singleton()->mesh_surface_get_blend_shape_arrays(mesh, p_surface); } @@ -1172,21 +1117,17 @@ Dictionary ArrayMesh::surface_get_lods(int p_surface) const { } int ArrayMesh::get_surface_count() const { - return surfaces.size(); } void ArrayMesh::add_blend_shape(const StringName &p_name) { - ERR_FAIL_COND_MSG(surfaces.size(), "Can't add a shape key count if surfaces are already created."); StringName name = p_name; if (blend_shapes.find(name) != -1) { - int count = 2; do { - name = String(p_name) + " " + itos(count); count++; } while (blend_shapes.find(name) != -1); @@ -1197,7 +1138,6 @@ void ArrayMesh::add_blend_shape(const StringName &p_name) { } int ArrayMesh::get_blend_shape_count() const { - return blend_shapes.size(); } StringName ArrayMesh::get_blend_shape_name(int p_index) const { @@ -1205,14 +1145,12 @@ StringName ArrayMesh::get_blend_shape_name(int p_index) const { return blend_shapes[p_index]; } void ArrayMesh::clear_blend_shapes() { - ERR_FAIL_COND_MSG(surfaces.size(), "Can't set shape key count if surfaces are already created."); blend_shapes.clear(); } void ArrayMesh::set_blend_shape_mode(BlendShapeMode p_mode) { - blend_shape_mode = p_mode; if (mesh.is_valid()) { RS::get_singleton()->mesh_set_blend_shape_mode(mesh, (RS::BlendShapeMode)p_mode); @@ -1220,36 +1158,30 @@ void ArrayMesh::set_blend_shape_mode(BlendShapeMode p_mode) { } ArrayMesh::BlendShapeMode ArrayMesh::get_blend_shape_mode() const { - return blend_shape_mode; } int ArrayMesh::surface_get_array_len(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, surfaces.size(), -1); return surfaces[p_idx].array_length; } int ArrayMesh::surface_get_array_index_len(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, surfaces.size(), -1); return surfaces[p_idx].index_array_length; } uint32_t ArrayMesh::surface_get_format(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, surfaces.size(), 0); return surfaces[p_idx].format; } ArrayMesh::PrimitiveType ArrayMesh::surface_get_primitive_type(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, surfaces.size(), PRIMITIVE_LINES); return surfaces[p_idx].primitive; } void ArrayMesh::surface_set_material(int p_idx, const Ref<Material> &p_material) { - ERR_FAIL_INDEX(p_idx, surfaces.size()); if (surfaces[p_idx].material == p_material) return; @@ -1270,7 +1202,6 @@ int ArrayMesh::surface_find_by_name(const String &p_name) const { } void ArrayMesh::surface_set_name(int p_idx, const String &p_name) { - ERR_FAIL_INDEX(p_idx, surfaces.size()); surfaces.write[p_idx].name = p_name; @@ -1278,20 +1209,17 @@ void ArrayMesh::surface_set_name(int p_idx, const String &p_name) { } String ArrayMesh::surface_get_name(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, surfaces.size(), String()); return surfaces[p_idx].name; } void ArrayMesh::surface_update_region(int p_surface, int p_offset, const Vector<uint8_t> &p_data) { - ERR_FAIL_INDEX(p_surface, surfaces.size()); RS::get_singleton()->mesh_surface_update_region(mesh, p_surface, p_offset, p_data); emit_changed(); } void ArrayMesh::surface_set_custom_aabb(int p_idx, const AABB &p_aabb) { - ERR_FAIL_INDEX(p_idx, surfaces.size()); surfaces.write[p_idx].aabb = p_aabb; // set custom aabb too? @@ -1299,18 +1227,15 @@ void ArrayMesh::surface_set_custom_aabb(int p_idx, const AABB &p_aabb) { } Ref<Material> ArrayMesh::surface_get_material(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, surfaces.size(), Ref<Material>()); return surfaces[p_idx].material; } RID ArrayMesh::get_rid() const { - _create_if_empty(); return mesh; } AABB ArrayMesh::get_aabb() const { - return aabb; } @@ -1324,7 +1249,6 @@ void ArrayMesh::clear_surfaces() { } void ArrayMesh::set_custom_aabb(const AABB &p_custom) { - _create_if_empty(); custom_aabb = p_custom; RS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); @@ -1332,18 +1256,15 @@ void ArrayMesh::set_custom_aabb(const AABB &p_custom) { } AABB ArrayMesh::get_custom_aabb() const { - return custom_aabb; } void ArrayMesh::regen_normalmaps() { - if (surfaces.size() == 0) { return; } Vector<Ref<SurfaceTool>> surfs; for (int i = 0; i < get_surface_count(); i++) { - Ref<SurfaceTool> st = memnew(SurfaceTool); st->create_from(Ref<ArrayMesh>(this), i); surfs.push_back(st); @@ -1352,7 +1273,6 @@ void ArrayMesh::regen_normalmaps() { clear_surfaces(); for (int i = 0; i < surfs.size(); i++) { - surfs.write[i]->generate_tangents(); surfs.write[i]->commit(Ref<ArrayMesh>(this)); } @@ -1362,7 +1282,6 @@ void ArrayMesh::regen_normalmaps() { bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y, int *&r_cache_data, unsigned int &r_cache_size, bool &r_used_cache); struct ArrayMeshLightmapSurface { - Ref<Material> material; Vector<SurfaceTool::Vertex> vertices; Mesh::PrimitiveType primitive; @@ -1377,7 +1296,6 @@ Error ArrayMesh::lightmap_unwrap(const Transform &p_base_transform, float p_texe } Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cache_size, bool &r_used_cache, const Transform &p_base_transform, float p_texel_size) { - ERR_FAIL_COND_V(!array_mesh_lightmap_unwrap_callback, ERR_UNCONFIGURED); ERR_FAIL_COND_V_MSG(blend_shapes.size() != 0, ERR_UNAVAILABLE, "Can't unwrap mesh with blend shapes."); @@ -1422,7 +1340,6 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach uv_indices.resize(vertex_ofs + vc); for (int j = 0; j < vc; j++) { - Vector3 v = transform.xform(r[j]); Vector3 n = normal_basis.xform(rn[j]).normalized(); @@ -1439,7 +1356,6 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach int ic = rindices.size(); 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()) continue; @@ -1497,7 +1413,6 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach print_verbose("Mesh: Gen indices: " + itos(gen_index_count)); //go through all indices for (int i = 0; i < gen_index_count; i += 3) { - ERR_FAIL_INDEX_V(gen_vertices[gen_indices[i + 0]], uv_indices.size(), ERR_BUG); ERR_FAIL_INDEX_V(gen_vertices[gen_indices[i + 1]], uv_indices.size(), ERR_BUG); ERR_FAIL_INDEX_V(gen_vertices[gen_indices[i + 2]], uv_indices.size(), ERR_BUG); @@ -1507,7 +1422,6 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach int surface = uv_indices[gen_vertices[gen_indices[i + 0]]].first; for (int j = 0; j < 3; j++) { - SurfaceTool::Vertex v = lightmap_surfaces[surface].vertices[uv_indices[gen_vertices[gen_indices[i + j]]].second]; if (lightmap_surfaces[surface].format & ARRAY_FORMAT_COLOR) { @@ -1559,7 +1473,6 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach } void ArrayMesh::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_blend_shape", "name"), &ArrayMesh::add_blend_shape); ClassDB::bind_method(D_METHOD("get_blend_shape_count"), &ArrayMesh::get_blend_shape_count); ClassDB::bind_method(D_METHOD("get_blend_shape_name", "index"), &ArrayMesh::get_blend_shape_name); @@ -1634,14 +1547,12 @@ void ArrayMesh::reload_from_file() { } ArrayMesh::ArrayMesh() { - //mesh is now created on demand //mesh = RenderingServer::get_singleton()->mesh_create(); blend_shape_mode = BLEND_SHAPE_MODE_RELATIVE; } ArrayMesh::~ArrayMesh() { - if (mesh.is_valid()) { RenderingServer::get_singleton()->free(mesh); } diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 80cd57846b..44e4e78322 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -152,7 +152,6 @@ public: }; class ArrayMesh : public Mesh { - GDCLASS(ArrayMesh, Mesh); RES_BASE_EXTENSION("mesh"); diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 76d96786bc..d428191f96 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -31,7 +31,6 @@ #include "mesh_data_tool.h" void MeshDataTool::clear() { - vertices.clear(); edges.clear(); faces.clear(); @@ -40,7 +39,6 @@ void MeshDataTool::clear() { } Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface) { - ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_mesh->surface_get_primitive_type(p_surface) != Mesh::PRIMITIVE_TRIANGLES, ERR_INVALID_PARAMETER); @@ -88,7 +86,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf vertices.resize(vcount); for (int i = 0; i < vcount; i++) { - Vertex v; v.vertex = vr[i]; if (nr) @@ -103,7 +100,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf v.color = col[i]; if (we) { - v.weights.push_back(we[i * 4 + 0]); v.weights.push_back(we[i * 4 + 1]); v.weights.push_back(we[i * 4 + 2]); @@ -111,7 +107,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf } if (bo) { - v.bones.push_back(bo[i * 4 + 0]); v.bones.push_back(bo[i * 4 + 1]); v.bones.push_back(bo[i * 4 + 2]); @@ -124,7 +119,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf Vector<int> indices; if (arrays[Mesh::ARRAY_INDEX].get_type() != Variant::NIL) { - indices = arrays[Mesh::ARRAY_INDEX]; } else { //make code simpler @@ -140,14 +134,12 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf Map<Point2i, int> edge_indices; for (int i = 0; i < icount; i += 3) { - Vertex *v[3] = { &vertices.write[r[i + 0]], &vertices.write[r[i + 1]], &vertices.write[r[i + 2]] }; int fidx = faces.size(); Face face; for (int j = 0; j < 3; j++) { - face.v[j] = r[i + j]; Point2i edge(r[i + j], r[i + (j + 1) % 3]); @@ -180,7 +172,6 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf } Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { - ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER); Array arr; arr.resize(Mesh::ARRAY_MAX); @@ -198,7 +189,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { Vector<int> in; { - v.resize(vcount); Vector3 *vr = v.ptrw(); @@ -245,7 +235,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { } for (int i = 0; i < vcount; i++) { - const Vertex &vtx = vertices[i]; vr[i] = vtx.vertex; @@ -265,7 +254,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { col[i] = vtx.color; if (we) { - we[i * 4 + 0] = vtx.weights[0]; we[i * 4 + 1] = vtx.weights[1]; we[i * 4 + 2] = vtx.weights[2]; @@ -273,7 +261,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { } if (bo) { - bo[i * 4 + 0] = vtx.bones[0]; bo[i * 4 + 1] = vtx.bones[1]; bo[i * 4 + 2] = vtx.bones[2]; @@ -285,7 +272,6 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { in.resize(fc * 3); int *iw = in.ptrw(); for (int i = 0; i < fc; i++) { - iw[i * 3 + 0] = faces[i].v[0]; iw[i * 3 + 1] = faces[i].v[1]; iw[i * 3 + 2] = faces[i].v[2]; @@ -318,108 +304,89 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { } int MeshDataTool::get_format() const { - return format; } int MeshDataTool::get_vertex_count() const { - return vertices.size(); } int MeshDataTool::get_edge_count() const { - return edges.size(); } int MeshDataTool::get_face_count() const { - return faces.size(); } Vector3 MeshDataTool::get_vertex(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector3()); return vertices[p_idx].vertex; } void MeshDataTool::set_vertex(int p_idx, const Vector3 &p_vertex) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].vertex = p_vertex; } Vector3 MeshDataTool::get_vertex_normal(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector3()); return vertices[p_idx].normal; } void MeshDataTool::set_vertex_normal(int p_idx, const Vector3 &p_normal) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].normal = p_normal; format |= Mesh::ARRAY_FORMAT_NORMAL; } Plane MeshDataTool::get_vertex_tangent(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Plane()); return vertices[p_idx].tangent; } void MeshDataTool::set_vertex_tangent(int p_idx, const Plane &p_tangent) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].tangent = p_tangent; format |= Mesh::ARRAY_FORMAT_TANGENT; } Vector2 MeshDataTool::get_vertex_uv(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector2()); return vertices[p_idx].uv; } void MeshDataTool::set_vertex_uv(int p_idx, const Vector2 &p_uv) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].uv = p_uv; format |= Mesh::ARRAY_FORMAT_TEX_UV; } Vector2 MeshDataTool::get_vertex_uv2(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector2()); return vertices[p_idx].uv2; } void MeshDataTool::set_vertex_uv2(int p_idx, const Vector2 &p_uv2) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].uv2 = p_uv2; format |= Mesh::ARRAY_FORMAT_TEX_UV2; } Color MeshDataTool::get_vertex_color(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Color()); return vertices[p_idx].color; } void MeshDataTool::set_vertex_color(int p_idx, const Color &p_color) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].color = p_color; format |= Mesh::ARRAY_FORMAT_COLOR; } Vector<int> MeshDataTool::get_vertex_bones(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector<int>()); return vertices[p_idx].bones; } void MeshDataTool::set_vertex_bones(int p_idx, const Vector<int> &p_bones) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].bones = p_bones; format |= Mesh::ARRAY_FORMAT_BONES; } Vector<float> MeshDataTool::get_vertex_weights(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector<float>()); return vertices[p_idx].weights; } @@ -430,75 +397,62 @@ void MeshDataTool::set_vertex_weights(int p_idx, const Vector<float> &p_weights) } Variant MeshDataTool::get_vertex_meta(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Variant()); return vertices[p_idx].meta; } void MeshDataTool::set_vertex_meta(int p_idx, const Variant &p_meta) { - ERR_FAIL_INDEX(p_idx, vertices.size()); vertices.write[p_idx].meta = p_meta; } Vector<int> MeshDataTool::get_vertex_edges(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector<int>()); return vertices[p_idx].edges; } Vector<int> MeshDataTool::get_vertex_faces(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, vertices.size(), Vector<int>()); return vertices[p_idx].faces; } int MeshDataTool::get_edge_vertex(int p_edge, int p_vertex) const { - ERR_FAIL_INDEX_V(p_edge, edges.size(), -1); ERR_FAIL_INDEX_V(p_vertex, 2, -1); return edges[p_edge].vertex[p_vertex]; } Vector<int> MeshDataTool::get_edge_faces(int p_edge) const { - ERR_FAIL_INDEX_V(p_edge, edges.size(), Vector<int>()); return edges[p_edge].faces; } Variant MeshDataTool::get_edge_meta(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, edges.size(), Variant()); return edges[p_idx].meta; } void MeshDataTool::set_edge_meta(int p_idx, const Variant &p_meta) { - ERR_FAIL_INDEX(p_idx, edges.size()); edges.write[p_idx].meta = p_meta; } int MeshDataTool::get_face_vertex(int p_face, int p_vertex) const { - ERR_FAIL_INDEX_V(p_face, faces.size(), -1); ERR_FAIL_INDEX_V(p_vertex, 3, -1); return faces[p_face].v[p_vertex]; } int MeshDataTool::get_face_edge(int p_face, int p_vertex) const { - ERR_FAIL_INDEX_V(p_face, faces.size(), -1); ERR_FAIL_INDEX_V(p_vertex, 3, -1); return faces[p_face].edges[p_vertex]; } Variant MeshDataTool::get_face_meta(int p_face) const { - ERR_FAIL_INDEX_V(p_face, faces.size(), Variant()); return faces[p_face].meta; } void MeshDataTool::set_face_meta(int p_face, const Variant &p_meta) { - ERR_FAIL_INDEX(p_face, faces.size()); faces.write[p_face].meta = p_meta; } Vector3 MeshDataTool::get_face_normal(int p_face) const { - ERR_FAIL_INDEX_V(p_face, faces.size(), Vector3()); Vector3 v0 = vertices[faces[p_face].v[0]].vertex; Vector3 v1 = vertices[faces[p_face].v[1]].vertex; @@ -508,17 +462,14 @@ Vector3 MeshDataTool::get_face_normal(int p_face) const { } Ref<Material> MeshDataTool::get_material() const { - return material; } void MeshDataTool::set_material(const Ref<Material> &p_material) { - material = p_material; } void MeshDataTool::_bind_methods() { - ClassDB::bind_method(D_METHOD("clear"), &MeshDataTool::clear); ClassDB::bind_method(D_METHOD("create_from_surface", "mesh", "surface"), &MeshDataTool::create_from_surface); ClassDB::bind_method(D_METHOD("commit_to_surface", "mesh"), &MeshDataTool::commit_to_surface); @@ -578,6 +529,5 @@ void MeshDataTool::_bind_methods() { } MeshDataTool::MeshDataTool() { - clear(); } diff --git a/scene/resources/mesh_data_tool.h b/scene/resources/mesh_data_tool.h index 5ac2c7e702..bf9f0dd25f 100644 --- a/scene/resources/mesh_data_tool.h +++ b/scene/resources/mesh_data_tool.h @@ -34,7 +34,6 @@ #include "scene/resources/mesh.h" class MeshDataTool : public Reference { - GDCLASS(MeshDataTool, Reference); int format; @@ -55,7 +54,6 @@ class MeshDataTool : public Reference { Vector<Vertex> vertices; struct Edge { - int vertex[2]; Vector<int> faces; Variant meta; @@ -64,7 +62,6 @@ class MeshDataTool : public Reference { Vector<Edge> edges; struct Face { - int v[3]; int edges[3]; Variant meta; diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index fffd192348..c0615d9b29 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -31,10 +31,8 @@ #include "mesh_library.h" bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (name.begins_with("item/")) { - int idx = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (!item_map.has(idx)) @@ -68,7 +66,6 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { } bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; int idx = name.get_slicec('/', 1).to_int(); ERR_FAIL_COND_V(!item_map.has(idx), false); @@ -93,9 +90,7 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const { } void MeshLibrary::_get_property_list(List<PropertyInfo> *p_list) const { - for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) { - String name = "item/" + itos(E->key()) + "/"; p_list->push_back(PropertyInfo(Variant::STRING, name + "name")); p_list->push_back(PropertyInfo(Variant::OBJECT, name + "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh")); @@ -108,7 +103,6 @@ void MeshLibrary::_get_property_list(List<PropertyInfo> *p_list) const { } void MeshLibrary::create_item(int p_item) { - ERR_FAIL_COND(p_item < 0); ERR_FAIL_COND(item_map.has(p_item)); item_map[p_item] = Item(); @@ -116,7 +110,6 @@ void MeshLibrary::create_item(int p_item) { } void MeshLibrary::set_item_name(int p_item, const String &p_name) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].name = p_name; emit_changed(); @@ -124,7 +117,6 @@ void MeshLibrary::set_item_name(int p_item, const String &p_name) { } void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].mesh = p_mesh; notify_change_to_owners(); @@ -133,7 +125,6 @@ void MeshLibrary::set_item_mesh(int p_item, const Ref<Mesh> &p_mesh) { } void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].shapes = p_shapes; _change_notify(); @@ -143,7 +134,6 @@ void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) } void MeshLibrary::set_item_navmesh(int p_item, const Ref<NavigationMesh> &p_navmesh) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].navmesh = p_navmesh; _change_notify(); @@ -153,7 +143,6 @@ void MeshLibrary::set_item_navmesh(int p_item, const Ref<NavigationMesh> &p_navm } void MeshLibrary::set_item_navmesh_transform(int p_item, const Transform &p_transform) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].navmesh_transform = p_transform; notify_change_to_owners(); @@ -162,7 +151,6 @@ void MeshLibrary::set_item_navmesh_transform(int p_item, const Transform &p_tran } void MeshLibrary::set_item_preview(int p_item, const Ref<Texture2D> &p_preview) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map[p_item].preview = p_preview; emit_changed(); @@ -170,47 +158,39 @@ void MeshLibrary::set_item_preview(int p_item, const Ref<Texture2D> &p_preview) } String MeshLibrary::get_item_name(int p_item) const { - ERR_FAIL_COND_V_MSG(!item_map.has(p_item), "", "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].name; } Ref<Mesh> MeshLibrary::get_item_mesh(int p_item) const { - ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Mesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].mesh; } Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const { - ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Vector<ShapeData>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].shapes; } Ref<NavigationMesh> MeshLibrary::get_item_navmesh(int p_item) const { - ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<NavigationMesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].navmesh; } Transform MeshLibrary::get_item_navmesh_transform(int p_item) const { - ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Transform(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].navmesh_transform; } Ref<Texture2D> MeshLibrary::get_item_preview(int p_item) const { - ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<Texture2D>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); return item_map[p_item].preview; } bool MeshLibrary::has_item(int p_item) const { - return item_map.has(p_item); } void MeshLibrary::remove_item(int p_item) { - ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'."); item_map.erase(p_item); notify_change_to_owners(); @@ -219,7 +199,6 @@ void MeshLibrary::remove_item(int p_item) { } void MeshLibrary::clear() { - item_map.clear(); notify_change_to_owners(); _change_notify(); @@ -227,12 +206,10 @@ void MeshLibrary::clear() { } Vector<int> MeshLibrary::get_item_list() const { - Vector<int> ret; ret.resize(item_map.size()); int idx = 0; for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) { - ret.write[idx++] = E->key(); } @@ -240,9 +217,7 @@ 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) return E->key(); } @@ -250,7 +225,6 @@ int MeshLibrary::find_item_by_name(const String &p_name) const { } int MeshLibrary::get_last_unused_item_id() const { - if (!item_map.size()) return 0; else @@ -258,7 +232,6 @@ int MeshLibrary::get_last_unused_item_id() const { } void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) { - ERR_FAIL_COND(p_shapes.size() & 1); Vector<ShapeData> shapes; for (int i = 0; i < p_shapes.size(); i += 2) { @@ -275,7 +248,6 @@ void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) { } Array MeshLibrary::_get_item_shapes(int p_item) const { - Vector<ShapeData> shapes = get_item_shapes(p_item); Array ret; for (int i = 0; i < shapes.size(); i++) { @@ -287,7 +259,6 @@ Array MeshLibrary::_get_item_shapes(int p_item) const { } void MeshLibrary::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_item", "id"), &MeshLibrary::create_item); ClassDB::bind_method(D_METHOD("set_item_name", "id", "name"), &MeshLibrary::set_item_name); ClassDB::bind_method(D_METHOD("set_item_mesh", "id", "mesh"), &MeshLibrary::set_item_mesh); diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index 55001f2545..7b78398669 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -38,7 +38,6 @@ #include "shape_3d.h" class MeshLibrary : public Resource { - GDCLASS(MeshLibrary, Resource); RES_BASE_EXTENSION("meshlib"); diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index ce561bfaaf..795ec0df4b 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -48,7 +48,6 @@ void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) { const Vector3 *r = xforms.ptr(); for (int i = 0; i < len / 4; i++) { - Transform t; t.basis[0] = r[i * 4 + 0]; t.basis[1] = r[i * 4 + 1]; @@ -60,7 +59,6 @@ void MultiMesh::_set_transform_array(const Vector<Vector3> &p_array) { } Vector<Vector3> MultiMesh::_get_transform_array() const { - if (transform_format != TRANSFORM_3D) return Vector<Vector3>(); @@ -73,7 +71,6 @@ Vector<Vector3> MultiMesh::_get_transform_array() const { Vector3 *w = xforms.ptrw(); for (int i = 0; i < instance_count; i++) { - Transform t = get_instance_transform(i); w[i * 4 + 0] = t.basis[0]; w[i * 4 + 1] = t.basis[1]; @@ -85,7 +82,6 @@ Vector<Vector3> MultiMesh::_get_transform_array() const { } void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) { - if (transform_format != TRANSFORM_2D) return; @@ -98,7 +94,6 @@ void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) { const Vector2 *r = xforms.ptr(); for (int i = 0; i < len / 3; i++) { - Transform2D t; t.elements[0] = r[i * 3 + 0]; t.elements[1] = r[i * 3 + 1]; @@ -109,7 +104,6 @@ void MultiMesh::_set_transform_2d_array(const Vector<Vector2> &p_array) { } Vector<Vector2> MultiMesh::_get_transform_2d_array() const { - if (transform_format != TRANSFORM_2D) return Vector<Vector2>(); @@ -122,7 +116,6 @@ Vector<Vector2> MultiMesh::_get_transform_2d_array() const { Vector2 *w = xforms.ptrw(); for (int i = 0; i < instance_count; i++) { - Transform2D t = get_instance_transform_2d(i); w[i * 3 + 0] = t.elements[0]; w[i * 3 + 1] = t.elements[1]; @@ -133,7 +126,6 @@ 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) @@ -143,13 +135,11 @@ void MultiMesh::_set_color_array(const Vector<Color> &p_array) { const Color *r = colors.ptr(); for (int i = 0; i < len; i++) { - set_instance_color(i, r[i]); } } Vector<Color> MultiMesh::_get_color_array() const { - if (instance_count == 0 || !use_colors) return Vector<Color>(); @@ -157,7 +147,6 @@ Vector<Color> MultiMesh::_get_color_array() const { colors.resize(instance_count); for (int i = 0; i < instance_count; i++) { - colors.set(i, get_instance_color(i)); } @@ -165,7 +154,6 @@ 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) @@ -175,13 +163,11 @@ void MultiMesh::_set_custom_data_array(const Vector<Color> &p_array) { const Color *r = custom_datas.ptr(); for (int i = 0; i < len; i++) { - set_instance_custom_data(i, r[i]); } } Vector<Color> MultiMesh::_get_custom_data_array() const { - if (instance_count == 0 || !use_custom_data) return Vector<Color>(); @@ -189,7 +175,6 @@ Vector<Color> MultiMesh::_get_custom_data_array() const { custom_datas.resize(instance_count); for (int i = 0; i < instance_count; i++) { - custom_datas.set(i, get_instance_custom_data(i)); } @@ -206,7 +191,6 @@ Vector<float> MultiMesh::get_buffer() const { } void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) { - mesh = p_mesh; if (!mesh.is_null()) RenderingServer::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); @@ -215,7 +199,6 @@ void MultiMesh::set_mesh(const Ref<Mesh> &p_mesh) { } Ref<Mesh> MultiMesh::get_mesh() const { - return mesh; } @@ -225,7 +208,6 @@ void MultiMesh::set_instance_count(int p_count) { instance_count = p_count; } int MultiMesh::get_instance_count() const { - return instance_count; } @@ -236,55 +218,44 @@ void MultiMesh::set_visible_instance_count(int p_count) { visible_instance_count = p_count; } int MultiMesh::get_visible_instance_count() const { - return visible_instance_count; } void MultiMesh::set_instance_transform(int p_instance, const Transform &p_transform) { - RenderingServer::get_singleton()->multimesh_instance_set_transform(multimesh, p_instance, p_transform); } void MultiMesh::set_instance_transform_2d(int p_instance, const Transform2D &p_transform) { - RenderingServer::get_singleton()->multimesh_instance_set_transform_2d(multimesh, p_instance, p_transform); } Transform MultiMesh::get_instance_transform(int p_instance) const { - return RenderingServer::get_singleton()->multimesh_instance_get_transform(multimesh, p_instance); } Transform2D MultiMesh::get_instance_transform_2d(int p_instance) const { - return RenderingServer::get_singleton()->multimesh_instance_get_transform_2d(multimesh, p_instance); } void MultiMesh::set_instance_color(int p_instance, const Color &p_color) { - RenderingServer::get_singleton()->multimesh_instance_set_color(multimesh, p_instance, p_color); } Color MultiMesh::get_instance_color(int p_instance) const { - return RenderingServer::get_singleton()->multimesh_instance_get_color(multimesh, p_instance); } void MultiMesh::set_instance_custom_data(int p_instance, const Color &p_custom_data) { - RenderingServer::get_singleton()->multimesh_instance_set_custom_data(multimesh, p_instance, p_custom_data); } Color MultiMesh::get_instance_custom_data(int p_instance) const { - return RenderingServer::get_singleton()->multimesh_instance_get_custom_data(multimesh, p_instance); } AABB MultiMesh::get_aabb() const { - return RenderingServer::get_singleton()->multimesh_get_aabb(multimesh); } RID MultiMesh::get_rid() const { - return multimesh; } @@ -307,17 +278,14 @@ bool MultiMesh::is_using_custom_data() const { } void MultiMesh::set_transform_format(TransformFormat p_transform_format) { - ERR_FAIL_COND(instance_count > 0); transform_format = p_transform_format; } MultiMesh::TransformFormat MultiMesh::get_transform_format() const { - return transform_format; } void MultiMesh::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MultiMesh::set_mesh); ClassDB::bind_method(D_METHOD("get_mesh"), &MultiMesh::get_mesh); ClassDB::bind_method(D_METHOD("set_use_colors", "enable"), &MultiMesh::set_use_colors); @@ -374,7 +342,6 @@ void MultiMesh::_bind_methods() { } MultiMesh::MultiMesh() { - multimesh = RenderingServer::get_singleton()->multimesh_create(); use_colors = false; use_custom_data = false; @@ -384,6 +351,5 @@ MultiMesh::MultiMesh() { } MultiMesh::~MultiMesh() { - RenderingServer::get_singleton()->free(multimesh); } diff --git a/scene/resources/multimesh.h b/scene/resources/multimesh.h index c1e52bc981..8478789d41 100644 --- a/scene/resources/multimesh.h +++ b/scene/resources/multimesh.h @@ -35,7 +35,6 @@ #include "servers/rendering_server.h" class MultiMesh : public Resource { - GDCLASS(MultiMesh, Resource); RES_BASE_EXTENSION("multimesh"); diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index e0aff2182e..f5d3c7a3fb 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -31,12 +31,10 @@ #include "navigation_mesh.h" void NavigationMesh::create_from_mesh(const Ref<Mesh> &p_mesh) { - vertices = Vector<Vector3>(); clear_polygons(); for (int i = 0; i < p_mesh->get_surface_count(); i++) { - if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) continue; Array arr = p_mesh->surface_get_arrays(i); @@ -82,17 +80,14 @@ int NavigationMesh::get_parsed_geometry_type() const { } void NavigationMesh::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; } uint32_t NavigationMesh::get_collision_mask() const { - return collision_mask; } void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -102,7 +97,6 @@ void NavigationMesh::set_collision_mask_bit(int p_bit, bool p_value) { } bool NavigationMesh::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } @@ -253,18 +247,15 @@ bool NavigationMesh::get_filter_walkable_low_height_spans() const { } void NavigationMesh::set_vertices(const Vector<Vector3> &p_vertices) { - vertices = p_vertices; _change_notify(); } Vector<Vector3> NavigationMesh::get_vertices() const { - return vertices; } void NavigationMesh::_set_polygons(const Array &p_array) { - polygons.resize(p_array.size()); for (int i = 0; i < p_array.size(); i++) { polygons.write[i].indices = p_array[i]; @@ -273,7 +264,6 @@ void NavigationMesh::_set_polygons(const Array &p_array) { } Array NavigationMesh::_get_polygons() const { - Array ret; ret.resize(polygons.size()); for (int i = 0; i < ret.size(); i++) { @@ -284,28 +274,23 @@ Array NavigationMesh::_get_polygons() const { } void NavigationMesh::add_polygon(const Vector<int> &p_polygon) { - Polygon polygon; polygon.indices = p_polygon; polygons.push_back(polygon); _change_notify(); } int NavigationMesh::get_polygon_count() const { - return polygons.size(); } Vector<int> NavigationMesh::get_polygon(int p_idx) { - ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>()); return polygons[p_idx].indices; } void NavigationMesh::clear_polygons() { - polygons.clear(); } Ref<Mesh> NavigationMesh::get_debug_mesh() { - if (debug_mesh.is_valid()) return debug_mesh; @@ -334,11 +319,9 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { int tidx = 0; for (List<Face3>::Element *E = faces.front(); E; E = E->next()) { - const Face3 &f = E->get(); for (int j = 0; j < 3; j++) { - tw[tidx++] = f.vertex[j]; _EdgeKey ek; ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON)); @@ -349,11 +332,9 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { Map<_EdgeKey, bool>::Element *F = edge_map.find(ek); if (F) { - F->get() = false; } else { - edge_map[ek] = true; } } @@ -362,7 +343,6 @@ Ref<Mesh> NavigationMesh::get_debug_mesh() { List<Vector3> lines; for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) { - if (E->get()) { lines.push_back(E->key().from); lines.push_back(E->key().to); diff --git a/scene/resources/navigation_mesh.h b/scene/resources/navigation_mesh.h index cc3ac6e3fd..6b9d1964f5 100644 --- a/scene/resources/navigation_mesh.h +++ b/scene/resources/navigation_mesh.h @@ -36,7 +36,6 @@ class Mesh; class NavigationMesh : public Resource { - GDCLASS(NavigationMesh, Resource); Vector<Vector3> vertices; @@ -47,7 +46,6 @@ class NavigationMesh : public Resource { Ref<ArrayMesh> debug_mesh; struct _EdgeKey { - Vector3 from; Vector3 to; diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 633771506e..199f0e3989 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -42,12 +42,10 @@ #define PACKED_SCENE_VERSION 2 bool SceneState::can_instance() const { - return nodes.size() > 0; } Node *SceneState::instance(GenEditState p_edit_state) const { - // nodes where instancing failed (because something is missing) List<Node *> stray_instances; @@ -85,18 +83,15 @@ Node *SceneState::instance(GenEditState p_edit_state) const { Map<Ref<Resource>, Ref<Resource>> resources_local_to_scene; for (int i = 0; i < nc; i++) { - const NodeData &n = nd[i]; Node *parent = nullptr; if (i > 0) { - ERR_FAIL_COND_V_MSG(n.parent == -1, nullptr, vformat("Invalid scene: node %s does not specify its parent node.", snames[n.name])); NODE_FROM_ID(nparent, n.parent); #ifdef DEBUG_ENABLED if (!nparent && (n.parent & FLAG_ID_IS_PATH)) { - WARN_PRINT(String("Parent path '" + String(node_paths[n.parent & FLAG_MASK]) + "' for node '" + String(snames[n.name]) + "' has vanished when instancing: '" + get_path() + "'.").ascii().get_data()); } #endif @@ -118,10 +113,8 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } else if (n.instance >= 0) { //instance a scene into this node if (n.instance & FLAG_INSTANCE_IS_PLACEHOLDER) { - String path = props[n.instance & FLAG_MASK]; if (disable_placeholders) { - Ref<PackedScene> sdata = ResourceLoader::load(path, "PackedScene"); ERR_FAIL_COND_V(!sdata.is_valid(), nullptr); node = sdata->instance(p_edit_state == GEN_EDIT_STATE_DISABLED ? PackedScene::GEN_EDIT_STATE_DISABLED : PackedScene::GEN_EDIT_STATE_INSTANCE); @@ -187,11 +180,9 @@ Node *SceneState::instance(GenEditState p_edit_state) const { //properties int nprop_count = n.properties.size(); if (nprop_count) { - const NodeData::Property *nprops = &n.properties[0]; for (int j = 0; j < nprop_count; j++) { - bool valid; ERR_FAIL_INDEX_V(nprops[j].name, sname_count, nullptr); ERR_FAIL_INDEX_V(nprops[j].value, prop_count, nullptr); @@ -213,7 +204,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const { node->set(E->get().first, E->get().second); } } else { - Variant value = props[nprops[j].value]; if (value.get_type() == Variant::OBJECT) { @@ -221,13 +211,11 @@ Node *SceneState::instance(GenEditState p_edit_state) const { Ref<Resource> res = value; if (res.is_valid()) { if (res->is_local_to_scene()) { - Map<Ref<Resource>, Ref<Resource>>::Element *E = resources_local_to_scene.find(res); if (E) { value = E->get(); } else { - Node *base = i == 0 ? node : ret_nodes[0]; if (p_edit_state == GEN_EDIT_STATE_MAIN) { @@ -259,7 +247,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const { //groups for (int j = 0; j < n.groups.size(); j++) { - ERR_FAIL_INDEX_V(n.groups[j], sname_count, nullptr); node->add_to_group(snames[n.groups[j]], true); } @@ -287,7 +274,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } if (n.owner >= 0) { - NODE_FROM_ID(owner, n.owner); if (owner) node->_set_owner_nocheck(owner); @@ -303,7 +289,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } for (Map<Ref<Resource>, Ref<Resource>>::Element *E = resources_local_to_scene.front(); E; E = E->next()) { - E->get()->setup_local_to_scene(); } @@ -313,7 +298,6 @@ Node *SceneState::instance(GenEditState p_edit_state) const { const ConnectionData *cdata = connections.ptr(); for (int i = 0; i < cc; i++) { - const ConnectionData &c = cdata[i]; //ERR_FAIL_INDEX_V( c.from, nc, nullptr ); //ERR_FAIL_INDEX_V( c.to, nc, nullptr ); @@ -353,7 +337,6 @@ 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)) return name_map[p_string]; @@ -363,7 +346,6 @@ 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)) return variant_map[p_variant]; @@ -373,7 +355,6 @@ static int _vm_get_variant(const Variant &p_variant, HashMap<Variant, int, Varia } Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map<StringName, int> &name_map, HashMap<Variant, int, VariantHasher, VariantComparator> &variant_map, Map<Node *, int> &node_map, Map<Node *, int> &nodepath_map) { - // this function handles all the work related to properly packing scenes, be it // instanced or inherited. // given the complexity of this process, an attempt will be made to properly @@ -418,9 +399,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map Node *n = p_node; while (n) { - if (n == p_owner) { - Ref<SceneState> state = n->get_scene_inherited_state(); if (state.is_valid()) { int node = state->find_node_by_path(n->get_path_to(p_node)); @@ -435,7 +414,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map } if (p_node->get_filename() != String() && p_node->get_owner() == p_owner && instanced_by_owner) { - if (p_node->get_scene_instance_load_placeholder()) { //it's a placeholder, use the placeholder path nd.instance = _vm_get_variant(p_node->get_filename(), variant_map); @@ -479,7 +457,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map StringName type = p_node->get_class(); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) { continue; } @@ -530,7 +507,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map } if (exists) { - //check if already exists and did not change if (value.get_type() == Variant::FLOAT && original.get_type() == Variant::FLOAT) { //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error @@ -540,7 +516,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map if (Math::is_equal_approx(a, b)) continue; } else if (bool(Variant::evaluate(Variant::OP_EQUAL, value, original))) { - continue; } } @@ -552,7 +527,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map } } else { - if (isdefault) { //it's the default value, no point in saving it continue; @@ -608,7 +582,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map //part of saved scene nd.owner = 0; } else { - nd.owner = -1; } @@ -637,14 +610,12 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map int parent_node = NO_PARENT_SAVED; if (save_node) { - //don't save the node if nothing and subscene node_map[p_node] = idx; //ok validate parent node if (p_parent_idx == NO_PARENT_SAVED) { - int sidx; if (nodepath_map.has(p_node->get_parent())) { sidx = nodepath_map[p_node->get_parent()]; @@ -663,7 +634,6 @@ 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) @@ -674,7 +644,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map } 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())) return OK; @@ -686,14 +655,12 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName //NodeData &nd = nodes[node_map[p_node]]; for (List<MethodInfo>::Element *E = _signals.front(); E; E = E->next()) { - List<Node::Connection> conns; p_node->get_signal_connection_list(E->get().name, &conns); conns.sort(); 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 @@ -721,7 +688,6 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName //go through ownership chain to see if this exists while (common_parent) { - Ref<SceneState> ps; if (common_parent == p_owner) @@ -730,7 +696,6 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName ps = common_parent->get_scene_instance_state(); if (ps.is_valid()) { - NodePath signal_from = common_parent->get_path_to(p_node); NodePath signal_to = common_parent->get_path_to(target); @@ -756,9 +721,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName bool exists2 = false; while (nl) { - if (nl == p_owner) { - Ref<SceneState> state = nl->get_scene_inherited_state(); if (state.is_valid()) { int from_node = state->find_node_by_path(nl->get_path_to(p_node)); @@ -835,7 +798,6 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName cd.signal = _nm_get_string(c.signal.get_name(), name_map); cd.flags = c.flags; for (int i = 0; i < c.binds.size(); i++) { - cd.binds.push_back(_vm_get_variant(c.binds[i], variant_map)); } connections.push_back(cd); @@ -843,7 +805,6 @@ 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) @@ -870,7 +831,6 @@ Error SceneState::pack(Node *p_scene) { String path = scene->get_scene_inherited_state()->get_path(); Ref<PackedScene> instance = ResourceLoader::load(path); if (instance.is_valid()) { - base_scene_idx = _vm_get_variant(instance, variant_map); } } @@ -891,21 +851,18 @@ Error SceneState::pack(Node *p_scene) { names.resize(name_map.size()); for (Map<StringName, int>::Element *E = name_map.front(); E; E = E->next()) { - names.write[E->get()] = E->key(); } variants.resize(variant_map.size()); const Variant *K = nullptr; while ((K = variant_map.next(K))) { - int idx = variant_map[*K]; variants.write[idx] = *K; } node_paths.resize(nodepath_map.size()); for (Map<Node *, int>::Element *E = nodepath_map.front(); E; E = E->next()) { - node_paths.write[E->get()] = scene->get_path_to(E->key()); } @@ -913,17 +870,14 @@ Error SceneState::pack(Node *p_scene) { } void SceneState::set_path(const String &p_path) { - path = p_path; } String SceneState::get_path() const { - return path; } void SceneState::clear() { - names.clear(); variants.clear(); nodes.clear(); @@ -935,9 +889,7 @@ void SceneState::clear() { } Ref<SceneState> SceneState::_get_base_scene_state() const { - if (base_scene_idx >= 0) { - Ref<PackedScene> ps = variants[base_scene_idx]; if (ps.is_valid()) { return ps->get_state(); @@ -948,7 +900,6 @@ Ref<SceneState> SceneState::_get_base_scene_state() const { } int SceneState::find_node_by_path(const NodePath &p_node) const { - if (!node_path_cache.has(p_node)) { if (_get_base_scene_state().is_valid()) { int idx = _get_base_scene_state()->find_node_by_path(p_node); @@ -980,7 +931,6 @@ int SceneState::find_node_by_path(const NodePath &p_node) const { } int SceneState::_find_base_scene_node_remap_key(int p_idx) const { - for (Map<int, int>::Element *E = base_scene_node_remap.front(); E; E = E->next()) { if (E->value() == p_idx) { return E->key(); @@ -990,7 +940,6 @@ int SceneState::_find_base_scene_node_remap_key(int p_idx) const { } Variant SceneState::get_property_value(int p_node, const StringName &p_property, bool &found) const { - found = false; ERR_FAIL_COND_V(p_node < 0, Variant()); @@ -1019,7 +968,6 @@ Variant SceneState::get_property_value(int p_node, const StringName &p_property, } bool SceneState::is_node_in_group(int p_node, const StringName &p_group) const { - ERR_FAIL_COND_V(p_node < 0, false); if (p_node < nodes.size()) { @@ -1040,17 +988,14 @@ bool SceneState::is_node_in_group(int p_node, const StringName &p_group) const { bool SceneState::disable_placeholders = false; void SceneState::set_disable_placeholders(bool p_disable) { - disable_placeholders = p_disable; } bool SceneState::is_connection(int p_node, const StringName &p_signal, int p_to_node, const StringName &p_to_method) const { - ERR_FAIL_COND_V(p_node < 0, false); ERR_FAIL_COND_V(p_to_node < 0, false); if (p_node < nodes.size() && p_to_node < nodes.size()) { - int signal_idx = -1; int method_idx = -1; for (int i = 0; i < names.size(); i++) { @@ -1065,9 +1010,7 @@ bool SceneState::is_connection(int p_node, const StringName &p_signal, int p_to_ //signal and method strings are stored.. for (int i = 0; i < connections.size(); i++) { - if (connections[i].from == p_node && connections[i].to == p_to_node && connections[i].signal == signal_idx && connections[i].method == method_idx) { - return true; } } @@ -1082,7 +1025,6 @@ bool SceneState::is_connection(int p_node, const StringName &p_signal, int p_to_ } void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { - ERR_FAIL_COND(!p_dictionary.has("names")); ERR_FAIL_COND(!p_dictionary.has("variants")); ERR_FAIL_COND(!p_dictionary.has("node_count")); @@ -1107,7 +1049,6 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { Vector<String> snames = p_dictionary["names"]; if (snames.size()) { - int namecount = snames.size(); names.resize(namecount); const String *r = snames.ptr(); @@ -1121,7 +1062,6 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { int varcount = svariants.size(); variants.resize(varcount); for (int i = 0; i < varcount; i++) { - variants.write[i] = svariants[i]; } @@ -1145,13 +1085,11 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { nd.instance = r[idx++]; nd.properties.resize(r[idx++]); for (int j = 0; j < nd.properties.size(); j++) { - nd.properties.write[j].name = r[idx++]; nd.properties.write[j].value = r[idx++]; } nd.groups.resize(r[idx++]); for (int j = 0; j < nd.groups.size(); j++) { - nd.groups.write[j] = r[idx++]; } } @@ -1171,7 +1109,6 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { cd.binds.resize(r[idx++]); for (int j = 0; j < cd.binds.size(); j++) { - cd.binds.write[j] = r[idx++]; } } @@ -1204,12 +1141,10 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { } Dictionary SceneState::get_bundled_scene() const { - Vector<String> rnames; rnames.resize(names.size()); if (names.size()) { - String *r = rnames.ptrw(); for (int i = 0; i < names.size(); i++) @@ -1224,7 +1159,6 @@ Dictionary SceneState::get_bundled_scene() const { d["node_count"] = nodes.size(); for (int i = 0; i < nodes.size(); i++) { - const NodeData &nd = nodes[i]; rnodes.push_back(nd.parent); rnodes.push_back(nd.owner); @@ -1237,13 +1171,11 @@ Dictionary SceneState::get_bundled_scene() const { rnodes.push_back(nd.instance); rnodes.push_back(nd.properties.size()); for (int j = 0; j < nd.properties.size(); j++) { - rnodes.push_back(nd.properties[j].name); rnodes.push_back(nd.properties[j].value); } rnodes.push_back(nd.groups.size()); for (int j = 0; j < nd.groups.size(); j++) { - rnodes.push_back(nd.groups[j]); } } @@ -1254,7 +1186,6 @@ Dictionary SceneState::get_bundled_scene() const { d["conn_count"] = connections.size(); for (int i = 0; i < connections.size(); i++) { - const ConnectionData &cd = connections[i]; rconns.push_back(cd.from); rconns.push_back(cd.to); @@ -1291,12 +1222,10 @@ Dictionary SceneState::get_bundled_scene() const { } int SceneState::get_node_count() const { - return nodes.size(); } 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) return StringName(); @@ -1304,7 +1233,6 @@ StringName SceneState::get_node_type(int p_idx) const { } StringName SceneState::get_node_name(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, nodes.size(), StringName()); return names[nodes[p_idx].name]; } @@ -1315,7 +1243,6 @@ int SceneState::get_node_index(int p_idx) const { } bool SceneState::is_node_instance_placeholder(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, nodes.size(), false); return nodes[p_idx].instance >= 0 && (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER); @@ -1330,7 +1257,6 @@ Ref<PackedScene> SceneState::get_node_instance(int p_idx) const { 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]; } @@ -1340,7 +1266,6 @@ Ref<PackedScene> SceneState::get_node_instance(int p_idx) const { } String SceneState::get_node_instance_placeholder(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, nodes.size(), String()); if (nodes[p_idx].instance >= 0 && (nodes[p_idx].instance & FLAG_INSTANCE_IS_PLACEHOLDER)) { @@ -1360,7 +1285,6 @@ Vector<StringName> SceneState::get_node_groups(int p_idx) const { } NodePath SceneState::get_node_path(int p_idx, bool p_for_parent) const { - ERR_FAIL_INDEX_V(p_idx, nodes.size(), NodePath()); if (nodes[p_idx].parent < 0 || nodes[p_idx].parent == NO_PARENT_SAVED) { @@ -1376,7 +1300,6 @@ NodePath SceneState::get_node_path(int p_idx, bool p_for_parent) const { int nidx = p_idx; while (true) { if (nodes[nidx].parent == NO_PARENT_SAVED || nodes[nidx].parent < 0) { - sub_path.insert(0, "."); break; } @@ -1405,7 +1328,6 @@ NodePath SceneState::get_node_path(int p_idx, bool p_for_parent) const { } int SceneState::get_node_property_count(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, nodes.size(), -1); return nodes[p_idx].properties.size(); } @@ -1422,7 +1344,6 @@ 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) return NodePath(); //root likely @@ -1434,11 +1355,9 @@ NodePath SceneState::get_node_owner_path(int p_idx) const { } int SceneState::get_connection_count() const { - return connections.size(); } NodePath SceneState::get_connection_source(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, connections.size(), NodePath()); if (connections[p_idx].from & FLAG_ID_IS_PATH) { return node_paths[connections[p_idx].from & FLAG_MASK]; @@ -1448,12 +1367,10 @@ NodePath SceneState::get_connection_source(int p_idx) const { } StringName SceneState::get_connection_signal(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, connections.size(), StringName()); return names[connections[p_idx].signal]; } NodePath SceneState::get_connection_target(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, connections.size(), NodePath()); if (connections[p_idx].to & FLAG_ID_IS_PATH) { return node_paths[connections[p_idx].to & FLAG_MASK]; @@ -1462,19 +1379,16 @@ NodePath SceneState::get_connection_target(int p_idx) const { } } StringName SceneState::get_connection_method(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, connections.size(), StringName()); return names[connections[p_idx].method]; } int SceneState::get_connection_flags(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, connections.size(), -1); return connections[p_idx].flags; } Array SceneState::get_connection_binds(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, connections.size(), Array()); Array binds; for (int i = 0; i < connections[p_idx].binds.size(); i++) { @@ -1484,7 +1398,6 @@ Array SceneState::get_connection_binds(int p_idx) const { } bool SceneState::has_connection(const NodePath &p_node_from, const StringName &p_signal, const NodePath &p_node_to, const StringName &p_method) { - // this method cannot be const because of this Ref<SceneState> ss = this; @@ -1528,13 +1441,11 @@ Vector<NodePath> SceneState::get_editable_instances() const { //add int SceneState::add_name(const StringName &p_name) { - names.push_back(p_name); return names.size() - 1; } int SceneState::find_name(const StringName &p_name) const { - for (int i = 0; i < names.size(); i++) { if (names[i] == p_name) return i; @@ -1544,18 +1455,15 @@ int SceneState::find_name(const StringName &p_name) const { } int SceneState::add_value(const Variant &p_value) { - variants.push_back(p_value); return variants.size() - 1; } int SceneState::add_node_path(const NodePath &p_path) { - node_paths.push_back(p_path); return (node_paths.size() - 1) | FLAG_ID_IS_PATH; } int SceneState::add_node(int p_parent, int p_owner, int p_type, int p_name, int p_instance, int p_index) { - NodeData nd; nd.parent = p_parent; nd.owner = p_owner; @@ -1569,7 +1477,6 @@ int SceneState::add_node(int p_parent, int p_owner, int p_type, int p_name, int return nodes.size() - 1; } void SceneState::add_node_property(int p_node, int p_name, int p_value) { - ERR_FAIL_INDEX(p_node, nodes.size()); ERR_FAIL_INDEX(p_name, names.size()); ERR_FAIL_INDEX(p_value, variants.size()); @@ -1580,18 +1487,15 @@ void SceneState::add_node_property(int p_node, int p_name, int p_value) { nodes.write[p_node].properties.push_back(prop); } void SceneState::add_node_group(int p_node, int p_group) { - ERR_FAIL_INDEX(p_node, nodes.size()); ERR_FAIL_INDEX(p_group, names.size()); nodes.write[p_node].groups.push_back(p_group); } void SceneState::set_base_scene(int p_idx) { - ERR_FAIL_INDEX(p_idx, variants.size()); base_scene_idx = p_idx; } void SceneState::add_connection(int p_from, int p_to, int p_signal, int p_method, int p_flags, const Vector<int> &p_binds) { - ERR_FAIL_INDEX(p_signal, names.size()); ERR_FAIL_INDEX(p_method, names.size()); @@ -1608,12 +1512,10 @@ void SceneState::add_connection(int p_from, int p_to, int p_signal, int p_method connections.push_back(c); } void SceneState::add_editable_instance(const NodePath &p_path) { - editable_instances.push_back(p_path); } Vector<String> SceneState::_get_node_groups(int p_idx) const { - Vector<StringName> groups = get_node_groups(p_idx); Vector<String> ret; @@ -1624,7 +1526,6 @@ Vector<String> SceneState::_get_node_groups(int p_idx) const { } void SceneState::_bind_methods() { - //unbuild API ClassDB::bind_method(D_METHOD("get_node_count"), &SceneState::get_node_count); @@ -1654,7 +1555,6 @@ void SceneState::_bind_methods() { } SceneState::SceneState() { - base_scene_idx = -1; last_modified_time = 0; } @@ -1662,32 +1562,26 @@ SceneState::SceneState() { //////////////// void PackedScene::_set_bundled_scene(const Dictionary &p_scene) { - state->set_bundled_scene(p_scene); } Dictionary PackedScene::_get_bundled_scene() const { - return state->get_bundled_scene(); } Error PackedScene::pack(Node *p_scene) { - return state->pack(p_scene); } void PackedScene::clear() { - state->clear(); } bool PackedScene::can_instance() const { - return state->can_instance(); } Node *PackedScene::instance(GenEditState p_edit_state) const { - #ifndef TOOLS_ENABLED ERR_FAIL_COND_V_MSG(p_edit_state != GEN_EDIT_STATE_DISABLED, nullptr, "Edit state is only for editors, does not work without tools compiled."); #endif @@ -1709,7 +1603,6 @@ Node *PackedScene::instance(GenEditState p_edit_state) const { } void PackedScene::replace_state(Ref<SceneState> p_by) { - state = p_by; state->set_path(get_path()); #ifdef TOOLS_ENABLED @@ -1718,7 +1611,6 @@ void PackedScene::replace_state(Ref<SceneState> p_by) { } void PackedScene::recreate_state() { - state = Ref<SceneState>(memnew(SceneState)); state->set_path(get_path()); #ifdef TOOLS_ENABLED @@ -1727,18 +1619,15 @@ void PackedScene::recreate_state() { } Ref<SceneState> PackedScene::get_state() { - return state; } void PackedScene::set_path(const String &p_path, bool p_take_over) { - state->set_path(p_path); Resource::set_path(p_path, p_take_over); } void PackedScene::_bind_methods() { - ClassDB::bind_method(D_METHOD("pack", "path"), &PackedScene::pack); ClassDB::bind_method(D_METHOD("instance", "edit_state"), &PackedScene::instance, DEFVAL(GEN_EDIT_STATE_DISABLED)); ClassDB::bind_method(D_METHOD("can_instance"), &PackedScene::can_instance); @@ -1754,6 +1643,5 @@ void PackedScene::_bind_methods() { } PackedScene::PackedScene() { - state = Ref<SceneState>(memnew(SceneState)); } diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index c5873a0792..898d5ff11f 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -35,7 +35,6 @@ #include "scene/main/node.h" class SceneState : public Reference { - GDCLASS(SceneState, Reference); Vector<StringName> names; @@ -54,7 +53,6 @@ class SceneState : public Reference { }; struct NodeData { - int parent; int owner; int type; @@ -63,7 +61,6 @@ class SceneState : public Reference { int index; struct Property { - int name; int value; }; @@ -81,7 +78,6 @@ class SceneState : public Reference { Vector<NodeData> nodes; struct ConnectionData { - int from; int to; int signal; @@ -195,7 +191,6 @@ public: VARIANT_ENUM_CAST(SceneState::GenEditState) class PackedScene : public Resource { - GDCLASS(PackedScene, Resource); RES_BASE_EXTENSION("scn"); diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index 1a28e2586d..e24cddd013 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -36,7 +36,6 @@ Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMate ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = nullptr; void ParticlesMaterial::init_shaders() { - dirty_materials = memnew(SelfList<ParticlesMaterial>::List); shader_names = memnew(ShaderNames); @@ -102,7 +101,6 @@ void ParticlesMaterial::init_shaders() { } void ParticlesMaterial::finish_shaders() { - memdelete(dirty_materials); dirty_materials = nullptr; @@ -110,7 +108,6 @@ void ParticlesMaterial::finish_shaders() { } void ParticlesMaterial::_update_shader() { - dirty_materials->remove(&element); MaterialKey mk = _compute_key(); @@ -129,7 +126,6 @@ void ParticlesMaterial::_update_shader() { current_key = mk; if (shader_map.has(mk)) { - RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader); shader_map[mk].users++; return; @@ -307,7 +303,6 @@ void ParticlesMaterial::_update_shader() { code += " float spread_rad = spread * degree_to_rad;\n"; if (flags[FLAG_DISABLE_Z]) { - code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n"; code += " angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0);\n"; code += " vec3 rot = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n"; @@ -352,7 +347,6 @@ void ParticlesMaterial::_update_shader() { if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) { if (flags[FLAG_DISABLE_Z]) { - code += " mat2 rotm;"; code += " rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;\n"; code += " rotm[1] = rotm[0].yx * vec2(1.0, -1.0);\n"; @@ -386,7 +380,6 @@ void ParticlesMaterial::_update_shader() { code += " float tex_linear_velocity = 0.0;\n"; if (flags[FLAG_DISABLE_Z]) { - 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 @@ -456,7 +449,6 @@ void ParticlesMaterial::_update_shader() { code += " VELOCITY += force * DELTA;\n"; code += " // orbit velocity\n"; if (flags[FLAG_DISABLE_Z]) { - code += " float orbit_amount = (orbit_velocity + tex_orbit_velocity) * mix(1.0, rand_from_seed(alt_seed), orbit_velocity_random);\n"; code += " if (orbit_amount != 0.0) {\n"; code += " float ang = orbit_amount * DELTA * pi * 2.0;\n"; @@ -527,7 +519,6 @@ void ParticlesMaterial::_update_shader() { code += "\n"; if (flags[FLAG_DISABLE_Z]) { - if (flags[FLAG_ALIGN_Y_TO_VELOCITY]) { code += " if (length(VELOCITY) > 0.0) {\n"; code += " TRANSFORM[1].xyz = normalize(VELOCITY);\n"; @@ -603,17 +594,14 @@ void ParticlesMaterial::_update_shader() { } void ParticlesMaterial::flush_changes() { - MutexLock lock(material_mutex); while (dirty_materials->first()) { - dirty_materials->first()->self()->_update_shader(); } } void ParticlesMaterial::_queue_shader_change() { - MutexLock lock(material_mutex); if (!element.in_list()) { @@ -622,46 +610,38 @@ void ParticlesMaterial::_queue_shader_change() { } bool ParticlesMaterial::_is_shader_dirty() const { - MutexLock lock(material_mutex); return element.in_list(); } void ParticlesMaterial::set_direction(Vector3 p_direction) { - direction = p_direction; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->direction, direction); } Vector3 ParticlesMaterial::get_direction() const { - return direction; } void ParticlesMaterial::set_spread(float p_spread) { - spread = p_spread; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->spread, p_spread); } float ParticlesMaterial::get_spread() const { - return spread; } void ParticlesMaterial::set_flatness(float p_flatness) { - flatness = p_flatness; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->flatness, p_flatness); } float ParticlesMaterial::get_flatness() const { - return flatness; } void ParticlesMaterial::set_param(Parameter p_param, float p_value) { - ERR_FAIL_INDEX(p_param, PARAM_MAX); parameters[p_param] = p_value; @@ -708,14 +688,12 @@ void ParticlesMaterial::set_param(Parameter p_param, float p_value) { } } float ParticlesMaterial::get_param(Parameter p_param) const { - ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return parameters[p_param]; } void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) { - ERR_FAIL_INDEX(p_param, PARAM_MAX); randomness[p_param] = p_value; @@ -762,14 +740,12 @@ void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) { } } float ParticlesMaterial::get_param_randomness(Parameter p_param) const { - ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return randomness[p_param]; } 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()) return; @@ -778,7 +754,6 @@ static void _adjust_curve_range(const Ref<Texture2D> &p_texture, float p_min, fl } void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D> &p_texture) { - ERR_FAIL_INDEX(p_param, PARAM_MAX); tex_parameters[p_param] = p_texture; @@ -837,25 +812,21 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D _queue_shader_change(); } Ref<Texture2D> ParticlesMaterial::get_param_texture(Parameter p_param) const { - ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Texture2D>()); return tex_parameters[p_param]; } void ParticlesMaterial::set_color(const Color &p_color) { - RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color, p_color); color = p_color; } Color ParticlesMaterial::get_color() const { - return color; } void ParticlesMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) { - color_ramp = p_texture; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, p_texture); _queue_shader_change(); @@ -863,7 +834,6 @@ void ParticlesMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) { } Ref<Texture2D> ParticlesMaterial::get_color_ramp() const { - return color_ramp; } @@ -889,87 +859,71 @@ void ParticlesMaterial::set_emission_shape(EmissionShape p_shape) { } void ParticlesMaterial::set_emission_sphere_radius(float p_radius) { - emission_sphere_radius = p_radius; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_sphere_radius, p_radius); } void ParticlesMaterial::set_emission_box_extents(Vector3 p_extents) { - emission_box_extents = p_extents; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_box_extents, p_extents); } void ParticlesMaterial::set_emission_point_texture(const Ref<Texture2D> &p_points) { - emission_point_texture = p_points; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, p_points); } void ParticlesMaterial::set_emission_normal_texture(const Ref<Texture2D> &p_normals) { - emission_normal_texture = p_normals; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, p_normals); } void ParticlesMaterial::set_emission_color_texture(const Ref<Texture2D> &p_colors) { - emission_color_texture = p_colors; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, p_colors); _queue_shader_change(); } void ParticlesMaterial::set_emission_point_count(int p_count) { - emission_point_count = p_count; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_point_count, p_count); } ParticlesMaterial::EmissionShape ParticlesMaterial::get_emission_shape() const { - return emission_shape; } float ParticlesMaterial::get_emission_sphere_radius() const { - return emission_sphere_radius; } Vector3 ParticlesMaterial::get_emission_box_extents() const { - return emission_box_extents; } Ref<Texture2D> ParticlesMaterial::get_emission_point_texture() const { - return emission_point_texture; } Ref<Texture2D> ParticlesMaterial::get_emission_normal_texture() const { - return emission_normal_texture; } Ref<Texture2D> ParticlesMaterial::get_emission_color_texture() const { - return emission_color_texture; } int ParticlesMaterial::get_emission_point_count() const { - return emission_point_count; } void ParticlesMaterial::set_trail_divisor(int p_divisor) { - trail_divisor = p_divisor; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_divisor, p_divisor); } int ParticlesMaterial::get_trail_divisor() const { - return trail_divisor; } void ParticlesMaterial::set_trail_size_modifier(const Ref<CurveTexture> &p_trail_size_modifier) { - trail_size_modifier = p_trail_size_modifier; Ref<CurveTexture> curve = trail_size_modifier; @@ -982,24 +936,20 @@ void ParticlesMaterial::set_trail_size_modifier(const Ref<CurveTexture> &p_trail } Ref<CurveTexture> ParticlesMaterial::get_trail_size_modifier() const { - return trail_size_modifier; } void ParticlesMaterial::set_trail_color_modifier(const Ref<GradientTexture> &p_trail_color_modifier) { - trail_color_modifier = p_trail_color_modifier; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_color_modifier, p_trail_color_modifier); _queue_shader_change(); } Ref<GradientTexture> ParticlesMaterial::get_trail_color_modifier() const { - return trail_color_modifier; } void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) { - gravity = p_gravity; Vector3 gset = gravity; if (gset == Vector3()) { @@ -1009,29 +959,24 @@ void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) { } Vector3 ParticlesMaterial::get_gravity() const { - return gravity; } void ParticlesMaterial::set_lifetime_randomness(float p_lifetime) { - lifetime_randomness = p_lifetime; RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->lifetime_randomness, lifetime_randomness); } float ParticlesMaterial::get_lifetime_randomness() const { - return lifetime_randomness; } RID ParticlesMaterial::get_shader_rid() const { - ERR_FAIL_COND_V(!shader_map.has(current_key), RID()); return shader_map[current_key].shader; } void ParticlesMaterial::_validate_property(PropertyInfo &property) const { - if (property.name == "color" && color_ramp.is_valid()) { property.usage = 0; } @@ -1062,12 +1007,10 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const { } Shader::Mode ParticlesMaterial::get_shader_mode() const { - return Shader::MODE_PARTICLES; } void ParticlesMaterial::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_direction", "degrees"), &ParticlesMaterial::set_direction); ClassDB::bind_method(D_METHOD("get_direction"), &ParticlesMaterial::get_direction); @@ -1235,7 +1178,6 @@ void ParticlesMaterial::_bind_methods() { ParticlesMaterial::ParticlesMaterial() : element(this) { - set_direction(Vector3(1, 0, 0)); set_spread(45); set_flatness(0); @@ -1276,7 +1218,6 @@ ParticlesMaterial::ParticlesMaterial() : } ParticlesMaterial::~ParticlesMaterial() { - MutexLock lock(material_mutex); if (shader_map.has(current_key)) { diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h index c6c8316995..a1a4c38842 100644 --- a/scene/resources/particles_material.h +++ b/scene/resources/particles_material.h @@ -35,7 +35,6 @@ #define PARTICLES_MATERIAL_H class ParticlesMaterial : public Material { - GDCLASS(ParticlesMaterial, Material); public: @@ -74,7 +73,6 @@ public: private: union MaterialKey { - struct { uint32_t texture_mask : 16; uint32_t texture_color : 1; @@ -103,7 +101,6 @@ private: MaterialKey current_key; _FORCE_INLINE_ MaterialKey _compute_key() const { - MaterialKey mk; mk.key = 0; for (int i = 0; i < PARAM_MAX; i++) { diff --git a/scene/resources/physics_material.cpp b/scene/resources/physics_material.cpp index 89fbf7a248..2a5cd1101a 100644 --- a/scene/resources/physics_material.cpp +++ b/scene/resources/physics_material.cpp @@ -31,7 +31,6 @@ #include "physics_material.h" void PhysicsMaterial::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicsMaterial::set_friction); ClassDB::bind_method(D_METHOD("get_friction"), &PhysicsMaterial::get_friction); diff --git a/scene/resources/physics_material.h b/scene/resources/physics_material.h index 1fac3fa6ef..34aa7066df 100644 --- a/scene/resources/physics_material.h +++ b/scene/resources/physics_material.h @@ -35,7 +35,6 @@ #include "servers/physics_server_3d.h" class PhysicsMaterial : public Resource { - GDCLASS(PhysicsMaterial, Resource); OBJ_SAVE_TYPE(PhysicsMaterial); RES_BASE_EXTENSION("phymat"); diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index c3daedf918..8e65ae8bed 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -32,11 +32,9 @@ #include "core/math/geometry.h" bool PolygonPathFinder::_is_point_inside(const Vector2 &p_point) const { - int crosses = 0; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { - const Edge &e = E->get(); Vector2 a = points[e.points[0]].pos; @@ -51,7 +49,6 @@ bool PolygonPathFinder::_is_point_inside(const Vector2 &p_point) const { } void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> &p_connections) { - ERR_FAIL_COND(p_connections.size() & 1); points.clear(); @@ -64,7 +61,6 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> bounds = Rect2(); for (int i = 0; i < p_points.size(); i++) { - points.write[i].pos = p_points[i]; points.write[i].penalty = 0; @@ -84,7 +80,6 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> //insert edges (which are also connetions) for (int i = 0; i < p_connections.size(); i += 2) { - Edge e(p_connections[i], p_connections[i + 1]); ERR_FAIL_INDEX(e.points[0], point_count); ERR_FAIL_INDEX(e.points[1], point_count); @@ -96,9 +91,7 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> //fill the remaining connections based on visibility for (int i = 0; i < point_count; i++) { - for (int j = i + 1; j < point_count; j++) { - if (edges.has(Edge(i, j))) continue; //if in edge ignore @@ -111,7 +104,6 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> 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) continue; @@ -134,7 +126,6 @@ void PolygonPathFinder::setup(const Vector<Vector2> &p_points, const Vector<int> } Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector2 &p_to) { - Vector<Vector2> path; Vector2 from = p_from; @@ -143,12 +134,10 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector Edge ignore_to_edge(-1, -1); if (!_is_point_inside(from)) { - float closest_dist = 1e20; Vector2 closest_point; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { - const Edge &e = E->get(); Vector2 seg[2] = { points[e.points[0]].pos, @@ -173,7 +162,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector Vector2 closest_point; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { - const Edge &e = E->get(); Vector2 seg[2] = { points[e.points[0]].pos, @@ -195,11 +183,9 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector //test direct connection { - bool can_see_eachother = true; 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]) continue; @@ -216,7 +202,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } if (can_see_eachother) { - path.push_back(from); path.push_back(to); return path; @@ -237,7 +222,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector points.write[bidx].penalty = 0; for (int i = 0; i < points.size() - 2; i++) { - bool valid_a = true; bool valid_b = true; points.write[i].prev = -1; @@ -252,7 +236,6 @@ 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) @@ -262,12 +245,10 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector Vector2 b = points[e.points[1]].pos; if (valid_a) { - if (e.points[0] != ignore_from_edge.points[1] && e.points[1] != ignore_from_edge.points[1] && e.points[0] != ignore_from_edge.points[0] && e.points[1] != ignore_from_edge.points[0]) { - if (Geometry::segment_intersects_segment_2d(a, b, from, points[i].pos, nullptr)) { valid_a = false; } @@ -275,12 +256,10 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } if (valid_b) { - if (e.points[0] != ignore_to_edge.points[1] && e.points[1] != ignore_to_edge.points[1] && e.points[0] != ignore_to_edge.points[0] && e.points[1] != ignore_to_edge.points[0]) { - if (Geometry::segment_intersects_segment_2d(a, b, to, points[i].pos, nullptr)) { valid_b = false; } @@ -308,7 +287,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector points.write[aidx].distance = 0; points.write[aidx].prev = aidx; for (Set<int>::Element *E = points[aidx].connections.front(); E; E = E->next()) { - open_list.insert(E->get()); points.write[E->get()].distance = from.distance_to(points[E->get()].pos); points.write[E->get()].prev = aidx; @@ -317,7 +295,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector bool found_route = false; while (true) { - if (open_list.size() == 0) { printf("open list empty\n"); break; @@ -329,14 +306,12 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector //this could be faster (cache previous results) for (Set<int>::Element *E = open_list.front(); E; E = E->next()) { - const Point &p = points[E->get()]; float cost = p.distance; cost += p.pos.distance_to(to); cost += p.penalty; if (cost < least_cost) { - least_cost_point = E->get(); least_cost = cost; } @@ -346,7 +321,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector //open the neighbours for search for (Set<int>::Element *E = np.connections.front(); E; E = E->next()) { - Point &p = points.write[E->get()]; float distance = np.pos.distance_to(p.pos) + np.distance; @@ -354,7 +328,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector //oh this was visited already, can we win the cost? if (p.distance > distance) { - p.prev = least_cost_point; //reasign previous p.distance = distance; } @@ -391,7 +364,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } for (int i = 0; i < points.size() - 2; i++) { - points.write[i].connections.erase(aidx); points.write[i].connections.erase(bidx); points.write[i].prev = -1; @@ -409,7 +381,6 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2 &p_from, const Vector } void PolygonPathFinder::_set_data(const Dictionary &p_data) { - ERR_FAIL_COND(!p_data.has("points")); ERR_FAIL_COND(!p_data.has("connections")); ERR_FAIL_COND(!p_data.has("segments")); @@ -432,13 +403,11 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) { const int *cr = con.ptr(); int cc = con.size(); for (int j = 0; j < cc; j++) { - points.write[i].connections.insert(cr[j]); } } if (p_data.has("penalties")) { - Vector<float> penalties = p_data["penalties"]; if (penalties.size() == pc) { const float *pr2 = penalties.ptr(); @@ -453,7 +422,6 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) { ERR_FAIL_COND(sc & 1); const int *sr = segs.ptr(); for (int i = 0; i < sc; i += 2) { - Edge e(sr[i], sr[i + 1]); edges.insert(e); } @@ -461,7 +429,6 @@ void PolygonPathFinder::_set_data(const Dictionary &p_data) { } Dictionary PolygonPathFinder::_get_data() const { - Dictionary d; Vector<Vector2> p; Vector<int> ind; @@ -491,7 +458,6 @@ Dictionary PolygonPathFinder::_get_data() const { } } { - int *iw = ind.ptrw(); int idx = 0; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { @@ -510,17 +476,14 @@ Dictionary PolygonPathFinder::_get_data() const { } bool PolygonPathFinder::is_point_inside(const Vector2 &p_point) const { - return _is_point_inside(p_point); } Vector2 PolygonPathFinder::get_closest_point(const Vector2 &p_point) const { - float closest_dist = 1e20; Vector2 closest_point; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { - const Edge &e = E->get(); Vector2 seg[2] = { points[e.points[0]].pos, @@ -542,7 +505,6 @@ Vector2 PolygonPathFinder::get_closest_point(const Vector2 &p_point) const { } Vector<Vector2> PolygonPathFinder::get_intersections(const Vector2 &p_from, const Vector2 &p_to) const { - Vector<Vector2> inters; for (Set<Edge>::Element *E = edges.front(); E; E = E->next()) { @@ -559,24 +521,20 @@ Vector<Vector2> PolygonPathFinder::get_intersections(const Vector2 &p_from, cons } Rect2 PolygonPathFinder::get_bounds() const { - return bounds; } void PolygonPathFinder::set_point_penalty(int p_point, float p_penalty) { - ERR_FAIL_INDEX(p_point, points.size() - 2); points.write[p_point].penalty = p_penalty; } float PolygonPathFinder::get_point_penalty(int p_point) const { - ERR_FAIL_INDEX_V(p_point, points.size() - 2, 0); return points[p_point].penalty; } void PolygonPathFinder::_bind_methods() { - ClassDB::bind_method(D_METHOD("setup", "points", "connections"), &PolygonPathFinder::setup); ClassDB::bind_method(D_METHOD("find_path", "from", "to"), &PolygonPathFinder::find_path); ClassDB::bind_method(D_METHOD("get_intersections", "from", "to"), &PolygonPathFinder::get_intersections); diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h index 2ef5c89e2a..f29299055e 100644 --- a/scene/resources/polygon_path_finder.h +++ b/scene/resources/polygon_path_finder.h @@ -34,7 +34,6 @@ #include "core/resource.h" class PolygonPathFinder : public Resource { - GDCLASS(PolygonPathFinder, Resource); struct Point { @@ -46,11 +45,9 @@ class PolygonPathFinder : public Resource { }; struct Edge { - int points[2]; _FORCE_INLINE_ bool operator<(const Edge &p_edge) const { - if (points[0] == p_edge.points[0]) return points[1] < p_edge.points[1]; else @@ -58,7 +55,6 @@ class PolygonPathFinder : public Resource { } Edge(int a = 0, int b = 0) { - if (a > b) { SWAP(a, b); } diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 46e8575018..30d884a5ac 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -35,7 +35,6 @@ PrimitiveMesh */ void PrimitiveMesh::_update() const { - Array arr; arr.resize(RS::ARRAY_MAX); _create_mesh_array(arr); @@ -47,7 +46,6 @@ void PrimitiveMesh::_update() const { int pc = points.size(); ERR_FAIL_COND(pc == 0); { - const Vector3 *r = points.ptr(); for (int i = 0; i < pc; i++) { if (i == 0) @@ -63,7 +61,6 @@ void PrimitiveMesh::_update() const { Vector<Vector3> normals = arr[RS::ARRAY_NORMAL]; if (normals.size() && indices.size()) { - { int nc = normals.size(); Vector3 *w = normals.ptrw(); @@ -99,7 +96,6 @@ void PrimitiveMesh::_update() const { } void PrimitiveMesh::_request_update() { - if (pending_request) return; _update(); @@ -143,7 +139,6 @@ Dictionary PrimitiveMesh::surface_get_lods(int p_surface) const { return Dictionary(); //not really supported } Array PrimitiveMesh::surface_get_blend_shape_arrays(int p_surface) const { - return Array(); //not really supported } @@ -230,14 +225,12 @@ Array PrimitiveMesh::get_mesh_arrays() const { } void PrimitiveMesh::set_custom_aabb(const AABB &p_custom) { - custom_aabb = p_custom; RS::get_singleton()->mesh_set_custom_aabb(mesh, custom_aabb); emit_changed(); } AABB PrimitiveMesh::get_custom_aabb() const { - return custom_aabb; } @@ -251,7 +244,6 @@ bool PrimitiveMesh::get_flip_faces() const { } PrimitiveMesh::PrimitiveMesh() { - flip_faces = false; // defaults mesh = RenderingServer::get_singleton()->mesh_create(); @@ -1382,7 +1374,6 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { }; for (int i = 0; i < 6; i++) { - int j = indices[i]; faces.set(i, quad_faces[j]); normals.set(i, Vector3(0, 0, 1)); diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index 5f17680c9e..3cffa44e3a 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -42,7 +42,6 @@ This class is set apart that it assumes a single surface is always generated for our mesh. */ class PrimitiveMesh : public Mesh { - GDCLASS(PrimitiveMesh, Mesh); private: @@ -134,7 +133,6 @@ public: Similar to test cube but with subdivision support and different texture coordinates */ class CubeMesh : public PrimitiveMesh { - GDCLASS(CubeMesh, PrimitiveMesh); private: @@ -168,7 +166,6 @@ public: */ class CylinderMesh : public PrimitiveMesh { - GDCLASS(CylinderMesh, PrimitiveMesh); private: @@ -205,7 +202,6 @@ public: Similar to quadmesh but with tessellation support */ class PlaneMesh : public PrimitiveMesh { - GDCLASS(PlaneMesh, PrimitiveMesh); private: @@ -234,7 +230,6 @@ public: A prism shapen, handy for ramps, triangles, etc. */ class PrismMesh : public PrimitiveMesh { - GDCLASS(PrismMesh, PrimitiveMesh); private: @@ -272,7 +267,6 @@ public: */ class QuadMesh : public PrimitiveMesh { - GDCLASS(QuadMesh, PrimitiveMesh); private: @@ -293,7 +287,6 @@ public: A sphere.. */ class SphereMesh : public PrimitiveMesh { - GDCLASS(SphereMesh, PrimitiveMesh); private: @@ -331,7 +324,6 @@ public: */ class PointMesh : public PrimitiveMesh { - GDCLASS(PointMesh, PrimitiveMesh) protected: diff --git a/scene/resources/ray_shape_3d.cpp b/scene/resources/ray_shape_3d.cpp index 0211c55f46..17205a500a 100644 --- a/scene/resources/ray_shape_3d.cpp +++ b/scene/resources/ray_shape_3d.cpp @@ -33,7 +33,6 @@ #include "servers/physics_server_3d.h" Vector<Vector3> RayShape3D::get_debug_mesh_lines() { - Vector<Vector3> points; points.push_back(Vector3()); points.push_back(Vector3(0, 0, get_length())); @@ -46,7 +45,6 @@ real_t RayShape3D::get_enclosing_radius() const { } void RayShape3D::_update_shape() { - Dictionary d; d["length"] = length; d["slips_on_slope"] = slips_on_slope; @@ -55,7 +53,6 @@ void RayShape3D::_update_shape() { } void RayShape3D::set_length(float p_length) { - length = p_length; _update_shape(); notify_change_to_owners(); @@ -63,12 +60,10 @@ void RayShape3D::set_length(float p_length) { } float RayShape3D::get_length() const { - return length; } void RayShape3D::set_slips_on_slope(bool p_active) { - slips_on_slope = p_active; _update_shape(); notify_change_to_owners(); @@ -80,7 +75,6 @@ bool RayShape3D::get_slips_on_slope() const { } void RayShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_length", "length"), &RayShape3D::set_length); ClassDB::bind_method(D_METHOD("get_length"), &RayShape3D::get_length); @@ -93,7 +87,6 @@ void RayShape3D::_bind_methods() { RayShape3D::RayShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_RAY)) { - length = 1.0; slips_on_slope = false; diff --git a/scene/resources/ray_shape_3d.h b/scene/resources/ray_shape_3d.h index 83bb71cca3..ef849d2dee 100644 --- a/scene/resources/ray_shape_3d.h +++ b/scene/resources/ray_shape_3d.h @@ -33,7 +33,6 @@ #include "scene/resources/shape_3d.h" class RayShape3D : public Shape3D { - GDCLASS(RayShape3D, Shape3D); float length; bool slips_on_slope; diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp index 19e72a65b0..949fddf2e7 100644 --- a/scene/resources/rectangle_shape_2d.cpp +++ b/scene/resources/rectangle_shape_2d.cpp @@ -33,29 +33,24 @@ #include "servers/physics_server_2d.h" #include "servers/rendering_server.h" void RectangleShape2D::_update_shape() { - PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), extents); emit_changed(); } void RectangleShape2D::set_extents(const Vector2 &p_extents) { - extents = p_extents; _update_shape(); } Vector2 RectangleShape2D::get_extents() const { - return extents; } void RectangleShape2D::draw(const RID &p_to_rid, const Color &p_color) { - RenderingServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-extents, extents * 2.0), p_color); } Rect2 RectangleShape2D::get_rect() const { - return Rect2(-extents, extents * 2.0); } @@ -64,7 +59,6 @@ real_t RectangleShape2D::get_enclosing_radius() const { } void RectangleShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_extents", "extents"), &RectangleShape2D::set_extents); ClassDB::bind_method(D_METHOD("get_extents"), &RectangleShape2D::get_extents); @@ -73,7 +67,6 @@ void RectangleShape2D::_bind_methods() { RectangleShape2D::RectangleShape2D() : Shape2D(PhysicsServer2D::get_singleton()->rectangle_shape_create()) { - extents = Vector2(10, 10); _update_shape(); } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 41146036f6..01af96b1e0 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -46,17 +46,14 @@ /// void ResourceLoaderText::set_local_path(const String &p_local_path) { - res_path = p_local_path; } Ref<Resource> ResourceLoaderText::get_resource() { - return resource; } Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { - VariantParser::Token token; VariantParser::get_token(p_stream, token, line, r_err_str); if (token.type != VariantParser::TK_NUMBER) { @@ -86,7 +83,6 @@ Error ResourceLoaderText::_parse_sub_resource_dummy(DummyReadData *p_data, Varia } Error ResourceLoaderText::_parse_ext_resource_dummy(DummyReadData *p_data, VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { - VariantParser::Token token; VariantParser::get_token(p_stream, token, line, r_err_str); if (token.type != VariantParser::TK_NUMBER) { @@ -110,7 +106,6 @@ Error ResourceLoaderText::_parse_ext_resource_dummy(DummyReadData *p_data, Varia } Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { - VariantParser::Token token; VariantParser::get_token(p_stream, token, line, r_err_str); if (token.type != VariantParser::TK_NUMBER) { @@ -123,11 +118,9 @@ Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, R if (use_nocache) { r_res = int_resources[index]; } else { - String path = local_path + "::" + itos(index); if (!ignore_resource_parsing) { - if (!ResourceCache::has(path)) { r_err_str = "Can't load cached sub-resource: " + path; return ERR_PARSE_ERROR; @@ -149,7 +142,6 @@ Error ResourceLoaderText::_parse_sub_resource(VariantParser::Stream *p_stream, R } Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, Ref<Resource> &r_res, int &line, String &r_err_str) { - VariantParser::Token token; VariantParser::get_token(p_stream, token, line, r_err_str); if (token.type != VariantParser::TK_NUMBER) { @@ -160,7 +152,6 @@ Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, R int id = token.value; if (!ignore_resource_parsing) { - if (!ext_resources.has(id)) { r_err_str = "Can't load cached ext-resource #" + itos(id); return ERR_PARSE_ERROR; @@ -172,10 +163,8 @@ Error ResourceLoaderText::_parse_ext_resource(VariantParser::Stream *p_stream, R if (ext_resources[id].cache.is_valid()) { r_res = ext_resources[id].cache; } else if (use_sub_threads) { - RES res = ResourceLoader::load_threaded_get(path); if (res.is_null()) { - if (ResourceLoader::get_abort_on_missing_resources()) { error = ERR_FILE_CORRUPT; error_text = "[ext_resource] referenced nonexistent resource at: " + path; @@ -212,9 +201,7 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars packed_scene.instance(); while (true) { - if (next_tag.name == "node") { - int parent = -1; int owner = -1; int type = -1; @@ -240,7 +227,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } if (next_tag.fields.has("instance")) { - instance = packed_scene->get_state()->add_value(next_tag.fields["instance"]); if (packed_scene->get_state()->get_node_count() == 0 && parent == -1) { @@ -250,7 +236,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } if (next_tag.fields.has("instance_placeholder")) { - String path = next_tag.fields["instance_placeholder"]; int path_v = packed_scene->get_state()->add_value(path); @@ -279,7 +264,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars int node_id = packed_scene->get_state()->add_node(parent, owner, type, name, instance, index); if (next_tag.fields.has("groups")) { - Array groups = next_tag.fields["groups"]; for (int i = 0; i < groups.size(); i++) { packed_scene->get_state()->add_node_group(node_id, packed_scene->get_state()->add_name(groups[i])); @@ -287,7 +271,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } while (true) { - String assign; Variant value; @@ -313,7 +296,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } } } else if (next_tag.name == "connection") { - if (!next_tag.fields.has("from")) { error = ERR_FILE_CORRUPT; error_text = "missing 'from' field from connection tag"; @@ -378,7 +360,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } } } else if (next_tag.name == "editable") { - if (!next_tag.fields.has("path")) { error = ERR_FILE_CORRUPT; error_text = "missing 'path' field from connection tag"; @@ -402,7 +383,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } } } else { - error = ERR_FILE_CORRUPT; _printerr(); return Ref<PackedScene>(); @@ -411,7 +391,6 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } Error ResourceLoaderText::load() { - if (error != OK) return error; @@ -459,7 +438,6 @@ Error ResourceLoaderText::load() { er.type = type; if (use_sub_threads) { - Error err = ResourceLoader::load_threaded_request(path, type, use_sub_threads, local_path); if (err != OK) { @@ -477,7 +455,6 @@ Error ResourceLoaderText::load() { RES res = ResourceLoader::load(path, type); if (res.is_null()) { - if (ResourceLoader::get_abort_on_missing_resources()) { error = ERR_FILE_CORRUPT; error_text = "[ext_resource] referenced nonexistent resource at: " + path; @@ -487,7 +464,6 @@ Error ResourceLoaderText::load() { ResourceLoader::notify_dependency_error(local_path, path, type); } } else { - #ifdef TOOLS_ENABLED //remember ID for saving res->set_id_for_path(local_path, index); @@ -544,7 +520,6 @@ Error ResourceLoaderText::load() { Object *obj = ClassDB::instance(type); if (!obj) { - error_text += "Can't create sub resource of type: " + type; _printerr(); error = ERR_FILE_CORRUPT; @@ -553,7 +528,6 @@ Error ResourceLoaderText::load() { Resource *r = Object::cast_to<Resource>(obj); if (!r) { - error_text += "Can't create sub resource of type, because not a resource: " + type; _printerr(); error = ERR_FILE_CORRUPT; @@ -570,7 +544,6 @@ Error ResourceLoaderText::load() { resource_current++; while (true) { - String assign; Variant value; @@ -587,7 +560,6 @@ Error ResourceLoaderText::load() { } //it's assignment } else if (next_tag.name != String()) { - error = OK; break; } else { @@ -609,7 +581,6 @@ Error ResourceLoaderText::load() { } if (is_scene) { - error_text += "found the 'resource' tag on a scene file!"; _printerr(); error = ERR_FILE_CORRUPT; @@ -618,7 +589,6 @@ Error ResourceLoaderText::load() { Object *obj = ClassDB::instance(res_type); if (!obj) { - error_text += "Can't create sub resource of type: " + res_type; _printerr(); error = ERR_FILE_CORRUPT; @@ -627,7 +597,6 @@ Error ResourceLoaderText::load() { Resource *r = Object::cast_to<Resource>(obj); if (!r) { - error_text += "Can't create sub resource of type, because not a resource: " + res_type; _printerr(); error = ERR_FILE_CORRUPT; @@ -639,7 +608,6 @@ Error ResourceLoaderText::load() { resource_current++; while (true) { - String assign; Variant value; @@ -664,7 +632,6 @@ Error ResourceLoaderText::load() { resource->set(assign, value); //it's assignment } else if (next_tag.name != String()) { - error = ERR_FILE_CORRUPT; error_text = "Extra tag found when parsing main resource file"; _printerr(); @@ -683,9 +650,7 @@ Error ResourceLoaderText::load() { //for scene files if (next_tag.name == "node") { - if (!is_scene) { - error_text += "found the 'node' tag on a resource file!"; _printerr(); error = ERR_FILE_CORRUPT; @@ -720,21 +685,17 @@ Error ResourceLoaderText::load() { } int ResourceLoaderText::get_stage() const { - return resource_current; } int ResourceLoaderText::get_stage_count() const { - return resources_total; //+ext_resources; } void ResourceLoaderText::set_translation_remapped(bool p_remapped) { - translation_remapped = p_remapped; } ResourceLoaderText::ResourceLoaderText() { - use_nocache = false; resources_total = 0; @@ -749,18 +710,15 @@ ResourceLoaderText::ResourceLoaderText() { } ResourceLoaderText::~ResourceLoaderText() { - memdelete(f); } void ResourceLoaderText::get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types) { - open(p_f); ignore_resource_parsing = true; ERR_FAIL_COND(error != OK); while (next_tag.name == "ext_resource") { - if (!next_tag.fields.has("type")) { error = ERR_FILE_CORRUPT; error_text = "Missing 'type' in external resource tag"; @@ -801,7 +759,6 @@ void ResourceLoaderText::get_dependencies(FileAccess *p_f, List<String> *p_depen } Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_path, const Map<String, String> &p_map) { - open(p_f, true); ERR_FAIL_COND_V(error != OK, error); ignore_resource_parsing = true; @@ -814,7 +771,6 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p uint64_t tag_end = f->get_position(); while (true) { - Error err = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp); if (err != OK) { @@ -826,7 +782,6 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p } if (next_tag.name != "ext_resource") { - //nothing was done if (!fw) return OK; @@ -834,9 +789,7 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p break; } else { - if (!fw) { - fw = FileAccess::open(p_path + ".depren", FileAccess::WRITE); if (is_scene) { fw->store_line("[gd_scene load_steps=" + itos(resources_total) + " format=" + itos(FORMAT_VERSION) + "]\n"); @@ -903,7 +856,6 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p } void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) { - error = OK; lines = 1; @@ -918,7 +870,6 @@ void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) { Error err = VariantParser::parse_tag(&stream, lines, error_text, tag); if (err) { - error = err; _printerr(); return; @@ -961,7 +912,6 @@ void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) { } if (!p_skip_first_tag) { - err = VariantParser::parse_tag(&stream, lines, error_text, next_tag, &rp); if (err) { @@ -978,7 +928,6 @@ void ResourceLoaderText::open(FileAccess *p_f, bool p_skip_first_tag) { } static void bs_save_unicode_string(FileAccess *f, const String &p_string, bool p_bit_on_len = false) { - CharString utf8 = p_string.utf8(); if (p_bit_on_len) { f->store_32((utf8.length() + 1) | 0x80000000); @@ -989,7 +938,6 @@ 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) return error; @@ -1028,7 +976,6 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) rp.userdata = &dummy_read; while (next_tag.name == "ext_resource") { - if (!next_tag.fields.has("path")) { error = ERR_FILE_CORRUPT; error_text = "Missing 'path' in external resource tag"; @@ -1092,7 +1039,6 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) Vector<size_t> local_pointers_pos; while (next_tag.name == "sub_resource" || next_tag.name == "resource") { - String type; int id = -1; bool main_res; @@ -1134,7 +1080,6 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) int prop_count = 0; while (true) { - String assign; Variant value; @@ -1151,14 +1096,12 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) } if (assign != String()) { - Map<StringName, int> empty_string_map; //unused bs_save_unicode_string(wf2, assign, true); ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_set, dummy_read.external_resources, empty_string_map); prop_count++; } else if (next_tag.name != String()) { - error = OK; break; } else { @@ -1178,7 +1121,6 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) //this is a node, must save one more! if (!is_scene) { - error_text += "found the 'node' tag on a resource file!"; _printerr(); error = ERR_FILE_CORRUPT; @@ -1207,7 +1149,6 @@ 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)) continue; @@ -1253,7 +1194,6 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) } String ResourceLoaderText::recognize(FileAccess *p_f) { - error = OK; lines = 1; @@ -1298,7 +1238,6 @@ 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) *r_error = ERR_CANT_OPEN; @@ -1329,7 +1268,6 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina } void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "") { get_recognized_extensions(p_extensions); return; @@ -1342,17 +1280,14 @@ void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String & } void ResourceFormatLoaderText::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("tscn"); p_extensions->push_back("tres"); } bool ResourceFormatLoaderText::handles_type(const String &p_type) const { - return true; } String ResourceFormatLoaderText::get_resource_type(const String &p_path) const { - String ext = p_path.get_extension().to_lower(); if (ext == "tscn") return "PackedScene"; @@ -1363,7 +1298,6 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const { FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { - return ""; //could not rwead } @@ -1376,10 +1310,8 @@ String ResourceFormatLoaderText::get_resource_type(const String &p_path) const { } void ResourceFormatLoaderText::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { - ERR_FAIL(); } @@ -1391,10 +1323,8 @@ void ResourceFormatLoaderText::get_dependencies(const String &p_path, List<Strin } Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { - ERR_FAIL_V(ERR_CANT_OPEN); } @@ -1408,7 +1338,6 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = nullptr; Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path, const String &p_dst_path) { - Error err; FileAccess *f = FileAccess::open(p_src_path, FileAccess::READ, &err); @@ -1435,18 +1364,14 @@ Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path, /*****************************************************************************************************/ String ResourceFormatSaverTextInstance::_write_resources(void *ud, const RES &p_resource) { - ResourceFormatSaverTextInstance *rsi = (ResourceFormatSaverTextInstance *)ud; return rsi->_write_resource(p_resource); } String ResourceFormatSaverTextInstance::_write_resource(const RES &res) { - if (external_resources.has(res)) { - return "ExtResource( " + itos(external_resources[res]) + " )"; } else { - if (internal_resources.has(res)) { return "SubResource( " + itos(internal_resources[res]) + " )"; } else if (res->get_path().length() && res->get_path().find("::") == -1) { @@ -1464,10 +1389,8 @@ String ResourceFormatSaverTextInstance::_write_resource(const RES &res) { } void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, bool p_main) { - switch (p_variant.get_type()) { case Variant::OBJECT: { - RES res = p_variant; if (res.is_null() || external_resources.has(res)) @@ -1494,11 +1417,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, List<PropertyInfo>::Element *I = property_list.front(); while (I) { - PropertyInfo pi = I->get(); if (pi.usage & PROPERTY_USAGE_STORAGE) { - Variant v = res->get(I->get().name); if (pi.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { @@ -1524,23 +1445,19 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, } break; case Variant::ARRAY: { - Array varray = p_variant; int len = varray.size(); for (int i = 0; i < len; i++) { - const Variant &v = varray.get(i); _find_resources(v); } } break; case Variant::DICTIONARY: { - Dictionary d = p_variant; List<Variant> keys; d.get_key_list(&keys); for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { - Variant v = d[E->get()]; _find_resources(v); } @@ -1551,7 +1468,6 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, } Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - if (p_path.ends_with(".tscn")) { packed_scene = p_resource; } @@ -1648,7 +1564,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r Vector<ResourceSort> sorted_er; for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) { - ResourceSort rs; rs.resource = E->key(); rs.index = E->get(); @@ -1669,10 +1584,8 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r Set<int> used_indices; for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { - RES res = E->get(); if (E->next() && (res->get_path() == "" || res->get_path().find("::") != -1)) { - if (res->get_subindex() != 0) { if (used_indices.has(res->get_subindex())) { res->set_subindex(0); //repeated @@ -1684,7 +1597,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { - RES res = E->get(); ERR_CONTINUE(!resource_set.has(res)); bool main = (E->next() == nullptr); @@ -1723,12 +1635,10 @@ 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")) continue; if (PE->get().usage & PROPERTY_USAGE_STORAGE) { - String name = PE->get().name; Variant value; if (PE->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) { @@ -1764,7 +1674,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r //if this is a scene, save nodes and connections! Ref<SceneState> state = packed_scene->get_state(); for (int i = 0; i < state->get_node_count(); i++) { - StringName type = state->get_node_type(i); StringName name = state->get_node_name(i); int index = state->get_node_index(i); @@ -1802,7 +1711,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_string(header); if (instance_placeholder != String()) { - String vars; f->store_string(" instance_placeholder="); VariantWriter::write_to_string(instance_placeholder, vars, _write_resources, this); @@ -1810,7 +1718,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } if (instance.is_valid()) { - String vars; f->store_string(" instance="); VariantWriter::write_to_string(instance, vars, _write_resources, this); @@ -1820,7 +1727,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_line("]"); for (int j = 0; j < state->get_node_property_count(i); j++) { - String vars; VariantWriter::write_to_string(state->get_node_property_value(i, j), vars, _write_resources, this); @@ -1832,7 +1738,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } for (int i = 0; i < state->get_connection_count(); i++) { - String connstr = "[connection"; connstr += " signal=\"" + String(state->get_connection_signal(i)) + "\""; connstr += " from=\"" + String(state->get_connection_source(i).simplified()) + "\""; @@ -1872,7 +1777,6 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r } Error ResourceFormatSaverText::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - if (p_path.ends_with(".sct") && p_resource->get_class() != "PackedScene") { return ERR_FILE_UNRECOGNIZED; } @@ -1882,11 +1786,9 @@ Error ResourceFormatSaverText::save(const String &p_path, const RES &p_resource, } bool ResourceFormatSaverText::recognize(const RES &p_resource) const { - return true; // all recognized! } void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (p_resource->get_class() == "PackedScene") p_extensions->push_back("tscn"); //text scene else diff --git a/scene/resources/resource_format_text.h b/scene/resources/resource_format_text.h index b9a6db5f36..cf522c9364 100644 --- a/scene/resources/resource_format_text.h +++ b/scene/resources/resource_format_text.h @@ -38,7 +38,6 @@ #include "scene/resources/packed_scene.h" class ResourceLoaderText { - bool translation_remapped; String local_path; String res_path; @@ -92,7 +91,6 @@ class ResourceLoaderText { }; struct DummyReadData { - Map<RES, int> external_resources; Map<int, RES> rev_external_resources; Set<RES> resource_set; @@ -150,7 +148,6 @@ public: }; class ResourceFormatSaverTextInstance { - String local_path; Ref<PackedScene> packed_scene; diff --git a/scene/resources/segment_shape_2d.cpp b/scene/resources/segment_shape_2d.cpp index 814c349784..6fce80b0df 100644 --- a/scene/resources/segment_shape_2d.cpp +++ b/scene/resources/segment_shape_2d.cpp @@ -34,14 +34,12 @@ #include "servers/rendering_server.h" bool SegmentShape2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - Vector2 l[2] = { a, b }; Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point, l); return p_point.distance_to(closest) < p_tolerance; } void SegmentShape2D::_update_shape() { - Rect2 r; r.position = a; r.size = b; @@ -50,32 +48,26 @@ void SegmentShape2D::_update_shape() { } void SegmentShape2D::set_a(const Vector2 &p_a) { - a = p_a; _update_shape(); } Vector2 SegmentShape2D::get_a() const { - return a; } void SegmentShape2D::set_b(const Vector2 &p_b) { - b = p_b; _update_shape(); } Vector2 SegmentShape2D::get_b() const { - return b; } void SegmentShape2D::draw(const RID &p_to_rid, const Color &p_color) { - RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, a, b, p_color, 3); } Rect2 SegmentShape2D::get_rect() const { - Rect2 rect; rect.position = a; rect.expand_to(b); @@ -87,7 +79,6 @@ real_t SegmentShape2D::get_enclosing_radius() const { } void SegmentShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_a", "a"), &SegmentShape2D::set_a); ClassDB::bind_method(D_METHOD("get_a"), &SegmentShape2D::get_a); @@ -100,7 +91,6 @@ void SegmentShape2D::_bind_methods() { SegmentShape2D::SegmentShape2D() : Shape2D(PhysicsServer2D::get_singleton()->segment_shape_create()) { - a = Vector2(); b = Vector2(0, 10); _update_shape(); @@ -109,7 +99,6 @@ SegmentShape2D::SegmentShape2D() : //////////////////////////////////////////////////////////// void RayShape2D::_update_shape() { - Dictionary d; d["length"] = length; d["slips_on_slope"] = slips_on_slope; @@ -118,7 +107,6 @@ void RayShape2D::_update_shape() { } void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) { - Vector2 tip = Vector2(0, get_length()); RS::get_singleton()->canvas_item_add_line(p_to_rid, Vector2(), tip, p_color, 3); Vector<Vector2> pts; @@ -134,7 +122,6 @@ void RayShape2D::draw(const RID &p_to_rid, const Color &p_color) { } Rect2 RayShape2D::get_rect() const { - Rect2 rect; rect.position = Vector2(); rect.expand_to(Vector2(0, length)); @@ -147,7 +134,6 @@ real_t RayShape2D::get_enclosing_radius() const { } void RayShape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_length", "length"), &RayShape2D::set_length); ClassDB::bind_method(D_METHOD("get_length"), &RayShape2D::get_length); @@ -159,17 +145,14 @@ void RayShape2D::_bind_methods() { } void RayShape2D::set_length(real_t p_length) { - length = p_length; _update_shape(); } real_t RayShape2D::get_length() const { - return length; } void RayShape2D::set_slips_on_slope(bool p_active) { - slips_on_slope = p_active; _update_shape(); } @@ -180,7 +163,6 @@ bool RayShape2D::get_slips_on_slope() const { RayShape2D::RayShape2D() : Shape2D(PhysicsServer2D::get_singleton()->ray_shape_create()) { - length = 20; slips_on_slope = false; _update_shape(); diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index 1ac2f7c3c9..188fc70ed3 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -36,12 +36,10 @@ #include "texture.h" Shader::Mode Shader::get_mode() const { - return mode; } void Shader::set_code(const String &p_code) { - String type = ShaderLanguage::get_shader_type(p_code); if (type == "canvas_item") { @@ -61,13 +59,11 @@ void Shader::set_code(const String &p_code) { } String Shader::get_code() const { - _update_shader(); return RenderingServer::get_singleton()->shader_get_code(shader); } void Shader::get_param_list(List<PropertyInfo> *p_params) const { - _update_shader(); List<PropertyInfo> local; @@ -76,7 +72,6 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const { params_cache_dirty = false; for (List<PropertyInfo>::Element *E = local.front(); E; E = E->next()) { - PropertyInfo pi = E->get(); if (default_textures.has(pi.name)) { //do not show default textures continue; @@ -84,7 +79,6 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const { pi.name = "shader_param/" + pi.name; params_cache[pi.name] = E->get().name; if (p_params) { - //small little hack if (pi.type == Variant::_RID) pi.type = Variant::OBJECT; @@ -94,14 +88,12 @@ void Shader::get_param_list(List<PropertyInfo> *p_params) const { } RID Shader::get_rid() const { - _update_shader(); return shader; } void Shader::set_default_texture_param(const StringName &p_param, const Ref<Texture2D> &p_texture) { - if (p_texture.is_valid()) { default_textures[p_param] = p_texture; RS::get_singleton()->shader_set_default_texture_param(shader, p_param, p_texture->get_rid()); @@ -114,7 +106,6 @@ 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)) return default_textures[p_param]; else @@ -122,9 +113,7 @@ Ref<Texture2D> Shader::get_default_texture_param(const StringName &p_param) cons } void Shader::get_default_texture_param_list(List<StringName> *r_textures) const { - for (const Map<StringName, Ref<Texture2D>>::Element *E = default_textures.front(); E; E = E->next()) { - r_textures->push_back(E->key()); } } @@ -134,7 +123,6 @@ bool Shader::is_text_shader() const { } bool Shader::has_param(const StringName &p_param) const { - return params_cache.has(p_param); } @@ -142,7 +130,6 @@ void Shader::_update_shader() const { } void Shader::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_mode"), &Shader::get_mode); ClassDB::bind_method(D_METHOD("set_code", "code"), &Shader::set_code); @@ -164,20 +151,17 @@ void Shader::_bind_methods() { } Shader::Shader() { - mode = MODE_SPATIAL; shader = RenderingServer::get_singleton()->shader_create(); params_cache_dirty = true; } Shader::~Shader() { - RenderingServer::get_singleton()->free(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) *r_error = ERR_FILE_CANT_OPEN; @@ -198,17 +182,14 @@ RES ResourceFormatLoaderShader::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderShader::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("shader"); } bool ResourceFormatLoaderShader::handles_type(const String &p_type) const { - return (p_type == "Shader"); } String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "shader") return "Shader"; @@ -216,7 +197,6 @@ String ResourceFormatLoaderShader::get_resource_type(const String &p_path) const } Error ResourceFormatSaverShader::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref<Shader> shader = p_resource; ERR_FAIL_COND_V(shader.is_null(), ERR_INVALID_PARAMETER); @@ -239,7 +219,6 @@ Error ResourceFormatSaverShader::save(const String &p_path, const RES &p_resourc } void ResourceFormatSaverShader::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (const Shader *shader = Object::cast_to<Shader>(*p_resource)) { if (shader->is_text_shader()) { p_extensions->push_back("shader"); @@ -247,6 +226,5 @@ void ResourceFormatSaverShader::get_recognized_extensions(const RES &p_resource, } } bool ResourceFormatSaverShader::recognize(const RES &p_resource) const { - return p_resource->get_class_name() == "Shader"; //only shader, not inherited } diff --git a/scene/resources/shader.h b/scene/resources/shader.h index 75c38bd561..9fa8a9ae95 100644 --- a/scene/resources/shader.h +++ b/scene/resources/shader.h @@ -37,7 +37,6 @@ #include "scene/resources/texture.h" class Shader : public Resource { - GDCLASS(Shader, Resource); OBJ_SAVE_TYPE(Shader); diff --git a/scene/resources/shape_2d.cpp b/scene/resources/shape_2d.cpp index 4fe585053a..b48de1aeb3 100644 --- a/scene/resources/shape_2d.cpp +++ b/scene/resources/shape_2d.cpp @@ -31,23 +31,19 @@ #include "shape_2d.h" #include "servers/physics_server_2d.h" RID Shape2D::get_rid() const { - return shape; } void Shape2D::set_custom_solver_bias(real_t p_bias) { - custom_bias = p_bias; PhysicsServer2D::get_singleton()->shape_set_custom_solver_bias(shape, custom_bias); } real_t Shape2D::get_custom_solver_bias() const { - return custom_bias; } bool Shape2D::collide_with_motion(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref<Shape2D> &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { - ERR_FAIL_COND_V(p_shape.is_null(), false); int r; return PhysicsServer2D::get_singleton()->shape_collide(get_rid(), p_local_xform, p_local_motion, p_shape->get_rid(), p_shape_xform, p_shape_motion, nullptr, 0, r); @@ -60,7 +56,6 @@ bool Shape2D::collide(const Transform2D &p_local_xform, const Ref<Shape2D> &p_sh } Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_xform, const Vector2 &p_local_motion, const Ref<Shape2D> &p_shape, const Transform2D &p_shape_xform, const Vector2 &p_shape_motion) { - ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; Vector2 result[max_contacts * 2]; @@ -78,7 +73,6 @@ Array Shape2D::collide_with_motion_and_get_contacts(const Transform2D &p_local_x return results; } Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const Ref<Shape2D> &p_shape, const Transform2D &p_shape_xform) { - ERR_FAIL_COND_V(p_shape.is_null(), Array()); const int max_contacts = 16; Vector2 result[max_contacts * 2]; @@ -97,7 +91,6 @@ Array Shape2D::collide_and_get_contacts(const Transform2D &p_local_xform, const } void Shape2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_custom_solver_bias", "bias"), &Shape2D::set_custom_solver_bias); ClassDB::bind_method(D_METHOD("get_custom_solver_bias"), &Shape2D::get_custom_solver_bias); ClassDB::bind_method(D_METHOD("collide", "local_xform", "with_shape", "shape_xform"), &Shape2D::collide); @@ -114,6 +107,5 @@ Shape2D::Shape2D(const RID &p_rid) { } Shape2D::~Shape2D() { - PhysicsServer2D::get_singleton()->free(shape); } diff --git a/scene/resources/shape_3d.cpp b/scene/resources/shape_3d.cpp index 97d03b3cfc..110543723c 100644 --- a/scene/resources/shape_3d.cpp +++ b/scene/resources/shape_3d.cpp @@ -36,11 +36,9 @@ #include "servers/physics_server_3d.h" void Shape3D::add_vertices_to_array(Vector<Vector3> &array, const Transform &p_xform) { - Vector<Vector3> toadd = get_debug_mesh_lines(); if (toadd.size()) { - int base = array.size(); array.resize(base + toadd.size()); Vector3 *w = array.ptrw(); @@ -60,7 +58,6 @@ void Shape3D::set_margin(real_t p_margin) { } Ref<ArrayMesh> Shape3D::get_debug_mesh() { - if (debug_mesh_cache.is_valid()) return debug_mesh_cache; @@ -73,7 +70,6 @@ Ref<ArrayMesh> Shape3D::get_debug_mesh() { Vector<Vector3> array; array.resize(lines.size()); { - Vector3 *w = array.ptrw(); for (int i = 0; i < lines.size(); i++) { w[i] = lines[i]; @@ -102,7 +98,6 @@ void Shape3D::_update_shape() { } void Shape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_margin", "margin"), &Shape3D::set_margin); ClassDB::bind_method(D_METHOD("get_margin"), &Shape3D::get_margin); diff --git a/scene/resources/shape_3d.h b/scene/resources/shape_3d.h index 6516868fd5..a83b2ed009 100644 --- a/scene/resources/shape_3d.h +++ b/scene/resources/shape_3d.h @@ -36,7 +36,6 @@ class ArrayMesh; class Shape3D : public Resource { - GDCLASS(Shape3D, Resource); OBJ_SAVE_TYPE(Shape3D); RES_BASE_EXTENSION("shape"); diff --git a/scene/resources/skin.cpp b/scene/resources/skin.cpp index df0620b6c4..86b65925f5 100644 --- a/scene/resources/skin.cpp +++ b/scene/resources/skin.cpp @@ -46,7 +46,6 @@ void Skin::add_bind(int p_bone, const Transform &p_pose) { } void Skin::add_named_bind(const String &p_name, const Transform &p_pose) { - uint32_t index = bind_count; set_bind_count(bind_count + 1); set_bind_name(index, p_name); @@ -105,7 +104,6 @@ bool Skin::_set(const StringName &p_name, const Variant &p_value) { } bool Skin::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; if (name == "bind_count") { r_ret = get_bind_count(); @@ -136,7 +134,6 @@ void Skin::_get_property_list(List<PropertyInfo> *p_list) const { } void Skin::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_bind_count", "bind_count"), &Skin::set_bind_count); ClassDB::bind_method(D_METHOD("get_bind_count"), &Skin::get_bind_count); diff --git a/scene/resources/sky.cpp b/scene/resources/sky.cpp index cbe86b16b2..e7ca12162b 100644 --- a/scene/resources/sky.cpp +++ b/scene/resources/sky.cpp @@ -43,7 +43,6 @@ void Sky::set_radiance_size(RadianceSize p_size) { } Sky::RadianceSize Sky::get_radiance_size() const { - return radiance_size; } @@ -69,12 +68,10 @@ Ref<Material> Sky::get_material() const { } RID Sky::get_rid() const { - return sky; } void Sky::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radiance_size", "size"), &Sky::set_radiance_size); ClassDB::bind_method(D_METHOD("get_radiance_size"), &Sky::get_radiance_size); @@ -108,6 +105,5 @@ Sky::Sky() { } Sky::~Sky() { - RS::get_singleton()->free(sky); }
\ No newline at end of file diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp index a0b6ab1e30..860673bee6 100644 --- a/scene/resources/sky_material.cpp +++ b/scene/resources/sky_material.cpp @@ -31,103 +31,83 @@ #include "sky_material.h" void ProceduralSkyMaterial::set_sky_top_color(const Color &p_sky_top) { - sky_top_color = p_sky_top; RS::get_singleton()->material_set_param(_get_material(), "sky_top_color", sky_top_color.to_linear()); } Color ProceduralSkyMaterial::get_sky_top_color() const { - return sky_top_color; } void ProceduralSkyMaterial::set_sky_horizon_color(const Color &p_sky_horizon) { - sky_horizon_color = p_sky_horizon; RS::get_singleton()->material_set_param(_get_material(), "sky_horizon_color", sky_horizon_color.to_linear()); } Color ProceduralSkyMaterial::get_sky_horizon_color() const { - return sky_horizon_color; } void ProceduralSkyMaterial::set_sky_curve(float p_curve) { - sky_curve = p_curve; RS::get_singleton()->material_set_param(_get_material(), "sky_curve", sky_curve); } float ProceduralSkyMaterial::get_sky_curve() const { - return sky_curve; } void ProceduralSkyMaterial::set_sky_energy(float p_energy) { - sky_energy = p_energy; RS::get_singleton()->material_set_param(_get_material(), "sky_energy", sky_energy); } float ProceduralSkyMaterial::get_sky_energy() const { - return sky_energy; } void ProceduralSkyMaterial::set_ground_bottom_color(const Color &p_ground_bottom) { - ground_bottom_color = p_ground_bottom; RS::get_singleton()->material_set_param(_get_material(), "ground_bottom_color", ground_bottom_color.to_linear()); } Color ProceduralSkyMaterial::get_ground_bottom_color() const { - return ground_bottom_color; } void ProceduralSkyMaterial::set_ground_horizon_color(const Color &p_ground_horizon) { - ground_horizon_color = p_ground_horizon; RS::get_singleton()->material_set_param(_get_material(), "ground_horizon_color", ground_horizon_color.to_linear()); } Color ProceduralSkyMaterial::get_ground_horizon_color() const { - return ground_horizon_color; } void ProceduralSkyMaterial::set_ground_curve(float p_curve) { - ground_curve = p_curve; RS::get_singleton()->material_set_param(_get_material(), "ground_curve", ground_curve); } float ProceduralSkyMaterial::get_ground_curve() const { - return ground_curve; } void ProceduralSkyMaterial::set_ground_energy(float p_energy) { - ground_energy = p_energy; RS::get_singleton()->material_set_param(_get_material(), "ground_energy", ground_energy); } float ProceduralSkyMaterial::get_ground_energy() const { - return ground_energy; } void ProceduralSkyMaterial::set_sun_angle_max(float p_angle) { - sun_angle_max = p_angle; RS::get_singleton()->material_set_param(_get_material(), "sun_angle_max", Math::deg2rad(sun_angle_max)); } float ProceduralSkyMaterial::get_sun_angle_max() const { - return sun_angle_max; } void ProceduralSkyMaterial::set_sun_curve(float p_curve) { - sun_curve = p_curve; RS::get_singleton()->material_set_param(_get_material(), "sun_curve", sun_curve); } float ProceduralSkyMaterial::get_sun_curve() const { - return sun_curve; } @@ -136,17 +116,14 @@ bool ProceduralSkyMaterial::_can_do_next_pass() const { } Shader::Mode ProceduralSkyMaterial::get_shader_mode() const { - return Shader::MODE_SKY; } RID ProceduralSkyMaterial::get_shader_rid() const { - return shader; } void ProceduralSkyMaterial::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_sky_top_color", "color"), &ProceduralSkyMaterial::set_sky_top_color); ClassDB::bind_method(D_METHOD("get_sky_top_color"), &ProceduralSkyMaterial::get_sky_top_color); @@ -195,7 +172,6 @@ void ProceduralSkyMaterial::_bind_methods() { } ProceduralSkyMaterial::ProceduralSkyMaterial() { - String code = "shader_type sky;\n\n"; code += "uniform vec4 sky_top_color : hint_color = vec4(0.35, 0.46, 0.71, 1.0);\n"; @@ -285,13 +261,11 @@ ProceduralSkyMaterial::~ProceduralSkyMaterial() { /* PanoramaSkyMaterial */ void PanoramaSkyMaterial::set_panorama(const Ref<Texture2D> &p_panorama) { - panorama = p_panorama; RS::get_singleton()->material_set_param(_get_material(), "source_panorama", panorama); } Ref<Texture2D> PanoramaSkyMaterial::get_panorama() const { - return panorama; } @@ -300,17 +274,14 @@ bool PanoramaSkyMaterial::_can_do_next_pass() const { } Shader::Mode PanoramaSkyMaterial::get_shader_mode() const { - return Shader::MODE_SKY; } RID PanoramaSkyMaterial::get_shader_rid() const { - return shader; } void PanoramaSkyMaterial::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_panorama", "texture"), &PanoramaSkyMaterial::set_panorama); ClassDB::bind_method(D_METHOD("get_panorama"), &PanoramaSkyMaterial::get_panorama); @@ -340,47 +311,38 @@ PanoramaSkyMaterial::~PanoramaSkyMaterial() { /* PhysicalSkyMaterial */ void PhysicalSkyMaterial::set_rayleigh_coefficient(float p_rayleigh) { - rayleigh = p_rayleigh; RS::get_singleton()->material_set_param(_get_material(), "rayleigh", rayleigh); } float PhysicalSkyMaterial::get_rayleigh_coefficient() const { - return rayleigh; } void PhysicalSkyMaterial::set_rayleigh_color(Color p_rayleigh_color) { - rayleigh_color = p_rayleigh_color; RS::get_singleton()->material_set_param(_get_material(), "rayleigh_color", rayleigh_color); } Color PhysicalSkyMaterial::get_rayleigh_color() const { - return rayleigh_color; } void PhysicalSkyMaterial::set_mie_coefficient(float p_mie) { - mie = p_mie; RS::get_singleton()->material_set_param(_get_material(), "mie", mie); } float PhysicalSkyMaterial::get_mie_coefficient() const { - return mie; } void PhysicalSkyMaterial::set_mie_eccentricity(float p_eccentricity) { - mie_eccentricity = p_eccentricity; RS::get_singleton()->material_set_param(_get_material(), "mie_eccentricity", mie_eccentricity); } float PhysicalSkyMaterial::get_mie_eccentricity() const { - return mie_eccentricity; } void PhysicalSkyMaterial::set_mie_color(Color p_mie_color) { - mie_color = p_mie_color; RS::get_singleton()->material_set_param(_get_material(), "mie_color", mie_color); } @@ -389,52 +351,42 @@ Color PhysicalSkyMaterial::get_mie_color() const { } void PhysicalSkyMaterial::set_turbidity(float p_turbidity) { - turbidity = p_turbidity; RS::get_singleton()->material_set_param(_get_material(), "turbidity", turbidity); } float PhysicalSkyMaterial::get_turbidity() const { - return turbidity; } void PhysicalSkyMaterial::set_sun_disk_scale(float p_sun_disk_scale) { - sun_disk_scale = p_sun_disk_scale; RS::get_singleton()->material_set_param(_get_material(), "sun_disk_scale", sun_disk_scale); } float PhysicalSkyMaterial::get_sun_disk_scale() const { - return sun_disk_scale; } void PhysicalSkyMaterial::set_ground_color(Color p_ground_color) { - ground_color = p_ground_color; RS::get_singleton()->material_set_param(_get_material(), "ground_color", ground_color); } Color PhysicalSkyMaterial::get_ground_color() const { - return ground_color; } void PhysicalSkyMaterial::set_exposure(float p_exposure) { - exposure = p_exposure; RS::get_singleton()->material_set_param(_get_material(), "exposure", exposure); } float PhysicalSkyMaterial::get_exposure() const { - return exposure; } void PhysicalSkyMaterial::set_dither_strength(float p_dither_strength) { - dither_strength = p_dither_strength; RS::get_singleton()->material_set_param(_get_material(), "dither_strength", dither_strength); } float PhysicalSkyMaterial::get_dither_strength() const { - return dither_strength; } @@ -443,17 +395,14 @@ bool PhysicalSkyMaterial::_can_do_next_pass() const { } Shader::Mode PhysicalSkyMaterial::get_shader_mode() const { - return Shader::MODE_SKY; } RID PhysicalSkyMaterial::get_shader_rid() const { - return shader; } void PhysicalSkyMaterial::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_rayleigh_coefficient", "rayleigh"), &PhysicalSkyMaterial::set_rayleigh_coefficient); ClassDB::bind_method(D_METHOD("get_rayleigh_coefficient"), &PhysicalSkyMaterial::get_rayleigh_coefficient); diff --git a/scene/resources/sky_material.h b/scene/resources/sky_material.h index 9bd9d7ec8b..cd245a2897 100644 --- a/scene/resources/sky_material.h +++ b/scene/resources/sky_material.h @@ -35,7 +35,6 @@ #define SKY_MATERIAL_H class ProceduralSkyMaterial : public Material { - GDCLASS(ProceduralSkyMaterial, Material); private: diff --git a/scene/resources/sphere_shape_3d.cpp b/scene/resources/sphere_shape_3d.cpp index 153db4c291..d24998ff18 100644 --- a/scene/resources/sphere_shape_3d.cpp +++ b/scene/resources/sphere_shape_3d.cpp @@ -32,13 +32,11 @@ #include "servers/physics_server_3d.h" Vector<Vector3> SphereShape3D::get_debug_mesh_lines() { - float r = get_radius(); Vector<Vector3> points; for (int i = 0; i <= 360; i++) { - float ra = Math::deg2rad((float)i); float rb = Math::deg2rad((float)i + 1); Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r; @@ -60,13 +58,11 @@ real_t SphereShape3D::get_enclosing_radius() const { } void SphereShape3D::_update_shape() { - PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), radius); Shape3D::_update_shape(); } void SphereShape3D::set_radius(float p_radius) { - radius = p_radius; _update_shape(); notify_change_to_owners(); @@ -74,12 +70,10 @@ void SphereShape3D::set_radius(float p_radius) { } float SphereShape3D::get_radius() const { - return radius; } void SphereShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &SphereShape3D::set_radius); ClassDB::bind_method(D_METHOD("get_radius"), &SphereShape3D::get_radius); @@ -88,6 +82,5 @@ void SphereShape3D::_bind_methods() { SphereShape3D::SphereShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_SPHERE)) { - set_radius(1.0); } diff --git a/scene/resources/sphere_shape_3d.h b/scene/resources/sphere_shape_3d.h index 3ed50cfe83..ee31bb615c 100644 --- a/scene/resources/sphere_shape_3d.h +++ b/scene/resources/sphere_shape_3d.h @@ -34,7 +34,6 @@ #include "scene/resources/shape_3d.h" class SphereShape3D : public Shape3D { - GDCLASS(SphereShape3D, Shape3D); float radius; diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 56fb5d441f..550abd29af 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -35,26 +35,22 @@ #include <limits.h> bool StyleBox::test_mask(const Point2 &p_point, const Rect2 &p_rect) const { - return true; } void StyleBox::set_default_margin(Margin p_margin, float p_value) { - ERR_FAIL_INDEX((int)p_margin, 4); margin[p_margin] = p_value; emit_changed(); } float StyleBox::get_default_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); return margin[p_margin]; } float StyleBox::get_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); if (margin[p_margin] < 0) @@ -68,17 +64,14 @@ CanvasItem *StyleBox::get_current_item_drawn() const { } Size2 StyleBox::get_minimum_size() const { - return Size2(get_margin(MARGIN_LEFT) + get_margin(MARGIN_RIGHT), get_margin(MARGIN_TOP) + get_margin(MARGIN_BOTTOM)); } Point2 StyleBox::get_offset() const { - return Point2(get_margin(MARGIN_LEFT), get_margin(MARGIN_TOP)); } Size2 StyleBox::get_center_size() const { - return Size2(); } @@ -87,7 +80,6 @@ Rect2 StyleBox::get_draw_rect(const Rect2 &p_rect) const { } void StyleBox::_bind_methods() { - ClassDB::bind_method(D_METHOD("test_mask", "point", "rect"), &StyleBox::test_mask); ClassDB::bind_method(D_METHOD("set_default_margin", "margin", "offset"), &StyleBox::set_default_margin); @@ -112,15 +104,12 @@ void StyleBox::_bind_methods() { } StyleBox::StyleBox() { - for (int i = 0; i < 4; i++) { - margin[i] = -1; } } void StyleBoxTexture::set_texture(Ref<Texture2D> p_texture) { - if (texture == p_texture) return; texture = p_texture; @@ -135,12 +124,10 @@ void StyleBoxTexture::set_texture(Ref<Texture2D> p_texture) { } Ref<Texture2D> StyleBoxTexture::get_texture() const { - return texture; } void StyleBoxTexture::set_normal_map(Ref<Texture2D> p_normal_map) { - if (normal_map == p_normal_map) return; normal_map = p_normal_map; @@ -148,12 +135,10 @@ void StyleBoxTexture::set_normal_map(Ref<Texture2D> p_normal_map) { } Ref<Texture2D> StyleBoxTexture::get_normal_map() const { - return normal_map; } void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) { - ERR_FAIL_INDEX((int)p_margin, 4); margin[p_margin] = p_size; @@ -167,14 +152,12 @@ void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) { _change_notify(margin_prop[p_margin]); } float StyleBoxTexture::get_margin_size(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); return margin[p_margin]; } float StyleBoxTexture::get_style_margin(Margin p_margin) const { - ERR_FAIL_INDEX_V((int)p_margin, 4, 0.0); return margin[p_margin]; @@ -206,18 +189,15 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const { } void StyleBoxTexture::set_draw_center(bool p_enabled) { - draw_center = p_enabled; emit_changed(); } bool StyleBoxTexture::is_draw_center_enabled() const { - return draw_center; } Size2 StyleBoxTexture::get_center_size() const { - if (texture.is_null()) return Size2(); @@ -225,7 +205,6 @@ Size2 StyleBoxTexture::get_center_size() const { } void StyleBoxTexture::set_expand_margin_size(Margin p_expand_margin, float p_size) { - ERR_FAIL_INDEX((int)p_expand_margin, 4); expand_margin[p_expand_margin] = p_size; emit_changed(); @@ -241,20 +220,17 @@ void StyleBoxTexture::set_expand_margin_size_individual(float p_left, float p_to void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) { for (int i = 0; i < 4; i++) { - expand_margin[i] = p_expand_margin_size; } emit_changed(); } float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const { - ERR_FAIL_INDEX_V((int)p_expand_margin, 4, 0); return expand_margin[p_expand_margin]; } void StyleBoxTexture::set_region_rect(const Rect2 &p_region_rect) { - if (region_rect == p_region_rect) return; @@ -263,31 +239,26 @@ void StyleBoxTexture::set_region_rect(const Rect2 &p_region_rect) { } Rect2 StyleBoxTexture::get_region_rect() const { - return region_rect; } void StyleBoxTexture::set_h_axis_stretch_mode(AxisStretchMode p_mode) { - ERR_FAIL_INDEX((int)p_mode, 3); axis_h = p_mode; emit_changed(); } StyleBoxTexture::AxisStretchMode StyleBoxTexture::get_h_axis_stretch_mode() const { - return axis_h; } void StyleBoxTexture::set_v_axis_stretch_mode(AxisStretchMode p_mode) { - ERR_FAIL_INDEX((int)p_mode, 3); axis_v = p_mode; emit_changed(); } StyleBoxTexture::AxisStretchMode StyleBoxTexture::get_v_axis_stretch_mode() const { - return axis_v; } @@ -299,12 +270,10 @@ void StyleBoxTexture::set_modulate(const Color &p_modulate) { } Color StyleBoxTexture::get_modulate() const { - return modulate; } void StyleBoxTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_texture", "texture"), &StyleBoxTexture::set_texture); ClassDB::bind_method(D_METHOD("get_texture"), &StyleBoxTexture::get_texture); @@ -362,7 +331,6 @@ void StyleBoxTexture::_bind_methods() { } StyleBoxTexture::StyleBoxTexture() { - for (int i = 0; i < 4; i++) { margin[i] = 0; expand_margin[i] = 0; @@ -379,23 +347,19 @@ StyleBoxTexture::~StyleBoxTexture() { //////////////// void StyleBoxFlat::set_bg_color(const Color &p_color) { - bg_color = p_color; emit_changed(); } Color StyleBoxFlat::get_bg_color() const { - return bg_color; } void StyleBoxFlat::set_border_color(const Color &p_color) { - border_color = p_color; emit_changed(); } Color StyleBoxFlat::get_border_color() const { - return border_color; } @@ -407,7 +371,6 @@ void StyleBoxFlat::set_border_width_all(int p_size) { emit_changed(); } int StyleBoxFlat::get_border_width_min() const { - return MIN(MIN(border_width[0], border_width[1]), MIN(border_width[2], border_width[3])); } @@ -423,17 +386,14 @@ int StyleBoxFlat::get_border_width(Margin p_margin) const { } void StyleBoxFlat::set_border_blend(bool p_blend) { - blend_border = p_blend; emit_changed(); } bool StyleBoxFlat::get_border_blend() const { - return blend_border; } void StyleBoxFlat::set_corner_radius_all(int radius) { - for (int i = 0; i < 4; i++) { corner_radius[i] = radius; } @@ -459,19 +419,16 @@ int StyleBoxFlat::get_corner_radius_min() const { } void StyleBoxFlat::set_corner_radius(const Corner p_corner, const int radius) { - ERR_FAIL_INDEX((int)p_corner, 4); corner_radius[p_corner] = radius; emit_changed(); } int StyleBoxFlat::get_corner_radius(const Corner p_corner) const { - ERR_FAIL_INDEX_V((int)p_corner, 4, 0); return corner_radius[p_corner]; } void StyleBoxFlat::set_expand_margin_size(Margin p_expand_margin, float p_size) { - ERR_FAIL_INDEX((int)p_expand_margin, 4); expand_margin[p_expand_margin] = p_size; emit_changed(); @@ -487,54 +444,44 @@ void StyleBoxFlat::set_expand_margin_size_individual(float p_left, float p_top, void StyleBoxFlat::set_expand_margin_size_all(float p_expand_margin_size) { for (int i = 0; i < 4; i++) { - expand_margin[i] = p_expand_margin_size; } emit_changed(); } float StyleBoxFlat::get_expand_margin_size(Margin p_expand_margin) const { - ERR_FAIL_INDEX_V((int)p_expand_margin, 4, 0.0); return expand_margin[p_expand_margin]; } void StyleBoxFlat::set_draw_center(bool p_enabled) { - draw_center = p_enabled; emit_changed(); } bool StyleBoxFlat::is_draw_center_enabled() const { - return draw_center; } void StyleBoxFlat::set_shadow_color(const Color &p_color) { - shadow_color = p_color; emit_changed(); } Color StyleBoxFlat::get_shadow_color() const { - return shadow_color; } void StyleBoxFlat::set_shadow_size(const int &p_size) { - shadow_size = p_size; emit_changed(); } int StyleBoxFlat::get_shadow_size() const { - return shadow_size; } void StyleBoxFlat::set_shadow_offset(const Point2 &p_offset) { - shadow_offset = p_offset; emit_changed(); } Point2 StyleBoxFlat::get_shadow_offset() const { - return shadow_offset; } @@ -563,7 +510,6 @@ int StyleBoxFlat::get_corner_detail() const { } Size2 StyleBoxFlat::get_center_size() const { - return Size2(); } @@ -593,7 +539,6 @@ inline void set_inner_corner_radius(const Rect2 style_rect, const Rect2 inner_re inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color> &colors, const Rect2 &style_rect, const int corner_radius[4], const Rect2 &ring_rect, const Rect2 &inner_rect, const Color &inner_color, const Color &outer_color, const int corner_detail, const bool fill_center = false) { - int vert_offset = verts.size(); if (!vert_offset) { vert_offset = 0; @@ -705,7 +650,6 @@ Rect2 StyleBoxFlat::get_draw_rect(const Rect2 &p_rect) const { } void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { - //PREPARATIONS bool draw_border = (border_width[0] > 0) || (border_width[1] > 0) || (border_width[2] > 0) || (border_width[3] > 0); bool draw_shadow = (shadow_size > 0); @@ -862,7 +806,6 @@ float StyleBoxFlat::get_style_margin(Margin p_margin) const { return border_width[p_margin]; } void StyleBoxFlat::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_bg_color", "color"), &StyleBoxFlat::set_bg_color); ClassDB::bind_method(D_METHOD("get_bg_color"), &StyleBoxFlat::get_bg_color); @@ -950,7 +893,6 @@ void StyleBoxFlat::_bind_methods() { } StyleBoxFlat::StyleBoxFlat() { - bg_color = Color(0.6, 0.6, 0.6); shadow_color = Color(0, 0, 0, 0.6); border_color = Color(0.8, 0.8, 0.8); @@ -1023,7 +965,6 @@ float StyleBoxLine::get_grow_begin() const { } void StyleBoxLine::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_color", "color"), &StyleBoxLine::set_color); ClassDB::bind_method(D_METHOD("get_color"), &StyleBoxLine::get_color); ClassDB::bind_method(D_METHOD("set_thickness", "thickness"), &StyleBoxLine::set_thickness); diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index f19b93d00d..99adbe589a 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -38,7 +38,6 @@ class CanvasItem; class StyleBox : public Resource { - GDCLASS(StyleBox, Resource); RES_BASE_EXTENSION("stylebox"); OBJ_SAVE_TYPE(StyleBox); @@ -68,7 +67,6 @@ public: }; class StyleBoxEmpty : public StyleBox { - GDCLASS(StyleBoxEmpty, StyleBox); virtual float get_style_margin(Margin p_margin) const { return 0; } @@ -78,7 +76,6 @@ public: }; class StyleBoxTexture : public StyleBox { - GDCLASS(StyleBoxTexture, StyleBox); public: @@ -144,7 +141,6 @@ public: VARIANT_ENUM_CAST(StyleBoxTexture::AxisStretchMode) class StyleBoxFlat : public StyleBox { - GDCLASS(StyleBoxFlat, StyleBox); Color bg_color; @@ -238,7 +234,6 @@ public: // just used to draw lines. class StyleBoxLine : public StyleBox { - GDCLASS(StyleBoxLine, StyleBox); Color color; int thickness; diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 4b392e23b7..95eaf461e1 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -36,7 +36,6 @@ #define EQ_VERTEX_DIST 0.00001 bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const { - if (vertex != p_vertex.vertex) return false; @@ -72,7 +71,6 @@ bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const { } uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) { - uint32_t h = hash_djb2_buffer((const uint8_t *)&p_vtx.vertex, sizeof(real_t) * 3); h = hash_djb2_buffer((const uint8_t *)&p_vtx.normal, sizeof(real_t) * 3, h); h = hash_djb2_buffer((const uint8_t *)&p_vtx.binormal, sizeof(real_t) * 3, h); @@ -86,7 +84,6 @@ uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) { } void SurfaceTool::begin(Mesh::PrimitiveType p_primitive) { - clear(); primitive = p_primitive; @@ -95,7 +92,6 @@ void SurfaceTool::begin(Mesh::PrimitiveType p_primitive) { } void SurfaceTool::add_vertex(const Vector3 &p_vertex) { - ERR_FAIL_COND(!begun); Vertex vtx; @@ -160,7 +156,6 @@ void SurfaceTool::add_vertex(const Vector3 &p_vertex) { format |= Mesh::ARRAY_FORMAT_VERTEX; } void SurfaceTool::add_color(Color p_color) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_COLOR)); @@ -169,7 +164,6 @@ void SurfaceTool::add_color(Color p_color) { last_color = p_color; } void SurfaceTool::add_normal(const Vector3 &p_normal) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_NORMAL)); @@ -179,7 +173,6 @@ void SurfaceTool::add_normal(const Vector3 &p_normal) { } void SurfaceTool::add_tangent(const Plane &p_tangent) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_TANGENT)); @@ -188,7 +181,6 @@ void SurfaceTool::add_tangent(const Plane &p_tangent) { } void SurfaceTool::add_uv(const Vector2 &p_uv) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_TEX_UV)); @@ -197,7 +189,6 @@ void SurfaceTool::add_uv(const Vector2 &p_uv) { } void SurfaceTool::add_uv2(const Vector2 &p_uv2) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_TEX_UV2)); @@ -206,7 +197,6 @@ void SurfaceTool::add_uv2(const Vector2 &p_uv2) { } void SurfaceTool::add_bones(const Vector<int> &p_bones) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_BONES)); @@ -215,7 +205,6 @@ void SurfaceTool::add_bones(const Vector<int> &p_bones) { } void SurfaceTool::add_weights(const Vector<float> &p_weights) { - ERR_FAIL_COND(!begun); ERR_FAIL_COND(!first && !(format & Mesh::ARRAY_FORMAT_WEIGHTS)); @@ -224,12 +213,10 @@ void SurfaceTool::add_weights(const Vector<float> &p_weights) { } void SurfaceTool::add_smooth_group(bool p_smooth) { - ERR_FAIL_COND(!begun); if (index_array.size()) { smooth_groups[index_array.size()] = p_smooth; } else { - smooth_groups[vertex_array.size()] = p_smooth; } } @@ -264,7 +251,6 @@ void SurfaceTool::add_triangle_fan(const Vector<Vector3> &p_vertices, const Vect } void SurfaceTool::add_index(int p_index) { - ERR_FAIL_COND(!begun); format |= Mesh::ARRAY_FORMAT_INDEX; @@ -272,29 +258,24 @@ void SurfaceTool::add_index(int p_index) { } Array SurfaceTool::commit_to_arrays() { - int varr_len = vertex_array.size(); Array a; a.resize(Mesh::ARRAY_MAX); for (int i = 0; i < Mesh::ARRAY_MAX; i++) { - if (!(format & (1 << i))) continue; //not in format switch (i) { - case Mesh::ARRAY_VERTEX: case Mesh::ARRAY_NORMAL: { - Vector<Vector3> array; array.resize(varr_len); Vector3 *w = array.ptrw(); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) { - const Vertex &v = E->get(); switch (i) { @@ -313,18 +294,15 @@ Array SurfaceTool::commit_to_arrays() { case Mesh::ARRAY_TEX_UV: case Mesh::ARRAY_TEX_UV2: { - Vector<Vector2> array; array.resize(varr_len); Vector2 *w = array.ptrw(); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) { - const Vertex &v = E->get(); switch (i) { - case Mesh::ARRAY_TEX_UV: { w[idx] = v.uv; } break; @@ -337,14 +315,12 @@ Array SurfaceTool::commit_to_arrays() { a[i] = array; } break; case Mesh::ARRAY_TANGENT: { - Vector<float> array; array.resize(varr_len * 4); float *w = array.ptrw(); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx += 4) { - const Vertex &v = E->get(); w[idx + 0] = v.tangent.x; @@ -360,14 +336,12 @@ Array SurfaceTool::commit_to_arrays() { } break; case Mesh::ARRAY_COLOR: { - Vector<Color> array; array.resize(varr_len); Color *w = array.ptrw(); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) { - const Vertex &v = E->get(); w[idx] = v.color; } @@ -375,14 +349,12 @@ Array SurfaceTool::commit_to_arrays() { a[i] = array; } break; case Mesh::ARRAY_BONES: { - Vector<int> array; array.resize(varr_len * 4); int *w = array.ptrw(); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx += 4) { - const Vertex &v = E->get(); ERR_CONTINUE(v.bones.size() != 4); @@ -396,19 +368,16 @@ Array SurfaceTool::commit_to_arrays() { } break; case Mesh::ARRAY_WEIGHTS: { - Vector<float> array; array.resize(varr_len * 4); float *w = array.ptrw(); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx += 4) { - const Vertex &v = E->get(); ERR_CONTINUE(v.weights.size() != 4); for (int j = 0; j < 4; j++) { - w[idx + j] = v.weights[j]; } } @@ -417,7 +386,6 @@ Array SurfaceTool::commit_to_arrays() { } break; case Mesh::ARRAY_INDEX: { - ERR_CONTINUE(index_array.size() == 0); Vector<int> array; @@ -426,7 +394,6 @@ Array SurfaceTool::commit_to_arrays() { int idx = 0; for (List<int>::Element *E = index_array.front(); E; E = E->next(), idx++) { - w[idx] = E->get(); } @@ -442,7 +409,6 @@ 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()) mesh = p_existing; @@ -467,7 +433,6 @@ Ref<ArrayMesh> SurfaceTool::commit(const Ref<ArrayMesh> &p_existing, uint32_t p_ } void SurfaceTool::index() { - if (index_array.size()) return; //already indexed @@ -475,7 +440,6 @@ void SurfaceTool::index() { List<Vertex> new_vertices; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) { - int *idxptr = indices.getptr(E->get()); int idx; if (!idxptr) { @@ -496,19 +460,16 @@ void SurfaceTool::index() { } void SurfaceTool::deindex() { - if (index_array.size() == 0) return; //nothing to deindex Vector<Vertex> varr; varr.resize(vertex_array.size()); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) { - varr.write[idx++] = E->get(); } vertex_array.clear(); for (List<int>::Element *E = index_array.front(); E; E = E->next()) { - ERR_FAIL_INDEX(E->get(), varr.size()); vertex_array.push_back(varr[E->get()]); } @@ -517,14 +478,12 @@ void SurfaceTool::deindex() { } void SurfaceTool::_create_list(const Ref<Mesh> &p_existing, int p_surface, List<Vertex> *r_vertex, List<int> *r_index, int &lformat) { - Array arr = p_existing->surface_get_arrays(p_surface); ERR_FAIL_COND(arr.size() != RS::ARRAY_MAX); _create_list_from_arrays(arr, r_vertex, r_index, lformat); } Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays) { - Vector<SurfaceTool::Vertex> ret; Vector<Vector3> varr = p_arrays[RS::ARRAY_VERTEX]; @@ -609,7 +568,6 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array } void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, List<int> *r_index, int &lformat) { - Vector<Vector3> varr = arr[RS::ARRAY_VERTEX]; Vector<Vector3> narr = arr[RS::ARRAY_NORMAL]; Vector<float> tarr = arr[RS::ARRAY_TANGENT]; @@ -693,7 +651,6 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li Vector<int> idx = arr[RS::ARRAY_INDEX]; int is = idx.size(); if (is) { - lformat |= RS::ARRAY_FORMAT_INDEX; const int *iarr = idx.ptr(); for (int i = 0; i < is; i++) { @@ -703,14 +660,12 @@ void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, Li } void SurfaceTool::create_from_triangle_arrays(const Array &p_arrays) { - clear(); primitive = Mesh::PRIMITIVE_TRIANGLES; _create_list_from_arrays(p_arrays, &vertex_array, &index_array, format); } void SurfaceTool::create_from(const Ref<Mesh> &p_existing, int p_surface) { - clear(); primitive = p_existing->surface_get_primitive_type(p_surface); _create_list(p_existing, p_surface, &vertex_array, &index_array, format); @@ -738,7 +693,6 @@ void SurfaceTool::create_from_blend_shape(const Ref<Mesh> &p_existing, int p_sur } void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const Transform &p_xform) { - if (vertex_array.size() == 0) { primitive = p_existing->surface_get_primitive_type(p_surface); format = 0; @@ -752,7 +706,6 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const int vfrom = vertex_array.size(); for (List<Vertex>::Element *E = nvertices.front(); E; E = E->next()) { - Vertex v = E->get(); v.vertex = p_xform.xform(v.vertex); if (nformat & RS::ARRAY_FORMAT_NORMAL) { @@ -767,7 +720,6 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const } for (List<int>::Element *E = nindices.front(); E; E = E->next()) { - int dst_index = E->get() + vfrom; index_array.push_back(dst_index); } @@ -785,7 +737,6 @@ struct TangentGenerationContextUserData { } // namespace int SurfaceTool::mikktGetNumFaces(const SMikkTSpaceContext *pContext) { - TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); if (triangle_data.indices.size() > 0) { @@ -795,11 +746,9 @@ int SurfaceTool::mikktGetNumFaces(const SMikkTSpaceContext *pContext) { } } int SurfaceTool::mikktGetNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace) { - return 3; //always 3 } void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert) { - TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); Vector3 v; if (triangle_data.indices.size() > 0) { @@ -817,7 +766,6 @@ void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext *pContext, float fvP } void SurfaceTool::mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert) { - TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); Vector3 v; if (triangle_data.indices.size() > 0) { @@ -834,7 +782,6 @@ void SurfaceTool::mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNor fvNormOut[2] = v.z; } void SurfaceTool::mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert) { - TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); Vector2 v; if (triangle_data.indices.size() > 0) { @@ -852,7 +799,6 @@ void SurfaceTool::mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvT void SurfaceTool::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, const int iVert) { - TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); Vertex *vtx = nullptr; if (triangle_data.indices.size() > 0) { @@ -871,7 +817,6 @@ void SurfaceTool::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, cons } void SurfaceTool::generate_tangents() { - ERR_FAIL_COND(!(format & Mesh::ARRAY_FORMAT_TEX_UV)); ERR_FAIL_COND(!(format & Mesh::ARRAY_FORMAT_NORMAL)); @@ -909,7 +854,6 @@ void SurfaceTool::generate_tangents() { } void SurfaceTool::generate_normals(bool p_flip) { - ERR_FAIL_COND(primitive != Mesh::PRIMITIVE_TRIANGLES); bool was_indexed = index_array.size(); @@ -925,7 +869,6 @@ void SurfaceTool::generate_normals(bool p_flip) { List<Vertex>::Element *B = vertex_array.front(); for (List<Vertex>::Element *E = B; E;) { - List<Vertex>::Element *v[3]; v[0] = E; v[1] = v[0]->next(); @@ -941,9 +884,7 @@ void SurfaceTool::generate_normals(bool p_flip) { normal = Plane(v[2]->get().vertex, v[1]->get().vertex, v[0]->get().vertex).normal; if (smooth) { - for (int i = 0; i < 3; i++) { - Vector3 *lv = vertex_hash.getptr(v[i]->get()); if (!lv) { vertex_hash.set(v[i]->get(), normal); @@ -952,20 +893,15 @@ void SurfaceTool::generate_normals(bool p_flip) { } } } else { - for (int i = 0; i < 3; i++) { - v[i]->get().normal = normal; } } count += 3; if (smooth_groups.has(count) || !E) { - if (vertex_hash.size()) { - while (B != E) { - Vector3 *lv = vertex_hash.getptr(B->get()); if (lv) { B->get().normal = lv->normalized(); @@ -994,12 +930,10 @@ void SurfaceTool::generate_normals(bool p_flip) { } void SurfaceTool::set_material(const Ref<Material> &p_material) { - material = p_material; } void SurfaceTool::clear() { - begun = false; primitive = Mesh::PRIMITIVE_LINES; format = 0; @@ -1012,7 +946,6 @@ void SurfaceTool::clear() { } void SurfaceTool::_bind_methods() { - ClassDB::bind_method(D_METHOD("begin", "primitive"), &SurfaceTool::begin); ClassDB::bind_method(D_METHOD("add_vertex", "vertex"), &SurfaceTool::add_vertex); @@ -1046,7 +979,6 @@ void SurfaceTool::_bind_methods() { } SurfaceTool::SurfaceTool() { - first = false; begun = false; primitive = Mesh::PRIMITIVE_LINES; diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h index 89034f656d..d7b255e695 100644 --- a/scene/resources/surface_tool.h +++ b/scene/resources/surface_tool.h @@ -36,12 +36,10 @@ #include "thirdparty/misc/mikktspace.h" class SurfaceTool : public Reference { - GDCLASS(SurfaceTool, Reference); public: struct Vertex { - Vector3 vertex; Color color; Vector3 normal; // normal, binormal, tangent diff --git a/scene/resources/text_file.cpp b/scene/resources/text_file.cpp index e291dcb67e..e3bd5ce0ae 100644 --- a/scene/resources/text_file.cpp +++ b/scene/resources/text_file.cpp @@ -49,7 +49,6 @@ void TextFile::reload_from_file() { } Error TextFile::load_text(const String &p_path) { - Vector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); diff --git a/scene/resources/text_file.h b/scene/resources/text_file.h index 666c088d04..356b070ea0 100644 --- a/scene/resources/text_file.h +++ b/scene/resources/text_file.h @@ -35,7 +35,6 @@ #include "core/io/resource_saver.h" class TextFile : public Resource { - GDCLASS(TextFile, Resource); private: diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index b212bba826..78b8e4d9ff 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -39,7 +39,6 @@ #include "servers/camera/camera_feed.h" Size2 Texture2D::get_size() const { - return Size2(get_width(), get_height()); } @@ -48,28 +47,24 @@ bool Texture2D::is_pixel_opaque(int p_x, int p_y) const { } void Texture2D::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 { - 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, get_size()), get_rid(), false, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void Texture2D::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 { - 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, get_rid(), p_tile, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void Texture2D::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 { - 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, get_rid(), p_src_rect, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, p_clip_uv, p_texture_filter, p_texture_repeat); } bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { - r_rect = p_rect; r_src_rect = p_src_rect; @@ -77,7 +72,6 @@ bool Texture2D::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Re } void Texture2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_width"), &Texture2D::get_width); ClassDB::bind_method(D_METHOD("get_height"), &Texture2D::get_height); ClassDB::bind_method(D_METHOD("get_size"), &Texture2D::get_size); @@ -96,7 +90,6 @@ Texture2D::Texture2D() { ///////////////////// void ImageTexture::reload_from_file() { - String path = ResourceLoader::path_remap(get_path()); if (!path.is_resource_file()) return; @@ -114,7 +107,6 @@ void ImageTexture::reload_from_file() { } bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "image") create_from_image(p_value); else if (p_name == "size") { @@ -129,7 +121,6 @@ bool ImageTexture::_set(const StringName &p_name, const Variant &p_value) { } bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "image") r_ret = get_data(); else if (p_name == "size") @@ -141,13 +132,11 @@ bool ImageTexture::_get(const StringName &p_name, Variant &r_ret) const { } void ImageTexture::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)); p_list->push_back(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "")); } void ImageTexture::_reload_hook(const RID &p_hook) { - String path = get_path(); if (!path.is_resource_file()) return; @@ -166,7 +155,6 @@ void ImageTexture::_reload_hook(const RID &p_hook) { } void ImageTexture::create_from_image(const Ref<Image> &p_image) { - ERR_FAIL_COND(p_image.is_null()); w = p_image->get_width(); h = p_image->get_height(); @@ -186,12 +174,10 @@ void ImageTexture::create_from_image(const Ref<Image> &p_image) { } Image::Format ImageTexture::get_format() const { - return format; } void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { - ERR_FAIL_COND(p_image.is_null()); ERR_FAIL_COND(texture.is_null()); ERR_FAIL_COND(p_image->get_width() != w || p_image->get_height() != h); @@ -212,12 +198,10 @@ void ImageTexture::update(const Ref<Image> &p_image, bool p_immediate) { } void ImageTexture::_resource_path_changed() { - String path = get_path(); } Ref<Image> ImageTexture::get_data() const { - if (image_stored) { return RenderingServer::get_singleton()->texture_2d_get(texture); } else { @@ -226,17 +210,14 @@ Ref<Image> ImageTexture::get_data() const { } int ImageTexture::get_width() const { - return w; } int ImageTexture::get_height() const { - return h; } RID ImageTexture::get_rid() const { - if (texture.is_null()) { //we are in trouble, create something temporary texture = RenderingServer::get_singleton()->texture_2d_placeholder_create(); @@ -245,12 +226,10 @@ RID ImageTexture::get_rid() const { } bool ImageTexture::has_alpha() const { - return (format == Image::FORMAT_LA8 || format == Image::FORMAT_RGBA8); } 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) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -258,7 +237,6 @@ void ImageTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m 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) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -266,7 +244,6 @@ void ImageTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile 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) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -275,7 +252,6 @@ void ImageTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons } bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { - if (!alpha_cache.is_valid()) { Ref<Image> img = get_data(); if (img.is_valid()) { @@ -290,7 +266,6 @@ bool ImageTexture::is_pixel_opaque(int p_x, int p_y) const { } if (alpha_cache.is_valid()) { - int aw = int(alpha_cache->get_size().width); int ah = int(alpha_cache->get_size().height); if (aw == 0 || ah == 0) { @@ -310,7 +285,6 @@ 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) w = s.x; @@ -320,7 +294,6 @@ void ImageTexture::set_size_override(const Size2 &p_size) { } void ImageTexture::set_path(const String &p_path, bool p_take_over) { - if (texture.is_valid()) { RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -329,7 +302,6 @@ void ImageTexture::set_path(const String &p_path, bool p_take_over) { } void ImageTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_from_image", "image"), &ImageTexture::create_from_image); ClassDB::bind_method(D_METHOD("get_format"), &ImageTexture::get_format); @@ -339,7 +311,6 @@ void ImageTexture::_bind_methods() { } ImageTexture::ImageTexture() { - w = h = 0; image_stored = false; mipmaps = false; @@ -347,7 +318,6 @@ ImageTexture::ImageTexture() { } ImageTexture::~ImageTexture() { - if (texture.is_valid()) { RenderingServer::get_singleton()->free(texture); } @@ -356,7 +326,6 @@ ImageTexture::~ImageTexture() { ////////////////////////////////////////// Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit) { - uint32_t data_format = f->get_32(); uint32_t w = f->get_16(); uint32_t h = f->get_16(); @@ -376,7 +345,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit bool first = true; for (uint32_t i = 0; i < mipmaps + 1; i++) { - uint32_t size = f->get_32(); if (p_size_limit > 0 && i < (mipmaps - 1) && (sw > p_size_limit || sh > p_size_limit)) { @@ -444,7 +412,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit int ofs = 0; for (int i = 0; i < mipmap_images.size(); i++) { - Vector<uint8_t> id = mipmap_images[i]->get_data(); int len = id.size(); const uint8_t *r = id.ptr(); @@ -458,7 +425,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit } } else if (data_format == DATA_FORMAT_IMAGE) { - int size = Image::get_image_data_size(w, h, format, mipmaps ? true : false); for (uint32_t i = 0; i < mipmaps + 1; i++) { @@ -493,7 +459,6 @@ Ref<Image> StreamTexture2D::load_image_from_file(FileAccess *f, int p_size_limit } void StreamTexture2D::set_path(const String &p_path, bool p_take_over) { - if (texture.is_valid()) { RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -502,7 +467,6 @@ void StreamTexture2D::set_path(const String &p_path, bool p_take_over) { } void StreamTexture2D::_requested_3d(void *p_ud) { - StreamTexture2D *st = (StreamTexture2D *)p_ud; Ref<StreamTexture2D> stex(st); ERR_FAIL_COND(!request_3d_callback); @@ -510,7 +474,6 @@ void StreamTexture2D::_requested_3d(void *p_ud) { } void StreamTexture2D::_requested_roughness(void *p_ud, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_roughness_channel) { - StreamTexture2D *st = (StreamTexture2D *)p_ud; Ref<StreamTexture2D> stex(st); ERR_FAIL_COND(!request_roughness_callback); @@ -518,7 +481,6 @@ void StreamTexture2D::_requested_roughness(void *p_ud, const String &p_normal_pa } void StreamTexture2D::_requested_normal(void *p_ud) { - StreamTexture2D *st = (StreamTexture2D *)p_ud; Ref<StreamTexture2D> stex(st); ERR_FAIL_COND(!request_normal_callback); @@ -530,12 +492,10 @@ StreamTexture2D::TextureFormatRoughnessRequestCallback StreamTexture2D::request_ StreamTexture2D::TextureFormatRequestCallback StreamTexture2D::request_normal_callback = nullptr; Image::Format StreamTexture2D::get_format() const { - return format; } Error StreamTexture2D::_load_data(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, bool &r_request_3d, bool &r_request_normal, bool &r_request_roughness, int &mipmap_limit, int p_size_limit) { - alpha_cache.unref(); ERR_FAIL_COND_V(image.is_null(), ERR_INVALID_PARAMETER); @@ -596,7 +556,6 @@ Error StreamTexture2D::_load_data(const String &p_path, int &tw, int &th, int &t } Error StreamTexture2D::load(const String &p_path) { - int lw, lh, lwc, lhc; Ref<Image> image; image.instance(); @@ -662,20 +621,16 @@ Error StreamTexture2D::load(const String &p_path) { return OK; } String StreamTexture2D::get_load_path() const { - return path_to_file; } int StreamTexture2D::get_width() const { - return w; } int StreamTexture2D::get_height() const { - return h; } RID StreamTexture2D::get_rid() const { - if (!texture.is_valid()) { texture = RS::get_singleton()->texture_2d_placeholder_create(); } @@ -683,7 +638,6 @@ 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) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -691,7 +645,6 @@ void StreamTexture2D::draw(RID p_canvas_item, const Point2 &p_pos, const Color & 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) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -699,7 +652,6 @@ void StreamTexture2D::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_t 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) return; RID normal_rid = p_normal_map.is_valid() ? p_normal_map->get_rid() : RID(); @@ -708,12 +660,10 @@ void StreamTexture2D::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, c } bool StreamTexture2D::has_alpha() const { - return false; } Ref<Image> StreamTexture2D::get_data() const { - if (texture.is_valid()) { return RS::get_singleton()->texture_2d_get(texture); } else { @@ -722,7 +672,6 @@ Ref<Image> StreamTexture2D::get_data() const { } bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const { - if (!alpha_cache.is_valid()) { Ref<Image> img = get_data(); if (img.is_valid()) { @@ -738,7 +687,6 @@ bool StreamTexture2D::is_pixel_opaque(int p_x, int p_y) const { } if (alpha_cache.is_valid()) { - int aw = int(alpha_cache->get_size().width); int ah = int(alpha_cache->get_size().height); if (aw == 0 || ah == 0) { @@ -758,7 +706,6 @@ 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()) return; @@ -775,7 +722,6 @@ void StreamTexture2D::_validate_property(PropertyInfo &property) const { } void StreamTexture2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("load", "path"), &StreamTexture2D::load); ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTexture2D::get_load_path); @@ -783,21 +729,18 @@ void StreamTexture2D::_bind_methods() { } StreamTexture2D::StreamTexture2D() { - format = Image::FORMAT_MAX; w = 0; h = 0; } StreamTexture2D::~StreamTexture2D() { - if (texture.is_valid()) { RS::get_singleton()->free(texture); } } RES ResourceFormatLoaderStreamTexture2D::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) { - Ref<StreamTexture2D> st; st.instance(); Error err = st->load(p_path); @@ -810,14 +753,12 @@ RES ResourceFormatLoaderStreamTexture2D::load(const String &p_path, const String } void ResourceFormatLoaderStreamTexture2D::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("stex"); } bool ResourceFormatLoaderStreamTexture2D::handles_type(const String &p_type) const { return p_type == "StreamTexture2D"; } String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "stex") return "StreamTexture2D"; return ""; @@ -826,7 +767,6 @@ String ResourceFormatLoaderStreamTexture2D::get_resource_type(const String &p_pa ////////////////////////////////////////// int AtlasTexture::get_width() const { - if (region.size.width == 0) { if (atlas.is_valid()) return atlas->get_width(); @@ -836,7 +776,6 @@ int AtlasTexture::get_width() const { } } int AtlasTexture::get_height() const { - if (region.size.height == 0) { if (atlas.is_valid()) return atlas->get_height(); @@ -846,7 +785,6 @@ int AtlasTexture::get_height() const { } } RID AtlasTexture::get_rid() const { - if (atlas.is_valid()) return atlas->get_rid(); @@ -854,7 +792,6 @@ RID AtlasTexture::get_rid() const { } bool AtlasTexture::has_alpha() const { - if (atlas.is_valid()) return atlas->has_alpha(); @@ -862,7 +799,6 @@ bool AtlasTexture::has_alpha() const { } void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) { - ERR_FAIL_COND(p_atlas == this); if (atlas == p_atlas) return; @@ -871,12 +807,10 @@ void AtlasTexture::set_atlas(const Ref<Texture2D> &p_atlas) { _change_notify("atlas"); } Ref<Texture2D> AtlasTexture::get_atlas() const { - return atlas; } void AtlasTexture::set_region(const Rect2 &p_region) { - if (region == p_region) return; region = p_region; @@ -885,12 +819,10 @@ void AtlasTexture::set_region(const Rect2 &p_region) { } Rect2 AtlasTexture::get_region() const { - return region; } void AtlasTexture::set_margin(const Rect2 &p_margin) { - if (margin == p_margin) return; margin = p_margin; @@ -899,24 +831,20 @@ void AtlasTexture::set_margin(const Rect2 &p_margin) { } Rect2 AtlasTexture::get_margin() const { - return margin; } void AtlasTexture::set_filter_clip(const bool p_enable) { - filter_clip = p_enable; emit_changed(); _change_notify("filter_clip"); } bool AtlasTexture::has_filter_clip() const { - return filter_clip; } void AtlasTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_atlas", "atlas"), &AtlasTexture::set_atlas); ClassDB::bind_method(D_METHOD("get_atlas"), &AtlasTexture::get_atlas); @@ -936,7 +864,6 @@ 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()) return; @@ -956,7 +883,6 @@ 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()) return; @@ -978,7 +904,6 @@ void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile RS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, dr, atlas->get_rid(), rc, p_modulate, p_transpose, normal_rid, specular_rid, p_specular_color_shininess, filter_clip, p_texture_filter, p_texture_repeat); } 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()) return; @@ -993,7 +918,6 @@ 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()) return false; @@ -1029,7 +953,6 @@ 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()) return true; @@ -1077,7 +1000,6 @@ void MeshTexture::set_image_size(const Size2 &p_size) { } Size2 MeshTexture::get_image_size() const { - return size; } @@ -1090,7 +1012,6 @@ Ref<Texture2D> MeshTexture::get_base_texture() const { } void MeshTexture::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 (mesh.is_null() || base_texture.is_null()) { return; } @@ -1128,7 +1049,6 @@ void MeshTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, RenderingServer::get_singleton()->canvas_item_add_mesh(p_canvas_item, mesh->get_rid(), xform, p_modulate, base_texture->get_rid(), normal_rid, specular_rid, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } void MeshTexture::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 (mesh.is_null() || base_texture.is_null()) { return; } @@ -1180,20 +1100,16 @@ MeshTexture::MeshTexture() { ////////////////////////////////////////// int LargeTexture::get_width() const { - return size.width; } int LargeTexture::get_height() const { - return size.height; } RID LargeTexture::get_rid() const { - return RID(); } bool LargeTexture::has_alpha() const { - for (int i = 0; i < pieces.size(); i++) { if (pieces[i].texture->has_alpha()) return true; @@ -1203,7 +1119,6 @@ bool LargeTexture::has_alpha() const { } int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND_V(p_texture.is_null(), -1); Piece p; p.offset = p_offset; @@ -1214,13 +1129,11 @@ int LargeTexture::add_piece(const Point2 &p_offset, const Ref<Texture2D> &p_text } void LargeTexture::set_piece_offset(int p_idx, const Point2 &p_offset) { - ERR_FAIL_INDEX(p_idx, pieces.size()); pieces.write[p_idx].offset = p_offset; }; void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND(p_texture == this); ERR_FAIL_COND(p_texture.is_null()); ERR_FAIL_INDEX(p_idx, pieces.size()); @@ -1228,17 +1141,14 @@ void LargeTexture::set_piece_texture(int p_idx, const Ref<Texture2D> &p_texture) }; void LargeTexture::set_size(const Size2 &p_size) { - size = p_size; } void LargeTexture::clear() { - pieces.clear(); size = Size2i(); } Array LargeTexture::_get_data() const { - Array arr; for (int i = 0; i < pieces.size(); i++) { arr.push_back(pieces[i].offset); @@ -1248,7 +1158,6 @@ Array LargeTexture::_get_data() const { return arr; } void LargeTexture::_set_data(const Array &p_array) { - ERR_FAIL_COND(p_array.size() < 1); ERR_FAIL_COND(!(p_array.size() & 1)); clear(); @@ -1259,24 +1168,19 @@ void LargeTexture::_set_data(const Array &p_array) { } int LargeTexture::get_piece_count() const { - return pieces.size(); } Vector2 LargeTexture::get_piece_offset(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, pieces.size(), Vector2()); return pieces[p_idx].offset; } Ref<Texture2D> LargeTexture::get_piece_texture(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, pieces.size(), Ref<Texture2D>()); return pieces[p_idx].texture; } Ref<Image> LargeTexture::to_image() const { - Ref<Image> img = memnew(Image(this->get_width(), this->get_height(), false, Image::FORMAT_RGBA8)); for (int i = 0; i < pieces.size(); i++) { - Ref<Image> src_img = pieces[i].texture->get_data(); img->blit_rect(src_img, Rect2(0, 0, src_img->get_width(), src_img->get_height()), pieces[i].offset); } @@ -1285,7 +1189,6 @@ Ref<Image> LargeTexture::to_image() const { } void LargeTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_piece", "ofs", "texture"), &LargeTexture::add_piece); ClassDB::bind_method(D_METHOD("set_piece_offset", "idx", "ofs"), &LargeTexture::set_piece_offset); ClassDB::bind_method(D_METHOD("set_piece_texture", "idx", "texture"), &LargeTexture::set_piece_texture); @@ -1303,16 +1206,13 @@ void LargeTexture::_bind_methods() { } void LargeTexture::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 { - for (int i = 0; i < pieces.size(); i++) { - // TODO pieces[i].texture->draw(p_canvas_item, pieces[i].offset + p_pos, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } } 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) return; @@ -1320,13 +1220,11 @@ void LargeTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile Size2 scale = p_rect.size / size; for (int i = 0; i < pieces.size(); i++) { - // TODO pieces[i].texture->draw_rect(p_canvas_item, Rect2(pieces[i].offset * scale + p_rect.position, pieces[i].texture->get_size() * scale), false, p_modulate, p_transpose, p_normal_map, p_specular_map, p_specular_color_shininess, p_texture_filter, p_texture_repeat); } } 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) return; @@ -1334,7 +1232,6 @@ void LargeTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons 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)) @@ -1349,9 +1246,7 @@ 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()) continue; @@ -1371,7 +1266,6 @@ LargeTexture::LargeTexture() { /////////////////// void CurveTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_width", "width"), &CurveTexture::set_width); ClassDB::bind_method(D_METHOD("set_curve", "curve"), &CurveTexture::set_curve); @@ -1384,14 +1278,12 @@ void CurveTexture::_bind_methods() { } void CurveTexture::set_width(int p_width) { - ERR_FAIL_COND(p_width < 32 || p_width > 4096); _width = p_width; _update(); } int CurveTexture::get_width() const { - return _width; } @@ -1421,7 +1313,6 @@ void CurveTexture::set_curve(Ref<Curve> p_curve) { } void CurveTexture::_update() { - Vector<uint8_t> data; data.resize(_width * sizeof(float)); @@ -1457,12 +1348,10 @@ void CurveTexture::_update() { } Ref<Curve> CurveTexture::get_curve() const { - return _curve; } RID CurveTexture::get_rid() const { - if (!_texture.is_valid()) { _texture = RS::get_singleton()->texture_2d_placeholder_create(); } @@ -1499,7 +1388,6 @@ GradientTexture::~GradientTexture() { } void GradientTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_gradient", "gradient"), &GradientTexture::set_gradient); ClassDB::bind_method(D_METHOD("get_gradient"), &GradientTexture::get_gradient); @@ -1530,7 +1418,6 @@ Ref<Gradient> GradientTexture::get_gradient() const { } void GradientTexture::_queue_update() { - if (update_pending) return; @@ -1539,7 +1426,6 @@ void GradientTexture::_queue_update() { } void GradientTexture::_update() { - update_pending = false; if (gradient.is_null()) @@ -1552,7 +1438,6 @@ void GradientTexture::_update() { Gradient &g = **gradient; for (int i = 0; i < width; i++) { - float ofs = float(i) / (width - 1); Color color = g.get_color_at_offset(ofs); @@ -1576,12 +1461,10 @@ void GradientTexture::_update() { } void GradientTexture::set_width(int p_width) { - width = p_width; _queue_update(); } int GradientTexture::get_width() const { - return width; } @@ -1595,7 +1478,6 @@ Ref<Image> GradientTexture::get_data() const { ////////////////////////////////////// void ProxyTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base", "base"), &ProxyTexture::set_base); ClassDB::bind_method(D_METHOD("get_base"), &ProxyTexture::get_base); @@ -1603,7 +1485,6 @@ void ProxyTexture::_bind_methods() { } void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND(p_texture == this); base = p_texture; @@ -1621,24 +1502,20 @@ void ProxyTexture::set_base(const Ref<Texture2D> &p_texture) { } Ref<Texture2D> ProxyTexture::get_base() const { - return base; } int ProxyTexture::get_width() const { - if (base.is_valid()) return base->get_width(); return 1; } int ProxyTexture::get_height() const { - if (base.is_valid()) return base->get_height(); return 1; } RID ProxyTexture::get_rid() const { - if (proxy.is_null()) { proxy_ph = RS::get_singleton()->texture_2d_placeholder_create(); proxy = RS::get_singleton()->texture_proxy_create(proxy_ph); @@ -1647,19 +1524,16 @@ RID ProxyTexture::get_rid() const { } bool ProxyTexture::has_alpha() const { - if (base.is_valid()) return base->has_alpha(); return false; } ProxyTexture::ProxyTexture() { - //proxy = RS::get_singleton()->texture_create(); } ProxyTexture::~ProxyTexture() { - if (proxy_ph.is_valid()) { RS::get_singleton()->free(proxy_ph); } @@ -1670,7 +1544,6 @@ ProxyTexture::~ProxyTexture() { ////////////////////////////////////////////// void AnimatedTexture::_update_proxy() { - RWLockRead r(rw_lock); float delta; @@ -1758,7 +1631,6 @@ bool AnimatedTexture::get_oneshot() const { } void AnimatedTexture::set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND(p_texture == this); ERR_FAIL_INDEX(p_frame, MAX_FRAMES); @@ -1821,7 +1693,6 @@ RID AnimatedTexture::get_rid() const { } bool AnimatedTexture::has_alpha() const { - RWLockRead r(rw_lock); if (!frames[current_frame].texture.is_valid()) { @@ -1832,7 +1703,6 @@ bool AnimatedTexture::has_alpha() const { } Ref<Image> AnimatedTexture::get_data() const { - RWLockRead r(rw_lock); if (!frames[current_frame].texture.is_valid()) { @@ -1843,7 +1713,6 @@ Ref<Image> AnimatedTexture::get_data() const { } bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const { - RWLockRead r(rw_lock); if (frames[current_frame].texture.is_valid()) { @@ -1853,7 +1722,6 @@ bool AnimatedTexture::is_pixel_opaque(int p_x, int p_y) const { } void AnimatedTexture::_validate_property(PropertyInfo &property) const { - String prop = property.name; if (prop.begins_with("frame_")) { int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int(); @@ -1931,7 +1799,6 @@ AnimatedTexture::~AnimatedTexture() { /////////////////////////////// void TextureLayered::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_format"), &TextureLayered::get_format); ClassDB::bind_method(D_METHOD("get_layered_type"), &TextureLayered::get_layered_type); ClassDB::bind_method(D_METHOD("get_width"), &TextureLayered::get_width); @@ -1990,7 +1857,6 @@ Array ImageTextureLayered::_get_images() const { } Error ImageTextureLayered::create_from_images(Vector<Ref<Image>> p_images) { - int new_layers = p_images.size(); ERR_FAIL_COND_V(new_layers == 0, ERR_INVALID_PARAMETER); if (layered_type == LAYERED_TYPE_CUBEMAP) { @@ -2065,7 +1931,6 @@ void ImageTextureLayered::set_path(const String &p_path, bool p_take_over) { } void ImageTextureLayered::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_from_images", "images"), &ImageTextureLayered::_create_from_images); ClassDB::bind_method(D_METHOD("update_layer", "image", "layer"), &ImageTextureLayered::update_layer); @@ -2092,7 +1957,6 @@ ImageTextureLayered::~ImageTextureLayered() { /////////////////////////////////////////// void StreamTextureLayered::set_path(const String &p_path, bool p_take_over) { - if (texture.is_valid()) { RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -2101,12 +1965,10 @@ void StreamTextureLayered::set_path(const String &p_path, bool p_take_over) { } Image::Format StreamTextureLayered::get_format() const { - return format; } Error StreamTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> &images, int &mipmap_limit, int p_size_limit) { - ERR_FAIL_COND_V(images.size() != 0, ERR_INVALID_PARAMETER); FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); @@ -2151,7 +2013,6 @@ Error StreamTextureLayered::_load_data(const String &p_path, Vector<Ref<Image>> } Error StreamTextureLayered::load(const String &p_path) { - Vector<Ref<Image>> images; int mipmap_limit; @@ -2185,20 +2046,16 @@ Error StreamTextureLayered::load(const String &p_path) { return OK; } String StreamTextureLayered::get_load_path() const { - return path_to_file; } int StreamTextureLayered::get_width() const { - return w; } int StreamTextureLayered::get_height() const { - return h; } int StreamTextureLayered::get_layers() const { - return layers; } bool StreamTextureLayered::has_mipmaps() const { @@ -2206,12 +2063,10 @@ bool StreamTextureLayered::has_mipmaps() const { } TextureLayered::LayeredType StreamTextureLayered::get_layered_type() const { - return layered_type; } RID StreamTextureLayered::get_rid() const { - if (!texture.is_valid()) { texture = RS::get_singleton()->texture_2d_layered_placeholder_create(RS::TextureLayeredType(layered_type)); } @@ -2219,7 +2074,6 @@ RID StreamTextureLayered::get_rid() const { } Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const { - if (texture.is_valid()) { return RS::get_singleton()->texture_2d_layer_get(texture, p_layer); } else { @@ -2228,7 +2082,6 @@ Ref<Image> StreamTextureLayered::get_layer_data(int p_layer) const { } void StreamTextureLayered::reload_from_file() { - String path = get_path(); if (!path.is_resource_file()) return; @@ -2245,7 +2098,6 @@ void StreamTextureLayered::_validate_property(PropertyInfo &property) const { } void StreamTextureLayered::_bind_methods() { - ClassDB::bind_method(D_METHOD("load", "path"), &StreamTextureLayered::load); ClassDB::bind_method(D_METHOD("get_load_path"), &StreamTextureLayered::get_load_path); @@ -2253,7 +2105,6 @@ void StreamTextureLayered::_bind_methods() { } StreamTextureLayered::StreamTextureLayered(LayeredType p_type) { - layered_type = p_type; format = Image::FORMAT_MAX; w = 0; @@ -2263,7 +2114,6 @@ StreamTextureLayered::StreamTextureLayered(LayeredType p_type) { } StreamTextureLayered::~StreamTextureLayered() { - if (texture.is_valid()) { RS::get_singleton()->free(texture); } @@ -2272,7 +2122,6 @@ StreamTextureLayered::~StreamTextureLayered() { ///////////////////////////////////////////////// RES ResourceFormatLoaderStreamTextureLayered::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) { - Ref<StreamTextureLayered> st; if (p_path.get_extension().to_lower() == "stexarray") { Ref<StreamTexture2DArray> s; @@ -2302,7 +2151,6 @@ RES ResourceFormatLoaderStreamTextureLayered::load(const String &p_path, const S } void ResourceFormatLoaderStreamTextureLayered::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("stexarray"); p_extensions->push_back("scube"); p_extensions->push_back("scubearray"); @@ -2311,7 +2159,6 @@ bool ResourceFormatLoaderStreamTextureLayered::handles_type(const String &p_type return p_type == "StreamTexture2DArray" || p_type == "StreamCubemap" || p_type == "StreamCubemapArray"; } String ResourceFormatLoaderStreamTextureLayered::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "stexarray") return "StreamTexture2DArray"; if (p_path.get_extension().to_lower() == "scube") diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 5d4131ec4c..005f899512 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -51,7 +51,6 @@ public: }; class Texture2D : public Texture { - GDCLASS(Texture2D, Texture); OBJ_SAVE_TYPE(Texture2D); // Saves derived classes with common type so they can be interchanged. @@ -81,7 +80,6 @@ public: class BitMap; class ImageTexture : public Texture2D { - GDCLASS(ImageTexture, Texture2D); RES_BASE_EXTENSION("tex"); @@ -133,7 +131,6 @@ public: }; class StreamTexture2D : public Texture2D { - GDCLASS(StreamTexture2D, Texture2D); public: @@ -220,7 +217,6 @@ public: }; class AtlasTexture : public Texture2D { - GDCLASS(AtlasTexture, Texture2D); RES_BASE_EXTENSION("atlastex"); @@ -264,7 +260,6 @@ public: class Mesh; class MeshTexture : public Texture2D { - GDCLASS(MeshTexture, Texture2D); RES_BASE_EXTENSION("meshtex"); @@ -302,13 +297,11 @@ public: }; class LargeTexture : public Texture2D { - GDCLASS(LargeTexture, Texture2D); RES_BASE_EXTENSION("largetex"); protected: struct Piece { - Point2 offset; Ref<Texture2D> texture; }; @@ -373,7 +366,6 @@ public: VARIANT_ENUM_CAST(TextureLayered::LayeredType) class ImageTextureLayered : public TextureLayered { - GDCLASS(ImageTextureLayered, TextureLayered); LayeredType layered_type; @@ -413,7 +405,6 @@ public: }; class Texture2DArray : public ImageTextureLayered { - GDCLASS(Texture2DArray, ImageTextureLayered) public: Texture2DArray() : @@ -421,7 +412,6 @@ public: }; class Cubemap : public ImageTextureLayered { - GDCLASS(Cubemap, ImageTextureLayered); public: @@ -430,7 +420,6 @@ public: }; class CubemapArray : public ImageTextureLayered { - GDCLASS(CubemapArray, ImageTextureLayered); public: @@ -439,7 +428,6 @@ public: }; class StreamTextureLayered : public TextureLayered { - GDCLASS(StreamTextureLayered, TextureLayered); public: @@ -498,7 +486,6 @@ public: }; class StreamTexture2DArray : public StreamTextureLayered { - GDCLASS(StreamTexture2DArray, StreamTextureLayered) public: StreamTexture2DArray() : @@ -506,7 +493,6 @@ public: }; class StreamCubemap : public StreamTextureLayered { - GDCLASS(StreamCubemap, StreamTextureLayered); public: @@ -515,7 +501,6 @@ public: }; class StreamCubemapArray : public StreamTextureLayered { - GDCLASS(StreamCubemapArray, StreamTextureLayered); public: @@ -532,7 +517,6 @@ public: }; class CurveTexture : public Texture2D { - GDCLASS(CurveTexture, Texture2D); RES_BASE_EXTENSION("curvetex") @@ -582,7 +566,6 @@ class GradientTexture : public Texture2D { public: struct Point { - float offset; Color color; bool operator<(const Point &p_ponit) const { @@ -659,7 +642,6 @@ private: RID proxy; struct Frame { - Ref<Texture2D> texture; float delay_sec; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 325ada69ea..7a28927583 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -33,12 +33,10 @@ #include "core/print_string.h" void Theme::_emit_theme_changed() { - emit_changed(); } Vector<String> Theme::_get_icon_list(const String &p_type) const { - Vector<String> ilret; List<StringName> il; @@ -54,7 +52,6 @@ Vector<String> Theme::_get_icon_list(const String &p_type) const { } Vector<String> Theme::_get_stylebox_list(const String &p_type) const { - Vector<String> ilret; List<StringName> il; @@ -70,7 +67,6 @@ Vector<String> Theme::_get_stylebox_list(const String &p_type) const { } Vector<String> Theme::_get_stylebox_types() const { - Vector<String> ilret; List<StringName> il; @@ -86,7 +82,6 @@ Vector<String> Theme::_get_stylebox_types() const { } Vector<String> Theme::_get_font_list(const String &p_type) const { - Vector<String> ilret; List<StringName> il; @@ -102,7 +97,6 @@ Vector<String> Theme::_get_font_list(const String &p_type) const { } Vector<String> Theme::_get_color_list(const String &p_type) const { - Vector<String> ilret; List<StringName> il; @@ -118,7 +112,6 @@ Vector<String> Theme::_get_color_list(const String &p_type) const { } Vector<String> Theme::_get_constant_list(const String &p_type) const { - Vector<String> ilret; List<StringName> il; @@ -134,7 +127,6 @@ Vector<String> Theme::_get_constant_list(const String &p_type) const { } Vector<String> Theme::_get_type_list(const String &p_type) const { - Vector<String> ilret; List<StringName> il; @@ -150,29 +142,22 @@ Vector<String> Theme::_get_type_list(const String &p_type) const { } bool Theme::_set(const StringName &p_name, const Variant &p_value) { - String sname = p_name; if (sname.find("/") != -1) { - String type = sname.get_slicec('/', 1); String node_type = sname.get_slicec('/', 0); String name = sname.get_slicec('/', 2); if (type == "icons") { - set_icon(name, node_type, p_value); } else if (type == "styles") { - set_stylebox(name, node_type, p_value); } else if (type == "fonts") { - set_font(name, node_type, p_value); } else if (type == "colors") { - set_color(name, node_type, p_value); } else if (type == "constants") { - set_constant(name, node_type, p_value); } else return false; @@ -184,38 +169,31 @@ bool Theme::_set(const StringName &p_name, const Variant &p_value) { } bool Theme::_get(const StringName &p_name, Variant &r_ret) const { - String sname = p_name; if (sname.find("/") != -1) { - String type = sname.get_slicec('/', 1); String node_type = sname.get_slicec('/', 0); String name = sname.get_slicec('/', 2); if (type == "icons") { - if (!has_icon(name, node_type)) r_ret = Ref<Texture2D>(); else r_ret = get_icon(name, node_type); } else if (type == "styles") { - if (!has_stylebox(name, node_type)) r_ret = Ref<StyleBox>(); else r_ret = get_stylebox(name, node_type); } else if (type == "fonts") { - if (!has_font(name, node_type)) r_ret = Ref<Font>(); 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 return false; @@ -227,17 +205,14 @@ bool Theme::_get(const StringName &p_name, Variant &r_ret) const { } void Theme::_get_property_list(List<PropertyInfo> *p_list) const { - List<PropertyInfo> list; const StringName *key = nullptr; while ((key = icon_map.next(key))) { - const StringName *key2 = nullptr; while ((key2 = icon_map[*key].next(key2))) { - list.push_back(PropertyInfo(Variant::OBJECT, String() + *key + "/icons/" + *key2, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL)); } } @@ -245,11 +220,9 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { key = nullptr; while ((key = style_map.next(key))) { - const StringName *key2 = nullptr; while ((key2 = style_map[*key].next(key2))) { - list.push_back(PropertyInfo(Variant::OBJECT, String() + *key + "/styles/" + *key2, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL)); } } @@ -257,11 +230,9 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { key = nullptr; while ((key = font_map.next(key))) { - const StringName *key2 = nullptr; while ((key2 = font_map[*key].next(key2))) { - list.push_back(PropertyInfo(Variant::OBJECT, String() + *key + "/fonts/" + *key2, PROPERTY_HINT_RESOURCE_TYPE, "Font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_STORE_IF_NULL)); } } @@ -269,11 +240,9 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { key = nullptr; while ((key = color_map.next(key))) { - const StringName *key2 = nullptr; while ((key2 = color_map[*key].next(key2))) { - list.push_back(PropertyInfo(Variant::COLOR, String() + *key + "/colors/" + *key2)); } } @@ -281,11 +250,9 @@ void Theme::_get_property_list(List<PropertyInfo> *p_list) const { key = nullptr; while ((key = constant_map.next(key))) { - const StringName *key2 = nullptr; while ((key2 = constant_map[*key].next(key2))) { - list.push_back(PropertyInfo(Variant::INT, String() + *key + "/constants/" + *key2)); } } @@ -297,7 +264,6 @@ 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) return; @@ -316,7 +282,6 @@ void Theme::set_default_theme_font(const Ref<Font> &p_default_font) { } Ref<Font> Theme::get_default_theme_font() const { - return default_theme_font; } @@ -327,40 +292,32 @@ Ref<StyleBox> Theme::default_style; Ref<Font> Theme::default_font; Ref<Theme> Theme::get_default() { - return default_theme; } void Theme::set_default(const Ref<Theme> &p_default) { - default_theme = p_default; } Ref<Theme> Theme::get_project_default() { - return project_default_theme; } void Theme::set_project_default(const Ref<Theme> &p_project_default) { - project_default_theme = p_project_default; } void Theme::set_default_icon(const Ref<Texture2D> &p_icon) { - default_icon = p_icon; } void Theme::set_default_style(const Ref<StyleBox> &p_style) { - default_style = p_style; } void Theme::set_default_font(const Ref<Font> &p_font) { - default_font = p_font; } void Theme::set_icon(const StringName &p_name, const StringName &p_type, const Ref<Texture2D> &p_icon) { - //ERR_FAIL_COND(p_icon.is_null()); bool new_value = !icon_map.has(p_type) || !icon_map[p_type].has(p_name); @@ -381,9 +338,7 @@ void Theme::set_icon(const StringName &p_name, const StringName &p_type, const R } } Ref<Texture2D> Theme::get_icon(const StringName &p_name, const StringName &p_type) const { - if (icon_map.has(p_type) && icon_map[p_type].has(p_name) && icon_map[p_type][p_name].is_valid()) { - return icon_map[p_type][p_name]; } else { return default_icon; @@ -391,12 +346,10 @@ Ref<Texture2D> Theme::get_icon(const StringName &p_name, const StringName &p_typ } bool Theme::has_icon(const StringName &p_name, const StringName &p_type) const { - return (icon_map.has(p_type) && icon_map[p_type].has(p_name) && icon_map[p_type][p_name].is_valid()); } void Theme::clear_icon(const StringName &p_name, const StringName &p_type) { - ERR_FAIL_COND(!icon_map.has(p_type)); ERR_FAIL_COND(!icon_map[p_type].has(p_name)); @@ -411,7 +364,6 @@ 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)) @@ -420,7 +372,6 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { const StringName *key = nullptr; while ((key = icon_map[p_type].next(key))) { - p_list->push_back(*key); } } @@ -458,7 +409,6 @@ 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)) @@ -467,13 +417,11 @@ void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) const StringName *key = nullptr; while ((key = shader_map[p_type].next(key))) { - p_list->push_back(*key); } } void Theme::set_stylebox(const StringName &p_name, const StringName &p_type, const Ref<StyleBox> &p_style) { - //ERR_FAIL_COND(p_style.is_null()); bool new_value = !style_map.has(p_type) || !style_map[p_type].has(p_name); @@ -494,9 +442,7 @@ void Theme::set_stylebox(const StringName &p_name, const StringName &p_type, con } Ref<StyleBox> Theme::get_stylebox(const StringName &p_name, const StringName &p_type) const { - if (style_map.has(p_type) && style_map[p_type].has(p_name) && style_map[p_type][p_name].is_valid()) { - return style_map[p_type][p_name]; } else { return default_style; @@ -504,12 +450,10 @@ Ref<StyleBox> Theme::get_stylebox(const StringName &p_name, const StringName &p_ } bool Theme::has_stylebox(const StringName &p_name, const StringName &p_type) const { - return (style_map.has(p_type) && style_map[p_type].has(p_name) && style_map[p_type][p_name].is_valid()); } void Theme::clear_stylebox(const StringName &p_name, const StringName &p_type) { - ERR_FAIL_COND(!style_map.has(p_type)); ERR_FAIL_COND(!style_map[p_type].has(p_name)); @@ -524,7 +468,6 @@ 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)) @@ -533,7 +476,6 @@ void Theme::get_stylebox_list(StringName p_type, List<StringName> *p_list) const const StringName *key = nullptr; while ((key = style_map[p_type].next(key))) { - p_list->push_back(*key); } } @@ -548,7 +490,6 @@ void Theme::get_stylebox_types(List<StringName> *p_list) const { } void Theme::set_font(const StringName &p_name, const StringName &p_type, const Ref<Font> &p_font) { - //ERR_FAIL_COND(p_font.is_null()); bool new_value = !font_map.has(p_type) || !font_map[p_type].has(p_name); @@ -569,7 +510,6 @@ 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()) return font_map[p_type][p_name]; else if (default_theme_font.is_valid()) @@ -579,12 +519,10 @@ Ref<Font> Theme::get_font(const StringName &p_name, const StringName &p_type) co } bool Theme::has_font(const StringName &p_name, const StringName &p_type) const { - return (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()); } void Theme::clear_font(const StringName &p_name, const StringName &p_type) { - ERR_FAIL_COND(!font_map.has(p_type)); ERR_FAIL_COND(!font_map[p_type].has(p_name)); @@ -598,7 +536,6 @@ 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)) @@ -607,13 +544,11 @@ void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const { const StringName *key = nullptr; while ((key = font_map[p_type].next(key))) { - p_list->push_back(*key); } } void Theme::set_color(const StringName &p_name, const StringName &p_type, const Color &p_color) { - bool new_value = !color_map.has(p_type) || !color_map[p_type].has(p_name); color_map[p_type][p_name] = p_color; @@ -625,7 +560,6 @@ 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)) return color_map[p_type][p_name]; else @@ -633,12 +567,10 @@ Color Theme::get_color(const StringName &p_name, const StringName &p_type) const } bool Theme::has_color(const StringName &p_name, const StringName &p_type) const { - return (color_map.has(p_type) && color_map[p_type].has(p_name)); } void Theme::clear_color(const StringName &p_name, const StringName &p_type) { - ERR_FAIL_COND(!color_map.has(p_type)); ERR_FAIL_COND(!color_map[p_type].has(p_name)); @@ -648,7 +580,6 @@ 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)) @@ -657,13 +588,11 @@ void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const { const StringName *key = nullptr; while ((key = color_map[p_type].next(key))) { - p_list->push_back(*key); } } void Theme::set_constant(const StringName &p_name, const StringName &p_type, int p_constant) { - bool new_value = !constant_map.has(p_type) || !constant_map[p_type].has(p_name); constant_map[p_type][p_name] = p_constant; @@ -674,7 +603,6 @@ 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)) return constant_map[p_type][p_name]; else { @@ -683,12 +611,10 @@ int Theme::get_constant(const StringName &p_name, const StringName &p_type) cons } bool Theme::has_constant(const StringName &p_name, const StringName &p_type) const { - return (constant_map.has(p_type) && constant_map[p_type].has(p_name)); } void Theme::clear_constant(const StringName &p_name, const StringName &p_type) { - ERR_FAIL_COND(!constant_map.has(p_type)); ERR_FAIL_COND(!constant_map[p_type].has(p_name)); @@ -698,7 +624,6 @@ 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)) @@ -707,13 +632,11 @@ void Theme::get_constant_list(StringName p_type, List<StringName> *p_list) const const StringName *key = nullptr; while ((key = constant_map[p_type].next(key))) { - p_list->push_back(*key); } } void Theme::clear() { - //these need disconnecting { const StringName *K = nullptr; @@ -766,13 +689,11 @@ void Theme::clear() { } void Theme::copy_default_theme() { - Ref<Theme> default_theme2 = get_default(); copy_theme(default_theme2); } void Theme::copy_theme(const Ref<Theme> &p_other) { - if (p_other.is_null()) { clear(); @@ -821,53 +742,45 @@ void Theme::copy_theme(const Ref<Theme> &p_other) { } void Theme::get_type_list(List<StringName> *p_list) const { - ERR_FAIL_NULL(p_list); Set<StringName> types; const StringName *key = nullptr; while ((key = icon_map.next(key))) { - types.insert(*key); } key = nullptr; while ((key = style_map.next(key))) { - types.insert(*key); } key = nullptr; while ((key = font_map.next(key))) { - types.insert(*key); } key = nullptr; while ((key = color_map.next(key))) { - types.insert(*key); } key = nullptr; while ((key = constant_map.next(key))) { - types.insert(*key); } for (Set<StringName>::Element *E = types.front(); E; E = E->next()) { - p_list->push_back(E->get()); } } void Theme::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_icon", "name", "type", "texture"), &Theme::set_icon); ClassDB::bind_method(D_METHOD("get_icon", "name", "type"), &Theme::get_icon); ClassDB::bind_method(D_METHOD("has_icon", "name", "type"), &Theme::has_icon); diff --git a/scene/resources/theme.h b/scene/resources/theme.h index b5043c35e8..3c72ddd8a2 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -39,7 +39,6 @@ #include "scene/resources/texture.h" class Theme : public Resource { - GDCLASS(Theme, Resource); RES_BASE_EXTENSION("theme"); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 1b68b7486b..38e50e35f1 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -33,7 +33,6 @@ #include "core/engine.h" bool TileSet::_set(const StringName &p_name, const Variant &p_value) { - String n = p_name; int slash = n.find("/"); if (slash == -1) @@ -206,7 +205,6 @@ 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) @@ -320,9 +318,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { } void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { - for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) { - int id = E->key(); String pre = itos(id) + "/"; p_list->push_back(PropertyInfo(Variant::STRING, pre + "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); @@ -382,13 +378,11 @@ void TileSet::autotile_set_bitmask_mode(int p_id, BitmaskMode p_mode) { } TileSet::BitmaskMode TileSet::autotile_get_bitmask_mode(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), BITMASK_2X2); return tile_map[p_id].autotile_data.bitmask_mode; } void TileSet::tile_set_texture(int p_id, const Ref<Texture2D> &p_texture) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].texture = p_texture; emit_changed(); @@ -396,39 +390,33 @@ void TileSet::tile_set_texture(int p_id, const Ref<Texture2D> &p_texture) { } Ref<Texture2D> TileSet::tile_get_texture(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture2D>()); return tile_map[p_id].texture; } void TileSet::tile_set_normal_map(int p_id, const Ref<Texture2D> &p_normal_map) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].normal_map = p_normal_map; emit_changed(); } Ref<Texture2D> TileSet::tile_get_normal_map(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<Texture2D>()); return tile_map[p_id].normal_map; } void TileSet::tile_set_material(int p_id, const Ref<ShaderMaterial> &p_material) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].material = p_material; emit_changed(); } Ref<ShaderMaterial> TileSet::tile_get_material(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<ShaderMaterial>()); return tile_map[p_id].material; } void TileSet::tile_set_modulate(int p_id, const Color &p_modulate) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].modulate = p_modulate; emit_changed(); @@ -436,26 +424,22 @@ void TileSet::tile_set_modulate(int p_id, const Color &p_modulate) { } Color TileSet::tile_get_modulate(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Color(1, 1, 1)); return tile_map[p_id].modulate; } void TileSet::tile_set_texture_offset(int p_id, const Vector2 &p_offset) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].offset = p_offset; emit_changed(); } Vector2 TileSet::tile_get_texture_offset(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); return tile_map[p_id].offset; } void TileSet::tile_set_region(int p_id, const Rect2 &p_region) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].region = p_region; emit_changed(); @@ -463,7 +447,6 @@ void TileSet::tile_set_region(int p_id, const Rect2 &p_region) { } Rect2 TileSet::tile_get_region(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Rect2()); return tile_map[p_id].region; } @@ -476,26 +459,22 @@ void TileSet::tile_set_tile_mode(int p_id, TileMode p_tile_mode) { } TileSet::TileMode TileSet::tile_get_tile_mode(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), SINGLE_TILE); return tile_map[p_id].tile_mode; } void TileSet::autotile_set_icon_coordinate(int p_id, Vector2 coord) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].autotile_data.icon_coord = coord; emit_changed(); } Vector2 TileSet::autotile_get_icon_coordinate(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); return tile_map[p_id].autotile_data.icon_coord; } void TileSet::autotile_set_spacing(int p_id, int p_spacing) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_spacing < 0); tile_map[p_id].autotile_data.spacing = p_spacing; @@ -503,39 +482,33 @@ void TileSet::autotile_set_spacing(int p_id, int p_spacing) { } int TileSet::autotile_get_spacing(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), 0); return tile_map[p_id].autotile_data.spacing; } void TileSet::autotile_set_size(int p_id, Size2 p_size) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_size.x <= 0 || p_size.y <= 0); tile_map[p_id].autotile_data.size = p_size; } Size2 TileSet::autotile_get_size(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Size2()); return tile_map[p_id].autotile_data.size; } void TileSet::autotile_clear_bitmask_map(int p_id) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].autotile_data.flags.clear(); } void TileSet::autotile_set_subtile_priority(int p_id, const Vector2 &p_coord, int p_priority) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_priority <= 0); tile_map[p_id].autotile_data.priority_map[p_coord] = p_priority; } int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) { - ERR_FAIL_COND_V(!tile_map.has(p_id), 1); if (tile_map[p_id].autotile_data.priority_map.has(p_coord)) { return tile_map[p_id].autotile_data.priority_map[p_coord]; @@ -545,21 +518,18 @@ int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) { } const Map<Vector2, int> &TileSet::autotile_get_priority_map(int p_id) const { - static Map<Vector2, int> dummy; ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); return tile_map[p_id].autotile_data.priority_map; } void TileSet::autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].autotile_data.z_index_map[p_coord] = p_z_index; emit_changed(); } int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) { - ERR_FAIL_COND_V(!tile_map.has(p_id), 1); if (tile_map[p_id].autotile_data.z_index_map.has(p_coord)) { return tile_map[p_id].autotile_data.z_index_map[p_coord]; @@ -569,14 +539,12 @@ int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) { } const Map<Vector2, int> &TileSet::autotile_get_z_index_map(int p_id) const { - static Map<Vector2, int> dummy; ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); return tile_map[p_id].autotile_data.z_index_map; } 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)) @@ -587,7 +555,6 @@ void TileSet::autotile_set_bitmask(int p_id, Vector2 p_coord, uint32_t p_flag) { } uint32_t TileSet::autotile_get_bitmask(int p_id, Vector2 p_coord) { - ERR_FAIL_COND_V(!tile_map.has(p_id), 0); if (!tile_map[p_id].autotile_data.flags.has(p_coord)) { return 0; @@ -596,7 +563,6 @@ uint32_t TileSet::autotile_get_bitmask(int p_id, Vector2 p_coord) { } const Map<Vector2, uint32_t> &TileSet::autotile_get_bitmask_map(int p_id) { - static Map<Vector2, uint32_t> dummy; static Map<Vector2, uint32_t> dummy_atlas; ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); @@ -616,7 +582,6 @@ const Map<Vector2, uint32_t> &TileSet::autotile_get_bitmask_map(int p_id) { } Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, const Node *p_tilemap_node, const Vector2 &p_tile_location) { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); //First try to forward selection to script if (p_tilemap_node->get_class_name() == "TileMap") { @@ -678,7 +643,6 @@ Vector2 TileSet::autotile_get_subtile_for_bitmask(int p_id, uint16_t p_bitmask, } Vector2 TileSet::atlastile_get_subtile_by_priority(int p_id, const Node *p_tilemap_node, const Vector2 &p_tile_location) { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); //First try to forward selection to script if (get_script_instance() != nullptr) { @@ -708,7 +672,6 @@ Vector2 TileSet::atlastile_get_subtile_by_priority(int p_id, const Node *p_tilem } void TileSet::tile_set_name(int p_id, const String &p_name) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].name = p_name; emit_changed(); @@ -716,19 +679,16 @@ void TileSet::tile_set_name(int p_id, const String &p_name) { } String TileSet::tile_get_name(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), String()); return tile_map[p_id].name; } void TileSet::tile_clear_shapes(int p_id) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].shapes_data.clear(); } void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way, const Vector2 &p_autotile_coord) { - ERR_FAIL_COND(!tile_map.has(p_id)); ShapeData new_data = ShapeData(); @@ -741,13 +701,11 @@ void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transf } int TileSet::tile_get_shape_count(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), 0); return tile_map[p_id].shapes_data.size(); } void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_shape) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_shape_id < 0); @@ -759,7 +717,6 @@ void TileSet::tile_set_shape(int p_id, int p_shape_id, const Ref<Shape2D> &p_sha } 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>()); @@ -770,7 +727,6 @@ Ref<Shape2D> TileSet::tile_get_shape(int p_id, int p_shape_id) const { } void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform2D &p_offset) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_shape_id < 0); @@ -781,7 +737,6 @@ void TileSet::tile_set_shape_transform(int p_id, int p_shape_id, const Transform } 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()); @@ -802,7 +757,6 @@ Vector2 TileSet::tile_get_shape_offset(int p_id, int p_shape_id) const { } void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_way) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_shape_id < 0); @@ -813,7 +767,6 @@ void TileSet::tile_set_shape_one_way(int p_id, int p_shape_id, const bool p_one_ } 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); @@ -824,7 +777,6 @@ bool TileSet::tile_get_shape_one_way(int p_id, int p_shape_id) const { } void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_margin) { - ERR_FAIL_COND(!tile_map.has(p_id)); ERR_FAIL_COND(p_shape_id < 0); @@ -835,7 +787,6 @@ void TileSet::tile_set_shape_one_way_margin(int p_id, int p_shape_id, float p_ma } 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); @@ -846,13 +797,11 @@ float TileSet::tile_get_shape_one_way_margin(int p_id, int p_shape_id) const { } void TileSet::tile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> &p_light_occluder) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].occluder = p_light_occluder; } Ref<OccluderPolygon2D> TileSet::tile_get_light_occluder(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>()); return tile_map[p_id].occluder; } @@ -869,7 +818,6 @@ void TileSet::autotile_set_light_occluder(int p_id, const Ref<OccluderPolygon2D> } Ref<OccluderPolygon2D> TileSet::autotile_get_light_occluder(int p_id, const Vector2 &p_coord) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<OccluderPolygon2D>()); if (!tile_map[p_id].autotile_data.occluder_map.has(p_coord)) { @@ -880,38 +828,32 @@ Ref<OccluderPolygon2D> TileSet::autotile_get_light_occluder(int p_id, const Vect } void TileSet::tile_set_navigation_polygon_offset(int p_id, const Vector2 &p_offset) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].navigation_polygon_offset = p_offset; } Vector2 TileSet::tile_get_navigation_polygon_offset(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); return tile_map[p_id].navigation_polygon_offset; } void TileSet::tile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].navigation_polygon = p_navigation_polygon; } Ref<NavigationPolygon> TileSet::tile_get_navigation_polygon(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<NavigationPolygon>()); return tile_map[p_id].navigation_polygon; } const Map<Vector2, Ref<OccluderPolygon2D>> &TileSet::autotile_get_light_oclusion_map(int p_id) const { - static Map<Vector2, Ref<OccluderPolygon2D>> dummy; ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); return tile_map[p_id].autotile_data.occluder_map; } void TileSet::autotile_set_navigation_polygon(int p_id, const Ref<NavigationPolygon> &p_navigation_polygon, const Vector2 &p_coord) { - ERR_FAIL_COND(!tile_map.has(p_id)); if (p_navigation_polygon.is_null()) { if (tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) { @@ -923,7 +865,6 @@ void TileSet::autotile_set_navigation_polygon(int p_id, const Ref<NavigationPoly } Ref<NavigationPolygon> TileSet::autotile_get_navigation_polygon(int p_id, const Vector2 &p_coord) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Ref<NavigationPolygon>()); if (!tile_map[p_id].autotile_data.navpoly_map.has(p_coord)) { return Ref<NavigationPolygon>(); @@ -933,26 +874,22 @@ Ref<NavigationPolygon> TileSet::autotile_get_navigation_polygon(int p_id, const } const Map<Vector2, Ref<NavigationPolygon>> &TileSet::autotile_get_navigation_map(int p_id) const { - static Map<Vector2, Ref<NavigationPolygon>> dummy; ERR_FAIL_COND_V(!tile_map.has(p_id), dummy); return tile_map[p_id].autotile_data.navpoly_map; } void TileSet::tile_set_occluder_offset(int p_id, const Vector2 &p_offset) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].occluder_offset = p_offset; } Vector2 TileSet::tile_get_occluder_offset(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector2()); return tile_map[p_id].occluder_offset; } void TileSet::tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].shapes_data = p_shapes; for (int i = 0; i < p_shapes.size(); i++) { @@ -962,27 +899,23 @@ void TileSet::tile_set_shapes(int p_id, const Vector<ShapeData> &p_shapes) { } Vector<TileSet::ShapeData> TileSet::tile_get_shapes(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Vector<ShapeData>()); return tile_map[p_id].shapes_data; } int TileSet::tile_get_z_index(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), 0); return tile_map[p_id].z_index; } void TileSet::tile_set_z_index(int p_id, int p_z_index) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map[p_id].z_index = p_z_index; emit_changed(); } void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { - ERR_FAIL_COND(!tile_map.has(p_id)); Vector<ShapeData> shapes_data; Transform2D default_transform = tile_get_shape_transform(p_id, 0); @@ -1043,7 +976,6 @@ void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) { } Array TileSet::_tile_get_shapes(int p_id) const { - ERR_FAIL_COND_V(!tile_map.has(p_id), Array()); Array arr; @@ -1062,7 +994,6 @@ Array TileSet::_tile_get_shapes(int p_id) const { } Array TileSet::_get_tiles_ids() const { - Array arr; for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) { @@ -1093,20 +1024,16 @@ void TileSet::_decompose_convex_shape(Ref<Shape2D> p_shape) { } void TileSet::get_tile_list(List<int> *p_tiles) const { - for (Map<int, TileData>::Element *E = tile_map.front(); E; E = E->next()) { - p_tiles->push_back(E->key()); } } bool TileSet::has_tile(int p_id) const { - return tile_map.has(p_id); } bool TileSet::is_tile_bound(int p_drawn_id, int p_neighbor_id) { - if (p_drawn_id == p_neighbor_id) { return true; } else if (get_script_instance() != nullptr) { @@ -1121,7 +1048,6 @@ bool TileSet::is_tile_bound(int p_drawn_id, int p_neighbor_id) { } void TileSet::remove_tile(int p_id) { - ERR_FAIL_COND(!tile_map.has(p_id)); tile_map.erase(p_id); _change_notify(""); @@ -1129,7 +1055,6 @@ void TileSet::remove_tile(int p_id) { } int TileSet::get_last_unused_tile_id() const { - if (tile_map.size()) return tile_map.back()->key() + 1; else @@ -1137,9 +1062,7 @@ int TileSet::get_last_unused_tile_id() const { } 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) return E->key(); } @@ -1147,14 +1070,12 @@ int TileSet::find_tile_by_name(const String &p_name) const { } void TileSet::clear() { - tile_map.clear(); _change_notify(""); emit_changed(); } void TileSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("create_tile", "id"), &TileSet::create_tile); ClassDB::bind_method(D_METHOD("autotile_clear_bitmask_map", "id"), &TileSet::autotile_clear_bitmask_map); ClassDB::bind_method(D_METHOD("autotile_set_icon_coordinate", "id", "coord"), &TileSet::autotile_set_icon_coordinate); diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 5f01959253..78f34e46ce 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -40,7 +40,6 @@ #include "scene/resources/texture.h" class TileSet : public Resource { - GDCLASS(TileSet, Resource); public: @@ -105,7 +104,6 @@ public: private: struct TileData { - String name; Ref<Texture2D> texture; Ref<Texture2D> normal_map; diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h index a9b96214c3..379ba53a34 100644 --- a/scene/resources/video_stream.h +++ b/scene/resources/video_stream.h @@ -34,7 +34,6 @@ #include "scene/resources/texture.h" class VideoStreamPlayback : public Resource { - GDCLASS(VideoStreamPlayback, Resource); public: @@ -68,7 +67,6 @@ public: }; class VideoStream : public Resource { - GDCLASS(VideoStream, Resource); OBJ_SAVE_TYPE(VideoStream); // Saves derived classes with common type so they can be interchanged. diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 5637aaec9a..31d0fc2c9d 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -39,12 +39,10 @@ bool VisualShaderNode::is_simple_decl() const { } void VisualShaderNode::set_output_port_for_preview(int p_index) { - port_preview = p_index; } int VisualShaderNode::get_output_port_for_preview() const { - return port_preview; } @@ -85,7 +83,6 @@ Vector<StringName> VisualShaderNode::get_editable_properties() const { } Array VisualShaderNode::get_default_input_values() const { - Array ret; for (Map<int, Variant>::Element *E = default_input_values.front(); E; E = E->next()) { ret.push_back(E->key()); @@ -94,7 +91,6 @@ Array VisualShaderNode::get_default_input_values() const { return ret; } void VisualShaderNode::set_default_input_values(const Array &p_values) { - if (p_values.size() % 2 == 0) { for (int i = 0; i < p_values.size(); i += 2) { default_input_values[p_values[i + 0]] = p_values[i + 1]; @@ -113,7 +109,6 @@ String VisualShaderNode::get_input_port_default_hint(int p_port) const { } void VisualShaderNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_output_port_for_preview", "port"), &VisualShaderNode::set_output_port_for_preview); ClassDB::bind_method(D_METHOD("get_output_port_for_preview"), &VisualShaderNode::get_output_port_for_preview); @@ -225,7 +220,6 @@ String VisualShaderNodeCustom::get_output_port_name(int p_port) const { } String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - ERR_FAIL_COND_V(!get_script_instance(), ""); ERR_FAIL_COND_V(!get_script_instance()->has_method("_get_code"), ""); Array input_vars; @@ -264,7 +258,6 @@ String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, Vis } void VisualShaderNodeCustom::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name")); BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_description")); BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category")); @@ -445,7 +438,6 @@ bool VisualShader::is_node_connection(Type p_type, int p_from_node, int p_from_p const Graph *g = &graph[p_type]; for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { return true; } @@ -460,7 +452,6 @@ bool VisualShader::is_nodes_connected_relatively(const Graph *p_graph, int p_nod const VisualShader::Node &node = p_graph->nodes[p_node]; for (const List<int>::Element *E = node.prev_connected_nodes.front(); E; E = E->next()) { - if (E->get() == p_target) { return true; } @@ -474,7 +465,6 @@ bool VisualShader::is_nodes_connected_relatively(const Graph *p_graph, int p_nod } bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const { - ERR_FAIL_INDEX_V(p_type, TYPE_MAX, false); const Graph *g = &graph[p_type]; @@ -501,7 +491,6 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po } for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { return false; } @@ -546,7 +535,6 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port, ERR_FAIL_COND_V_MSG(!is_port_types_compatible(from_port_type, to_port_type), ERR_INVALID_PARAMETER, "Incompatible port types (scalar/vec/bool) with transform."); for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { ERR_FAIL_V(ERR_ALREADY_EXISTS); } @@ -569,7 +557,6 @@ void VisualShader::disconnect_nodes(Type p_type, int p_from_node, int p_from_por Graph *g = &graph[p_type]; for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { g->connections.erase(E); g->nodes[p_to_node].prev_connected_nodes.erase(p_from_node); @@ -615,9 +602,7 @@ void VisualShader::set_mode(Mode p_mode) { flags.clear(); shader_mode = p_mode; for (int i = 0; i < TYPE_MAX; i++) { - for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { - Ref<VisualShaderNodeInput> input = E->get().node; if (input.is_valid()) { input->shader_mode = shader_mode; @@ -630,7 +615,6 @@ void VisualShader::set_mode(Mode p_mode) { // clear connections since they are no longer valid for (List<Connection>::Element *E = graph[i].connections.front(); E;) { - bool keep = true; List<Connection>::Element *N = E->next(); @@ -684,7 +668,6 @@ bool VisualShader::is_text_shader() const { } String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port, Vector<DefaultTextureParam> &default_tex_params) const { - Ref<VisualShaderNode> node = get_node(p_type, p_node); ERR_FAIL_COND_V(!node.is_valid(), String()); ERR_FAIL_COND_V(p_port < 0 || p_port >= node->get_output_port_count(), String()); @@ -703,7 +686,6 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { Ref<VisualShaderNodeGlobalExpression> global_expression = Object::cast_to<VisualShaderNodeGlobalExpression>(E->get().node.ptr()); if (global_expression.is_valid()) { - String expr = ""; expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n"; expr += global_expression->generate_global(get_mode(), Type(i), -1); @@ -772,7 +754,6 @@ String VisualShader::validate_port_name(const String &p_name, const List<String> } if (name != String()) { - String valid_name; for (int i = 0; i < name.length(); i++) { @@ -813,13 +794,11 @@ String VisualShader::validate_port_name(const String &p_name, const List<String> } String VisualShader::validate_uniform_name(const String &p_name, const Ref<VisualShaderNodeUniform> &p_uniform) const { - String name = p_name; //validate name first while (name.length() && !IS_INITIAL_CHAR(name[0])) { name = name.substr(1, name.length() - 1); } if (name != String()) { - String valid_name; for (int i = 0; i < name.length(); i++) { @@ -840,7 +819,6 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua int attempt = 1; while (true) { - bool exists = false; for (int i = 0; i < TYPE_MAX; i++) { for (const Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { @@ -890,7 +868,6 @@ static const char *type_string[VisualShader::TYPE_MAX] = { "light" }; bool VisualShader::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (name == "mode") { set_mode(Shader::Mode(int(p_value))); @@ -927,7 +904,6 @@ bool VisualShader::_set(const StringName &p_name, const Variant &p_value) { String index = name.get_slicec('/', 2); if (index == "connections") { - Vector<int> conns = p_value; if (conns.size() % 4 == 0) { for (int i = 0; i < conns.size(); i += 4) { @@ -964,7 +940,6 @@ bool VisualShader::_set(const StringName &p_name, const Variant &p_value) { } bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; if (name == "mode") { r_ret = get_mode(); @@ -993,7 +968,6 @@ bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const { String index = name.get_slicec('/', 2); if (index == "connections") { - Vector<int> conns; for (const List<Connection>::Element *E = graph[type].connections.front(); E; E = E->next()) { conns.push_back(E->get().from_node); @@ -1074,13 +1048,11 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < TYPE_MAX; i++) { for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { - String prop_name = "nodes/"; prop_name += type_string[i]; prop_name += "/" + itos(E->key()); if (E->key() != NODE_ID_OUTPUT) { - p_list->push_back(PropertyInfo(Variant::OBJECT, prop_name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); } p_list->push_back(PropertyInfo(Variant::VECTOR2, prop_name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); @@ -1099,7 +1071,6 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { } Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBuilder &global_code_per_node, Map<Type, StringBuilder> &global_code_per_func, StringBuilder &code, Vector<VisualShader::DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview, Set<StringName> &r_classes) const { - const Ref<VisualShaderNode> vsnode = graph[type].nodes[node].node; //check inputs recursively first @@ -1181,7 +1152,6 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui inputs[i] = "int(" + src_var + ")"; } } else { - Variant defval = vsnode->get_input_port_default_value(i); if (defval.get_type() == Variant::FLOAT) { float val = defval; @@ -1283,7 +1253,6 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui bool skip_global = input.is_valid() && for_preview; if (!skip_global) { - global_code += vsnode->generate_global(get_mode(), type, node); String class_name = vsnode->get_class_name(); @@ -1330,11 +1299,8 @@ void VisualShader::_update_shader() const { //fill render mode enums int idx = 0; while (render_mode_enums[idx].string) { - if (shader_mode == render_mode_enums[idx].mode) { - if (modes.has(render_mode_enums[idx].string)) { - int which = modes[render_mode_enums[idx].string]; int count = 0; for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { @@ -1357,7 +1323,6 @@ void VisualShader::_update_shader() const { //fill render mode flags for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { - String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (flags.has(mode)) { if (render_mode != String()) { @@ -1369,7 +1334,6 @@ void VisualShader::_update_shader() const { } if (render_mode != String()) { - global_code += "render_mode " + render_mode + ";\n\n"; } @@ -1377,7 +1341,6 @@ void VisualShader::_update_shader() const { String global_expressions; for (int i = 0, index = 0; i < TYPE_MAX; i++) { - if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { continue; } @@ -1385,7 +1348,6 @@ void VisualShader::_update_shader() const { for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { Ref<VisualShaderNodeGlobalExpression> global_expression = Object::cast_to<VisualShaderNodeGlobalExpression>(E->get().node.ptr()); if (global_expression.is_valid()) { - String expr = ""; expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n"; expr += global_expression->generate_global(get_mode(), Type(i), -1); @@ -1397,7 +1359,6 @@ void VisualShader::_update_shader() const { } for (int i = 0; i < TYPE_MAX; i++) { - if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { continue; } @@ -1483,7 +1444,6 @@ void VisualShader::rebuild() { } void VisualShader::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &VisualShader::set_mode); ClassDB::bind_method(D_METHOD("add_node", "type", "node", "position", "id"), &VisualShader::add_node); @@ -1762,24 +1722,19 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = { }; int VisualShaderNodeInput::get_input_port_count() const { - return 0; } VisualShaderNodeInput::PortType VisualShaderNodeInput::get_input_port_type(int p_port) const { - return PORT_TYPE_SCALAR; } String VisualShaderNodeInput::get_input_port_name(int p_port) const { - return ""; } int VisualShaderNodeInput::get_output_port_count() const { - return 1; } VisualShaderNodeInput::PortType VisualShaderNodeInput::get_output_port_type(int p_port) const { - return get_input_type_by_name(input_name); } String VisualShaderNodeInput::get_output_port_name(int p_port) const { @@ -1791,7 +1746,6 @@ String VisualShaderNodeInput::get_caption() const { } String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - if (get_output_port_type(0) == PORT_TYPE_SAMPLER) { return ""; } @@ -1868,7 +1822,6 @@ String VisualShaderNodeInput::get_input_name() const { } String VisualShaderNodeInput::get_input_real_name() const { - int idx = 0; while (ports[idx].mode != Shader::MODE_MAX) { @@ -1882,7 +1835,6 @@ String VisualShaderNodeInput::get_input_real_name() const { } VisualShaderNodeInput::PortType VisualShaderNodeInput::get_input_type_by_name(String p_name) const { - int idx = 0; while (ports[idx].mode != Shader::MODE_MAX) { @@ -1944,7 +1896,6 @@ String VisualShaderNodeInput::get_input_index_name(int p_index) const { } void VisualShaderNodeInput::_validate_property(PropertyInfo &property) const { - if (property.name == "input_name") { String port_list; @@ -1974,7 +1925,6 @@ Vector<StringName> VisualShaderNodeInput::get_editable_properties() const { } void VisualShaderNodeInput::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_input_name", "name"), &VisualShaderNodeInput::set_input_name); ClassDB::bind_method(D_METHOD("get_input_name"), &VisualShaderNodeInput::get_input_name); ClassDB::bind_method(D_METHOD("get_input_real_name"), &VisualShaderNodeInput::get_input_real_name); @@ -2060,7 +2010,6 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = { }; int VisualShaderNodeOutput::get_input_port_count() const { - int idx = 0; int count = 0; @@ -2075,7 +2024,6 @@ int VisualShaderNodeOutput::get_input_port_count() const { } VisualShaderNodeOutput::PortType VisualShaderNodeOutput::get_input_port_type(int p_port) const { - int idx = 0; int count = 0; @@ -2093,7 +2041,6 @@ VisualShaderNodeOutput::PortType VisualShaderNodeOutput::get_input_port_type(int } String VisualShaderNodeOutput::get_input_port_name(int p_port) const { - int idx = 0; int count = 0; @@ -2115,7 +2062,6 @@ Variant VisualShaderNodeOutput::get_input_port_default_value(int p_port) const { } int VisualShaderNodeOutput::get_output_port_count() const { - return 0; } VisualShaderNodeOutput::PortType VisualShaderNodeOutput::get_output_port_type(int p_port) const { @@ -2126,7 +2072,6 @@ String VisualShaderNodeOutput::get_output_port_name(int p_port) const { } bool VisualShaderNodeOutput::is_port_separator(int p_index) const { - if (shader_mode == Shader::MODE_SPATIAL && shader_type == VisualShader::TYPE_FRAGMENT) { String name = get_input_port_name(p_index); return (name == "Normal" || name == "Rim" || name == "Alpha Scissor"); @@ -2139,14 +2084,12 @@ String VisualShaderNodeOutput::get_caption() const { } String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - int idx = 0; int count = 0; String code; while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type) { - if (p_input_vars[count] != String()) { String s = ports[idx].string; if (s.find(":") != -1) { @@ -2188,7 +2131,6 @@ VisualShaderNodeUniform::Qualifier VisualShaderNodeUniform::get_qualifier() cons } void VisualShaderNodeUniform::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_uniform_name", "name"), &VisualShaderNodeUniform::set_uniform_name); ClassDB::bind_method(D_METHOD("get_uniform_name"), &VisualShaderNodeUniform::get_uniform_name); @@ -2218,7 +2160,6 @@ String VisualShaderNodeUniform::_get_qual_str() const { } String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { - List<String> keyword_list; ShaderLanguage::get_keyword_list(&keyword_list); if (keyword_list.find(uniform_name)) { @@ -2256,7 +2197,6 @@ Vector2 VisualShaderNodeGroupBase::get_size() const { } void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) { - if (inputs == p_inputs) return; @@ -2269,7 +2209,6 @@ void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) { int input_port_count = input_strings.size(); for (int i = 0; i < input_port_count; i++) { - Vector<String> arr = input_strings[i].split(","); ERR_FAIL_COND(arr.size() != 3); @@ -2289,7 +2228,6 @@ String VisualShaderNodeGroupBase::get_inputs() const { } void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) { - if (outputs == p_outputs) return; @@ -2302,7 +2240,6 @@ void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) { int output_port_count = output_strings.size(); for (int i = 0; i < output_port_count; i++) { - Vector<String> arr = output_strings[i].split(","); ERR_FAIL_COND(arr.size() != 3); @@ -2339,7 +2276,6 @@ bool VisualShaderNodeGroupBase::is_valid_port_name(const String &p_name) const { } void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const String &p_name) { - String str = itos(p_id) + "," + itos(p_type) + "," + p_name + ";"; Vector<String> inputs_strings = inputs.split(";", false); int index = 0; @@ -2376,7 +2312,6 @@ void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const Strin } void VisualShaderNodeGroupBase::remove_input_port(int p_id) { - ERR_FAIL_COND(!has_input_port(p_id)); Vector<String> inputs_strings = inputs.split(";", false); @@ -2409,7 +2344,6 @@ bool VisualShaderNodeGroupBase::has_input_port(int p_id) const { } void VisualShaderNodeGroupBase::add_output_port(int p_id, int p_type, const String &p_name) { - String str = itos(p_id) + "," + itos(p_type) + "," + p_name + ";"; Vector<String> outputs_strings = outputs.split(";", false); int index = 0; @@ -2446,7 +2380,6 @@ void VisualShaderNodeGroupBase::add_output_port(int p_id, int p_type, const Stri } void VisualShaderNodeGroupBase::remove_output_port(int p_id) { - ERR_FAIL_COND(!has_output_port(p_id)); Vector<String> outputs_strings = outputs.split(";", false); @@ -2487,7 +2420,6 @@ void VisualShaderNodeGroupBase::clear_output_ports() { } 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); @@ -2522,7 +2454,6 @@ VisualShaderNodeGroupBase::PortType VisualShaderNodeGroupBase::get_input_port_ty } void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_name) { - ERR_FAIL_COND(!has_input_port(p_id)); ERR_FAIL_COND(!is_valid_port_name(p_name)); @@ -2557,7 +2488,6 @@ String VisualShaderNodeGroupBase::get_input_port_name(int p_id) const { } 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); @@ -2592,7 +2522,6 @@ VisualShaderNodeGroupBase::PortType VisualShaderNodeGroupBase::get_output_port_t } void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_name) { - ERR_FAIL_COND(!has_output_port(p_id)); ERR_FAIL_COND(!is_valid_port_name(p_name)); @@ -2644,7 +2573,6 @@ Control *VisualShaderNodeGroupBase::get_control(int p_index) { } void VisualShaderNodeGroupBase::_apply_port_changes() { - Vector<String> inputs_strings = inputs.split(";", false); Vector<String> outputs_strings = outputs.split(";", false); @@ -2680,7 +2608,6 @@ bool VisualShaderNodeGroupBase::is_editable() const { } void VisualShaderNodeGroupBase::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_size", "size"), &VisualShaderNodeGroupBase::set_size); ClassDB::bind_method(D_METHOD("get_size"), &VisualShaderNodeGroupBase::get_size); @@ -2742,7 +2669,6 @@ String VisualShaderNodeExpression::get_expression() const { } String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String _expression = expression; _expression = _expression.insert(0, "\n"); @@ -2842,7 +2768,6 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad } void VisualShaderNodeExpression::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_expression", "expression"), &VisualShaderNodeExpression::set_expression); ClassDB::bind_method(D_METHOD("get_expression"), &VisualShaderNodeExpression::get_expression); diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index 56f8e74d2b..8bd09df512 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -98,7 +98,6 @@ private: void _queue_update(); union ConnectionKey { - struct { uint64_t node : 32; uint64_t port : 32; diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 03db8c3ac5..b89f069211 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -65,13 +65,11 @@ String VisualShaderNodeFloatConstant::generate_code(Shader::Mode p_mode, VisualS } void VisualShaderNodeFloatConstant::set_constant(float p_value) { - constant = p_value; emit_changed(); } float VisualShaderNodeFloatConstant::get_constant() const { - return constant; } @@ -82,7 +80,6 @@ Vector<StringName> VisualShaderNodeFloatConstant::get_editable_properties() cons } void VisualShaderNodeFloatConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeFloatConstant::set_constant); ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeFloatConstant::get_constant); @@ -143,7 +140,6 @@ Vector<StringName> VisualShaderNodeIntConstant::get_editable_properties() const } void VisualShaderNodeIntConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeIntConstant::set_constant); ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeIntConstant::get_constant); @@ -204,7 +200,6 @@ Vector<StringName> VisualShaderNodeBooleanConstant::get_editable_properties() co } void VisualShaderNodeBooleanConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeBooleanConstant::set_constant); ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeBooleanConstant::get_constant); @@ -246,7 +241,6 @@ String VisualShaderNodeColorConstant::get_output_port_name(int p_port) const { } String VisualShaderNodeColorConstant::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code; code += "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.r, constant.g, constant.b) + ";\n"; code += "\t" + p_output_vars[1] + " = " + vformat("%.6f", constant.a) + ";\n"; @@ -255,13 +249,11 @@ String VisualShaderNodeColorConstant::generate_code(Shader::Mode p_mode, VisualS } void VisualShaderNodeColorConstant::set_constant(Color p_value) { - constant = p_value; emit_changed(); } Color VisualShaderNodeColorConstant::get_constant() const { - return constant; } @@ -272,7 +264,6 @@ Vector<StringName> VisualShaderNodeColorConstant::get_editable_properties() cons } void VisualShaderNodeColorConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeColorConstant::set_constant); ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeColorConstant::get_constant); @@ -318,13 +309,11 @@ String VisualShaderNodeVec3Constant::generate_code(Shader::Mode p_mode, VisualSh } void VisualShaderNodeVec3Constant::set_constant(Vector3 p_value) { - constant = p_value; emit_changed(); } Vector3 VisualShaderNodeVec3Constant::get_constant() const { - return constant; } @@ -335,7 +324,6 @@ Vector<StringName> VisualShaderNodeVec3Constant::get_editable_properties() const } void VisualShaderNodeVec3Constant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeVec3Constant::set_constant); ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeVec3Constant::get_constant); @@ -388,13 +376,11 @@ String VisualShaderNodeTransformConstant::generate_code(Shader::Mode p_mode, Vis } void VisualShaderNodeTransformConstant::set_constant(Transform p_value) { - constant = p_value; emit_changed(); } Transform VisualShaderNodeTransformConstant::get_constant() const { - return constant; } @@ -405,7 +391,6 @@ Vector<StringName> VisualShaderNodeTransformConstant::get_editable_properties() } void VisualShaderNodeTransformConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant", "value"), &VisualShaderNodeTransformConstant::set_constant); ClassDB::bind_method(D_METHOD("get_constant"), &VisualShaderNodeTransformConstant::get_constant); @@ -426,7 +411,6 @@ int VisualShaderNodeTexture::get_input_port_count() const { } VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_input_port_type(int p_port) const { - switch (p_port) { case 0: return PORT_TYPE_VECTOR; @@ -440,7 +424,6 @@ VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_input_port_type(i } String VisualShaderNodeTexture::get_input_port_name(int p_port) const { - switch (p_port) { case 0: return "uv"; @@ -477,7 +460,6 @@ String VisualShaderNodeTexture::get_input_port_default_hint(int p_port) const { } static String make_unique_id(VisualShader::Type p_type, int p_id, const String &p_name) { - static const char *typepf[VisualShader::TYPE_MAX] = { "vtx", "frg", "lgt" }; return p_name + "_" + String(typepf[p_type]) + "_" + itos(p_id); } @@ -492,9 +474,7 @@ Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture::get_default_t } String VisualShaderNodeTexture::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - if (source == SOURCE_TEXTURE) { - String u = "uniform sampler2D " + make_unique_id(p_type, p_id, "tex"); switch (texture_type) { case TYPE_DATA: @@ -513,7 +493,6 @@ String VisualShaderNodeTexture::generate_global(Shader::Mode p_mode, VisualShade } String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - if (source == SOURCE_TEXTURE) { String id = make_unique_id(p_type, p_id, "tex"); String code; @@ -568,7 +547,6 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: } if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default. @@ -592,7 +570,6 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: } if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; if (p_input_vars[0] == String()) { // Use UV by default. @@ -616,7 +593,6 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: } if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; if (p_input_vars[0] == String()) { // Use UV by default. @@ -650,7 +626,6 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: } if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; if (p_input_vars[0] == String()) { // Use UV by default. @@ -716,13 +691,11 @@ VisualShaderNodeTexture::Source VisualShaderNodeTexture::get_source() const { } void VisualShaderNodeTexture::set_texture(Ref<Texture2D> p_value) { - texture = p_value; emit_changed(); } Ref<Texture2D> VisualShaderNodeTexture::get_texture() const { - return texture; } @@ -746,7 +719,6 @@ Vector<StringName> VisualShaderNodeTexture::get_editable_properties() const { } String VisualShaderNodeTexture::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { - if (source == SOURCE_TEXTURE) { return String(); // all good } @@ -756,22 +728,18 @@ String VisualShaderNodeTexture::get_warning(Shader::Mode p_mode, VisualShader::T } if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) { - return String(); // all good } if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { - return String(); // all good } if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM) { - return String(); // all good } if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) { - if (get_output_port_for_preview() == 0) { // DEPTH_TEXTURE is not supported in preview(canvas_item) shader return TTR("Invalid source for preview."); } @@ -782,7 +750,6 @@ String VisualShaderNodeTexture::get_warning(Shader::Mode p_mode, VisualShader::T } void VisualShaderNodeTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_source", "value"), &VisualShaderNodeTexture::set_source); ClassDB::bind_method(D_METHOD("get_source"), &VisualShaderNodeTexture::get_source); @@ -870,7 +837,6 @@ Vector<VisualShader::DefaultTextureParam> VisualShaderNodeCubemap::get_default_t } String VisualShaderNodeCubemap::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - if (source == SOURCE_TEXTURE) { String u = "uniform samplerCube " + make_unique_id(p_type, p_id, "cube"); switch (texture_type) { @@ -889,7 +855,6 @@ String VisualShaderNodeCubemap::generate_global(Shader::Mode p_mode, VisualShade } String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code; String id; if (source == SOURCE_TEXTURE) { @@ -949,13 +914,11 @@ VisualShaderNodeCubemap::Source VisualShaderNodeCubemap::get_source() const { } void VisualShaderNodeCubemap::set_cube_map(Ref<Cubemap> p_value) { - cube_map = p_value; emit_changed(); } Ref<Cubemap> VisualShaderNodeCubemap::get_cube_map() const { - return cube_map; } @@ -979,7 +942,6 @@ Vector<StringName> VisualShaderNodeCubemap::get_editable_properties() const { } void VisualShaderNodeCubemap::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_source", "value"), &VisualShaderNodeCubemap::set_source); ClassDB::bind_method(D_METHOD("get_source"), &VisualShaderNodeCubemap::get_source); @@ -1038,10 +1000,8 @@ String VisualShaderNodeFloatOp::get_output_port_name(int p_port) const { } String VisualShaderNodeFloatOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code = "\t" + p_output_vars[0] + " = "; switch (op) { - case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; break; @@ -1078,13 +1038,11 @@ String VisualShaderNodeFloatOp::generate_code(Shader::Mode p_mode, VisualShader: } void VisualShaderNodeFloatOp::set_operator(Operator p_op) { - op = p_op; emit_changed(); } VisualShaderNodeFloatOp::Operator VisualShaderNodeFloatOp::get_operator() const { - return op; } @@ -1095,7 +1053,6 @@ Vector<StringName> VisualShaderNodeFloatOp::get_editable_properties() const { } void VisualShaderNodeFloatOp::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeFloatOp::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeFloatOp::get_operator); @@ -1150,10 +1107,8 @@ String VisualShaderNodeIntOp::get_output_port_name(int p_port) const { } String VisualShaderNodeIntOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code = "\t" + p_output_vars[0] + " = "; switch (op) { - case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; break; @@ -1181,7 +1136,6 @@ String VisualShaderNodeIntOp::generate_code(Shader::Mode p_mode, VisualShader::T } void VisualShaderNodeIntOp::set_operator(Operator p_op) { - op = p_op; emit_changed(); } @@ -1197,7 +1151,6 @@ Vector<StringName> VisualShaderNodeIntOp::get_editable_properties() const { } void VisualShaderNodeIntOp::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeIntOp::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeIntOp::get_operator); @@ -1249,10 +1202,8 @@ String VisualShaderNodeVectorOp::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code = "\t" + p_output_vars[0] + " = "; switch (op) { - case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; break; @@ -1295,13 +1246,11 @@ String VisualShaderNodeVectorOp::generate_code(Shader::Mode p_mode, VisualShader } void VisualShaderNodeVectorOp::set_operator(Operator p_op) { - op = p_op; emit_changed(); } VisualShaderNodeVectorOp::Operator VisualShaderNodeVectorOp::get_operator() const { - return op; } @@ -1312,7 +1261,6 @@ Vector<StringName> VisualShaderNodeVectorOp::get_editable_properties() const { } void VisualShaderNodeVectorOp::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeVectorOp::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeVectorOp::get_operator); @@ -1369,29 +1317,23 @@ String VisualShaderNodeColorOp::get_output_port_name(int p_port) const { } String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code; static const char *axisn[3] = { "x", "y", "z" }; switch (op) { case OP_SCREEN: { - code += "\t" + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") * (vec3(1.0) - " + p_input_vars[1] + ");\n"; } break; case OP_DIFFERENCE: { - code += "\t" + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n"; } break; case OP_DARKEN: { - code += "\t" + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } break; case OP_LIGHTEN: { - code += "\t" + p_output_vars[0] + " = max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } break; case OP_OVERLAY: { - for (int i = 0; i < 3; i++) { code += "\t{\n"; code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; @@ -1406,16 +1348,13 @@ String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader: } break; case OP_DODGE: { - code += "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n"; } break; case OP_BURN: { - code += "\t" + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") / (" + p_input_vars[1] + ");\n"; } break; case OP_SOFT_LIGHT: { - for (int i = 0; i < 3; i++) { code += "\t{\n"; code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; @@ -1430,7 +1369,6 @@ String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader: } break; case OP_HARD_LIGHT: { - for (int i = 0; i < 3; i++) { code += "\t{\n"; code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; @@ -1450,7 +1388,6 @@ String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader: } void VisualShaderNodeColorOp::set_operator(Operator p_op) { - op = p_op; switch (op) { case OP_SCREEN: @@ -1485,7 +1422,6 @@ void VisualShaderNodeColorOp::set_operator(Operator p_op) { } VisualShaderNodeColorOp::Operator VisualShaderNodeColorOp::get_operator() const { - return op; } @@ -1496,7 +1432,6 @@ Vector<StringName> VisualShaderNodeColorOp::get_editable_properties() const { } void VisualShaderNodeColorOp::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeColorOp::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeColorOp::get_operator); @@ -1550,7 +1485,6 @@ String VisualShaderNodeTransformMult::get_output_port_name(int p_port) const { } String VisualShaderNodeTransformMult::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - if (op == OP_AxB) { return "\t" + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; } else if (op == OP_BxA) { @@ -1563,13 +1497,11 @@ String VisualShaderNodeTransformMult::generate_code(Shader::Mode p_mode, VisualS } void VisualShaderNodeTransformMult::set_operator(Operator p_op) { - op = p_op; emit_changed(); } VisualShaderNodeTransformMult::Operator VisualShaderNodeTransformMult::get_operator() const { - return op; } @@ -1580,7 +1512,6 @@ Vector<StringName> VisualShaderNodeTransformMult::get_editable_properties() cons } void VisualShaderNodeTransformMult::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformMult::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformMult::get_operator); @@ -1641,13 +1572,11 @@ String VisualShaderNodeTransformVecMult::generate_code(Shader::Mode p_mode, Visu } void VisualShaderNodeTransformVecMult::set_operator(Operator p_op) { - op = p_op; emit_changed(); } VisualShaderNodeTransformVecMult::Operator VisualShaderNodeTransformVecMult::get_operator() const { - return op; } @@ -1658,7 +1587,6 @@ Vector<StringName> VisualShaderNodeTransformVecMult::get_editable_properties() c } void VisualShaderNodeTransformVecMult::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformVecMult::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformVecMult::get_operator); @@ -1707,7 +1635,6 @@ String VisualShaderNodeFloatFunc::get_output_port_name(int p_port) const { } String VisualShaderNodeFloatFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *scalar_func_id[FUNC_ONEMINUS + 1] = { "sin($)", "cos($)", @@ -1747,13 +1674,11 @@ String VisualShaderNodeFloatFunc::generate_code(Shader::Mode p_mode, VisualShade } void VisualShaderNodeFloatFunc::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeFloatFunc::Function VisualShaderNodeFloatFunc::get_function() const { - return func; } @@ -1764,7 +1689,6 @@ Vector<StringName> VisualShaderNodeFloatFunc::get_editable_properties() const { } void VisualShaderNodeFloatFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeFloatFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeFloatFunc::get_function); @@ -1878,7 +1802,6 @@ void VisualShaderNodeIntFunc::set_function(Function p_func) { } VisualShaderNodeIntFunc::Function VisualShaderNodeIntFunc::get_function() const { - return func; } @@ -1889,7 +1812,6 @@ Vector<StringName> VisualShaderNodeIntFunc::get_editable_properties() const { } void VisualShaderNodeIntFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeIntFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeIntFunc::get_function); @@ -1937,7 +1859,6 @@ String VisualShaderNodeVectorFunc::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *vec_func_id[FUNC_ONEMINUS + 1] = { "normalize($)", "max(min($, vec3(1.0)), vec3(0.0))", @@ -2004,7 +1925,6 @@ String VisualShaderNodeVectorFunc::generate_code(Shader::Mode p_mode, VisualShad } void VisualShaderNodeVectorFunc::set_function(Function p_func) { - func = p_func; if (func == FUNC_RGB2HSV) { simple_decl = false; @@ -2017,7 +1937,6 @@ void VisualShaderNodeVectorFunc::set_function(Function p_func) { } VisualShaderNodeVectorFunc::Function VisualShaderNodeVectorFunc::get_function() const { - return func; } @@ -2028,7 +1947,6 @@ Vector<StringName> VisualShaderNodeVectorFunc::get_editable_properties() const { } void VisualShaderNodeVectorFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeVectorFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeVectorFunc::get_function); @@ -2107,7 +2025,6 @@ String VisualShaderNodeColorFunc::get_output_port_name(int p_port) const { } String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code; switch (func) { @@ -2135,13 +2052,11 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade } void VisualShaderNodeColorFunc::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeColorFunc::Function VisualShaderNodeColorFunc::get_function() const { - return func; } @@ -2152,7 +2067,6 @@ Vector<StringName> VisualShaderNodeColorFunc::get_editable_properties() const { } void VisualShaderNodeColorFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeColorFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeColorFunc::get_function); @@ -2199,7 +2113,6 @@ String VisualShaderNodeTransformFunc::get_output_port_name(int p_port) const { } String VisualShaderNodeTransformFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *funcs[FUNC_TRANSPOSE + 1] = { "inverse($)", "transpose($)" @@ -2211,13 +2124,11 @@ String VisualShaderNodeTransformFunc::generate_code(Shader::Mode p_mode, VisualS } void VisualShaderNodeTransformFunc::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeTransformFunc::Function VisualShaderNodeTransformFunc::get_function() const { - return func; } @@ -2228,7 +2139,6 @@ Vector<StringName> VisualShaderNodeTransformFunc::get_editable_properties() cons } void VisualShaderNodeTransformFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeTransformFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeTransformFunc::get_function); @@ -2389,7 +2299,6 @@ String VisualShaderNodeScalarDerivativeFunc::get_output_port_name(int p_port) co } String VisualShaderNodeScalarDerivativeFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *funcs[FUNC_Y + 1] = { "fwidth($)", "dFdx($)", @@ -2402,13 +2311,11 @@ String VisualShaderNodeScalarDerivativeFunc::generate_code(Shader::Mode p_mode, } void VisualShaderNodeScalarDerivativeFunc::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeScalarDerivativeFunc::Function VisualShaderNodeScalarDerivativeFunc::get_function() const { - return func; } @@ -2419,7 +2326,6 @@ Vector<StringName> VisualShaderNodeScalarDerivativeFunc::get_editable_properties } void VisualShaderNodeScalarDerivativeFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeScalarDerivativeFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeScalarDerivativeFunc::get_function); @@ -2466,7 +2372,6 @@ String VisualShaderNodeVectorDerivativeFunc::get_output_port_name(int p_port) co } String VisualShaderNodeVectorDerivativeFunc::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *funcs[FUNC_Y + 1] = { "fwidth($)", "dFdx($)", @@ -2479,13 +2384,11 @@ String VisualShaderNodeVectorDerivativeFunc::generate_code(Shader::Mode p_mode, } void VisualShaderNodeVectorDerivativeFunc::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeVectorDerivativeFunc::Function VisualShaderNodeVectorDerivativeFunc::get_function() const { - return func; } @@ -2496,7 +2399,6 @@ Vector<StringName> VisualShaderNodeVectorDerivativeFunc::get_editable_properties } void VisualShaderNodeVectorDerivativeFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeVectorDerivativeFunc::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeVectorDerivativeFunc::get_function); @@ -2943,7 +2845,6 @@ int VisualShaderNodeVectorRefract::get_input_port_count() const { } VisualShaderNodeVectorRefract::PortType VisualShaderNodeVectorRefract::get_input_port_type(int p_port) const { - if (p_port == 2) { return PORT_TYPE_SCALAR; } @@ -3165,7 +3066,6 @@ String VisualShaderNodeVectorCompose::generate_code(Shader::Mode p_mode, VisualS } VisualShaderNodeVectorCompose::VisualShaderNodeVectorCompose() { - set_input_port_default_value(0, 0.0); set_input_port_default_value(1, 0.0); set_input_port_default_value(2, 0.0); @@ -3214,7 +3114,6 @@ String VisualShaderNodeTransformCompose::generate_code(Shader::Mode p_mode, Visu } VisualShaderNodeTransformCompose::VisualShaderNodeTransformCompose() { - set_input_port_default_value(0, Vector3()); set_input_port_default_value(1, Vector3()); set_input_port_default_value(2, Vector3()); @@ -3647,7 +3546,6 @@ String VisualShaderNodeColorUniform::get_output_port_name(int p_port) const { } String VisualShaderNodeColorUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - return _get_qual_str() + "uniform vec4 " + get_uniform_name() + " : hint_color;\n"; } @@ -3777,7 +3675,6 @@ int VisualShaderNodeTextureUniform::get_output_port_count() const { } VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_output_port_type(int p_port) const { - switch (p_port) { case 0: return PORT_TYPE_VECTOR; @@ -3791,7 +3688,6 @@ VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_out } String VisualShaderNodeTextureUniform::get_output_port_name(int p_port) const { - switch (p_port) { case 0: return "rgb"; @@ -3832,7 +3728,6 @@ String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, Visu } String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String id = get_uniform_name(); String code = "\t{\n"; if (p_input_vars[0] == String()) { // Use UV by default. @@ -3855,7 +3750,6 @@ String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, Visual } void VisualShaderNodeTextureUniform::set_texture_type(TextureType p_type) { - texture_type = p_type; emit_changed(); } @@ -3953,7 +3847,6 @@ String VisualShaderNodeTextureUniformTriplanar::get_input_port_name(int p_port) } String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - String code; code += "// TRIPLANAR FUNCTION GLOBAL CODE\n"; @@ -3976,11 +3869,9 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader: } String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { - String code; if (p_type == VisualShader::TYPE_VERTEX) { - code += "\t// TRIPLANAR FUNCTION VERTEX CODE\n"; code += "\t\ttriplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n"; code += "\t\ttriplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n"; @@ -3992,7 +3883,6 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader: } String VisualShaderNodeTextureUniformTriplanar::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String id = get_uniform_name(); String code = "\t{\n"; @@ -4142,7 +4032,6 @@ String VisualShaderNodeIf::get_output_port_name(int p_port) const { } String VisualShaderNodeIf::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code; code += "\tif(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b code += "\t{\n"; @@ -4212,7 +4101,6 @@ String VisualShaderNodeSwitch::get_output_port_name(int p_port) const { } String VisualShaderNodeSwitch::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String code; code += "\tif(" + p_input_vars[0] + ")\n"; code += "\t{\n"; @@ -4308,7 +4196,6 @@ String VisualShaderNodeFresnel::get_output_port_name(int p_port) const { } String VisualShaderNodeFresnel::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String normal; String view; if (p_input_vars[0] == String()) { @@ -4342,42 +4229,34 @@ VisualShaderNodeFresnel::VisualShaderNodeFresnel() { ////////////// Is String VisualShaderNodeIs::get_caption() const { - return "Is"; } int VisualShaderNodeIs::get_input_port_count() const { - return 1; } VisualShaderNodeIs::PortType VisualShaderNodeIs::get_input_port_type(int p_port) const { - return PORT_TYPE_SCALAR; } String VisualShaderNodeIs::get_input_port_name(int p_port) const { - return ""; } int VisualShaderNodeIs::get_output_port_count() const { - return 1; } VisualShaderNodeIs::PortType VisualShaderNodeIs::get_output_port_type(int p_port) const { - return PORT_TYPE_BOOLEAN; } String VisualShaderNodeIs::get_output_port_name(int p_port) const { - return ""; } String VisualShaderNodeIs::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *funcs[FUNC_IS_NAN + 1] = { "isinf($)", "isnan($)" @@ -4389,25 +4268,21 @@ String VisualShaderNodeIs::generate_code(Shader::Mode p_mode, VisualShader::Type } void VisualShaderNodeIs::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeIs::Function VisualShaderNodeIs::get_function() const { - return func; } Vector<StringName> VisualShaderNodeIs::get_editable_properties() const { - Vector<StringName> props; props.push_back("function"); return props; } void VisualShaderNodeIs::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeIs::set_function); ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeIs::get_function); @@ -4418,7 +4293,6 @@ void VisualShaderNodeIs::_bind_methods() { } VisualShaderNodeIs::VisualShaderNodeIs() { - func = FUNC_IS_INF; set_input_port_default_value(0, 0.0); } @@ -4426,12 +4300,10 @@ VisualShaderNodeIs::VisualShaderNodeIs() { ////////////// Compare String VisualShaderNodeCompare::get_caption() const { - return "Compare"; } int VisualShaderNodeCompare::get_input_port_count() const { - if (ctype == CTYPE_SCALAR && (func == FUNC_EQUAL || func == FUNC_NOT_EQUAL)) { return 3; } @@ -4439,7 +4311,6 @@ int VisualShaderNodeCompare::get_input_port_count() const { } VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(int p_port) const { - if (p_port == 2) return PORT_TYPE_SCALAR; switch (ctype) { @@ -4482,7 +4353,6 @@ String VisualShaderNodeCompare::get_output_port_name(int p_port) const { } String VisualShaderNodeCompare::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { - if (ctype == CTYPE_BOOLEAN || ctype == CTYPE_TRANSFORM) { if (func > FUNC_NOT_EQUAL) { return TTR("Invalid comparison function for that type."); @@ -4493,7 +4363,6 @@ String VisualShaderNodeCompare::get_warning(Shader::Mode p_mode, VisualShader::T } String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - static const char *ops[FUNC_LESS_THAN_EQUAL + 1] = { "==", "!=", @@ -4559,7 +4428,6 @@ String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader: } void VisualShaderNodeCompare::set_comparison_type(ComparisonType p_type) { - ctype = p_type; switch (ctype) { @@ -4593,29 +4461,24 @@ void VisualShaderNodeCompare::set_comparison_type(ComparisonType p_type) { } VisualShaderNodeCompare::ComparisonType VisualShaderNodeCompare::get_comparison_type() const { - return ctype; } void VisualShaderNodeCompare::set_function(Function p_func) { - func = p_func; emit_changed(); } VisualShaderNodeCompare::Function VisualShaderNodeCompare::get_function() const { - return func; } void VisualShaderNodeCompare::set_condition(Condition p_cond) { - condition = p_cond; emit_changed(); } VisualShaderNodeCompare::Condition VisualShaderNodeCompare::get_condition() const { - return condition; } @@ -4629,7 +4492,6 @@ Vector<StringName> VisualShaderNodeCompare::get_editable_properties() const { } void VisualShaderNodeCompare::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_comparison_type", "type"), &VisualShaderNodeCompare::set_comparison_type); ClassDB::bind_method(D_METHOD("get_comparison_type"), &VisualShaderNodeCompare::get_comparison_type); diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index f2f67d3814..99b9c7803e 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -38,9 +38,7 @@ #include "servers/rendering_server.h" struct SpatialIndexer2D { - struct CellRef { - int ref; _FORCE_INLINE_ int inc() { @@ -58,7 +56,6 @@ struct SpatialIndexer2D { }; struct CellKey { - union { struct { int32_t x; @@ -74,7 +71,6 @@ struct SpatialIndexer2D { }; struct CellData { - Map<VisibilityNotifier2D *, CellRef> notifiers; }; @@ -84,7 +80,6 @@ struct SpatialIndexer2D { Map<VisibilityNotifier2D *, Rect2> notifiers; struct ViewportData { - Map<VisibilityNotifier2D *, uint64_t> notifiers; Rect2 rect; }; @@ -96,30 +91,24 @@ struct SpatialIndexer2D { uint64_t pass; void _notifier_update_cells(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect, bool p_add) { - Point2i begin = p_rect.position; begin /= cell_size; Point2i end = p_rect.position + p_rect.size; end /= cell_size; for (int i = begin.x; i <= end.x; i++) { - for (int j = begin.y; j <= end.y; j++) { - CellKey ck; ck.x = i; ck.y = j; Map<CellKey, CellData>::Element *E = cells.find(ck); if (p_add) { - if (!E) E = cells.insert(ck, CellData()); E->get().notifiers[p_notifier].inc(); } else { - ERR_CONTINUE(!E); if (E->get().notifiers[p_notifier].dec() == 0) { - E->get().notifiers.erase(p_notifier); if (E->get().notifiers.empty()) { cells.erase(E); @@ -131,7 +120,6 @@ struct SpatialIndexer2D { } void _notifier_add(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect) { - ERR_FAIL_COND(notifiers.has(p_notifier)); notifiers[p_notifier] = p_rect; _notifier_update_cells(p_notifier, p_rect, true); @@ -139,7 +127,6 @@ 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) @@ -152,7 +139,6 @@ struct SpatialIndexer2D { } void _notifier_remove(VisibilityNotifier2D *p_notifier) { - Map<VisibilityNotifier2D *, Rect2>::Element *E = notifiers.find(p_notifier); ERR_FAIL_COND(!E); _notifier_update_cells(p_notifier, E->get(), false); @@ -160,7 +146,6 @@ struct SpatialIndexer2D { List<Viewport *> removed; for (Map<Viewport *, ViewportData>::Element *F = viewports.front(); F; F = F->next()) { - Map<VisibilityNotifier2D *, uint64_t>::Element *G = F->get().notifiers.find(p_notifier); if (G) { @@ -170,7 +155,6 @@ struct SpatialIndexer2D { } while (!removed.empty()) { - p_notifier->_exit_viewport(removed.front()->get()); removed.pop_front(); } @@ -179,7 +163,6 @@ struct SpatialIndexer2D { } void _add_viewport(Viewport *p_viewport, const Rect2 &p_rect) { - ERR_FAIL_COND(viewports.has(p_viewport)); ViewportData vd; vd.rect = p_rect; @@ -188,7 +171,6 @@ 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) @@ -201,7 +183,6 @@ struct SpatialIndexer2D { ERR_FAIL_COND(!viewports.has(p_viewport)); List<VisibilityNotifier2D *> removed; for (Map<VisibilityNotifier2D *, uint64_t>::Element *E = viewports[p_viewport].notifiers.front(); E; E = E->next()) { - removed.push_back(E->key()); } @@ -214,12 +195,10 @@ struct SpatialIndexer2D { } void _update() { - if (!changed) return; for (Map<Viewport *, ViewportData>::Element *E = viewports.front(); E; E = E->next()) { - Point2i begin = E->get().rect.position; begin /= cell_size; Point2i end = E->get().rect.position + E->get().rect.size; @@ -231,11 +210,9 @@ struct SpatialIndexer2D { int visible_cells = (end.x - begin.x) * (end.y - begin.y); if (visible_cells > 10000) { - //well you zoomed out a lot, it's your problem. To avoid freezing in the for loops below, we'll manually check cell by cell 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) @@ -245,10 +222,8 @@ struct SpatialIndexer2D { //notifiers in cell for (Map<VisibilityNotifier2D *, CellRef>::Element *G = F->get().notifiers.front(); G; G = G->next()) { - Map<VisibilityNotifier2D *, uint64_t>::Element *H = E->get().notifiers.find(G->key()); if (!H) { - H = E->get().notifiers.insert(G->key(), pass); added.push_back(G->key()); } else { @@ -258,12 +233,9 @@ struct SpatialIndexer2D { } } else { - //check cells in grid fashion for (int i = begin.x; i <= end.x; i++) { - for (int j = begin.y; j <= end.y; j++) { - CellKey ck; ck.x = i; ck.y = j; @@ -275,10 +247,8 @@ struct SpatialIndexer2D { //notifiers in cell for (Map<VisibilityNotifier2D *, CellRef>::Element *G = F->get().notifiers.front(); G; G = G->next()) { - Map<VisibilityNotifier2D *, uint64_t>::Element *H = E->get().notifiers.find(G->key()); if (!H) { - H = E->get().notifiers.insert(G->key(), pass); added.push_back(G->key()); } else { @@ -290,7 +260,6 @@ struct SpatialIndexer2D { } for (Map<VisibilityNotifier2D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) { - if (F->get() != pass) removed.push_back(F->key()); } @@ -311,7 +280,6 @@ struct SpatialIndexer2D { } SpatialIndexer2D() { - pass = 0; changed = false; cell_size = GLOBAL_DEF("world/2d/cell_size", 100); @@ -319,56 +287,45 @@ struct SpatialIndexer2D { }; void World2D::_register_viewport(Viewport *p_viewport, const Rect2 &p_rect) { - indexer->_add_viewport(p_viewport, p_rect); } void World2D::_update_viewport(Viewport *p_viewport, const Rect2 &p_rect) { - indexer->_update_viewport(p_viewport, p_rect); } void World2D::_remove_viewport(Viewport *p_viewport) { - indexer->_remove_viewport(p_viewport); } void World2D::_register_notifier(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect) { - indexer->_notifier_add(p_notifier, p_rect); } void World2D::_update_notifier(VisibilityNotifier2D *p_notifier, const Rect2 &p_rect) { - indexer->_notifier_update(p_notifier, p_rect); } void World2D::_remove_notifier(VisibilityNotifier2D *p_notifier) { - indexer->_notifier_remove(p_notifier); } void World2D::_update() { - indexer->_update(); } RID World2D::get_canvas() { - return canvas; } RID World2D::get_space() { - return space; } void World2D::get_viewport_list(List<Viewport *> *r_viewports) { - for (Map<Viewport *, SpatialIndexer2D::ViewportData>::Element *E = indexer->viewports.front(); E; E = E->next()) { r_viewports->push_back(E->key()); } } void World2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_canvas"), &World2D::get_canvas); ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space); @@ -380,12 +337,10 @@ void World2D::_bind_methods() { } PhysicsDirectSpaceState2D *World2D::get_direct_space_state() { - return PhysicsServer2D::get_singleton()->space_get_direct_state(space); } World2D::World2D() { - canvas = RenderingServer::get_singleton()->canvas_create(); space = PhysicsServer2D::get_singleton()->space_create(); @@ -401,7 +356,6 @@ World2D::World2D() { } World2D::~World2D() { - RenderingServer::get_singleton()->free(canvas); PhysicsServer2D::get_singleton()->free(space); memdelete(indexer); diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index 88b4c2594c..c330719104 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -40,7 +40,6 @@ class Viewport; struct SpatialIndexer2D; class World2D : public Resource { - GDCLASS(World2D, Resource); RID canvas; diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp index dee00dd82a..d8ec7f507c 100644 --- a/scene/resources/world_3d.cpp +++ b/scene/resources/world_3d.cpp @@ -37,18 +37,15 @@ #include "scene/scene_string_names.h" struct SpatialIndexer { - Octree<VisibilityNotifier3D> octree; struct NotifierData { - AABB aabb; OctreeElementID id; }; Map<VisibilityNotifier3D *, NotifierData> notifiers; struct CameraData { - Map<VisibilityNotifier3D *, uint64_t> notifiers; }; @@ -65,7 +62,6 @@ struct SpatialIndexer { uint64_t last_frame; void _notifier_add(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { - ERR_FAIL_COND(notifiers.has(p_notifier)); notifiers[p_notifier].aabb = p_rect; notifiers[p_notifier].id = octree.create(p_notifier, p_rect); @@ -73,7 +69,6 @@ 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) @@ -85,7 +80,6 @@ struct SpatialIndexer { } void _notifier_remove(VisibilityNotifier3D *p_notifier) { - Map<VisibilityNotifier3D *, NotifierData>::Element *E = notifiers.find(p_notifier); ERR_FAIL_COND(!E); @@ -94,7 +88,6 @@ struct SpatialIndexer { List<Camera3D *> removed; for (Map<Camera3D *, CameraData>::Element *F = cameras.front(); F; F = F->next()) { - Map<VisibilityNotifier3D *, uint64_t>::Element *G = F->get().notifiers.find(p_notifier); if (G) { @@ -104,7 +97,6 @@ struct SpatialIndexer { } while (!removed.empty()) { - p_notifier->_exit_camera(removed.front()->get()); removed.pop_front(); } @@ -113,7 +105,6 @@ struct SpatialIndexer { } void _add_camera(Camera3D *p_camera) { - ERR_FAIL_COND(cameras.has(p_camera)); CameraData vd; cameras[p_camera] = vd; @@ -121,7 +112,6 @@ struct SpatialIndexer { } void _update_camera(Camera3D *p_camera) { - Map<Camera3D *, CameraData>::Element *E = cameras.find(p_camera); ERR_FAIL_COND(!E); changed = true; @@ -131,7 +121,6 @@ struct SpatialIndexer { ERR_FAIL_COND(!cameras.has(p_camera)); List<VisibilityNotifier3D *> removed; for (Map<VisibilityNotifier3D *, uint64_t>::Element *E = cameras[p_camera].notifiers.front(); E; E = E->next()) { - removed.push_back(E->key()); } @@ -144,7 +133,6 @@ struct SpatialIndexer { } void _update(uint64_t p_frame) { - if (p_frame == last_frame) return; last_frame = p_frame; @@ -153,7 +141,6 @@ struct SpatialIndexer { return; for (Map<Camera3D *, CameraData>::Element *E = cameras.front(); E; E = E->next()) { - pass++; Camera3D *c = E->key(); @@ -168,12 +155,10 @@ struct SpatialIndexer { List<VisibilityNotifier3D *> removed; for (int i = 0; i < culled; i++) { - //notifiers in frustum Map<VisibilityNotifier3D *, uint64_t>::Element *H = E->get().notifiers.find(ptr[i]); if (!H) { - E->get().notifiers.insert(ptr[i], pass); added.push_back(ptr[i]); } else { @@ -182,7 +167,6 @@ struct SpatialIndexer { } for (Map<VisibilityNotifier3D *, uint64_t>::Element *F = E->get().notifiers.front(); F; F = F->next()) { - if (F->get() != pass) removed.push_back(F->key()); } @@ -202,7 +186,6 @@ struct SpatialIndexer { } SpatialIndexer() { - pass = 0; last_frame = 0; changed = false; @@ -211,60 +194,51 @@ struct SpatialIndexer { }; void World3D::_register_camera(Camera3D *p_camera) { - #ifndef _3D_DISABLED indexer->_add_camera(p_camera); #endif } void World3D::_update_camera(Camera3D *p_camera) { - #ifndef _3D_DISABLED indexer->_update_camera(p_camera); #endif } void World3D::_remove_camera(Camera3D *p_camera) { - #ifndef _3D_DISABLED indexer->_remove_camera(p_camera); #endif } void World3D::_register_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { - #ifndef _3D_DISABLED indexer->_notifier_add(p_notifier, p_rect); #endif } void World3D::_update_notifier(VisibilityNotifier3D *p_notifier, const AABB &p_rect) { - #ifndef _3D_DISABLED indexer->_notifier_update(p_notifier, p_rect); #endif } void World3D::_remove_notifier(VisibilityNotifier3D *p_notifier) { - #ifndef _3D_DISABLED indexer->_notifier_remove(p_notifier); #endif } void World3D::_update(uint64_t p_frame) { - #ifndef _3D_DISABLED indexer->_update(p_frame); #endif } RID World3D::get_space() const { - return space; } RID World3D::get_scenario() const { - return scenario; } @@ -283,7 +257,6 @@ void World3D::set_environment(const Ref<Environment> &p_environment) { } Ref<Environment> World3D::get_environment() const { - return environment; } @@ -302,12 +275,10 @@ void World3D::set_fallback_environment(const Ref<Environment> &p_environment) { } Ref<Environment> World3D::get_fallback_environment() const { - return fallback_environment; } void World3D::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { - camera_effects = p_camera_effects; if (camera_effects.is_valid()) RS::get_singleton()->scenario_set_camera_effects(scenario, camera_effects->get_rid()); @@ -316,24 +287,20 @@ void World3D::set_camera_effects(const Ref<CameraEffects> &p_camera_effects) { } Ref<CameraEffects> World3D::get_camera_effects() const { - return camera_effects; } PhysicsDirectSpaceState3D *World3D::get_direct_space_state() { - return PhysicsServer3D::get_singleton()->space_get_direct_state(space); } void World3D::get_camera_list(List<Camera3D *> *r_cameras) { - for (Map<Camera3D *, SpatialIndexer::CameraData>::Element *E = indexer->cameras.front(); E; E = E->next()) { r_cameras->push_back(E->key()); } } void World3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space); ClassDB::bind_method(D_METHOD("get_scenario"), &World3D::get_scenario); ClassDB::bind_method(D_METHOD("set_environment", "env"), &World3D::set_environment); @@ -352,7 +319,6 @@ void World3D::_bind_methods() { } World3D::World3D() { - space = PhysicsServer3D::get_singleton()->space_create(); scenario = RenderingServer::get_singleton()->scenario_create(); @@ -372,7 +338,6 @@ World3D::World3D() { } World3D::~World3D() { - PhysicsServer3D::get_singleton()->free(space); RenderingServer::get_singleton()->free(scenario); diff --git a/scene/resources/world_margin_shape_3d.cpp b/scene/resources/world_margin_shape_3d.cpp index aa96f8aa68..d613413b33 100644 --- a/scene/resources/world_margin_shape_3d.cpp +++ b/scene/resources/world_margin_shape_3d.cpp @@ -33,7 +33,6 @@ #include "servers/physics_server_3d.h" Vector<Vector3> WorldMarginShape3D::get_debug_mesh_lines() { - Plane p = get_plane(); Vector<Vector3> points; @@ -62,13 +61,11 @@ Vector<Vector3> WorldMarginShape3D::get_debug_mesh_lines() { } void WorldMarginShape3D::_update_shape() { - PhysicsServer3D::get_singleton()->shape_set_data(get_shape(), plane); Shape3D::_update_shape(); } void WorldMarginShape3D::set_plane(Plane p_plane) { - plane = p_plane; _update_shape(); notify_change_to_owners(); @@ -76,12 +73,10 @@ void WorldMarginShape3D::set_plane(Plane p_plane) { } Plane WorldMarginShape3D::get_plane() const { - return plane; } void WorldMarginShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_plane", "plane"), &WorldMarginShape3D::set_plane); ClassDB::bind_method(D_METHOD("get_plane"), &WorldMarginShape3D::get_plane); @@ -90,6 +85,5 @@ void WorldMarginShape3D::_bind_methods() { WorldMarginShape3D::WorldMarginShape3D() : Shape3D(PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_PLANE)) { - set_plane(Plane(0, 1, 0, 0)); } diff --git a/scene/resources/world_margin_shape_3d.h b/scene/resources/world_margin_shape_3d.h index 5e0f046628..acb479972b 100644 --- a/scene/resources/world_margin_shape_3d.h +++ b/scene/resources/world_margin_shape_3d.h @@ -34,7 +34,6 @@ #include "scene/resources/shape_3d.h" class WorldMarginShape3D : public Shape3D { - GDCLASS(WorldMarginShape3D, Shape3D); Plane plane; |