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.

170 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class representing session state for the SFM
  4. //
  5. //=============================================================================
  6. #ifndef SFMSESSION_H
  7. #define SFMSESSION_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmehandle.h"
  12. #include "datamodel/dmelement.h"
  13. #include "tier1/utlvector.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. class CDmElement;
  18. class CDmeFilmClip;
  19. class CDmeClip;
  20. struct studiohdr_t;
  21. class Vector;
  22. class Quaternion;
  23. class CDmeGameModel;
  24. class CDmeCamera;
  25. class CDmeDag;
  26. class CDmeAnimationSet;
  27. //-----------------------------------------------------------------------------
  28. // Camera creation paramaters
  29. //-----------------------------------------------------------------------------
  30. struct DmeCameraParams_t
  31. {
  32. DmeCameraParams_t() : fov( 90.0f )
  33. {
  34. name[ 0 ] = 0;
  35. origin.Init();
  36. angles.Init();
  37. }
  38. DmeCameraParams_t( const char *pszName ) : fov( 90.0f )
  39. {
  40. Q_strncpy( name, pszName ? pszName : "", sizeof( name ) );
  41. origin.Init();
  42. angles.Init();
  43. }
  44. DmeCameraParams_t( const char *pszName, const Vector &org, const QAngle &ang ) :
  45. fov( 90.0f ), origin( org ), angles( ang )
  46. {
  47. Q_strncpy( name, pszName ? pszName : "", sizeof( name ) );
  48. }
  49. char name[ 128 ];
  50. Vector origin;
  51. QAngle angles;
  52. float fov;
  53. };
  54. //-----------------------------------------------------------------------------
  55. // A class representing the SFM Session
  56. // FIXME: Should this be a dmelement? Maybe!
  57. //-----------------------------------------------------------------------------
  58. class CSFMSession
  59. {
  60. public:
  61. CSFMSession();
  62. // Creates a new (empty) session
  63. void Init();
  64. void Shutdown();
  65. // Creates session settings
  66. void CreateSessionSettings();
  67. // Gets/sets the root
  68. CDmElement *Root();
  69. const CDmElement *Root() const;
  70. void SetRoot( CDmElement *pRoot );
  71. // Methods to get at session settings
  72. template< class T > const T& GetSettings( const char *pSettingName ) const;
  73. CDmAttribute * GetSettingsAttribute( const char *pSettingName, DmAttributeType_t type );
  74. template< class E > E* GetSettingsElement( const char *pSettingName ) const;
  75. template< class T > void SetSettings( const char *pSettingName, const T& value );
  76. // Creates a game model
  77. CDmeGameModel *CreateEditorGameModel( studiohdr_t *hdr, const Vector &vecOrigin, Quaternion &qOrientation );
  78. // Creates a camera
  79. CDmeCamera *CreateCamera( const DmeCameraParams_t& params );
  80. // Finds or creates a scene
  81. CDmeDag *FindOrCreateScene( CDmeFilmClip *pShot, const char *pSceneName );
  82. private:
  83. void CreateRenderSettings( CDmElement *pSettings, float flLegacyFramerate );
  84. void CreateProgressiveRefinementSettings( CDmElement *pRenderSettings );
  85. CDmeHandle< CDmElement > m_hRoot;
  86. // CDmeHandle< CDmeFilmClip > m_hCurrentMovie;
  87. // CUtlVector< CDmeHandle< CDmeClip > > m_hClipStack;
  88. // CUtlVector< CDmeHandle< CDmeClip > > m_hSelectedClip[ NUM_SELECTION_TYPES ];
  89. };
  90. //-----------------------------------------------------------------------------
  91. // Inline methods
  92. //-----------------------------------------------------------------------------
  93. inline CDmElement *CSFMSession::Root()
  94. {
  95. return m_hRoot;
  96. }
  97. inline const CDmElement *CSFMSession::Root() const
  98. {
  99. return m_hRoot;
  100. }
  101. //-----------------------------------------------------------------------------
  102. // Method to get at various settings
  103. //-----------------------------------------------------------------------------
  104. template< class T >
  105. inline const T& CSFMSession::GetSettings( const char *pSettingName ) const
  106. {
  107. CDmElement *pSettings = m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL;
  108. if ( pSettings )
  109. return pSettings->GetValue< T >( pSettingName );
  110. static T defaultVal;
  111. CDmAttributeInfo<T>::SetDefaultValue( defaultVal );
  112. return defaultVal;
  113. }
  114. inline CDmAttribute *CSFMSession::GetSettingsAttribute( const char *pSettingName, DmAttributeType_t type )
  115. {
  116. CDmElement *pSettings = m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL;
  117. if ( pSettings )
  118. return pSettings->GetAttribute( pSettingName, type );
  119. return NULL;
  120. }
  121. template< class T >
  122. inline void CSFMSession::SetSettings( const char *pSettingName, const T& value )
  123. {
  124. CDmElement *pSettings = m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL;
  125. if ( pSettings )
  126. {
  127. pSettings->SetValue( pSettingName, value );
  128. }
  129. }
  130. template< class E >
  131. inline E* CSFMSession::GetSettingsElement( const char *pSettingName ) const
  132. {
  133. CDmElement *pSettings = m_hRoot->GetValueElement< CDmElement >( "settings" );
  134. return pSettings ? pSettings->GetValueElement< E >( pSettingName ) : NULL;
  135. }
  136. #endif // SFMSESSION_H