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.

177 lines
4.9 KiB

  1. //====== Copyright � 1996-2004, 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. CDmElement * GetSettings() const;
  73. template< class T > const T& GetSettings( const char *pSettingName ) const;
  74. CDmAttribute * GetSettingsAttribute( const char *pSettingName, DmAttributeType_t type );
  75. template< class E > E* GetSettingsElement( const char *pSettingName ) const;
  76. template< class T > void SetSettings( const char *pSettingName, const T& value );
  77. // Creates a game model
  78. CDmeGameModel *CreateEditorGameModel( studiohdr_t *hdr, const Vector &vecOrigin, Quaternion &qOrientation );
  79. // Creates a camera
  80. CDmeCamera *CreateCamera( const DmeCameraParams_t& params );
  81. private:
  82. void CreateRenderSettings( CDmElement *pSettings );
  83. void CreateProgressiveRefinementSettings( CDmElement *pRenderSettings );
  84. void CreatePosterSettings( CDmElement *pRenderSettings );
  85. void CreateMovieSettings( CDmElement *pRenderSettings );
  86. void CreateSharedPresetGroupSettings( CDmElement *pRenderSettings );
  87. CDmeHandle< CDmElement > m_hRoot;
  88. // CDmeHandle< CDmeFilmClip > m_hCurrentMovie;
  89. // CUtlVector< CDmeHandle< CDmeClip > > m_hClipStack;
  90. // CUtlVector< CDmeHandle< CDmeClip > > m_hSelectedClip[ NUM_SELECTION_TYPES ];
  91. };
  92. //-----------------------------------------------------------------------------
  93. // Inline methods
  94. //-----------------------------------------------------------------------------
  95. inline CDmElement *CSFMSession::Root()
  96. {
  97. return m_hRoot;
  98. }
  99. inline const CDmElement *CSFMSession::Root() const
  100. {
  101. return m_hRoot;
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Method to get at various settings
  105. //-----------------------------------------------------------------------------
  106. inline CDmElement *CSFMSession::GetSettings() const
  107. {
  108. return m_hRoot.Get() ? m_hRoot->GetValueElement< CDmElement >( "settings" ) : NULL;
  109. }
  110. template< class T >
  111. inline const T& CSFMSession::GetSettings( const char *pSettingName ) const
  112. {
  113. CDmElement *pSettings = GetSettings();
  114. if ( pSettings )
  115. return pSettings->GetValue< T >( pSettingName );
  116. static T defaultVal;
  117. CDmAttributeInfo<T>::SetDefaultValue( defaultVal );
  118. return defaultVal;
  119. }
  120. inline CDmAttribute *CSFMSession::GetSettingsAttribute( const char *pSettingName, DmAttributeType_t type )
  121. {
  122. CDmElement *pSettings = GetSettings();
  123. if ( pSettings )
  124. return pSettings->GetAttribute( pSettingName, type );
  125. return NULL;
  126. }
  127. template< class T >
  128. inline void CSFMSession::SetSettings( const char *pSettingName, const T& value )
  129. {
  130. CDmElement *pSettings = GetSettings();
  131. if ( pSettings )
  132. {
  133. pSettings->SetValue( pSettingName, value );
  134. }
  135. }
  136. template< class E >
  137. inline E* CSFMSession::GetSettingsElement( const char *pSettingName ) const
  138. {
  139. CDmElement *pSettings = GetSettings();
  140. return pSettings ? pSettings->GetValueElement< E >( pSettingName ) : NULL;
  141. }
  142. #endif // SFMSESSION_H