setting ResolutionCap to limit the actual screen resolution

This commit is contained in:
Jens Hemprich 2007-02-09 22:39:59 +00:00
parent 8e1801a702
commit e1fb42b75b
5 changed files with 224 additions and 203 deletions

View File

@ -47,7 +47,7 @@ GlideSettings::IOErr GlideSettingsFSp::makeSettingsFolderFileSpec(const char* pa
/** /**
* Find/Create settings folder * Find/Create settings folder
* @return fnfErr means the CLassic environment wasn't found * @return fnfErr means the Classic environment wasn't found
*/ */
GlideSettings::IOErr GlideSettingsFSp::init(const char* applicationname) GlideSettings::IOErr GlideSettingsFSp::init(const char* applicationname)
{ {
@ -71,6 +71,7 @@ GlideSettings::IOErr GlideSettingsFSp::init(const char* applicationname)
} }
} }
// Make references to various files // Make references to various files
m_fsSettingsFile.vRefNum = 0;
if (err == noErr) if (err == noErr)
{ {
err = makeSettingsFolderFileSpec(&s_SettingsFolderName[1], s_LogFileName, &m_fsLogFile); err = makeSettingsFolderFileSpec(&s_SettingsFolderName[1], s_LogFileName, &m_fsLogFile);
@ -79,7 +80,6 @@ GlideSettings::IOErr GlideSettingsFSp::init(const char* applicationname)
err = makeSettingsFolderFileSpec(&s_SettingsFolderName[1], s_DefaultSettingsFileName, &m_fsDefaultSettingsFile); err = makeSettingsFolderFileSpec(&s_SettingsFolderName[1], s_DefaultSettingsFileName, &m_fsDefaultSettingsFile);
if (err == noErr) if (err == noErr)
{ {
m_fsSettingsFile.vRefNum = 0;
if (applicationname) if (applicationname)
{ {
err = makeSettingsFolderFileSpec(&s_SettingsFolderName[1], applicationname, &m_fsSettingsFile); err = makeSettingsFolderFileSpec(&s_SettingsFolderName[1], applicationname, &m_fsSettingsFile);
@ -143,7 +143,7 @@ GlideSettings::IOErr GlideSettingsFSp::read_settings_from_file(FSSpec* file, Gli
err = save(); err = save();
if (err == noErr) if (err == noErr)
{ {
// Now we have o load the file into memory to make the settings reader happy // Now we have to load the file into memory to make the settings reader happy
err = read_file(file, &m_FileBuffer, &m_FileBufferSize, &m_SettingsFileRefnum); err = read_file(file, &m_FileBuffer, &m_FileBufferSize, &m_SettingsFileRefnum);
} }
} }

View File

@ -26,7 +26,6 @@ protected:
IOErr create(); IOErr create();
IOErr read_defaults(); IOErr read_defaults();
IOErr read(); IOErr read();
inline bool isApplicationSpecific() {return m_fsSettingsFile.vRefNum != 0;};
IOErr put_raw(const char* string); IOErr put_raw(const char* string);
IOErr close(); IOErr close();
const unsigned char* PascalString(char* string); const unsigned char* PascalString(char* string);

View File

@ -63,6 +63,11 @@ bool GlideSettings::get(const char* setting, const char** value)
sscanf(v, "%255s", buffer); sscanf(v, "%255s", buffer);
found = true; found = true;
} }
else
{
// Wrong match, maybe a comment
v++;
}
} }
} }
*value = buffer; *value = buffer;
@ -127,6 +132,7 @@ void GlideSettings::defaults()
// OpenGL extensions that can be disabled via the config file must be set to // OpenGL extensions that can be disabled via the config file must be set to
// true in order to become enabled in ValidateUserConfig() // true in order to become enabled in ValidateUserConfig()
Resolution = 1; Resolution = 1;
ResolutionCap = 0;
MonitorRefreshRate = 0; MonitorRefreshRate = 0;
DepthBufferBits = 0; DepthBufferBits = 0;
FullSceneAntiAliasing = 0; FullSceneAntiAliasing = 0;
@ -140,29 +146,29 @@ void GlideSettings::defaults()
#endif #endif
ColorAlphaRenderMode = OpenGLideColorAlphaRenderMode_Automatic; ColorAlphaRenderMode = OpenGLideColorAlphaRenderMode_Automatic;
PrecisionFix = 1; PrecisionFix = 1;
/* /*
// Not bad // Not bad
GapFix = static_cast<OpenGLideGapFixFlags>(OpenGLideGapFixFlag_Enabled | GapFix = static_cast<OpenGLideGapFixFlags>(OpenGLideGapFixFlag_IncircleOr |
OpenGLideGapFixFlag_IncircleOr |
OpenGLideGapFixFlag_DepthFactor); OpenGLideGapFixFlag_DepthFactor);
GapFixParam1 = 3.0f; GapFixParam1 = 3.0f;
GapFixParam2 = 10.0f; GapFixParam2 = 10.0f;
GapFixParam3 = 3.0f; GapFixParam3 = 3.0f;
GapFixDepthFactor = 3.3f; GapFixDepthFactor = 3.3f;
*/ */
/* /*
// But this one is better // But this one is better
GapFix = static_cast<OpenGLideGapFixFlags>(OpenGLideGapFixFlag_Enabled | GapFix = static_cast<OpenGLideGapFixFlags>(OpenGLideGapFixFlag_VertexLengthSecondRadius |
OpenGLideGapFixFlag_VertexLengthSecondRadius |
OpenGLideGapFixFlag_DepthFactor); OpenGLideGapFixFlag_DepthFactor);
GapFixParam1 = 3.0f; GapFixParam1 = 3.0f;
GapFixParam2 = 25.0f; GapFixParam2 = 25.0f;
GapFixParam3 = 0.9f; GapFixParam3 = 0.9f;
GapFixDepthFactor = 3.3f; GapFixDepthFactor = 3.3f;
*/ */
// @todo: Let's make this even more better
GapFix = static_cast<OpenGLideGapFixFlags>(/*OpenGLideGapFixFlag_Enabled |*/ // @todo: Let's improve these default values even more
OpenGLideGapFixFlag_VertexLengthSecondRadius | GapFix = static_cast<OpenGLideGapFixFlags>(OpenGLideGapFixFlag_VertexLengthSecondRadius |
OpenGLideGapFixFlag_DepthFactor); OpenGLideGapFixFlag_DepthFactor);
GapFixParam1 = 3.0f; GapFixParam1 = 3.0f;
GapFixParam2 = 25.0f; GapFixParam2 = 25.0f;
@ -215,11 +221,11 @@ GlideSettings::IOErr GlideSettings::read_settings()
#ifdef OGL_DEBUG #ifdef OGL_DEBUG
GlideMsg("Reading values...\n"); GlideMsg("Reading values...\n");
#endif #endif
GlideSettings::IOErr err = noErr;
unsigned long value; unsigned long value;
get("DisplayMode", &value); get("DisplayMode", &value);
DisplayMode = static_cast<OpenGLideDisplayMode>(value); DisplayMode = static_cast<OpenGLideDisplayMode>(value);
get("Resolution", &Resolution); get("Resolution", &Resolution);
get("ResolutionCap", &ResolutionCap);
get("MonitorRefreshRate", &MonitorRefreshRate); get("MonitorRefreshRate", &MonitorRefreshRate);
get("DepthBufferBits", &DepthBufferBits); get("DepthBufferBits", &DepthBufferBits);
get("Mipmapping", &Mipmapping); get("Mipmapping", &Mipmapping);
@ -257,7 +263,7 @@ GlideSettings::IOErr GlideSettings::read_settings()
get("ShamelessPlug", &ShamelessPlug); get("ShamelessPlug", &ShamelessPlug);
get("UseApplicationSpecificSettings", &UseApplicationSpecificSettings); get("UseApplicationSpecificSettings", &UseApplicationSpecificSettings);
get("AutoEnableGameSpecificSettings", &AutoEnableGameSpecificSettings); get("AutoEnableGameSpecificSettings", &AutoEnableGameSpecificSettings);
return err; return noErr;
} }
GlideSettings::IOErr GlideSettings::load() GlideSettings::IOErr GlideSettings::load()
@ -279,29 +285,35 @@ GlideSettings::IOErr GlideSettings::load()
} }
if (success && strcmp(version, prefs_version) == 0) if (success && strcmp(version, prefs_version) == 0)
{ {
// Version match
err = read_settings(); err = read_settings();
} }
else if (!success) else if (!success)
{ {
GlideMsg(version_complaint, "default"); // Unable to read settings file version information - somethings seriously wrong
GlideError(version_complaint, "default");
} }
else else
{ {
// Write new settings file after settings file version change
GlideMsg("Configuration outdated - Creating new default settings %s...\n", prefs_version); GlideMsg("Configuration outdated - Creating new default settings %s...\n", prefs_version);
defaults(); defaults();
err = create_defaults(); err = create_defaults();
if (err == noErr) if (err == noErr)
{ {
err = saveSettings(); err = save();
} }
} }
if (err == noErr) if (err == noErr)
{ {
if (isApplicationSpecific() && UseApplicationSpecificSettings) // Default or application specific config?
if (UseApplicationSpecificSettings)
{ {
// Read application specific config
err = read(); err = read();
if (err == noErr) if (err == noErr)
{ {
// Version check
success = get("Version", &version); success = get("Version", &version);
if (success && strcmp(version, prefs_version) == 0) if (success && strcmp(version, prefs_version) == 0)
{ {
@ -314,16 +326,18 @@ GlideSettings::IOErr GlideSettings::load()
} }
else if (!success) else if (!success)
{ {
GlideMsg(version_complaint, "application specific"); // Unable to read settings file version information - somethings seriously wrong
GlideError(version_complaint, "application specific");
} }
else else
{ {
// Write new settings file after settings file version change
GlideMsg("Configuration outdated - Creating new application specific settings %s...\n", prefs_version); GlideMsg("Configuration outdated - Creating new application specific settings %s...\n", prefs_version);
defaults(); defaults();
err = create(); err = create();
if (err == noErr) if (err == noErr)
{ {
err = saveSettings(); err = save();
} }
} }
} }
@ -338,7 +352,9 @@ GlideSettings::IOErr GlideSettings::saveSettings()
#ifdef OGL_DEBUG #ifdef OGL_DEBUG
GlideMsg("Saving...\n"); GlideMsg("Saving...\n");
#endif #endif
put("Configuration File for MacGLide"); IOErr err = put("Configuration File for MacGLide");
if (err == noErr)
{
put(); put();
put(); put();
put("Current version number of the settings file:" ); put("Current version number of the settings file:" );
@ -354,11 +370,18 @@ GlideSettings::IOErr GlideSettings::saveSettings()
put("DisplayMode", static_cast<unsigned long>(DisplayMode)); put("DisplayMode", static_cast<unsigned long>(DisplayMode));
put(); put();
put("Display resolution:"); put("Display resolution:");
put("0: Always use the resolution denoted by the ResolutionCap settings");
put("1-8: Multiplier for Glide resolution as requested by the"); put("1-8: Multiplier for Glide resolution as requested by the");
put("game/application. Any value equal or greater than 512:"); put("game/application. Any value equal or greater than 512:");
put("fixed x resolution (y is computed for a 4/3 aspect ratio)"); put("fixed x resolution (y is computed for a 4/3 aspect ratio)");
put("Resolution", Resolution); put("Resolution", Resolution);
put(); put();
put("Display resolution cap:");
put("0 to disable, otherwise the maximum");
put("x resolution to use for the Glide display");
put("(y is computed for a 4/3 aspect ratio)");
put("ResolutionCap", ResolutionCap);
put();
put("Refresh rate of the monitor:"); put("Refresh rate of the monitor:");
put("0 to use the Glide refresh rate as requested by the game/"); put("0 to use the Glide refresh rate as requested by the game/");
put("application. Any other value equal or greater than 60(Hz):"); put("application. Any other value equal or greater than 60(Hz):");
@ -502,7 +525,9 @@ GlideSettings::IOErr GlideSettings::saveSettings()
put(); put();
put("Shows the 3Dfx logo in the lower right corner of the screen"); put("Shows the 3Dfx logo in the lower right corner of the screen");
put("ShamelessPlug", ShamelessPlug); put("ShamelessPlug", ShamelessPlug);
GlideSettings::IOErr err = close(); // Get the error code of the last write in order to catch errors like "Disk full" etc.
err = put();
}
return err; return err;
} }
@ -616,19 +641,14 @@ GlideSettings::IOErr GlideSettings::put(const char* setting, bool value)
GlideSettings::IOErr GlideSettings::save() GlideSettings::IOErr GlideSettings::save()
{ {
IOErr err = noErr; IOErr err = saveSettings();
if (isApplicationSpecific()) if (err == noErr)
{ {
err = create(); err = close();
} }
else else
{ {
err = create_defaults();
}
if (err == noErr)
{
err = saveSettings();
}
close(); close();
return noErr; }
return err;
} }

View File

@ -69,6 +69,7 @@ struct ConfigStruct
{ {
OpenGLideDisplayMode DisplayMode; OpenGLideDisplayMode DisplayMode;
unsigned long Resolution; unsigned long Resolution;
unsigned long ResolutionCap;
unsigned long MonitorRefreshRate; unsigned long MonitorRefreshRate;
unsigned long DepthBufferBits; unsigned long DepthBufferBits;
unsigned long FullSceneAntiAliasing; unsigned long FullSceneAntiAliasing;
@ -143,7 +144,6 @@ protected:
void defaults(); void defaults();
virtual IOErr read_defaults()=0; virtual IOErr read_defaults()=0;
virtual IOErr read()=0; virtual IOErr read()=0;
virtual bool isApplicationSpecific()=0;
IOErr read_settings(); IOErr read_settings();
IOErr saveSettings(); IOErr saveSettings();
bool get(const char* setting, const char** value); bool get(const char* setting, const char** value);

View File

@ -225,13 +225,13 @@ grSstWinOpen(FxU32 hwnd,
} }
#endif #endif
Glide.WindowWidth = windowDimensions[ Glide.Resolution ].width; Glide.WindowWidth = windowDimensions[Glide.Resolution].width;
Glide.WindowHeight = windowDimensions[ Glide.Resolution ].height; Glide.WindowHeight = windowDimensions[Glide.Resolution].height;
// Set the size of the opengl window (might be different from Glide window size) // Set the size of the opengl window (might be different from Glide window size)
if (UserConfig.Resolution == 0) if (UserConfig.Resolution == 0)
{ {
// Does only work if the library is loaded at startup, before the game changes the screen resolution // Does only work if the library is loaded at startup, before the game changes the screen resolution
if (DisplayManager_GetDesktopDisplayResolution(OpenGL.WindowWidth, OpenGL.WindowHeight) != noErr) if (!DisplayManager_GetDesktopDisplayResolution(OpenGL.WindowWidth, OpenGL.WindowHeight))
{ {
// Use the resuolution requested by the game // Use the resuolution requested by the game
OpenGL.WindowWidth = Glide.WindowWidth; OpenGL.WindowWidth = Glide.WindowWidth;
@ -244,18 +244,20 @@ grSstWinOpen(FxU32 hwnd,
OpenGL.WindowWidth = Glide.WindowWidth * UserConfig.Resolution; OpenGL.WindowWidth = Glide.WindowWidth * UserConfig.Resolution;
OpenGL.WindowHeight = Glide.WindowHeight * UserConfig.Resolution; OpenGL.WindowHeight = Glide.WindowHeight * UserConfig.Resolution;
} }
else if (UserConfig.Resolution >= 512) else
{ {
// override the resolution // override the resolution
OpenGL.WindowWidth = UserConfig.Resolution; OpenGL.WindowWidth = UserConfig.Resolution;
// Glide games have a fixed 4/3 aspect ratio // Glide games have a fixed 4/3 aspect ratio
OpenGL.WindowHeight = UserConfig.Resolution * 3 / 4; OpenGL.WindowHeight = UserConfig.Resolution * 3 / 4;
} }
else // Limit the display size to the max allowed screen resolution
if (UserConfig.ResolutionCap)
{ {
// Use the resuolution requested by the game OpenGL.WindowWidth = min(OpenGL.WindowWidth,
OpenGL.WindowWidth = Glide.WindowWidth; UserConfig.ResolutionCap);
OpenGL.WindowHeight = Glide.WindowHeight; OpenGL.WindowHeight = min(OpenGL.WindowHeight,
UserConfig.ResolutionCap * 3 / 4);
} }
Glide.WindowTotalPixels = Glide.WindowWidth * Glide.WindowHeight; Glide.WindowTotalPixels = Glide.WindowWidth * Glide.WindowHeight;
Glide.Refresh = ref; Glide.Refresh = ref;