Пример #1
0
        //  Call this at the application start. It will look into config file and get video parameters. If not found, default will be chosen. Then video mode will be initialized.
        static void InitFromConfig()
        {
            MyMwcLog.WriteLine("MyVideoModeManager.InitFromConfig START");

            //  Here we store width/height of windows desktop - becuase later they can
            //  change after we switch to fullscreen and we want to have these original values.
            m_originalWindowsDesktopWidth  = GraphicsAdapter.Default.CurrentDisplayMode.Width;
            m_originalWindowsDesktopHeight = GraphicsAdapter.Default.CurrentDisplayMode.Height;

            //  Read from config or use default/recommended values
            bool                configFullscreen     = MyConfig.FullScreen;
            int                 configVideoAdapter   = MyConfig.VideoAdapter;
            MyVideoModeEx       configVideoMode      = MyConfig.VideoMode;
            bool                configVerticalSync   = MyConfig.VerticalSync;
            bool                configHardwareCursor = MyConfig.HardwareCursor;
            MyRenderQualityEnum configRenderQuality  = MyConfig.RenderQuality;
            float               configFieldOfView    = MyConfig.FieldOfView;

            //  Save values to config
            MyConfig.VideoAdapter   = configVideoAdapter;
            MyConfig.VideoMode      = configVideoMode;
            MyConfig.FullScreen     = configFullscreen;
            MyConfig.VerticalSync   = configVerticalSync;
            MyConfig.HardwareCursor = configHardwareCursor;
            MyConfig.RenderQuality  = configRenderQuality;
            MyConfig.FieldOfView    = configFieldOfView;
            MyConfig.Save();

            //  Finally change/init the video mode
            BeginChangeVideoMode(true, configVideoAdapter, configVideoMode, configFullscreen, configVerticalSync, configHardwareCursor, configRenderQuality, configFieldOfView, true, null);
            ApplyChanges();

            MyMwcLog.WriteLine("MyVideoModeManager.InitFromConfig END");
        }
Пример #2
0
        static void RegisterVideoMode(int adapterIndex, int width, int height, float ratio)
        {
            if ((width > MyMinerGame.GraphicsDeviceManager.MaxTextureSize) || (height > MyMinerGame.GraphicsDeviceManager.MaxTextureSize))
            {
                MyMwcLog.WriteLine("VideoMode " + width.ToString() + " x " + height.ToString() + " requires texture size which is not supported by this HW (this HW supports max " + MyMinerGame.GraphicsDeviceManager.MaxTextureSize.ToString() + ")");
            }

            MyVideoModeEx newVideoMode = null;

            if (!m_resolutionMap.ContainsKey(adapterIndex))
            {
                m_resolutionMap.Add(adapterIndex, new Dictionary <int, Dictionary <int, MyVideoModeEx> >());
            }

            if (!m_videoModeList.ContainsKey(adapterIndex))
            {
                m_videoModeList.Add(adapterIndex, new List <MyVideoModeEx>());
            }

            if (!m_aspectRatioMap.ContainsKey(adapterIndex))
            {
                m_aspectRatioMap.Add(adapterIndex, new Dictionary <float, SortedDictionary <int, MyVideoModeEx> >());
            }


            if (m_resolutionMap[adapterIndex].ContainsKey(width) == false)
            {
                m_resolutionMap[adapterIndex][width] = new Dictionary <int, MyVideoModeEx>();
                newVideoMode = new MyVideoModeEx(width, height, ratio);
            }
            else if (m_resolutionMap[adapterIndex][width].ContainsKey(height) == false)
            {
                newVideoMode = new MyVideoModeEx(width, height, ratio);
            }

            if (newVideoMode != null)  // So there is a new video mode added, add it to maps and populate related fields
            {
                newVideoMode.IsRecommended = newVideoMode.AspectRatioEnum == m_recommendedAspectRatio[adapterIndex].AspectRatioEnum;
                m_resolutionMap[adapterIndex][width][height] = newVideoMode;
                m_videoModeList[adapterIndex].Add(newVideoMode);

                if (m_aspectRatioMap[adapterIndex].ContainsKey(newVideoMode.AspectRatio) == false)
                {
                    m_aspectRatioMap[adapterIndex][newVideoMode.AspectRatio] = new SortedDictionary <int, MyVideoModeEx>();
                    m_aspectRatioMap[adapterIndex][newVideoMode.AspectRatio].Add(newVideoMode.Width, newVideoMode);
                }
                else if (m_aspectRatioMap[adapterIndex][newVideoMode.AspectRatio].ContainsKey(width) == false)
                {
                    m_aspectRatioMap[adapterIndex][newVideoMode.AspectRatio].Add(newVideoMode.Width, newVideoMode);
                }
            }
        }
