예제 #1
0
        private void setupConfig()
        {
            Dependencies.Cache(debugConfig  = new FrameworkDebugConfigManager());
            Dependencies.Cache(config       = new FrameworkConfigManager(Storage));
            Dependencies.Cache(Localisation = new LocalisationEngine(config));

            activeGCMode = debugConfig.GetBindable <GCLatencyMode>(DebugSetting.ActiveGCMode);
            activeGCMode.ValueChanged += newMode =>
            {
                GCSettings.LatencyMode = IsActive ? newMode : GCLatencyMode.Interactive;
            };

            frameSyncMode = config.GetBindable <FrameSync>(FrameworkSetting.FrameSync);
            frameSyncMode.ValueChanged += newMode =>
            {
                float refreshRate = DisplayDevice.Default.RefreshRate;
                // For invalid refresh rates let's assume 60 Hz as it is most common.
                if (refreshRate <= 0)
                {
                    refreshRate = 60;
                }

                float drawLimiter   = refreshRate;
                float updateLimiter = drawLimiter * 2;

                setVSyncMode();

                switch (newMode)
                {
                case FrameSync.VSync:
                    drawLimiter    = int.MaxValue;
                    updateLimiter *= 2;
                    break;

                case FrameSync.Limit2x:
                    drawLimiter   *= 2;
                    updateLimiter *= 2;
                    break;

                case FrameSync.Limit4x:
                    drawLimiter   *= 4;
                    updateLimiter *= 4;
                    break;

                case FrameSync.Limit8x:
                    drawLimiter   *= 8;
                    updateLimiter *= 8;
                    break;

                case FrameSync.Unlimited:
                    drawLimiter = updateLimiter = int.MaxValue;
                    break;
                }

                if (DrawThread != null)
                {
                    DrawThread.ActiveHz = drawLimiter;
                }
                if (UpdateThread != null)
                {
                    UpdateThread.ActiveHz = updateLimiter;
                }
            };

            enabledInputHandlers = config.GetBindable <string>(FrameworkSetting.ActiveInputHandlers);
            enabledInputHandlers.ValueChanged += enabledString =>
            {
                var  configHandlers = enabledString.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s));
                bool useDefaults    = !configHandlers.Any();

                // make sure all the handlers in the configuration file are available, else reset to sane defaults.
                foreach (string handler in configHandlers)
                {
                    if (AvailableInputHandlers.All(h => h.ToString() != handler))
                    {
                        useDefaults = true;
                        break;
                    }
                }

                if (useDefaults)
                {
                    resetInputHandlers();
                    enabledInputHandlers.Value = string.Join(" ", AvailableInputHandlers.Where(h => h.Enabled).Select(h => h.ToString()));
                }
                else
                {
                    foreach (var handler in AvailableInputHandlers)
                    {
                        var handlerType = handler.ToString();
                        handler.Enabled.Value = configHandlers.Any(ch => ch == handlerType);
                    }
                }
            };

            cursorSensitivity = config.GetBindable <double>(FrameworkSetting.CursorSensitivity);
        }
예제 #2
0
        private void setupConfig()
        {
            Dependencies.Cache(debugConfig  = new FrameworkDebugConfigManager());
            Dependencies.Cache(config       = new FrameworkConfigManager(Storage));
            Dependencies.Cache(Localisation = new LocalisationEngine(config));

            activeGCMode = debugConfig.GetBindable <GCLatencyMode>(DebugSetting.ActiveGCMode);
            activeGCMode.ValueChanged += newMode =>
            {
                GCSettings.LatencyMode = IsActive ? newMode : GCLatencyMode.Interactive;
            };

            frameSyncMode = config.GetBindable <FrameSync>(FrameworkSetting.FrameSync);
            frameSyncMode.ValueChanged += newMode =>
            {
                float refreshRate = DisplayDevice.Default.RefreshRate;
                // For invalid refresh rates let's assume 60 Hz as it is most common.
                if (refreshRate <= 0)
                {
                    refreshRate = 60;
                }

                float drawLimiter   = refreshRate;
                float updateLimiter = drawLimiter * 2;

                setVSyncMode();

                switch (newMode)
                {
                case FrameSync.VSync:
                    drawLimiter    = int.MaxValue;
                    updateLimiter *= 2;
                    break;

                case FrameSync.Limit2x:
                    drawLimiter   *= 2;
                    updateLimiter *= 2;
                    break;

                case FrameSync.Limit4x:
                    drawLimiter   *= 4;
                    updateLimiter *= 4;
                    break;

                case FrameSync.Limit8x:
                    drawLimiter   *= 8;
                    updateLimiter *= 8;
                    break;

                case FrameSync.Unlimited:
                    drawLimiter = updateLimiter = int.MaxValue;
                    break;
                }

                if (DrawThread != null)
                {
                    DrawThread.ActiveHz = drawLimiter;
                }
                if (UpdateThread != null)
                {
                    UpdateThread.ActiveHz = updateLimiter;
                }
            };

            ignoredInputHandlers = config.GetBindable <string>(FrameworkSetting.IgnoredInputHandlers);
            ignoredInputHandlers.ValueChanged += ignoredString =>
            {
                var configIgnores = ignoredString.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s));

                // for now, we always want at least one handler disabled (don't want raw and non-raw mouse at once).
                bool restoreDefaults = !configIgnores.Any();

                if (restoreDefaults)
                {
                    resetInputHandlers();
                    ignoredInputHandlers.Value = string.Join(" ", AvailableInputHandlers.Where(h => !h.Enabled).Select(h => h.ToString()));
                }
                else
                {
                    foreach (var handler in AvailableInputHandlers)
                    {
                        var handlerType = handler.ToString();
                        handler.Enabled.Value = configIgnores.All(ch => ch != handlerType);
                    }
                }
            };

            cursorSensitivity = config.GetBindable <double>(FrameworkSetting.CursorSensitivity);

            performanceLogging = config.GetBindable <bool>(FrameworkSetting.PerformanceLogging);
            performanceLogging.ValueChanged += enabled => threads.ForEach(t => t.Monitor.EnablePerformanceProfiling = enabled);
            performanceLogging.TriggerChange();
        }