mirror of
https://github.com/zeldaret/botw
synced 2026-08-19 13:33:23 -04:00
ksys/phys: Use named bools in RigidBody to improve call site readability
This commit is contained in:
@@ -33,7 +33,7 @@ void KorokTargetMove::calc_() {
|
||||
auto* actor = mActor;
|
||||
auto* body = actor->getMainBody();
|
||||
if (*mIsBezier_d || *mIsTargetWarp_m) {
|
||||
body->setPosition(*mTargetPos_d, true);
|
||||
body->setPosition(*mTargetPos_d);
|
||||
setFinished();
|
||||
return;
|
||||
}
|
||||
@@ -42,7 +42,7 @@ void KorokTargetMove::calc_() {
|
||||
sead::Vector3f pos(mtx(0, 3), mtx(1, 3), mtx(2, 3));
|
||||
|
||||
ksys::VFR::chaseVec(&pos, *mTargetPos_d, *mSpeed_d);
|
||||
body->changePosition(pos, true);
|
||||
body->changePosition(pos, ksys::phys::KeepAngularVelocity{true});
|
||||
|
||||
sead::Vector3f t = pos - *mTargetPos_d;
|
||||
if (t.length() < *mSpeed_d) {
|
||||
|
||||
@@ -139,7 +139,7 @@ void RagdollController::setTransform(const hkQsTransformf& transform) {
|
||||
if (mExtraRigidBody) {
|
||||
sead::Matrix34f old_transform;
|
||||
mRigidBodies[mRigidBodyIndex]->getTransform(&old_transform);
|
||||
mExtraRigidBody->setTransform(old_transform, true);
|
||||
mExtraRigidBody->setTransform(old_transform);
|
||||
|
||||
if (mGroupHandler) {
|
||||
mExtraRigidBody->setCollisionFilterInfo(
|
||||
|
||||
@@ -476,9 +476,10 @@ void RigidBody::setContactPointInfo(ContactPointInfo* info) {
|
||||
System::instance()->registerContactPointInfo(info);
|
||||
}
|
||||
|
||||
void RigidBody::freeze(bool should_freeze, bool preserve_velocities, bool preserve_max_impulse) {
|
||||
if (hasFlag(Flag::Frozen) == should_freeze) {
|
||||
if (should_freeze) {
|
||||
void RigidBody::freeze(ShouldFreeze should_freeze, PreserveVelocities preserve_velocities,
|
||||
PreserveMaxImpulse preserve_max_impulse) {
|
||||
if (hasFlag(Flag::Frozen) == bool(should_freeze)) {
|
||||
if (bool(should_freeze)) {
|
||||
setLinearVelocity(sead::Vector3f::zero);
|
||||
setAngularVelocity(sead::Vector3f::zero);
|
||||
}
|
||||
@@ -486,41 +487,43 @@ void RigidBody::freeze(bool should_freeze, bool preserve_velocities, bool preser
|
||||
}
|
||||
|
||||
if (!mMotionAccessor) {
|
||||
mFlags.change(Flag::Frozen, should_freeze);
|
||||
mFlags.change(Flag::Frozen, bool(should_freeze));
|
||||
return;
|
||||
}
|
||||
|
||||
if (should_freeze) {
|
||||
mMotionAccessor->freeze(true, preserve_velocities, preserve_max_impulse);
|
||||
if (bool(should_freeze)) {
|
||||
mMotionAccessor->freeze(true, bool(preserve_velocities), bool(preserve_max_impulse));
|
||||
mFlags.set(Flag::Frozen);
|
||||
} else {
|
||||
mFlags.reset(Flag::Frozen);
|
||||
mMotionAccessor->freeze(false, preserve_velocities, preserve_max_impulse);
|
||||
mMotionAccessor->freeze(false, bool(preserve_velocities), bool(preserve_max_impulse));
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBody::setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty) {
|
||||
if (hasFlag(Flag::FixedWithImpulsePreserved) != fixed) {
|
||||
mFlags.change(Flag::FixedWithImpulsePreserved, fixed);
|
||||
if (!fixed && mark_linear_vel_as_dirty) {
|
||||
void RigidBody::setFixedAndPreserveImpulse(Fixed fixed,
|
||||
MarkLinearVelAsDirty mark_linear_vel_as_dirty) {
|
||||
if (hasFlag(Flag::FixedWithImpulsePreserved) != bool(fixed)) {
|
||||
mFlags.change(Flag::FixedWithImpulsePreserved, bool(fixed));
|
||||
if (!bool(fixed) && bool(mark_linear_vel_as_dirty)) {
|
||||
setMotionFlag(MotionFlag::DirtyLinearVelocity);
|
||||
}
|
||||
}
|
||||
|
||||
freeze(hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed), true, true);
|
||||
freeze(ShouldFreeze{hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed)},
|
||||
PreserveVelocities{true}, PreserveMaxImpulse{true});
|
||||
}
|
||||
|
||||
void RigidBody::setFixed(bool fixed, bool preserve_velocities) {
|
||||
if (hasFlag(Flag::Fixed) != fixed) {
|
||||
mFlags.change(Flag::Fixed, fixed);
|
||||
if (!fixed) {
|
||||
void RigidBody::setFixed(Fixed fixed, PreserveVelocities preserve_velocities) {
|
||||
if (hasFlag(Flag::Fixed) != bool(fixed)) {
|
||||
mFlags.change(Flag::Fixed, bool(fixed));
|
||||
if (!bool(fixed)) {
|
||||
setMotionFlag(MotionFlag::DirtyLinearVelocity);
|
||||
setMotionFlag(MotionFlag::_40000);
|
||||
}
|
||||
}
|
||||
|
||||
freeze(hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed), preserve_velocities,
|
||||
false);
|
||||
freeze(ShouldFreeze{hasFlag(Flag::FixedWithImpulsePreserved) || hasFlag(Flag::Fixed)},
|
||||
preserve_velocities, PreserveMaxImpulse{false});
|
||||
}
|
||||
|
||||
void RigidBody::resetFrozenState() {
|
||||
@@ -835,13 +838,14 @@ void RigidBody::setColor(const sead::Color4f& color, const void* a, bool b) {
|
||||
// (which are normally invisible).
|
||||
}
|
||||
|
||||
void RigidBody::setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions) {
|
||||
void RigidBody::setPosition(const sead::Vector3f& position,
|
||||
PropagateToLinkedMotions propagate_to_linked_motions) {
|
||||
if (util::isVectorInvalid(position)) {
|
||||
onInvalidParameter();
|
||||
return;
|
||||
}
|
||||
|
||||
mMotionAccessor->setPosition(position, propagate_to_linked_motions);
|
||||
mMotionAccessor->setPosition(position, bool(propagate_to_linked_motions));
|
||||
}
|
||||
|
||||
void RigidBody::getPosition(sead::Vector3f* position) const {
|
||||
@@ -888,13 +892,14 @@ sead::Matrix34f RigidBody::getTransform() const {
|
||||
return transform;
|
||||
}
|
||||
|
||||
void RigidBody::setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions) {
|
||||
void RigidBody::setTransform(const sead::Matrix34f& mtx,
|
||||
PropagateToLinkedMotions propagate_to_linked_motions) {
|
||||
if (util::isMatrixInvalid(mtx)) {
|
||||
onInvalidParameter();
|
||||
return;
|
||||
}
|
||||
|
||||
mMotionAccessor->setTransform(mtx, propagate_to_linked_motions);
|
||||
mMotionAccessor->setTransform(mtx, bool(propagate_to_linked_motions));
|
||||
}
|
||||
|
||||
bool RigidBody::isTransformDirty() const {
|
||||
@@ -1111,14 +1116,15 @@ void RigidBody::changePositionAndRotation(const sead::Matrix34f& transform, floa
|
||||
mMotionAccessor->setAngularVelocity(angular_velocity, epsilon);
|
||||
}
|
||||
|
||||
void RigidBody::changePosition(const sead::Vector3f& target_position, bool keep_angular_velocity,
|
||||
float epsilon) {
|
||||
void RigidBody::changePosition(const sead::Vector3f& target_position,
|
||||
KeepAngularVelocity keep_angular_velocity, float epsilon) {
|
||||
hkVector4f velocity;
|
||||
computeLinearVelocity(&velocity, target_position, keep_angular_velocity);
|
||||
computeLinearVelocity(&velocity, target_position,
|
||||
TakeAngularVelocityIntoAccount{bool(keep_angular_velocity)});
|
||||
|
||||
mMotionAccessor->setLinearVelocity(velocity, epsilon);
|
||||
|
||||
if (!keep_angular_velocity)
|
||||
if (!bool(keep_angular_velocity))
|
||||
mMotionAccessor->setAngularVelocity(sead::Vector3f::zero, epsilon);
|
||||
}
|
||||
|
||||
@@ -1189,13 +1195,13 @@ void RigidBody::computeLinearVelocity(hkVector4f* velocity, const hkVector4f& ta
|
||||
velocity->mul(inv_delta_time);
|
||||
}
|
||||
|
||||
KSYS_ALWAYS_INLINE void RigidBody::computeLinearVelocity(hkVector4f* velocity,
|
||||
const hkVector4f& target_position,
|
||||
bool take_angular_velocity_into_account,
|
||||
float inv_delta_time) const {
|
||||
KSYS_ALWAYS_INLINE void
|
||||
RigidBody::computeLinearVelocity(hkVector4f* velocity, const hkVector4f& target_position,
|
||||
TakeAngularVelocityIntoAccount take_angular_velocity_into_account,
|
||||
float inv_delta_time) const {
|
||||
auto hk_current_pos = toHkVec4(getPosition());
|
||||
|
||||
if (take_angular_velocity_into_account) {
|
||||
if (bool(take_angular_velocity_into_account)) {
|
||||
const auto center = getCenterOfMassInLocal();
|
||||
if (center.x == 0 && center.y == 0 && center.z == 0) {
|
||||
hkVector4f rel_pos;
|
||||
@@ -1212,18 +1218,18 @@ KSYS_ALWAYS_INLINE void RigidBody::computeLinearVelocity(hkVector4f* velocity,
|
||||
velocity->mul(inv_delta_time);
|
||||
}
|
||||
|
||||
KSYS_ALWAYS_INLINE void
|
||||
RigidBody::computeLinearVelocity(hkVector4f* velocity, const sead::Vector3f& target_position,
|
||||
bool take_angular_velocity_into_account) const {
|
||||
KSYS_ALWAYS_INLINE void RigidBody::computeLinearVelocity(
|
||||
hkVector4f* velocity, const sead::Vector3f& target_position,
|
||||
TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const {
|
||||
const float inv_delta_time = getInvDeltaTime();
|
||||
const auto hk_target_pos = toHkVec4(target_position);
|
||||
computeLinearVelocity(velocity, hk_target_pos, take_angular_velocity_into_account,
|
||||
inv_delta_time);
|
||||
}
|
||||
|
||||
void RigidBody::computeLinearVelocity(sead::Vector3f* velocity,
|
||||
const sead::Vector3f& target_position,
|
||||
bool take_angular_velocity_into_account) const {
|
||||
void RigidBody::computeLinearVelocity(
|
||||
sead::Vector3f* velocity, const sead::Vector3f& target_position,
|
||||
TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const {
|
||||
hkVector4f result;
|
||||
computeLinearVelocity(&result, target_position, take_angular_velocity_into_account);
|
||||
storeToVec3(velocity, result);
|
||||
@@ -1744,7 +1750,7 @@ void* RigidBody::m11() {
|
||||
void RigidBody::onMaxPositionExceeded() {
|
||||
// debug logging?
|
||||
[[maybe_unused]] sead::Vector3f position = getPosition();
|
||||
setPosition(sead::Vector3f::zero, true);
|
||||
setPosition(sead::Vector3f::zero, PropagateToLinkedMotions{true});
|
||||
}
|
||||
|
||||
const char* RigidBody::getName() {
|
||||
|
||||
@@ -34,6 +34,15 @@ class RigidBodyMotionSensor;
|
||||
class SystemGroupHandler;
|
||||
class UserTag;
|
||||
|
||||
enum class ShouldFreeze : bool;
|
||||
enum class PreserveVelocities : bool;
|
||||
enum class PreserveMaxImpulse : bool;
|
||||
enum class Fixed : bool;
|
||||
enum class MarkLinearVelAsDirty : bool;
|
||||
enum class PropagateToLinkedMotions : bool;
|
||||
enum class KeepAngularVelocity : bool;
|
||||
enum class TakeAngularVelocityIntoAccount : bool;
|
||||
|
||||
class RigidBase {
|
||||
public:
|
||||
virtual ~RigidBase() = default;
|
||||
@@ -201,9 +210,10 @@ public:
|
||||
ContactPointInfo* getContactPointInfo() const { return mContactPointInfo; }
|
||||
void setContactPointInfo(ContactPointInfo* info);
|
||||
|
||||
void freeze(bool should_freeze, bool preserve_velocities, bool preserve_max_impulse);
|
||||
void setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty);
|
||||
void setFixed(bool fixed, bool preserve_velocities);
|
||||
void freeze(ShouldFreeze should_freeze, PreserveVelocities preserve_velocities,
|
||||
PreserveMaxImpulse preserve_max_impulse);
|
||||
void setFixedAndPreserveImpulse(Fixed fixed, MarkLinearVelAsDirty mark_linear_vel_as_dirty);
|
||||
void setFixed(Fixed fixed, PreserveVelocities preserve_velocities);
|
||||
void resetFrozenState();
|
||||
|
||||
// 0x0000007100f8ee50 - FIXME: figure out what type is
|
||||
@@ -282,7 +292,9 @@ public:
|
||||
|
||||
void setColor(const sead::Color4f& color, const void* a, bool b);
|
||||
|
||||
void setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions);
|
||||
void setPosition(
|
||||
const sead::Vector3f& position,
|
||||
PropagateToLinkedMotions propagate_to_linked_motions = PropagateToLinkedMotions{true});
|
||||
void getPosition(sead::Vector3f* position) const;
|
||||
sead::Vector3f getPosition() const;
|
||||
virtual void onImpulse(RigidBody* body_b, float impulse) const;
|
||||
@@ -296,7 +308,9 @@ public:
|
||||
|
||||
void getTransform(sead::Matrix34f* mtx) const;
|
||||
sead::Matrix34f getTransform() const;
|
||||
void setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions);
|
||||
void setTransform(
|
||||
const sead::Matrix34f& mtx,
|
||||
PropagateToLinkedMotions propagate_to_linked_motions = PropagateToLinkedMotions{true});
|
||||
bool isTransformDirty() const;
|
||||
|
||||
void updateShape();
|
||||
@@ -332,7 +346,8 @@ public:
|
||||
/// Modify the body's position by changing the linear velocity.
|
||||
/// This is preferable to setting the position directly (see changePositionAndRotation for an
|
||||
/// explanation).
|
||||
void changePosition(const sead::Vector3f& target_position, bool keep_angular_velocity,
|
||||
void changePosition(const sead::Vector3f& target_position,
|
||||
KeepAngularVelocity keep_angular_velocity,
|
||||
float epsilon = sead::Mathf::epsilon());
|
||||
|
||||
/// Modify the body's rotation by changing the angular velocity.
|
||||
@@ -361,13 +376,16 @@ public:
|
||||
const hkQuaternionf& rotation, float inv_delta_time) const;
|
||||
/// Compute the linear velocity that would be necessary to instantly reach the target position.
|
||||
void computeLinearVelocity(hkVector4f* velocity, const hkVector4f& target_position,
|
||||
bool take_angular_velocity_into_account, float inv_delta_time) const;
|
||||
TakeAngularVelocityIntoAccount take_angular_velocity_into_account,
|
||||
float inv_delta_time) const;
|
||||
/// Compute the linear velocity that would be necessary to instantly reach the target position.
|
||||
void computeLinearVelocity(hkVector4f* velocity, const sead::Vector3f& target_position,
|
||||
bool take_angular_velocity_into_account) const;
|
||||
void
|
||||
computeLinearVelocity(hkVector4f* velocity, const sead::Vector3f& target_position,
|
||||
TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const;
|
||||
/// Compute the linear velocity that would be necessary to instantly reach the target position.
|
||||
void computeLinearVelocity(sead::Vector3f* velocity, const sead::Vector3f& target_position,
|
||||
bool take_angular_velocity_into_account) const;
|
||||
void
|
||||
computeLinearVelocity(sead::Vector3f* velocity, const sead::Vector3f& target_position,
|
||||
TakeAngularVelocityIntoAccount take_angular_velocity_into_account) const;
|
||||
|
||||
/// Compute the linear and angular velocities that would be necessary to instantly reach the
|
||||
/// target position and rotation.
|
||||
|
||||
@@ -624,7 +624,7 @@ void RigidBodyMotionEntity::copyTransformToAllLinkedBodies() {
|
||||
if (!body->isAddedToWorld() && body->isAddingBodyToWorld()) {
|
||||
sead::Matrix34f transform;
|
||||
mBody->getTransform(&transform);
|
||||
body->setTransform(transform, true);
|
||||
body->setTransform(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ RigidBodySet::~RigidBodySet() {
|
||||
util::PrintDebug("~RigidBodySet");
|
||||
}
|
||||
|
||||
void RigidBodySet::setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty) {
|
||||
void RigidBodySet::setFixedAndPreserveImpulse(Fixed fixed,
|
||||
MarkLinearVelAsDirty mark_linear_vel_as_dirty) {
|
||||
for (auto& body : mRigidBodies)
|
||||
body.setFixedAndPreserveImpulse(fixed, mark_linear_vel_as_dirty);
|
||||
}
|
||||
@@ -36,7 +37,7 @@ void RigidBodySet::setEntityMotionFlag200(bool set) {
|
||||
body.setEntityMotionFlag200(set);
|
||||
}
|
||||
|
||||
void RigidBodySet::setFixed(bool fixed, bool preserve_velocities) {
|
||||
void RigidBodySet::setFixed(Fixed fixed, PreserveVelocities preserve_velocities) {
|
||||
for (auto& body : mRigidBodies)
|
||||
body.setFixed(fixed, preserve_velocities);
|
||||
}
|
||||
@@ -107,7 +108,7 @@ void RigidBodySet::setSystemGroupHandler(SystemGroupHandler* handler, ContactLay
|
||||
|
||||
void RigidBodySet::setTransform(const sead::Matrix34f& mtx) {
|
||||
for (auto& body : mRigidBodies)
|
||||
body.setTransform(mtx, true);
|
||||
body.setTransform(mtx);
|
||||
}
|
||||
|
||||
void RigidBodySet::enableContactLayer(ContactLayer layer) {
|
||||
|
||||
@@ -13,6 +13,10 @@ class RigidBody;
|
||||
class SystemGroupHandler;
|
||||
class UserTag;
|
||||
|
||||
enum class Fixed : bool;
|
||||
enum class MarkLinearVelAsDirty : bool;
|
||||
enum class PreserveVelocities : bool;
|
||||
|
||||
class RigidBodySet : public sead::hostio::Node {
|
||||
public:
|
||||
explicit RigidBodySet(const sead::SafeString& name);
|
||||
@@ -24,12 +28,12 @@ public:
|
||||
const sead::PtrArray<RigidBody>& getRigidBodies() const { return mRigidBodies; }
|
||||
RigidBody* getRigidBody(int idx) const { return mRigidBodies[idx]; }
|
||||
|
||||
void setFixedAndPreserveImpulse(bool fixed, bool mark_linear_vel_as_dirty);
|
||||
void setFixedAndPreserveImpulse(Fixed fixed, MarkLinearVelAsDirty mark_linear_vel_as_dirty);
|
||||
void resetFrozenState();
|
||||
void setUseSystemTimeFactor(bool use);
|
||||
void clearFlag400000(bool clear);
|
||||
void setEntityMotionFlag200(bool set);
|
||||
void setFixed(bool fixed, bool preserve_velocities);
|
||||
void setFixed(Fixed fixed, PreserveVelocities preserve_velocities);
|
||||
|
||||
void updateMotionTypeRelatedFlags();
|
||||
void triggerScheduledMotionTypeChange();
|
||||
|
||||
@@ -126,7 +126,7 @@ void StaticCompoundRigidBodyGroup::addToWorld() {
|
||||
|
||||
auto lock = body->makeScopedLock();
|
||||
|
||||
body->setTransform(getTransform(), true);
|
||||
body->setTransform(getTransform());
|
||||
|
||||
if (body->getMotionFlags().isOn(RigidBody::MotionFlag::BodyRemovalRequested)) {
|
||||
body->resetMotionFlagDirect(RigidBody::MotionFlag::BodyRemovalRequested);
|
||||
@@ -204,7 +204,7 @@ void StaticCompoundRigidBodyGroup::applyExtraTransforms() {
|
||||
}
|
||||
|
||||
for (int i = 0, n = mRigidBodies.size(); i < n; ++i) {
|
||||
mRigidBodies[i]->setTransform(getTransform(), true);
|
||||
mRigidBodies[i]->setTransform(getTransform());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user