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.

163 lines
6.0 KiB

  1. //========= Copyright Valve Corporation, 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. // Converts from any one DMX file format to another
  12. //
  13. //=============================================================================
  14. #include "dmserializers.h"
  15. #include "dmserializers/idmserializers.h"
  16. #include "appframework/iappsystem.h"
  17. #include "filesystem.h"
  18. #include "datamodel/idatamodel.h"
  19. #include "datamodel/dmelementfactoryhelper.h"
  20. #include "tier2/tier2.h"
  21. //-----------------------------------------------------------------------------
  22. // format updater macros
  23. //-----------------------------------------------------------------------------
  24. #define DECLARE_FORMAT_UPDATER( _name, _description, _extension, _version, _encoding ) \
  25. class CDmFormatUpdater_ ## _name : public IDmFormatUpdater \
  26. { \
  27. public: \
  28. CDmFormatUpdater_ ## _name() {} \
  29. virtual const char *GetName() const { return #_name; } \
  30. virtual const char *GetDescription() const { return _description; } \
  31. virtual const char *GetExtension() const { return _extension; } \
  32. virtual const char *GetDefaultEncoding() const { return _encoding; } \
  33. virtual int GetCurrentVersion() const { return _version; } \
  34. virtual bool Update( CDmElement **pRoot, int nSourceVersion ) { return true; } \
  35. }; \
  36. static CDmFormatUpdater_ ## _name s_FormatUpdater ## _name; \
  37. void InstallFormatUpdater_ ## _name( IDataModel *pFactory ) \
  38. { \
  39. pFactory->AddFormatUpdater( &s_FormatUpdater ## _name ); \
  40. }
  41. #define INSTALL_FORMAT_UPDATER( _name ) InstallFormatUpdater_ ## _name( g_pDataModel )
  42. //-----------------------------------------------------------------------------
  43. // format updaters
  44. //-----------------------------------------------------------------------------
  45. DECLARE_FORMAT_UPDATER( dmx, "Generic DMX", "dmx", 1, "binary" )
  46. DECLARE_FORMAT_UPDATER( movieobjects, "Generic MovieObjects", "dmx", 1, "binary" )
  47. DECLARE_FORMAT_UPDATER( sfm, "Generic SFM", "dmx", 1, "binary" )
  48. DECLARE_FORMAT_UPDATER( sfm_session, "SFM Session", "dmx", 1, "binary" )
  49. DECLARE_FORMAT_UPDATER( sfm_trackgroup, "SFM TrackGroup", "dmx", 1, "binary" )
  50. DECLARE_FORMAT_UPDATER( pcf, "Particle Configuration File", "dmx", 1, "binary" )
  51. DECLARE_FORMAT_UPDATER( preset, "Preset File", "dmx", 1, "keyvalues2" )
  52. DECLARE_FORMAT_UPDATER( facial_animation, "Facial Animation File", "dmx", 1, "binary" )
  53. DECLARE_FORMAT_UPDATER( model, "DMX Model", "dmx", 1, "binary" )
  54. //DECLARE_FORMAT_UPDATER( animation, "DMX Animation", "dmx", 1, "binary" )
  55. //DECLARE_FORMAT_UPDATER( dcc_makefile, "DMX Makefile", "dmx", 1, "keyvalues2" )
  56. //-----------------------------------------------------------------------------
  57. // The application object
  58. //-----------------------------------------------------------------------------
  59. class CDmSerializers : public CBaseAppSystem< IDmSerializers >
  60. {
  61. typedef CBaseAppSystem< IDmSerializers > BaseClass;
  62. public:
  63. // Inherited from IAppSystem
  64. virtual bool Connect( CreateInterfaceFn factory );
  65. virtual void *QueryInterface( const char *pInterfaceName );
  66. virtual InitReturnVal_t Init();
  67. };
  68. //-----------------------------------------------------------------------------
  69. // Singleton interface
  70. //-----------------------------------------------------------------------------
  71. static CDmSerializers g_DmSerializers;
  72. IDmSerializers *g_pDmSerializers = &g_DmSerializers;
  73. //-----------------------------------------------------------------------------
  74. // Here's where the app systems get to learn about each other
  75. //-----------------------------------------------------------------------------
  76. bool CDmSerializers::Connect( CreateInterfaceFn factory )
  77. {
  78. if ( !BaseClass::Connect( factory ) )
  79. return false;
  80. if ( !factory( FILESYSTEM_INTERFACE_VERSION, NULL ) )
  81. {
  82. Warning( "DmSerializers needs the file system to function" );
  83. return false;
  84. }
  85. // Here's the main point where all DM element classes get installed
  86. // Necessary to do it here so all type symbols for all DME classes are set
  87. // up prior to install
  88. InstallDmElementFactories( );
  89. return true;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Here's where systems can access other interfaces implemented by this object
  93. //-----------------------------------------------------------------------------
  94. void *CDmSerializers::QueryInterface( const char *pInterfaceName )
  95. {
  96. if ( !V_strcmp( pInterfaceName, DMSERIALIZERS_INTERFACE_VERSION ) )
  97. return (IDmSerializers*)this;
  98. return NULL;
  99. }
  100. //-----------------------------------------------------------------------------
  101. // Init, shutdown
  102. //-----------------------------------------------------------------------------
  103. InitReturnVal_t CDmSerializers::Init()
  104. {
  105. InitReturnVal_t nRetVal = BaseClass::Init();
  106. if ( nRetVal != INIT_OK )
  107. return nRetVal;
  108. // Install non-dmx importers
  109. InstallActBusyImporter( g_pDataModel );
  110. InstallVMTImporter( g_pDataModel );
  111. InstallVMFImporter( g_pDataModel );
  112. // Install legacy dmx importers
  113. InstallSFMV1Importer( g_pDataModel );
  114. InstallSFMV2Importer( g_pDataModel );
  115. InstallSFMV3Importer( g_pDataModel );
  116. InstallSFMV4Importer( g_pDataModel );
  117. InstallSFMV5Importer( g_pDataModel );
  118. InstallSFMV6Importer( g_pDataModel );
  119. InstallSFMV7Importer( g_pDataModel );
  120. InstallSFMV8Importer( g_pDataModel );
  121. InstallSFMV9Importer( g_pDataModel );
  122. // install dmx format updaters
  123. INSTALL_FORMAT_UPDATER( dmx );
  124. INSTALL_FORMAT_UPDATER( movieobjects );
  125. INSTALL_FORMAT_UPDATER( sfm );
  126. INSTALL_FORMAT_UPDATER( sfm_session );
  127. INSTALL_FORMAT_UPDATER( sfm_trackgroup );
  128. INSTALL_FORMAT_UPDATER( pcf );
  129. INSTALL_FORMAT_UPDATER( preset );
  130. INSTALL_FORMAT_UPDATER( facial_animation );
  131. INSTALL_FORMAT_UPDATER( model );
  132. // INSTALL_FORMAT_UPDATER( animation );
  133. // INSTALL_FORMAT_UPDATER( dcc_makefile );
  134. return INIT_OK;
  135. }