Add templated version of ObjectDB::get_instance()

This commit is contained in:
kobewi
2025-03-27 14:42:42 +01:00
parent 594d64ec24
commit bc9d0c7835
49 changed files with 121 additions and 104 deletions

View File

@@ -997,7 +997,7 @@ Variant AnimationMixer::_post_process_key_value(const Ref<Animation> &p_anim, in
switch (p_anim->track_get_type(p_track)) {
case Animation::TYPE_POSITION_3D: {
if (p_object_sub_idx >= 0) {
Skeleton3D *skel = Object::cast_to<Skeleton3D>(ObjectDB::get_instance(p_object_id));
Skeleton3D *skel = ObjectDB::get_instance<Skeleton3D>(p_object_id);
if (skel) {
return Vector3(p_value) * skel->get_motion_scale();
}
@@ -1867,7 +1867,7 @@ void AnimationMixer::_blend_apply() {
root_motion_rotation_accumulator = t->rot;
root_motion_scale_accumulator = t->scale;
} else if (t->skeleton_id.is_valid() && t->bone_idx >= 0) {
Skeleton3D *t_skeleton = Object::cast_to<Skeleton3D>(ObjectDB::get_instance(t->skeleton_id));
Skeleton3D *t_skeleton = ObjectDB::get_instance<Skeleton3D>(t->skeleton_id);
if (!t_skeleton) {
return;
}
@@ -1882,7 +1882,7 @@ void AnimationMixer::_blend_apply() {
}
} else if (!t->skeleton_id.is_valid()) {
Node3D *t_node_3d = Object::cast_to<Node3D>(ObjectDB::get_instance(t->object_id));
Node3D *t_node_3d = ObjectDB::get_instance<Node3D>(t->object_id);
if (!t_node_3d) {
return;
}
@@ -1902,7 +1902,7 @@ void AnimationMixer::_blend_apply() {
#ifndef _3D_DISABLED
TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
MeshInstance3D *t_mesh_3d = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(t->object_id));
MeshInstance3D *t_mesh_3d = ObjectDB::get_instance<MeshInstance3D>(t->object_id);
if (t_mesh_3d) {
t_mesh_3d->set_blend_shape_value(t->shape_index, t->value);
}
@@ -2131,7 +2131,7 @@ void AnimationMixer::_build_backup_track_cache() {
if (t->root_motion) {
// Do nothing.
} else if (t->skeleton_id.is_valid() && t->bone_idx >= 0) {
Skeleton3D *t_skeleton = Object::cast_to<Skeleton3D>(ObjectDB::get_instance(t->skeleton_id));
Skeleton3D *t_skeleton = ObjectDB::get_instance<Skeleton3D>(t->skeleton_id);
if (!t_skeleton) {
return;
}
@@ -2145,7 +2145,7 @@ void AnimationMixer::_build_backup_track_cache() {
t->scale = t_skeleton->get_bone_pose_scale(t->bone_idx);
}
} else if (!t->skeleton_id.is_valid()) {
Node3D *t_node_3d = Object::cast_to<Node3D>(ObjectDB::get_instance(t->object_id));
Node3D *t_node_3d = ObjectDB::get_instance<Node3D>(t->object_id);
if (!t_node_3d) {
return;
}
@@ -2164,7 +2164,7 @@ void AnimationMixer::_build_backup_track_cache() {
case Animation::TYPE_BLEND_SHAPE: {
#ifndef _3D_DISABLED
TrackCacheBlendShape *t = static_cast<TrackCacheBlendShape *>(track);
MeshInstance3D *t_mesh_3d = Object::cast_to<MeshInstance3D>(ObjectDB::get_instance(t->object_id));
MeshInstance3D *t_mesh_3d = ObjectDB::get_instance<MeshInstance3D>(t->object_id);
if (t_mesh_3d) {
t->value = t_mesh_3d->get_blend_shape_value(t->shape_index);
}

View File

@@ -63,7 +63,7 @@ void Tweener::start() {
}
Ref<Tween> Tweener::_get_tween() {
return Ref<Tween>(ObjectDB::get_instance(tween_id));
return ObjectDB::get_ref<Tween>(tween_id);
}
void Tweener::_finish() {
@@ -432,7 +432,7 @@ bool Tween::can_process(bool p_tree_paused) const {
Node *Tween::get_bound_node() const {
if (is_bound) {
return Object::cast_to<Node>(ObjectDB::get_instance(bound_node));
return ObjectDB::get_instance<Node>(bound_node);
} else {
return nullptr;
}