Bug fixes

This commit is contained in:
Jack Andersen 2018-11-17 14:10:26 -10:00
parent 28d695eea4
commit b099be63dd
5 changed files with 27 additions and 29 deletions

View File

@ -26,17 +26,18 @@ zeus::CVector3f CSteeringBehaviors::Seek(const CPhysicsActor& actor,
}
zeus::CVector3f CSteeringBehaviors::Arrival(const CPhysicsActor& actor,
const zeus::CVector3f& v0, float f31) const
const zeus::CVector3f& dest, float dampingRadius) const
{
if (!v0.canBeNormalized())
zeus::CVector3f posDiff = dest - actor.GetTranslation();
if (!posDiff.canBeNormalized())
return {};
if (v0.magSquared() < (f31 * f31))
f31 = v0.magSquared() / (f31 * f31);
if (posDiff.magSquared() < (dampingRadius * dampingRadius))
dampingRadius = posDiff.magSquared() / (dampingRadius * dampingRadius);
else
f31 = 1.f;
dampingRadius = 1.f;
return f31 * v0.normalized();
return dampingRadius * posDiff.normalized();
}
zeus::CVector3f CSteeringBehaviors::Pursuit(const CPhysicsActor& actor,
@ -69,34 +70,30 @@ zeus::CVector3f CSteeringBehaviors::Alignment(const CPhysicsActor& actor,
if (!list.empty())
{
for (const TUniqueId& id : list)
{
if (const CActor* act = static_cast<const CActor*>(mgr.GetObjectById(id)))
align += act->GetTransform().frontVector();
}
align *= zeus::CVector3f(1.f / float(list.size()));
align *= zeus::CVector3f(1.f / float(list.size()));
}
float diff = zeus::CVector3f::getAngleDiff(actor.GetTransform().frontVector(), align);
return align * ( diff / M_PIF);
return align * (diff / M_PIF);
}
zeus::CVector3f CSteeringBehaviors::Cohesion(const CPhysicsActor& actor,
rstl::reserved_vector<TUniqueId, 1024>& list, float f1, const CStateManager& mgr) const
rstl::reserved_vector<TUniqueId, 1024>& list, float dampingRadius, const CStateManager& mgr) const
{
zeus::CVector3f cohesion;
zeus::CVector3f dest;
if (!list.empty())
{
for (const TUniqueId& id : list)
{
if (const CActor* act = static_cast<const CActor*>(mgr.GetObjectById(id)))
cohesion += act->GetTranslation();
}
dest += act->GetTranslation();
cohesion *= zeus::CVector3f(1.f / float(list.size()));
return Arrival(actor, cohesion, f1);
dest *= zeus::CVector3f(1.f / float(list.size()));
return Arrival(actor, dest, dampingRadius);
}
return cohesion;
return dest;
}
zeus::CVector2f CSteeringBehaviors::Flee2D(const CPhysicsActor& actor,
@ -164,7 +161,7 @@ bool CSteeringBehaviors::SolveCubic(
float f25 = std::pow(std::fabs(f24 + f30), 0.333333f);
f1 = std::pow(std::fabs(f24 - f30), 0.333333f);
f1 = (f24 - f30) > 0.f ? f1 : -f1;
f25 = (f24 - f30) > 0.f ? f25 : -f25;
f25 = (f24 + f30) > 0.f ? f25 : -f25;
out.push_back(f25 + f1 - f31);
}
for (float& f : out)

View File

@ -14,13 +14,13 @@ class CSteeringBehaviors
public:
zeus::CVector3f Flee(const CPhysicsActor& actor, const zeus::CVector3f& v0) const;
zeus::CVector3f Seek(const CPhysicsActor& actor, const zeus::CVector3f& target) const;
zeus::CVector3f Arrival(const CPhysicsActor& actor, const zeus::CVector3f& v0, float f1) const;
zeus::CVector3f Arrival(const CPhysicsActor& actor, const zeus::CVector3f& dest, float dampingRadius) const;
zeus::CVector3f Pursuit(const CPhysicsActor& actor, const zeus::CVector3f& v0, const zeus::CVector3f& v1) const;
zeus::CVector3f Separation(const CPhysicsActor& actor, const zeus::CVector3f& pos, float separation) const;
zeus::CVector3f Alignment(const CPhysicsActor& actor, rstl::reserved_vector<TUniqueId, 1024>& list,
const CStateManager& mgr) const;
zeus::CVector3f Cohesion(const CPhysicsActor& actor, rstl::reserved_vector<TUniqueId, 1024>& list,
float f1, const CStateManager& mgr) const;
float dampingRadius, const CStateManager& mgr) const;
zeus::CVector2f Flee2D(const CPhysicsActor& actor, const zeus::CVector2f& v0) const;
zeus::CVector2f Arrival2D(const CPhysicsActor& actor, const zeus::CVector2f& v0, float f1) const;
static bool SolveQuadratic(float, float, float, float&, float&);

