| 1737 | } |
| 1738 | |
| 1739 | void LoadResources(Prototype* prototype, dmParticleDDF::ParticleFX* ddf) |
| 1740 | { |
| 1741 | uint32_t emitter_count = ddf->m_Emitters.m_Count; |
| 1742 | if (prototype->m_DDF != 0x0) |
| 1743 | { |
| 1744 | dmDDF::FreeMessage(prototype->m_DDF); |
| 1745 | } |
| 1746 | prototype->m_DDF = ddf; |
| 1747 | prototype->m_Emitters.SetCapacity(emitter_count); |
| 1748 | prototype->m_Emitters.SetSize(emitter_count); |
| 1749 | |
| 1750 | memset(prototype->m_Emitters.Begin(), 0, emitter_count * sizeof(EmitterPrototype)); |
| 1751 | for (uint32_t i = 0; i < emitter_count; ++i) |
| 1752 | { |
| 1753 | dmParticleDDF::Emitter* emitter_ddf = &ddf->m_Emitters[i]; |
| 1754 | // Add-alpha is deprecated because of premultiplied alpha and replaced by Add |
| 1755 | if (emitter_ddf->m_BlendMode == dmParticleDDF::BLEND_MODE_ADD_ALPHA) |
| 1756 | emitter_ddf->m_BlendMode = dmParticleDDF::BLEND_MODE_ADD; |
| 1757 | EmitterPrototype* emitter = &prototype->m_Emitters[i]; |
| 1758 | emitter->m_Animation = dmHashString64(emitter_ddf->m_Animation); |
| 1759 | emitter->m_BlendMode = emitter_ddf->m_BlendMode; |
| 1760 | emitter->m_Id = dmHashString64(emitter_ddf->m_Id); |
| 1761 | // Approximate splines with linear segments |
| 1762 | memset(emitter->m_Properties, 0, sizeof(emitter->m_Properties)); |
| 1763 | memset(emitter->m_ParticleProperties, 0, sizeof(emitter->m_ParticleProperties)); |
| 1764 | uint32_t prop_count = emitter_ddf->m_Properties.m_Count; |
| 1765 | for (uint32_t j = 0; j < prop_count; ++j) |
| 1766 | { |
| 1767 | const dmParticleDDF::Emitter::Property& p = emitter_ddf->m_Properties[j]; |
| 1768 | if (p.m_Key < dmParticleDDF::EMITTER_KEY_COUNT) |
| 1769 | { |
| 1770 | Property& property = emitter->m_Properties[p.m_Key]; |
| 1771 | SampleProperty(p.m_Points.m_Data, p.m_Points.m_Count, property.m_Segments); |
| 1772 | property.m_Spread = p.m_Spread; |
| 1773 | } |
| 1774 | else |
| 1775 | { |
| 1776 | dmLogWarning("The key %d is not a valid emitter key.", p.m_Key); |
| 1777 | } |
| 1778 | } |
| 1779 | // Calculate max life time |
| 1780 | const Property& life_time = emitter->m_Properties[dmParticleDDF::EMITTER_KEY_PARTICLE_LIFE_TIME]; |
| 1781 | float max_life_time = 0.0f; |
| 1782 | for (uint32_t j = 0; j < PROPERTY_SAMPLE_COUNT; ++j) |
| 1783 | { |
| 1784 | const LinearSegment& s = life_time.m_Segments[j]; |
| 1785 | max_life_time = dmMath::Max(dmMath::Select(s.m_K, s.m_Y + s.m_K, s.m_Y), max_life_time); |
| 1786 | } |
| 1787 | emitter->m_MaxParticleLifeTime = max_life_time; |
| 1788 | // particle properties |
| 1789 | prop_count = emitter_ddf->m_ParticleProperties.m_Count; |
| 1790 | for (uint32_t i = 0; i < prop_count; ++i) |
| 1791 | { |
| 1792 | const dmParticleDDF::Emitter::ParticleProperty& p = emitter_ddf->m_ParticleProperties[i]; |
| 1793 | if (p.m_Key < dmParticleDDF::PARTICLE_KEY_COUNT) |
| 1794 | { |
| 1795 | SampleProperty(p.m_Points.m_Data, p.m_Points.m_Count, emitter->m_ParticleProperties[p.m_Key].m_Segments); |
| 1796 | } |
no test coverage detected