2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptTimer.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-04-19 21:25:26 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-04-19 21:25:26 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptTimer::CScriptTimer(TUniqueId uid, std::string_view name, const CEntityInfo& info, float startTime,
|
2016-12-19 18:27:58 +00:00
|
|
|
float maxRandDelay, bool loop, bool autoStart, bool active)
|
2016-04-20 21:44:18 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
2016-12-19 18:27:58 +00:00
|
|
|
, x34_time(startTime)
|
|
|
|
, x38_startTime(startTime)
|
|
|
|
, x3c_maxRandDelay(maxRandDelay)
|
|
|
|
, x40_loop(loop)
|
|
|
|
, x41_autoStart(autoStart)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x42_isTiming(autoStart) {}
|
2016-04-19 21:25:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptTimer::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptTimer::Think(float dt, CStateManager& mgr) {
|
2020-05-07 15:47:05 +00:00
|
|
|
if (GetActive() && IsTiming()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ApplyTime(dt, mgr);
|
2020-05-07 15:47:05 +00:00
|
|
|
}
|
2016-12-19 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptTimer::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) {
|
|
|
|
if (GetActive()) {
|
|
|
|
if (msg == EScriptObjectMessage::Start) {
|
|
|
|
StartTiming(true);
|
|
|
|
} else if (msg == EScriptObjectMessage::Stop) {
|
|
|
|
StartTiming(false);
|
|
|
|
} else if (msg == EScriptObjectMessage::ResetAndStart) {
|
|
|
|
Reset(stateMgr);
|
|
|
|
StartTiming(true);
|
|
|
|
} else if (msg == EScriptObjectMessage::Reset) {
|
|
|
|
Reset(stateMgr);
|
2022-10-18 15:17:01 +00:00
|
|
|
if (x41_autoStart) {
|
|
|
|
StartTiming(true);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (msg == EScriptObjectMessage::StopAndReset) {
|
|
|
|
Reset(stateMgr);
|
|
|
|
StartTiming(false);
|
2016-12-19 18:27:58 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
|
2016-12-19 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CScriptTimer::IsTiming() const { return x42_isTiming; }
|
|
|
|
|
|
|
|
void CScriptTimer::StartTiming(bool isTiming) { x42_isTiming = isTiming; }
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptTimer::Reset(CStateManager& mgr) {
|
2020-05-07 15:47:05 +00:00
|
|
|
const float rDt = mgr.GetActiveRandom()->Float();
|
2018-12-08 05:30:43 +00:00
|
|
|
x34_time = (x3c_maxRandDelay * rDt) + x38_startTime;
|
2016-12-19 18:27:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptTimer::ApplyTime(float dt, CStateManager& mgr) {
|
2020-05-07 15:47:05 +00:00
|
|
|
if (x34_time <= 0.f || !GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-05-07 15:47:05 +00:00
|
|
|
}
|
2016-12-19 18:27:58 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x34_time -= dt;
|
2020-05-07 15:47:05 +00:00
|
|
|
if (x34_time > 0.f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendScriptMsgs(EScriptObjectState::Zero, mgr, EScriptObjectMessage::None);
|
|
|
|
|
|
|
|
x42_isTiming = false;
|
|
|
|
if (!x40_loop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Reset(mgr);
|
|
|
|
if (!x41_autoStart) {
|
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-05-07 15:47:05 +00:00
|
|
|
|
|
|
|
x42_isTiming = true;
|
2016-12-19 18:27:58 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|