MCPcopy Create free account
hub / github.com/carbonengine/trinity / UpdateElementDeclaration

Method UpdateElementDeclaration

trinity/Particle/Tr2ParticleSystem.cpp:1147–1256  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Rebuilds internal particle element declaration based on m_elements list. --------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1145// Rebuilds internal particle element declaration based on m_elements list.
1146// --------------------------------------------------------------------------------------
1147void Tr2ParticleSystem::UpdateElementDeclaration()
1148{
1149 m_isValid = false;
1150 DestroyBuffers();
1151 m_declaration = Tr2EffectStateManager::UNINITIALIZED_DECLARATION;
1152 m_elementMap.clear();
1153 for( unsigned i = 0; i < Tr2ParticleElementDeclarationName::CUSTOM; ++i )
1154 {
1155 m_semanticElements[i].m_offset = -1;
1156 }
1157 for( unsigned i = 0; i < Tr2ParticleElementData::COUNT; ++i )
1158 {
1159 CCP_ALIGNED_FREE( m_buffers[i] );
1160 m_buffers[i] = nullptr;
1161 m_vertexSizes[i] = 0;
1162 }
1163
1164 m_aliveCount = 0;
1165
1166 if( m_elements.empty() )
1167 {
1168 return;
1169 }
1170
1171 // Check for duplicate semantics and usage indexes
1172 bool semantics[Tr2ParticleElementDeclarationName::CUSTOM];
1173 static const unsigned USAGE_INDEX_COUNT = 8;
1174 bool usages[USAGE_INDEX_COUNT];
1175 std::fill( std::begin( semantics ), std::end( semantics ), false );
1176 std::fill( std::begin( usages ), std::end( usages ), false );
1177 for( auto it = m_elements.begin(); it != m_elements.end(); ++it )
1178 {
1179 if( ( *it )->m_name.m_type != Tr2ParticleElementDeclarationName::CUSTOM )
1180 {
1181 if( semantics[( *it )->m_name.m_type] )
1182 {
1183 CCP_LOGERR( "Duplicate semantics %s in a particle system", ( *it )->GetName().c_str() );
1184 return;
1185 }
1186 semantics[( *it )->m_name.m_type] = true;
1187 }
1188 else if( ( *it )->m_usedByGPU )
1189 {
1190 if( ( *it )->m_usageIndex >= USAGE_INDEX_COUNT )
1191 {
1192 CCP_LOGERR(
1193 "Particle declaration element %s usage index %u is out of range (needs to be less than %u)",
1194 ( *it )->GetName().c_str(),
1195 ( *it )->m_usageIndex,
1196 USAGE_INDEX_COUNT );
1197 return;
1198 }
1199 if( usages[( *it )->m_usageIndex] )
1200 {
1201 CCP_LOGERR( "Duplicate usage index %u for particle declaration element %s", ( *it )->m_usageIndex, ( *it )->GetName().c_str() );
1202 return;
1203 }
1204 usages[( *it )->m_usageIndex] = true;

Callers 1

RefreshMethod · 0.80

Calls 8

emptyMethod · 0.80
beginFunction · 0.50
endFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
GetNameMethod · 0.45
GetSizeMethod · 0.45
BindMethod · 0.45

Tested by

no test coverage detected