Improved startup performance
This commit is contained in:
parent
222f35f33c
commit
bdf6cea4a7
11 changed files with 85 additions and 70 deletions
|
@ -323,6 +323,7 @@ enum class Language
|
|||
Spanish = 5,
|
||||
Ukrainian = 6,
|
||||
Portuguese = 7,
|
||||
Catalan = 8
|
||||
};
|
||||
|
||||
enum class StereoFilter
|
||||
|
|
|
@ -74,17 +74,22 @@ namespace Mesen.GUI.Config
|
|||
LoadConfig();
|
||||
}
|
||||
|
||||
private static object _initLock = new object();
|
||||
private static void LoadConfig()
|
||||
{
|
||||
if(_config == null) {
|
||||
if(File.Exists(ConfigFile)) {
|
||||
_config = Configuration.Deserialize(ConfigFile);
|
||||
_dirtyConfig = Configuration.Deserialize(ConfigFile);
|
||||
} else {
|
||||
//Create new config file and save it to disk
|
||||
_config = new Configuration();
|
||||
_dirtyConfig = new Configuration();
|
||||
_config.Save();
|
||||
lock(_initLock) {
|
||||
if(_config == null) {
|
||||
if(File.Exists(ConfigFile)) {
|
||||
_config = Configuration.Deserialize(ConfigFile);
|
||||
_dirtyConfig = Configuration.Deserialize(ConfigFile);
|
||||
} else {
|
||||
//Create new config file and save it to disk
|
||||
_config = new Configuration();
|
||||
_dirtyConfig = new Configuration();
|
||||
_config.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,12 +234,17 @@ namespace Mesen.GUI.Config
|
|||
}
|
||||
}
|
||||
|
||||
private static DateTime _lastSaveTime = DateTime.MinValue;
|
||||
public static void ApplyChanges()
|
||||
{
|
||||
_config.NeedToSave = false;
|
||||
_config = _dirtyConfig.Clone();
|
||||
_config.NeedToSave = true;
|
||||
_config.Save();
|
||||
|
||||
if((DateTime.Now - _lastSaveTime).Seconds > 1) {
|
||||
ConfigManager.SaveConfig();
|
||||
_lastSaveTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RejectChanges()
|
||||
|
|
|
@ -286,9 +286,11 @@ namespace Mesen.GUI.Controls
|
|||
|
||||
private void ctrlNsfPlayer_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.Repeat = this.Repeat;
|
||||
this.Shuffle = this.Shuffle;
|
||||
btnPause.Focus();
|
||||
if(!this.DesignMode && this.Visible) {
|
||||
this.Repeat = this.Repeat;
|
||||
this.Shuffle = this.Shuffle;
|
||||
btnPause.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnNext_MouseDown(object sender, MouseEventArgs e)
|
||||
|
|
|
@ -55,9 +55,6 @@ namespace Mesen.GUI.Controls
|
|||
lblSaveDate.Font = new Font(_fonts.Families[0], 10);
|
||||
|
||||
picPrevGame.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
|
||||
if(!ConfigManager.Config.PreferenceInfo.DisableGameSelectionScreen) {
|
||||
Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +63,7 @@ namespace Mesen.GUI.Controls
|
|||
get { return base.Visible; }
|
||||
set
|
||||
{
|
||||
if((_initialized && _recentGames.Count == 0) || ConfigManager.Config.PreferenceInfo.DisableGameSelectionScreen) {
|
||||
if(value && ((_initialized && _recentGames.Count == 0) || ConfigManager.Config.PreferenceInfo.DisableGameSelectionScreen)) {
|
||||
value = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@ namespace Mesen.GUI.Forms
|
|||
}
|
||||
|
||||
ConfigManager.Config.InputInfo.DefaultMapping = mappingType;
|
||||
ConfigManager.Config.InitializeDefaults();
|
||||
ConfigManager.ApplyChanges();
|
||||
ConfigManager.SaveConfig();
|
||||
|
||||
if(chkCreateShortcut.Checked) {
|
||||
this.CreateShortcut();
|
||||
|
|
1
GUI.NET/Forms/frmMain.Designer.cs
generated
1
GUI.NET/Forms/frmMain.Designer.cs
generated
|
@ -305,7 +305,6 @@ namespace Mesen.GUI.Forms
|
|||
this.menuStrip.Size = new System.Drawing.Size(430, 24);
|
||||
this.menuStrip.TabIndex = 0;
|
||||
this.menuStrip.Text = "menuStrip1";
|
||||
this.menuStrip.VisibleChanged += new System.EventHandler(this.menuStrip_VisibleChanged);
|
||||
//
|
||||
// mnuFile
|
||||
//
|
||||
|
|
|
@ -121,6 +121,7 @@ namespace Mesen.GUI.Forms
|
|||
ResourceHelper.UpdateEmuLanguage();
|
||||
ResourceHelper.ApplyResources(this);
|
||||
UpdateMenus();
|
||||
UpdateRecentFiles();
|
||||
InitializeFdsDiskMenu();
|
||||
InitializeNsfMode(true);
|
||||
ctrlRecentGames.UpdateGameInfo();
|
||||
|
|
|
@ -58,14 +58,6 @@ namespace Mesen.GUI.Forms
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
if(ConfigManager.Config.WindowLocation.HasValue) {
|
||||
this.StartPosition = FormStartPosition.Manual;
|
||||
this.Location = ConfigManager.Config.WindowLocation.Value;
|
||||
} else {
|
||||
//First launch
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
}
|
||||
|
||||
Version currentVersion = new Version(InteropEmu.GetMesenVersion());
|
||||
lblVersion.Text = currentVersion.ToString();
|
||||
|
||||
|
@ -129,6 +121,9 @@ namespace Mesen.GUI.Forms
|
|||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
ResourceHelper.LoadResources(ConfigManager.Config.PreferenceInfo.DisplayLanguage);
|
||||
ResourceHelper.UpdateEmuLanguage();
|
||||
|
||||
base.OnLoad(e);
|
||||
|
||||
#if HIDETESTMENU
|
||||
|
@ -158,6 +153,14 @@ namespace Mesen.GUI.Forms
|
|||
|
||||
UpdateViewerSize();
|
||||
|
||||
if(ConfigManager.Config.WindowLocation.HasValue) {
|
||||
this.StartPosition = FormStartPosition.Manual;
|
||||
this.Location = ConfigManager.Config.WindowLocation.Value;
|
||||
} else {
|
||||
//First launch
|
||||
this.StartPosition = FormStartPosition.CenterScreen;
|
||||
}
|
||||
|
||||
if(ConfigManager.Config.PreferenceInfo.CloudSaveIntegration) {
|
||||
Task.Run(() => CloudSyncHelper.Sync());
|
||||
}
|
||||
|
@ -199,6 +202,9 @@ namespace Mesen.GUI.Forms
|
|||
}
|
||||
|
||||
this.LoadGameFromCommandLine(_commandLineArgs);
|
||||
|
||||
this.menuStrip.VisibleChanged += new System.EventHandler(this.menuStrip_VisibleChanged);
|
||||
this.UpdateRendererLocation();
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
|
@ -772,6 +778,11 @@ namespace Mesen.GUI.Forms
|
|||
}
|
||||
|
||||
private void menuStrip_VisibleChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.UpdateRendererLocation();
|
||||
}
|
||||
|
||||
private void UpdateRendererLocation()
|
||||
{
|
||||
if(this.HideMenuStrip) {
|
||||
IntPtr handle = this.Handle;
|
||||
|
|
|
@ -9,6 +9,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Serialization;
|
||||
using Mesen.GUI.Config;
|
||||
using Mesen.GUI.Forms;
|
||||
|
||||
|
@ -61,6 +62,12 @@ namespace Mesen.GUI
|
|||
private static void Main(string[] args)
|
||||
{
|
||||
try {
|
||||
Task.Run(() => {
|
||||
//Cache deserializers in another thread
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
|
||||
xmlSerializer = new XmlSerializer(typeof(DebugWorkspace));
|
||||
});
|
||||
|
||||
if(Type.GetType("Mono.Runtime") != null) {
|
||||
Program.IsMono = true;
|
||||
}
|
||||
|
@ -90,7 +97,6 @@ namespace Mesen.GUI
|
|||
Directory.CreateDirectory(ConfigManager.HomeFolder);
|
||||
Directory.SetCurrentDirectory(ConfigManager.HomeFolder);
|
||||
try {
|
||||
ResourceHelper.LoadResources(ConfigManager.Config.PreferenceInfo.DisplayLanguage);
|
||||
if(!ResourceManager.ExtractResources()) {
|
||||
return;
|
||||
}
|
||||
|
@ -123,21 +129,17 @@ namespace Mesen.GUI
|
|||
return;
|
||||
}
|
||||
|
||||
ResourceHelper.UpdateEmuLanguage();
|
||||
|
||||
using(SingleInstance singleInstance = new SingleInstance()) {
|
||||
if(singleInstance.FirstInstance || !Config.ConfigManager.Config.PreferenceInfo.SingleInstance) {
|
||||
if(singleInstance.FirstInstance || !ConfigManager.Config.PreferenceInfo.SingleInstance) {
|
||||
frmMain frmMain = new frmMain(args);
|
||||
|
||||
if(Config.ConfigManager.Config.PreferenceInfo.SingleInstance) {
|
||||
singleInstance.ListenForArgumentsFromSuccessiveInstances();
|
||||
singleInstance.ArgumentsReceived += (object sender, ArgumentsReceivedEventArgs e) => {
|
||||
frmMain.BeginInvoke((MethodInvoker)(() => {
|
||||
frmMain.ProcessCommandLineArguments(e.Args, false);
|
||||
frmMain.LoadGameFromCommandLine(e.Args);
|
||||
}));
|
||||
};
|
||||
}
|
||||
singleInstance.ListenForArgumentsFromSuccessiveInstances();
|
||||
singleInstance.ArgumentsReceived += (object sender, ArgumentsReceivedEventArgs e) => {
|
||||
frmMain.BeginInvoke((MethodInvoker)(() => {
|
||||
frmMain.ProcessCommandLineArguments(e.Args, false);
|
||||
frmMain.LoadGameFromCommandLine(e.Args);
|
||||
}));
|
||||
};
|
||||
|
||||
Application.Run(frmMain);
|
||||
} else {
|
||||
|
|
|
@ -12,32 +12,10 @@ namespace Mesen.GUI
|
|||
{
|
||||
class ResourceManager
|
||||
{
|
||||
private static void ExtractResource(string resourceName, string filename)
|
||||
{
|
||||
if(File.Exists(filename)) {
|
||||
try {
|
||||
File.Delete(filename);
|
||||
} catch { }
|
||||
}
|
||||
Assembly a = Assembly.GetExecutingAssembly();
|
||||
using(Stream s = a.GetManifestResourceStream(resourceName)) {
|
||||
byte[] buffer = new byte[s.Length];
|
||||
s.Read(buffer, 0, (int)s.Length);
|
||||
try {
|
||||
File.WriteAllBytes(Path.Combine(ConfigManager.HomeFolder, filename), buffer);
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExtractFile(ZipArchiveEntry entry, string outputFilename)
|
||||
{
|
||||
if(File.Exists(outputFilename)) {
|
||||
try {
|
||||
File.Delete(outputFilename);
|
||||
} catch { }
|
||||
}
|
||||
try {
|
||||
entry.ExtractToFile(outputFilename);
|
||||
entry.ExtractToFile(outputFilename, true);
|
||||
} catch { }
|
||||
}
|
||||
|
||||
|
@ -55,10 +33,6 @@ namespace Mesen.GUI
|
|||
private static void CleanupOldFiles()
|
||||
{
|
||||
try {
|
||||
if(Directory.Exists(Path.Combine(ConfigManager.HomeFolder, "Resources"))) {
|
||||
Directory.Delete(Path.Combine(ConfigManager.HomeFolder, "Resources"), true);
|
||||
}
|
||||
|
||||
if(Directory.Exists(Path.Combine(ConfigManager.HomeFolder, "WinMesen"))) {
|
||||
Directory.Delete(Path.Combine(ConfigManager.HomeFolder, "WinMesen"), true);
|
||||
}
|
||||
|
|
|
@ -238,9 +238,6 @@ WindowsKeyManager::WindowsKeyManager(HWND hWnd)
|
|||
}
|
||||
}
|
||||
|
||||
_xInput.reset(new XInputManager());
|
||||
_directInput.reset(new DirectInputManager(hWnd));
|
||||
|
||||
StartUpdateDeviceThread();
|
||||
}
|
||||
|
||||
|
@ -253,6 +250,9 @@ WindowsKeyManager::~WindowsKeyManager()
|
|||
void WindowsKeyManager::StartUpdateDeviceThread()
|
||||
{
|
||||
_updateDeviceThread = std::thread([=]() {
|
||||
_xInput.reset(new XInputManager());
|
||||
_directInput.reset(new DirectInputManager(_hWnd));
|
||||
|
||||
while(!_stopUpdateDeviceThread) {
|
||||
//Check for newly plugged in controllers every 5 secs (this takes ~60-70ms when no new controllers are found)
|
||||
if(_xInput->NeedToUpdate()) {
|
||||
|
@ -272,6 +272,10 @@ void WindowsKeyManager::StartUpdateDeviceThread()
|
|||
|
||||
void WindowsKeyManager::RefreshState()
|
||||
{
|
||||
if(!_xInput || !_directInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
_xInput->RefreshState();
|
||||
_directInput->RefreshState();
|
||||
}
|
||||
|
@ -279,6 +283,10 @@ void WindowsKeyManager::RefreshState()
|
|||
bool WindowsKeyManager::IsKeyPressed(uint32_t key)
|
||||
{
|
||||
if(key >= 0x10000) {
|
||||
if(!_xInput || !_directInput) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(key >= 0x11000) {
|
||||
//Directinput key
|
||||
uint8_t gamepadPort = (key - 0x11000) / 0x100;
|
||||
|
@ -309,6 +317,10 @@ bool WindowsKeyManager::IsMouseButtonPressed(MouseButton button)
|
|||
|
||||
uint32_t WindowsKeyManager::GetPressedKey()
|
||||
{
|
||||
if(!_xInput || !_directInput) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_xInput->RefreshState();
|
||||
for(int i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||
for(int j = 1; j <= 26; j++) {
|
||||
|
@ -357,6 +369,10 @@ uint32_t WindowsKeyManager::GetKeyCode(string keyName)
|
|||
|
||||
void WindowsKeyManager::UpdateDevices()
|
||||
{
|
||||
if(!_xInput || !_directInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
Console::Pause();
|
||||
_xInput->UpdateDeviceList();
|
||||
_directInput->UpdateDeviceList();
|
||||
|
|
Loading…
Add table
Reference in a new issue