Fix CScriptActorRotate

This commit is contained in:
Phillip Stephens 2018-02-09 17:23:18 -08:00
parent 083571e693
commit d35cc2ce1d
5 changed files with 137 additions and 16 deletions

View File

@ -57,10 +57,12 @@ void CScriptActorRotate::Think(float dt, CStateManager& mgr)
if (TCastToPtr<CActor> act = mgr.ObjectById(actorPair.first))
{
zeus::CTransform xf =
zeus::CTransform::RotateX(zeus::degToRad(timeOffset * x34_rotation.x)) *
zeus::CTransform::RotateZ(zeus::degToRad(timeOffset * x34_rotation.z)) *
zeus::CTransform::RotateY(zeus::degToRad(timeOffset * x34_rotation.y)) *
zeus::CTransform::RotateZ(zeus::degToRad(timeOffset * x34_rotation.z));
act->SetTransform({xf.basis, act->GetTranslation()});
zeus::CTransform::RotateX(zeus::degToRad(timeOffset * x34_rotation.x));
zeus::CTransform localRot = actorPair.second * xf;
localRot.origin = act->GetTranslation();
act->SetTransform(localRot);
if (TCastToPtr<CScriptPlatform> plat = mgr.ObjectById(actorPair.first))
UpdatePlatformRiders(*plat.GetPtr(), xf, mgr);
@ -71,6 +73,7 @@ void CScriptActorRotate::Think(float dt, CStateManager& mgr)
{
if (!x58_25_skipSpiderBallWaypoints)
UpdateSpiderBallWaypoints(mgr);
if (x58_26_updateActors)
UpdateActors(false, mgr);
}
@ -133,7 +136,7 @@ void CScriptActorRotate::UpdateActors(bool next, CStateManager& mgr)
if (!x48_actors.empty())
{
x58_24_updateRotation = true;
x44_currentTime = (next ? 0.f : x40_maxTime);
x44_currentTime = (next ? x40_maxTime : 0.f);
}
}

View File

