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.

323 lines
9.4 KiB

  1. //====== Copyright � 1996-2004, Valve Corporation, All rights reserved. =======
  2. //
  3. // Describes an asset: something that is compiled from sources,
  4. // in potentially multiple steps, to a compiled resource
  5. //
  6. //=============================================================================
  7. #include "movieobjects/dmedccmakefile.h"
  8. #include "datamodel/dmelementfactoryhelper.h"
  9. #include "tier2/fileutils.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. //-----------------------------------------------------------------------------
  13. // Hook into datamodel
  14. //-----------------------------------------------------------------------------
  15. IMPLEMENT_ELEMENT_FACTORY( DmeSourceDCCFile, CDmeSourceDCCFile );
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. void CDmeSourceDCCFile::OnConstruction()
  20. {
  21. m_RootDCCObjects.Init( this, "rootDCCObjects" );
  22. m_ExportType.InitAndSet( this, "exportType", 0 );
  23. m_FrameStart.InitAndSet( this, "frameStart", 0.0f );
  24. m_FrameEnd.InitAndSet( this, "frameEnd", 0.0f );
  25. m_FrameIncrement.InitAndSet( this, "frameIncrement", 1.0f );
  26. }
  27. void CDmeSourceDCCFile::OnDestruction()
  28. {
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Hook into datamodel
  32. //-----------------------------------------------------------------------------
  33. IMPLEMENT_ELEMENT_FACTORY( DmeSourceMayaFile, CDmeSourceMayaFile );
  34. IMPLEMENT_ELEMENT_FACTORY( DmeSourceMayaModelFile, CDmeSourceMayaModelFile );
  35. IMPLEMENT_ELEMENT_FACTORY( DmeSourceMayaAnimationFile, CDmeSourceMayaAnimationFile );
  36. //-----------------------------------------------------------------------------
  37. // Purpose:
  38. //-----------------------------------------------------------------------------
  39. void CDmeSourceMayaFile::OnConstruction()
  40. {
  41. }
  42. void CDmeSourceMayaFile::OnDestruction()
  43. {
  44. }
  45. void CDmeSourceMayaModelFile::OnConstruction()
  46. {
  47. m_ExportType = 0;
  48. }
  49. void CDmeSourceMayaModelFile::OnDestruction()
  50. {
  51. }
  52. void CDmeSourceMayaAnimationFile::OnConstruction()
  53. {
  54. m_ExportType = 1;
  55. }
  56. void CDmeSourceMayaAnimationFile::OnDestruction()
  57. {
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Hook into datamodel
  61. //-----------------------------------------------------------------------------
  62. IMPLEMENT_ELEMENT_FACTORY( DmeSourceXSIFile, CDmeSourceXSIFile );
  63. //-----------------------------------------------------------------------------
  64. // Purpose:
  65. //-----------------------------------------------------------------------------
  66. void CDmeSourceXSIFile::OnConstruction()
  67. {
  68. }
  69. void CDmeSourceXSIFile::OnDestruction()
  70. {
  71. }
  72. //-----------------------------------------------------------------------------
  73. // Hook into datamodel
  74. //-----------------------------------------------------------------------------
  75. IMPLEMENT_ELEMENT_FACTORY( DmeDCCMakefile, CDmeDCCMakefile );
  76. //-----------------------------------------------------------------------------
  77. // Purpose:
  78. //-----------------------------------------------------------------------------
  79. void CDmeDCCMakefile::OnConstruction()
  80. {
  81. m_bFlushFile = false;
  82. }
  83. void CDmeDCCMakefile::OnDestruction()
  84. {
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Compile assets
  88. //-----------------------------------------------------------------------------
  89. void CDmeDCCMakefile::GetOutputs( CUtlVector<CUtlString> &fullPaths )
  90. {
  91. fullPaths.RemoveAll();
  92. char pOutputName[MAX_PATH];
  93. Q_FileBase( GetFileName(), pOutputName, sizeof(pOutputName) );
  94. if ( !pOutputName[0] )
  95. return;
  96. // FIXME: We need to come up with an appropriate directory structure for export
  97. char pOutputDir[MAX_PATH];
  98. GetMakefilePath( pOutputDir, sizeof(pOutputDir) );
  99. if ( !pOutputDir[0] )
  100. return;
  101. Q_StripTrailingSlash( pOutputDir );
  102. char pFullPath[MAX_PATH];
  103. Q_snprintf( pFullPath, sizeof(pFullPath), "%s\\%s.dmx", pOutputDir, pOutputName );
  104. fullPaths.AddToTail( pFullPath );
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Creates, destroys the output element associated with this makefile
  108. //-----------------------------------------------------------------------------
  109. CDmElement *CDmeDCCMakefile::CreateOutputElement( )
  110. {
  111. if ( m_bFlushFile )
  112. {
  113. m_bFlushFile = false;
  114. if ( GetFileId() != DMFILEID_INVALID )
  115. {
  116. // NOTE: CDmeHandles will correctly re-hook up to the new makefile after load
  117. // If the file fails to load, we have the copy. If the file correctly has the make in it
  118. // it will replace this copy I made
  119. CDmeHandle< CDmeDCCMakefile > hMakefileOld;
  120. hMakefileOld = this;
  121. // NOTE NOTE NOTE
  122. // UnloadFile essentially calls delete this!
  123. // So don't refer to any state in this DmElement after that
  124. DmFileId_t fileId = GetFileId();
  125. g_pDataModel->UnloadFile( fileId );
  126. CDmElement *pRoot = NULL;
  127. if ( g_pDataModel->RestoreFromFile( g_pDataModel->GetFileName( fileId ), NULL, NULL, &pRoot, CR_DELETE_OLD ) != DMFILEID_INVALID )
  128. {
  129. // NOTE: Unload/restore kills the this pointer, we need to redo this
  130. if ( hMakefileOld.Get() )
  131. {
  132. hMakefileOld->SetDirty( false );
  133. return hMakefileOld->CreateOutputElement();
  134. }
  135. }
  136. // NOTE: We expect file backup prior to compile to avoid really fatal errors
  137. // This case happens if the file failed to load. In this case, we must use
  138. // the copy of the makefile
  139. Assert( 0 );
  140. return NULL;
  141. }
  142. }
  143. // The output element is the root element containing the makefile
  144. return FindReferringElement< CDmElement >( this, "makefile" );
  145. }
  146. void CDmeDCCMakefile::DestroyOutputElement( CDmElement *pOutput )
  147. {
  148. m_bFlushFile = true;
  149. }
  150. //-----------------------------------------------------------------------------
  151. // Hook into datamodel
  152. //-----------------------------------------------------------------------------
  153. IMPLEMENT_ELEMENT_FACTORY( DmeMayaMakefile, CDmeMayaMakefile );
  154. IMPLEMENT_ELEMENT_FACTORY( DmeMayaModelMakefile, CDmeMayaModelMakefile );
  155. IMPLEMENT_ELEMENT_FACTORY( DmeMayaAnimationMakefile, CDmeMayaAnimationMakefile );
  156. //-----------------------------------------------------------------------------
  157. // Purpose:
  158. //-----------------------------------------------------------------------------
  159. void CDmeMayaMakefile::OnConstruction()
  160. {
  161. }
  162. void CDmeMayaMakefile::OnDestruction()
  163. {
  164. }
  165. void CDmeMayaModelMakefile::OnConstruction()
  166. {
  167. }
  168. void CDmeMayaModelMakefile::OnDestruction()
  169. {
  170. }
  171. void CDmeMayaAnimationMakefile::OnConstruction()
  172. {
  173. }
  174. void CDmeMayaAnimationMakefile::OnDestruction()
  175. {
  176. }
  177. //-----------------------------------------------------------------------------
  178. // Returns source types
  179. //-----------------------------------------------------------------------------
  180. static DmeMakefileType_t s_pMayaModelSourceTypes[] =
  181. {
  182. { "DmeSourceMayaModelFile", "Maya Model File", true, "makefiledir:../maya", "*.ma;*.mb", "Maya File (*.ma,*.mb)" },
  183. { NULL, NULL, false, NULL, NULL, NULL },
  184. };
  185. DmeMakefileType_t* CDmeMayaModelMakefile::GetSourceTypes()
  186. {
  187. return s_pMayaModelSourceTypes;
  188. }
  189. static DmeMakefileType_t s_pMayaAnimationSourceTypes[] =
  190. {
  191. { "DmeSourceMayaAnimationFile", "Maya Animation File", true, "makefiledir:../maya", "*.ma;*.mb", "Maya File (*.ma,*.mb)" },
  192. { NULL, NULL, false, NULL, NULL, NULL },
  193. };
  194. DmeMakefileType_t* CDmeMayaAnimationMakefile::GetSourceTypes()
  195. {
  196. return s_pMayaAnimationSourceTypes;
  197. }
  198. //-----------------------------------------------------------------------------
  199. // Makefile type
  200. //-----------------------------------------------------------------------------
  201. static DmeMakefileType_t s_MayaModelMakefileType =
  202. {
  203. "DmeMayaModelMakefile", "Maya Model Component", true, "contentdir:models", "*.dmx", "DMX File (*.dmx)"
  204. };
  205. DmeMakefileType_t *CDmeMayaModelMakefile::GetMakefileType()
  206. {
  207. return &s_MayaModelMakefileType;
  208. }
  209. static DmeMakefileType_t s_MayaAnimationMakefileType =
  210. {
  211. "DmeMayaAnimationMakefile", "Maya Animation Component", true, "contentdir:models", "*.dmx", "DMX File (*.dmx)"
  212. };
  213. DmeMakefileType_t *CDmeMayaAnimationMakefile::GetMakefileType()
  214. {
  215. return &s_MayaAnimationMakefileType;
  216. }
  217. //-----------------------------------------------------------------------------
  218. // Hook into datamodel
  219. //-----------------------------------------------------------------------------
  220. IMPLEMENT_ELEMENT_FACTORY( DmeXSIMakefile, CDmeXSIMakefile );
  221. //-----------------------------------------------------------------------------
  222. // Purpose:
  223. //-----------------------------------------------------------------------------
  224. void CDmeXSIMakefile::OnConstruction()
  225. {
  226. }
  227. void CDmeXSIMakefile::OnDestruction()
  228. {
  229. }
  230. //-----------------------------------------------------------------------------
  231. // Returns source types
  232. //-----------------------------------------------------------------------------
  233. static DmeMakefileType_t s_pXSISourceTypes[] =
  234. {
  235. { "DmeSourceXSIFile", "XSI File", true, "makefiledir:../xsi", "*.xsi", "XSI File (*.xsi)" },
  236. { NULL, NULL, false, NULL, NULL, NULL },
  237. };
  238. DmeMakefileType_t* CDmeXSIMakefile::GetSourceTypes()
  239. {
  240. return s_pXSISourceTypes;
  241. }
  242. //-----------------------------------------------------------------------------
  243. // Makefile type
  244. //-----------------------------------------------------------------------------
  245. static DmeMakefileType_t s_XSIMakefileType =
  246. {
  247. "DmeXSIMakefile", "XSI Model Component", true, "contentdir:models", "*.dmx", "DMX File (*.dmx)",
  248. };
  249. DmeMakefileType_t *CDmeXSIMakefile::GetMakefileType()
  250. {
  251. return &s_XSIMakefileType;
  252. }