CElementGen: Make use of std::array where applicable

This commit is contained in:
Lioncash 2020-03-09 12:37:15 -04:00
parent 35adfe8abf
commit 9db07b037a
3 changed files with 31 additions and 25 deletions

View File

@ -249,28 +249,28 @@ void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Conte
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{gen.m_uniformBuf.get()};
if (regPipeline != nullptr) {
for (size_t i = 0; i < std::size(gen.m_normalDataBind); ++i) {
for (size_t i = 0; i < gen.m_normalDataBind.size(); ++i) {
gen.m_normalDataBind[i] =
ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(),
uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
}
}
if (regPipelineSub != nullptr) {
for (size_t i = 0; i < std::size(gen.m_normalSubDataBind); ++i) {
for (size_t i = 0; i < gen.m_normalSubDataBind.size(); ++i) {
gen.m_normalSubDataBind[i] =
ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(),
uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
}
}
if (redToAlphaPipeline != nullptr) {
for (size_t i = 0; i < std::size(gen.m_redToAlphaDataBind); ++i) {
for (size_t i = 0; i < gen.m_redToAlphaDataBind.size(); ++i) {
gen.m_redToAlphaDataBind[i] =
ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(),
uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
}
}
if (redToAlphaPipelineSub != nullptr) {
for (size_t i = 0; i < std::size(gen.m_redToAlphaSubDataBind); ++i) {
for (size_t i = 0; i < gen.m_redToAlphaSubDataBind.size(); ++i) {
gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding(
(*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(),
nullptr, texCount, textures.data(), nullptr, nullptr);
@ -283,14 +283,14 @@ void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Conte
texCount = std::min(texCount, 1);
if (regPipelinePmus != nullptr) {
for (size_t i = 0; i < std::size(gen.m_normalDataBindPmus); ++i) {
for (size_t i = 0; i < gen.m_normalDataBindPmus.size(); ++i) {
gen.m_normalDataBindPmus[i] =
ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(),
uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr);
}
}
if (redToAlphaPipelinePmus != nullptr) {
for (size_t i = 0; i < std::size(gen.m_redToAlphaDataBindPmus); ++i) {
for (size_t i = 0; i < gen.m_redToAlphaDataBindPmus.size(); ++i) {
gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding(
(*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(),
nullptr, texCount, textures.data(), nullptr, nullptr);

View File

@ -16,7 +16,15 @@
#define MAX_GLOBAL_PARTICLES 2560
namespace urde {
static logvisor::Module Log("urde::CElementGen");
namespace {
logvisor::Module Log("urde::CElementGen");
constexpr std::array ShadClsSizes{
sizeof(SParticleInstanceTex),
sizeof(SParticleInstanceIndTex),
sizeof(SParticleInstanceNoTex),
};
} // Anonymous namespace
u16 CElementGen::g_GlobalSeed = 99;
bool CElementGen::g_subtractBlend = false;
@ -45,9 +53,6 @@ void CElementGen::Initialize() {
void CElementGen::Shutdown() { CElementGenShaders::Shutdown(); }
static const size_t ShadClsSizes[] = {sizeof(SParticleInstanceTex), sizeof(SParticleInstanceIndTex),
sizeof(SParticleInstanceNoTex)};
CElementGen::CElementGen(const TToken<CGenDescription>& gen, EModelOrientationType orientType,
EOptionalSystemFlags flags)
: x1c_genDesc(gen), x2c_orientType(orientType), x27c_randState(x94_randomSeed) {
@ -212,11 +217,11 @@ CElementGen::CElementGen(const TToken<CGenDescription>& gen, EModelOrientationTy
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
if (!x26c_31_LINE) {
m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[int(m_shaderClass)], maxInsts);
m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts);
m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1);
}
if (desc->x45_24_x31_26_PMUS) {
m_instBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[int(m_shaderClass)], maxInsts);
m_instBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts);
m_uniformBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1);
}
CElementGenShaders::BuildShaderDataBinding(ctx, *this);
@ -366,7 +371,7 @@ void CElementGen::UpdateAdvanceAccessParameters(u32 activeParticleCount, u32 par
adv8->GetValue(particleFrame, arr[7]);
}
bool CElementGen::UpdateVelocitySource(u32 idx, u32 particleFrame, CParticle& particle) {
bool CElementGen::UpdateVelocitySource(size_t idx, u32 particleFrame, CParticle& particle) {
bool err;
if (x278_hasVMD[idx]) {
zeus::CVector3f localVel = x208_orientationInverse * particle.x1c_vel;
@ -433,9 +438,10 @@ void CElementGen::UpdateExistingParticles() {
++x25c_activeParticleCount;
for (int i = 0; i < 4; ++i) {
if (!x280_VELSources[i])
for (size_t i = 0; i < x280_VELSources.size(); ++i) {
if (!x280_VELSources[i]) {
break;
}
UpdateVelocitySource(i, particleFrame, particle);
}

View File

@ -68,7 +68,7 @@ private:
int m_maxMAXP = 256;
u16 x94_randomSeed = g_GlobalSeed;
float x98_generatorRate = 1.f;
float x9c_externalVars[16] = {};
std::array<float, 16> x9c_externalVars{};
zeus::CVector3f xdc_translation;
zeus::CVector3f xe8_globalTranslation;
@ -110,9 +110,9 @@ private:
int x270_MBSP = 0;
int m_maxMBSP = 0;
ERglLightBits x274_backupLightActive = ERglLightBits::None;
bool x278_hasVMD[4] = {};
std::array<bool, 4> x278_hasVMD{};
CRandom16 x27c_randState;
CModVectorElement* x280_VELSources[4] = {};
std::array<CModVectorElement*, 4> x280_VELSources{};
std::vector<std::unique_ptr<CParticleGen>> x290_activePartChildren;
int x2a0_CSSD = 0;
@ -148,15 +148,15 @@ public:
EOptionalSystemFlags flags = EOptionalSystemFlags::One);
~CElementGen() override;
boo::ObjToken<boo::IShaderDataBinding> m_normalDataBind[2];
boo::ObjToken<boo::IShaderDataBinding> m_normalSubDataBind[2];
boo::ObjToken<boo::IShaderDataBinding> m_redToAlphaDataBind[2];
boo::ObjToken<boo::IShaderDataBinding> m_redToAlphaSubDataBind[2];
std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_normalDataBind;
std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_normalSubDataBind;
std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_redToAlphaDataBind;
std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_redToAlphaSubDataBind;
boo::ObjToken<boo::IGraphicsBufferD> m_instBuf;
boo::ObjToken<boo::IGraphicsBufferD> m_uniformBuf;
boo::ObjToken<boo::IShaderDataBinding> m_normalDataBindPmus[2];
boo::ObjToken<boo::IShaderDataBinding> m_redToAlphaDataBindPmus[2];
std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_normalDataBindPmus;
std::array<boo::ObjToken<boo::IShaderDataBinding>, 2> m_redToAlphaDataBindPmus;
boo::ObjToken<boo::IGraphicsBufferD> m_instBufPmus;
boo::ObjToken<boo::IGraphicsBufferD> m_uniformBufPmus;
@ -171,7 +171,7 @@ public:
static void Shutdown();
void UpdateAdvanceAccessParameters(u32 activeParticleCount, u32 particleFrame);
bool UpdateVelocitySource(u32 idx, u32 particleFrame, CParticle& particle);
bool UpdateVelocitySource(size_t idx, u32 particleFrame, CParticle& particle);
void UpdateExistingParticles();
void CreateNewParticles(int);
void UpdatePSTranslationAndOrientation();