Team Fortress 2 Source Code as on 22/4/2020
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.

109 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "unitlib/unitlib.h"
  9. #include "datamodel/dmelement.h"
  10. #include "movieobjects/movieobjects.h"
  11. #include "datamodel/idatamodel.h"
  12. #include "tier1/utlbuffer.h"
  13. #include "filesystem.h"
  14. #include "movieobjects/dmelog.h"
  15. #include "choreoscene.h"
  16. #include "choreoevent.h"
  17. #include "iscenetokenprocessor.h"
  18. #include "tier1/tokenreader.h"
  19. #include "characterset.h"
  20. #include "movieobjects/dmx_to_vcd.h"
  21. #include "tier3/scenetokenprocessor.h"
  22. #include "tier2/tier2.h"
  23. char const *vcdtestfile = "dmxtest.vcd";
  24. void RunSceneToDmxTests( CChoreoScene *scene )
  25. {
  26. DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( scene->GetFilename() );
  27. CDmeFilmClip *dmx = CreateElement< CDmeFilmClip >( scene->GetFilename(), fileid );
  28. Assert( dmx );
  29. bool success = ConvertSceneToDmx( scene, dmx );
  30. Assert( success );
  31. CChoreoScene *scene2 = new CChoreoScene( NULL );
  32. scene2->SetFileName( scene->GetFilename() );
  33. success = ConvertDmxToScene( dmx, scene2 );
  34. Assert( success );
  35. char sz[ 512 ];
  36. Q_StripExtension( scene->GetFilename(), sz, sizeof( sz ) );
  37. Q_strncat( sz, "_2.vcd", sizeof( sz ), COPY_ALL_CHARACTERS );
  38. scene2->SaveToFile( sz );
  39. delete scene2;
  40. g_pDataModel->RemoveFileId( fileid );
  41. }
  42. DEFINE_TESTCASE_NOSUITE( DmxTestVcdToDme )
  43. {
  44. Msg( "Running .vcd (faceposer) to dmx tests\n" );
  45. #ifdef _DEBUG
  46. int nStartingCount = g_pDataModel->GetAllocatedElementCount();
  47. #endif
  48. CDisableUndoScopeGuard guard;
  49. g_pDmElementFramework->BeginEdit();
  50. const char *pFileName = vcdtestfile;
  51. char pFullPathName[ MAX_PATH ];
  52. char pDir[ MAX_PATH ];
  53. if ( g_pFullFileSystem->GetCurrentDirectory( pDir, sizeof( pDir ) ) )
  54. {
  55. V_ComposeFileName( pDir, vcdtestfile, pFullPathName, sizeof( pFullPathName ) );
  56. V_RemoveDotSlashes( pFullPathName );
  57. pFileName = pFullPathName;
  58. }
  59. CUtlBuffer buf;
  60. if ( g_pFullFileSystem->ReadFile( pFileName, NULL, buf ) )
  61. {
  62. SetTokenProcessorBuffer( (char *)buf.Base() );
  63. CChoreoScene *scene = ChoreoLoadScene( pFileName, NULL, GetTokenProcessor(), NULL );
  64. if ( scene )
  65. {
  66. RunSceneToDmxTests( scene );
  67. delete scene;
  68. }
  69. }
  70. else
  71. {
  72. Msg( "Unable to load test file '%s'\n", pFileName );
  73. }
  74. g_pDataModel->ClearUndo();
  75. #ifdef _DEBUG
  76. int nEndingCount = g_pDataModel->GetAllocatedElementCount();
  77. AssertEquals( nEndingCount, nStartingCount );
  78. if ( nEndingCount != nStartingCount )
  79. {
  80. for ( DmElementHandle_t hElement = g_pDataModel->FirstAllocatedElement() ;
  81. hElement != DMELEMENT_HANDLE_INVALID;
  82. hElement = g_pDataModel->NextAllocatedElement( hElement ) )
  83. {
  84. CDmElement *pElement = g_pDataModel->GetElement( hElement );
  85. Assert( pElement );
  86. if ( !pElement )
  87. return;
  88. Msg( "[%s : %s] in memory\n", pElement->GetName(), pElement->GetTypeString() );
  89. }
  90. }
  91. #endif
  92. }