2017-01-04 04:08:30 +00:00
|
|
|
#include "World/CScriptShadowProjector.hpp"
|
|
|
|
#include "World/CActorParameters.hpp"
|
|
|
|
#include "World/CProjectedShadow.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
2017-01-15 03:07:01 +00:00
|
|
|
#include "TCastTo.hpp"
|
2017-01-04 04:08:30 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
bool b2, float scale, float f2, float opacity, float opacityQ,
|
|
|
|
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)
|
|
|
|
, x10c_textureSize(textureSize)
|
|
|
|
{
|
2017-01-25 04:40:19 +00:00
|
|
|
x110_24_persistent = b2;
|
2017-01-04 04:08:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
void CScriptShadowProjector::Accept(IVisitor& visitor)
|
|
|
|
{
|
|
|
|
visitor.Visit(this);
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
void CScriptShadowProjector::Think(float dt, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (GetActive() && x110_25_shadowInvalidated)
|
|
|
|
{
|
|
|
|
xfc_opacity = (x100_opacityRecip * xfc_opacity) - dt;
|
|
|
|
if (dt > 0.f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x108_projectedShadow.reset();
|
|
|
|
|
|
|
|
x110_25_shadowInvalidated = false;
|
|
|
|
SendScriptMsgs(EScriptObjectState::Zero, mgr, EScriptObjectMessage::None);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptShadowProjector::CreateProjectedShadow()
|
|
|
|
{
|
|
|
|
if (!GetActive() || x104_target == kInvalidUniqueId || xfc_opacity <= 0.f)
|
|
|
|
x108_projectedShadow.reset();
|
|
|
|
else
|
|
|
|
x108_projectedShadow.reset(new CProjectedShadow(x10c_textureSize, x10c_textureSize, x110_24_persistent));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CScriptShadowProjector::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
CActor::AcceptScriptMsg(msg, uid, mgr);
|
|
|
|
if (msg == EScriptObjectMessage::Decrement)
|
|
|
|
{
|
|
|
|
if (x110_24_persistent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (xfc_opacity <= 0.f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x110_25_shadowInvalidated = true;
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
else if (msg == EScriptObjectMessage::InitializedInArea)
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
|
|
|
for (const SConnection& conn : x20_conns)
|
|
|
|
{
|
|
|
|
if (conn.x0_state != EScriptObjectState::Play)
|
|
|
|
continue;
|
|
|
|
|
2017-01-15 03:07:01 +00:00
|
|
|
const CActor* act = TCastToConstPtr<CActor>(mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId)));
|
2017-01-04 04:08:30 +00:00
|
|
|
if (!act)
|
|
|
|
continue;
|
|
|
|
const CModelData* mData = act->GetModelData();
|
|
|
|
if (!mData || (!mData->GetAnimationData() && !mData->GetNormalModel()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
x104_target = act->GetUniqueId();
|
|
|
|
}
|
|
|
|
if (x104_target == kInvalidUniqueId)
|
2017-06-04 01:01:09 +00:00
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
2017-01-04 04:08:30 +00:00
|
|
|
else
|
|
|
|
CreateProjectedShadow();
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (msg == EScriptObjectMessage::Activate)
|
|
|
|
CreateProjectedShadow();
|
|
|
|
}
|
|
|
|
|
2017-02-11 00:52:52 +00:00
|
|
|
void CScriptShadowProjector::PreRender(CStateManager&, const zeus::CFrustum &)
|
2017-01-04 04:08:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|