Esempio n. 1
0
        public void Play()
        {
            bool   skipped = false;
            ushort x       = (ushort)((_vm.Settings.Game.Width - _decoder.GetWidth()) / 2);
            ushort y       = (ushort)((_vm.Settings.Game.Height - _decoder.GetHeight()) / 2);

            while (!SwordEngine.ShouldQuit && !_decoder.EndOfVideo && !skipped)
            {
                if (_decoder.NeedsUpdate)
                {
                    var frame = _decoder.DecodeNextFrame();
                    if (frame != null)
                    {
                        if (SystemVars.Platform == Core.IO.Platform.PSX)
                        {
                            DrawFramePSX(frame);
                        }
                        else
                        {
                            _vm.GraphicsManager.CopyRectToScreen(frame.Pixels, frame.Pitch, x, y, frame.Width, frame.Height);
                        }
                    }

                    if (_decoder.HasDirtyPalette)
                    {
                        var palette = ToPalette(_decoder.Palette);
                        _vm.GraphicsManager.SetPalette(palette, 0, 256);

                        UpdateColors();
                    }

                    var pixels = _vm.GraphicsManager.Pixels;
                    PerformPostProcessing(pixels);
                    _vm.GraphicsManager.CopyRectToScreen(pixels, _vm.Settings.Game.Width * Surface.GetBytesPerPixel(_vm.GraphicsManager.PixelFormat), 0, 0, _vm.Settings.Game.Width, _vm.Settings.Game.Height);
                    _vm.GraphicsManager.UpdateScreen();
                }

                int count;
                var lastState = new ScummInputState();
                do
                {
                    var state = _vm.System.InputManager.GetState();
                    count = state.GetKeys().Count;
                    if (state.IsKeyDown(KeyCode.Escape) || (lastState.IsLeftButtonDown && !state.IsLeftButtonDown))
                    {
                        skipped = true;
                    }
                    _vm.System.InputManager.ResetKeys();
                    lastState = state;
                } while (!skipped && count != 0);

                ServiceLocator.Platform.Sleep(10);
            }

            // Need to jump back to paletted color
            if (SystemVars.Platform == Core.IO.Platform.PSX)
            {
                _vm.GraphicsManager.PixelFormat = PixelFormat.Indexed8;
            }
        }