@ -12,7 +12,7 @@ class CScriptActorRotate : public CEntity
{
zeus::CVector3f x34_rotation;
float x40_maxTime;
float x44_currentTime;
float x44_currentTime = 0.f;
std::map<TUniqueId, zeus::CTransform> x48_actors;
union

View File

@ -28,22 +28,139 @@ void CScriptColorModulate::Accept(IVisitor& visitor)
visitor.Visit(this);
}
void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr)
void CScriptColorModulate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& mgr)
{
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
CEntity::AcceptScriptMsg(msg, objId, mgr);
return;
if (!GetActive())
return;
if (msg == EScriptObjectMessage::Decrement)
{
if (x54_29_)
{
x38_ = x38_ == 0;
x54_29_ = false;
return;
}
else if (x54_30_)
{
if (x38_ == 0)
x3c_ = 0.f;
else
x3c_ = -((x50_ * (x3c_ / x4c_)) - x50_);
}
else
SetTargetFlags(mgr, CalculateFlags(x44_));
x54_30_ = true;
x38_ = 0;
}
else if (msg == EScriptObjectMessage::Increment)
{
if (x54_29_)
{
x38_ = x38_ == 0;
x54_29_ = false;
return;
}
else if (x54_30_)
{
if (x38_ == 0)
x3c_ = 0.f;
else
x3c_ = -((x4c_ * (x3c_ / x50_)) - x4c_);
}
else
SetTargetFlags(mgr, CalculateFlags(x40_));
x54_30_ = true;
x38_ = 0;
}
}
void CScriptColorModulate::Think(float, CStateManager &)
void CScriptColorModulate::Think(float dt, CStateManager& mgr)
{
return;
if (!GetActive() || !x54_30_)
return;
x3c_ += dt;
if (x38_ == 0)
{
float f2 = x4c_;
float f1 = f2 - dt;
if (std::fabs(f1) < 0.000001)
f1 = 1.f;
else
{
f1 = x3c_;
f1 /= f2;
if (f1 >= 1.f)
f1 = 1.f;
}
zeus::CColor lerpedCol = zeus::CColor::lerp(x40_, x44_, f1);
CModelFlags flags = CalculateFlags(lerpedCol);
SetTargetFlags(mgr, flags);
if (x3c_ <= x4c_)
return;
End(mgr);
}
else if (x38_ == 1)
{
float f2 = x50_;
float f1 = f2 - dt;
if (std::fabs(f1) < 0.000001)
f1 = 1.f;
else
{
f1 = x3c_;
f1 /= f2;
if (f1 >= 1.f)
f1 = 1.f;
}
zeus::CColor lerpedCol = zeus::CColor::lerp(x40_, x44_, f1);
CModelFlags flags = CalculateFlags(lerpedCol);
SetTargetFlags(mgr, flags);
if (x3c_ <= x50_)
return;
End(mgr);
}
}
zeus::CColor CScriptColorModulate::CalculateFlags(const zeus::CColor &) const
CModelFlags CScriptColorModulate::CalculateFlags(const zeus::CColor &) const
{
return {};
}
void CScriptColorModulate::SetTargetFlags(CStateManager &, const CModelFlags &)
void CScriptColorModulate::SetTargetFlags(CStateManager& stateMgr, const CModelFlags& flags)
{
for (const SConnection& conn : x20_conns)
{
if (conn.x0_state != EScriptObjectState::Play || conn.x4_msg != EScriptObjectMessage::Activate)
continue;
auto search = stateMgr.GetIdListForScript(conn.x8_objId);
for (auto it = search.first ; it != search.second ; ++it)
{
CEntity* ent = stateMgr.ObjectById(it->second);
if (CActor* act = TCastToPtr<CActor>(ent))
act->SetDrawFlags(flags);
}
}
if (x34_ != kInvalidUniqueId)
{
CEntity* ent = stateMgr.ObjectById(x34_);
if (CActor* act = TCastToPtr<CActor>(ent))
act->SetDrawFlags(flags);
}
}
void CScriptColorModulate::FadeOutHelper(CStateManager &, TUniqueId, float)
@ -61,7 +178,7 @@ void CScriptColorModulate::End(CStateManager& stateMgr)
if (x54_24_ && !x54_29_)
{
x54_29_ = true;
x38_ = 0;
x38_ = x38_ == 0;
return;
}
@ -70,12 +187,12 @@ void CScriptColorModulate::End(CStateManager& stateMgr)
if (x54_25_)
SetTargetFlags(stateMgr, CModelFlags(0, 0, 3, zeus::CColor::skWhite));
if (x54_24_)
stateMgr.SendScriptMsg(x8_uid, x34_, EScriptObjectMessage::Deactivate);
if (x55_24_)
stateMgr.SendScriptMsgAlways(x34_, x8_uid, EScriptObjectMessage::Deactivate);
CEntity::SendScriptMsgs(EScriptObjectState::MaxReached, stateMgr, EScriptObjectMessage::None);
if (x54_31_)
stateMgr.FreeScriptObject(x8_uid);
if (!x54_31_)
stateMgr.FreeScriptObject(GetUniqueId());
}
}

View File

@ -47,7 +47,7 @@ public:
void Accept(IVisitor& visitor);
void AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr);
void Think(float, CStateManager &);
zeus::CColor CalculateFlags(const zeus::CColor&) const;
CModelFlags CalculateFlags(const zeus::CColor&) const;
void SetTargetFlags(CStateManager&, const CModelFlags&);
static void FadeOutHelper(CStateManager&, TUniqueId, float);
static void FadeInHelper(CStateManager&, TUniqueId, float);

View File

@ -23,6 +23,7 @@ void CScriptGenerator::Accept(IVisitor& visitor) { visitor.Visit(this); }
void CScriptGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr)
{
return;
if (msg == EScriptObjectMessage::SetToZero && GetActive() && !x20_conns.empty())
{
std::vector<TUniqueId> follows;