Skip to content

Commit

Permalink
Update libraries and adjust code to match again
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePixelGamer committed Jul 26, 2024
1 parent 96f611f commit de0fd08
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/Game/DLC/aocHardModeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ void HardModeManager::init_() {
}

void HardModeManager::nerfHpRestore(f32* hp) const {
*hp = sead::Mathf::max(*hp * getMultiplier(MultiplierType::HpRestore), 1.0f);
*hp = sead::Mathf::clampMin(*hp * getMultiplier(MultiplierType::HpRestore), 1.0f);
}

void HardModeManager::nerfHpRestore(s32* hp) const {
*hp = sead::Mathi::max(*hp * getMultiplier(MultiplierType::HpRestore), 1);
*hp = sead::Mathi::clampMin(*hp * getMultiplier(MultiplierType::HpRestore), 1);
}

void HardModeManager::modifyEnemyNoticeDuration(f32* value) const {
*value = sead::Mathf::max(*value * getMultiplier(MultiplierType::EnemyNoticeDuration), 0);
*value = sead::Mathf::clampMin(*value * getMultiplier(MultiplierType::EnemyNoticeDuration), 0);
}

bool HardModeManager::shouldCreateLifeRecoverInfo(ksys::act::Actor* actor) {
Expand Down
13 changes: 7 additions & 6 deletions src/KingSystem/Physics/RigidBody/Shape/Box/physBoxShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ BoxShape* BoxShape::make(const BoxShapeParam& param, sead::Heap* heap) {
hkpBoxShape* box = nullptr;
if (auto* storage = util::allocStorage<hkpBoxShape>(heap)) {
const auto radius = param.convex_radius;
const hkVector4f half_extents{sead::Mathf::max(param.extents.x / 2 - radius, 0.001),
sead::Mathf::max(param.extents.y / 2 - radius, 0.001),
sead::Mathf::max(param.extents.z / 2 - radius, 0.001)};
const hkVector4f half_extents{sead::Mathf::clampMin(param.extents.x / 2 - radius, 0.001),
sead::Mathf::clampMin(param.extents.y / 2 - radius, 0.001),
sead::Mathf::clampMin(param.extents.z / 2 - radius, 0.001)};
box = new (storage) hkpBoxShape(half_extents, radius);
}

Expand Down Expand Up @@ -122,9 +122,10 @@ const hkpShape* BoxShape::updateHavokShape() {
if (mFlags.isOn(Flag::Dirty)) {
{
const auto radius = mHavokShape->getRadius();
const sead::Vector3f half_extents{sead::Mathf::max(mExtents.x / 2 - radius, 0.001),
sead::Mathf::max(mExtents.y / 2 - radius, 0.001),
sead::Mathf::max(mExtents.z / 2 - radius, 0.001)};
const sead::Vector3f half_extents{
sead::Mathf::clampMin(mExtents.x / 2 - radius, 0.001),
sead::Mathf::clampMin(mExtents.y / 2 - radius, 0.001),
sead::Mathf::clampMin(mExtents.z / 2 - radius, 0.001)};
const auto ref_count = mHavokShape->getReferenceCount();
mHavokShape = new (mHavokShape) hkpBoxShape(toHkVec4(half_extents), radius);
mHavokShape->setReferenceCount(ref_count);
Expand Down
14 changes: 7 additions & 7 deletions src/KingSystem/Physics/RigidBody/physRigidBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ bool RigidBody::initMotionAccessorForDynamicMotion(sead::Heap* heap) {

hkMatrix3 inertia;
body->getInertiaLocal(inertia);
param.inertia = {sead::Mathf::max(inertia(0, 0), MinInertia),
sead::Mathf::max(inertia(1, 1), MinInertia),
sead::Mathf::max(inertia(2, 2), MinInertia)};
param.inertia = {sead::Mathf::clampMin(inertia(0, 0), MinInertia),
sead::Mathf::clampMin(inertia(1, 1), MinInertia),
sead::Mathf::clampMin(inertia(2, 2), MinInertia)};
param.center_of_mass = toVec3(body->getCenterOfMassLocal());
param.linear_damping = body->getLinearDamping();
param.angular_damping = body->getAngularDamping();
Expand Down Expand Up @@ -126,9 +126,9 @@ bool RigidBody::createMotion(hkpMaxSizeMotion* motion, MotionType motion_type,

case MotionType::Dynamic: {
hkMatrix3f inertia_local;
inertia_local.m_col0.set(sead::Mathf::max(param.inertia.x, MinInertia), 0, 0);
inertia_local.m_col1.set(0, sead::Mathf::max(param.inertia.y, MinInertia), 0);
inertia_local.m_col2.set(0, 0, sead::Mathf::max(param.inertia.z, MinInertia));
inertia_local.m_col0.set(sead::Mathf::clampMin(param.inertia.x, MinInertia), 0, 0);
inertia_local.m_col1.set(0, sead::Mathf::clampMin(param.inertia.y, MinInertia), 0);
inertia_local.m_col2.set(0, 0, sead::Mathf::clampMin(param.inertia.z, MinInertia));

hkpRigidBody::createDynamicRigidMotion(
hkpMotion::MOTION_DYNAMIC, position, rotation, param.mass, inertia_local,
Expand Down Expand Up @@ -1630,7 +1630,7 @@ bool RigidBody::isEntityMotionFlag80On() const {
void RigidBody::setColImpulseScale(float scale) {
if (!isEntity())
return;
scale = sead::Mathf::max(scale, 0.0);
scale = sead::Mathf::clampMin(scale, 0.0);
getEntityMotionAccessor()->setColImpulseScale(scale);
}

Expand Down
12 changes: 2 additions & 10 deletions src/KingSystem/Physics/RigidBody/physRigidBodyMotionEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,6 @@ float RigidBodyMotionEntity::getMassInv() const {
return mMotion->getMassInv();
}

static inline float max3(float a, float b, float c) {
return sead::Mathf::max(c, a > b ? a : b);
}

static inline float min3(float a, float b, float c) {
return sead::Mathf::min(a < b ? a : b, c);
}

void RigidBodyMotionEntity::setInertiaLocal(const sead::Vector3f& inertia) {
if (mBody->isCharacterControllerType())
return;
Expand All @@ -317,8 +309,8 @@ void RigidBodyMotionEntity::setInertiaLocal(const sead::Vector3f& inertia) {
return;
}

const float max = max3(inertia.x, inertia.y, inertia.z);
const float min = min3(inertia.x, inertia.y, inertia.z);
const float max = sead::Mathf::max3(inertia.x, inertia.y, inertia.z);
const float min = sead::Mathf::min3(inertia.x, inertia.y, inertia.z);
const float threshold = max * 0.8f;

bool need_to_recreate_motion = false;
Expand Down
17 changes: 9 additions & 8 deletions src/KingSystem/Physics/System/physContactMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,20 @@ void ContactMgr::setImpulseEntryContactInfo(RigidBody* body_a, RigidBody* body_b
const auto relative_vel = linvel_a - linvel_b;
const auto dot_neg = [&](const auto& vec) { return vec.dot(-contact_point_normal); };

float magnitude = is_flag_off ? sead::Mathf::max(0.0, relative_vel.dot(-contact_point_normal)) :
sead::Mathf::max(0.0, relative_vel.length());
float magnitude = is_flag_off ?
sead::Mathf::clampMin(0.0, relative_vel.dot(-contact_point_normal)) :
sead::Mathf::clampMin(0.0, relative_vel.length());

if (magnitude >= entry->magnitude) {
float i1, i2;
if (is_flag_off) {
i1 = sead::Mathf::min(sead::Mathf::max(0.0, dot_neg(linvel_a)), magnitude);
i2 = sead::Mathf::min(sead::Mathf::max(0.0, linvel_b.dot(contact_point_normal)),
sead::Mathf::max(0.0, dot_neg(relative_vel)));
i1 = sead::Mathf::min(sead::Mathf::clampMin(0.0, dot_neg(linvel_a)), magnitude);
i2 = sead::Mathf::min(sead::Mathf::clampMin(0.0, linvel_b.dot(contact_point_normal)),
sead::Mathf::clampMin(0.0, dot_neg(relative_vel)));
} else {
i1 = sead::Mathf::min(sead::Mathf::max(0.0, linvel_a.length()), magnitude);
i2 = sead::Mathf::min(sead::Mathf::max(0.0, linvel_b.length()),
sead::Mathf::max(0.0, relative_vel.length()));
i1 = sead::Mathf::min(sead::Mathf::clampMin(0.0, linvel_a.length()), magnitude);
i2 = sead::Mathf::min(sead::Mathf::clampMin(0.0, linvel_b.length()),
sead::Mathf::clampMin(0.0, relative_vel.length()));
}

entry->magnitude = magnitude;
Expand Down
4 changes: 2 additions & 2 deletions src/KingSystem/System/VFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ VFR::~VFR() {
}

void VFR::setDelta(u32 core, f32 delta) {
delta = sead::Mathf::max(delta, 0.01f);
delta = sead::Mathf::clampMin(delta, 0.01f);
*mRawDeltaFrames[core] = delta;
*mDeltaFrames[core] = delta * *mIntervalRatios[core];
*mRawDeltaTimes[core] = delta * mFrameTime;
Expand Down Expand Up @@ -111,7 +111,7 @@ void VFR::TimeSpeedMultiplier::update(f32 multiplier) {
if (target_value < value) {
value = target_value;
} else {
sead::Mathf::chase(&value, target_value, sead::Mathf::max(value * multiplier, 0.01));
sead::Mathf::chase(&value, target_value, sead::Mathf::clampMin(value * multiplier, 0.01));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/KingSystem/World/worldManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ float Manager::calcTempDay(float height) const {
float normal_temp = 23.0f;

if (isMainField() && worldInfoLoaded()) {
height = sead::Mathf::max(height, 0.0f);
height = sead::Mathf::clampMin(height, 0.0f);

int a = -1;
float h{};
Expand Down Expand Up @@ -182,7 +182,7 @@ float Manager::calcTempNight(float height) const {
float normal_temp = 23.0f;

if (isMainField() && worldInfoLoaded()) {
height = sead::Mathf::max(height, 0.0f);
height = sead::Mathf::clampMin(height, 0.0f);

int a = -1;
float h{};
Expand Down
2 changes: 1 addition & 1 deletion src/KingSystem/World/worldTimeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void TimeMgr::calc_() {
if (!mFindDungeonActivated && mTime >= 11_h)
mTime = 11_h;

_d0 = sead::Mathf::max(mTimeStep / DefaultTimeStep, 1.0);
_d0 = sead::Mathf::clampMin(mTimeStep / DefaultTimeStep, 1.0);
mBloodMoonTimer += delta;
break;
}
Expand Down

0 comments on commit de0fd08

Please sign in to comment.