Files

150 lines
5.2 KiB
C++
Raw Permalink Normal View History

2020-01-15 07:07:48 -05:00
#include "Runtime/Character/CParticleGenInfo.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Graphics/CBooRenderer.hpp"
#include "Runtime/Graphics/IRenderer.hpp"
#include "Runtime/Particle/CParticleGen.hpp"
#include "Runtime/World/CGameLight.hpp"
#include "TCastTo.hpp" // Generated file, do not modify include path
2021-04-10 01:42:06 -07:00
namespace metaforce {
2017-11-12 20:19:18 -10:00
CParticleGenInfo::CParticleGenInfo(const SObjectTag& part, int frameCount, std::string_view boneName,
2018-12-07 19:30:43 -10:00
const zeus::CVector3f& scale, CParticleData::EParentedMode parentMode, int flags,
EParticleGenType type)
2017-01-20 22:03:37 -08:00
: x4_part(part)
, xc_seconds(frameCount / 60.f)
, x10_boneName(boneName)
, x28_parentMode(parentMode)
2017-06-02 20:03:07 -10:00
, x2c_flags(flags)
2017-01-20 22:03:37 -08:00
, x30_particleScale(scale)
2018-12-07 19:30:43 -10:00
, x80_type(type) {}
2017-01-20 22:03:37 -08:00
static TUniqueId _initializeLight(const std::weak_ptr<CParticleGen>& system, CStateManager& stateMgr, TAreaId areaId,
2018-12-07 19:30:43 -10:00
int lightId) {
TUniqueId ret = kInvalidUniqueId;
std::shared_ptr<CParticleGen> systemRef = system.lock();
if (systemRef->SystemHasLight()) {
ret = stateMgr.AllocateUniqueId();
stateMgr.AddObject(
new CGameLight(ret, areaId, false, "ParticleLight",
zeus::CTransform(systemRef->GetOrientation().buildMatrix3f(), systemRef->GetTranslation()),
kInvalidUniqueId, systemRef->GetLight(), u32(lightId), 0, 0.f));
}
return ret;
}
2017-01-20 22:03:37 -08:00
CParticleGenInfoGeneric::CParticleGenInfoGeneric(const SObjectTag& part, const std::weak_ptr<CParticleGen>& system,
2017-11-12 20:19:18 -10:00
int frameCount, std::string_view boneName,
2017-01-20 22:03:37 -08:00
const zeus::CVector3f& scale, CParticleData::EParentedMode parentMode,
2017-06-02 20:03:07 -10:00
int flags, CStateManager& stateMgr, TAreaId areaId, int lightId,
2018-05-13 13:27:47 -10:00
EParticleGenType state)
2018-12-07 19:30:43 -10:00
: CParticleGenInfo(part, frameCount, boneName, scale, parentMode, flags, state), x84_system(system) {
if (lightId == -1)
x88_lightId = kInvalidUniqueId;
else
x88_lightId = _initializeLight(system, stateMgr, areaId, lightId);
}
void CParticleGenInfoGeneric::AddToRenderer() { g_Renderer->AddParticleGen(*x84_system); }
2017-01-20 22:03:37 -08:00
void CParticleGenInfoGeneric::Render() { x84_system->Render(); }
2018-12-07 19:30:43 -10:00
void CParticleGenInfoGeneric::Update(float dt, CStateManager& stateMgr) {
x84_system->Update(dt);
2017-01-20 22:03:37 -08:00
if (x88_lightId == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CGameLight> gl = stateMgr.ObjectById(x88_lightId)) {
gl->SetLight(x84_system->GetLight());
2018-12-07 19:30:43 -10:00
}
}
2018-12-07 19:30:43 -10:00
void CParticleGenInfoGeneric::SetOrientation(const zeus::CTransform& xf, CStateManager& stateMgr) {
x84_system->SetOrientation(xf);
2017-01-20 22:03:37 -08:00
if (x88_lightId == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CGameLight> gl = stateMgr.ObjectById(x88_lightId)) {
gl->SetRotation(zeus::CQuaternion(xf.buildMatrix3f()));
2018-12-07 19:30:43 -10:00
}
}
2018-12-07 19:30:43 -10:00
void CParticleGenInfoGeneric::SetTranslation(const zeus::CVector3f& trans, CStateManager& stateMgr) {
x84_system->SetTranslation(trans);
2017-01-20 22:03:37 -08:00
if (x88_lightId == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CGameLight> gl = stateMgr.ObjectById(x88_lightId)) {
gl->SetTranslation(trans);
2018-12-07 19:30:43 -10:00
}
}
2018-12-07 19:30:43 -10:00
void CParticleGenInfoGeneric::SetGlobalOrientation(const zeus::CTransform& xf, CStateManager& stateMgr) {
x84_system->SetGlobalOrientation(xf);
2017-01-20 22:03:37 -08:00
if (x88_lightId == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CGameLight> gl = stateMgr.ObjectById(x88_lightId)) {
gl->SetRotation(zeus::CQuaternion(xf.buildMatrix3f()));
2018-12-07 19:30:43 -10:00
}
}
2018-12-07 19:30:43 -10:00
void CParticleGenInfoGeneric::SetGlobalTranslation(const zeus::CVector3f& trans, CStateManager& stateMgr) {
x84_system->SetGlobalTranslation(trans);
2017-01-20 22:03:37 -08:00
if (x88_lightId == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CGameLight> gl = stateMgr.ObjectById(x88_lightId)) {
gl->SetTranslation(trans);
2018-12-07 19:30:43 -10:00
}
}
2017-01-20 22:03:37 -08:00
void CParticleGenInfoGeneric::SetGlobalScale(const zeus::CVector3f& scale) { x84_system->SetGlobalScale(scale); }
void CParticleGenInfoGeneric::SetParticleEmission(bool isActive, CStateManager& stateMgr) {
x84_system->SetParticleEmission(isActive);
2017-01-20 22:03:37 -08:00
if (x88_lightId == kInvalidUniqueId) {
return;
}
if (const TCastToPtr<CGameLight> gl = stateMgr.ObjectById(x88_lightId)) {
gl->SetActive(isActive);
}
}
2017-01-20 22:03:37 -08:00
bool CParticleGenInfoGeneric::IsSystemDeletable() const { return x84_system->IsSystemDeletable(); }
std::optional<zeus::CAABox> CParticleGenInfoGeneric::GetBounds() const { return x84_system->GetBounds(); }
2017-01-20 22:03:37 -08:00
bool CParticleGenInfoGeneric::HasActiveParticles() const { return x84_system->GetParticleCount() != 0; }
2017-01-20 22:03:37 -08:00
void CParticleGenInfoGeneric::DestroyParticles() { x84_system->DestroyParticles(); }
2017-01-20 22:03:37 -08:00
bool CParticleGenInfoGeneric::HasLight() const { return x84_system->SystemHasLight(); }
2017-01-20 22:03:37 -08:00
TUniqueId CParticleGenInfoGeneric::GetLightId() const { return x88_lightId; }
2018-12-07 19:30:43 -10:00
void CParticleGenInfoGeneric::DeleteLight(CStateManager& mgr) {
if (x88_lightId != kInvalidUniqueId) {
mgr.FreeScriptObject(x88_lightId);
x88_lightId = kInvalidUniqueId;
}
}
2017-01-20 22:03:37 -08:00
void CParticleGenInfoGeneric::SetModulationColor(const zeus::CColor& color) { x84_system->SetModulationColor(color); }
2021-04-10 01:42:06 -07:00
} // namespace metaforce