Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.6 KiB

  1. //=========== (C) Copyright 1999 Valve, L.L.C. All rights reserved. ===========
  2. //
  3. // The copyright to the contents herein is the property of Valve, L.L.C.
  4. // The contents may be used and/or copied only with the written permission of
  5. // Valve, L.L.C., or in accordance with the terms and conditions stipulated in
  6. // the agreement/contract under which the contents have been supplied.
  7. //
  8. // $Header: $
  9. // $NoKeywords: $
  10. //
  11. // Material editor
  12. //=============================================================================
  13. #include "mksutil.h"
  14. #include "tier2/fileutils.h"
  15. void CMksUtil::Init( const char *objectName )
  16. {
  17. m_SequenceCount = 0;
  18. m_Name = objectName;
  19. }
  20. void CMksUtil::CreateNewSequenceEntry()
  21. {
  22. int index = m_MksEntries.AddToTail();
  23. m_MksEntries[index].entryType = ENTRYTYPE_SEQUENCE;
  24. m_MksEntries[index].sequenceNumber = m_SequenceCount;
  25. m_SequenceCount++;
  26. }
  27. void CMksUtil::CreateNewFrameEntry( const char* pFrameName, float displayTime )
  28. {
  29. int index = m_MksEntries.AddToTail();
  30. m_MksEntries[index].entryType = ENTRYTYPE_FRAME;
  31. m_MksEntries[index].pFrameName = pFrameName;
  32. m_MksEntries[index].displayTime = displayTime;
  33. }
  34. CUtlString CMksUtil::GetName()
  35. {
  36. return m_Name;
  37. }
  38. void CMksUtil::WriteFile()
  39. {
  40. if ( m_Name.IsEmpty() )
  41. {
  42. Msg( "Error: No mks output filename set!\n" );
  43. return;
  44. }
  45. CUtlString mksFileName = m_Name;
  46. mksFileName += ".mks";
  47. char pMksFileFullPath[ MAX_PATH ];
  48. if ( !GenerateFullPath( mksFileName, NULL, pMksFileFullPath, sizeof( pMksFileFullPath ) ) )
  49. {
  50. Warning( "CDataModel: Unable to generate full path for file %s\n", mksFileName );
  51. return;
  52. }
  53. COutputTextFile Outfile( pMksFileFullPath );
  54. if ( !Outfile.IsOk() )
  55. {
  56. Msg( "Error: failed to write MKS \"%s\"!\n", pMksFileFullPath );
  57. return;
  58. }
  59. char buffer[33];
  60. for ( int i = m_MksEntries.Head(); i < m_MksEntries.InvalidIndex(); i = m_MksEntries.Next( i ) )
  61. {
  62. if ( m_MksEntries[i].entryType == ENTRYTYPE_SEQUENCE )
  63. {
  64. Outfile.Write( "\n", sizeof( char ) );
  65. Outfile.Write( "sequence ", sizeof( char ) * Q_strlen("sequence ") );
  66. itoa( m_MksEntries[i].sequenceNumber, buffer, 10 );
  67. Outfile.Write( buffer, sizeof( char ) * Q_strlen(buffer) );
  68. }
  69. else if ( m_MksEntries[i].entryType == ENTRYTYPE_FRAME )
  70. {
  71. Outfile.Write( "frame ", sizeof( char ) * Q_strlen("frame ") );
  72. Outfile.Write( m_MksEntries[i].pFrameName, sizeof( char ) * Q_strlen(m_MksEntries[i].pFrameName) );
  73. Outfile.Write( " ", sizeof( char ) );
  74. sprintf( buffer, "%.1f", m_MksEntries[i].displayTime );
  75. Outfile.Write( buffer, sizeof( char ) * Q_strlen(buffer) );
  76. }
  77. Outfile.Write( "\n", sizeof( char ) );
  78. }
  79. Msg( "Ok: successfully saved MKS \"%s\"\n", pMksFileFullPath );
  80. }