mirror of https://github.com/AxioDL/metaforce.git
CGameProjectile: Return std::nullopt in GetTouchBounds()
Same behavior, but doesn't potentially unnecessary zero out the entirety of the buffer within the optional and only sets a single byte.
This commit is contained in:
parent
d47f8c2784
commit
b122fd30a8
|
@ -322,8 +322,9 @@ CRayCastResult CGameProjectile::RayCollisionCheckWithWorld(TUniqueId& idOut, con
|
||||||
CProjectileTouchResult CGameProjectile::CanCollideWith(CActor& act, CStateManager& mgr) const {
|
CProjectileTouchResult CGameProjectile::CanCollideWith(CActor& act, CStateManager& mgr) const {
|
||||||
if (act.GetDamageVulnerability()->GetVulnerability(x12c_curDamageInfo.GetWeaponMode(), false) ==
|
if (act.GetDamageVulnerability()->GetVulnerability(x12c_curDamageInfo.GetWeaponMode(), false) ==
|
||||||
EVulnerability::PassThrough) {
|
EVulnerability::PassThrough) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
} else {
|
}
|
||||||
|
|
||||||
if (TCastToConstPtr<CScriptTrigger>(act)) {
|
if (TCastToConstPtr<CScriptTrigger>(act)) {
|
||||||
return CanCollideWithTrigger(act, mgr);
|
return CanCollideWithTrigger(act, mgr);
|
||||||
} else if (TCastToConstPtr<CScriptPlatform>(act) || TCastToConstPtr<CCollisionActor>(act) ||
|
} else if (TCastToConstPtr<CScriptPlatform>(act) || TCastToConstPtr<CCollisionActor>(act) ||
|
||||||
|
@ -332,7 +333,6 @@ CProjectileTouchResult CGameProjectile::CanCollideWith(CActor& act, CStateManage
|
||||||
} else {
|
} else {
|
||||||
return CanCollideWithGameObject(act, mgr);
|
return CanCollideWithGameObject(act, mgr);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CProjectileTouchResult CGameProjectile::CanCollideWithComplexCollision(const CActor& act,
|
CProjectileTouchResult CGameProjectile::CanCollideWithComplexCollision(const CActor& act,
|
||||||
|
@ -346,29 +346,39 @@ CProjectileTouchResult CGameProjectile::CanCollideWithComplexCollision(const CAc
|
||||||
useAct = toad;
|
useAct = toad;
|
||||||
} else if (const TCastToConstPtr<CCollisionActor> cact = act) {
|
} else if (const TCastToConstPtr<CCollisionActor> cact = act) {
|
||||||
if (cact->GetOwnerId() == xec_ownerId) {
|
if (cact->GetOwnerId() == xec_ownerId) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
}
|
}
|
||||||
useAct = cact.GetPtr();
|
useAct = cact.GetPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useAct) {
|
if (!useAct) {
|
||||||
|
return {act.GetUniqueId(), std::nullopt};
|
||||||
|
}
|
||||||
|
|
||||||
const CCollisionPrimitive* prim = useAct->GetCollisionPrimitive();
|
const CCollisionPrimitive* prim = useAct->GetCollisionPrimitive();
|
||||||
zeus::CTransform xf = useAct->GetPrimitiveTransform();
|
const zeus::CTransform xf = useAct->GetPrimitiveTransform();
|
||||||
zeus::CVector3f deltaPos = GetTranslation() - x298_previousPos;
|
const zeus::CVector3f deltaPos = GetTranslation() - x298_previousPos;
|
||||||
if (deltaPos.canBeNormalized()) {
|
if (!deltaPos.canBeNormalized()) {
|
||||||
zeus::CVector3f dir = deltaPos.normalized();
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
|
}
|
||||||
|
|
||||||
|
const zeus::CVector3f dir = deltaPos.normalized();
|
||||||
float mag = deltaPos.magnitude();
|
float mag = deltaPos.magnitude();
|
||||||
CRayCastResult res = prim->CastRayInternal(
|
const CRayCastResult res = prim->CastRayInternal(
|
||||||
{x298_previousPos, dir, mag, xf,
|
{x298_previousPos, dir, mag, xf,
|
||||||
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
||||||
if (!res.IsValid()) {
|
if (res.IsValid()) {
|
||||||
|
return {act.GetUniqueId(), {res}};
|
||||||
|
}
|
||||||
|
|
||||||
if (prim->GetPrimType() == FOURCC('SPHR')) {
|
if (prim->GetPrimType() == FOURCC('SPHR')) {
|
||||||
mag *= 2.f;
|
mag *= 2.f;
|
||||||
CRayCastResult res2 = prim->CastRayInternal(
|
const CRayCastResult res2 = prim->CastRayInternal(
|
||||||
{x298_previousPos - dir * mag, dir, deltaPos.magnitude(), xf,
|
{x298_previousPos - dir * mag, dir, deltaPos.magnitude(), xf,
|
||||||
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
||||||
if (res2.IsValid())
|
if (res2.IsValid()) {
|
||||||
return {act.GetUniqueId(), {res2}};
|
return {act.GetUniqueId(), {res2}};
|
||||||
|
}
|
||||||
} else if (const TCastToConstPtr<CCollisionActor> cAct = act) {
|
} else if (const TCastToConstPtr<CCollisionActor> cAct = act) {
|
||||||
const float rad = cAct->GetSphereRadius();
|
const float rad = cAct->GetSphereRadius();
|
||||||
if ((x298_previousPos - GetTranslation()).magSquared() < rad * rad) {
|
if ((x298_previousPos - GetTranslation()).magSquared() < rad * rad) {
|
||||||
|
@ -377,42 +387,34 @@ CProjectileTouchResult CGameProjectile::CanCollideWithComplexCollision(const CAc
|
||||||
return {act.GetUniqueId(), {{0.f, point, {revDir, point.dot(revDir)}, act.GetMaterialList()}}};
|
return {act.GetUniqueId(), {{0.f, point, {revDir, point.dot(revDir)}, act.GetMaterialList()}}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {kInvalidUniqueId, {}};
|
|
||||||
} else {
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
return {act.GetUniqueId(), {res}};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {kInvalidUniqueId, {}};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {act.GetUniqueId(), {}};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CProjectileTouchResult CGameProjectile::CanCollideWithGameObject(CActor& act, CStateManager& mgr) const {
|
CProjectileTouchResult CGameProjectile::CanCollideWithGameObject(CActor& act, CStateManager& mgr) const {
|
||||||
const TCastToConstPtr<CGameProjectile> proj = act;
|
const TCastToConstPtr<CGameProjectile> proj = act;
|
||||||
if (!proj) {
|
if (!proj) {
|
||||||
if (!act.GetMaterialList().HasMaterial(EMaterialTypes::Solid) && !act.HealthInfo(mgr)) {
|
if (!act.GetMaterialList().HasMaterial(EMaterialTypes::Solid) && !act.HealthInfo(mgr)) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
} else if (act.GetUniqueId() == xec_ownerId) {
|
} else if (act.GetUniqueId() == xec_ownerId) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
} else if (act.GetUniqueId() == x2c2_lastResolvedObj) {
|
} else if (act.GetUniqueId() == x2c2_lastResolvedObj) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
} else if (xf8_filter.GetExcludeList().Intersection(act.GetMaterialList())) {
|
} else if (xf8_filter.GetExcludeList().Intersection(act.GetMaterialList())) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
} else if (TCastToPtr<CAi> ai = act) {
|
} else if (TCastToPtr<CAi> ai = act) {
|
||||||
if (!ai->CanBeShot(mgr, int(xe8_projectileAttribs))) {
|
if (!ai->CanBeShot(mgr, int(xe8_projectileAttribs))) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((xe8_projectileAttribs & EProjectileAttrib::PartialCharge) == EProjectileAttrib::PartialCharge ||
|
} else if ((xe8_projectileAttribs & EProjectileAttrib::PartialCharge) == EProjectileAttrib::PartialCharge ||
|
||||||
(proj->xe8_projectileAttribs & EProjectileAttrib::PartialCharge) == EProjectileAttrib::PartialCharge) {
|
(proj->xe8_projectileAttribs & EProjectileAttrib::PartialCharge) == EProjectileAttrib::PartialCharge) {
|
||||||
return {act.GetUniqueId(), {}};
|
return {act.GetUniqueId(), std::nullopt};
|
||||||
} else if ((xe8_projectileAttribs & EProjectileAttrib::PartialCharge) != EProjectileAttrib::PartialCharge &&
|
} else if ((xe8_projectileAttribs & EProjectileAttrib::PartialCharge) != EProjectileAttrib::PartialCharge &&
|
||||||
(proj->xe8_projectileAttribs & EProjectileAttrib::PartialCharge) != EProjectileAttrib::PartialCharge) {
|
(proj->xe8_projectileAttribs & EProjectileAttrib::PartialCharge) != EProjectileAttrib::PartialCharge) {
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
}
|
}
|
||||||
return {act.GetUniqueId(), {}};
|
return {act.GetUniqueId(), std::nullopt};
|
||||||
}
|
}
|
||||||
|
|
||||||
CProjectileTouchResult CGameProjectile::CanCollideWithTrigger(const CActor& act, const CStateManager& mgr) const {
|
CProjectileTouchResult CGameProjectile::CanCollideWithTrigger(const CActor& act, const CStateManager& mgr) const {
|
||||||
|
@ -431,9 +433,9 @@ CProjectileTouchResult CGameProjectile::CanCollideWithTrigger(const CActor& act,
|
||||||
leftWater = true;
|
leftWater = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {(enteredWater || leftWater) ? act.GetUniqueId() : kInvalidUniqueId, {}};
|
return {(enteredWater || leftWater) ? act.GetUniqueId() : kInvalidUniqueId, std::nullopt};
|
||||||
}
|
}
|
||||||
return {kInvalidUniqueId, {}};
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CAABox CGameProjectile::GetProjectileBounds() const {
|
zeus::CAABox CGameProjectile::GetProjectileBounds() const {
|
||||||
|
@ -446,9 +448,10 @@ zeus::CAABox CGameProjectile::GetProjectileBounds() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<zeus::CAABox> CGameProjectile::GetTouchBounds() const {
|
std::optional<zeus::CAABox> CGameProjectile::GetTouchBounds() const {
|
||||||
if (x2e4_24_active)
|
if (x2e4_24_active) {
|
||||||
return {GetProjectileBounds()};
|
return {GetProjectileBounds()};
|
||||||
return {};
|
}
|
||||||
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
Loading…
Reference in New Issue