1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-26 23:53:09 +01:00

Remove DX7 renderer and support anisotropic filtering selection.

This commit is contained in:
Nick Blakely 2022-10-29 17:45:12 -07:00
parent 31625f7466
commit 709fe37557
6 changed files with 137 additions and 65 deletions

View File

@ -31,7 +31,9 @@
this.cmbRenderer = new System.Windows.Forms.ComboBox();
this.cmbResolution = new System.Windows.Forms.ComboBox();
this.cmbAntialiasing = new System.Windows.Forms.ComboBox();
this.cmbAnisotropy = new System.Windows.Forms.ComboBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
@ -43,13 +45,12 @@
this.btnCancel = new System.Windows.Forms.Button();
this.btnResetDefaults = new System.Windows.Forms.Button();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.chkUpdates = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.cmbBranch = new System.Windows.Forms.ComboBox();
this.BranchGroupBox = new System.Windows.Forms.GroupBox();
this.chkUpdates = new System.Windows.Forms.CheckBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.BranchGroupBox.SuspendLayout();
this.SuspendLayout();
//
// cmbRenderer
@ -83,11 +84,22 @@
this.cmbAntialiasing.Size = new System.Drawing.Size(335, 24);
this.cmbAntialiasing.TabIndex = 2;
//
// cmbAnisotropy
//
this.cmbAnisotropy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbAnisotropy.FormattingEnabled = true;
this.cmbAnisotropy.Location = new System.Drawing.Point(165, 133);
this.cmbAnisotropy.Name = "cmbAnisotropy";
this.cmbAnisotropy.Size = new System.Drawing.Size(335, 24);
this.cmbAnisotropy.TabIndex = 3;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.cmbAnisotropy);
this.groupBox1.Controls.Add(this.cmbRenderer);
this.groupBox1.Controls.Add(this.cmbResolution);
this.groupBox1.Controls.Add(this.cmbAntialiasing);
@ -95,11 +107,20 @@
this.groupBox1.Margin = new System.Windows.Forms.Padding(4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4);
this.groupBox1.Size = new System.Drawing.Size(509, 143);
this.groupBox1.Size = new System.Drawing.Size(509, 176);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Graphics Settings";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(26, 138);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(127, 16);
this.label4.TabIndex = 7;
this.label4.Text = "Anisotropic Filtering:";
//
// label3
//
this.label3.AutoSize = true;
@ -135,7 +156,7 @@
this.groupBox2.Controls.Add(this.cmbMode);
this.groupBox2.Controls.Add(this.chkTripleBuffering);
this.groupBox2.Controls.Add(this.chkVSync);
this.groupBox2.Location = new System.Drawing.Point(16, 170);
this.groupBox2.Location = new System.Drawing.Point(16, 199);
this.groupBox2.Margin = new System.Windows.Forms.Padding(4);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Padding = new System.Windows.Forms.Padding(4);
@ -160,8 +181,8 @@
//
// chkTripleBuffering
//
this.chkTripleBuffering.AutoSize = true;
this.chkTripleBuffering.Location = new System.Drawing.Point(16, 79);
this.chkTripleBuffering.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.chkTripleBuffering.Location = new System.Drawing.Point(13, 79);
this.chkTripleBuffering.Margin = new System.Windows.Forms.Padding(4);
this.chkTripleBuffering.Name = "chkTripleBuffering";
this.chkTripleBuffering.Size = new System.Drawing.Size(119, 20);
@ -171,18 +192,18 @@
//
// chkVSync
//
this.chkVSync.AutoSize = true;
this.chkVSync.Location = new System.Drawing.Point(16, 53);
this.chkVSync.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.chkVSync.Location = new System.Drawing.Point(13, 53);
this.chkVSync.Margin = new System.Windows.Forms.Padding(4);
this.chkVSync.Name = "chkVSync";
this.chkVSync.Size = new System.Drawing.Size(107, 20);
this.chkVSync.Size = new System.Drawing.Size(119, 20);
this.chkVSync.TabIndex = 1;
this.chkVSync.Text = "Vertical Sync";
this.chkVSync.UseVisualStyleBackColor = true;
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(317, 272);
this.btnOK.Location = new System.Drawing.Point(317, 304);
this.btnOK.Margin = new System.Windows.Forms.Padding(4);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(100, 28);
@ -194,7 +215,7 @@
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(425, 272);
this.btnCancel.Location = new System.Drawing.Point(425, 304);
this.btnCancel.Margin = new System.Windows.Forms.Padding(4);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(100, 28);
@ -205,7 +226,7 @@
//
// btnResetDefaults
//
this.btnResetDefaults.Location = new System.Drawing.Point(400, 170);
this.btnResetDefaults.Location = new System.Drawing.Point(400, 205);
this.btnResetDefaults.Margin = new System.Windows.Forms.Padding(4);
this.btnResetDefaults.Name = "btnResetDefaults";
this.btnResetDefaults.Size = new System.Drawing.Size(125, 28);
@ -216,46 +237,46 @@
//
// groupBox3
//
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.cmbBranch);
this.groupBox3.Controls.Add(this.chkUpdates);
this.groupBox3.Location = new System.Drawing.Point(181, 167);
this.groupBox3.Location = new System.Drawing.Point(181, 199);
this.groupBox3.Margin = new System.Windows.Forms.Padding(4);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Padding = new System.Windows.Forms.Padding(4);
this.groupBox3.Size = new System.Drawing.Size(169, 54);
this.groupBox3.Size = new System.Drawing.Size(211, 97);
this.groupBox3.TabIndex = 6;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Other";
this.groupBox3.Text = "Updates";
//
// chkUpdates
// label5
//
this.chkUpdates.AutoSize = true;
this.chkUpdates.Location = new System.Drawing.Point(11, 24);
this.chkUpdates.Margin = new System.Windows.Forms.Padding(4);
this.chkUpdates.Name = "chkUpdates";
this.chkUpdates.Size = new System.Drawing.Size(140, 20);
this.chkUpdates.TabIndex = 1;
this.chkUpdates.Text = "Check for Updates";
this.chkUpdates.UseVisualStyleBackColor = true;
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(8, 54);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(52, 16);
this.label5.TabIndex = 10;
this.label5.Text = "Branch:";
//
// cmbBranch
//
this.cmbBranch.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbBranch.FormattingEnabled = true;
this.cmbBranch.Location = new System.Drawing.Point(27, 17);
this.cmbBranch.Location = new System.Drawing.Point(66, 49);
this.cmbBranch.Name = "cmbBranch";
this.cmbBranch.Size = new System.Drawing.Size(124, 24);
this.cmbBranch.TabIndex = 9;
//
// BranchGroupBox
// chkUpdates
//
this.BranchGroupBox.Controls.Add(this.cmbBranch);
this.BranchGroupBox.Location = new System.Drawing.Point(181, 222);
this.BranchGroupBox.Name = "BranchGroupBox";
this.BranchGroupBox.Size = new System.Drawing.Size(169, 49);
this.BranchGroupBox.TabIndex = 10;
this.BranchGroupBox.TabStop = false;
this.BranchGroupBox.Text = "Branch";
this.BranchGroupBox.Visible = false;
this.chkUpdates.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.chkUpdates.Location = new System.Drawing.Point(8, 25);
this.chkUpdates.Margin = new System.Windows.Forms.Padding(4);
this.chkUpdates.Name = "chkUpdates";
this.chkUpdates.Size = new System.Drawing.Size(182, 20);
this.chkUpdates.TabIndex = 1;
this.chkUpdates.Text = "Check for Updates";
this.chkUpdates.UseVisualStyleBackColor = true;
//
// OptionsForm
//
@ -264,9 +285,8 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(541, 316);
this.ClientSize = new System.Drawing.Size(541, 346);
this.ControlBox = false;
this.Controls.Add(this.BranchGroupBox);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.btnResetDefaults);
this.Controls.Add(this.btnCancel);
@ -286,10 +306,8 @@
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.BranchGroupBox.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -299,7 +317,9 @@
private System.Windows.Forms.ComboBox cmbRenderer;
private System.Windows.Forms.ComboBox cmbResolution;
private System.Windows.Forms.ComboBox cmbAntialiasing;
private System.Windows.Forms.ComboBox cmbAnisotropy;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
@ -313,6 +333,6 @@
private System.Windows.Forms.CheckBox chkUpdates;
private System.Windows.Forms.ComboBox cmbMode;
private System.Windows.Forms.ComboBox cmbBranch;
private System.Windows.Forms.GroupBox BranchGroupBox;
private System.Windows.Forms.Label label5;
}
}

