Пример #1
0
        //--------------------------------------------------------------
        #region Creation & Cleanup
        //--------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance of the <see cref="DebugGraphicsScreen" /> class.
        /// </summary>
        /// <param name="services">The services.</param>
        public DebugGraphicsScreen(IServiceLocator services)
            : base(services?.GetInstance <IGraphicsService>())
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            Coverage      = GraphicsScreenCoverage.Partial;
            _spriteBatch  = GraphicsService.GetSpriteBatch();
            _whiteTexture = GraphicsService.GetDefaultTexture2DWhite();

            var contentManager = services.GetInstance <ContentManager>();
            var spriteFont     = contentManager.Load <SpriteFont>("DigitalRune.Editor.Game/Fonts/DejaVuSans");

            DebugRenderer          = new DebugRenderer(GraphicsService, spriteFont);
            _internalDebugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            // To count the update frame rate, we handle the GameLogicUpdating event.
            // (We cannot use GraphicsScreen.OnUpdate because it is only called at the same rate if
            // the graphics screen is registered in the graphics service. If it is not registered,
            // then OnUpdate and OnRender are always called together.)
            var editor = services.GetInstance <IEditorService>();

            _gameExtension = editor.Extensions.OfType <GameExtension>().FirstOrDefault();
            if (_gameExtension != null)
            {
                _gameExtension.GameLogicUpdating += OnGameLogicUpdating;
            }
        }
        private void UpdateTimer()
        {
            if (WindowsHelper.IsInDesignMode)
            {
                return;
            }

            if (_gameTimer == null)
            {
                if (AssociatedObject.IsLoaded)
                {
                    var editor = EditorHelper.GetEditor(AssociatedObject).ThrowIfMissing();
                    _gameTimer     = editor.Services.GetInstance <IGameTimer>().ThrowIfMissing();
                    _gameExtension = editor.Extensions.OfType <GameExtension>().FirstOrDefault().ThrowIfMissing();
                }
                else
                {
                    AssociatedObject.Loaded += (s, e) => UpdateTimer();
                    return;
                }
            }

            // Start/stop timer based on current state.
            var view = AssociatedObject;

            if (view != null && view.IsFocused && IsEnabled)
            {
                _gameExtension.GameLoopNewFrame += OnTick;
            }
            else
            {
                _gameExtension.GameLoopNewFrame -= OnTick;
            }
        }
Пример #3
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="DebugGraphicsScreen" /> class.
        /// </summary>
        /// <param name="services">The services.</param>
        public DebugGraphicsScreen(IServiceLocator services)
            : base(services?.GetInstance<IGraphicsService>())
        {
            if (services == null)
                throw new ArgumentNullException(nameof(services));

            Coverage = GraphicsScreenCoverage.Partial;
            _spriteBatch = GraphicsService.GetSpriteBatch();
            _whiteTexture = GraphicsService.GetDefaultTexture2DWhite();

            var contentManager = services.GetInstance<ContentManager>();
            var spriteFont = contentManager.Load<SpriteFont>("DigitalRune.Editor.Game/Fonts/DejaVuSans");
            DebugRenderer = new DebugRenderer(GraphicsService, spriteFont);
            _internalDebugRenderer = new DebugRenderer(GraphicsService, spriteFont);

            // To count the update frame rate, we handle the GameLogicUpdating event.
            // (We cannot use GraphicsScreen.OnUpdate because it is only called at the same rate if
            // the graphics screen is registered in the graphics service. If it is not registered,
            // then OnUpdate and OnRender are always called together.)
            var editor = services.GetInstance<IEditorService>();
            _gameExtension = editor.Extensions.OfType<GameExtension>().FirstOrDefault();
            if (_gameExtension != null)
                _gameExtension.GameLogicUpdating += OnGameLogicUpdating;
        }
Пример #4
0
        protected override void OnDeactivated(DeactivationEventArgs eventArgs)
        {
            if (eventArgs.Closed)
            {
                _gameExtension.GameLogicUpdating -= OnGameLogicUpdating;
                _gameExtension = null;

                Document.PropertyChanged -= OnDocumentPropertyChanged;
                Reset(true, true);
            }

            base.OnDeactivated(eventArgs);
        }
Пример #5
0
        protected override void OnActivated(ActivationEventArgs eventArgs)
        {
            if (eventArgs.Opened)
            {
                _gameExtension = Document.Editor.Extensions.OfType<GameExtension>().FirstOrDefault().ThrowIfMissing();
                _gameExtension.GameLogicUpdating += OnGameLogicUpdating;

                Document.PropertyChanged += OnDocumentPropertyChanged;
                Initialize();
            }

            base.OnActivated(eventArgs);
        }