public void SetDeviceViewport(Viewport viewport)
 {
     MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame::SetDeviceViewport");
     if (m_renderTargetsCount == 0)
     {
         if ((MyMinerGame.Static.GraphicsManager.PreferredBackBufferHeight >= (viewport.Height + viewport.Y)) &&
             (MyMinerGame.Static.GraphicsManager.PreferredBackBufferWidth >= (viewport.Width + viewport.X)))
         {
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("set viewport");
             MyMinerGame.Static.GraphicsDevice.Viewport = viewport;
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
         }
         else
         {
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("change screen size");
             MyVideoModeManager.UpdateScreenSize();
             MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
         }
     }
     else
     {
         MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("set viewport");
         MyMinerGame.Static.GraphicsDevice.Viewport = viewport;
         MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
     }
     MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
 }
 //  Revert changes - setting new video resolution must be done from Draw call, because when called
 //  from Update while game isn't active (alt-tabed or minimized) it will fail on weird XNA exceptions
 void RevertChanges()
 {
     //  Revert and change video mode to OLD settings
     MyVideoModeManager.BeginChangeVideoMode(true,
                                             m_settingsOld.VideoAdapter,
                                             m_settingsOld.VideoMode,
                                             m_settingsOld.FullScreen, m_settingsOld.VerticalSync, m_settingsOld.HardwareCursor, m_settingsOld.RenderQuality, m_settingsOld.FieldOfView, false, OnVideoModeChanged);
 }
        void OnVideoAdapterSelected()
        {
            int adapterIndex = m_videoAdapterCombobox.GetSelectedKey();

            AddDisplayModesToComboBox(adapterIndex);
            UpdateRecommendecAspectRatioLabel(adapterIndex);

            m_videoModeCombobox.SelectItemByKey(MyVideoModeManager.GetVideoModeIndexByWidthAndHeight(adapterIndex, m_settingsOld.VideoMode.Width, m_settingsOld.VideoMode.Height));
        }
 void UpdateControls(MyGuiScreenOptionsVideoSettings settings)
 {
     m_videoAdapterCombobox.SelectItemByKey(settings.VideoAdapter);
     m_videoModeCombobox.SelectItemByKey(MyVideoModeManager.GetVideoModeIndexByWidthAndHeight(settings.VideoAdapter, settings.VideoMode.Width, settings.VideoMode.Height));
     m_fullscreenCheckbox.Checked     = settings.FullScreen;
     m_verticalSyncCheckbox.Checked   = settings.VerticalSync;
     m_hardwareCursorCheckbox.Checked = settings.HardwareCursor;
     m_renderQualityCombobox.SelectItemByKey((int)settings.RenderQuality);
     m_fieldOfViewSlider.SetValue(settings.FieldOfView);
     OnFovChanged(m_fieldOfViewSlider);
 }
        void AddDisplayModesToComboBox(int adapterIndex)
        {
            m_videoModeCombobox.ClearItems();

            int counter = 0;

            foreach (MyVideoModeEx videoMode in MyVideoModeManager.GetAllSupportedVideoModes(adapterIndex))
            {
                m_videoModeCombobox.AddItem(counter++, new StringBuilder(
                                                videoMode.Width + " × " + videoMode.Height + string.Format(videoMode.IsRecommended ? " – {0} ***" : " – {0}", MyTextsWrapper.Get(MyAspectRatioExList.Get(videoMode.AspectRatioEnum).TextShort))
                                                ));
            }
        }
        /// <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);
        }
        public void OnApplyClick(MyGuiControlButton sender)
        {
            //  Update NEW settings
            bool somethingChanged = UpdateSettings(m_settingsNew);

            //  Change video mode to new one
            if (somethingChanged)
            {
                MyVideoModeManager.BeginChangeVideoMode(true, m_settingsNew.VideoAdapter, m_settingsNew.VideoMode, m_settingsNew.FullScreen, m_settingsNew.VerticalSync, m_settingsNew.HardwareCursor, m_settingsNew.RenderQuality, m_settingsNew.FieldOfView, false, OnVideoModeChangedAndComfirm);
            }
            else
            {
                CloseScreen();
            }
        }
        void OnVideoModeSelected()
        {
            MyVideoModeEx mode = MyVideoModeManager.GetVideoModeByIndex(m_videoAdapterCombobox.GetSelectedKey(), m_videoModeCombobox.GetSelectedKey());

            m_fieldOfViewSlider.SetValue(MyConstants.FIELD_OF_VIEW_CONFIG_DEFAULT);
            if (mode.AspectRatio >= (12.0 / 3.0))
            {
                m_fieldOfViewSlider.SetBounds(MyConstants.FIELD_OF_VIEW_CONFIG_MIN, MyConstants.FIELD_OF_VIEW_CONFIG_MAX_TRIPLE_HEAD);
            }
            else if (mode.AspectRatio >= (8.0 / 3.0))
            {
                m_fieldOfViewSlider.SetBounds(MyConstants.FIELD_OF_VIEW_CONFIG_MIN, MyConstants.FIELD_OF_VIEW_CONFIG_MAX_DUAL_HEAD);
            }
            else
            {
                m_fieldOfViewSlider.SetBounds(MyConstants.FIELD_OF_VIEW_CONFIG_MIN, MyConstants.FIELD_OF_VIEW_CONFIG_MAX);
            }
        }
        //  Allows the game to perform any initialization it needs to before starting to run.
        //  This is where it can query for any required services and load any non-graphic
        //  related content.  Calling base.Initialize will enumerate through any components
        //  and initialize them as well.
        protected override void Initialize()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame::Initialize");
            MyMwcLog.WriteLine("MyMinerGame.Initialize() - START");
            MyMwcLog.IncreaseIndent();

            Window.NativeWindow.Text = "MinerWars 2081";
            ((System.Windows.Forms.Form)Window.NativeWindow).Icon = new System.Drawing.Icon("MinerWars.ico");

            if (OnGameInit != null)
            {
                OnGameInit(this);
            }

            MyVideoModeManager.Initialize();

#if !DEBUG
            try
            {
#endif
            // Load data
            LoadData();

            // Load content
            base.Initialize();

            InitQuickLaunch();

#if !DEBUG
        }
        catch (Exception ex)
        {
            //  We are catching exceptions in LoadContent, because if error occures here, it app will start unloading
            //  so we skip to UnloadContent and there we will get another exception (because app wasn't really loaded when unload started)
            //  So we want original exception in log.
            MyMwcLog.WriteLine(ex);
            throw;
        }
#endif

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.Initialize() - END");
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
        bool UpdateSettings(MyGuiScreenOptionsVideoSettings settings)
        {
            bool retval = settings.VideoMode != MyVideoModeManager.GetVideoModeByIndex(m_videoAdapterCombobox.GetSelectedKey(), m_videoModeCombobox.GetSelectedKey()) ||
                          settings.VideoAdapter != m_videoAdapterCombobox.GetSelectedKey() ||
                          settings.FullScreen != m_fullscreenCheckbox.Checked ||
                          settings.VerticalSync != m_verticalSyncCheckbox.Checked ||
                          settings.HardwareCursor != m_hardwareCursorCheckbox.Checked ||
                          settings.RenderQuality != (MyRenderQualityEnum)m_renderQualityCombobox.GetSelectedKey() ||
                          settings.FieldOfView != m_fieldOfViewSlider.GetValue();

            settings.VideoAdapter   = m_videoAdapterCombobox.GetSelectedKey();
            settings.VideoMode      = MyVideoModeManager.GetVideoModeByIndex(settings.VideoAdapter, m_videoModeCombobox.GetSelectedKey());
            settings.FullScreen     = m_fullscreenCheckbox.Checked;
            settings.VerticalSync   = m_verticalSyncCheckbox.Checked;
            settings.HardwareCursor = m_hardwareCursorCheckbox.Checked;
            settings.RenderQuality  = (MyRenderQualityEnum)m_renderQualityCombobox.GetSelectedKey();
            settings.FieldOfView    = m_fieldOfViewSlider.GetValue();

            return(retval);
        }
Exemple #11
0
        protected virtual Matrix GetLocalMatrixForCockpitView()
        {
            float yOffset = MySmallShipConstants.ALL_SMALL_SHIP_MODEL_SCALE * YOffset;
            float zOffset = MySmallShipConstants.ALL_SMALL_SHIP_MODEL_SCALE * ZOffset;

            // in triple monitors, we must hack weapon's zOffset
            if (MyVideoModeManager.IsTripleHead())
            {
                float maxDistanceFromCenterX = 10f;
                float muFOV = (MyCamera.FieldOfView - MyConstants.FIELD_OF_VIEW_CONFIG_MIN) /
                              (MyConstants.FIELD_OF_VIEW_CONFIG_MAX_TRIPLE_HEAD - MyConstants.FIELD_OF_VIEW_CONFIG_MIN);
                float distanceFromCenterX = Math.Abs(this.LocalMatrix.Translation.X);
                float muDistanceX         = (distanceFromCenterX - 0f) / (maxDistanceFromCenterX - 0f);

                zOffset = zOffset - ((1f - muDistanceX) * (1f - muFOV) * 0.9f) + muDistanceX * muFOV * 2.5f;
            }

            Matrix localMatrix = Matrix.CreateTranslation(0f, yOffset, zOffset) * this.LocalMatrix;

            return(localMatrix);
        }
        private void OnVideoModeChangedAndComfirm(MinerWars.AppCode.Game.VideoMode.MyVideoModeManager.MyVideoModeChangeOperation result)
        {
            bool changed = MyVideoModeManager.EndChangeVideoMode(result);

            if (changed)
            {
                if (MyVideoModeManager.HasAnythingChanged(result))
                {
                    //udpate screen here
                    m_waitingForConfirmation = true;
                    MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.MESSAGE, MyTextsWrapperEnum.DoYouWantToKeepTheseSettingsXSecondsRemaining,
                                                                     MyTextsWrapperEnum.MessageBoxCaptionPleaseConfirm, MyTextsWrapperEnum.Yes, MyTextsWrapperEnum.No,
                                                                     OnMessageBoxCallback, MyGuiConstants.VIDEO_OPTIONS_CONFIRMATION_TIMEOUT_IN_MILISECONDS));
                }
            }
            else
            {
                MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.SorryButSelectedSettingsAreNotSupportedByYourHardware,
                                                                 MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null));

                m_doRevert = true;
            }
        }
        public override void HandleInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            base.HandleInput(input, receivedFocusInThisUpdate);

            if (MyGuiInput.ENABLE_DEVELOPER_KEYS)
            {
                if (input.IsNewKeyPress(Keys.C) && input.IsAnyCtrlKeyPressed())
                {
                    CopySector();
                }
                if (input.IsNewKeyPress(Keys.V) && input.IsAnyCtrlKeyPressed())
                {
                    PasteSector();
                }
            }


            if (MyFakes.DRAW_FACTION_AREAS_IN_SOLAR_MAP)
            {
                MySolarMapAreaInput.HandleInput(m_solarMapRender, input, receivedFocusInThisUpdate);
            }

            float   rollIndicator     = input.GetRoll();
            Vector2 rotationIndicator = Vector2.Zero;

            if (input.IsNewRightMousePressed() && MyVideoModeManager.IsHardwareCursorUsed())
            {
                m_oldRotationIndicator = input.GetRotation();
            }

            if (input.IsRightMousePressed())
            {
                if (MyVideoModeManager.IsHardwareCursorUsed())
                {
                    rotationIndicator      = m_oldRotationIndicator - input.GetRotation();
                    m_oldRotationIndicator = input.GetRotation();
                }
                else
                {
                    rotationIndicator = input.GetRotation();
                }
            }
            Vector3 moveIndicator = input.GetPositionDelta();

            if (input.IsKeyPress(Keys.Left))
            {
                moveIndicator.X = -1;
            }
            if (input.IsKeyPress(Keys.Right))
            {
                moveIndicator.X = 1;
            }
            if (input.IsKeyPress(Keys.Up))
            {
                moveIndicator.Z = -1;
            }
            if (input.IsKeyPress(Keys.Down))
            {
                moveIndicator.Z = 1;
            }

            m_camera.Zoom(input.DeltaMouseScrollWheelValue());

            m_camera.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator, 1);


            bool sectorChanged = false;

            if (m_lastSector != m_camera.TargetSector)
            {
                sectorChanged = true;
                m_lastSector  = m_camera.TargetSector;
            }



            MySolarSystemMapNavigationMark navigationMarkUnderMouse = GetNearestNavigationMarkUnderMouseCursor();

            const float maxHeightForEnter = MySolarSystemMapCamera.SECTOR_SIZE_GAMEUNITS * 16;

            if (sectorChanged) // we have moved camera so deselect sector
            {
                m_selectedSector = null;
            }


            // tool tips
            if (m_lastNavigationMarkUnderMouse != navigationMarkUnderMouse)
            {
                m_toolTip.ClearToolTips();
                if (navigationMarkUnderMouse != null)
                {
                    m_toolTip.AddToolTip(new StringBuilder(GetSectorName(navigationMarkUnderMouse)));
                    if (!String.IsNullOrEmpty(navigationMarkUnderMouse.Description))
                    {
                        m_toolTip.AddToolTip(new StringBuilder(navigationMarkUnderMouse.Description), Color.LightGray);
                    }
                    m_toolTip.AddToolTip(new StringBuilder(navigationMarkUnderMouse.Sector.ToString()), Color.LightGray);
                }
                m_lastNavigationMarkUnderMouse = navigationMarkUnderMouse;
            }



            if (navigationMarkUnderMouse != null)
            {
                MyGuiManager.SetMouseCursorTexture(MyGuiManager.GetMouseCursorHandTexture());

                if (input.IsNewLeftMousePressed() && !m_travelButton.IsMouseOver())
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                    if (m_selectedNavigationMark != null)
                    {
                        m_selectedNavigationMark.Highlight = false;
                    }

                    m_selectedNavigationMark           = navigationMarkUnderMouse;
                    m_selectedNavigationMark.Highlight = true;
                    sectorChanged          = true;
                    m_slectionLocked       = true;
                    m_travelButton.Visible = false;
                }
                if (input.IsNewLeftMouseDoubleClick())
                {
                    TravelToSector(navigationMarkUnderMouse.Sector, navigationMarkUnderMouse.MissionID);
                }
            }
            else if (m_camera.CameraDistance < maxHeightForEnter && !m_slectionLocked)
            {
                if (MyGuiScreenGamePlay.CanTravelToSector(m_camera.TargetSector))
                {
                    //MyGuiManager.SetMouseCursorTexture(MyGuiManager.GetMouseCursorHandTexture());
                    if (m_selectedNavigationMark != null)
                    {
                        m_selectedNavigationMark.Highlight = false;
                    }

                    var navigationMarkUnderCamera = GetNavigationMarkUnderCamera();
                    if (navigationMarkUnderCamera != null && navigationMarkUnderCamera.Sector == m_camera.TargetSector)
                    {
                        m_selectedNavigationMark = navigationMarkUnderCamera;
                    }
                    else
                    {
                        m_selectedNavigationMark = new MySolarSystemMapNavigationMark(m_camera.TargetSector, "");
                        m_travelButton.Visible   = false;
                    }
                }
                else
                {
                    m_selectedNavigationMark = null;
                }
            }
            else if (input.IsNewLeftMousePressed())
            {
                if (m_selectedNavigationMark != null)
                {
                    m_selectedNavigationMark.Highlight = false;
                }
                if (!m_travelButton.IsMouseOver())
                {
                    m_selectedNavigationMark = null;
                }
                m_slectionLocked = false;
            }
            else if (sectorChanged && m_camera.CameraDistance > maxHeightForEnter && !m_slectionLocked)
            {
                m_selectedNavigationMark = null;
            }
            else
            {
                MyGuiManager.SetMouseCursorTexture(MyGuiManager.GetMouseCursorArrowTexture());
            }



            if (m_selectedNavigationMark != null)
            {
                if (!m_travelButton.Visible)
                {
                    m_travelButton.Text.Clear();
                    string text = GetSectorName(m_selectedNavigationMark);
                    if (text.Length > 21)
                    {
                        text  = text.Substring(0, 20);
                        text += "…";
                    }
                    m_travelButton.Text.Append(MyTextsWrapper.GetFormatString(MyTextsWrapperEnum.TravelTo, text));
                    //                    float width = MyGuiManager.GetNormalizedSize( MyGuiManager.GetFontMinerWarsBlue(), m_travelButton.Text, 1).X + 0.05f;
                    //  m_travelButton.SetSize(new Vector2(width, MyGuiConstants.BACK_BUTTON_SIZE.Y));
                    m_travelButton.Visible = true;
                }
            }
            else
            {
                m_travelButton.Visible = false;
            }
        }
Exemple #14
0
            public void Draw()
            {
                ClearTexts();
                int visibleCount = Math.Min(m_notifications.Count, MyNotificationConstants.MAX_DISPLAYED_NOTIFICATIONS_COUNT);

                for (int i = 0; i < visibleCount; i++)
                {
                    MyNotification actualNotification   = m_notifications[i];
                    StringBuilder  messageStringBuilder = m_textsPool.Allocate();
                    Debug.Assert(actualNotification != null);
                    Debug.Assert(messageStringBuilder != null);

                    bool hasConfirmation = actualNotification.HasDefaultDisappearMessage();

                    messageStringBuilder.Append(actualNotification.GetText());

                    if (hasConfirmation)
                    {
                        messageStringBuilder.AppendLine();
                        messageStringBuilder.ConcatFormat(m_defaultNotificationDisapearMessage, MyGuiManager.GetInput().GetGameControlTextEnum(MyGameControlEnums.NOTIFICATION_CONFIRMATION));
                    }

                    // draw background:
                    Vector2 textSize = MyGuiManager.GetNormalizedSize(m_usedFont, messageStringBuilder, actualNotification.GetScale());

                    m_textSizes.Add(textSize);
                    m_texts.Add(messageStringBuilder);
                }

                MyGuiManager.BeginSpriteBatch();
                var offset = new Vector2(VideoMode.MyVideoModeManager.IsTripleHead() ? -1 : 0, 0);


                // Draw fog
                Vector2 notificationPosition = Position;

                for (int i = 0; i < visibleCount; i++)
                {
                    Vector2 fogFadeSize = m_textSizes[i] * new Vector2(1.6f, 8.0f);

                    MyGuiManager.DrawSpriteBatch(MyGuiManager.GetFogSmallTexture(), notificationPosition + offset, fogFadeSize,
                                                 m_fogColor,
                                                 MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoModeManager.IsTripleHead());

                    notificationPosition.Y += m_textSizes[i].Y;
                }

                // Draw texts
                notificationPosition = Position;
                for (int i = 0; i < visibleCount; i++)
                {
                    MyNotification actualNotification = m_notifications[i];

                    MyGuiManager.DrawString(actualNotification.GetFont(), m_texts[i], notificationPosition + offset,
                                            actualNotification.GetScale(), Color.White,
                                            MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyVideoModeManager.IsTripleHead());
                    notificationPosition.Y += m_textSizes[i].Y;
                }
                MyGuiManager.EndSpriteBatch();
            }
        //  Allows the game to run logic such as updating the world, checking for collisions, gathering input, and playing audio.
        protected override void Update(GameTime gameTime)
        {
            if (m_debugFont == null)
            {
                return;
            }

            // Apply video mode changes.
            MyVideoModeManager.ApplyChanges();

            //  Update times in static member variables
            UpdateTimes(gameTime);

            //if (MyMinerGame.IsDeviceResetted)
            //  MyVideoModeManager.UpdateAfterDeviceReset();

            MyRender.GetRenderProfiler().StartProfilingBlock("Particles wait");
            MyParticlesManager.WaitUntilUpdateCompleted();
            MyRender.GetRenderProfiler().EndProfilingBlock();

            MyRender.GetRenderProfiler().StartProfilingBlock("Receive Multiplayer Messages");
            MyMultiplayerPeers.Static.Update();
            MyRender.GetRenderProfiler().EndProfilingBlock();

            int updateBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("Update", ref updateBlock);

            if (MyMwcFinalBuildConstants.EnableLoggingInDrawAndUpdateAndGuiLoops == true)
            {
                MyMwcLog.WriteLine("MyMinerGame.Update() - START");
                MyMwcLog.IncreaseIndent();
                MyMwcLog.WriteLine("Update - gameTime.ElapsedGameTime: " + gameTime.ElapsedGameTime.ToString());
                MyMwcLog.WriteLine("Update - gameTime.TotalGameTime: " + gameTime.TotalGameTime.ToString());

                MyMwcLog.WriteLine("Max Garbage Generation: " + GC.MaxGeneration.ToString());
                for (int i = 0; i <= GC.MaxGeneration; ++i)
                {
                    MyMwcLog.WriteLine("Generation " + i.ToString() + ": " + GC.CollectionCount(i).ToString() +
                                       " collections");
                }
                MyMwcLog.WriteLine("Total Memory: " + MyValueFormatter.GetFormatedLong(GC.GetTotalMemory(false)) +
                                   " bytes");
            }

            //  Inform us if there were some garbage collection
            if (MyMwcFinalBuildConstants.EnableLoggingGarbageCollectionCalls)
            {
                int newGc = MyGarbageCollectionManager.GetGarbageCollectionsCountFromLastCall();
                if (newGc > 0)
                {
                    MyMwcLog.WriteLine("####### Garbage collections from the last call: " + newGc + " #######");
                }
            }


            int updateManagersBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("UpdateManagers", ref updateManagersBlock);

            MyRender.GetRenderProfiler().EndProfilingBlock(updateManagersBlock);

            //  Now I think that it's better if HandleInput is called after Update, because then input methods
            //  such as Shot() have up-to-date values such as position, forward vector, etc
            int guiManagerBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("GuiManager", ref guiManagerBlock);
            MyGuiManager.Update();
            MyRender.GetRenderProfiler().EndProfilingBlock(guiManagerBlock);

            //After guimanager update because of object world matrices updates of objects
            MyParticlesManager.Update();

            int inputBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("Input", ref inputBlock);
            MyGuiManager.HandleInput();
            MyRender.GetRenderProfiler().EndProfilingBlock(inputBlock);

            int serverUpdateBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("MyClientServer.Update", ref serverUpdateBlock);
            //MyClientServer.Update();       ti
            MyRender.GetRenderProfiler().EndProfilingBlock(serverUpdateBlock);

            if (MyMwcFinalBuildConstants.SimulateSlowUpdate)
            {
                System.Threading.Thread.Sleep(7);
            }

            int audioUpdateBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("MyAudio.Update", ref audioUpdateBlock);
            MyAudio.Update();
            MyDialogues.Update();
            MyRender.GetRenderProfiler().EndProfilingBlock(audioUpdateBlock);

            int othersBlock = -1;

            MyRender.GetRenderProfiler().StartProfilingBlock("Others", ref othersBlock);

            if (MyMwcFinalBuildConstants.EnableLoggingInDrawAndUpdateAndGuiLoops == true)
            {
                if (MyMwcLog.IsIndentKeyIncreased())
                {
                    MyMwcLog.DecreaseIndent();
                }
                MyMwcLog.WriteLine("MyMinerGame.Update() - END");
            }

            ProcessInvoke();

            if (OnGameUpdate != null)
            {
                OnGameUpdate(gameTime);
            }

            base.Update(gameTime);

            MyRender.GetRenderProfiler().EndProfilingBlock(othersBlock);

            MyRender.GetRenderProfiler().EndProfilingBlock(updateBlock);
        }
        public MyMinerGame(ServiceContainer services)
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyMinerGame()::constructor");
            MyMwcLog.WriteLine("MyMinerGame.Constructor() - START");
            MyMwcLog.IncreaseIndent();

            Services = services;

            // we want check objectbuilders, prefab's configurations, gameplay constants and building specifications
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Checks");
            MyMwcObjectBuilder_Base.Check();
            MyPrefabConstants.Check();
            MyGameplayConstants.Check();
            MyBuildingSpecifications.Check();
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("Preallocate");

            Preallocate();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("IsAdmin");
            WindowsIdentity  windowsIdentity  = WindowsIdentity.GetCurrent();
            WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity);
            bool             IsAdmin          = windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);

            MyMwcLog.WriteLine("IsAdmin " + IsAdmin.ToString());
            MyMwcLog.WriteLine("Game dir: " + GameDir);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyCustomGraphicsDeviceManagerDX");
