// // SizeModule.cpp // cocos2d_libs // // Created by 徐俊杰 on 2020/4/24. // #include "rparticle/Modules/SizeModule.h" //#include "UnityPrefix.h" //#include "rparticle/Modules/SizeModule.h" //#include "Runtime/BaseClasses/ObjectDefines.h" #include "rparticle/Serialize/TransferFunctions/SerializeTransfer.h" #include "rparticle/Math/Random/Random.h" #include "rparticle/ParticleSystemUtils.h" NS_RRP_BEGIN template void UpdateTpl(const MinMaxCurve& curve, const ParticleSystemParticles& ps, float* tempSize, size_t fromIndex, size_t toIndex) { for (size_t q = fromIndex; q < toIndex; ++q) { const float time = NormalizedTime(ps, q); const float random = GenerateRandom(ps.randomSeed[q] + kParticleSystemSizeCurveId); tempSize[q] *= MAX(0.0f, Evaluate (curve, time, random)); } } template void UpdateTplSingle(const MinMaxCurve& curve, const ParticleSystemParticle& particle, float& tempSize) { const float time = NormalizedTime(particle); const float random = GenerateRandom(particle.randomSeed + kParticleSystemSizeCurveId); tempSize *= std::max(0.0f, Evaluate(curve, time, random)); } SizeModule::SizeModule() : ParticleSystemModule(false) {} void SizeModule::Update (const ParticleSystemParticles& ps, float* tempSize, size_t fromIndex, size_t toIndex) { DebugAssert(toIndex <= ps.array_size ()); if(m_Curve.minMaxState == kMMCScalar) UpdateTpl(m_Curve, ps, tempSize, fromIndex, toIndex); else if (m_Curve.IsOptimized() && m_Curve.UsesMinMax ()) UpdateTpl(m_Curve, ps, tempSize, fromIndex, toIndex); else if(m_Curve.IsOptimized()) UpdateTpl(m_Curve, ps, tempSize, fromIndex, toIndex); else UpdateTpl(m_Curve, ps, tempSize, fromIndex, toIndex); } void SizeModule::UpdateSingle(const ParticleSystemParticle& particle, bool uses3DSize, float& tempSize) const { if(m_Curve.minMaxState == kMMCScalar) UpdateTplSingle(m_Curve, particle, tempSize); else if (m_Curve.IsOptimized() && m_Curve.UsesMinMax ()) UpdateTplSingle(m_Curve, particle, tempSize); else if(m_Curve.IsOptimized()) UpdateTplSingle(m_Curve, particle, tempSize); else UpdateTplSingle(m_Curve, particle, tempSize); } template void SizeModule::Transfer (TransferFunction& transfer) { ParticleSystemModule::Transfer (transfer); transfer.Transfer (m_Curve, "curve"); } INSTANTIATE_TEMPLATE_TRANSFER(SizeModule) NS_RRP_END