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.

243 lines
4.9 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. //#include <strstrea.h>
  8. #include "vraddll.h"
  9. #include "bsplib.h"
  10. #include "vrad.h"
  11. #include "map_shared.h"
  12. #include "lightmap.h"
  13. #include "threads.h"
  14. static CUtlVector<unsigned char> g_LastGoodLightData;
  15. static CUtlVector<unsigned char> g_FacesTouched;
  16. static CVRadDLL g_VRadDLL;
  17. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVRadDLL, IVRadDLL, VRAD_INTERFACE_VERSION, g_VRadDLL );
  18. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CVRadDLL, ILaunchableDLL, LAUNCHABLE_DLL_INTERFACE_VERSION, g_VRadDLL );
  19. // ---------------------------------------------------------------------------- //
  20. // temporary static array data size tracking
  21. // original data size = 143 megs
  22. // - converting ddispindices, ddispverts, g_dispinfo, and dlightdata to CUtlVector
  23. // - 51 megs
  24. // ---------------------------------------------------------------------------- //
  25. class dat
  26. {
  27. public:
  28. char *name;
  29. int size;
  30. };
  31. #define DATENTRY(name) {#name, sizeof(name)}
  32. dat g_Dats[] =
  33. {
  34. DATENTRY(dmodels),
  35. DATENTRY(dvisdata),
  36. DATENTRY(dlightdataLDR),
  37. DATENTRY(dlightdataHDR),
  38. DATENTRY(dentdata),
  39. DATENTRY(dleafs),
  40. DATENTRY(dplanes),
  41. DATENTRY(dvertexes),
  42. DATENTRY(g_vertnormalindices),
  43. DATENTRY(g_vertnormals),
  44. DATENTRY(texinfo),
  45. DATENTRY(dtexdata),
  46. DATENTRY(g_dispinfo),
  47. DATENTRY(dorigfaces),
  48. DATENTRY(g_primitives),
  49. DATENTRY(g_primverts),
  50. DATENTRY(g_primindices),
  51. DATENTRY(dfaces),
  52. DATENTRY(dedges),
  53. DATENTRY(dleaffaces),
  54. DATENTRY(dleafbrushes),
  55. DATENTRY(dsurfedges),
  56. DATENTRY(dbrushes),
  57. DATENTRY(dbrushsides),
  58. DATENTRY(dareas),
  59. DATENTRY(dareaportals),
  60. DATENTRY(dworldlights),
  61. DATENTRY(dleafwaterdata),
  62. DATENTRY(g_ClipPortalVerts),
  63. DATENTRY(g_CubemapSamples),
  64. DATENTRY(g_TexDataStringData),
  65. DATENTRY(g_TexDataStringTable),
  66. DATENTRY(g_Overlays)
  67. };
  68. int CalcDatSize()
  69. {
  70. int ret = 0;
  71. int count = sizeof( g_Dats ) / sizeof( g_Dats[0] );
  72. int i;
  73. for( i=1; i < count; i++ )
  74. {
  75. if( g_Dats[i-1].size > g_Dats[i].size )
  76. {
  77. dat temp = g_Dats[i-1];
  78. g_Dats[i-1] = g_Dats[i];
  79. g_Dats[i] = temp;
  80. if( i > 1 )
  81. i -= 2;
  82. else
  83. i -= 1;
  84. }
  85. }
  86. for( i=0; i < count; i++ )
  87. ret += g_Dats[i].size;
  88. return ret;
  89. }
  90. int g_TotalDatSize = CalcDatSize();
  91. int CVRadDLL::main( int argc, char **argv )
  92. {
  93. return VRAD_Main( argc, argv );
  94. }
  95. bool CVRadDLL::Init( char const *pFilename )
  96. {
  97. VRAD_Init();
  98. // Set options and run vrad startup code.
  99. do_fast = true;
  100. g_bLowPriorityThreads = true;
  101. g_pIncremental = GetIncremental();
  102. VRAD_LoadBSP( pFilename );
  103. return true;
  104. }
  105. void CVRadDLL::Release()
  106. {
  107. }
  108. void CVRadDLL::GetBSPInfo( CBSPInfo *pInfo )
  109. {
  110. pInfo->dlightdata = pdlightdata->Base();
  111. pInfo->lightdatasize = pdlightdata->Count();
  112. pInfo->dfaces = dfaces;
  113. pInfo->m_pFacesTouched = g_FacesTouched.Base();
  114. pInfo->numfaces = numfaces;
  115. pInfo->dvertexes = dvertexes;
  116. pInfo->numvertexes = numvertexes;
  117. pInfo->dedges = dedges;
  118. pInfo->numedges = numedges;
  119. pInfo->dsurfedges = dsurfedges;
  120. pInfo->numsurfedges = numsurfedges;
  121. pInfo->texinfo = texinfo.Base();
  122. pInfo->numtexinfo = texinfo.Count();
  123. pInfo->g_dispinfo = g_dispinfo.Base();
  124. pInfo->g_numdispinfo = g_dispinfo.Count();
  125. pInfo->dtexdata = dtexdata;
  126. pInfo->numtexdata = numtexdata;
  127. pInfo->texDataStringData = g_TexDataStringData.Base();
  128. pInfo->nTexDataStringData = g_TexDataStringData.Count();
  129. pInfo->texDataStringTable = g_TexDataStringTable.Base();
  130. pInfo->nTexDataStringTable = g_TexDataStringTable.Count();
  131. }
  132. bool CVRadDLL::DoIncrementalLight( char const *pVMFFile )
  133. {
  134. char tempPath[MAX_PATH], tempFilename[MAX_PATH];
  135. GetTempPath( sizeof( tempPath ), tempPath );
  136. GetTempFileName( tempPath, "vmf_entities_", 0, tempFilename );
  137. FileHandle_t fp = g_pFileSystem->Open( tempFilename, "wb" );
  138. if( !fp )
  139. return false;
  140. g_pFileSystem->Write( pVMFFile, strlen(pVMFFile)+1, fp );
  141. g_pFileSystem->Close( fp );
  142. // Parse the new entities.
  143. if( !LoadEntsFromMapFile( tempFilename ) )
  144. return false;
  145. // Create lights.
  146. CreateDirectLights();
  147. // set up sky cameras
  148. ProcessSkyCameras();
  149. g_bInterrupt = false;
  150. if( RadWorld_Go() )
  151. {
  152. // Save off the last finished lighting results for the BSP.
  153. g_LastGoodLightData.CopyArray( pdlightdata->Base(), pdlightdata->Count() );
  154. if( g_pIncremental )
  155. g_pIncremental->GetFacesTouched( g_FacesTouched );
  156. return true;
  157. }
  158. else
  159. {
  160. g_iCurFace = 0;
  161. return false;
  162. }
  163. }
  164. bool CVRadDLL::Serialize()
  165. {
  166. if( !g_pIncremental )
  167. return false;
  168. if( g_LastGoodLightData.Count() > 0 )
  169. {
  170. pdlightdata->CopyArray( g_LastGoodLightData.Base(), g_LastGoodLightData.Count() );
  171. if( g_pIncremental->Serialize() )
  172. {
  173. // Delete this so it doesn't keep re-saving it.
  174. g_LastGoodLightData.Purge();
  175. return true;
  176. }
  177. }
  178. return false;
  179. }
  180. float CVRadDLL::GetPercentComplete()
  181. {
  182. return (float)g_iCurFace / numfaces;
  183. }
  184. void CVRadDLL::Interrupt()
  185. {
  186. g_bInterrupt = true;
  187. }