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

Method Bind

trinity/Particle/Tr2PlaneConstraint.cpp:197–255  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Implements ITr2GenericParticleConstraint interface. A chance for constraint to bind itself to a particle system. Called when constaint is added to the particle system or when system is re-binded. Arguments: system - Particle system the constaint is attached to. --------------------------------------

Source from the content-addressed store, hash-verified

195// system - Particle system the constaint is attached to.
196// --------------------------------------------------------------------------------------
197void Tr2PlaneConstraint::Bind( Tr2ParticleSystem* system )
198{
199 m_isValid = false;
200 const Tr2ParticleElementDataMap& declaration = system->GetElementDeclaration();
201
202 Tr2ParticleElementDeclarationName position( Tr2ParticleElementDeclarationName::POSITION );
203 auto i = declaration.find( position );
204 if( i == declaration.end() )
205 {
206 CCP_LOGERR( "Tr2PlaneConstraint needs POSITION particle element in the system" );
207 return;
208 }
209 else
210 {
211 m_positionElement = i->second;
212 }
213
214 Tr2ParticleElementDeclarationName velocity( Tr2ParticleElementDeclarationName::VELOCITY );
215 i = declaration.find( velocity );
216 if( i == declaration.end() )
217 {
218 m_velocityElement.m_bufferType = m_velocityElement.GPU;
219 m_velocityElement.m_offset = -1;
220 }
221 else
222 {
223 m_velocityElement = i->second;
224 }
225
226 if( !m_particleRadiusComponent.empty() )
227 {
228 Tr2ParticleElementDeclarationName size( Tr2ParticleElementDeclarationName::CUSTOM, m_particleRadiusComponent.c_str() );
229 i = declaration.find( size );
230 if( i == declaration.end() )
231 {
232 CCP_LOGERR( "Tr2PlaneConstraint can not find particle size component \"%s\" in thesystem", m_particleRadiusComponent.c_str() );
233 return;
234 }
235 else
236 {
237 m_radiusElement = i->second;
238 }
239 }
240 else
241 {
242 m_radiusElement.m_bufferType = m_radiusElement.GPU;
243 m_radiusElement.m_offset = -1;
244 }
245
246 std::set<Tr2ParticleElementDeclarationName> boundElements;
247 for( auto it = m_generators.begin(); it != m_generators.end(); ++it )
248 {
249 if( !( *it )->Bind( declaration, boundElements ) )
250 {
251 return;
252 }
253 }
254 m_isValid = true;

Callers 5

OnListModifiedMethod · 0.45
RebindConstraintsMethod · 0.45
RebindMethod · 0.45
RefreshMethod · 0.45

Calls 3

emptyMethod · 0.80
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected