Ejemplo n.º 1
0
        /// <summary>
        /// Load graphics resources content.
        /// </summary>
        public override void LoadContent()
        {
            int block1 = -1;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame::LoadContent", ref block1);
            base.LoadContent();

            DefaultSurface           = MyMinerGame.Static.GraphicsDevice.GetRenderTarget(0);
            DefaultSurface.DebugName = "DefaultSurface";
            DefaultDepth             = MyMinerGame.Static.GraphicsDevice.DepthStencilSurface;
            DefaultDepth.DebugName   = "DefaultDepth";

            MyMwcLog.WriteLine("MyMinerGame.LoadContent() - START");
            MyMwcLog.IncreaseIndent();

            MyVideoModeManager.UpdateScreenSize();

            System.Drawing.Font systemfont = new System.Drawing.Font("Tahoma", 12f, FontStyle.Regular);
            m_debugFont = new SharpDX.Direct3D9.Font(GraphicsDevice, systemfont);

            // GUI
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyGuiManager.LoadContent()");
            MyGuiManager.LoadContent();

            // Models
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyModels.LoadContent()");
            MyModels.LoadContent();

            // Render
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyRender.LoadContent();");
            MyRender.LoadContent();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyDebugDraw.LoadContent();");
            MyDebugDraw.LoadContent();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyDebugDrawCachedLines.LoadContent()");
            MyDebugDrawCachedLines.LoadContent();


            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MySunGlare.LoadContent()");
            MySunGlare.LoadContent();
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.LoadContent() - END");

            GC.Collect();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(block1);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Processes this operation.
            /// </summary>
            internal void Process()
            {
                MyMwcLog.WriteLine("MyVideoModeManager.ChangeVideoMode - START");
                MyMwcLog.IncreaseIndent();

                bool modeChange = !videoMode.Equals(m_videoMode) || m_videoAdapter != videoAdapter || m_fullScreen != fullScreen ||
                                  m_verticalSync != verticalSync,
                     qualityChange        = MyRenderConstants.RenderQualityProfile.RenderQuality != renderQuality,
                     fovChange            = m_fieldOfView != fieldOfView,
                     hardwareCursorChange = m_hardwareCursor != hardwareCursor;

                SomethingChanged = modeChange || qualityChange || fovChange || hardwareCursorChange;

                bool needReloadContent = false;

                m_fullScreen     = fullScreen;
                m_videoMode      = videoMode;
                m_videoAdapter   = videoAdapter;
                m_verticalSync   = verticalSync;
                m_hardwareCursor = hardwareCursor;
                m_fieldOfView    = fieldOfView;

                //  User provided values
                MyMwcLog.WriteLine("Width: " + videoMode.Width);
                MyMwcLog.WriteLine("Height: " + videoMode.Height);
                MyMwcLog.WriteLine("FullScreen: " + m_fullScreen);
                MyMwcLog.WriteLine("VerticalSync: " + m_verticalSync);
                MyMwcLog.WriteLine("HardwareCursor: " + m_hardwareCursor);
                MyMwcLog.WriteLine("RenderQuality: " + (int)renderQuality);

                /*
                 * foreach (GraphicsAdapter adapter in GraphicsAdapter.Adapters)
                 * {
                 *  MyMwcLog.WriteLine("adapter.Description: " + adapter.Description.Description);
                 *  MyMwcLog.WriteLine("adapter.VendorId: " + adapter.Description.VendorId);
                 *  MyMwcLog.WriteLine("adapter.DeviceId: " + adapter.Description.DeviceId);
                 *  MyMwcLog.WriteLine("adapter.DeviceName: " + adapter.Name);
                 *  MyMwcLog.WriteLine("adapter.IsDefaultAdapter: " + adapter.IsDefaultAdapter);
                 *  //MyMwcLog.WriteLine("adapter.IsWideScreen: " + adapter.Description.);
                 *  MyMwcLog.WriteLine("adapter.Revision: " + adapter.Description.Revision);
                 *  MyMwcLog.WriteLine("adapter.SubSystemId: " + adapter.Description.SubsystemId);
                 *  MyMwcLog.WriteLine("adapter.CurrentDisplayMode.Width: " + adapter.CurrentDisplayMode.Width);
                 *  MyMwcLog.WriteLine("adapter.CurrentDisplayMode.Height: " + adapter.CurrentDisplayMode.Height);
                 *  MyMwcLog.WriteLine("adapter.CurrentDisplayMode.AspectRatio: " +
                 * adapter.CurrentDisplayMode.AspectRatio);
                 *  MyMwcLog.WriteLine("adapter.CurrentDisplayMode.Format: " + adapter.CurrentDisplayMode.Format);
                 * }
                 */
                //  System values

                /*
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.Description: " +
                 *                 GraphicsAdapter.Default.Description.Description);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.VendorId: " + GraphicsAdapter.Default.Description.VendorId);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.DeviceId: " + GraphicsAdapter.Default.Description.DeviceId);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.DeviceName: " +
                 *                 GraphicsAdapter.Default.Name);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.IsDefaultAdapter: " +
                 *                 GraphicsAdapter.Default.IsDefaultAdapter);
                 * //                MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.IsWideScreen: " +
                 * //                                 GraphicsAdapter.Default.IsWideScreen);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.Revision: " + GraphicsAdapter.Default.Description.Revision);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.SubSystemId: " +
                 *                 GraphicsAdapter.Default.Description.SubsystemId);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width: " +
                 *                 GraphicsAdapter.Default.CurrentDisplayMode.Width);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height: " +
                 *                 GraphicsAdapter.Default.CurrentDisplayMode.Height);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.AspectRatio: " +
                 *                 GraphicsAdapter.Default.CurrentDisplayMode.AspectRatio);
                 * MyMwcLog.WriteLine("GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Format: " +
                 *                 GraphicsAdapter.Default.CurrentDisplayMode.Format);
                 * MyMwcLog.WriteLine("PreferredBackBufferFormat: " +
                 *                 MyMinerGameDX.GraphicsDeviceManager.PreferredBackBufferFormat);
                 * MyMwcLog.WriteLine("PreferredDepthStencilFormat: " +
                 *                 MyMinerGameDX.GraphicsDeviceManager.PreferredDepthStencilFormat);
                 * MyMwcLog.WriteLine("PreferredBackBufferWidth: " +
                 *                 MyMinerGameDX.GraphicsDeviceManager.PreferredBackBufferWidth);
                 * MyMwcLog.WriteLine("PreferredBackBufferHeight: " +
                 *                 MyMinerGameDX.GraphicsDeviceManager.PreferredBackBufferHeight);
                 * MyMwcLog.WriteLine("PreferMultiSampling: " + MyMinerGameDX.GraphicsDeviceManager.PreferMultiSampling);
                 * MyMwcLog.WriteLine("SynchronizeWithVerticalRetrace: " +
                 *                 MyMinerGameDX.GraphicsDeviceManager.SynchronizeWithVerticalRetrace);
                 * //                MyMwcLog.WriteLine("GraphicsProfile: " + MyMinerGameDX.GraphicsDeviceManager.fea);
                 */
                Changed = false;

                if (IsSupportedDisplayMode(videoAdapter, videoMode.Width, videoMode.Height, m_fullScreen) == true)
                {
                    // The mode is supported, so set the buffer formats, apply changes and return
                    //MyMinerGameDX.GraphicsDeviceManager.PreferMultiSampling = false;
                    MyMinerGame.GraphicsDeviceManager.PreferredVideoAdapter = videoAdapter;

                    MyMinerGame.GraphicsDeviceManager.PreferredBackBufferWidth  = videoMode.Width;
                    MyMinerGame.GraphicsDeviceManager.PreferredBackBufferHeight = videoMode.Height;
#if RENDER_PROFILING || GPU_PROFILING
                    MyMinerGame.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
#else
                    MyMinerGame.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = m_verticalSync;
#endif
                    MyMinerGame.GraphicsDeviceManager.IsFullScreen = m_fullScreen;
                    MyMinerGame.GraphicsDeviceManager.PreferredDepthStencilFormat = Format.D24S8;
                    //  We need stencil in backbuffer because
                    Changed = true;
                }

                try
                {
                    if (callApplyChanges)
                    {
                        if (modeChange)
                        {
                            //  ApplyChanges() should be called only if we change screen resolution during game. It shouldn't be called when we
                            //  set up resolution at game start up (because Game class Initialize is handling that for us and if we also do it - it can
                            //  have bad consequences on dual monitor setup).
                            MyMinerGame.GraphicsDeviceManager.ApplyChanges();
                            //MyRender.ResetStates();
                        }

                        if (qualityChange)
                        {
                            needReloadContent = MyRenderConstants.RenderQualityProfile.NeedReloadContent;
                            MyRenderConstants.SwitchRenderQuality(renderQuality);
                            needReloadContent |= MyRenderConstants.RenderQualityProfile.NeedReloadContent;
                        }

                        if (fovChange)
                        {
                            if (MinerWars.CommonLIB.AppCode.Utils.MyMwcUtils.IsZero(fieldOfView - MinerWarsMath.MathHelper.ToRadians(70)))
                            { //replace old default value
                                fieldOfView = MinerWarsMath.MathHelper.ToRadians(60);
                            }

                            MyCamera.FieldOfView = fieldOfView;

                            if (MyCamera.Zoom != null)
                            {
                                MyCamera.Zoom.Update();
                            }
                            MyCamera.ChangeFov(MyCamera.FieldOfView);
                        }

                        // if (hardwareCursorChange)
                        {
                            // do whatever is necessary to switch cursor between hardware/software
                            MyMinerGame.Static.IsMouseVisible = m_hardwareCursor;
                            MinerWars.AppCode.Game.GUI.Core.MyGuiManager.SetMouseCursorVisibility(m_hardwareCursor);
                        }

                        if (needReloadContent && MyMinerGame.Static.IsActive && !first)
                        {
                            //MyMinerGame.Static.ReloadContent();
                            MyRender.LoadContent();
                            MyModels.ReloadContent();
                            MinerWars.AppCode.Game.Voxels.MyVoxelMaterials.ReloadContent();
                            MyTextureManager.ReloadTextures();
                        }
                    }

                    if (Changed)
                    {
                        UpdateScreenSize();
                    }
                }
                catch (Exception e)
                {
                    Debug.Fail("Failed to change resolution");
                    MyMwcLog.WriteLine("Failed to update screen size: " + e.ToString());
                    Changed = false;
                }

                if (!Changed || needReloadContent)
                {
                    // There was error when changing resolution, so we try to restore previous state - so recreate render targets with old size
                    try
                    {
                        // reset render targets, or it will crash in next draw, before reverting the settings
                        //  MyRender.CreateRenderTargets();
                        //  MyRender.CreateEnvironmentMapsRT(MyRenderConstants.ENVIRONMENT_MAP_SIZE);
                    }
                    catch (Exception)
                    {
                        Debug.Fail("Failed to reload content");
                        Changed = false;
                        MyMwcLog.WriteLine("Failed to reload content");
                    }
                }

                if (this.requestCallback != null)
                {
                    this.requestCallback(this);
                }

                MyMinerGame.IsGameReady = true;

                MyMwcLog.DecreaseIndent();
                MyMwcLog.WriteLine("MyVideoModeManager.ChangeVideoMode - END");
            }