Skip to content

Commit

Permalink
Add checks to keep Affinity enabled
Browse files Browse the repository at this point in the history
Changed:
- Affinity is should remain enabled no matter which option is chosen
-- If Affinity range is not enabled it will use the old Affinity Limiter, otherwise it will instead use the new one
  • Loading branch information
DavidCarbon committed May 22, 2024
1 parent cae6b01 commit e910a7e
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 240 deletions.
6 changes: 2 additions & 4 deletions SBRW.Launcher.Net/App/UI_Forms/Main_Screen/Screen_Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ public partial class Screen_Main : Form
public static int TotalModFileCount { get; set; }
public static string Custom_SBRW_Pack { get { return Path.Combine(Locations.LauncherFolder, "GameFiles.sbrwpack"); } }

public static int Game_Affinity { get; set; } = 8;
public static int Game_Affinity { get; set; } = 4;
public static int Game_Affinity_Start { get; set; } = 0;
public static int Game_Affinity_End { get; set; } = 8;
public static bool TEST_Game_Affinity { get; set; }
public static bool TEST_Classic_Affinity { get; set; }
public static int Game_Affinity_End { get; set; } = 3;

public Screen_Main()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private void Game_Live_Data(string UserID, string LoginToken, string ServerIP, F
{
if (!(Disposing || IsDisposed))
{
if (new Process_Start_Game() { Live_Process_Cores_Max = (TEST_Classic_Affinity ? -1 : Game_Affinity) }.Initialize(Save_Settings.Live_Data.Game_Path, ServerIP, LoginToken,
if (new Process_Start_Game() { Live_Process_Cores_Max = Game_Affinity }.Initialize(Save_Settings.Live_Data.Game_Path, ServerIP, LoginToken,
UserID, Launcher_Value.Launcher_Select_Server_Data.ID.ToUpper(), true, "nfsw.exe") != null)
{
/* Request a New Session */
Expand Down Expand Up @@ -479,7 +479,7 @@ private void Game_Live_Data(string UserID, string LoginToken, string ServerIP, F
/* Wait 60 Seconds */
bool Game_Fully_Loaded = Process_Start_Game.Live_Process.WaitForInputIdle(60000);
/* Set Affinity For the Game */
if (TEST_Game_Affinity)
if (Game_Affinity.Equals(-1))
{
Process_Start_Game.Live_Process.Affinity(Game_Affinity_Start, Game_Affinity_End);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ private async void SettingsSave_Click(object sender, EventArgs e)
/* Store Old Location for Security Panel to Use Later on */
Save_Settings.Live_Data.Game_Path_Old = Save_Settings.Live_Data.Game_Path;
Save_Settings.Live_Data.Firewall_Game = "Not Excluded";
ButtonsColorSet(Button_Security_Center, 2, true);
#endif

Save_Settings.Live_Data.Game_Path = NewGameFilesPath;
Expand Down Expand Up @@ -303,12 +302,14 @@ private async void SettingsSave_Click(object sender, EventArgs e)
Save_Settings.Live_Data.Launcher_Discord_Presence = CheckBox_RPC.Checked ? "1" : "0";
}

/*
if ((Save_Settings.Live_Data.Launcher_Insider != (CheckBox_Opt_Insider.Checked ? "1" : "0")) &&
!Insider_Settings_Lock && !BuildDevelopment.Allowed())
{
BuildBeta.Allowed((Save_Settings.Live_Data.Launcher_Insider = CheckBox_Opt_Insider.Checked ? "1" : "0") == "1");
RestartRequired = true;
}
*/

if (Save_Settings.Live_Data.Launcher_Theme_Support != (CheckBox_Theme_Support.Checked ? "1" : "0"))
{
Expand Down Expand Up @@ -448,19 +449,9 @@ await Task.Run(() =>
/// <param name="e"></param>
private void Button_Experiments_Click(object sender, EventArgs e)
{
if (!Screen_Main.Game_Affinity.Equals(NumericUpDown_Game_Affinity.Value))
if (!Screen_Main.Game_Affinity.Equals(NumericUpDown_Range_Affinity.Value))
{
Screen_Main.Game_Affinity = (int)NumericUpDown_Game_Affinity.Value;
}

if (!Screen_Main.TEST_Game_Affinity.Equals(CheckBox_Enable_Game_Affinity.Checked))
{
Screen_Main.TEST_Game_Affinity = CheckBox_Enable_Game_Affinity.Checked;
}

if (!Screen_Main.TEST_Classic_Affinity.Equals(CheckBox_Disable_Classic_Affinity.Checked))
{
Screen_Main.TEST_Classic_Affinity = CheckBox_Disable_Classic_Affinity.Checked;
Screen_Main.Game_Affinity = (int)NumericUpDown_Range_Affinity.Value;
}

if (Screen_Main.Screen_Instance != default)
Expand All @@ -469,28 +460,37 @@ private void Button_Experiments_Click(object sender, EventArgs e)
Screen_Main.Screen_Instance.Button_Account_Manager.Visible = CheckBox_Enable_ACM.Checked;
}
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void NumericUpDown_Range_Affinity_ValueChanged(object sender, EventArgs e)
{
if (CheckBox_Enable_Game_Affinity.Checked)
if (CheckBox_Enable_Affinity_Range.Checked)
{
if (RadioButton_Affinity_Add.Checked)
{
if ((int)NumericUpDown_Range_Affinity.Value >= Environment.ProcessorCount - 1)
int Max_Processor_Count = Environment.ProcessorCount - 1;

if ((int)NumericUpDown_Range_Affinity.Value >= Max_Processor_Count)
{
// Ensure we don't go above the max core count
Screen_Main.Game_Affinity_Start = (int)Math.Max(0, NumericUpDown_Range_Affinity.Value - 3);
Screen_Main.Game_Affinity_End = Environment.ProcessorCount - 1;
Screen_Main.Game_Affinity_End = Max_Processor_Count;
}
else if ((Max_Processor_Count - (int)NumericUpDown_Range_Affinity.Value) >= 0 &&
(Max_Processor_Count - (int)NumericUpDown_Range_Affinity.Value) <= 3)
{
Screen_Main.Game_Affinity_Start = Max_Processor_Count - 3;
Screen_Main.Game_Affinity_End = Max_Processor_Count;
}
else
{
// Normal add mode range
Screen_Main.Game_Affinity_Start = (int)NumericUpDown_Range_Affinity.Value;
Screen_Main.Game_Affinity_End = (int)Math.Min(Environment.ProcessorCount - 1, NumericUpDown_Range_Affinity.Value + 3);
Screen_Main.Game_Affinity_End = (int)Math.Min(Max_Processor_Count, NumericUpDown_Range_Affinity.Value + 3);
}
}
else if (RadioButton_Affinity_Subtract.Checked)
Expand All @@ -509,10 +509,24 @@ private void NumericUpDown_Range_Affinity_ValueChanged(object sender, EventArgs
}
}

Screen_Main.Game_Affinity = -1;
Label_Affinity_Core_Range.Text = $"Range: {Screen_Main.Game_Affinity_Start}-{Screen_Main.Game_Affinity_End}";
}
else
{
Screen_Main.Game_Affinity = BuildDevelopment.Allowed() ? (int)NumericUpDown_Range_Affinity.Value : 4;
Label_Affinity_Core_Range.Text = $"{(int)NumericUpDown_Range_Affinity.Value} Cores";
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckBox_Enable_Affinity_Range_CheckedChanged(object sender, EventArgs e)
{
Enable_Affinity_Range(CheckBox_Enable_Affinity_Range.Checked);
}
#endregion
/// <summary>
/// Settings Cancel
/// </summary>
Expand Down Expand Up @@ -832,7 +846,6 @@ private async void Screen_Settings_Load(object sender, EventArgs e)
CheckBox_Proxy.Checked = !Save_Settings.Proxy_RunTime();
CheckBox_RPC.Checked = !Save_Settings.RPC_Discord();
CheckBox_Alt_WebCalls.Checked = Save_Settings.WebCalls_Alt();
CheckBox_Opt_Insider.Checked = InformationCache.EnableInsiderPreview();
CheckBox_Theme_Support.Checked = Save_Settings.Theme_Custom();
CheckBox_JSON_Update_Cache.Checked = Save_Settings.Update_Frequency_JSON();
CheckBox_Proxy_Domain.Checked = Save_Settings.Proxy_Domain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using SBRW.Launcher.Core.Extension.String_;
using SBRW.Launcher.Core.Extra.File_;
using SBRW.Launcher.Core.Theme;
using SBRW.Launcher.RunTime.InsiderKit;
using SBRW.Launcher.RunTime.LauncherCore.APICheckers;
using SBRW.Launcher.RunTime.LauncherCore.Global;
using SBRW.Launcher.RunTime.LauncherCore.Lists;
Expand Down Expand Up @@ -42,7 +43,6 @@ private void WindowsDefenderGameFilesDirctoryChange()
Save_Settings.Live_Data.Game_Path_Old = Save_Settings.Live_Data.Game_Path;
Save_Settings.Live_Data.Firewall_Game = "Not Excluded";
Save_Settings.Live_Data.Defender_Game = "Not Excluded";
ButtonsColorSet(Button_Security_Center, 2, true);
#endif

Save_Settings.Live_Data.Game_Path = NewGameFilesPath;
Expand Down Expand Up @@ -428,7 +428,7 @@ public static void ButtonsColorSet(Button Elements, int Color, bool EnabledORDis
}
}
/// <summary>
/// On Button/Dropdown Functions
/// Translation for Game Display Timer
/// </summary>
/// <returns></returns>
private string Display_Timer_Button_Selection()
Expand All @@ -446,5 +446,68 @@ private string Display_Timer_Button_Selection()
return "0";
}
}
/// <summary>
/// Translation for Log to File Selection
/// </summary>
/// <returns></returns>
private string Log_To_File_Selection()
{
if (Radio_Button_Proxy_Logging_All.Checked)
{
return "1";
}
else if (Radio_Button_Proxy_Logging_Errors.Checked)
{
return "2";
}
else if (Radio_Button_Proxy_Logging_Requests.Checked)
{
return "3";
}
else if (Radio_Button_Proxy_Logging_Responses.Checked)
{
return "4";
}
else
{
return "0";
}
}
/// <summary>
///
/// </summary>
/// <param name="Enable_Affinity_Range"></param>
private void Enable_Affinity_Range(bool Enable_Affinity_Range)
{
/* NOTE: We start counting up from Core 0 !!! So for 4 Cores its range is 0-3 */
if (Enable_Affinity_Range)
{
if (BuildDevelopment.Allowed())
{
NumericUpDown_Range_Affinity.Increment = 1;
NumericUpDown_Range_Affinity.Minimum = 0;
NumericUpDown_Range_Affinity.Maximum = Environment.ProcessorCount - 1;
NumericUpDown_Range_Affinity.Value = 3;
}

Label_Affinity_Core_Calculator.Visible = true;
Panel_Affinity_Range.Visible = true;
}
else if (BuildDevelopment.Allowed())
{
NumericUpDown_Range_Affinity.Increment = 2;
NumericUpDown_Range_Affinity.Minimum = 2;
NumericUpDown_Range_Affinity.Maximum = Environment.ProcessorCount >= 8 ? 8 : Environment.ProcessorCount.Equals(6) ? 6 : 4;
NumericUpDown_Range_Affinity.Value = Environment.ProcessorCount >= 4 ? 4 : 2;
Label_Affinity_Core_Calculator.Visible = true;
Panel_Affinity_Range.Visible = true;
Label_Affinity_Core_Range.Text = $"{(int)NumericUpDown_Range_Affinity.Value} Cores";
}
else
{
Label_Affinity_Core_Calculator.Visible = false;
Panel_Affinity_Range.Visible = false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ private void Set_Visuals()
LinkLabel_Launcher_Path.Text = AppDomain.CurrentDomain.BaseDirectory;
TabPage_About.Text = Label_Version_Build_About.Text = "Version: " + Application.ProductVersion;

NumericUpDown_Range_Affinity.Minimum = 0;
NumericUpDown_Range_Affinity.Maximum = Environment.ProcessorCount - 1;
NumericUpDown_Range_Affinity.Value = 3;
//TODO Add Implementation for Setting Range if User has Range Enabled
Enable_Affinity_Range(CheckBox_Enable_Affinity_Range.Checked);

/*******************************/
/* Set Font /
Expand All @@ -245,7 +244,6 @@ private void Set_Visuals()
Button_Console_Submit.Font = new Font(FormsFont.Primary_Bold(), SecondaryFontSize, FontStyle.Bold);
Input_Console.Font = new Font(FormsFont.Primary(), MainFontSize, FontStyle.Regular);
/* */
Button_Security_Center.Font = new Font(FormsFont.Primary_Bold(), MainFontSize, FontStyle.Bold);
Label_Game_Files.Font = new Font(FormsFont.Primary_Bold(), MainFontSize, FontStyle.Bold);
Button_Change_Game_Path.Font = new Font(FormsFont.Primary_Bold(), MainFontSize, FontStyle.Bold);
Button_Change_Game_Path_Setup.Font = new Font(FormsFont.Primary_Bold(), MainFontSize, FontStyle.Bold);
Expand All @@ -257,7 +255,6 @@ private void Set_Visuals()
Button_Launcher_logs.Font = new Font(FormsFont.Primary_Bold(), SecondaryFontSize, FontStyle.Bold);
Button_Clear_NFSWO_Logs.Font = new Font(FormsFont.Primary_Bold(), SecondaryFontSize, FontStyle.Bold);
Button_Clear_Server_Mods.Font = new Font(FormsFont.Primary_Bold(), SecondaryFontSize, FontStyle.Bold);
CheckBox_Opt_Insider.Font = new Font(FormsFont.Primary(), MainFontSize, FontStyle.Regular);
#region FONT: Setup Tab
/* Setup Tab */
Button_CDN_List_Setup.Font = new Font(FormsFont.Primary_Bold(), SecondaryFontSize, FontStyle.Bold);
Expand Down Expand Up @@ -354,7 +351,6 @@ private void Set_Visuals()
ButtonsColorSet(Button_Launcher_logs, 0, true);
ButtonsColorSet(Button_Clear_NFSWO_Logs, 0, false);
ButtonsColorSet(Button_Clear_Server_Mods, 0, false);
ButtonsColorSet(Button_Security_Center, 0, true);
ButtonsColorSet(Button_CDN_List, VisualsAPIChecker.Local_Cached_API() ? (Screen_Parent.Launcher_Setup.Equals(1) ? 2 : 0) : 4, true);
ButtonsColorSet(Button_CDN_List_Setup, VisualsAPIChecker.Local_Cached_API() ? (Screen_Parent.Launcher_Setup.Equals(1) ? 2 : 0) : 4, true);
ButtonsColorSet(Button_Console_Submit, 1, true);
Expand Down Expand Up @@ -392,9 +388,7 @@ private void Set_Visuals()
CheckBox_Proxy.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_RPC.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_Alt_WebCalls.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_Opt_Insider.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_Theme_Support.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_LZMA_Downloader.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_JSON_Update_Cache.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_Host_to_IP.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
CheckBox_Proxy_Domain.ForeColor = Color_Winform_Other.CheckBoxes_Settings;
Expand Down Expand Up @@ -459,7 +453,6 @@ private void Set_Visuals()
Button_Console_Submit.Click += new EventHandler(Console_Enter);
Button_CDN_List.Click += new EventHandler(Button_CDN_Selector_Click);
Button_CDN_List_Setup.Click += new EventHandler(Button_CDN_Selector_Click);
Button_Security_Center.Click += new EventHandler(Button_Security_Center_Click);
Button_Game_Verify_Files.Click += new EventHandler(Button_Game_Verify_Files_Click);
Button_Save.Click += new EventHandler(SettingsSave_Click);
Button_Save_Setup.Click += new EventHandler(SettingsSave_Click);
Expand Down Expand Up @@ -498,6 +491,7 @@ private void Set_Visuals()
KeyPreview = true;

NumericUpDown_Range_Affinity.ValueChanged += new EventHandler(NumericUpDown_Range_Affinity_ValueChanged);
CheckBox_Enable_Affinity_Range.CheckedChanged += new EventHandler(CheckBox_Enable_Affinity_Range_CheckedChanged);

/********************************/
/* Load XML (Only one Section) /
Expand Down Expand Up @@ -533,16 +527,13 @@ private void Set_Visuals()

ToolTip_Hover.SetToolTip(Button_Launcher_logs, "Removes all but current session \"LOGS\\\" folders");
ToolTip_Hover.SetToolTip(Button_Clear_Server_Mods, "Erases all Server Mods from .data/MODS folders");
ToolTip_Hover.SetToolTip(Button_Security_Center, "Opens a new Panel to review Security Information and Settings");

ToolTip_Hover.SetToolTip(CheckBox_Word_Filter_Check, "Disables the In-Game Chat \"censor\" or word filter.");
ToolTip_Hover.SetToolTip(CheckBox_Proxy, "Disables the Launcher Proxy communications hook.\n" +
"Can not be turned off for httpS Servers.\n" +
"Will also impact/limit the DiscordRPC functions.");
ToolTip_Hover.SetToolTip(CheckBox_RPC, "Prevents Launcher from sending Discord Presence information.");

ToolTip_Hover.SetToolTip(CheckBox_Opt_Insider, "Unchecked: Only Official \"Release\" Builds will prompt Updates\n" +
"Checked: Insider/Beta Build\'s will be available to the Updater");
ToolTip_Hover.SetToolTip(CheckBox_Theme_Support, "Enables supporting External Themes for the Launcher");
/* @Zacam: Update Text to reflect new options
ToolTip_Hover.SetToolTip(CheckBox_Legacy_Timer, "Setting for Legacy Timer:\n" +
Expand All @@ -551,9 +542,6 @@ private void Set_Visuals()
ToolTip_Hover.SetToolTip(CheckBox_Alt_WebCalls, "Changes the internal method used by Launcher for Communications\n" +
"Unchecked: Uses \'standard\' WebClient calls\n" +
"Checked: Uses WebClientWithTimeout");
ToolTip_Hover.SetToolTip(CheckBox_LZMA_Downloader, "Setting for LZMA Downloader:\n" +
"If Checked, this enables the old LZMA Downloader\n" +
"If Unchecked, enables the new SBRW Pack Downloader");
ToolTip_Hover.SetToolTip(CheckBox_JSON_Update_Cache, "Setting for JSON Update Cache Frequency:\n" +
"If Checked, this enables daily cache update for Launcher Related JSON Files\n" +
"If Unchecked, enables hourly cache update for Launcher Related JSON Files");
Expand Down
8 changes: 4 additions & 4 deletions SBRW.Launcher.RunTime/InsiderKit/BuildInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class BuildInformation
{
/* Current month, day, year (2 digits), and letter! Ex: 12-15-20-A */
/* If a second build gets release within the same day bump letter version up (No R2 or D2)*/
const string DATE = "05-21-2024";
const string DATE_SHORT = "05-21-24";
const string TIME = "2159";
const string TIME_SECONDS = "20";
const string DATE = "05-22-2024";
const string DATE_SHORT = "05-22-24";
const string TIME = "0202";
const string TIME_SECONDS = "30";
const string TIME_ZONE = "-07:00";
/// <summary>
/// Build Information <i>(Full Information)</i>
Expand Down
Loading

0 comments on commit e910a7e

Please sign in to comment.