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.

161 lines
4.5 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 "vstdlib/cvar.h"
  14. #include "appframework/vguimatsysapp.h"
  15. #include "nowindows.h"
  16. #include "FileSystem.h"
  17. #include "materialsystem/IMaterialSystem.h"
  18. #include "vgui/IVGui.h"
  19. #include "vgui/ISystem.h"
  20. #include "vgui_controls/Panel.h"
  21. #include "vgui/ISurface.h"
  22. #include "vgui_controls/controls.h"
  23. #include "vgui/IScheme.h"
  24. #include "vgui/ILocalize.h"
  25. #include "vgui/IPanel.h"
  26. #include "tier0/dbg.h"
  27. #include "vgui_controls/Frame.h"
  28. #include "vgui_controls/AnimationController.h"
  29. #include "tier0/icommandline.h"
  30. #include "materialsystem/MaterialSystem_Config.h"
  31. #include "VGuiMatSurface/IMatSystemSurface.h"
  32. #include "filesystem_init.h"
  33. #include "vstdlib/iprocessutils.h"
  34. #include "matsys_controls/matsyscontrols.h"
  35. #include "matsys_controls/mdlpicker.h"
  36. #include "IStudioRender.h"
  37. #include "datacache/idatacache.h"
  38. #include "datacache/imdlcache.h"
  39. #include "vphysics_interface.h"
  40. #include "vgui_controls/frame.h"
  41. #include "materialsystem/IMaterialSystemHardwareConfig.h"
  42. #include "materialsystem/materialsystemutil.h"
  43. #include "tier3/tier3.h"
  44. #include "vgui_controls/consoledialog.h"
  45. #include "icvar.h"
  46. #include "vgui/keycode.h"
  47. #include "vguimaterial.h"
  48. #include "tier0/vprof.h"
  49. #include "tier0/progressbar.h"
  50. #include "amalg_texture_vars.h"
  51. #include "amalg_texture.h"
  52. #include "dmeamalgtexture.h"
  53. #include "datamodel/dmelement.h"
  54. #include "datamodel/dmelementfactoryhelper.h"
  55. #include "tier2/fileutils.h"
  56. #include "amalg_texture_parser.h"
  57. #include "dmserializers/idmserializers.h"
  58. //-----------------------------------------------------------------------------
  59. // The application object
  60. //-----------------------------------------------------------------------------
  61. class CMksUtil
  62. {
  63. public:
  64. enum
  65. {
  66. ENTRYTYPE_SEQUENCE,
  67. ENTRYTYPE_FRAME,
  68. ENTRYTYPE_MAX
  69. };
  70. struct sMKSInfo
  71. {
  72. int entryType;
  73. int sequenceNumber;
  74. const char *pFrameName; // array?
  75. float displayTime;
  76. };
  77. void GenerateMKSEntries();
  78. void GenerateMKSFile( const char *pMksFileName );
  79. void CreateNewSequenceEntry();
  80. void CreateNewFrameEntry( const char* pFrameName, float displayTime = 1.0f );
  81. private:
  82. CUtlLinkedList< sMKSInfo > m_MksEntries;
  83. int m_SequenceCount;
  84. };
  85. void CMksUtil::CreateNewSequenceEntry()
  86. {
  87. int index = m_MksEntries.AddToTail();
  88. m_MksEntries[index].entryType = ENTRYTYPE_SEQUENCE;
  89. m_MksEntries[index].sequenceNumber = m_SequenceCount;
  90. m_SequenceCount++;
  91. }
  92. void CMksUtil::CreateNewFrameEntry( const char* pFrameName, float displayTime )
  93. {
  94. int index = m_MksEntries.AddToTail();
  95. m_MksEntries[index].entryType = ENTRYTYPE_FRAME;
  96. m_MksEntries[index].pFrameName = pFrameName;
  97. m_MksEntries[index].displayTime = displayTime;
  98. }
  99. void CMksUtil::GenerateMKSFile( const char *pMksFileName )
  100. {
  101. if ( pMksFileName == NULL )
  102. {
  103. Msg( "Error: No mks output filename set!\n" );
  104. return;
  105. }
  106. char pMksFileFullPath[ MAX_PATH ];
  107. if ( !GenerateFullPath( pMksFileName, NULL, pMksFileFullPath, sizeof( pMksFileFullPath ) ) )
  108. {
  109. Warning( "CDataModel: Unable to generate full path for file %s\n", pMksFileName );
  110. return;
  111. }
  112. COutputTextFile Outfile( pMksFileFullPath );
  113. if ( !Outfile.IsOk() )
  114. {
  115. Msg( "Error: failed to write MKS \"%s\"!\n", pMksFileFullPath );
  116. return;
  117. }
  118. char buffer[33];
  119. for ( int i = m_MksEntries.Head(); i < m_MksEntries.InvalidIndex(); i = m_MksEntries.Next( i ) )
  120. {
  121. if ( m_MksEntries[i].entryType == ENTRYTYPE_SEQUENCE )
  122. {
  123. Outfile.Write( "\n", sizeof( char ) );
  124. Outfile.Write( "sequence ", sizeof( char ) * Q_strlen("sequence ") );
  125. itoa( m_MksEntries[i].sequenceNumber, buffer, 10 );
  126. Outfile.Write( buffer, sizeof( char ) * Q_strlen(buffer) );
  127. }
  128. else if ( m_MksEntries[i].entryType == ENTRYTYPE_FRAME )
  129. {
  130. Outfile.Write( "frame ", sizeof( char ) * Q_strlen("frame ") );
  131. Outfile.Write( m_MksEntries[i].pFrameName, sizeof( char ) * Q_strlen(m_MksEntries[i].pFrameName) );
  132. Outfile.Write( " ", sizeof( char ) );
  133. sprintf( buffer, "%.1f", m_MksEntries[i].displayTime );
  134. Outfile.Write( buffer, sizeof( char ) * Q_strlen(buffer) );
  135. }
  136. Outfile.Write( "\n", sizeof( char ) );
  137. }
  138. Msg( "Ok: successfully saved MKS \"%s\"\n", pMksFileFullPath );
  139. }