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.

175 lines
3.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef INCREMENTAL_H
  8. #define INCREMENTAL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "iincremental.h"
  13. #include "utllinkedlist.h"
  14. #include "utlvector.h"
  15. #include "utlbuffer.h"
  16. #include "vrad.h"
  17. #define INCREMENTALFILE_VERSION 31241
  18. class CIncLight;
  19. class CLightValue
  20. {
  21. public:
  22. float m_Dot;
  23. };
  24. class CLightFace
  25. {
  26. public:
  27. unsigned short m_FaceIndex; // global face index
  28. unsigned short m_LightFacesIndex; // index into CIncLight::m_LightFaces.
  29. // The lightmap grid for this face. Only used while building lighting data for a face.
  30. // Compressed into m_CompressedData immediately afterwards.
  31. CUtlVector<CLightValue> m_LightValues;
  32. CUtlBuffer m_CompressedData;
  33. CIncLight *m_pLight;
  34. };
  35. class CIncLight
  36. {
  37. public:
  38. CIncLight();
  39. ~CIncLight();
  40. CLightFace* FindOrCreateLightFace( int iFace, int lmSize, bool *bNew=NULL );
  41. public:
  42. CRITICAL_SECTION m_CS;
  43. // This is the light for which m_LightFaces was built.
  44. dworldlight_t m_Light;
  45. CLightFace *m_pCachedFaces[MAX_TOOL_THREADS+1];
  46. // The list of faces that this light contributes to.
  47. CUtlLinkedList<CLightFace*, unsigned short> m_LightFaces;
  48. // Largest value in intensity of light. Used to scale dot products up into a
  49. // range where their values make sense.
  50. float m_flMaxIntensity;
  51. };
  52. class CIncrementalHeader
  53. {
  54. public:
  55. class CLMSize
  56. {
  57. public:
  58. unsigned char m_Width;
  59. unsigned char m_Height;
  60. };
  61. CUtlVector<CLMSize> m_FaceLightmapSizes;
  62. };
  63. class CIncremental : public IIncremental
  64. {
  65. public:
  66. CIncremental();
  67. ~CIncremental();
  68. // IIncremental overrides.
  69. public:
  70. virtual bool Init( char const *pBSPFilename, char const *pIncrementalFilename );
  71. // Load the light definitions out of the incremental file.
  72. // Figure out which lights have changed.
  73. // Change 'activelights' to only consist of new or changed lights.
  74. virtual bool PrepareForLighting();
  75. virtual void AddLightToFace(
  76. IncrementalLightID lightID,
  77. int iFace,
  78. int iSample,
  79. int lmSize,
  80. float dot,
  81. int iThread );
  82. virtual void FinishFace(
  83. IncrementalLightID lightID,
  84. int iFace,
  85. int iThread );
  86. // For each face that was changed during the lighting process, save out
  87. // new data for it in the incremental file.
  88. virtual bool Finalize();
  89. virtual void GetFacesTouched( CUtlVector<unsigned char> &touched );
  90. virtual bool Serialize();
  91. private:
  92. // Read/write the header from the file.
  93. bool ReadIncrementalHeader( long fp, CIncrementalHeader *pHeader );
  94. bool WriteIncrementalHeader( long fp );
  95. // Returns true if the incremental file is valid and we can use InitUpdate.
  96. bool IsIncrementalFileValid();
  97. void Term();
  98. // For each light in 'activelights', add a light to m_Lights and link them together.
  99. void AddLightsForActiveLights();
  100. // Load and save the state.
  101. bool LoadIncrementalFile();
  102. bool SaveIncrementalFile();
  103. typedef CUtlVector<CLightFace*> CFaceLightList;
  104. void LinkLightsToFaces( CUtlVector<CFaceLightList> &faceLights );
  105. private:
  106. char const *m_pIncrementalFilename;
  107. char const *m_pBSPFilename;
  108. CUtlLinkedList<CIncLight*, IncrementalLightID>
  109. m_Lights;
  110. // The face index is set to 1 if a face has new lighting data applied to it.
  111. // This is used to optimize the set of lightmaps we recomposite.
  112. CUtlVector<unsigned char> m_FacesTouched;
  113. int m_TotalMemory;
  114. // Set to true when one or more runs were completed successfully.
  115. bool m_bSuccessfulRun;
  116. };
  117. #endif // INCREMENTAL_H