View File

@ -808,7 +808,7 @@ void CBooRenderer::DisablePVS()
xc8_pvs = std::experimental::nullopt;
}
void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender)
void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender, bool activateLights)
{
SetupRendererStates();
@ -839,7 +839,8 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender)
CBooModel* model = *it;
if (model->TryLockTextures())
{
ActivateLightsForModel(&item, *model);
if (activateLights)
ActivateLightsForModel(&item, *model);
model->UpdateUniformData(flags, nullptr, nullptr, bufIdx);
}
}
@ -1449,7 +1450,7 @@ int CBooRenderer::DrawOverlappingWorldModelIDs(int alphaVal, const std::vector<u
const zeus::CAABox& aabb) const
{
SetupRendererStates();
const_cast<CBooRenderer&>(*this).UpdateAreaUniforms(-1);
const_cast<CBooRenderer&>(*this).UpdateAreaUniforms(-1, false, false);
CModelFlags flags;
flags.m_extendedShader = EExtendedShader::SolidColor; // Do solid color draw

View File

@ -211,7 +211,7 @@ public:
const SShader* shaderSet);
void EnablePVS(const CPVSVisSet&, u32);
void DisablePVS();
void UpdateAreaUniforms(int areaIdx, bool shadowRender = false);
void UpdateAreaUniforms(int areaIdx, bool shadowRender = false, bool activateLights = true);
void RemoveStaticGeometry(const std::vector<CMetroidModelInstance>*);
void DrawAreaGeometry(int areaIdx, int mask, int targetMask);
void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender = false);

View File

@ -446,7 +446,7 @@ void CParasite::UpdatePFDestination(CStateManager& mgr)
void CParasite::DoFlockingBehavior(CStateManager& mgr)
{
zeus::CVector3f upVec = x34_transform.basis[2];
rstl::reserved_vector<TUniqueId, 1024> _834;
rstl::reserved_vector<TUniqueId, 1024> parasiteList;
zeus::CAABox aabb(GetTranslation() - x6e4_parasiteSearchRadius,
GetTranslation() + x6e4_parasiteSearchRadius);
if ((x5d4_thinkCounter % 6) == 0)
@ -462,7 +462,7 @@ void CParasite::DoFlockingBehavior(CStateManager& mgr)
{
if (parasite != this && parasite->IsAlive())
{
_834.push_back(parasite->GetUniqueId());
parasiteList.push_back(parasite->GetUniqueId());
float distSq = (parasite->GetTranslation() - GetTranslation()).magSquared();
if (distSq < minDistSq)
{
@ -477,8 +477,8 @@ void CParasite::DoFlockingBehavior(CStateManager& mgr)
x6e8_parasiteSeparationDist) * x604_activeSpeed;
else
x628_parasiteSeparationMove = zeus::CVector3f::skZero;
x634_parasiteCohesionMove = x45c_steeringBehaviors.Cohesion(*this, _834, 0.6f, mgr) * x604_activeSpeed;
x640_parasiteAlignmentMove = x45c_steeringBehaviors.Alignment(*this, _834, mgr) * x604_activeSpeed;
x634_parasiteCohesionMove = x45c_steeringBehaviors.Cohesion(*this, parasiteList, 0.6f, mgr) * x604_activeSpeed;
x640_parasiteAlignmentMove = x45c_steeringBehaviors.Alignment(*this, parasiteList, mgr) * x604_activeSpeed;
}
if ((mgr.GetPlayer().GetTranslation() - GetTranslation()).magSquared() <