View File

@ -38,22 +38,22 @@ namespace Giants.Launcher
this.config.TryGetBool(ConfigSections.Update, ConfigKeys.EnableBranchSelection, defaultValue: false, out bool enableBranchSelection);
this.enableBranchSelection = enableBranchSelection;
// Must come first as other options depend on it
this.PopulateRenderers();
this.SetRenderer();
this.PopulateResolution();
this.PopulateAnisotropy();
this.PopulateAntialiasing();
this.SetOptions();
}
private async void OptionsForm_Load(object sender, EventArgs e)
{
// Must come first as other options depend on it
this.PopulateRenderers();
this.SetRenderer();
this.PopulateResolution();
this.PopulateAnisotropy();
this.PopulateAntialiasing();
await this.PopulateBranches();
this.SetOptions();
}
}
private async Task PopulateBranches()
{
@ -66,8 +66,6 @@ namespace Giants.Launcher
cmbBranch.Items.AddRange(branches.ToArray());
cmbBranch.SelectedItem = this.currentBranchName;
BranchGroupBox.Visible = true;
cmbBranch.Visible = true;
}
catch (Exception e)
@ -100,13 +98,15 @@ namespace Giants.Launcher
}
else
{
renderer = GameSettings.CompatibleRenderers.Find(r => r.FileName == "gg_dx7r.dll");
renderer = GameSettings.CompatibleRenderers.Find(r => r.FileName == "gg_dx9r.dll");
this.cmbRenderer.SelectedItem = renderer;
}
}
private void SetOptions()
{
SetRenderer();
var resolutions = (List<ScreenResolution>)this.cmbResolution.DataSource;
this.cmbResolution.SelectedItem = resolutions.Find(r => r.Width == GameSettings.Get<int>(RegistryKeys.VideoWidth) && r.Height == GameSettings.Get<int>(RegistryKeys.VideoHeight));
if (this.cmbResolution.SelectedItem == null)
@ -117,6 +117,11 @@ namespace Giants.Launcher
if (this.cmbAntialiasing.SelectedItem == null)
this.cmbAntialiasing.SelectedIndex = 0;
var anisotropyOptions = (List<KeyValuePair<string, int>>)this.cmbAnisotropy.DataSource;
this.cmbAnisotropy.SelectedItem = anisotropyOptions.Find(o => o.Value == GameSettings.Get<int>(RegistryKeys.AnisotropicFiltering));
if (this.cmbAnisotropy.SelectedItem == null)
this.cmbAnisotropy.SelectedIndex = 0;
this.chkUpdates.Checked = GameSettings.Get<int>(RegistryKeys.NoAutoUpdate) != 1;
if (this.enableBranchSelection)
@ -191,6 +196,23 @@ namespace Giants.Launcher
anisotropyOptions.Add(new KeyValuePair<string,int>(string.Format(Resources.OptionSamples, i), i));
}
}
// Try to keep current selection when repopulating
int? currentValue = null;
if (this.cmbAnisotropy.SelectedValue != null)
{
currentValue = (int)this.cmbAnisotropy.SelectedValue;
}
this.cmbAnisotropy.DataSource = anisotropyOptions;
this.cmbAnisotropy.DisplayMember = "Key";
this.cmbAnisotropy.ValueMember = "Value";
if (currentValue != null)
this.cmbAnisotropy.SelectedValue = currentValue;
if (this.cmbAnisotropy.SelectedValue == null)
this.cmbAnisotropy.SelectedIndex = 0;
}
private void PopulateResolution()
@ -271,6 +293,7 @@ namespace Giants.Launcher
}
GameSettings.Modify(RegistryKeys.Antialiasing, this.cmbAntialiasing.SelectedValue);
GameSettings.Modify(RegistryKeys.AnisotropicFiltering, this.cmbAnisotropy.SelectedValue);
bool windowed = (WindowType)this.cmbMode.SelectedIndex == WindowType.Windowed || (WindowType)this.cmbMode.SelectedIndex == WindowType.Borderless;
GameSettings.Modify(RegistryKeys.Windowed, windowed == true ? 1 : 0);
bool borderless = (WindowType)this.cmbMode.SelectedIndex == WindowType.Borderless;

