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.

136 lines
3.5 KiB

  1. //===== Copyright � 1996-2006, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: sheet definitions for particles and other sprite functions
  4. //
  5. //===========================================================================//
  6. #ifndef PSHEET_H
  7. #define PSHEET_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlobjectreference.h"
  12. #include "materialsystem/MaterialSystemUtil.h"
  13. #include "tier1/utlvector.h"
  14. class CUtlBuffer;
  15. // classes for keeping a dictionary of sheet files in memory. A sheet is a bunch of frames packewd
  16. // within one texture. Each sheet has 1 or more frame sequences stored for it.
  17. // for fast lookups to retrieve sequence data, we store the sequence information discretized into
  18. // a fixed # of frames. If this discretenesss is a visual problem, you can lerp the blend values to get it
  19. // perfect.
  20. #define SEQUENCE_SAMPLE_COUNT 512
  21. #define MAX_IMAGES_PER_FRAME_ON_DISK 4
  22. #define MAX_IMAGES_PER_FRAME_IN_MEMORY 2
  23. struct SequenceSampleTextureCoords_t
  24. {
  25. float m_fLeft_U0;
  26. float m_fTop_V0;
  27. float m_fRight_U0;
  28. float m_fBottom_V0;
  29. float m_fLeft_U1;
  30. float m_fTop_V1;
  31. float m_fRight_U1;
  32. float m_fBottom_V1;
  33. };
  34. struct SheetSequenceSample_t
  35. {
  36. // coordinates of two rectangles (old and next frame coords)
  37. SequenceSampleTextureCoords_t m_TextureCoordData[MAX_IMAGES_PER_FRAME_IN_MEMORY];
  38. float m_fBlendFactor;
  39. void CopyFirstFrameToOthers(void)
  40. {
  41. // for old format files only supporting one image per frame
  42. for(int i=1; i < MAX_IMAGES_PER_FRAME_IN_MEMORY; i++)
  43. {
  44. m_TextureCoordData[i] = m_TextureCoordData[0];
  45. }
  46. }
  47. };
  48. enum SheetSequenceFlags_t
  49. {
  50. SEQ_FLAG_CLAMP = 0x1, // as opposed to loop
  51. SEQ_FLAG_NO_ALPHA = 0x2, // packed as sequence-rgb (alpha channel should be ignored)
  52. SEQ_FLAG_NO_COLOR = 0x4, // packed as sequence-a (color channels should be ignored)
  53. };
  54. class CSheet
  55. {
  56. public:
  57. // read form a .sht file. This is the usual thing to do
  58. CSheet( CUtlBuffer &buf );
  59. CSheet( void );
  60. ~CSheet( void );
  61. const SheetSequenceSample_t *GetSampleForSequence( float flAge, float flAgeScale, int nSequence, bool bForceLoop );
  62. // references for smart ptrs
  63. CUtlReferenceList<CSheet> m_References;
  64. struct SheetInfo_t
  65. {
  66. SheetSequenceSample_t *m_pSamples;
  67. uint8 m_SeqFlags;
  68. bool m_bSequenceIsCopyOfAnotherSequence;
  69. int16 m_nNumFrames;
  70. float m_flFrameSpan;
  71. };
  72. CUtlVector< SheetInfo_t > m_SheetInfo;
  73. };
  74. //////////////////////////////////////////////////////////////////////////
  75. class IMesh;
  76. class IMaterial;
  77. // A heavier-weight version of CSheet with more bells and whistles
  78. class CSheetExtended
  79. {
  80. public:
  81. explicit CSheetExtended( IMaterial* pMaterial );
  82. ~CSheetExtended();
  83. int GetSheetSequenceCount();
  84. int GetNthSequenceIndex( int nSequenceNumber );
  85. const SheetSequenceSample_t *GetSampleForSequence( float flAge, float flAgeScale, int nSequence, bool bForceLoop );
  86. float GetSequenceTimeSpan( int nSequenceIndex );
  87. void DrawSheet( IMesh *pMesh, const Vector &vCenter, float flRadius, int nSheetSequence, float flAge, float flSheetPreviewSpeed, bool bLoopSheetPreview, int nSecondarySequence=-1, bool bOverrideSpriteCard=false );
  88. bool ValidSheetData();
  89. bool SequenceHasAlphaData( int nSequenceIndex );
  90. bool SequenceHasColorData( int nSequenceIndex );
  91. // Helper
  92. static bool IsMaterialSeparateAlphaColorMaterial( IMaterial* pMat );
  93. static bool IsMaterialDualSequence( IMaterial* pMat );
  94. private:
  95. void LoadFromBuffer( CUtlBuffer& buf );
  96. void LoadFromMaterial( IMaterial* pMaterial );
  97. // TEMP: Store in a CSheet for now - eventually we'll want more data
  98. CSheet* m_pSheetData;
  99. CMaterialReference m_Material;
  100. };
  101. #endif // PSHEET_H