Merge pull request #101285 from Nazarwadim/use_LocalVector_in_animation

Use `LocalVector` in `Animation`
This commit is contained in:
Thaddeus Crews 2025-09-16 20:28:52 -05:00
commit 2557b0da9f
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
5 changed files with 285 additions and 285 deletions

View file

@ -74,7 +74,7 @@ void PhysicalBoneSimulator3D::_pose_updated() {
return; return;
} }
// If this triggers that means that we likely haven't rebuilt the bone list yet. // If this triggers that means that we likely haven't rebuilt the bone list yet.
if (skeleton->get_bone_count() != bones.size()) { if (skeleton->get_bone_count() != (int)bones.size()) {
// NOTE: this is re-entrant and will call _pose_updated again. // NOTE: this is re-entrant and will call _pose_updated again.
_bone_list_changed(); _bone_list_changed();
} else { } else {
@ -85,8 +85,8 @@ void PhysicalBoneSimulator3D::_pose_updated() {
} }
void PhysicalBoneSimulator3D::_bone_pose_updated(Skeleton3D *p_skeleton, int p_bone_id) { void PhysicalBoneSimulator3D::_bone_pose_updated(Skeleton3D *p_skeleton, int p_bone_id) {
ERR_FAIL_INDEX(p_bone_id, bones.size()); ERR_FAIL_UNSIGNED_INDEX((uint32_t)p_bone_id, bones.size());
bones.write[p_bone_id].global_pose = p_skeleton->get_bone_global_pose(p_bone_id); bones[p_bone_id].global_pose = p_skeleton->get_bone_global_pose(p_bone_id);
} }
void PhysicalBoneSimulator3D::_set_active(bool p_active) { void PhysicalBoneSimulator3D::_set_active(bool p_active) {
@ -96,7 +96,7 @@ void PhysicalBoneSimulator3D::_set_active(bool p_active) {
} }
void PhysicalBoneSimulator3D::_reset_physical_bones_state() { void PhysicalBoneSimulator3D::_reset_physical_bones_state() {
for (int i = 0; i < bones.size(); i += 1) { for (uint32_t i = 0; i < bones.size(); i += 1) {
if (bones[i].physical_bone) { if (bones[i].physical_bone) {
bones[i].physical_bone->reset_physics_simulation_state(); bones[i].physical_bone->reset_physics_simulation_state();
} }
@ -140,7 +140,7 @@ void PhysicalBoneSimulator3D::bind_physical_bone_to_bone(int p_bone, PhysicalBon
ERR_FAIL_INDEX(p_bone, bone_size); ERR_FAIL_INDEX(p_bone, bone_size);
ERR_FAIL_COND(bones[p_bone].physical_bone); ERR_FAIL_COND(bones[p_bone].physical_bone);
ERR_FAIL_NULL(p_physical_bone); ERR_FAIL_NULL(p_physical_bone);
bones.write[p_bone].physical_bone = p_physical_bone; bones[p_bone].physical_bone = p_physical_bone;
_rebuild_physical_bones_cache(); _rebuild_physical_bones_cache();
} }
@ -148,7 +148,7 @@ void PhysicalBoneSimulator3D::bind_physical_bone_to_bone(int p_bone, PhysicalBon
void PhysicalBoneSimulator3D::unbind_physical_bone_from_bone(int p_bone) { void PhysicalBoneSimulator3D::unbind_physical_bone_from_bone(int p_bone) {
const int bone_size = bones.size(); const int bone_size = bones.size();
ERR_FAIL_INDEX(p_bone, bone_size); ERR_FAIL_INDEX(p_bone, bone_size);
bones.write[p_bone].physical_bone = nullptr; bones[p_bone].physical_bone = nullptr;
_rebuild_physical_bones_cache(); _rebuild_physical_bones_cache();
} }
@ -193,7 +193,7 @@ void PhysicalBoneSimulator3D::_rebuild_physical_bones_cache() {
for (int i = 0; i < b_size; ++i) { for (int i = 0; i < b_size; ++i) {
PhysicalBone3D *parent_pb = _get_physical_bone_parent(i); PhysicalBone3D *parent_pb = _get_physical_bone_parent(i);
if (parent_pb != bones[i].cache_parent_physical_bone) { if (parent_pb != bones[i].cache_parent_physical_bone) {
bones.write[i].cache_parent_physical_bone = parent_pb; bones[i].cache_parent_physical_bone = parent_pb;
if (bones[i].physical_bone) { if (bones[i].physical_bone) {
bones[i].physical_bone->_on_bone_parent_changed(); bones[i].physical_bone->_on_bone_parent_changed();
} }
@ -361,7 +361,7 @@ Transform3D PhysicalBoneSimulator3D::get_bone_global_pose(int p_bone) const {
void PhysicalBoneSimulator3D::set_bone_global_pose(int p_bone, const Transform3D &p_pose) { void PhysicalBoneSimulator3D::set_bone_global_pose(int p_bone, const Transform3D &p_pose) {
const int bone_size = bones.size(); const int bone_size = bones.size();
ERR_FAIL_INDEX(p_bone, bone_size); ERR_FAIL_INDEX(p_bone, bone_size);
bones.write[p_bone].global_pose = p_pose; bones[p_bone].global_pose = p_pose;
} }
void PhysicalBoneSimulator3D::_process_modification(double p_delta) { void PhysicalBoneSimulator3D::_process_modification(double p_delta) {
@ -369,7 +369,7 @@ void PhysicalBoneSimulator3D::_process_modification(double p_delta) {
if (!skeleton) { if (!skeleton) {
return; return;
} }
ERR_FAIL_COND(skeleton->get_bone_count() != bones.size()); ERR_FAIL_COND(skeleton->get_bone_count() != (int)bones.size());
for (int i = 0; i < skeleton->get_bone_count(); i++) { for (int i = 0; i < skeleton->get_bone_count(); i++) {
if (!bones[i].physical_bone) { if (!bones[i].physical_bone) {
continue; continue;

View file

@ -56,7 +56,7 @@ class PhysicalBoneSimulator3D : public SkeletonModifier3D {
} }
}; };
Vector<SimulatedBone> bones; LocalVector<SimulatedBone> bones;
/// This is a slow API, so it's cached /// This is a slow API, so it's cached
PhysicalBone3D *_get_physical_bone_parent(int p_bone); PhysicalBone3D *_get_physical_bone_parent(int p_bone);

View file

@ -613,10 +613,10 @@ void AnimationMixer::_create_track_num_to_track_cache_for_animation(Ref<Animatio
return; return;
} }
LocalVector<TrackCache *> &track_num_to_track_cache = animation_track_num_to_track_cache.insert_new(p_animation, LocalVector<TrackCache *>())->value; LocalVector<TrackCache *> &track_num_to_track_cache = animation_track_num_to_track_cache.insert_new(p_animation, LocalVector<TrackCache *>())->value;
const Vector<Animation::Track *> &tracks = p_animation->get_tracks(); const LocalVector<Animation::Track *> &tracks = p_animation->get_tracks();
track_num_to_track_cache.resize(tracks.size()); track_num_to_track_cache.resize(tracks.size());
for (int i = 0; i < tracks.size(); i++) { for (uint32_t i = 0; i < tracks.size(); i++) {
TrackCache **track_ptr = track_cache.getptr(tracks[i]->thash); TrackCache **track_ptr = track_cache.getptr(tracks[i]->thash);
if (track_ptr == nullptr) { if (track_ptr == nullptr) {
track_num_to_track_cache[i] = nullptr; track_num_to_track_cache[i] = nullptr;
@ -1137,7 +1137,7 @@ void AnimationMixer::_blend_calc_total_weight() {
LocalVector<TrackCache *> &track_num_to_track_cache = animation_track_num_to_track_cache[a]; LocalVector<TrackCache *> &track_num_to_track_cache = animation_track_num_to_track_cache[a];
thread_local HashSet<Animation::TypeHash, HashHasher> processed_hashes; thread_local HashSet<Animation::TypeHash, HashHasher> processed_hashes;
processed_hashes.clear(); processed_hashes.clear();
const Vector<Animation::Track *> tracks = a->get_tracks(); const LocalVector<Animation::Track *> &tracks = a->get_tracks();
Animation::Track *const *tracks_ptr = tracks.ptr(); Animation::Track *const *tracks_ptr = tracks.ptr();
int count = tracks.size(); int count = tracks.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -1185,7 +1185,7 @@ void AnimationMixer::_blend_process(double p_delta, bool p_update_only) {
#endif // _3D_DISABLED #endif // _3D_DISABLED
ERR_CONTINUE_EDMSG(!animation_track_num_to_track_cache.has(a), "No animation in cache."); ERR_CONTINUE_EDMSG(!animation_track_num_to_track_cache.has(a), "No animation in cache.");
LocalVector<TrackCache *> &track_num_to_track_cache = animation_track_num_to_track_cache[a]; LocalVector<TrackCache *> &track_num_to_track_cache = animation_track_num_to_track_cache[a];
const Vector<Animation::Track *> tracks = a->get_tracks(); const LocalVector<Animation::Track *> &tracks = a->get_tracks();
Animation::Track *const *tracks_ptr = tracks.ptr(); Animation::Track *const *tracks_ptr = tracks.ptr();
real_t a_length = a->get_length(); real_t a_length = a->get_length();
int count = tracks.size(); int count = tracks.size();

File diff suppressed because it is too large Load diff

View file

@ -135,7 +135,7 @@ private:
/* POSITION TRACK */ /* POSITION TRACK */
struct PositionTrack : public Track { struct PositionTrack : public Track {
Vector<TKey<Vector3>> positions; LocalVector<TKey<Vector3>> positions;
int32_t compressed_track = -1; int32_t compressed_track = -1;
PositionTrack() { type = TYPE_POSITION_3D; } PositionTrack() { type = TYPE_POSITION_3D; }
}; };
@ -143,7 +143,7 @@ private:
/* ROTATION TRACK */ /* ROTATION TRACK */
struct RotationTrack : public Track { struct RotationTrack : public Track {
Vector<TKey<Quaternion>> rotations; LocalVector<TKey<Quaternion>> rotations;
int32_t compressed_track = -1; int32_t compressed_track = -1;
RotationTrack() { type = TYPE_ROTATION_3D; } RotationTrack() { type = TYPE_ROTATION_3D; }
}; };
@ -151,7 +151,7 @@ private:
/* SCALE TRACK */ /* SCALE TRACK */
struct ScaleTrack : public Track { struct ScaleTrack : public Track {
Vector<TKey<Vector3>> scales; LocalVector<TKey<Vector3>> scales;
int32_t compressed_track = -1; int32_t compressed_track = -1;
ScaleTrack() { type = TYPE_SCALE_3D; } ScaleTrack() { type = TYPE_SCALE_3D; }
}; };
@ -159,7 +159,7 @@ private:
/* BLEND SHAPE TRACK */ /* BLEND SHAPE TRACK */
struct BlendShapeTrack : public Track { struct BlendShapeTrack : public Track {
Vector<TKey<float>> blend_shapes; LocalVector<TKey<float>> blend_shapes;
int32_t compressed_track = -1; int32_t compressed_track = -1;
BlendShapeTrack() { type = TYPE_BLEND_SHAPE; } BlendShapeTrack() { type = TYPE_BLEND_SHAPE; }
}; };
@ -169,7 +169,7 @@ private:
struct ValueTrack : public Track { struct ValueTrack : public Track {
UpdateMode update_mode = UPDATE_CONTINUOUS; UpdateMode update_mode = UPDATE_CONTINUOUS;
bool update_on_seek = false; bool update_on_seek = false;
Vector<TKey<Variant>> values; LocalVector<TKey<Variant>> values;
ValueTrack() { ValueTrack() {
type = TYPE_VALUE; type = TYPE_VALUE;
@ -184,7 +184,7 @@ private:
}; };
struct MethodTrack : public Track { struct MethodTrack : public Track {
Vector<MethodKey> methods; LocalVector<MethodKey> methods;
MethodTrack() { type = TYPE_METHOD; } MethodTrack() { type = TYPE_METHOD; }
}; };
@ -200,7 +200,7 @@ private:
}; };
struct BezierTrack : public Track { struct BezierTrack : public Track {
Vector<TKey<BezierKey>> values; LocalVector<TKey<BezierKey>> values;
BezierTrack() { BezierTrack() {
type = TYPE_BEZIER; type = TYPE_BEZIER;
@ -218,7 +218,7 @@ private:
}; };
struct AudioTrack : public Track { struct AudioTrack : public Track {
Vector<TKey<AudioKey>> values; LocalVector<TKey<AudioKey>> values;
bool use_blend = true; bool use_blend = true;
AudioTrack() { AudioTrack() {
@ -229,7 +229,7 @@ private:
/* ANIMATION TRACK */ /* ANIMATION TRACK */
struct AnimationTrack : public Track { struct AnimationTrack : public Track {
Vector<TKey<StringName>> values; LocalVector<TKey<StringName>> values;
AnimationTrack() { AnimationTrack() {
type = TYPE_ANIMATION; type = TYPE_ANIMATION;
@ -246,20 +246,20 @@ private:
MarkerKey() = default; MarkerKey() = default;
}; };
Vector<MarkerKey> marker_names; // time -> name LocalVector<MarkerKey> marker_names; // time -> name
HashMap<StringName, double> marker_times; // name -> time HashMap<StringName, double> marker_times; // name -> time
HashMap<StringName, Color> marker_colors; // name -> color HashMap<StringName, Color> marker_colors; // name -> color
Vector<Track *> tracks; LocalVector<Track *> tracks;
template <typename T, typename V> template <typename T, typename V>
int _insert(double p_time, T &p_keys, const V &p_value); int _insert(double p_time, T &p_keys, const V &p_value);
int _marker_insert(double p_time, Vector<MarkerKey> &p_keys, const MarkerKey &p_value); int _marker_insert(double p_time, LocalVector<MarkerKey> &p_keys, const MarkerKey &p_value);
template <typename K> template <typename K>
inline int _find(const Vector<K> &p_keys, double p_time, bool p_backward = false, bool p_limit = false) const; inline int _find(const LocalVector<K> &p_keys, double p_time, bool p_backward = false, bool p_limit = false) const;
_FORCE_INLINE_ Vector3 _interpolate(const Vector3 &p_a, const Vector3 &p_b, real_t p_c) const; _FORCE_INLINE_ Vector3 _interpolate(const Vector3 &p_a, const Vector3 &p_b, real_t p_c) const;
_FORCE_INLINE_ Quaternion _interpolate(const Quaternion &p_a, const Quaternion &p_b, real_t p_c) const; _FORCE_INLINE_ Quaternion _interpolate(const Quaternion &p_a, const Quaternion &p_b, real_t p_c) const;
@ -274,10 +274,10 @@ private:
_FORCE_INLINE_ Variant _cubic_interpolate_angle_in_time(const Variant &p_pre_a, const Variant &p_a, const Variant &p_b, const Variant &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const; _FORCE_INLINE_ Variant _cubic_interpolate_angle_in_time(const Variant &p_pre_a, const Variant &p_a, const Variant &p_b, const Variant &p_post_b, real_t p_c, real_t p_pre_a_t, real_t p_b_t, real_t p_post_b_t) const;
template <typename T> template <typename T>
_FORCE_INLINE_ T _interpolate(const Vector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok, bool p_backward = false) const; _FORCE_INLINE_ T _interpolate(const LocalVector<TKey<T>> &p_keys, double p_time, InterpolationType p_interp, bool p_loop_wrap, bool *p_ok, bool p_backward = false) const;
template <typename T> template <typename T>
_FORCE_INLINE_ void _track_get_key_indices_in_range(const Vector<T> &p_array, double from_time, double to_time, List<int> *p_indices, bool p_is_backward) const; _FORCE_INLINE_ void _track_get_key_indices_in_range(const LocalVector<T> &p_array, double from_time, double to_time, List<int> *p_indices, bool p_is_backward) const;
double length = 1.0; double length = 1.0;
real_t step = DEFAULT_STEP; real_t step = DEFAULT_STEP;
@ -408,7 +408,7 @@ public:
int add_track(TrackType p_type, int p_at_pos = -1); int add_track(TrackType p_type, int p_at_pos = -1);
void remove_track(int p_track); void remove_track(int p_track);
_FORCE_INLINE_ const Vector<Track *> get_tracks() { _FORCE_INLINE_ const LocalVector<Track *> &get_tracks() {
return tracks; return tracks;
} }