View File

@ -43,16 +43,20 @@ namespace Giants.Launcher
public static void SetDefaults(string gamePath)
{
// Set default settings:
Settings[RegistryKeys.Renderer] = "gg_dx7r.dll";
Settings[RegistryKeys.Renderer] = "gg_dx9r.dll";
Settings[RegistryKeys.Antialiasing] = 0;
Settings[RegistryKeys.AnisotropicFiltering] = 0;
Settings[RegistryKeys.VideoDepth] = 32;
Settings[RegistryKeys.Windowed] = 0;
Settings[RegistryKeys.BorderlessWindow] = 0;
Settings[RegistryKeys.Windowed] = 1;
Settings[RegistryKeys.BorderlessWindow] = 1;
Settings[RegistryKeys.VerticalSync] = 1;
Settings[RegistryKeys.TripleBuffering] = 1;
Settings[RegistryKeys.NoAutoUpdate] = 0;
// Set the current desktop resolution, leaving bit depth at the default 32:
Settings[RegistryKeys.VideoWidth] = Screen.PrimaryScreen.Bounds.Width;
Settings[RegistryKeys.VideoHeight] = Screen.PrimaryScreen.Bounds.Height;
// Get a list of renderers compatible with the user's system
if (!CompatibleRenderers.Any())
{
@ -64,18 +68,16 @@ namespace Giants.Launcher
caption: Resources.Error,
buttons: MessageBoxButtons.OK,
icon: MessageBoxIcon.Error);
return;
}
}
// Select the highest priority renderer
if (CompatibleRenderers.Any())
{
Settings[RegistryKeys.Renderer] = Path.GetFileName(CompatibleRenderers.Max().FilePath);
}
// Set the current desktop resolution, leaving bit depth at the default 32:
Settings[RegistryKeys.VideoWidth] = Screen.PrimaryScreen.Bounds.Width;
Settings[RegistryKeys.VideoHeight] = Screen.PrimaryScreen.Bounds.Height;
var bestRenderer = CompatibleRenderers.Max();
Settings[RegistryKeys.Renderer] = Path.GetFileName(bestRenderer.FilePath);
Settings[RegistryKeys.AnisotropicFiltering] = bestRenderer.MaxAnisotropy;
Settings[RegistryKeys.Antialiasing] = bestRenderer.MaxAntialiasing;
}
public static void Load(string gamePath)

