Rework particle token descriptions

This commit is contained in:
Luke Street 2022-03-10 18:56:55 -05:00
parent d7dbec5be0
commit 929bb65417
13 changed files with 75 additions and 107 deletions

View File

@ -88,7 +88,7 @@ void CCollisionResponseData::AddParticleSystemToResponse(EWeaponCollisionRespons
CSimplePool* resPool) {
const auto i = size_t(type);
const std::vector<CAssetId> tracker(8);
x0_generators[i].emplace(CPF::GetChildGeneratorDesc(in, resPool, tracker).m_token);
x0_generators[i] = CPF::GetChildGeneratorDesc(in, resPool, tracker).x0_res;
}
bool CCollisionResponseData::CheckAndAddDecalToResponse(FourCC clsId, CInputStream& in, CSimplePool* resPool) {

View File

@ -212,14 +212,14 @@ void CDecal::RenderMdl() {
if (desc.x5c_24_DMAB) {
const CModelFlags flags(7, 0, 1, color);
desc.x38_DMDL.m_token->Draw(flags);
desc.x38_DMDL->Draw(flags);
} else {
if (color.a() == 1.f) {
constexpr CModelFlags flags(0, 0, 3, zeus::skWhite);
desc.x38_DMDL.m_token->Draw(flags);
desc.x38_DMDL->Draw(flags);
} else {
const CModelFlags flags(5, 0, 1, color);
desc.x38_DMDL.m_token->Draw(flags);
desc.x38_DMDL->Draw(flags);
}
}
}

View File

@ -631,27 +631,27 @@ void CElementGen::UpdateChildParticleSystems(double dt) {
CGlobalRandom gr(x27c_randState);
SChildGeneratorDesc& icts = desc->x8c_x78_ICTS;
if (icts.m_found && x84_prevFrame != x74_curFrame && x2a0_CSSD == x74_curFrame) {
if (icts && x84_prevFrame != x74_curFrame && x2a0_CSSD == x74_curFrame) {
int ncsyVal = 1;
if (CIntElement* ncsy = desc->x9c_x88_NCSY.get())
ncsy->GetValue(x74_curFrame, ncsyVal);
CGenDescription* ictsDesc = icts.m_token.GetObj();
CGenDescription* ictsDesc = icts.GetObj();
if (!(x26d_27_enableOPTS && ictsDesc->x45_31_x32_25_OPTS)) {
x290_activePartChildren.reserve(ncsyVal + x290_activePartChildren.size());
for (int i = 0; i < ncsyVal; ++i) {
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(icts.m_token);
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(*icts);
x290_activePartChildren.emplace_back(std::move(chGen));
}
}
}
SChildGeneratorDesc& iits = desc->xb8_xa4_IITS;
if (iits.m_found && x84_prevFrame != x74_curFrame && x74_curFrame < x268_PSLT && x88_particleEmission == 1 &&
if (iits && x84_prevFrame != x74_curFrame && x74_curFrame < x268_PSLT && x88_particleEmission == 1 &&
x74_curFrame >= x2a4_SISY && ((x74_curFrame - x2a4_SISY) % x2a8_PISY) == 0) {
CGenDescription* iitsDesc = iits.m_token.GetObj();
CGenDescription* iitsDesc = iits.GetObj();
if (!(x26d_27_enableOPTS && iitsDesc->x45_31_x32_25_OPTS)) {
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(iits.m_token);
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(*iits);
x290_activePartChildren.emplace_back(std::move(chGen));
}
}
@ -678,24 +678,24 @@ void CElementGen::UpdateChildParticleSystems(double dt) {
}
SChildGeneratorDesc& idts = desc->xa4_x90_IDTS;
if (idts.m_found && x74_curFrame == x268_PSLT && x84_prevFrame != x74_curFrame) {
if (idts && x74_curFrame == x268_PSLT && x84_prevFrame != x74_curFrame) {
int ndsyVal = 1;
if (CIntElement* ndsy = desc->xb4_xa0_NDSY.get())
ndsy->GetValue(0, ndsyVal);
CGenDescription* idtsDesc = idts.m_token.GetObj();
CGenDescription* idtsDesc = idts.GetObj();
if (!(x26d_27_enableOPTS && idtsDesc->x45_31_x32_25_OPTS)) {
x290_activePartChildren.reserve(ndsyVal + x290_activePartChildren.size());
for (int i = 0; i < ndsyVal; ++i) {
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(idts.m_token);
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(*idts);
x290_activePartChildren.emplace_back(std::move(chGen));
}
}
}
SSwooshGeneratorDesc& sswh = desc->xd4_xc0_SSWH;
if (sswh.m_found && x84_prevFrame != x74_curFrame && x74_curFrame == x2ac_SSSD) {
std::unique_ptr<CParticleGen> sswhGen = std::make_unique<CParticleSwoosh>(sswh.m_token, 0);
if (sswh && x84_prevFrame != x74_curFrame && x74_curFrame == x2ac_SSSD) {
std::unique_ptr<CParticleGen> sswhGen = std::make_unique<CParticleSwoosh>(*sswh, 0);
sswhGen->SetGlobalTranslation(xe8_globalTranslation);
sswhGen->SetGlobalScale(x100_globalScale);
sswhGen->SetLocalScale(x16c_localScale);
@ -706,8 +706,8 @@ void CElementGen::UpdateChildParticleSystems(double dt) {
}
SElectricGeneratorDesc& selc = desc->xec_xd8_SELC;
if (selc.m_found && x84_prevFrame != x74_curFrame && x74_curFrame == x2bc_SESD) {
std::unique_ptr<CParticleGen> selcGen = std::make_unique<CParticleElectric>(selc.m_token);
if (selc && x84_prevFrame != x74_curFrame && x74_curFrame == x2bc_SESD) {
std::unique_ptr<CParticleGen> selcGen = std::make_unique<CParticleElectric>(*selc);
selcGen->SetGlobalTranslation(xe8_globalTranslation);
selcGen->SetGlobalScale(x100_globalScale);
selcGen->SetLocalScale(x16c_localScale);
@ -862,7 +862,7 @@ void CElementGen::Render(const CActorLights* actorLights) {
if (x30_particles.size()) {
SParticleModel& pmdl = desc->x5c_x48_PMDL;
if (pmdl.m_found || desc->x45_24_x31_26_PMUS)
if (pmdl || desc->x45_24_x31_26_PMUS)
RenderModels(actorLights);
if (x26c_31_LINE)
@ -1076,7 +1076,7 @@ void CElementGen::RenderModels(const CActorLights* actorLights) {
break;
}
} else {
CModel* model = desc->x5c_x48_PMDL.m_token.GetObj();
CModel* model = desc->x5c_x48_PMDL.GetObj();
if (actorLights)
actorLights->ActivateLights();
if (g_subtractBlend) {

View File

@ -37,13 +37,13 @@ SParticleModel CParticleDataFactory::GetModel(CInputStream& in, CSimplePool* res
CAssetId id = in.Get<CAssetId>();
if (!id.IsValid())
return {};
return {resPool->GetObj({FOURCC('CMDL'), id}), true};
return resPool->GetObj({FOURCC('CMDL'), id});
}
SChildGeneratorDesc CParticleDataFactory::GetChildGeneratorDesc(CAssetId res, CSimplePool* resPool,
const std::vector<CAssetId>& tracker) {
if (std::count(tracker.cbegin(), tracker.cend(), res) == 0)
return {resPool->GetObj({FOURCC('PART'), res}), true};
return resPool->GetObj({FOURCC('PART'), res});
return {};
}
@ -65,7 +65,7 @@ SSwooshGeneratorDesc CParticleDataFactory::GetSwooshGeneratorDesc(CInputStream&
CAssetId id = in.Get<CAssetId>();
if (!id.IsValid())
return {};
return {resPool->GetObj({FOURCC('SWHC'), id}), true};
return resPool->GetObj({FOURCC('SWHC'), id});
}
SElectricGeneratorDesc CParticleDataFactory::GetElectricGeneratorDesc(CInputStream& in, CSimplePool* resPool) {
@ -75,7 +75,7 @@ SElectricGeneratorDesc CParticleDataFactory::GetElectricGeneratorDesc(CInputStre
CAssetId id = in.Get<CAssetId>();
if (!id.IsValid())
return {};
return {resPool->GetObj({FOURCC('ELSC'), id}), true};
return resPool->GetObj({FOURCC('ELSC'), id});
}
std::unique_ptr<CUVElement> CParticleDataFactory::GetTextureElement(CInputStream& in, CSimplePool* resPool) {
@ -1012,20 +1012,11 @@ bool CParticleDataFactory::CreateGPSM(CGenDescription* fillDesc, CInputStream& i
}
void CParticleDataFactory::LoadGPSMTokens(CGenDescription* desc) {
if (desc->x5c_x48_PMDL.m_found)
desc->x5c_x48_PMDL.m_model = desc->x5c_x48_PMDL.m_token.GetObj();
if (desc->x8c_x78_ICTS.m_found)
desc->x8c_x78_ICTS.m_gen = desc->x8c_x78_ICTS.m_token.GetObj();
if (desc->xa4_x90_IDTS.m_found)
desc->xa4_x90_IDTS.m_gen = desc->xa4_x90_IDTS.m_token.GetObj();
if (desc->xb8_xa4_IITS.m_found)
desc->xb8_xa4_IITS.m_gen = desc->xb8_xa4_IITS.m_token.GetObj();
if (desc->xd4_xc0_SSWH.m_found)
desc->xd4_xc0_SSWH.m_swoosh = desc->xd4_xc0_SSWH.m_token.GetObj();
desc->x5c_x48_PMDL.Load();
desc->x8c_x78_ICTS.Load();
desc->xa4_x90_IDTS.Load();
desc->xb8_xa4_IITS.Load();
desc->xd4_xc0_SSWH.Load();
}
CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,

View File

@ -24,41 +24,29 @@ class CUVElement;
class CVParamTransfer;
class CVectorElement;
struct SParticleModel {
TLockedToken<CModel> m_token;
bool m_found = false;
CModel* m_model = nullptr;
SParticleModel() = default;
SParticleModel(CToken&& tok, bool found) : m_token(std::move(tok)), m_found(found) {}
explicit operator bool() const { return m_found; }
template <typename T>
struct STokenDesc {
std::optional<TLockedToken<T>> x0_res;
STokenDesc() = default;
STokenDesc(CToken&& tok) : x0_res(std::move(tok)) {}
void Load() {
if (x0_res) {
x0_res->GetObj();
}
}
explicit operator bool() const { return x0_res.has_value(); }
auto* GetObj() { return x0_res ? x0_res->GetObj() : nullptr; }
const auto* GetObj() const { return x0_res ? x0_res->GetObj() : nullptr; }
auto& operator*() { return *x0_res; }
const auto& operator*() const { return *x0_res; }
auto& operator->() { return *x0_res; }
const auto& operator->() const { return *x0_res; }
};
struct SChildGeneratorDesc {
TLockedToken<CGenDescription> m_token;
bool m_found = false;
CGenDescription* m_gen = nullptr;
SChildGeneratorDesc() = default;
SChildGeneratorDesc(CToken&& tok, bool found) : m_token(std::move(tok)), m_found(found) {}
explicit operator bool() const { return m_found; }
};
struct SSwooshGeneratorDesc {
TLockedToken<CSwooshDescription> m_token;
bool m_found = false;
CSwooshDescription* m_swoosh = nullptr;
SSwooshGeneratorDesc() = default;
SSwooshGeneratorDesc(CToken&& tok, bool found) : m_token(std::move(tok)), m_found(found) {}
explicit operator bool() const { return m_found; }
};
struct SElectricGeneratorDesc {
TLockedToken<CElectricDescription> m_token;
bool m_found = false;
CElectricDescription* m_electric = nullptr;
SElectricGeneratorDesc() = default;
SElectricGeneratorDesc(CToken&& tok, bool found) : m_token(std::move(tok)), m_found(found) {}
explicit operator bool() const { return m_found; }
};
using SParticleModel = STokenDesc<CModel>;
using SChildGeneratorDesc = STokenDesc<CGenDescription>;
using SSwooshGeneratorDesc = STokenDesc<CSwooshDescription>;
using SElectricGeneratorDesc = STokenDesc<CElectricDescription>;
class CParticleDataFactory {
friend class CDecalDataFactory;
@ -105,4 +93,4 @@ CFactoryFnReturn FParticleFactory(const SObjectTag& tag, CInputStream& in, const
// but introduce circular dependencies if included at the start
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"

View File

@ -45,7 +45,7 @@ CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token)
if (desc->x40_SSWH) {
x450_27_haveSSWH = true;
for (int i = 0; i < x154_SCNT; ++i) {
x1e0_swooshGenerators.emplace_back(std::make_unique<CParticleSwoosh>(desc->x40_SSWH.m_token, x150_SSEG));
x1e0_swooshGenerators.emplace_back(std::make_unique<CParticleSwoosh>(*desc->x40_SSWH, x150_SSEG));
x1e0_swooshGenerators.back()->DoElectricWarmup();
}
}
@ -59,7 +59,7 @@ CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token)
x450_25_haveGPSM = true;
x400_gpsmGenerators.reserve(x154_SCNT);
for (int i = 0; i < x154_SCNT; ++i) {
x400_gpsmGenerators.emplace_back(std::make_unique<CElementGen>(desc->x50_GPSM.m_token));
x400_gpsmGenerators.emplace_back(std::make_unique<CElementGen>(*desc->x50_GPSM));
x400_gpsmGenerators.back()->SetParticleEmission(false);
}
}
@ -68,7 +68,7 @@ CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token)
x450_26_haveEPSM = true;
x410_epsmGenerators.reserve(x154_SCNT);
for (int i = 0; i < x154_SCNT; ++i) {
x410_epsmGenerators.emplace_back(std::make_unique<CElementGen>(desc->x60_EPSM.m_token));
x410_epsmGenerators.emplace_back(std::make_unique<CElementGen>(*desc->x60_EPSM));
x410_epsmGenerators.back()->SetParticleEmission(false);
}
}

View File

@ -116,12 +116,9 @@ bool CParticleElectricDataFactory::CreateELSM(CElectricDescription* desc, CInput
}
void CParticleElectricDataFactory::LoadELSMTokens(CElectricDescription* desc) {
if (desc->x40_SSWH.m_found)
desc->x40_SSWH.m_swoosh = desc->x40_SSWH.m_token.GetObj();
if (desc->x50_GPSM.m_found)
desc->x50_GPSM.m_gen = desc->x50_GPSM.m_token.GetObj();
if (desc->x60_EPSM.m_found)
desc->x60_EPSM.m_gen = desc->x60_EPSM.m_token.GetObj();
desc->x40_SSWH.Load();
desc->x50_GPSM.Load();
desc->x60_EPSM.Load();
}
CFactoryFnReturn FParticleElectricDataFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,

View File

@ -124,7 +124,7 @@ bool CProjectileWeaponDataFactory::CreateWPSM(CWeaponDescription* desc, CInputSt
break;
CAssetId id(in);
if (id.IsValid())
desc->x94_COLR = {resPool->GetObj({FOURCC('CRSC'), id}), true};
desc->x94_COLR = resPool->GetObj({FOURCC('CRSC'), id});
break;
}
case SBIG('EWTR'):

View File

@ -13,13 +13,7 @@
namespace metaforce {
class CCollisionResponseData;
struct SCollisionResponseData {
TToken<CCollisionResponseData> m_res;
bool m_found = false;
SCollisionResponseData() = default;
SCollisionResponseData(CToken&& tok, bool found) : m_res(std::move(tok)), m_found(found) {}
explicit operator bool() const { return m_found; }
};
using SCollisionResponseData = STokenDesc<CCollisionResponseData>;
class CWeaponDescription {
public:

View File

@ -496,7 +496,7 @@ void CGrappleArm::RenderXRayModel(const CStateManager& mgr, const zeus::CTransfo
// g_Renderer->SetAmbientColor(zeus::skWhite);
CSkinnedModel& model = *x50_grappleArmSkeletonModel->GetAnimationData()->GetModelData();
// model.GetModelInst()->ActivateLights({CLight::BuildLocalAmbient({}, zeus::skWhite)});
x0_grappleArmModel->GetAnimationData()->Render(model, flags, std::nullopt, nullptr);
x0_grappleArmModel->GetAnimationData()->Render(model, flags, nullptr, nullptr);
// g_Renderer->SetAmbientColor(zeus::skWhite);
// CGraphics::DisableAllLights();
}

View File

@ -511,7 +511,7 @@ void CGunWeapon::DrawHologram(const CStateManager& mgr, const zeus::CTransform&
// g_Renderer->SetAmbientColor(zeus::skWhite);
CSkinnedModel& model = *x60_holoModelData->GetAnimationData()->GetModelData();
// model.GetModelInst()->ActivateLights({CLight::BuildLocalAmbient({}, zeus::skWhite)});
x10_solidModelData->GetAnimationData()->Render(model, flags, std::nullopt, nullptr);
x10_solidModelData->GetAnimationData()->Render(model, flags, nullptr, nullptr);
// g_Renderer->SetAmbientColor(zeus::skWhite);
// CGraphics::DisableAllLights();
}

View File

@ -252,12 +252,11 @@ void CPlasmaProjectile::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId send
switch (msg) {
case EScriptObjectMessage::Registered: {
xe6_27_thermalVisorFlags = 2;
const SChildGeneratorDesc& apsm = x170_projectile.GetWeaponDescription()->x34_APSM;
if (apsm)
x520_weaponGen = std::make_unique<CElementGen>(apsm.m_token);
const auto& weaponDesc = x170_projectile.GetWeaponDescription();
if (weaponDesc->x34_APSM)
x520_weaponGen = std::make_unique<CElementGen>(*weaponDesc->x34_APSM);
if (x520_weaponGen && x520_weaponGen->SystemHasLight())
CreatePlasmaLights(x170_projectile.GetWeaponDescription().GetObjectTag()->id.Value(), x520_weaponGen->GetLight(),
mgr);
CreatePlasmaLights(weaponDesc.GetObjectTag()->id.Value(), x520_weaponGen->GetLight(), mgr);
else
x520_weaponGen.reset();
if (x548_28_drawOwnerFirst)

View File

@ -21,26 +21,26 @@ CProjectileWeapon::CProjectileWeapon(const TToken<CWeaponDescription>& wDesc, co
x124_25_APSO = x4_weaponDesc->x28_APSO;
if (x4_weaponDesc->x34_APSM) {
xfc_APSMGen = std::make_unique<CElementGen>(
x4_weaponDesc->x34_APSM.m_token, CElementGen::EModelOrientationType::Normal,
*x4_weaponDesc->x34_APSM, CElementGen::EModelOrientationType::Normal,
(xe4_flags & 0x1) == 0x1 ? CElementGen::EOptionalSystemFlags::Two : CElementGen::EOptionalSystemFlags::One);
xfc_APSMGen->SetGlobalScale(scale);
}
if (x4_weaponDesc->x44_APS2) {
x100_APS2Gen = std::make_unique<CElementGen>(
x4_weaponDesc->x44_APS2.m_token, CElementGen::EModelOrientationType::Normal,
*x4_weaponDesc->x44_APS2, CElementGen::EModelOrientationType::Normal,
(xe4_flags & 0x1) == 0x1 ? CElementGen::EOptionalSystemFlags::Two : CElementGen::EOptionalSystemFlags::One);
x100_APS2Gen->SetGlobalScale(scale);
}
if (x4_weaponDesc->x54_ASW1) {
x118_swoosh1 = std::make_unique<CParticleSwoosh>(x4_weaponDesc->x54_ASW1.m_token, 0);
x118_swoosh1 = std::make_unique<CParticleSwoosh>(*x4_weaponDesc->x54_ASW1, 0);
x118_swoosh1->SetGlobalScale(scale);
}
if (x4_weaponDesc->x64_ASW2) {
x11c_swoosh2 = std::make_unique<CParticleSwoosh>(x4_weaponDesc->x64_ASW2.m_token, 0);
x11c_swoosh2 = std::make_unique<CParticleSwoosh>(*x4_weaponDesc->x64_ASW2, 0);
x11c_swoosh2->SetGlobalScale(scale);
}
if (x4_weaponDesc->x74_ASW3) {
x120_swoosh3 = std::make_unique<CParticleSwoosh>(x4_weaponDesc->x74_ASW3.m_token, 0);
x120_swoosh3 = std::make_unique<CParticleSwoosh>(*x4_weaponDesc->x74_ASW3, 0);
x120_swoosh3->SetGlobalScale(scale);
}
if (CIntElement* pslt = x4_weaponDesc->x14_PSLT.get())
@ -60,8 +60,7 @@ CProjectileWeapon::CProjectileWeapon(const TToken<CWeaponDescription>& wDesc, co
} else {
SetRelativeOrientation(zeus::CTransform());
}
if (x4_weaponDesc->x84_OHEF)
x108_model.emplace(x4_weaponDesc->x84_OHEF.m_token);
x108_model = x4_weaponDesc->x84_OHEF.x0_res;
x124_26_AP11 = x4_weaponDesc->x2a_AP11;
x124_27_AP21 = x4_weaponDesc->x2b_AP21;
x124_28_AS11 = x4_weaponDesc->x2c_AS11;
@ -124,13 +123,13 @@ std::optional<zeus::CAABox> CProjectileWeapon::GetBounds() const {
float CProjectileWeapon::GetAudibleFallOff() const {
if (!x4_weaponDesc->x94_COLR)
return 0.f;
return x4_weaponDesc->x94_COLR.m_res->GetAudibleFallOff();
return x4_weaponDesc->x94_COLR->GetAudibleFallOff();
}
float CProjectileWeapon::GetAudibleRange() const {
if (!x4_weaponDesc->x94_COLR)
return 0.f;
return x4_weaponDesc->x94_COLR.m_res->GetAudibleRange();
return x4_weaponDesc->x94_COLR->GetAudibleRange();
}
std::optional<TLockedToken<CDecalDescription>>
@ -138,13 +137,13 @@ CProjectileWeapon::GetDecalForCollision(EWeaponCollisionResponseTypes type) cons
if (!x4_weaponDesc->x94_COLR) {
return std::nullopt;
}
return x4_weaponDesc->x94_COLR.m_res->GetDecalDescription(type);
return x4_weaponDesc->x94_COLR->GetDecalDescription(type);
}
s32 CProjectileWeapon::GetSoundIdForCollision(EWeaponCollisionResponseTypes type) const {
if (!x4_weaponDesc->x94_COLR)
return -1;
return x4_weaponDesc->x94_COLR.m_res->GetSoundEffectId(type);
return x4_weaponDesc->x94_COLR->GetSoundEffectId(type);
}
std::optional<TLockedToken<CGenDescription>> CProjectileWeapon::CollisionOccured(EWeaponCollisionResponseTypes type,
@ -183,7 +182,7 @@ std::optional<TLockedToken<CGenDescription>> CProjectileWeapon::CollisionOccured
if (!x4_weaponDesc->x94_COLR) {
return std::nullopt;
}
return x4_weaponDesc->x94_COLR.m_res->GetParticleDescription(type);
return x4_weaponDesc->x94_COLR->GetParticleDescription(type);
}
}