2017-07-16 06:13:37 +00:00
|
|
|
#include "CHUDBillboardEffect.hpp"
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-07-16 06:13:37 +00:00
|
|
|
#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
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2017-07-16 06:13:37 +00:00
|
|
|
|
|
|
|
u32 CHUDBillboardEffect::g_IndirectTexturedBillboardCount = 0;
|
|
|
|
u32 CHUDBillboardEffect::g_BillboardCount = 0;
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
CHUDBillboardEffect::CHUDBillboardEffect(const std::optional<TToken<CGenDescription>>& particle,
|
|
|
|
const std::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)
|
2019-02-24 07:15:54 +00:00
|
|
|
: CEffect(uid, CEntityInfo(kInvalidAreaId, CEntity::NullConnectionList), active, name, zeus::CTransform()) {
|
2018-12-08 05:30:43 +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
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (particle) {
|
|
|
|
x104_26_isElementGen = true;
|
|
|
|
xe8_generator = std::make_unique<CElementGen>(*particle);
|
|
|
|
if (static_cast<CElementGen&>(*xe8_generator).IsIndirectTextured())
|
|
|
|
++g_IndirectTexturedBillboardCount;
|
|
|
|
} else {
|
|
|
|
xe8_generator = std::make_unique<CParticleElectric>(*electric);
|
|
|
|
}
|
|
|
|
++g_BillboardCount;
|
|
|
|
xe8_generator->SetModulationColor(color);
|
|
|
|
xe8_generator->SetLocalScale(xf8_localScale);
|
2017-07-16 06:13:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CHUDBillboardEffect::~CHUDBillboardEffect() {
|
|
|
|
--g_BillboardCount;
|
|
|
|
if (xe8_generator->Get4CharId() == FOURCC('PART'))
|
|
|
|
if (static_cast<CElementGen&>(*xe8_generator).IsIndirectTextured())
|
|
|
|
--g_IndirectTexturedBillboardCount;
|
2017-07-16 06:13:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHUDBillboardEffect::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
|
|
|
|
2018-12-08 05:30:43 +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);
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (xe8_generator->IsSystemDeletable())
|
|
|
|
mgr.FreeScriptObject(GetUniqueId());
|
|
|
|
}
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHUDBillboardEffect::AddToRenderer(const zeus::CFrustum& frustum, const CStateManager& mgr) const {
|
|
|
|
if (x104_25_enableRender && x104_24_renderAsParticleGen) {
|
|
|
|
g_Renderer->AddParticleGen(*xe8_generator);
|
|
|
|
}
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
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());
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CHUDBillboardEffect::Render(const CStateManager& mgr) const {
|
|
|
|
if (x104_25_enableRender && !x104_24_renderAsParticleGen) {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CHUDBillboardEffect::Render", zeus::skPurple);
|
2018-12-08 05:30:43 +00:00
|
|
|
xe8_generator->Render();
|
|
|
|
}
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CHUDBillboardEffect::GetNearClipDistance(CStateManager& mgr) {
|
|
|
|
return mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetNearClipDistance() + 0.01f;
|
2017-07-16 06:13:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f CHUDBillboardEffect::GetScaleForPOV(CStateManager& mgr) { return {0.155f, 1.f, 0.155f}; }
|
2017-07-16 06:13:37 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|