2017-07-16 06:13:37 +00:00
|
|
|
#include "CHUDBillboardEffect.hpp"
|
|
|
|
#include "TCastTo.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "Camera/CGameCamera.hpp"
|
2018-11-04 01:08:44 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
|
|
|
#include "Graphics/CBooRenderer.hpp"
|
|
|
|
#include "World/CPlayer.hpp"
|
|
|
|
#include "World/CWorld.hpp"
|
2017-07-16 06:13:37 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
u32 CHUDBillboardEffect::g_IndirectTexturedBillboardCount = 0;
|
|
|
|
u32 CHUDBillboardEffect::g_BillboardCount = 0;
|
|
|
|
|
|
|
|
CHUDBillboardEffect::CHUDBillboardEffect(const std::experimental::optional<TToken<CGenDescription>>& particle,
|
|
|
|
const std::experimental::optional<TToken<CElectricDescription>>& electric,
|
2018-11-04 01:08:44 +00:00
|
|
|
TUniqueId uid, bool active, std::string_view name, float dist,
|
|
|
|
const zeus::CVector3f& scale0, const zeus::CColor& color,
|
|
|
|
const zeus::CVector3f& scale1, const zeus::CVector3f& translation)
|
2017-07-16 06:13:37 +00:00
|
|
|
: CEffect(uid, CEntityInfo(kInvalidAreaId, CEntity::NullConnectionList), active, name, zeus::CTransform::Identity())
|
|
|
|
{
|
2018-11-04 01:08:44 +00:00
|
|
|
xec_translation = translation;
|
|
|
|
xec_translation.y += dist;
|
|
|
|
xf8_localScale = scale1 * scale0;
|
|
|
|
x104_24_renderAsParticleGen = true;
|
|
|
|
x104_25_enableRender = false;
|
|
|
|
x104_26_isElementGen = false;
|
|
|
|
x104_27_runIndefinitely = false;
|
2017-07-16 06:13:37 +00:00
|
|
|
|
|
|
|
if (particle)
|
|
|
|
{
|
2018-11-04 01:08:44 +00:00
|
|
|
x104_26_isElementGen = true;
|
2017-09-11 02:18:49 +00:00
|
|
|
xe8_generator = std::make_unique<CElementGen>(*particle);
|
2017-07-16 06:13:37 +00:00
|
|
|
if (static_cast<CElementGen&>(*xe8_generator).IsIndirectTextured())
|
|
|
|
++g_IndirectTexturedBillboardCount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xe8_generator = std::make_unique<CParticleElectric>(*electric);
|
|
|
|
}
|
|
|
|
++g_BillboardCount;
|
|
|
|
xe8_generator->SetModulationColor(color);
|
2018-11-04 01:08:44 +00:00
|
|
|
xe8_generator->SetLocalScale(xf8_localScale);
|
2017-07-16 06:13:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHUDBillboardEffect::~CHUDBillboardEffect()
|
|
|
|
{
|
|
|
|
--g_BillboardCount;
|
|
|
|
if (xe8_generator->Get4CharId() == FOURCC('PART'))
|
|
|
|
if (static_cast<CElementGen&>(*xe8_generator).IsIndirectTextured())
|
|
|
|
--g_IndirectTexturedBillboardCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUDBillboardEffect::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
2018-11-04 01:08:44 +00:00
|
|
|
float CHUDBillboardEffect::CalcGenRate()
|
|
|
|
{
|
|
|
|
float f1;
|
|
|
|
if (g_BillboardCount + g_IndirectTexturedBillboardCount <= 4)
|
|
|
|
f1 = 0.f;
|
|
|
|
else
|
|
|
|
f1 = g_BillboardCount * 0.2f + g_IndirectTexturedBillboardCount * 0.1f;
|
|
|
|
return 1.f - std::min(f1, 0.8f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUDBillboardEffect::Think(float dt, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (GetActive())
|
|
|
|
{
|
|
|
|
mgr.SetActorAreaId(*this, mgr.GetWorld()->GetCurrentAreaId());
|
|
|
|
float oldGenRate = xe8_generator->GetGeneratorRate();
|
|
|
|
xe8_generator->SetGeneratorRate(oldGenRate * CalcGenRate());
|
|
|
|
xe8_generator->Update(dt);
|
|
|
|
xe8_generator->SetGeneratorRate(oldGenRate);
|
|
|
|
if (!x104_27_runIndefinitely)
|
|
|
|
{
|
|
|
|
x108_timeoutTimer += dt;
|
|
|
|
if (x108_timeoutTimer > 30.f)
|
|
|
|
{
|
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xe8_generator->IsSystemDeletable())
|
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUDBillboardEffect::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) const
|
|
|
|
{
|
|
|
|
if (x104_25_enableRender && x104_24_renderAsParticleGen)
|
|
|
|
{
|
|
|
|
g_Renderer->AddParticleGen(*xe8_generator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUDBillboardEffect::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum)
|
|
|
|
{
|
|
|
|
if (mgr.GetPlayer().GetCameraState() == CPlayer::EPlayerCameraState::FirstPerson)
|
|
|
|
{
|
|
|
|
zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr);
|
|
|
|
xe8_generator->SetGlobalTranslation(camXf * xec_translation);
|
|
|
|
xe8_generator->SetGlobalOrientation(camXf);
|
|
|
|
x104_25_enableRender = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x104_25_enableRender = false;
|
|
|
|
}
|
|
|
|
x104_24_renderAsParticleGen = !mgr.RenderLast(GetUniqueId());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHUDBillboardEffect::Render(const CStateManager& mgr) const
|
|
|
|
{
|
|
|
|
if (x104_25_enableRender && !x104_24_renderAsParticleGen)
|
|
|
|
{
|
|
|
|
xe8_generator->Render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-16 06:13:37 +00:00
|
|
|
float CHUDBillboardEffect::GetNearClipDistance(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
return mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetNearClipDistance() + 0.01f;
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f CHUDBillboardEffect::GetScaleForPOV(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
return {0.155f, 1.f, 0.155f};
|
|
|
|
}
|
|
|
|
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|