#if !DEBUG
            try
            {
#endif

            this.Exiting      += MyMinerGame_Exiting;
            this.Activated    += MyMinerGame_OnActivated;
            this.Deactivated  += MyMinerGame_OnDeactivated;
            this.m_InvokeQueue = new ConcurrentQueue <Tuple <ManualResetEvent, Action> >();
            this.m_MainThread  = Thread.CurrentThread;

            GraphicsDeviceManager = new MyCustomGraphicsDeviceManagerDX(this);

            m_isGraphicsSupported = GraphicsDeviceManager.ChangeProfileSupport();
            m_isGraphicsSupported = true;

            if (m_isGraphicsSupported)
            {
                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.HookEventHandlers");

                MyVideoModeManager.HookEventHandlers();

                //Content = new MyCustomContentManager(Services, ContentDir);
                //  Content = new SharpDX.Toolkit.Content.ContentManager(Services);

                RootDirectory      = Path.Combine(GameDir, "Content");
                RootDirectoryDebug = Path.GetFullPath(System.IO.Path.Combine(GameDir, "..\\..\\..\\Content"));

                RootDirectoryEffects = RootDirectory;

                Static = this;

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

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogApplicationInformation");


                MyVideoModeManager.LogApplicationInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogInformation");

                MyVideoModeManager.LogInformation();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyVideoModeManager.LogEnvironmentInformation");

                MyVideoModeManager.LogEnvironmentInformation();

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

                MyPlugins.LoadContent();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyConfig.Load");

                MyConfig.Load();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyMath.Init");

                MyMath.Init();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyTextsWrapper.Init");

                MyTextsWrapper.Init();

                MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartNextBlock("MyDialoguesWrapper.Init");

                MyDialoguesWrapper.Init();

                //  If I don't set TargetElapsedTime, default value will be used, which is 60 times per second, and it will be more precise than if I calculate
                //  it like below - SO I MUST BE DOING THE WRONG CALCULATION !!!
                //  We use fixed timestep. Update() is called at this precise timesteps. If Update or Draw takes more time, Update will be called more time. Draw is called only after Update.
#if RENDER_PROFILING || GPU_PROFILING
                IsFixedTimeStep = false;
                MyMinerGame.GraphicsDeviceManager.SynchronizeWithVerticalRetrace = false;
#else
                IsFixedTimeStep = MyFakes.FIXED_TIMESTEP;
#endif
            }

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

            InitMultithreading();
#if !DEBUG
        }

        catch (Exception ex)
        {
            //  We are catching exceptions in constructor, because if error occures here, it app will start unloading
            //  so we skip to UnloadContent and there we will get another exception (because app wasn't really loaded when unload started)
            //  So we want original exception in log.
            MyMwcLog.WriteLine(ex);
            throw;
        }
#endif

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMinerGame.Constructor() - END");
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }