2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptShadowProjector.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
|
|
|
#include "Runtime/World/CProjectedShadow.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptShadowProjector::CScriptShadowProjector(TUniqueId uid, std::string_view name, const CEntityInfo& info,
|
2017-01-04 04:08:30 +00:00
|
|
|
const zeus::CTransform& xf, bool active, const zeus::CVector3f& offset,
|
2020-04-11 05:50:10 +00:00
|
|
|
bool persistent, float scale, float f2, float opacity, float opacityQ,
|
2017-01-04 04:08:30 +00:00
|
|
|
s32 textureSize)
|
|
|
|
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
|
|
|
|
kInvalidUniqueId)
|
|
|
|
, xe8_scale(scale)
|
|
|
|
, xec_offset(offset)
|
|
|
|
, xf8_zOffsetAdjust(f2)
|
|
|
|
, xfc_opacity(opacity)
|
|
|
|
, x100_opacityRecip(opacity < 0.00001 ? 1.f : opacityQ / opacity)
|
2020-04-11 05:50:10 +00:00
|
|
|
, x10c_textureSize(textureSize)
|
2020-04-20 04:57:50 +00:00
|
|
|
, x110_24_persistent(persistent) {}
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptShadowProjector::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptShadowProjector::Think(float dt, CStateManager& mgr) {
|
2020-05-07 16:27:49 +00:00
|
|
|
if (!GetActive() || !x110_25_shadowInvalidated) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2022-11-08 15:42:55 +00:00
|
|
|
xfc_opacity = -(x100_opacityRecip * dt - xfc_opacity);
|
|
|
|
if (xfc_opacity > 0.f) {
|
2020-05-07 16:27:49 +00:00
|
|
|
return;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2022-11-08 15:42:55 +00:00
|
|
|
xfc_opacity = 0.f;
|
2020-05-07 16:27:49 +00:00
|
|
|
x108_projectedShadow.reset();
|
|
|
|
|
|
|
|
x110_25_shadowInvalidated = false;
|
|
|
|
SendScriptMsgs(EScriptObjectState::Zero, mgr, EScriptObjectMessage::None);
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptShadowProjector::CreateProjectedShadow() {
|
2020-05-07 16:27:49 +00:00
|
|
|
if (!GetActive() || x104_target == kInvalidUniqueId || xfc_opacity <= 0.f) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x108_projectedShadow.reset();
|
2020-05-07 16:27:49 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
x108_projectedShadow.reset(new CProjectedShadow(x10c_textureSize, x10c_textureSize, x110_24_persistent));
|
2020-05-07 16:27:49 +00:00
|
|
|
}
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptShadowProjector::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr) {
|
|
|
|
CActor::AcceptScriptMsg(msg, uid, mgr);
|
2017-01-04 04:08:30 +00:00
|
|
|
|
2022-11-08 15:42:55 +00:00
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::InitializedInArea:
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-05-07 16:27:49 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::Play) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 16:27:49 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
const CActor* act = TCastToConstPtr<CActor>(mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId)));
|
2022-11-08 15:42:55 +00:00
|
|
|
if (act) {
|
|
|
|
const CModelData* mData = act->GetModelData();
|
|
|
|
if (mData && (mData->GetAnimationData() || mData->HasNormalModel())) {
|
|
|
|
x104_target = act->GetUniqueId();
|
|
|
|
break;
|
|
|
|
}
|
2020-05-07 16:27:49 +00:00
|
|
|
}
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
2020-05-07 16:27:49 +00:00
|
|
|
if (x104_target == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
2022-11-08 15:42:55 +00:00
|
|
|
break;
|
2020-05-07 16:27:49 +00:00
|
|
|
}
|
2022-11-08 15:42:55 +00:00
|
|
|
[[fallthrough]];
|
|
|
|
case EScriptObjectMessage::Deactivate:
|
|
|
|
case EScriptObjectMessage::Activate:
|
2018-12-08 05:30:43 +00:00
|
|
|
CreateProjectedShadow();
|
2022-11-08 15:42:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EScriptObjectMessage::Decrement:
|
|
|
|
if (!GetActive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc_opacity > 0.f) {
|
|
|
|
x110_25_shadowInvalidated = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2020-05-07 16:27:49 +00:00
|
|
|
}
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
void CScriptShadowProjector::PreRender(CStateManager&, const zeus::CFrustum&) {}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|