2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CGameLight.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CActorParameters.hpp"
|
2020-12-13 07:39:55 +00:00
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/CSimplePool.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "Graphics/CCubeRenderer.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CGameLight::CGameLight(TUniqueId uid, TAreaId aid, bool active, std::string_view name, const zeus::CTransform& xf,
|
2020-04-06 12:46:36 +00:00
|
|
|
TUniqueId parentId, const CLight& light, u32 sourceId, u32 priority, float lifeTime)
|
2018-12-08 05:30:43 +00:00
|
|
|
: CActor(uid, active, name, CEntityInfo(aid, CEntity::NullConnectionList), xf, CModelData::CModelDataNull(),
|
|
|
|
CMaterialList(), CActorParameters::None(), kInvalidUniqueId)
|
|
|
|
, xe8_parentId(parentId)
|
|
|
|
, xec_light(light)
|
|
|
|
, x13c_lightId(sourceId)
|
2020-04-06 12:46:36 +00:00
|
|
|
, x140_priority(priority)
|
|
|
|
, x144_lifeTime(lifeTime) {
|
2018-12-08 05:30:43 +00:00
|
|
|
xec_light.GetRadius();
|
|
|
|
xec_light.GetIntensity();
|
|
|
|
SetLightPriorityAndId();
|
2016-10-01 19:00:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameLight::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-21 06:03:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameLight::Think(float dt, CStateManager& mgr) {
|
|
|
|
if (x144_lifeTime <= 0.f)
|
|
|
|
return;
|
|
|
|
x144_lifeTime -= dt;
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x144_lifeTime <= 0.f)
|
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
2016-10-01 19:00:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameLight::SetLightPriorityAndId() {
|
|
|
|
xec_light.x3c_priority = x140_priority;
|
|
|
|
xec_light.x40_lightId = x13c_lightId;
|
2016-10-01 19:00:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameLight::SetLight(const CLight& light) {
|
|
|
|
xec_light = light;
|
|
|
|
xec_light.GetRadius();
|
|
|
|
xec_light.GetIntensity();
|
|
|
|
SetLightPriorityAndId();
|
2016-10-01 19:00:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CLight CGameLight::GetLight() const {
|
|
|
|
CLight ret = xec_light;
|
|
|
|
ret.SetPosition(x34_transform * xec_light.GetPosition());
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (ret.GetType() != ELightType::Point)
|
|
|
|
ret.SetDirection(x34_transform.rotate(xec_light.GetDirection()).normalized());
|
2016-10-01 19:00:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return ret;
|
2016-10-01 19:00:16 +00:00
|
|
|
}
|
2020-12-13 07:39:55 +00:00
|
|
|
|
|
|
|
void CGameLight::DebugDraw() {
|
|
|
|
if (!m_debugRes) {
|
|
|
|
const auto* tok = (xec_light.GetType() == ELightType::Spot || xec_light.GetType() == ELightType::Directional)
|
|
|
|
? g_ResFactory->GetResourceIdByName("CMDL_DebugLightCone")
|
|
|
|
: g_ResFactory->GetResourceIdByName("CMDL_DebugSphere");
|
|
|
|
if (tok != nullptr && tok->type == FOURCC('CMDL')) {
|
|
|
|
m_debugRes = CStaticRes(tok->id, zeus::skOne3f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_debugRes && !m_debugModel) {
|
|
|
|
m_debugModel = std::make_unique<CModelData>(*m_debugRes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_debugModel) {
|
|
|
|
g_Renderer->SetGXRegister1Color(xec_light.GetColor());
|
|
|
|
CModelFlags modelFlags;
|
|
|
|
modelFlags.x0_blendMode = 5;
|
|
|
|
modelFlags.x4_color = zeus::skWhite;
|
|
|
|
modelFlags.x4_color.a() = 0.5f;
|
|
|
|
m_debugModel->Render(CModelData::EWhichModel::Normal, zeus::CTransform::Translate(xec_light.GetPosition()), nullptr,
|
|
|
|
modelFlags);
|
|
|
|
m_debugModel->Render(CModelData::EWhichModel::Normal, x34_transform, nullptr, modelFlags);
|
|
|
|
}
|
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|