Пример #3
0
        public static MyVideoModeEx GetDefaultVideoModeForEmptyConfig(int adapterIndex)
        {
            for (int i = 0; i < m_videoModeList[adapterIndex].Count; i++)
            {
                MyVideoModeEx videoMode = m_videoModeList[adapterIndex][i];
                if (videoMode.Width == System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
                    &&
                    videoMode.Height == System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
                {
                    return(videoMode);
                }
            }

            return(null);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public MyVideoModeChangeOperation(bool callApplyChanges, bool fullScreen, bool verticalSync, bool hardwareCursor,
                                   float fieldOfView,
                                   int videoAdapter, MyVideoModeEx videoMode,
                                   MyRenderQualityEnum renderQuality, bool first, Action <MyVideoModeChangeOperation> requestCallback)
 {
     this.callApplyChanges = callApplyChanges;
     this.fullScreen       = fullScreen;
     this.verticalSync     = verticalSync;
     this.hardwareCursor   = hardwareCursor;
     this.fieldOfView      = fieldOfView;
     this.videoAdapter     = videoAdapter;
     this.videoMode        = videoMode;
     this.renderQuality    = renderQuality;
     this.first            = first;
     this.requestCallback  = requestCallback;
 }
Пример #5
0
        //  This video mode is used when user has empty config and we need to set some default resolution
        //  The idea is to find resolution which is close to 1280x720 because that one is high-res enough
        //  and runs smoothly on all sorts of computers
        public static MyVideoModeEx GetDefaultVideoModeForEmptyConfigWithClosestAspectRatio(int adapterIndex, float aspectRatio)
        {
            List <MyVideoModeEx> sortByClosestAspectRatio = new List <MyVideoModeEx>();

            for (int i = 0; i < m_videoModeList[adapterIndex].Count; i++)
            {
                MyVideoModeEx videoMode = m_videoModeList[adapterIndex][i];
                if (videoMode.Width <= 1280)
                {
                    sortByClosestAspectRatio.Add(videoMode);
                }
            }

            if (sortByClosestAspectRatio.Count > 0)
            {
                sortByClosestAspectRatio.Sort(
                    delegate(MyVideoModeEx p1, MyVideoModeEx p2)
                {
                    float deltaP1 = Math.Abs(aspectRatio - p1.AspectRatio);
                    float deltaP2 = Math.Abs(aspectRatio - p2.AspectRatio);
                    return(deltaP1.CompareTo(deltaP2));
                }
                    );

                MyAspectRatioEnum thisAspectRatio = sortByClosestAspectRatio[0].AspectRatioEnum;

                //  Now look for highest resolution (we have guaranteed that none is more than 1280x***)
                MyVideoModeEx maxVideoMode = null;
                for (int i = 0; i < sortByClosestAspectRatio.Count; i++)
                {
                    MyVideoModeEx videoMode = sortByClosestAspectRatio[i];
                    if (videoMode.AspectRatioEnum == thisAspectRatio)
                    {
                        if ((maxVideoMode == null) || (videoMode.Width > maxVideoMode.Width))
                        {
                            maxVideoMode = videoMode;
                        }
                    }
                }

                return(maxVideoMode);
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        /// <summary>
        /// Begins the change video mode.
        /// </summary>
        /// <param name="callApplyChanges">if set to <c>true</c> [call apply changes].</param>
        /// <param name="videoMode">The video mode.</param>
        /// <param name="fullScreen">if set to <c>true</c> [full screen].</param>
        /// <param name="verticalSync">if set to <c>true</c> [vertical sync].</param>
        /// <param name="hardwareCursor">if set to <c>true</c> [hardware cursor].</param>
        /// <param name="renderQuality">The render quality.</param>
        /// <param name="fieldOfView">The field of view.</param>
        /// <param name="requestCallback">The request callback.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public static void BeginChangeVideoMode(bool callApplyChanges, int videoAdapter, MyVideoModeEx videoMode, bool fullScreen, bool verticalSync, bool hardwareCursor, MyRenderQualityEnum renderQuality, float fieldOfView, bool first, Action <MyVideoModeChangeOperation> requestCallback)
        {
            var result = new MyVideoModeChangeOperation(callApplyChanges, fullScreen, verticalSync, hardwareCursor, fieldOfView,
                                                        videoAdapter, videoMode, renderQuality, first, requestCallback);

            m_changeOperations.Enqueue(result);
        }