ksys/phys: Fix accuracy issue for storeToVec3

Allows us to get rid of a bunch of local variables that only existed
to force the entire vector to be loaded.
This commit is contained in:
Léo Lam 2022-03-03 11:50:09 +01:00
parent b2a66ca858
commit 26f4aea77c
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 10 additions and 17 deletions

View File

@ -1312,8 +1312,7 @@ void RigidBody::getCenterOfMassInWorld(sead::Vector3f* center) const {
center->setMul(transform, local_center);
} else {
auto hk_center = getMotion()->getCenterOfMassInWorld();
storeToVec3(center, hk_center);
storeToVec3(center, getMotion()->getCenterOfMassInWorld());
}
}

View File

@ -120,8 +120,7 @@ void RigidBodyMotionEntity::setCenterOfMassInLocal(const sead::Vector3f& center)
}
void RigidBodyMotionEntity::getCenterOfMassInLocal(sead::Vector3f* center) {
const auto hk_center = mMotion->getCenterOfMassLocal();
storeToVec3(center, hk_center);
storeToVec3(center, mMotion->getCenterOfMassLocal());
}
bool RigidBodyMotionEntity::setLinearVelocity(const sead::Vector3f& velocity, float epsilon) {
@ -147,8 +146,7 @@ bool RigidBodyMotionEntity::setLinearVelocity(const hkVector4f& velocity, float
void RigidBodyMotionEntity::getLinearVelocity(sead::Vector3f* velocity) {
auto* motion = getHkBodyMotionOrLocalMotionIf(RigidBody::MotionFlag::DirtyLinearVelocity);
const auto hk_vel = motion->getLinearVelocity();
storeToVec3(velocity, hk_vel);
storeToVec3(velocity, motion->getLinearVelocity());
}
bool RigidBodyMotionEntity::setAngularVelocity(const sead::Vector3f& velocity, float epsilon) {
@ -174,8 +172,7 @@ bool RigidBodyMotionEntity::setAngularVelocity(const hkVector4f& velocity, float
void RigidBodyMotionEntity::getAngularVelocity(sead::Vector3f* velocity) {
auto* motion = getHkBodyMotionOrLocalMotionIf(RigidBody::MotionFlag::DirtyAngularVelocity);
const auto hk_vel = motion->getAngularVelocity();
storeToVec3(velocity, hk_vel);
storeToVec3(velocity, motion->getAngularVelocity());
}
void RigidBodyMotionEntity::setMaxLinearVelocity(float max) {

View File

@ -156,8 +156,7 @@ void RigidBodyMotionSensor::getPosition(sead::Vector3f* position) {
if (hasMotionFlagSet(RigidBody::MotionFlag::DirtyTransform)) {
mTransform.getTranslation(*position);
} else {
const auto hk_position = getRigidBodyMotion()->getPosition();
storeToVec3(position, hk_position);
storeToVec3(position, getRigidBodyMotion()->getPosition());
}
}
@ -196,8 +195,7 @@ void RigidBodyMotionSensor::getCenterOfMassInLocal(sead::Vector3f* center) {
if (hasMotionFlagSet(RigidBody::MotionFlag::DirtyCenterOfMassLocal)) {
center->e = mCenterOfMassInLocal.e;
} else {
const auto hk_center = getRigidBodyMotion()->getCenterOfMassLocal();
storeToVec3(center, hk_center);
storeToVec3(center, getRigidBodyMotion()->getCenterOfMassLocal());
}
}
@ -220,8 +218,7 @@ void RigidBodyMotionSensor::getLinearVelocity(sead::Vector3f* velocity) {
if (hasMotionFlagSet(RigidBody::MotionFlag::DirtyLinearVelocity)) {
velocity->e = mLinearVelocity.e;
} else {
const auto hk_velocity = getRigidBodyMotion()->getLinearVelocity();
storeToVec3(velocity, hk_velocity);
storeToVec3(velocity, getRigidBodyMotion()->getLinearVelocity());
}
}
@ -244,8 +241,7 @@ void RigidBodyMotionSensor::getAngularVelocity(sead::Vector3f* velocity) {
if (hasMotionFlagSet(RigidBody::MotionFlag::DirtyAngularVelocity)) {
velocity->e = mAngularVelocity.e;
} else {
const auto hk_velocity = getRigidBodyMotion()->getAngularVelocity();
storeToVec3(velocity, hk_velocity);
storeToVec3(velocity, getRigidBodyMotion()->getAngularVelocity());
}
}

View File

@ -25,7 +25,8 @@ inline void toHkVec4(hkVector4f* out, const sead::Vector3f& vec) {
return {vec.x, vec.y, vec.z};
}
inline void storeToVec3(sead::Vector3f* out, const hkVector4f& vec) {
// NOLINTNEXTLINE(performance-unnecessary-value-param)
inline void storeToVec3(sead::Vector3f* out, hkVector4f vec) {
vec.store<3>(out->e.data());
}