2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-14 13:26:09 +00:00

Rework particle token descriptions

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

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: