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,16 +322,16 @@ 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};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TCastToConstPtr<CScriptTrigger>(act)) {
|
||||||
|
return CanCollideWithTrigger(act, mgr);
|
||||||
|
} else if (TCastToConstPtr<CScriptPlatform>(act) || TCastToConstPtr<CCollisionActor>(act) ||
|
||||||
|
CPatterned::CastTo<MP1::CPuddleToadGamma>(&act)) {
|
||||||
|
return CanCollideWithComplexCollision(act, mgr);
|
||||||
} else {
|
} else {
|
||||||
if (TCastToConstPtr<CScriptTrigger>(act)) {
|
return CanCollideWithGameObject(act, mgr);
|
||||||
return CanCollideWithTrigger(act, mgr);
|
|
||||||
} else if (TCastToConstPtr<CScriptPlatform>(act) || TCastToConstPtr<CCollisionActor>(act) ||
|
|
||||||
CPatterned::CastTo<MP1::CPuddleToadGamma>(&act)) {
|
|
||||||
return CanCollideWithComplexCollision(act, mgr);
|
|
||||||
} else {
|
|
||||||
return CanCollideWithGameObject(act, mgr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,73 +346,75 @@ 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) {
|
||||||
const CCollisionPrimitive* prim = useAct->GetCollisionPrimitive();
|
return {act.GetUniqueId(), std::nullopt};
|
||||||
zeus::CTransform xf = useAct->GetPrimitiveTransform();
|
|
||||||
zeus::CVector3f deltaPos = GetTranslation() - x298_previousPos;
|
|
||||||
if (deltaPos.canBeNormalized()) {
|
|
||||||
zeus::CVector3f dir = deltaPos.normalized();
|
|
||||||
float mag = deltaPos.magnitude();
|
|
||||||
CRayCastResult res = prim->CastRayInternal(
|
|
||||||
{x298_previousPos, dir, mag, xf,
|
|
||||||
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
|
||||||
if (!res.IsValid()) {
|
|
||||||
if (prim->GetPrimType() == FOURCC('SPHR')) {
|
|
||||||
mag *= 2.f;
|
|
||||||
CRayCastResult res2 = prim->CastRayInternal(
|
|
||||||
{x298_previousPos - dir * mag, dir, deltaPos.magnitude(), xf,
|
|
||||||
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
|
||||||
if (res2.IsValid())
|
|
||||||
return {act.GetUniqueId(), {res2}};
|
|
||||||
} else if (const TCastToConstPtr<CCollisionActor> cAct = act) {
|
|
||||||
const float rad = cAct->GetSphereRadius();
|
|
||||||
if ((x298_previousPos - GetTranslation()).magSquared() < rad * rad) {
|
|
||||||
const zeus::CVector3f point = x298_previousPos - dir * rad * 1.125f;
|
|
||||||
const zeus::CUnitVector3f revDir(-dir);
|
|
||||||
return {act.GetUniqueId(), {{0.f, point, {revDir, point.dot(revDir)}, act.GetMaterialList()}}};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {kInvalidUniqueId, {}};
|
|
||||||
} else {
|
|
||||||
return {act.GetUniqueId(), {res}};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {kInvalidUniqueId, {}};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {act.GetUniqueId(), {}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CCollisionPrimitive* prim = useAct->GetCollisionPrimitive();
|
||||||
|
const zeus::CTransform xf = useAct->GetPrimitiveTransform();
|
||||||
|
const zeus::CVector3f deltaPos = GetTranslation() - x298_previousPos;
|
||||||
|
if (!deltaPos.canBeNormalized()) {
|
||||||
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
|
}
|
||||||
|
|
||||||
|
const zeus::CVector3f dir = deltaPos.normalized();
|
||||||
|
float mag = deltaPos.magnitude();
|
||||||
|
const CRayCastResult res = prim->CastRayInternal(
|
||||||
|
{x298_previousPos, dir, mag, xf,
|
||||||
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
||||||
|
if (res.IsValid()) {
|
||||||
|
return {act.GetUniqueId(), {res}};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prim->GetPrimType() == FOURCC('SPHR')) {
|
||||||
|
mag *= 2.f;
|
||||||
|
const CRayCastResult res2 = prim->CastRayInternal(
|
||||||
|
{x298_previousPos - dir * mag, dir, deltaPos.magnitude(), xf,
|
||||||
|
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough})});
|
||||||
|
if (res2.IsValid()) {
|
||||||
|
return {act.GetUniqueId(), {res2}};
|
||||||
|
}
|
||||||
|
} else if (const TCastToConstPtr<CCollisionActor> cAct = act) {
|
||||||
|
const float rad = cAct->GetSphereRadius();
|
||||||
|
if ((x298_previousPos - GetTranslation()).magSquared() < rad * rad) {
|
||||||
|
const zeus::CVector3f point = x298_previousPos - dir * rad * 1.125f;
|
||||||
|
const zeus::CUnitVector3f revDir(-dir);
|
||||||
|
return {act.GetUniqueId(), {{0.f, point, {revDir, point.dot(revDir)}, act.GetMaterialList()}}};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {kInvalidUniqueId, std::nullopt};
|
||||||
}
|
}
|
||||||
|
|
||||||
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