View File

@ -118,6 +118,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Forms\OptionsForm.resx">
<DependentUpon>OptionsForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>

View File

@ -29,6 +29,10 @@ namespace Giants.Launcher
/// <returns>True if the given renderer is supported by the system.</returns>
public static bool GetRendererCapabilities(string dllPath, ref GFXCapabilityInfo capabilities)
{
string currentDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(Path.GetDirectoryName(dllPath));
bool rendererSupported = false;
IntPtr pDll = NativeMethods.LoadLibrary(dllPath);
if (pDll == IntPtr.Zero)
@ -43,6 +47,8 @@ namespace Giants.Launcher
NativeMethods.FreeLibrary(pDll);
Directory.SetCurrentDirectory(currentDirectory);
return rendererSupported;
}

View File

@ -30,6 +30,23 @@ namespace Giants.Launcher
this.Flags = (RendererFlag)gfxCaps.flags;
this.Priority = gfxCaps.priority;
this.Name = gfxCaps.rendererName;
if (this.Flags.HasFlag(RendererFlag.MSAA16x))
{
this.MaxAntialiasing = 16;
}
else if (this.Flags.HasFlag(RendererFlag.MSAA8x))
{
this.MaxAntialiasing = 8;
}
else if (this.Flags.HasFlag(RendererFlag.MSAA4x))
{
this.MaxAntialiasing = 4;
}
else if (this.Flags.HasFlag(RendererFlag.MSAA2x))
{
this.MaxAntialiasing = 2;
}
}
public override string ToString()
@ -54,6 +71,7 @@ namespace Giants.Launcher
this.FilePath == info.FilePath &&
this.FileName == info.FileName &&
this.MaxAnisotropy == info.MaxAnisotropy &&
this.MaxAntialiasing == info.MaxAntialiasing &&
this.Flags == info.Flags &&
this.Priority == info.Priority &&
this.Name == info.Name;
@ -65,6 +83,7 @@ namespace Giants.Launcher
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.FilePath);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.FileName);
hashCode = hashCode * -1521134295 + this.MaxAnisotropy.GetHashCode();
hashCode = hashCode * -1521134295 + this.MaxAntialiasing.GetHashCode();
hashCode = hashCode * -1521134295 + this.Flags.GetHashCode();
hashCode = hashCode * -1521134295 + this.Priority.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(this.Name);
@ -74,6 +93,7 @@ namespace Giants.Launcher
public string FilePath { get; private set; }
public string FileName { get; private set; }
public int MaxAnisotropy { get; private set; }
public int MaxAntialiasing { get; private set; }
public RendererFlag Flags { get; private set; }
public int Priority { get; private set; }
public string Name { get; set; }