GLSettings.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #include "stdh.h"
  13. // list of settings data
  14. static CListHead _lhSettings;
  15. extern INDEX sam_iVideoSetup; // 0==speed, 1==normal, 2==quality, 3==custom
  16. class CSettingsEntry {
  17. public:
  18. CListNode se_lnNode;
  19. CTString se_strRenderer;
  20. CTString se_strDescription;
  21. CTFileName se_fnmScript;
  22. // check if this entry matches given info
  23. BOOL Matches( const CTString &strRenderer) const;
  24. };
  25. // last valid settings info
  26. static CTString _strLastRenderer;
  27. extern CTString _strPreferencesDescription = "";
  28. extern INDEX _iLastPreferences = 1;
  29. // check if this entry matches given info
  30. BOOL CSettingsEntry::Matches( const CTString &strRenderer) const
  31. {
  32. return strRenderer.Matches(se_strRenderer);
  33. }
  34. const char *RenderingPreferencesDescription(int iMode)
  35. {
  36. if (iMode==0) {
  37. return TRANS("speed");
  38. } else if (iMode==1) {
  39. return TRANS("normal");
  40. } else if (iMode==2) {
  41. return TRANS("quality");
  42. } else if (iMode==3) {
  43. return TRANS("custom");
  44. } else {
  45. ASSERT(FALSE);
  46. return TRANS("normal");
  47. }
  48. }
  49. void InitGLSettings(void)
  50. {
  51. ASSERT(_lhSettings.IsEmpty());
  52. char achrLine [1024];
  53. char achrRenderer[1024];
  54. char achrDesc [1024];
  55. char achrScript [1024];
  56. CTFileStream strmFile;
  57. try
  58. {
  59. strmFile.Open_t( CTString("Scripts\\GLSettings\\GLSettings.lst"), CTStream::OM_READ);
  60. INDEX iIndex = 0;
  61. do
  62. {
  63. achrLine [0] = 0;
  64. achrRenderer[0] = 0;
  65. achrDesc [0] = 0;
  66. achrScript [0] = 0;
  67. strmFile.GetLine_t( achrLine, 1024);
  68. sscanf( achrLine,
  69. "\"%1024[^\"]\"%*[^\"]\"%1024[^\"]\"%*[^\"]\"%1024[^\"]\"", achrRenderer, achrDesc, achrScript);
  70. if( achrRenderer[0]==0) continue;
  71. CSettingsEntry &se = *new CSettingsEntry;
  72. se.se_strRenderer = achrRenderer;
  73. se.se_strDescription = achrDesc;
  74. se.se_fnmScript = CTString(achrScript);
  75. _lhSettings.AddTail( se.se_lnNode);
  76. }
  77. while( !strmFile.AtEOF());
  78. }
  79. // ignore errors
  80. catch (char *strError) {
  81. WarningMessage(TRANS("unable to setup OpenGL settings list: %s"), strError);
  82. }
  83. _strLastRenderer= "none";
  84. _iLastPreferences = 1;
  85. _pShell->DeclareSymbol("persistent CTString sam_strLastRenderer;", &_strLastRenderer);
  86. _pShell->DeclareSymbol("persistent INDEX sam_iLastSetup;", &_iLastPreferences);
  87. }
  88. CSettingsEntry *GetGLSettings( const CTString &strRenderer)
  89. {
  90. // for each setting
  91. FOREACHINLIST(CSettingsEntry, se_lnNode, _lhSettings, itse)
  92. { // return the one that matches
  93. CSettingsEntry &se = *itse;
  94. if( se.Matches(strRenderer)) return &se;
  95. }
  96. // none found
  97. return NULL;
  98. }
  99. extern void ApplyGLSettings(BOOL bForce)
  100. {
  101. CPrintF( TRANS("\nAutomatic 3D-board preferences adjustment...\n"));
  102. CDisplayAdapter &da = _pGfx->gl_gaAPI[_pGfx->gl_eCurrentAPI].ga_adaAdapter[_pGfx->gl_iCurrentAdapter];
  103. CPrintF( TRANS("Detected: %s - %s - %s\n"), da.da_strVendor, da.da_strRenderer, da.da_strVersion);
  104. // get new settings
  105. CSettingsEntry *pse = GetGLSettings( da.da_strRenderer);
  106. // if none found
  107. if (pse==NULL) {
  108. // error
  109. CPrintF(TRANS("No matching preferences found! Automatic adjustment disabled!\n"));
  110. return;
  111. }
  112. // report
  113. CPrintF(TRANS("Matching: %s (%s)\n"), pse->se_strRenderer, pse->se_strDescription);
  114. _strPreferencesDescription = pse->se_strDescription;
  115. if (!bForce) {
  116. // if same as last
  117. if( pse->se_strDescription==_strLastRenderer && sam_iVideoSetup==_iLastPreferences) {
  118. // do nothing
  119. CPrintF(TRANS("Similar to last, keeping same preferences.\n"));
  120. return;
  121. }
  122. CPrintF(TRANS("Different than last, applying new preferences.\n"));
  123. } else {
  124. CPrintF(TRANS("Applying new preferences.\n"));
  125. }
  126. // clamp rendering preferences (just to be on the safe side)
  127. sam_iVideoSetup = Clamp( sam_iVideoSetup, 0L, 3L);
  128. CPrintF(TRANS("Mode: %s\n"), RenderingPreferencesDescription(sam_iVideoSetup));
  129. // if not in custom mode
  130. if (sam_iVideoSetup<3) {
  131. // execute the script
  132. CTString strCmd;
  133. strCmd.PrintF("include \"Scripts\\GLSettings\\%s\"", CTString(pse->se_fnmScript));
  134. _pShell->Execute(strCmd);
  135. // refresh textures
  136. _pShell->Execute("RefreshTextures();");
  137. }
  138. // done
  139. CPrintF(TRANS("Done.\n\n"));
  140. // remember settings
  141. _strLastRenderer = pse->se_strDescription;
  142. _iLastPreferences = sam_iVideoSetup;
  143. }