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

Method SaveToCMF

trinity/Particle/Tr2ParticleSystem.cpp:1371–1471  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Saves current particle data into a CMF file. Arguments: resPath - Resource path of the CMF file to save particle data to. --------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1369// resPath - Resource path of the CMF file to save particle data to.
1370// --------------------------------------------------------------------------------------
1371void Tr2ParticleSystem::SaveToCMF( const char* resPath ) const
1372{
1373 if( !m_isValid )
1374 {
1375 return;
1376 }
1377
1378 std::wstring resPathW = (const wchar_t*)CA2W( resPath );
1379 std::wstring filename = BePaths->ResolvePathForWritingW( resPathW );
1380
1381#if WITH_GRANNY
1382 if( filename.size() >= 4 && filename.compare( filename.size() - 4, 4, L".gr2" ) == 0 )
1383 {
1384 return SaveToGranny( resPath );
1385 }
1386#endif
1387
1388 cmf::MemoryAllocator allocator;
1389 cmf::BufferManager bufferAllocator( allocator );
1390 cmf::Span<cmf::VertexElement> cmfVertexDecl = allocator.AllocateSpan<cmf::VertexElement>( m_elementMap.size() );
1391
1392 unsigned vertexSize = 0;
1393 std::map<Tr2ParticleElementDeclarationName, unsigned> offsets;
1394
1395 Tr2VertexDefinition vd;
1396 for( auto i = m_elementMap.begin(); i != m_elementMap.end(); ++i )
1397 {
1398 static const unsigned dimensions[] = {
1399 Tr2VertexDefinition::DT_SIZE_1,
1400 Tr2VertexDefinition::DT_SIZE_2,
1401 Tr2VertexDefinition::DT_SIZE_3,
1402 Tr2VertexDefinition::DT_SIZE_4,
1403 };
1404 auto& item = vd.Add( static_cast<Tr2VertexDefinition::DataType>( vd.FLOAT32_1 | dimensions[i->second.m_dimension - 1] ), i->first.GetD3DUsage(), i->second.m_usageIndex, 0 );
1405 item.m_offset = vertexSize;
1406
1407 offsets[i->first] = vertexSize;
1408
1409 vertexSize += i->second.m_dimension;
1410 }
1411 if( !ConvertVertexDeclToCMF( vd, cmfVertexDecl, (uint32_t)cmfVertexDecl.size() ) )
1412 {
1413 return;
1414 }
1415
1416 unsigned totalSize = 0;
1417 for( unsigned i = 0; i < Tr2ParticleElementData::COUNT; ++i )
1418 {
1419 totalSize += m_vertexSizes[i];
1420 }
1421 std::vector<float> vertices;
1422 vertices.resize( totalSize * m_aliveCount );
1423 if( m_aliveCount )
1424 {
1425 float* vertex = vertices.data();
1426 for( unsigned i = 0; i < m_aliveCount; ++i )
1427 {
1428 for( auto j = m_elementMap.begin(); j != m_elementMap.end(); ++j )

Callers

nothing calls this directly

Calls 8

ConvertVertexDeclToCMFFunction · 0.85
fopen_sFunction · 0.85
sizeMethod · 0.80
GetD3DUsageMethod · 0.80
AllocateStringMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected