2016-03-11 14:57:17 +01:00
|
|
|
/* Copyright (c) 2002-2012 Croteam Ltd. All rights reserved. */
|
|
|
|
|
2016-03-29 03:03:54 +02:00
|
|
|
#include "SeriousSam/StdH.h"
|
2016-03-11 14:57:17 +01:00
|
|
|
|
|
|
|
// list of settings data
|
|
|
|
static CListHead _lhSettings;
|
|
|
|
extern INDEX sam_iVideoSetup; // 0==speed, 1==normal, 2==quality, 3==custom
|
|
|
|
|
|
|
|
class CSettingsEntry {
|
|
|
|
public:
|
|
|
|
CListNode se_lnNode;
|
|
|
|
CTString se_strRenderer;
|
|
|
|
CTString se_strDescription;
|
|
|
|
CTFileName se_fnmScript;
|
|
|
|
// check if this entry matches given info
|
|
|
|
BOOL Matches( const CTString &strRenderer) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// last valid settings info
|
|
|
|
static CTString _strLastRenderer;
|
2016-03-29 03:03:54 +02:00
|
|
|
CTString _strPreferencesDescription = "";
|
|
|
|
INDEX _iLastPreferences = 1;
|
2016-03-11 14:57:17 +01:00
|
|
|
|
|
|
|
// check if this entry matches given info
|
|
|
|
BOOL CSettingsEntry::Matches( const CTString &strRenderer) const
|
|
|
|
{
|
|
|
|
return strRenderer.Matches(se_strRenderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *RenderingPreferencesDescription(int iMode)
|
|
|
|
{
|
|
|
|
if (iMode==0) {
|
|
|
|
return TRANS("speed");
|
|
|
|
} else if (iMode==1) {
|
|
|
|
return TRANS("normal");
|
|
|
|
} else if (iMode==2) {
|
|
|
|
return TRANS("quality");
|
|
|
|
} else if (iMode==3) {
|
|
|
|
return TRANS("custom");
|
|
|
|
} else {
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return TRANS("normal");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitGLSettings(void)
|
|
|
|
{
|
|
|
|
ASSERT(_lhSettings.IsEmpty());
|
|
|
|
|
|
|
|
char achrLine [1024];
|
|
|
|
char achrRenderer[1024];
|
|
|
|
char achrDesc [1024];
|
|
|
|
char achrScript [1024];
|
|
|
|
|
|
|
|
CTFileStream strmFile;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
strmFile.Open_t( CTString("Scripts\\GLSettings\\GLSettings.lst"), CTStream::OM_READ);
|
|
|
|
INDEX iIndex = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
achrLine [0] = 0;
|
|
|
|
achrRenderer[0] = 0;
|
|
|
|
achrDesc [0] = 0;
|
|
|
|
achrScript [0] = 0;
|
|
|
|
strmFile.GetLine_t( achrLine, 1024);
|
|
|
|
sscanf( achrLine,
|
|
|
|
"\"%1024[^\"]\"%*[^\"]\"%1024[^\"]\"%*[^\"]\"%1024[^\"]\"", achrRenderer, achrDesc, achrScript);
|
|
|
|
if( achrRenderer[0]==0) continue;
|
|
|
|
|
|
|
|
CSettingsEntry &se = *new CSettingsEntry;
|
|
|
|
se.se_strRenderer = achrRenderer;
|
|
|
|
se.se_strDescription = achrDesc;
|
|
|
|
se.se_fnmScript = CTString(achrScript);
|
|
|
|
_lhSettings.AddTail( se.se_lnNode);
|
|
|
|
}
|
|
|
|
while( !strmFile.AtEOF());
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore errors
|
|
|
|
catch (char *strError) {
|
|
|
|
WarningMessage(TRANS("unable to setup OpenGL settings list: %s"), strError);
|
|
|
|
}
|
|
|
|
|
|
|
|
_strLastRenderer= "none";
|
|
|
|
_iLastPreferences = 1;
|
2016-03-29 03:03:54 +02:00
|
|
|
_pShell->DeclareSymbol("persistent CTString sam_strLastRenderer;", (void *) &_strLastRenderer);
|
|
|
|
_pShell->DeclareSymbol("persistent INDEX sam_iLastSetup;", (void *) &_iLastPreferences);
|
2016-03-11 14:57:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CSettingsEntry *GetGLSettings( const CTString &strRenderer)
|
|
|
|
{
|
|
|
|
// for each setting
|
|
|
|
FOREACHINLIST(CSettingsEntry, se_lnNode, _lhSettings, itse)
|
|
|
|
{ // return the one that matches
|
|
|
|
CSettingsEntry &se = *itse;
|
|
|
|
if( se.Matches(strRenderer)) return &se;
|
|
|
|
}
|
|
|
|
// none found
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern void ApplyGLSettings(BOOL bForce)
|
|
|
|
{
|
|
|
|
CPrintF( TRANS("\nAutomatic 3D-board preferences adjustment...\n"));
|
|
|
|
CDisplayAdapter &da = _pGfx->gl_gaAPI[_pGfx->gl_eCurrentAPI].ga_adaAdapter[_pGfx->gl_iCurrentAdapter];
|
2016-03-29 03:03:54 +02:00
|
|
|
CPrintF( TRANS("Detected: %s - %s - %s\n"), (const char *) da.da_strVendor, (const char *) da.da_strRenderer, (const char *) da.da_strVersion);
|
2016-03-11 14:57:17 +01:00
|
|
|
|
|
|
|
// get new settings
|
|
|
|
CSettingsEntry *pse = GetGLSettings( da.da_strRenderer);
|
|
|
|
|
|
|
|
// if none found
|
|
|
|
if (pse==NULL) {
|
|
|
|
// error
|
|
|
|
CPrintF(TRANS("No matching preferences found! Automatic adjustment disabled!\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// report
|
2016-03-29 03:03:54 +02:00
|
|
|
CPrintF(TRANS("Matching: %s (%s)\n"),
|
|
|
|
(const char *) pse->se_strRenderer,
|
|
|
|
(const char *) pse->se_strDescription);
|
|
|
|
|
2016-03-11 14:57:17 +01:00
|
|
|
_strPreferencesDescription = pse->se_strDescription;
|
|
|
|
|
|
|
|
if (!bForce) {
|
|
|
|
// if same as last
|
|
|
|
if( pse->se_strDescription==_strLastRenderer && sam_iVideoSetup==_iLastPreferences) {
|
|
|
|
// do nothing
|
|
|
|
CPrintF(TRANS("Similar to last, keeping same preferences.\n"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CPrintF(TRANS("Different than last, applying new preferences.\n"));
|
|
|
|
} else {
|
|
|
|
CPrintF(TRANS("Applying new preferences.\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// clamp rendering preferences (just to be on the safe side)
|
|
|
|
sam_iVideoSetup = Clamp( sam_iVideoSetup, 0L, 3L);
|
2016-03-29 03:03:54 +02:00
|
|
|
CPrintF(TRANS("Mode: %s\n"), (const char *) RenderingPreferencesDescription(sam_iVideoSetup));
|
2016-03-11 14:57:17 +01:00
|
|
|
// if not in custom mode
|
|
|
|
if (sam_iVideoSetup<3) {
|
|
|
|
// execute the script
|
|
|
|
CTString strCmd;
|
2016-03-29 03:03:54 +02:00
|
|
|
strCmd.PrintF("include \"Scripts\\GLSettings\\%s\"", (const char *) (CTString(pse->se_fnmScript)));
|
2016-03-11 14:57:17 +01:00
|
|
|
_pShell->Execute(strCmd);
|
|
|
|
// refresh textures
|
|
|
|
_pShell->Execute("RefreshTextures();");
|
|
|
|
}
|
|
|
|
// done
|
|
|
|
CPrintF(TRANS("Done.\n\n"));
|
|
|
|
|
|
|
|
// remember settings
|
|
|
|
_strLastRenderer = pse->se_strDescription;
|
|
|
|
_iLastPreferences = sam_iVideoSetup;
|
|
|
|
}
|